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.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
35
36 public class OrganizationComponentBuilder implements ComponentBuilder<KSPropositionEditor> {
37
38 private OrganizationService organizationService;
39
40 @Override
41 public List<String> getComponentIds() {
42 return null;
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
71 }
72
73 @Override
74 public void validate(KSPropositionEditor propositionEditor) {
75
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 }