• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

openmrs / openmrs-core / 23193642646

17 Mar 2026 12:13PM UTC coverage: 63.1% (-0.3%) from 63.429%
23193642646

push

github

rkorytkowski
Fixing: Fix an issue with the ModuleResourceServlet

0 of 2 new or added lines in 1 file covered. (0.0%)

925 existing lines in 17 files now uncovered.

23137 of 36667 relevant lines covered (63.1%)

0.63 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

32.31
/api/src/main/java/org/openmrs/scheduler/TaskDefinition.java
1
/**
2
 * This Source Code Form is subject to the terms of the Mozilla Public License,
3
 * v. 2.0. If a copy of the MPL was not distributed with this file, You can
4
 * obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under
5
 * the terms of the Healthcare Disclaimer located at http://openmrs.org/license.
6
 *
7
 * Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS
8
 * graphic logo is a trademark of OpenMRS Inc.
9
 */
10
package org.openmrs.scheduler;
11

12
import java.util.Date;
13
import java.util.HashMap;
14
import java.util.Map;
15

16
import com.fasterxml.jackson.annotation.JsonGetter;
17
import com.fasterxml.jackson.annotation.JsonIgnore;
18
import com.fasterxml.jackson.annotation.JsonSetter;
19
import org.hibernate.envers.Audited;
20
import org.hibernate.envers.NotAudited;
21
import org.openmrs.BaseChangeableOpenmrsMetadata;
22
import org.openmrs.User;
23
import org.slf4j.Logger;
24
import org.slf4j.LoggerFactory;
25

26
/**
27
 * Represents the metadata for a task that can be scheduled.
28
 * 
29
 * @deprecated since 2.9.x use {@link TaskData} instead.
30
 */
31
@Deprecated
32
@Audited
33
public class TaskDefinition extends BaseChangeableOpenmrsMetadata implements TaskData {
34
        
35
        private static final Logger log = LoggerFactory.getLogger(TaskDefinition.class);
1✔
36
        
37
        // Task metadata
38
        private Integer id;
39
        
40
        // This class must implement the schedulable interface or it will fail to start
41
        private String taskClass;
42
        
43
        private transient Task taskInstance = null;
1✔
44
        
45
        // Scheduling metadata
46
        private Date startTime;
47
        
48
        private Date lastExecutionTime;
49
        
50
        private Long repeatInterval = 0L; // NOW in seconds to give us ability to
1✔
51
        
52
        // support longer intervals (years, decades,
53
        // milleniums)
54
        
55
        private Boolean startOnStartup = false;
1✔
56
        
57
        private String startTimePattern;
58
        
59
        private Boolean started;
60
        
61
        // Relationships
62
        @NotAudited
63
        private Map<String, String> properties;
64
        
65
        /**
66
         * Default no-arg public constructor
67
         */
68
        public TaskDefinition() {
1✔
69
                this.started = Boolean.FALSE; // default
1✔
70
                this.startTime = new Date(); // makes it easier during task creation
1✔
71
                // as we have a default date populated
72
                this.properties = new HashMap<>();
1✔
73
        }
1✔
74
        
75
        /**
76
         * Public constructor
77
         */
78
        public TaskDefinition(Integer id, String name, String description, String taskClass) {
UNCOV
79
                this();
×
UNCOV
80
                log.debug("Creating taskconfig: " + id);
×
UNCOV
81
                this.id = id;
×
UNCOV
82
                setName(name);
×
UNCOV
83
                setDescription(description);
×
UNCOV
84
                this.taskClass = taskClass;
×
UNCOV
85
        }
×
86
        
87
        /**
88
         * Get the task identifier.
89
         * 
90
         * @return <code>Integer</code> identifier of the task
91
         */
92
        @Override
93
        public Integer getId() {
UNCOV
94
                return this.id;
×
95
        }
96
        
97
        /**
98
         * Set the task identifier.
99
         * 
100
         * @param id
101
         */
102
        @Override
103
        public void setId(Integer id) {
UNCOV
104
                this.id = id;
×
UNCOV
105
        }
×
106
        
107
        /**
108
         * Get the data map used to provide the task with runtime data.
109
         * 
110
         * @return the data map
111
         */
112
        @NotAudited
113
        public Map<String, String> getProperties() {
UNCOV
114
                return this.properties;
×
115
        }
116
        
117
        /**
118
         * Set the properties of the task. This overrides any properties previously set with the
119
         * setProperty(String, String) method.
120
         * 
121
         * @param properties <code>Map&lt;String, String&gt;</code> of the properties to set
122
         */
123
        public void setProperties(Map<String, String> properties) {
UNCOV
124
                this.properties = properties;
×
UNCOV
125
        }
×
126
        
127
        /**
128
         * Get the schedulable object to be executed.
129
         * 
130
         * @return the schedulable object
131
         */
132
        public String getTaskClass() {
133
                return this.taskClass;
1✔
134
        }
135
        
136
        /**
137
         * Set the schedulable object to be executed.
138
         * 
139
         * @param taskClass <code>String</code> taskClass of a schedulable object
140
         */
141
        public void setTaskClass(String taskClass) {
142
                this.taskClass = taskClass;
1✔
143
        }
1✔
144
        
145
        /**
146
         * Get the start time for when the task should be executed.
147
         * 
148
         * @return long start time
149
         */
150
        public Date getStartTime() {
151
                return startTime;
1✔
152
        }
153
        
154
        /**
155
         * Set the start time for when the task should be executed. For instance, use "new Date()", if
156
         * you want it to start now.
157
         * 
158
         * @param startTime start time for the task
159
         */
160
        public void setStartTime(Date startTime) {
161
                this.startTime = startTime;
1✔
162
        }
1✔
163
        
164
        /**
165
         * Get the time the task was last executed.
166
         * 
167
         * @return long last execution time
168
         */
169
        public Date getLastExecutionTime() {
UNCOV
170
                return lastExecutionTime;
×
171
        }
172
        
173
        /**
174
         * Set the time the task was last executed
175
         * 
176
         * @param lastExecutionTime last execution time
177
         */
178
        public void setLastExecutionTime(Date lastExecutionTime) {
UNCOV
179
                this.lastExecutionTime = lastExecutionTime;
×
UNCOV
180
        }
×
181
        
182
        /**
183
         * Gets the number of seconds until task is executed again.
184
         * 
185
         * @return long number of seconds.
186
         */
187
        public Long getRepeatInterval() {
188
                return repeatInterval;
1✔
189
        }
190
        
191
        /**
192
         * Sets the number of seconds until task is executed again.
193
         * 
194
         * @param repeatInterval number of seconds, or 0 to indicate to repetition
195
         */
196
        public void setRepeatInterval(Long repeatInterval) {
197
                this.repeatInterval = repeatInterval;
1✔
198
        }
1✔
199
        
200
        /**
201
         * Get the date format used to set the start time.
202
         */
203
        public String getStartTimePattern() {
204
                return this.startTimePattern;
1✔
205
        }
206
        
207
        /**
208
         * Sets the date format used to set the start time.
209
         */
210
        public void setStartTimePattern(String pattern) {
211
                this.startTimePattern = pattern;
1✔
212
        }
1✔
213
        
214
        /**
215
         * Gets the flag that indicates whether the task should startup as soon as the scheduler starts.
216
         */
217
        public Boolean getStartOnStartup() {
UNCOV
218
                return this.startOnStartup;
×
219
        }
220
        
221
        /**
222
         * Sets the flag that indicates whether the task should startup as soon as the scheduler starts.
223
         */
224
        public void setStartOnStartup(Boolean startOnStartup) {
UNCOV
225
                this.startOnStartup = startOnStartup;
×
UNCOV
226
        }
×
227
        
228
        /**
229
         * Gets the flag that indicates whether the task has been started.
230
         */
231
        public Boolean getStarted() {
UNCOV
232
                return this.started;
×
233
        }
234
        
235
        /**
236
         * Sets the flag that indicates whether the task has been started.
237
         */
238
        public void setStarted(Boolean started) {
UNCOV
239
                this.started = started;
×
UNCOV
240
        }
×
241
        
242
        /**
243
         * Get task configuration property.
244
         * 
245
         * @param key the <code>String</code> key of the property to get
246
         * @return the <code>String</code> value for the given key
247
         */
248
        public String getProperty(String key) {
UNCOV
249
                return this.properties.get(key);
×
250
        }
251
        
252
        /**
253
         * Set task configuration property. Only supports strings at the moment.
254
         * 
255
         * @param key the <code>String</code> key of the property to set
256
         * @param value the <code>String</code> value of the property to set
257
         */
258
        public void setProperty(String key, String value) {
UNCOV
259
                this.properties.put(key, value);
×
UNCOV
260
        }
×
261
        
262
        /**
263
         * Convenience method that asks SchedulerUtil for it's next execution time.
264
         * 
265
         * @return the <code>Date</code> of the next execution
266
         */
267
        public Date getNextExecutionTime() {
UNCOV
268
                return SchedulerUtil.getNextExecution(this);
×
269
        }
270
        
271
        /**
272
         * Convenience method to calculate the seconds until the next execution time.
273
         * 
274
         * @return the number of seconds until the next execution
275
         */
276
        public long getSecondsUntilNextExecutionTime() {
UNCOV
277
                return (getNextExecutionTime().getTime() - System.currentTimeMillis()) / 1000;
×
278
                
279
        }
280
        
281
        // ==================================   Metadata ============================
282
        
283
        /**
284
         * @see java.lang.Object#toString()
285
         */
286
        @Override
287
        public String toString() {
UNCOV
288
                return "[TaskDefinition " + " id=" + getId() + " name=" + getName() + " class=" + getTaskClass() + " startTime="
×
UNCOV
289
                        + getStartTime() + " repeatInterval=" + this.getRepeatInterval() + " secondsUntilNext="
×
UNCOV
290
                        + this.getSecondsUntilNextExecutionTime() + "]";
×
291
        }
292
        
293
        /**
294
         * Gets the runnable task instance associated with this definition.
295
         * 
296
         * @return related task, or null if none instantiated (definition hasn't been scheduled)
297
         */
298
        @JsonIgnore
299
        public Task getTaskInstance() {
UNCOV
300
                return taskInstance;
×
301
        }
302
        
303
        /**
304
         * Sets the runnable task instance associated with this definition. This should be set by the
305
         * scheduler which instantiates the task.
306
         * 
307
         * @param taskInstance
308
         */
309
        public void setTaskInstance(Task taskInstance) {
UNCOV
310
                this.taskInstance = taskInstance;
×
UNCOV
311
        }
×
312

313
        @Override
314
        @JsonIgnore
315
        public User getCreator() {
UNCOV
316
                return super.getCreator();
×
317
        }
318
        
319
        @JsonGetter
320
        public String getCreatorSystemId() {
UNCOV
321
                return super.getCreator().getSystemId();
×
322
        }
323

324
        @JsonSetter
325
        public void setCreatorSystemId(String systemId) {
UNCOV
326
                if (systemId != null) {
×
UNCOV
327
                        User creator = getCreator();
×
UNCOV
328
                        if (creator == null) {
×
UNCOV
329
                                creator = new User();
×
UNCOV
330
                                setCreator(creator);
×
331
                        }
UNCOV
332
                        creator.setSystemId(systemId);
×
333
                }
UNCOV
334
        }
×
335

336
        @Override
337
        @JsonIgnore
338
        public User getChangedBy() {
UNCOV
339
                return super.getChangedBy();
×
340
        }
341

342
        @Override
343
        @JsonIgnore
344
        public User getRetiredBy() {
UNCOV
345
                return super.getRetiredBy();
×
346
        }
347
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc