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