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 public TMJobDataMap(@NotNull String type, @NotNull String description) {
41 this(type, description, Trigger.TriggerState.NONE);
42 }
43
44
45
46
47
48
49
50
51 public TMJobDataMap(@NotNull String type, @NotNull String description, @NotNull Trigger.TriggerState state) {
52 this(type, description, state, Trigger.DEFAULT_PRIORITY);
53 }
54
55
56
57
58
59
60
61
62
63 public TMJobDataMap(
64 @NotNull String type, @NotNull String description, @NotNull Trigger.TriggerState state, int priority) {
65 super();
66
67 Assert.notNull(type, "type must not be null");
68 Assert.doesNotContain(type, "null", "type must not be null");
69 Assert.notNull(description, "description must not be null");
70 Assert.notNull(state, "state must not be null");
71 super.put(Task.TYPE_KEY, type);
72 super.put(Task.DESCRIPTION_KEY, description);
73 super.put(Task.STATE_KEY, state);
74 setPriority(priority);
75 }
76
77 @NotNull public String getType() {
78 return super.get(Task.TYPE_KEY).toString();
79 }
80
81 @NotNull public String getDescription() {
82 return super.get(Task.DESCRIPTION_KEY).toString();
83 }
84
85 @NotNull public Trigger.TriggerState getState() {
86 return (Trigger.TriggerState) super.get(Task.STATE_KEY);
87 }
88
89 public void setState(Trigger.TriggerState state) {
90 if (null == state) {
91 state = Trigger.TriggerState.NONE;
92 }
93 super.put(Task.STATE_KEY, state);
94 }
95
96
97
98
99
100
101 public void setPriority(int priority) {
102 if (priority < 0) {
103 priority = 0;
104 }
105 super.put(Task.PRIORITY_KEY, priority);
106 }
107
108 public int getPriority() {
109 return (int) super.get(Task.PRIORITY_KEY);
110 }
111 }