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.enrollment.class2.courseoffering.krms.naturallanguage.context;
17  
18  import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
19  import org.kuali.student.r2.common.constants.CommonServiceConstants;
20  import org.kuali.student.r2.core.krms.naturallanguage.TermParameterTypes;
21  import org.kuali.student.r2.common.dto.ContextInfo;
22  import org.kuali.student.r2.core.organization.dto.OrgInfo;
23  import org.kuali.student.r2.core.organization.service.OrganizationService;
24  
25  import javax.xml.namespace.QName;
26  import java.util.Map;
27  import org.kuali.rice.core.api.exception.RiceIllegalStateException;
28  import org.kuali.student.common.util.security.ContextUtils;
29  
30  
31  /**
32   * This class creates the template context for an organization.
33   */
34  public class OrganizationContextImpl extends BasicContextImpl {
35  
36  	private OrganizationService organizationService;
37  
38  	public final static String ORG_TOKEN = "org";
39  
40  	public void setOrganizationService(OrganizationService organizationService) {
41  		this.organizationService = organizationService;
42  	}
43      private OrganizationService getOrganizationService() {
44          if (organizationService == null) {
45              organizationService = (OrganizationService) GlobalResourceLoader.getService(new QName(CommonServiceConstants.REF_OBJECT_URI_GLOBAL_PREFIX + "organization", "OrganizationService"));
46  
47          }
48          return organizationService;
49  
50      }
51  
52  
53  	private OrgInfo getOrganization(String orgId, ContextInfo context)  {
54  		if (orgId == null) {
55  			return null;
56  		}
57  		try {
58  
59  			return this.getOrganizationService().getOrg(orgId, context);
60  		} catch (Exception e) {
61                      throw new RiceIllegalStateException (e);
62  		}
63  	}
64  
65      /**
66       * Creates the context map (template data) for the requirement component.
67       *
68       * @param parameters
69       * @throws org.kuali.student.r2.common.exceptions.OperationFailedException Creating context map fails
70       */
71      @Override
72      public Map<String, Object> createContextMap(Map<String, Object> parameters) {
73          ContextInfo contextInfo = ContextUtils.createDefaultContextInfo();
74          Map<String, Object> contextMap = super.createContextMap(parameters);
75  
76          String orgId = (String) parameters.get(TermParameterTypes.ORGANIZATION_KEY.getId());
77          OrgInfo org = getOrganization(orgId, contextInfo);
78          if( org != null){
79              contextMap.put(ORG_TOKEN, org);
80          }
81  
82          return contextMap;
83      }
84  }