1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
34
35 public class AdministeringOrgComponentBuilder implements ComponentBuilder<KSPropositionEditor> {
36
37 private OrganizationService organizationService;
38
39 @Override
40 public List<String> getComponentIds() {
41 return null;
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
70 }
71
72 @Override
73 public void validate(KSPropositionEditor propositionEditor) {
74
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 }