1
2
3
4 package org.kuali.student.lum.workflow.qualifierresolver;
5
6 import java.util.ArrayList;
7 import java.util.LinkedHashMap;
8 import java.util.List;
9 import java.util.Map;
10
11 import org.apache.commons.lang.StringUtils;
12 import org.kuali.rice.kew.engine.RouteContext;
13 import org.kuali.rice.student.bo.KualiStudentKimAttributes;
14 import org.kuali.student.r2.common.exceptions.DoesNotExistException;
15 import org.kuali.student.r2.common.util.ContextUtils;
16 import org.kuali.student.r2.core.organization.dto.OrgInfo;
17 import org.kuali.student.r2.core.organization.dto.OrgOrgRelationInfo;
18 import org.kuali.student.r2.core.organization.service.OrganizationService;
19 import org.kuali.student.lum.workflow.node.OrganizationDynamicNode;
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38 public class OrganizationCurriculumCommitteeQualifierResolver extends AbstractOrganizationServiceQualifierResolver {
39 protected static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(OrganizationCurriculumCommitteeQualifierResolver.class);
40
41 @Override
42 public List<Map<String,String>> resolve(RouteContext routeContext) {
43
44 String orgIdValue = routeContext.getNodeInstance().getNodeState(OrganizationDynamicNode.NODE_STATE_ORG_ID_KEY).getValue();
45 if (StringUtils.isBlank(orgIdValue)) {
46 throw new RuntimeException("Cannot find valid organization ID in Route Node Instance Node States");
47 }
48 if (LOG.isDebugEnabled()) {
49 LOG.debug("orgIdValue = '" + orgIdValue + "'");
50 }
51
52 try {
53 List<Map<String,String>> attributeSets = new ArrayList<Map<String,String>>();
54
55 List<OrgOrgRelationInfo> orgRelationInfos = getOrganizationService().getOrgOrgRelationsByOrg(orgIdValue, ContextUtils.getContextInfo());
56 for (OrgOrgRelationInfo orgOrgRelationInfo : orgRelationInfos) {
57
58 if (StringUtils.equals("Active", orgOrgRelationInfo.getStateKey())) {
59
60 if (StringUtils.equals(AbstractOrganizationServiceQualifierResolver.KUALI_ORG_TYPE_CURRICULUM_PARENT, orgOrgRelationInfo.getTypeKey())) {
61 OrgInfo nextNodeOrgInfo = getOrganization(orgOrgRelationInfo.getRelatedOrgId());
62
63 if (StringUtils.equals(AbstractOrganizationServiceQualifierResolver.KUALI_ORG_COC, nextNodeOrgInfo.getTypeKey())) {
64 if (LOG.isDebugEnabled()) {
65 LOG.debug("---- Related Org Relation: " + nextNodeOrgInfo.getId() + " - " + nextNodeOrgInfo.getShortName() + " (" + nextNodeOrgInfo.getLongName() + ")");
66 }
67 Map<String,String> attributeSet = new LinkedHashMap<String,String>();
68 attributeSet.put(KualiStudentKimAttributes.QUALIFICATION_ORG_ID, nextNodeOrgInfo.getId());
69 attributeSets.add(attributeSet);
70 }
71 }
72 }
73 }
74
75 if (attributeSets.isEmpty()) {
76 OrgInfo currentNodeOrg = getOrganization(orgIdValue);
77 Map<String,String> attributeSet = new LinkedHashMap<String,String>();
78 attributeSet.put(KualiStudentKimAttributes.QUALIFICATION_ORG_ID, currentNodeOrg.getId());
79 attributeSets.add(attributeSet);
80 }
81 return attributeSets;
82 } catch (Exception e) {
83 LOG.error("Error getting organization(s) or organization relations", e);
84 throw new RuntimeException(e);
85 }
86 }
87
88 protected OrgInfo getOrganization(String orgId) throws Exception {
89
90 OrgInfo orgInfo = getOrganizationService().getOrg(orgId, null);
91 return orgInfo;
92
93
94
95
96 }
97
98 }