MaintenanceWindowImpl.java
4.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* org.apache.sling.api.resource.Resource
* org.apache.sling.api.resource.ResourceUtil
* org.apache.sling.api.resource.ValueMap
*/
package com.adobe.granite.maintenance.impl;
import com.adobe.granite.maintenance.MaintenanceTaskInfo;
import com.adobe.granite.maintenance.MaintenanceUtil;
import com.adobe.granite.maintenance.impl.Util;
import java.io.Serializable;
import java.util.Collections;
import java.util.List;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceUtil;
import org.apache.sling.api.resource.ValueMap;
public class MaintenanceWindowImpl
implements Serializable {
private static final long serialVersionUID = 2;
private final String title;
private final String startTimeExpression;
private final String endTimeExpression;
private List<MaintenanceTaskInfo> tasks = Collections.emptyList();
private final MaintenanceTaskInfo.TaskSchedule schedule;
public MaintenanceWindowImpl(Resource windowResource) throws IllegalArgumentException {
Integer[] endWeekDays;
int[] endTimeDef;
ValueMap vm = ResourceUtil.getValueMap((Resource)windowResource);
String startTime = (String)vm.get("windowStartTime", String.class);
String endTime = (String)vm.get("windowEndTime", String.class);
if (!MaintenanceUtil.isValidTimeInterval(startTime, endTime)) {
throw new IllegalAccessError("Start and/or end time invalid: " + startTime + ", " + endTime);
}
String scheduleInfo = ((String)vm.get("windowSchedule", (Object)"daily")).toUpperCase();
this.schedule = MaintenanceTaskInfo.TaskSchedule.valueOf(scheduleInfo);
Integer[] weekDays = (Integer[])vm.get("windowScheduleWeekdays", Integer[].class);
Integer weekDayFirstLast = (Integer)vm.get("windowFirstLastStartDay", Integer.class);
this.title = (String)vm.get("jcr:title", (Object)windowResource.getName());
this.startTimeExpression = Util.getCronExpression(this.schedule, weekDays, startTime, weekDayFirstLast);
if (this.startTimeExpression == null) {
throw new IllegalArgumentException("Invalid start time expression");
}
boolean adjustEndTime = false;
int[] startTimeDef = MaintenanceUtil.parseTime(startTime);
if (startTimeDef[0] > (endTimeDef = MaintenanceUtil.parseTime(endTime))[0] || startTimeDef[0] == endTimeDef[0] && startTimeDef[1] > endTimeDef[1]) {
adjustEndTime = true;
}
if ((endWeekDays = weekDays) != null && endWeekDays.length > 1) {
endWeekDays[0] = endWeekDays[1];
}
if (adjustEndTime) {
switch (this.schedule) {
case DAILY: {
if (weekDays == null) break;
for (int i = 0; i < weekDays.length; ++i) {
endWeekDays[i] = weekDays[i] + 1;
if (endWeekDays[i] != 8) continue;
endWeekDays[i] = 0;
}
break;
}
case WEEKLY:
case BIWEEKLY:
case MONTHLY: {
if (endWeekDays == null) {
endWeekDays = new Integer[]{2};
break;
}
if (endWeekDays.length != 1) break;
endWeekDays[0] = weekDays[0] + 1;
if (endWeekDays[0] != 8) break;
endWeekDays[0] = 0;
}
}
}
this.endTimeExpression = Util.getCronExpression(this.schedule, endWeekDays, endTime, null);
if (this.endTimeExpression == null) {
throw new IllegalArgumentException("Invalid end time expression");
}
}
public void setTasks(List<MaintenanceTaskInfo> tasks) {
this.tasks = tasks;
}
public String getStartCronExpression() {
return this.startTimeExpression;
}
public String getEndCronExpression() {
return this.endTimeExpression;
}
public String getStartScheduleName() {
return MaintenanceWindowImpl.class.getName() + "/" + this.title + "/start";
}
public String getEndScheduleName() {
return MaintenanceWindowImpl.class.getName() + "/" + this.title + "/end";
}
public List<MaintenanceTaskInfo> getMaintenanceTaskInfos() {
return this.tasks;
}
public MaintenanceTaskInfo.TaskSchedule getSchedule() {
return this.schedule;
}
public String getTitle() {
return this.title;
}
}