View Javadoc

1   /**
2    * Copyright 2010 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.r2.lum.statement.config.context;
17  
18  import org.kuali.student.r1.core.statement.dto.ReqComponentInfo;
19  import org.kuali.student.r1.lum.statement.typekey.ReqComponentFieldTypes;
20  import org.kuali.student.r2.common.dto.ContextInfo;
21  import org.kuali.student.r2.common.exceptions.OperationFailedException;
22  import org.kuali.student.r2.common.util.ContextUtils;
23  import org.kuali.student.r2.core.atp.service.AtpService;
24  import org.kuali.student.r2.core.class1.type.dto.TypeInfo;
25  import org.kuali.student.r2.core.class1.type.service.TypeService;
26  
27  import java.util.Map;
28  
29  
30  /**
31   * This class creates the template context for an academic time period.
32   */
33  public class AtpContextImpl extends BasicContextImpl {
34  
35  
36      private AtpService atpService;
37      private TypeService typeService;
38  	
39  	public final static String DURATION_TYPE_TOKEN = "durationType";
40  	public final static String DURATION_TOKEN = "duration";
41  
42  	public void setAtpService(AtpService atpService) {
43  		this.atpService = atpService;
44  	}
45  
46  
47      public TypeService getTypeService() {
48          return typeService;
49      }
50  
51      public void setTypeService(TypeService typeService) {
52          this.typeService = typeService;
53      }
54  
55  	private TypeInfo getAtpDurationType(String atpDurationTypeKey) throws OperationFailedException {
56  		if (atpDurationTypeKey == null) {
57  			return null;
58  		}
59  		try {
60  			TypeInfo atpDurationType = this.getTypeService().getType(atpDurationTypeKey, ContextUtils.getContextInfo());
61  			return atpDurationType;
62  		} catch (Exception e) {
63  			throw new OperationFailedException(e.getMessage(), e);
64  		}
65  	}
66  	
67      /**
68       * Creates the context map (template data) for the requirement component.
69       * 
70       *
71       *
72       * @param reqComponent Requirement component
73       * @param contextInfo
74       * @throws OperationFailedException Creating context map fails
75       */
76      public Map<String, Object> createContextMap(ReqComponentInfo reqComponent, ContextInfo contextInfo) throws OperationFailedException {
77          String durationTypeKey = getReqComponentFieldValue(reqComponent, ReqComponentFieldTypes.DURATION_TYPE_KEY.getId());
78          String duration = getReqComponentFieldValue(reqComponent, ReqComponentFieldTypes.DURATION_KEY.getId());
79          TypeInfo atpDurationType = getAtpDurationType(durationTypeKey);
80  
81          Map<String, Object> contextMap = super.createContextMap(reqComponent, contextInfo);
82          contextMap.put(DURATION_TYPE_TOKEN, atpDurationType);
83          contextMap.put(DURATION_TOKEN, duration);
84          return contextMap;
85      }
86  }