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) map.get("type"), (String) map.get("description"));
25 this.putAll(map);
26
27 this.setPriority((Integer) map.getOrDefault("priority", Trigger.DEFAULT_PRIORITY));
28 }
29
30
31
32
33
34
35
36
37 public TMJobDataMap(@NotNull String type, @NotNull String description) {
38 this(type, description, Trigger.TriggerState.NONE);
39 }
40
41
42
43
44
45
46
47
48 public TMJobDataMap(
49 @NotNull String type, @NotNull String description, @NotNull Trigger.TriggerState status) {
50 this(type, description, status, Trigger.DEFAULT_PRIORITY);
51 }
52
53
54
55
56
57
58
59
60
61 public TMJobDataMap(
62 @NotNull String type,
63 @NotNull String description,
64 @NotNull Trigger.TriggerState status,
65 int priority) {
66 super();
67
68 Assert.notNull(type, "type must not be null");
69 Assert.notNull(description, "description must not be null");
70 Assert.notNull(status, "status must not be null");
71 super.put("type", type);
72 super.put("description", description);
73 super.put("status", status);
74 setPriority(priority);
75 }
76
77 @NotNull
78 public String getType() {
79 return super.get("type").toString();
80 }
81
82 @NotNull
83 public String getDescription() {
84 return super.get("description").toString();
85 }
86
87 @NotNull
88 public Trigger.TriggerState getStatus() {
89 return (Trigger.TriggerState) super.get("status");
90 }
91
92 public void setStatus(Trigger.TriggerState status) {
93 if (null == status) {
94 status = Trigger.TriggerState.NONE;
95 }
96 super.put("status", status);
97 }
98
99
100
101
102
103
104 public void setPriority(int priority) {
105 if (priority < 0) {
106 priority = 0;
107 }
108 super.put("priority", priority);
109 }
110
111 public int getPriority() {
112 return (int) super.get("priority");
113 }
114 }