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    import org.joda.time.DateTime;
027    import org.joda.time.format.DateTimeFormat;
028    import org.joda.time.format.DateTimeFormatter;
029    
030    public class BatchJobUtil {
031            
032            public static final DateTimeFormatter FORMAT = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
033    
034            public static String getJobGroupName(Class<?> jobClass, Map<String, String> jobGroupDataMap) {
035                    return jobClass.getSimpleName() + "-JobGroup-" + getDataMapString(jobGroupDataMap);
036            }
037            
038            public static String getJobName(Class<?> jobClass, Map<String, String> jobDataMap) {
039                    return jobClass.getSimpleName() + "-Job-" + getDataMapString(jobDataMap);
040            }
041            
042            public static String getTriggerGroupName(Class<?> jobClass, Map<String, String> triggerDataMap) {
043            return jobClass.getSimpleName() + "-TriggerGroup-" + getDataMapString(triggerDataMap);
044            }
045            
046            public static String getTriggerName(Class<?> jobClass, Date jobDate) {
047                    return jobClass.getSimpleName() + "-Trigger-" + "date=" + FORMAT.print(new DateTime(jobDate));
048            }
049            
050            private static String getDataMapString(Map<String, String> dataMap) {
051                    List<String> dataMapPairs = new ArrayList<String>();
052                    for (Map.Entry<String, String> dataMapEntry : dataMap.entrySet()) {
053                            dataMapPairs.add(dataMapEntry.getKey() + "=" + dataMapEntry.getValue());
054                    }
055                    return StringUtils.join(dataMapPairs, "&");
056            }
057    
058    }