View Javadoc

1   /**
2    * Copyright 2004-2013 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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  }