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