| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| DestinationRuleAttribute |
|
| 1.2;1.2 |
| 1 | /** | |
| 2 | * Copyright 2005-2011 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 edu.sampleu.travel.workflow; | |
| 17 | ||
| 18 | import java.util.ArrayList; | |
| 19 | import java.util.HashMap; | |
| 20 | import java.util.List; | |
| 21 | import java.util.Map; | |
| 22 | ||
| 23 | import org.kuali.rice.kew.rule.GenericWorkflowAttribute; | |
| 24 | import org.kuali.rice.kew.rule.WorkflowAttributeValidationError; | |
| 25 | import org.kuali.rice.kns.web.ui.Field; | |
| 26 | import org.kuali.rice.kns.web.ui.Row; | |
| 27 | ||
| 28 | public class DestinationRuleAttribute extends GenericWorkflowAttribute { | |
| 29 | ||
| 30 | private static final String DEST_LABEL = "Destination"; | |
| 31 | private static final String DEST_FIELD_KEY = "destination"; | |
| 32 | ||
| 33 | 0 | private final List<Row> rows = new ArrayList<Row>(); |
| 34 | ||
| 35 | private String destination; | |
| 36 | ||
| 37 | public DestinationRuleAttribute() { | |
| 38 | 0 | super("destination"); |
| 39 | 0 | } |
| 40 | ||
| 41 | public DestinationRuleAttribute(String destination) { | |
| 42 | 0 | super("destination"); |
| 43 | 0 | this.destination = destination; |
| 44 | 0 | } |
| 45 | ||
| 46 | /* | |
| 47 | public boolean isMatch(DocumentContent docContent, List<RuleExtension> ruleExtensions) { | |
| 48 | try { | |
| 49 | boolean foundDestRule = false; | |
| 50 | for (Iterator extensionsIterator = ruleExtensions.iterator(); extensionsIterator.hasNext();) { | |
| 51 | RuleExtension extension = (RuleExtension) extensionsIterator.next(); | |
| 52 | if (extension.getRuleTemplateAttribute().getRuleAttribute().getClassName().equals(getClass().getName())) { | |
| 53 | for (Iterator valuesIterator = extension.getExtensionValues().iterator(); valuesIterator.hasNext();) { | |
| 54 | RuleExtensionValue extensionValue = (RuleExtensionValue) valuesIterator.next(); | |
| 55 | String key = extensionValue.getKey(); | |
| 56 | String value = extensionValue.getValue(); | |
| 57 | if (key.equals(DEST_FIELD_KEY)) { | |
| 58 | destination = value; | |
| 59 | foundDestRule = true; | |
| 60 | } | |
| 61 | } | |
| 62 | } | |
| 63 | } | |
| 64 | if (! foundDestRule) { | |
| 65 | return false; | |
| 66 | } | |
| 67 | ||
| 68 | Element element = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse( | |
| 69 | new InputSource(new BufferedReader(new StringReader(docContent.getDocContent())))).getDocumentElement(); | |
| 70 | XPath xpath = XPathFactory.newInstance().newXPath(); | |
| 71 | String docContentDest = xpath.evaluate("//destination", element); | |
| 72 | return destination.equals(docContentDest); | |
| 73 | } catch (Exception e) { | |
| 74 | throw new RuntimeException(e); | |
| 75 | } | |
| 76 | }*/ | |
| 77 | ||
| 78 | public List<Row> getRuleRows() { | |
| 79 | 0 | return getRows(); |
| 80 | } | |
| 81 | ||
| 82 | public List<Row> getRoutingDataRows() { | |
| 83 | 0 | return getRows(); |
| 84 | } | |
| 85 | ||
| 86 | private List<Row> getRows() { | |
| 87 | 0 | log.info("Returning rows: " + rows); |
| 88 | 0 | List<Field> fields = new ArrayList<Field>(); |
| 89 | 0 | fields.add(new Field(DEST_LABEL, "", Field.TEXT, false, DEST_FIELD_KEY, "", false, false, null, null)); |
| 90 | 0 | List<Row> rows = new ArrayList<Row>(); |
| 91 | 0 | rows.add(new Row(fields)); |
| 92 | 0 | return rows; |
| 93 | } | |
| 94 | ||
| 95 | /* setter for edoclite field */ | |
| 96 | public void setDestination(String destination) { | |
| 97 | 0 | this.destination = destination; |
| 98 | 0 | } |
| 99 | ||
| 100 | public Map<String, String> getProperties() { | |
| 101 | 0 | Map<String, String> props = new HashMap<String, String>(); |
| 102 | 0 | props.put("destination", destination); |
| 103 | 0 | return props; |
| 104 | } | |
| 105 | ||
| 106 | public List validateRoutingData(Map paramMap) { | |
| 107 | 0 | return validateInputMap(paramMap); |
| 108 | } | |
| 109 | ||
| 110 | public List validateRuleData(Map paramMap) { | |
| 111 | 0 | return validateInputMap(paramMap); |
| 112 | } | |
| 113 | ||
| 114 | private List validateInputMap(Map paramMap) { | |
| 115 | 0 | List errors = new ArrayList(); |
| 116 | 0 | this.destination = (String) paramMap.get(DEST_FIELD_KEY); |
| 117 | 0 | if (this.destination == null && required) { |
| 118 | 0 | errors.add(new WorkflowAttributeValidationError(DEST_FIELD_KEY, "Destination is required.")); |
| 119 | } | |
| 120 | 0 | return errors; |
| 121 | } | |
| 122 | } |