1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.kpme.core.batch;
17
18 import java.util.ArrayList;
19 import java.util.List;
20 import java.util.Map;
21
22 import org.apache.commons.lang.StringUtils;
23 import org.joda.time.DateTime;
24 import org.joda.time.format.DateTimeFormat;
25 import org.joda.time.format.DateTimeFormatter;
26
27 public class BatchJobUtil {
28
29 public static final DateTimeFormatter FORMAT = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
30
31 public static String getJobGroupName(Class<?> jobClass, Map<String, String> jobGroupDataMap) {
32 return jobClass.getSimpleName() + "-JobGroup-" + getDataMapString(jobGroupDataMap);
33 }
34
35 public static String getJobName(Class<?> jobClass, Map<String, String> jobDataMap) {
36 return jobClass.getSimpleName() + "-Job-" + getDataMapString(jobDataMap);
37 }
38
39 public static String getTriggerGroupName(Class<?> jobClass, Map<String, String> triggerDataMap) {
40 return jobClass.getSimpleName() + "-TriggerGroup-" + getDataMapString(triggerDataMap);
41 }
42
43 public static String getTriggerName(Class<?> jobClass, DateTime jobDate) {
44 return jobClass.getSimpleName() + "-Trigger-" + "date=" + FORMAT.print(jobDate);
45 }
46
47 private static String getDataMapString(Map<String, String> dataMap) {
48 List<String> dataMapPairs = new ArrayList<String>();
49 for (Map.Entry<String, String> dataMapEntry : dataMap.entrySet()) {
50 dataMapPairs.add(dataMapEntry.getKey() + "=" + dataMapEntry.getValue());
51 }
52 return StringUtils.join(dataMapPairs, "&");
53 }
54
55 }