1 /** 2 * Copyright 2005-2012 The Kuali Foundation 3 * 4 * Licensed under the Educational Community License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.opensource.org/licenses/ecl2.php 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package org.kuali.rice.kew.rule; 17 18 import org.kuali.rice.core.api.uif.RemotableAttributeError; 19 import org.kuali.rice.core.api.uif.RemotableAttributeErrorContract; 20 import org.kuali.rice.kew.api.rule.RuleExtension; 21 import org.kuali.rice.kew.exception.WorkflowServiceError; 22 import org.kuali.rice.kew.routeheader.DocumentContent; 23 import org.kuali.rice.kew.rule.xmlrouting.GenericXMLRuleAttribute; 24 import org.kuali.rice.kew.api.KewApiConstants; 25 import org.kuali.rice.kns.web.ui.Row; 26 27 import java.io.Serializable; 28 import java.util.List; 29 import java.util.Map; 30 31 32 /** 33 * <p>Interface which abstracts a piece of information ("attribute") associated with 34 * a Workflow document, which can be used to make routing decisions when combined 35 * with Rules.</p> 36 * <p>WorkflowAttribute lifecycle:</p> 37 * <p>Definition via XML</p> 38 * <ol> 39 * <li>Attribute definition is defined in XML (... any actions that are performed on-definition)</li> 40 * <li>Attribute definition is registered in a Rule Template definition in XML</li> 41 * <li>Rule Template is associated with a Document and a Rule in XML</li> 42 * </ol> 43 * <p>Definition via UI (this documentation needs work)</p> 44 * <ol> 45 * <li>...?...</li> 46 * <li>{@link #validateRuleData(Map)} and {@link #validateRoutingData(Map)} and are called to validate the configuration/extension values 47 * of the rule definition, and the user-configured rule data (??). see {@link org.kuali.rice.kew.rule.web.WebRuleBaseValues}, 48 * {@link org.kuali.rice.kew.rule.RuleRoutingAttribute}.</li> 49 * <li>Not sure where and why these are called, or how that is reconciled with XML-based ingestion....? The 'required' field only seems 50 * to matter with regard to these two methods; it seems to only ever be used in implementations of these two methods</li> 51 * </ol> 52 * <p>Runtime evaluation</p> 53 * <ol> 54 * <li>Client application constructs {@link org.kuali.rice.kew.api.document.attribute.WorkflowAttributeDefinition} and attaches 55 * it to the client-side document</li> 56 * <li>Upon action taken on the document, the Attributes that are described by the <code>WorkflowAttributeDefinitionVO</code>s 57 * are looked up (... how ...) and constructed on the client side.</li> 58 * <li>If the attribute is a {@link WorkflowAttributeXmlValidator} (e.g. {@link org.kuali.rice.kew.rule.xmlrouting.StandardGenericXMLRuleAttribute}), 59 * then {@link WorkflowAttributeXmlValidator#validateClientRoutingData()} is called to validate any data the client app may have set 60 * on the client-instantiated attribute (the {@link org.kuali.rice.kew.api.document.attribute.WorkflowAttributeDefinition})</li> 61 * <li>Attribute content (content the attribute generates to place in the eDoc document content) is obtained from the attribute 62 * via {@link WorkflowRuleAttribute#getDocContent()} or {@link org.kuali.rice.kew.framework.document.attribute.SearchableAttribute#generateSearchContent(org.kuali.rice.kew.api.extension.ExtensionDefinition, String, org.kuali.rice.kew.api.document.attribute.WorkflowAttributeDefinition)}, 63 * depending on whether the attribute is a WorkflowAttribute or {@link org.kuali.rice.kew.framework.document.attribute.SearchableAttribute}</li> 64 * <li>When a Rule is invoked (for instance, when a <code>requests</code> node is fired), all attributes associated with the rule 65 * (those associated with the Rule Template associated with the rule) which are WorkflowAttributes are enumerated and for each: 66 * <ol> 67 * <li>A special case is made for attributes defined in XML as 68 * of "RuleXmlAttribute" type ({@link KewApiConstants#RULE_XML_ATTRIBUTE_TYPE}): the attribute is cast to {@link GenericXMLRuleAttribute} 69 * and RuleAttribute business object is set on it ({@link GenericXMLRuleAttribute#setRuleAttribute(org.kuali.rice.kew.rule.RuleAttribute)} 70 * before proceeding with isMatch invocation. (what about a RuleAttributeAware interface so this can be done generically for all worklfow attribute 71 * implementations?)</li> 72 * <li>{@link WorkflowRuleAttribute#isMatch(DocumentContent, List)} is called with the Rule's extension values passed</li> 73 * </ol> 74 * </li> 75 * <li>If all attributes for the rule match, the rule is fired</li> 76 * </ol> 77 * 78 * @author Kuali Rice Team (rice.collab@kuali.org) 79 */ 80 public interface WorkflowRuleAttribute extends Serializable { 81 82 /** 83 * Returns true if this Attribute finds a match in the given DocContent. If true, 84 * the associated document will be routed to the users specifed by the UNF 85 * 86 * The isMatch method is responsible for determining whether content in a document matches content saved in workflow, thus determining whether to fire a rule or not. 87 * The isMatch method takes a DocumentContent object and a list of rule extension objects and returns a Boolean. The DocumentContent object contains the data in XML 88 * format that will be compared with the rules saved in workflow. Rule extension objects come from a potential rule that may match the document content on this eDoc. 89 * The potential rule is selected based on the Document Type and Rule Templates associated with this eDoc. Each rule extension object contains a list of rule extension 90 * value objects which have the data we will use in key value format to compare to the document content. The key will be determined by a unique string assigned by this 91 * attribute. The Value is determined when a rule is created and data is entered for the particular key. If a match is found, this method returns true and the eDoc will 92 * be routed based on this rule. If no match is found, the method returns false and the eDoc will not be routed based on this rule. 93 */ 94 boolean isMatch(DocumentContent docContent, List<RuleExtension> ruleExtensions); 95 96 /** 97 * Each Row contains Fields describing the UI-level presentation of a single RuleExtensionValue. 98 * <p> 99 * A single Row may contain more than one actual Field instance, but Fields beyond the first one 100 * are there to provide context for the display and evaluation of the first one. 101 * 102 * <p>The getRuleRows method returns a list of rows that contain Fields describing the UI-level presentation of a single RuleExtensionValue for the creation of a rule. 103 * A single row may contain more than one actual Field object, but Fields beyond the first one are there to provide context for the display and evaluation of the first one. 104 * For example, a secondary field may be a lookupable or a searchable valid values object. An individual field consists of a field label, a field help url, a field type, 105 * whether a lookupable is associated with this field, a property name, a property value, valid values, the name of the lookupable, and the default lookupable name for this field. 106 * The field label is a short title that will display on the jsp describing what data to enter for this field. The field help url is optional, but will pop open in a new window 107 * the url entered. The field type is the type of field to display (e.g. hidden, text, drop down, radio, quickfinder (lookupable), lookup result only (this type is needed for 108 * the lookupable, but does not actually render on the jsp), and finally drop down refresh (this type is a drop down box that when it's value changes another drop down box's 109 * valid values will be changed as well)). The lookupable indicator determines whether this field will have a lookupable (valid value search) associated with it. The property 110 * name is the name of the field when rendered on the jsp. This needs to be unique when compared to other field names on the jsp. The property value is the value entered into 111 * the text box or other field type on the jsp. This value will be empty when creating the field and populated during form submission. A List of valid values is optional and 112 * needed to populate drop down boxes or radio buttons. This list consists of KeyValue objects which the key will be the value passed in on submission and the label will 113 * be what is display on the jsp. The lookupable is the name of the lookable service to be called for this field. The default lookupable name is the name of the field on the 114 * lookupable itself. This may be the same of the property name of the field. This is needed when field conversions are needed. If the lookupable returns a key that doesn't 115 * match a property name on the jsp it needs to be converted to one that does. So if the property name is different than the default lookupable name, the lookupable will 116 * convert the return key to the property name of the field. Example: say by default a lookupable returns "color=red" on the url. The default lookupable name would be "color" 117 * and if you needed a different name for this property on the jsp such as "wallcolor", the lookupable will now return "wallcolor=red" instead of the default "color=red". The 118 * default lookupable name also is the key for rule extension values. When an extension value is saved the value comes from the UI and the key from this field. If this field 119 * is left null, then the property name of the field will become the key stored in the database for the extension value. A row can also consist of a group label and number 120 * of rows for this label to span for this attribute. If a group label is present, it will display on the rule creation jsp and group together the individual rows for this 121 * attribute. The total rows number will rowspan the group label across the rows of this attribute. 122 * NOTE: the group label and number of rows to span must be specified on each row object for the display to work correctly. 123 * 124 * <p>Additionally, it is very important that the List of Row objects is reconstructed every time getRuleRows is called. This is because the code which processes 125 * these Rows will set the propertyValue directly on the Field objects contained within. Essentially, this means the Rows and Fields should not be constructed once inside of 126 * the attribute and cached statically, but instead be recreated each time this method is called. 127 */ 128 List<Row> getRuleRows(); 129 130 /** 131 * RoutingDataRows contain Rows describing the UI-level presentation of the ruleData fields 132 * used to determine where a given document would be routed according to the associated rule. 133 * 134 * <p>The getRoutingDataRows method returns a list of rows that contain Fields describing the UI-level presentation of a single RuleExtensionValue for the routing report feature. 135 * These rows are used to determine where an eDoc would route if these values were entered. They are constructed the same way rule rows are described above and a lot of times 136 * are identical. 137 * 138 * <p>Additionally, it is very important that the List of Row objects is reconstructed every time getRoutingDataRows is called. This is because the code which processes 139 * these Rows will set the propertyValue directly on the Field objects contained within. Essentially, this means the Rows and Fields should not be constructed once inside of 140 * the attribute and cached statically, but instead be recreated each time this method is called. 141 */ 142 List<Row> getRoutingDataRows(); 143 144 /** 145 * Returns a String containing this Attribute's routingData values, formatted as a series of XML 146 * tags. The returned tags need not be contained within a single top-level tag. 147 * <p> 148 * For example, DollarRangeAttribute returns a single tag containing its totalDollarAmount, thus: 149 * <pre> 150 * <totalDollarAmount>345</totalDollarAmount> 151 * </pre> 152 */ 153 String getDocContent(); 154 155 /** 156 * Returns the List of RuleExtensionValue objects associated with this Rule, each of which contains 157 * the name and value of one of the parameters used by this Attribute to control when the associated 158 * Rule gets evaluated. RuleExtensionValues are assigned when the Rule is created. 159 * <p> 160 * For example, the DollarRangeAttribute has two associated RuleExtensionValues - its minimum and 161 * maximum values - which control when a rule containing that attribute gets evaluated. 162 * <p> 163 * The UI instantiates a Rule from a RuleTemplate, uses the RuleRows of all of that Rule's Attributes 164 * to build a form, uses user input to create a set of RuleExtensionValues which get persisted when 165 * the rule is persisted. 166 * 167 * To create a RuleExtensionValue object, instantiate a new object, set the key which will be located on the Rule's attribute, 168 * set the value which will be entered on the form from the UI side, and finally add each RuleExtensionValue object to a list. 169 * 170 * 171 * (Basically, given a configured/initialized attribute, marshalls out the RuleExtensionValues representing the current state of 172 * the attribute - Aaron Hamid FIXME) 173 */ 174 List<RuleExtensionValue> getRuleExtensionValues(); 175 176 /** 177 * Validates routingData values in the incoming map. Called by the UI during rule creation. 178 * 179 * This method is responsible for validating and setting the data entered on the form from the UI of the routing report to the Rule's attribute. 180 * The values will be in a Map with the key being the key of the RuleExtensionValue and the value being the value of the data entered from the 181 * UI. This method is used for the routing report which may have different fields than the rule data. 182 * 183 * @param paramMap Map containing the names and values of the routing data for this Attribute 184 */ 185 List<RemotableAttributeError> validateRoutingData(Map<String, String> paramMap); 186 187 /** 188 * Validates ruleExtension values in the incoming map. Called by the UI during rule creation. 189 * 190 * This method is responsible for validating and setting the data entered on the form from the UI of the rule creation to the Rule's attribute. 191 * The values will be in a Map with the key being the key of the RuleExtensionValue and the value being the value of the data entered from the UI. 192 * This method is used for rule creation which may have different fields than the routing report data. 193 * 194 * @param paramMap Map containing the names and values of the rule extensions for this Attribute 195 */ 196 List<RemotableAttributeError> validateRuleData(Map<String, String> paramMap); 197 198 /** 199 * Sets the required flag for this Attribute to true. If required is true, the extensionValues for 200 * this Attribute must be filled in before the associated Rule can be persisted. 201 * 202 * This method sets a flag on whether this attribute is required or not. 203 * When a rule template is created, the rule's attribute can be required. 204 * This setting is then passed to the attribute by this method and can be used by the validateRuleData or validateRoutingData method as fit. 205 */ 206 void setRequired(boolean required); 207 208 /** 209 * Returns true if the extensionValues on this Attribute must be filled in before the associated 210 * Rule can be persisted. 211 */ 212 boolean isRequired(); 213 214 }