BrightSide Workbench Full Report + Source Code
TaskMigration.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2022 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 package org.turro.scheduler.task.migration;
20 
21 import java.io.IOException;
22 import java.util.Set;
23 import org.turro.elephant.context.IConstructor;
24 import org.turro.log.WebLoggers;
25 import org.turro.scheduler.motor.Constraints;
26 import org.turro.scheduler.motor.DefaultTask;
27 import org.turro.scheduler.motor.ScheduledSet;
28 import org.turro.scheduler.task.constraints.Month;
29 import org.turro.scheduler.task.constraints.TaskConstraints;
30 import org.turro.scheduler.task.constraints.WeekDay;
31 import org.turro.scheduler.task.settings.TaskSettings;
32 import org.turro.scheduler.task.settings.TaskSettingsSet;
33 
38 public class TaskMigration {
39 
40 
41  public static TaskSettingsSet migrate(IConstructor constructor) {
42  if(TaskSettingsSet.noTasks()) {
43  return doMigrate(constructor);
44  }
45  return new TaskSettingsSet();
46  }
47 
48  private static TaskSettingsSet doMigrate(IConstructor constructor) {
49  Set defs = new ScheduledSet();
50  ScheduledSet.loadSet(constructor, defs);
51  TaskSettingsSet set = new TaskSettingsSet();
52  for(DefaultTask def : (Set<DefaultTask>) defs) {
53  if(!"IScheduledTask_QueueSender".equals(def.getImplementation())) {
54  TaskSettings settings = new TaskSettings();
55  settings.setActive(def.isActive());
56  settings.setImplementation(def.getClass().getName() + "Task");
57  settings.setDescription(def.getDescription());
58  settings.setStartDate(def.getStartDate());
59  settings.setEndDate(def.getEndDate());
60  settings.setData(def.getData());
61  TaskConstraints cons = settings.getConstraints();
62  Constraints dcons = def.getConstraints();
63  for(Integer i : dcons.getDaysOfMonth()) {
64  cons.getDaysOfMonth().add(i);
65  }
66  for(Integer i : dcons.getHours()) {
67  cons.getHours().add(i);
68  }
69  for(Integer i : dcons.getMinutes()) {
70  cons.getMinutes().add(i);
71  }
72  for(org.turro.scheduler.constraints.Month i : dcons.getMonths()) {
73  cons.getMonths().add(Month.valueOf(i.name()));
74  }
75  for(org.turro.scheduler.constraints.WeekDay i : dcons.getWeekDays()) {
76  cons.getWeekDays().add(WeekDay.valueOf(i.name()));
77  }
78  set.add(settings);
79  }
80  }
81  try {
82  set.save();
83  } catch (IOException ex) {
84  WebLoggers.severe(TaskMigration.class).exception(ex).log();
85  }
86  return set;
87  }
88 
89 }
DayOfMonthConstraint getDaysOfMonth()
static void loadSet(IConstructor constructor, Set set)
static TaskSettingsSet migrate(IConstructor constructor)
void setImplementation(String implementation)