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.rice.student.bo.KualiStudentKimAttributes; 11 12 public class OrganizationQualifierResolver 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 @Override 18 public List<AttributeSet> resolve(RouteContext context) { 19 List<AttributeSet> attributeSets = new ArrayList<AttributeSet>(); 20 String orgIdKey = getNodeSpecificOrganizationIdAttributeSetKey(context); 21 for (String orgId : getOrganizationIdsFromDocumentContent(context)) { 22 AttributeSet attributeSet = new AttributeSet(); 23 attributeSet.put(orgIdKey, orgId); 24 attributeSet.put(KualiStudentKimAttributes.QUALIFICATION_ORG_ID, orgId); 25 attributeSets.add(attributeSet); 26 } 27 return attributeSets; 28 } 29 30 public String getNodeSpecificOrganizationIdAttributeSetKey(RouteContext context) { 31 String organizationIdFieldKey = RouteNodeUtils.getValueOfCustomProperty(context.getNodeInstance().getRouteNode(), ROUTE_NODE_XML_ORG_ID_QUALIFIER_KEY); 32 if (StringUtils.isBlank(organizationIdFieldKey)) { 33 if (usesNonDerivedOrganizationRoles(context)) { 34 throw new RuntimeException("Cannot find required XML element '" + ROUTE_NODE_XML_ORG_ID_QUALIFIER_KEY + "' on the Route Node XML configuration."); 35 } 36 } 37 return organizationIdFieldKey; 38 } 39 40 public Boolean usesNonDerivedOrganizationRoles(RouteContext context) { 41 String useNonDerivedOrganizationRoles = RouteNodeUtils.getValueOfCustomProperty(context.getNodeInstance().getRouteNode(), ROUTE_NODE_XML_USE_NON_DERIVED_ROLES); 42 if (StringUtils.isNotBlank(useNonDerivedOrganizationRoles)) { 43 return Boolean.valueOf(useNonDerivedOrganizationRoles); 44 } 45 return true; 46 } 47 }