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 java.util.Map;
19  
20  import org.kuali.student.r2.lum.statement.config.context.util.NLHelper;
21  import org.kuali.student.r2.common.exceptions.OperationFailedException;
22  import org.kuali.student.r1.core.statement.dto.ReqComponentInfo;
23  import org.kuali.student.r1.core.statement.naturallanguage.AbstractContext;
24  import org.kuali.student.r1.lum.statement.typekey.ReqComponentFieldTypes;
25  import org.kuali.student.r2.common.dto.ContextInfo;
26  
27  public class BasicContextImpl extends AbstractContext<ReqComponentInfo> {
28  	/**
29  	 * <code>NLHelper</code> token (key) references a static natural language
30  	 * helper class for use in templates.
31  	 * e.g. '$NLHelper.getProperGrammer($intValue, "course", "courses")'
32  	 */
33  	public final static String NL_HELPER_TOKEN = "NLHelper";
34  	/**
35  	 * Relational operator token.
36  	 */
37  	public final static String OPERATOR_TOKEN = "relationalOperator";
38  	/**
39  	 * An integer value token.
40  	 */
41  	public final static String INTEGER_VALUE_TOKEN = "intValue";
42  
43  	/**
44  	 * Constructor.
45  	 */
46  	public BasicContextImpl() {
47  	}
48  	
49      /**
50       * Creates the context map (template data) for the requirement component.
51       * Also, adds the field token map to the context map.
52       *
53       *
54       *
55       * @param reqComponent Requirement component
56       * @param contextInfo
57       * @throws OperationFailedException Creating context map fails
58       */
59      public Map<String, Object> createContextMap(ReqComponentInfo reqComponent, ContextInfo contextInfo) throws OperationFailedException {
60      	String value = getReqComponentFieldValue(reqComponent, ReqComponentFieldTypes.INTEGER_VALUE1_KEY.getId());
61      	String operator = getReqComponentFieldValue(reqComponent, ReqComponentFieldTypes.OPERATOR_KEY.getId());
62      	
63      	Map<String, Object> contextMap = super.createContextMap(reqComponent,contextInfo);
64          contextMap.put(NL_HELPER_TOKEN, NLHelper.class);
65  		if(operator != null) {
66  	        contextMap.put(OPERATOR_TOKEN, operator);
67  		}
68  		if(value != null) {
69  			contextMap.put(INTEGER_VALUE_TOKEN, Integer.valueOf(value));
70  		}
71  
72          return contextMap;
73      }
74  }