1
2
3
4
5
6 package org.tailormap.api.scheduling;
7
8 import jakarta.validation.constraints.NotNull;
9 import java.util.HashMap;
10 import java.util.Map;
11 import org.quartz.Trigger;
12 import org.springframework.util.Assert;
13
14
15 public class TMJobDataMap extends HashMap<String, Object> {
16
17
18
19
20
21
22
23 public TMJobDataMap(Map<String, Object> map) {
24 this(String.valueOf(map.get(Task.TYPE_KEY)), (String) map.get(Task.DESCRIPTION_KEY));
25 this.putAll(map);
26
27 if (map.containsKey(Task.PRIORITY_KEY)) {
28 this.setPriority((Integer) map.getOrDefault(Task.PRIORITY_KEY, Trigger.DEFAULT_PRIORITY));
29 } else {
30 this.setPriority(Trigger.DEFAULT_PRIORITY);
31 }
32 }
33
34
35
36
37
38
39
40
41 public TMJobDataMap(@NotNull String type, @NotNull String description) {
42 this(type, description, Trigger.TriggerState.NONE);
43 }
44
45
46
47
48
49
50
51
52 public TMJobDataMap(
53 @NotNull String type, @NotNull String description, @NotNull Trigger.TriggerState state) {
54 this(type, description, state, Trigger.DEFAULT_PRIORITY);
55 }
56
57
58
59
60
61
62
63
64
65 public TMJobDataMap(
66 @NotNull String type,
67 @NotNull String description,
68 @NotNull Trigger.TriggerState state,
69 int priority) {
70 super();
71
72 Assert.notNull(type, "type must not be null");
73 Assert.doesNotContain(type, "null", "type must not be null");
74 Assert.notNull(description, "description must not be null");
75 Assert.notNull(state, "state must not be null");
76 super.put(Task.TYPE_KEY, type);
77 super.put(Task.DESCRIPTION_KEY, description);
78 super.put(Task.STATE_KEY, state);
79 setPriority(priority);
80 }
81
82 @NotNull
83 public String getType() {
84 return super.get(Task.TYPE_KEY).toString();
85 }
86
87 @NotNull
88 public String getDescription() {
89 return super.get(Task.DESCRIPTION_KEY).toString();
90 }
91
92 @NotNull
93 public Trigger.TriggerState getState() {
94 return (Trigger.TriggerState) super.get(Task.STATE_KEY);
95 }
96
97 public void setState(Trigger.TriggerState state) {
98 if (null == state) {
99 state = Trigger.TriggerState.NONE;
100 }
101 super.put(Task.STATE_KEY, state);
102 }
103
104
105
106
107
108
109
110 public void setPriority(int priority) {
111 if (priority < 0) {
112 priority = 0;
113 }
114 super.put(Task.PRIORITY_KEY, priority);
115 }
116
117 public int getPriority() {
118 return (int) super.get(Task.PRIORITY_KEY);
119 }
120 }