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