Coverage Report - org.kuali.student.lum.workflow.qualifierresolver.CocOrganizationQualifierResolver
 
Classes in this File Line Coverage Branch Coverage Complexity
CocOrganizationQualifierResolver
0%
0/27
0%
0/12
2.286
 
 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 org.apache.commons.lang.StringUtils;
 10  
 import org.kuali.rice.kew.engine.RouteContext;
 11  
 import org.kuali.rice.kew.engine.node.RouteNodeUtils;
 12  
 import org.kuali.rice.kim.bo.types.dto.AttributeSet;
 13  
 import org.kuali.student.core.search.dto.SearchResultRow;
 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  
  *   <organizationShortNameQualifierKey>orgId</organizationShortNameQualifierKey>
 32  
  *   <organizationIdDocumentContentKey>orgId</organizationIdDocumentContentKey>
 33  
  * </role>
 34  
  * }
 35  
  * </pre>
 36  
  * 
 37  
  * <p>
 38  
  * A sample of the Document Content xml expected by default:
 39  
  * <p>
 40  
  * 
 41  
  * <pre>
 42  
  * {@code
 43  
  * <info>
 44  
  *   <orgId>1234</orgId>
 45  
  *   <orgId>5678</orgId>
 46  
  * </info>
 47  
  * }
 48  
  * </pre>
 49  
  * 
 50  
  */
 51  0
 public class CocOrganizationQualifierResolver extends AbstractOrganizationServiceQualifierResolver {
 52  0
     private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(CocOrganizationQualifierResolver.class);
 53  
 
 54  
     protected static final String ROUTE_NODE_XML_ORG_ID_QUALIFIER_KEY = "organizationIdQualifierKey";
 55  
     protected static final String ROUTE_NODE_XML_ORG_SHORT_NAME_QUALIFIER_KEY = "organizationShortNameQualifierKey";
 56  
     protected static final String ROUTE_NODE_XML_USE_NON_DERIVED_ROLES = "useNonDerivedRoles";
 57  
 
 58  
     public static final String KUALI_ORG_TYPE_CURRICULUM_PARENT = "kuali.org.CurriculumParent";
 59  
     public static final String KUALI_ORG_HIERARCHY_CURRICULUM = "kuali.org.hierarchy.Curriculum";
 60  
     public static final String KUALI_ORG_COC = "kuali.org.COC";
 61  
 
 62  
     /**
 63  
      * @see org.kuali.rice.kew.role.QualifierResolver#resolve(org.kuali.rice.kew.engine.RouteContext)
 64  
      */
 65  
     @Override
 66  
     public List<AttributeSet> resolve(RouteContext context) {
 67  0
         List<AttributeSet> attributeSets = new ArrayList<AttributeSet>();
 68  0
         String orgShortNameKey = getNodeSpecificOrganizationShortNameAttributeSetKey(context);
 69  0
         String orgIdKey = getNodeSpecificOrganizationIdAttributeSetKey(context);
 70  0
         for (String orgId : getOrganizationIdsFromDocumentContent(context)) {
 71  0
             List<SearchResultRow> results = relatedOrgsFromOrgId(orgId, getOrganizationRelationTypeCode(), getRelatedOrganizationTypeCode());
 72  0
             attributeSets.addAll(attributeSetFromSearchResult(results, orgShortNameKey, orgIdKey));
 73  0
         }
 74  0
         return attributeSets;
 75  
     }
 76  
 
 77  
     public String getNodeSpecificOrganizationIdAttributeSetKey(RouteContext context) {
 78  0
         String organizationIdFieldKey = RouteNodeUtils.getValueOfCustomProperty(context.getNodeInstance().getRouteNode(), ROUTE_NODE_XML_ORG_ID_QUALIFIER_KEY);
 79  0
         if (StringUtils.isBlank(organizationIdFieldKey)) {
 80  0
             if (usesNonDerivedOrganizationRoles(context)) {
 81  0
                 throw new RuntimeException("Cannot find required XML element '" + ROUTE_NODE_XML_ORG_ID_QUALIFIER_KEY + "' on the Route Node XML configuration.");
 82  
             }
 83  
         }
 84  0
         return organizationIdFieldKey;
 85  
     }
 86  
 
 87  
     public String getNodeSpecificOrganizationShortNameAttributeSetKey(RouteContext context) {
 88  0
         String organizationShortNameFieldKey = RouteNodeUtils.getValueOfCustomProperty(context.getNodeInstance().getRouteNode(), ROUTE_NODE_XML_ORG_SHORT_NAME_QUALIFIER_KEY);
 89  0
         if (StringUtils.isBlank(organizationShortNameFieldKey)) {
 90  0
             if (usesNonDerivedOrganizationRoles(context)) {
 91  0
                 throw new RuntimeException("Cannot find required XML element '" + ROUTE_NODE_XML_ORG_SHORT_NAME_QUALIFIER_KEY + "' on the Route Node XML configuration.");
 92  
             }
 93  
         }
 94  0
         return organizationShortNameFieldKey;
 95  
     }
 96  
 
 97  
     public Boolean usesNonDerivedOrganizationRoles(RouteContext context) {
 98  0
         String useNonDerivedOrganizationRoles = RouteNodeUtils.getValueOfCustomProperty(context.getNodeInstance().getRouteNode(), ROUTE_NODE_XML_USE_NON_DERIVED_ROLES);
 99  0
         if (StringUtils.isNotBlank(useNonDerivedOrganizationRoles)) {
 100  0
             return Boolean.valueOf(useNonDerivedOrganizationRoles);
 101  
         }
 102  0
         return true;
 103  
     }
 104  
 
 105  
     protected String getOrganizationHierarchyTypeCode() {
 106  0
         return KUALI_ORG_HIERARCHY_CURRICULUM;
 107  
     }
 108  
 
 109  
     protected String getOrganizationRelationTypeCode() {
 110  0
         return KUALI_ORG_TYPE_CURRICULUM_PARENT;
 111  
     }
 112  
 
 113  
     protected String getRelatedOrganizationTypeCode() {
 114  0
         return KUALI_ORG_COC;
 115  
     }
 116  
 
 117  
 }