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.dto.OrgInfo;
25  import org.kuali.student.r2.core.organization.service.OrganizationService;
26  
27  import javax.xml.namespace.QName;
28  import java.util.HashMap;
29  import java.util.List;
30  import java.util.Map;
31  
32  /**
33   * @author Kuali Student Team
34   */
35  public class AdministeringOrgComponentBuilder implements ComponentBuilder<KSPropositionEditor> {
36  
37      private OrganizationService organizationService;
38  
39      @Override
40      public List<String> getComponentIds() {
41          return null;  //To change body of implemented methods use File | Settings | File Templates.
42      }
43  
44      @Override
45      public void resolveTermParameters(KSPropositionEditor propositionEditor, Map<String, String> termParameters) {
46          String orgId = termParameters.get(KSKRMSServiceConstants.TERM_PARAMETER_TYPE_ORGANIZATION_KEY);
47          if (orgId != null) {
48              try {
49                  OrgInfo orgInfo = this.getOrganizationService().getOrg(orgId, ContextUtils.getContextInfo());
50                  propositionEditor.setOrgInfo(orgInfo);
51              } catch (Exception e) {
52                  throw new RuntimeException("Could not load orgarnization", e);
53              }
54  
55          }
56      }
57  
58      @Override
59      public Map<String, String> buildTermParameters(KSPropositionEditor propositionEditor) {
60          Map<String, String> termParameters = new HashMap<String, String>();
61          if (propositionEditor.getOrgInfo() != null){
62              termParameters.put(KSKRMSServiceConstants.TERM_PARAMETER_TYPE_ORGANIZATION_KEY, propositionEditor.getOrgInfo().getId());
63          }
64          return termParameters;
65      }
66  
67      @Override
68      public void onSubmit(KSPropositionEditor propositionEditor) {
69          //To change body of implemented methods use File | Settings | File Templates.
70      }
71  
72      @Override
73      public void validate(KSPropositionEditor propositionEditor) {
74          //To change body of implemented methods use File | Settings | File Templates.
75      }
76  
77      protected OrganizationService getOrganizationService() {
78          if (organizationService == null) {
79              organizationService = (OrganizationService) GlobalResourceLoader.getService(new QName(OrganizationServiceConstants.NAMESPACE, OrganizationServiceConstants.SERVICE_NAME_LOCAL_PART));
80          }
81          return organizationService;
82      }
83  
84  }