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.lum.lu.ui.krms.builder;
17  
18  import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
19  import org.kuali.rice.krms.builder.ComponentBuilder;
20  import org.kuali.rice.krms.builder.ComponentBuilderUtils;
21  import org.kuali.rice.krms.util.PropositionTreeUtil;
22  import org.kuali.student.lum.lu.ui.krms.dto.CluInformation;
23  import org.kuali.student.lum.lu.ui.krms.dto.LUPropositionEditor;
24  import org.kuali.student.lum.lu.ui.krms.dto.ProgramCluSetInformation;
25  import org.kuali.student.r2.common.util.ContextUtils;
26  import org.kuali.student.r2.core.constants.KSKRMSServiceConstants;
27  import org.kuali.student.r2.core.constants.OrganizationServiceConstants;
28  import org.kuali.student.r2.core.organization.dto.OrgInfo;
29  import org.kuali.student.r2.core.organization.service.OrganizationService;
30  import org.kuali.student.r2.core.versionmanagement.dto.VersionDisplayInfo;
31  import org.kuali.student.r2.lum.clu.dto.CluInfo;
32  import org.kuali.student.r2.lum.clu.dto.CluResultInfo;
33  import org.kuali.student.r2.lum.clu.dto.CluSetInfo;
34  import org.kuali.student.r2.lum.clu.dto.ResultOptionInfo;
35  import org.kuali.student.r2.lum.clu.service.CluService;
36  import org.kuali.student.r2.lum.lrc.dto.ResultValuesGroupInfo;
37  import org.kuali.student.r2.lum.lrc.service.LRCService;
38  import org.kuali.student.r2.lum.util.constants.CluServiceConstants;
39  import org.kuali.student.r2.lum.util.constants.LrcServiceConstants;
40  
41  import javax.xml.namespace.QName;
42  import java.util.ArrayList;
43  import java.util.Collections;
44  import java.util.Date;
45  import java.util.HashMap;
46  import java.util.List;
47  import java.util.Map;
48  
49  /**
50   * @author Kuali Student Team
51   */
52  public class ProgramWithOrgDurationComponentBuilder extends ProgramComponentBuilder {
53  
54      private OrganizationService organizationService;
55      @Override
56      public List<String> getComponentIds() {
57          return null;
58      }
59  
60      @Override
61      public void resolveTermParameters(LUPropositionEditor propositionEditor, Map<String, String> termParameters) {
62          super.resolveTermParameters(propositionEditor,termParameters);
63          String orgId = termParameters.get(KSKRMSServiceConstants.TERM_PARAMETER_TYPE_ORGANIZATION_KEY);
64          String durationType = termParameters.get(KSKRMSServiceConstants.TERM_PARAMETER_TYPE_DURATION_TYPE_KEY);
65          String duration = termParameters.get(KSKRMSServiceConstants.TERM_PARAMETER_TYPE_DURATION_KEY);
66          if (durationType != null) {
67              propositionEditor.setDurationType(durationType);
68          }
69          if (duration != null) {
70              propositionEditor.setDuration(Integer.parseInt(duration));
71          }
72          if (orgId != null) {
73              try {
74                  OrgInfo orgInfo = this.getOrganizationService().getOrg(orgId, ContextUtils.getContextInfo());
75                  propositionEditor.setOrgInfo(orgInfo);
76              } catch (Exception e) {
77                  throw new RuntimeException(e);
78              }
79  
80          }
81  
82      }
83  
84      @Override
85      public Map<String, String> buildTermParameters(LUPropositionEditor propositionEditor) {
86          Map<String, String> termParameters = new HashMap<String, String>();
87          termParameters = super.buildTermParameters(propositionEditor);
88          termParameters.put(KSKRMSServiceConstants.TERM_PARAMETER_TYPE_DURATION_TYPE_KEY, propositionEditor.getDurationType());
89          termParameters.put(KSKRMSServiceConstants.TERM_PARAMETER_TYPE_DURATION_KEY, propositionEditor.getDuration().toString());
90          if (propositionEditor.getOrgInfo() != null){
91              termParameters.put(KSKRMSServiceConstants.TERM_PARAMETER_TYPE_ORGANIZATION_KEY, propositionEditor.getOrgInfo().getId());
92          }
93          return termParameters;
94  
95  
96      }
97  
98      @Override
99      public void onSubmit(LUPropositionEditor propositionEditor) {
100         super.onSubmit(propositionEditor);
101     }
102 
103     @Override
104     public void validate(LUPropositionEditor propositionEditor) {
105         super.validate(propositionEditor);
106     }
107     protected OrganizationService getOrganizationService() {
108         if (organizationService == null) {
109             organizationService = (OrganizationService) GlobalResourceLoader.getService(new QName(OrganizationServiceConstants.NAMESPACE, OrganizationServiceConstants.SERVICE_NAME_LOCAL_PART));
110         }
111         return organizationService;
112     }
113 }