1 package org.kuali.student.lum.workflow.qualifierresolver; 2 3 import java.util.ArrayList; 4 import java.util.List; 5 6 import org.apache.commons.lang.StringUtils; 7 import org.kuali.rice.kew.engine.RouteContext; 8 import org.kuali.rice.kew.engine.node.RouteNodeUtils; 9 import org.kuali.rice.kim.bo.types.dto.AttributeSet; 10 import org.kuali.student.common.search.dto.SearchResultRow; 11 12 public class ParentOrganizationQualifierResolver extends 13 AbstractOrganizationServiceQualifierResolver { 14 protected static final String ROUTE_NODE_XML_ORG_ID_QUALIFIER_KEY = "organizationIdQualifierKey"; 15 protected static final String ROUTE_NODE_XML_USE_NON_DERIVED_ROLES = "useNonDerivedRoles"; 16 17 protected static final String ROUTE_NODE_XML_ORG_RELATION_TYPE = "organizationRelationType"; 18 protected static final String ROUTE_NODE_XML_RELATED_ORG_TYPE = "relatedOrganizationType"; 19 20 @Override 21 public List<AttributeSet> resolve(RouteContext context) { 22 List<AttributeSet> attributeSets = new ArrayList<AttributeSet>(); 23 24 String orgIdKey = getNodeSpecificOrganizationIdAttributeSetKey(context); 25 String orgRelationType = getOrganizationRelationTypeCode(context); 26 String relatedOrgType = getRelatedOrganizationTypeCode(context); 27 28 for (String orgId : getOrganizationIdsFromDocumentContent(context)) { 29 List<SearchResultRow> results = relatedOrgsFromOrgId(orgId, orgRelationType, relatedOrgType); 30 attributeSets.addAll(attributeSetFromSearchResult(results, orgIdKey)); 31 } 32 return attributeSets; 33 } 34 35 protected String getRelatedOrganizationTypeCode(RouteContext context) { 36 String relatedOrganizationType = RouteNodeUtils.getValueOfCustomProperty(context.getNodeInstance().getRouteNode(), ROUTE_NODE_XML_RELATED_ORG_TYPE); 37 if(StringUtils.isBlank(relatedOrganizationType)){ 38 throw new RuntimeException("Cannot find required XML element '" + ROUTE_NODE_XML_RELATED_ORG_TYPE + "' on the Route Node XML configuration."); 39 } 40 return relatedOrganizationType; 41 } 42 43 protected String getOrganizationRelationTypeCode(RouteContext context) { 44 String orgRelationType = RouteNodeUtils.getValueOfCustomProperty(context.getNodeInstance().getRouteNode(), ROUTE_NODE_XML_ORG_RELATION_TYPE); 45 if(StringUtils.isBlank(orgRelationType)){ 46 throw new RuntimeException("Cannot find required XML element '" + ROUTE_NODE_XML_ORG_RELATION_TYPE + "' on the Route Node XML configuration."); 47 } 48 return orgRelationType; 49 } 50 51 public String getNodeSpecificOrganizationIdAttributeSetKey(RouteContext context) { 52 String organizationIdFieldKey = RouteNodeUtils.getValueOfCustomProperty(context.getNodeInstance().getRouteNode(), ROUTE_NODE_XML_ORG_ID_QUALIFIER_KEY); 53 if (StringUtils.isBlank(organizationIdFieldKey)) { 54 if (usesNonDerivedOrganizationRoles(context)) { 55 throw new RuntimeException("Cannot find required XML element '" + ROUTE_NODE_XML_ORG_ID_QUALIFIER_KEY + "' on the Route Node XML configuration."); 56 } 57 } 58 return organizationIdFieldKey; 59 } 60 61 public Boolean usesNonDerivedOrganizationRoles(RouteContext context) { 62 String useNonDerivedOrganizationRoles = RouteNodeUtils.getValueOfCustomProperty(context.getNodeInstance().getRouteNode(), ROUTE_NODE_XML_USE_NON_DERIVED_ROLES); 63 if (StringUtils.isNotBlank(useNonDerivedOrganizationRoles)) { 64 return Boolean.valueOf(useNonDerivedOrganizationRoles); 65 } 66 return true; 67 } 68 }