Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright 2005-2013 The Kuali Foundation Licensed under the Educational Community License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.opensource.org/licenses/ecl2.php Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
 
 package org.kuali.rice.kew.routemodule;
 
 
 import java.util.List;


A RouteModule that generates requests for responsibilities statically defined in the config block of the node.

Author(s):
Kuali Rice Team (rice.collab@kuali.org)
 
 public class InlineRequestsRouteModule extends FlexRMAdapter {
     private static final Logger LOG = Logger.getLogger(InlineRequestsRouteModule.class);

    
This overridden method is used to decipher the inline xpath and responsibilities of a route node definition and use them to create action reqeusts

 
     @Override
     public List<ActionRequestValuefindActionRequests(RouteContext contextthrows Exception {
         // comment this out while implementing the meta-rules stuff
         // re-implement later
         List<ActionRequestValueactionRequests = new ArrayList<ActionRequestValue>();
         RouteNodeInstance currentNode = context.getNodeInstance();
         String contentFragment = currentNode.getRouteNode().getContentFragment();
         // parse with JDOM to reuse RuleXmlParser
         Document doc = XmlHelper.trimSAXXml(new ByteArrayInputStream(contentFragment.getBytes()));
         Element root = doc.getRootElement();
         List<StringruleAttributeNames = new ArrayList<String>();
         List<StringruleAttributeClassNames = new ArrayList<String>();
         List<StringxpathExpressions = new ArrayList<String>();
         // get the list of ruleAttributes to use
         Element ruleAttributes = root.getChild("ruleAttributes");
         if (ruleAttributes != null) {
             for (Object o : ruleAttributes.getChildren("name")) {
                 Element e = (Elemento;
                 ruleAttributeNames.add(e.getText());
             }
             for (Object o : ruleAttributes.getChildren("className")) {
                 Element e = (Elemento;
                 ruleAttributeClassNames.add(e.getText());
             }
         }
         // get the list of xpath expressions to verify
         for (Object oroot.getChildren("match")) {
             Element e = (Elemento;
             xpathExpressions.add(e.getText());
         }
         if ( (ruleAttributeNames.isEmpty()) && (ruleAttributeClassNames.isEmpty()) && (xpathExpressions.isEmpty()) ) {
             throw new RuntimeException("Match xpath expression not specified (should be parse-time exception...)");
         }
 
         List<WorkflowRuleAttributeattributes = new ArrayList<WorkflowRuleAttribute>();
        for (String attributeName : ruleAttributeNames) {
            attributes.add(getRuleAttributeByName(attributeName));
        }
        for (String attributeClassName : ruleAttributeClassNames) {
            attributes.addAll(getRuleAttributeByClassName(attributeClassName));
        }
        
        // at this point if we have no xpath expressions or attributes we cannot match
        if (attributes.isEmpty() && xpathExpressions.isEmpty()) {
            return actionRequests;
        }
        
        Boolean match = .;
        if (!xpathExpressions.isEmpty()) {
            XPath xpath = XPathHelper.newXPath();
            for (String xpathExpression : xpathExpressions) {
                match &= (Booleanxpath.evaluate(xpathExpressioncontext.getDocumentContent().getDocument(), .);
            }
        }
        for (WorkflowRuleAttribute workflowAttribute : attributes) {
            // no rule extensions to pass in below because we have no rule... simple attribute matching only
            match &= workflowAttribute.isMatch(context.getDocumentContent(), Collections.<RuleExtension>emptyList());
        }
        
        if (match.booleanValue()) {
//            LOG.debug("Expression '" + xpathExpression + "' matched document '" + context.getDocumentContent().getDocContent() + "'");
        } else {
            // return an empty list because we didn't find a match using the given xpath
//            LOG.debug("Expression '" + xpathExpression + "' did NOT match document '" + context.getDocumentContent().getDocContent() + "'");
            return actionRequests;
        }
        RuleXmlParser parser = new RuleXmlParser();
        ActionRequestFactory arf = new ActionRequestFactory(context.getDocument(), currentNode);
        // this rule is only used to obtain description, forceAction flag, and the rulebasevalues id, which may be null
        RuleBaseValues fakeRule = new RuleBaseValues();
        fakeRule.setName("fakeRule");
        fakeRule.setActive(.);
        fakeRule.setCurrentInd(.);
        fakeRule.setDescription("a fake rule");
        fakeRule.setForceAction(.);
        fakeRule.setId(null);
        for (Object oroot.getChildren("responsibility".)) {
            Element e = (Elemento;
            RuleResponsibilityBo responsibility = parser.parseResponsibility(efakeRule);
            responsibilities.add(org.kuali.rice.kew.api.rule.RuleResponsibility.Builder.create(responsibility).build());
        }
        if (responsibilities.isEmpty()) {
            throw new RuntimeException("No responsibilities found on node " + currentNode.getName());
        }
        makeActionRequests(arfresponsibilitiescontext, RuleBaseValues.to(fakeRule), context.getDocument(), nullnull);
        actionRequests.addAll(arf.getRequestGraphs());
        return actionRequests;
    }
    
    @Override
    public String toString() {
        return "InlineRequestsRouteModule";
    }
    private WorkflowRuleAttribute getRuleAttributeByName(String ruleAttributeName) {
        return materializeRuleAttribute(KewApiServiceLocator.getExtensionRepositoryService().getExtensionByName(
                ruleAttributeName));
    }
    
    private List<WorkflowRuleAttributegetRuleAttributeByClassName(String ruleAttributeClassName) {
        List<ExtensionDefinitionextensionDefinitions = 
                KewApiServiceLocator.getExtensionRepositoryService().getExtensionsByResourceDescriptor(ruleAttributeClassName);
        List<WorkflowRuleAttributeworkflowRuleAttributes = new ArrayList<WorkflowRuleAttribute>();
        for (ExtensionDefinition extension : extensionDefinitions) {
            workflowRuleAttributes.add(materializeRuleAttribute(extension));
        }
        return workflowRuleAttributes;
    }
    
    private WorkflowRuleAttribute materializeRuleAttribute(ExtensionDefinition extensionDefinition) {
        if (extensionDefinition != null) {
            if (..equals(extensionDefinition.getType())) {
                ObjectDefinition objDef = new ObjectDefinition(extensionDefinition.getResourceDescriptor(), extensionDefinition.getApplicationId());
                return (WorkflowRuleAttribute) GlobalResourceLoader.getObject(objDef);
            } else if (..equals(extensionDefinition.getType())) {
                ObjectDefinition objDef = new ObjectDefinition(extensionDefinition.getResourceDescriptor(), extensionDefinition.getApplicationId());
                WorkflowRuleAttribute workflowAttribute = (WorkflowRuleAttribute) GlobalResourceLoader.getObject(objDef);
                //required to make it work because ruleAttribute XML is required to construct custom columns
                ((GenericXMLRuleAttributeworkflowAttribute).setExtensionDefinition(extensionDefinition);
                return workflowAttribute;
            }
        }
        return null;
    }
    
New to GrepCode? Check out our FAQ X