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