View Javadoc
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.util.security.ContextUtils;
15  import org.kuali.student.r2.core.organization.dto.OrgInfo;
16  import org.kuali.student.r2.core.organization.dto.OrgOrgRelationInfo;
17  import org.kuali.student.r2.core.organization.service.OrganizationService;
18  import org.kuali.student.lum.workflow.node.OrganizationDynamicNode;
19  import org.slf4j.Logger;
20  import org.slf4j.LoggerFactory;
21  
22  /**
23   * A qualifier resolver class that is used by the hierarchy routing node {@link OrganizationDynamicNode}.
24   *
25   * This qualifier resolver will get the organization id value from inside the current route node instance and use the
26   * {@link OrganizationService#getOrgOrgRelationsByOrg(String)} method to find all relations to it. From those relations
27   * this class will select the ones that are both active and of the relation type matching
28   * {@link AbstractOrganizationServiceQualifierResolver.KUALI_ORG_TYPE_CURRICULUM_PARENT}. Once the list of those relations has been
29   * determined this qualifier resolver will select any of the organizations that match the above relation details but
30   * also only organizations that are of the type {@link AbstractOrganizationServiceQualifierResolver.KUALI_ORG_COC}. Those
31   * organizations will be returned as qualifications with the details being the organization id and the organization
32   * short name fields.
33   *
34   * If no relation is found that is both active and of the relation type matching
35   * {@link AbstractOrganizationServiceQualifierResolver.KUALI_ORG_TYPE_CURRICULUM_PARENT} then this class will use the organization
36   * found on the current route node instance as the qualification returned.
37   *
38   * @deprecated - this was written as a test case that was never implemented (see also {@link OrganizationDynamicNode})
39   */
40  @Deprecated
41  public class OrganizationCurriculumCommitteeQualifierResolver extends AbstractOrganizationServiceQualifierResolver {
42      protected static final Logger LOG = LoggerFactory.getLogger(OrganizationCurriculumCommitteeQualifierResolver.class);
43  
44      @Override
45      public List<Map<String,String>> resolve(RouteContext routeContext) {
46          // get the organization id from the current route node instance and error out if not found
47          String orgIdValue = routeContext.getNodeInstance().getNodeState(OrganizationDynamicNode.NODE_STATE_ORG_ID_KEY).getValue();
48          if (StringUtils.isBlank(orgIdValue)) {
49              throw new RuntimeException("Cannot find valid organization ID in Route Node Instance Node States");
50          }
51          LOG.debug("orgIdValue = '{}'", orgIdValue);
52  
53          try {
54              List<Map<String,String>> attributeSets = new ArrayList<Map<String,String>>();
55              // find the OrgOrgRelationInfo objects associated with the org from the route node instance
56              List<OrgOrgRelationInfo> orgRelationInfos = getOrganizationService().getOrgOrgRelationsByOrg(orgIdValue, ContextUtils.getContextInfo());
57              for (OrgOrgRelationInfo orgOrgRelationInfo : orgRelationInfos) {
58                  // check that the relationship is active
59                  if (StringUtils.equals("Active", orgOrgRelationInfo.getStateKey())) {
60                      // check for the proper relationship type
61                      if (StringUtils.equals(AbstractOrganizationServiceQualifierResolver.KUALI_ORG_TYPE_CURRICULUM_PARENT, orgOrgRelationInfo.getTypeKey())) {
62                          OrgInfo nextNodeOrgInfo = getOrganization(orgOrgRelationInfo.getRelatedOrgId());
63                          // check the org type of the related org is the proper org type
64                          if (StringUtils.equals(AbstractOrganizationServiceQualifierResolver.KUALI_ORG_COC, nextNodeOrgInfo.getTypeKey())) {
65                              LOG.debug("---- Related Org Relation: {} - {} ({})", nextNodeOrgInfo.getId(), nextNodeOrgInfo.getShortName(), nextNodeOrgInfo.getLongName());
66                              Map<String,String> attributeSet = new LinkedHashMap<String,String>();
67                              attributeSet.put(KualiStudentKimAttributes.QUALIFICATION_ORG_ID, nextNodeOrgInfo.getId());
68                              attributeSets.add(attributeSet);
69                          }
70                      }
71                  }
72              }
73              // if no org is found then use the org on the route node instance
74              if (attributeSets.isEmpty()) {
75                  OrgInfo currentNodeOrg = getOrganization(orgIdValue);
76                  Map<String,String> attributeSet = new LinkedHashMap<String,String>();
77                  attributeSet.put(KualiStudentKimAttributes.QUALIFICATION_ORG_ID, currentNodeOrg.getId());
78                  attributeSets.add(attributeSet);
79              }
80              return attributeSets;
81          } catch (Exception e) {
82              LOG.error("Error getting organization(s) or organization relations", e);
83              throw new RuntimeException(e);
84          }
85      }
86  
87      protected OrgInfo getOrganization(String orgId) throws Exception {
88  //        try {
89          	OrgInfo orgInfo = getOrganizationService().getOrg(orgId, null);
90              return orgInfo;
91  //        } catch (DoesNotExistException e) {
92  //            LOG.error("No valid organization found for id '" + orgId + "'", e);
93  //            throw e;
94  //        }
95      }
96  
97  }