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