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  
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  }