View Javadoc

1   /**
2    * Copyright 2012 The Kuali Foundation Licensed under the
3    * Educational Community License, Version 2.0 (the "License"); you may
4    * not use this file except in compliance with the License. You may
5    * obtain a copy of the License at
6    *
7    * http://www.osedu.org/licenses/ECL-2.0
8    *
9    * Unless required by applicable law or agreed to in writing,
10   * software distributed under the License is distributed on an "AS IS"
11   * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12   * or implied. See the License for the specific language governing
13   * permissions and limitations under the License.
14   *
15   */
16  package org.kuali.student.enrollment.class2.acal.service.impl;
17  
18  import org.apache.commons.httpclient.util.DateUtil;
19  import org.kuali.student.enrollment.acal.dto.TermInfo;
20  import org.kuali.student.enrollment.class2.acal.service.TermCodeGenerator;
21  import org.kuali.student.r2.core.constants.AtpServiceConstants;
22  
23  import java.util.Collections;
24  import java.util.HashMap;
25  import java.util.Map;
26  
27  /**
28   * This class //TODO ...
29   *
30   * @author Kuali Student Team
31   */
32  public class TermCodeGeneratorImpl implements TermCodeGenerator {
33      private static final String YEAR_ONLY_FORMAT_STRING = "yyyy";
34  
35      private static Map<String, Integer> termTypeCodeMap;
36  
37      static {
38          Map<String, Integer> map = new HashMap<String, Integer>(4);
39  
40          map.put(AtpServiceConstants.ATP_WINTER_TYPE_KEY, 1);
41          map.put(AtpServiceConstants.ATP_SPRING_TYPE_KEY, 2);
42          map.put(AtpServiceConstants.ATP_SUMMER_TYPE_KEY, 3);
43          map.put(AtpServiceConstants.ATP_FALL_TYPE_KEY, 4);
44  
45          termTypeCodeMap = Collections.unmodifiableMap(map);
46      }
47  
48      @Override
49      public String generateTermCode(TermInfo term) {
50          // if the term is not of a type that is handled by the defined formula, return null, since the value for the atp code is undefined at that point
51          if(!termTypeCodeMap.containsKey(term.getTypeKey())) {
52              return null;
53          }
54  
55          StringBuilder result = new StringBuilder(DateUtil.formatDate(term.getStartDate(), YEAR_ONLY_FORMAT_STRING));
56  
57          result.append(termTypeCodeMap.get(term.getTypeKey()).toString());
58  
59          return result.toString();
60      }
61  }