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
27 public class BatchJobUtil {
28
29 public static final DateFormat FORMAT = new SimpleDateFormat("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, Date jobDate) {
44 return jobClass.getSimpleName() + "-Trigger-" + "date=" + FORMAT.format(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 }