1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
package org.kuali.rice.edl.impl.components; |
18 | |
|
19 | |
import java.util.Iterator; |
20 | |
import java.util.List; |
21 | |
|
22 | |
import org.kuali.rice.edl.impl.EDLContext; |
23 | |
import org.kuali.rice.edl.impl.RequestParser; |
24 | |
import org.kuali.rice.kew.api.WorkflowDocument; |
25 | |
import org.kuali.rice.kew.api.document.PropertyDefinition; |
26 | |
import org.kuali.rice.kew.api.document.WorkflowAttributeDefinition; |
27 | |
import org.kuali.rice.kew.api.document.WorkflowAttributeValidationError; |
28 | |
import org.w3c.dom.Element; |
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | 0 | public class AttributeEDLConfigComponent extends SimpleWorkflowEDLConfigComponent { |
37 | |
|
38 | |
public List getMatchingParams(Element originalConfigElement, RequestParser requestParser, EDLContext edlContext) { |
39 | 0 | List matchingParams = super.getMatchingParams(originalConfigElement, requestParser, edlContext); |
40 | |
|
41 | 0 | if (!edlContext.getUserAction().isLoadAction()) { |
42 | 0 | String attributeName = originalConfigElement.getAttribute("attributeName"); |
43 | 0 | String attributePropertyName = originalConfigElement.getAttribute("name"); |
44 | |
|
45 | 0 | WorkflowDocument document = (WorkflowDocument) requestParser |
46 | |
.getAttribute(RequestParser.WORKFLOW_DOCUMENT_SESSION_KEY); |
47 | |
|
48 | 0 | document.clearAttributeContent(); |
49 | |
|
50 | 0 | WorkflowAttributeDefinition.Builder attributeDefBuilder = getWorkflowAttributeDefinitionVO(attributeName, document); |
51 | |
|
52 | 0 | for (Iterator iter = matchingParams.iterator(); iter.hasNext();) { |
53 | 0 | MatchingParam param = (MatchingParam) iter.next(); |
54 | 0 | PropertyDefinition property = attributeDefBuilder.getPropertyDefinition(attributePropertyName); |
55 | |
|
56 | 0 | if (property == null) { |
57 | 0 | property = PropertyDefinition.create(attributePropertyName, param.getParamValue()); |
58 | |
} else { |
59 | |
|
60 | 0 | attributeDefBuilder.getPropertyDefinitions().remove(property); |
61 | 0 | property = PropertyDefinition.create(property.getName(), param.getParamValue()); |
62 | |
} |
63 | 0 | attributeDefBuilder.addPropertyDefinition(property); |
64 | |
|
65 | 0 | } |
66 | |
|
67 | 0 | WorkflowAttributeDefinition attributeDef = attributeDefBuilder.build(); |
68 | 0 | document.addAttributeDefinition(attributeDef); |
69 | |
|
70 | |
|
71 | 0 | if (edlContext.getUserAction().isValidatableAction()) { |
72 | 0 | List<WorkflowAttributeValidationError> errors = document.validateAttributeDefinition(attributeDef); |
73 | 0 | if (!errors.isEmpty()) { |
74 | 0 | getEdlContext().setInError(true); |
75 | |
} |
76 | 0 | for (WorkflowAttributeValidationError error : errors) { |
77 | 0 | MatchingParam param = getMatchingParam(matchingParams, error.getKey()); |
78 | |
|
79 | 0 | if (param == null) { |
80 | 0 | List globalErrors = (List) getEdlContext().getRequestParser().getAttribute( |
81 | |
RequestParser.GLOBAL_ERRORS_KEY); |
82 | 0 | globalErrors.add(error.getMessage()); |
83 | 0 | } else { |
84 | 0 | param.setError(Boolean.TRUE); |
85 | 0 | param.setErrorMessage(error.getMessage()); |
86 | |
} |
87 | 0 | } |
88 | |
} |
89 | |
} |
90 | 0 | return matchingParams; |
91 | |
} |
92 | |
|
93 | |
private WorkflowAttributeDefinition.Builder getWorkflowAttributeDefinitionVO(String attributeName, WorkflowDocument document) { |
94 | 0 | for (WorkflowAttributeDefinition attributeDefinition : document.getAttributeDefinitions()) { |
95 | 0 | if (attributeDefinition.getAttributeName().equals(attributeName)) { |
96 | 0 | return WorkflowAttributeDefinition.Builder.create(attributeDefinition); |
97 | |
} |
98 | |
} |
99 | 0 | return WorkflowAttributeDefinition.Builder.create(attributeName); |
100 | |
} |
101 | |
|
102 | |
private MatchingParam getMatchingParam(List matchingParams, String name) { |
103 | 0 | for (Iterator iterator = matchingParams.iterator(); iterator.hasNext();) { |
104 | 0 | MatchingParam param = (MatchingParam) iterator.next(); |
105 | 0 | if (param.getParamName().equals(name)) { |
106 | 0 | return param; |
107 | |
} |
108 | 0 | } |
109 | 0 | return null; |
110 | |
} |
111 | |
} |