001 /** 002 * Copyright 2004-2013 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 package org.kuali.hr.time.batch; 017 018 import java.text.DateFormat; 019 import java.text.SimpleDateFormat; 020 import java.util.ArrayList; 021 import java.util.Date; 022 import java.util.List; 023 import java.util.Map; 024 025 import org.apache.commons.lang.StringUtils; 026 027 public class BatchJobUtil { 028 029 public static final DateFormat FORMAT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ"); 030 031 public static String getJobGroupName(Class<?> jobClass, Map<String, String> jobGroupDataMap) { 032 return jobClass.getSimpleName() + "-JobGroup-" + getDataMapString(jobGroupDataMap); 033 } 034 035 public static String getJobName(Class<?> jobClass, Map<String, String> jobDataMap) { 036 return jobClass.getSimpleName() + "-Job-" + getDataMapString(jobDataMap); 037 } 038 039 public static String getTriggerGroupName(Class<?> jobClass, Map<String, String> triggerDataMap) { 040 return jobClass.getSimpleName() + "-TriggerGroup-" + getDataMapString(triggerDataMap); 041 } 042 043 public static String getTriggerName(Class<?> jobClass, Date jobDate) { 044 return jobClass.getSimpleName() + "-Trigger-" + "date=" + FORMAT.format(jobDate); 045 } 046 047 private static String getDataMapString(Map<String, String> dataMap) { 048 List<String> dataMapPairs = new ArrayList<String>(); 049 for (Map.Entry<String, String> dataMapEntry : dataMap.entrySet()) { 050 dataMapPairs.add(dataMapEntry.getKey() + "=" + dataMapEntry.getValue()); 051 } 052 return StringUtils.join(dataMapPairs, "&"); 053 } 054 055 }