1
2
3
4
5
6
7
8
9
10
11
12
13
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
29
30
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
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 }