View Javadoc

1   /**
2    * Copyright 2005-2013 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.student.core.krms.builder;
17  
18  import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
19  import org.kuali.rice.krms.builder.ComponentBuilder;
20  import org.kuali.student.core.krms.dto.KSPropositionEditor;
21  import org.kuali.student.r2.common.util.ContextUtils;
22  import org.kuali.student.r2.core.constants.KSKRMSServiceConstants;
23  import org.kuali.student.r2.core.constants.OrganizationServiceConstants;
24  import org.kuali.student.r2.core.organization.service.OrganizationService;
25  import org.kuali.student.r2.core.organization.dto.OrgInfo;
26  
27  import javax.xml.namespace.QName;
28  
29  import java.util.HashMap;
30  import java.util.List;
31  import java.util.Map;
32  
33  /**
34   * @author Kuali Student Team
35   */
36  public class OrganizationComponentBuilder implements ComponentBuilder<KSPropositionEditor> {
37  
38      private OrganizationService organizationService;
39  
40      @Override
41      public List<String> getComponentIds() {
42          return null;  //To change body of implemented methods use File | Settings | File Templates.
43      }
44  
45      @Override
46      public void resolveTermParameters(KSPropositionEditor propositionEditor, Map<String, String> termParameters) {
47          String orgId = termParameters.get(KSKRMSServiceConstants.TERM_PARAMETER_TYPE_ORGANIZATION_KEY);
48          if (orgId != null) {
49              try {
50                  OrgInfo orgInfo = this.getOrganizationService().getOrg(orgId, ContextUtils.getContextInfo());
51                  propositionEditor.setOrgInfo(orgInfo);
52              } catch (Exception e) {
53                  throw new RuntimeException("Could not load orgarnization", e);
54              }
55  
56          }
57      }
58  
59      @Override
60      public Map<String, String> buildTermParameters(KSPropositionEditor propositionEditor) {
61          Map<String, String> termParameters = new HashMap<String, String>();
62          if (propositionEditor.getOrgInfo() != null){
63              termParameters.put(KSKRMSServiceConstants.TERM_PARAMETER_TYPE_ORGANIZATION_KEY, propositionEditor.getOrgInfo().getId());
64          }
65          return termParameters;
66      }
67  
68      @Override
69      public void onSubmit(KSPropositionEditor propositionEditor) {
70          //To change body of implemented methods use File | Settings | File Templates.
71      }
72  
73      @Override
74      public void validate(KSPropositionEditor propositionEditor) {
75          //To change body of implemented methods use File | Settings | File Templates.
76      }
77  
78      protected OrganizationService getOrganizationService() {
79          if (organizationService == null) {
80              organizationService = (OrganizationService) GlobalResourceLoader.getService(new QName(OrganizationServiceConstants.NAMESPACE, OrganizationServiceConstants.SERVICE_NAME_LOCAL_PART));
81          }
82          return organizationService;
83      }
84  
85  }