View Javadoc

1   /**
2    * 
3    */
4   package org.kuali.student.lum.workflow.qualifierresolver;
5   
6   import java.util.ArrayList;
7   import java.util.List;
8   import java.util.Map;
9   
10  import org.apache.commons.lang.StringUtils;
11  import org.kuali.rice.kew.engine.RouteContext;
12  import org.kuali.rice.kew.engine.node.RouteNodeUtils;
13  import org.kuali.student.r2.core.search.dto.SearchResultRowInfo;
14  
15  /**
16   * A QualifierResolver class that will use configuration elements from the Route Node xml configuration to get a list of
17   * organizations related to the organization(s) that are set in the document content xml for a particular document
18   * instance.
19   * 
20   * <p>
21   * A sample of the Route Node configuration:
22   * <p>
23   * 
24   * <pre>
25   * {@code
26   * <role name="Document Organization Review">
27   *   <activationType>P</activationType>
28   *   <qualifierResolverClass>org.kuali.student.lum.workflow.qualifierresolver.CocOrganizationQualifierResolver</qualifierResolverClass>
29   *   <useNonDerivedRoles>true</useNonDerivedRoles>
30   *   <organizationIdQualifierKey>orgId</organizationIdQualifierKey>
31   *   <organizationIdDocumentContentKey>orgId</organizationIdDocumentContentKey>
32   * </role>
33   * }
34   * </pre>
35   * 
36   * <p>
37   * A sample of the Document Content xml expected by default:
38   * <p>
39   * 
40   * <pre>
41   * {@code
42   * <info>
43   *   <orgId>1234</orgId>
44   *   <orgId>5678</orgId>
45   * </info>
46   * }
47   * </pre>
48   * 
49   */
50  public class CocOrganizationQualifierResolver extends AbstractOrganizationServiceQualifierResolver {
51  
52      protected static final String ROUTE_NODE_XML_ORG_ID_QUALIFIER_KEY = "organizationIdQualifierKey";
53      protected static final String ROUTE_NODE_XML_USE_NON_DERIVED_ROLES = "useNonDerivedRoles";
54  
55      public static final String KUALI_ORG_TYPE_CURRICULUM_PARENT = "kuali.org.CurriculumParent";
56      public static final String KUALI_ORG_HIERARCHY_CURRICULUM = "kuali.org.hierarchy.Curriculum";
57      public static final String KUALI_ORG_COC = "kuali.org.COC";
58  
59      /**
60       * @see org.kuali.rice.kew.role.QualifierResolver#resolve(org.kuali.rice.kew.engine.RouteContext)
61       */
62      @Override
63      public List<Map<String,String>> resolve(RouteContext context) {
64          List<Map<String,String>> attributeSets = new ArrayList<Map<String,String>>();
65          String orgIdKey = getNodeSpecificOrganizationIdAttributeSetKey(context);
66          for (String orgId : getOrganizationIdsFromDocumentContent(context)) {
67              List<SearchResultRowInfo> results = relatedOrgsFromOrgId(orgId, getOrganizationRelationTypeCode(), getRelatedOrganizationTypeCode());
68              attributeSets.addAll(attributeSetFromSearchResult(results, orgIdKey));
69          }
70          return attributeSets;
71      }
72  
73      public String getNodeSpecificOrganizationIdAttributeSetKey(RouteContext context) {
74          String organizationIdFieldKey = RouteNodeUtils.getValueOfCustomProperty(context.getNodeInstance().getRouteNode(), ROUTE_NODE_XML_ORG_ID_QUALIFIER_KEY);
75          if (StringUtils.isBlank(organizationIdFieldKey)) {
76              if (usesNonDerivedOrganizationRoles(context)) {
77                  throw new RuntimeException("Cannot find required XML element '" + ROUTE_NODE_XML_ORG_ID_QUALIFIER_KEY + "' on the Route Node XML configuration.");
78              }
79          }
80          return organizationIdFieldKey;
81      }
82      
83      public Boolean usesNonDerivedOrganizationRoles(RouteContext context) {
84          String useNonDerivedOrganizationRoles = RouteNodeUtils.getValueOfCustomProperty(context.getNodeInstance().getRouteNode(), ROUTE_NODE_XML_USE_NON_DERIVED_ROLES);
85          if (StringUtils.isNotBlank(useNonDerivedOrganizationRoles)) {
86              return Boolean.valueOf(useNonDerivedOrganizationRoles);
87          }
88          return true;
89      }
90  
91      protected String getOrganizationHierarchyTypeCode() {
92          return KUALI_ORG_HIERARCHY_CURRICULUM;
93      }
94  
95      protected String getOrganizationRelationTypeCode() {
96          return KUALI_ORG_TYPE_CURRICULUM_PARENT;
97      }
98  
99      protected String getRelatedOrganizationTypeCode() {
100         return KUALI_ORG_COC;
101     }
102 
103 }