| 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.dto.PropertyDefinitionDTO; |
| 25 | |
import org.kuali.rice.kew.dto.WorkflowAttributeDefinitionDTO; |
| 26 | |
import org.kuali.rice.kew.dto.WorkflowAttributeValidationErrorDTO; |
| 27 | |
import org.kuali.rice.kew.exception.WorkflowException; |
| 28 | |
import org.kuali.rice.kew.exception.WorkflowRuntimeException; |
| 29 | |
import org.kuali.rice.kew.service.WorkflowDocument; |
| 30 | |
import org.w3c.dom.Element; |
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | |
|
| 38 | |
|
| 39 | 0 | public class AttributeEDLConfigComponent extends SimpleWorkflowEDLConfigComponent { |
| 40 | |
|
| 41 | |
|
| 42 | |
public List getMatchingParams(Element originalConfigElement, RequestParser requestParser, EDLContext edlContext) { |
| 43 | 0 | List matchingParams = super.getMatchingParams(originalConfigElement, requestParser, edlContext); |
| 44 | |
|
| 45 | 0 | if (!edlContext.getUserAction().isLoadAction()) { |
| 46 | 0 | String attributeName = originalConfigElement.getAttribute("attributeName"); |
| 47 | 0 | String attributePropertyName = originalConfigElement.getAttribute("name"); |
| 48 | |
|
| 49 | 0 | WorkflowDocument document = (WorkflowDocument)requestParser.getAttribute(RequestParser.WORKFLOW_DOCUMENT_SESSION_KEY); |
| 50 | |
|
| 51 | 0 | document.clearAttributeContent(); |
| 52 | |
|
| 53 | 0 | WorkflowAttributeDefinitionDTO attributeDef = getWorkflowAttributeDefinitionVO(attributeName, document); |
| 54 | 0 | for (Iterator iter = matchingParams.iterator(); iter.hasNext();) { |
| 55 | 0 | MatchingParam param = (MatchingParam) iter.next(); |
| 56 | 0 | PropertyDefinitionDTO property = attributeDef.getProperty(attributePropertyName); |
| 57 | |
|
| 58 | 0 | if (property == null) { |
| 59 | 0 | property = new PropertyDefinitionDTO(attributePropertyName, param.getParamValue()); |
| 60 | 0 | attributeDef.addProperty(property); |
| 61 | |
} else { |
| 62 | 0 | property.setValue(param.getParamValue()); |
| 63 | |
} |
| 64 | 0 | } |
| 65 | |
|
| 66 | |
try { |
| 67 | |
|
| 68 | 0 | if (edlContext.getUserAction().isValidatableAction()) { |
| 69 | 0 | WorkflowAttributeValidationErrorDTO[] errors = document.validateAttributeDefinition(attributeDef); |
| 70 | 0 | if (errors.length > 0) { |
| 71 | 0 | getEdlContext().setInError(true); |
| 72 | |
} |
| 73 | 0 | for (int index = 0; index < errors.length; index++) { |
| 74 | 0 | WorkflowAttributeValidationErrorDTO error = errors[index]; |
| 75 | 0 | MatchingParam param = getMatchingParam(matchingParams, error.getKey()); |
| 76 | |
|
| 77 | 0 | if (param == null) { |
| 78 | 0 | List globalErrors = (List)getEdlContext().getRequestParser().getAttribute(RequestParser.GLOBAL_ERRORS_KEY); |
| 79 | 0 | globalErrors.add(error.getMessage()); |
| 80 | 0 | } else { |
| 81 | 0 | param.setError(Boolean.TRUE); |
| 82 | 0 | param.setErrorMessage(error.getMessage()); |
| 83 | |
} |
| 84 | |
} |
| 85 | |
} |
| 86 | 0 | } catch (WorkflowException e) { |
| 87 | 0 | throw new WorkflowRuntimeException("Encountered an error when validating form.", e); |
| 88 | 0 | } |
| 89 | |
} |
| 90 | 0 | return matchingParams; |
| 91 | |
} |
| 92 | |
|
| 93 | |
private WorkflowAttributeDefinitionDTO getWorkflowAttributeDefinitionVO(String attributeName, WorkflowDocument document) { |
| 94 | 0 | for (int i = 0; i < document.getAttributeDefinitions().length; i++) { |
| 95 | 0 | WorkflowAttributeDefinitionDTO workflowAttributeDef = (WorkflowAttributeDefinitionDTO)document.getAttributeDefinitions()[i]; |
| 96 | 0 | if (workflowAttributeDef.getAttributeName().equals(attributeName)) { |
| 97 | 0 | return workflowAttributeDef; |
| 98 | |
} |
| 99 | |
} |
| 100 | 0 | WorkflowAttributeDefinitionDTO workflowAttributeDef = new WorkflowAttributeDefinitionDTO(attributeName); |
| 101 | 0 | document.addAttributeDefinition(workflowAttributeDef); |
| 102 | 0 | return workflowAttributeDef; |
| 103 | |
} |
| 104 | |
|
| 105 | |
private MatchingParam getMatchingParam(List matchingParams, String name) { |
| 106 | 0 | for (Iterator iterator = matchingParams.iterator(); iterator.hasNext();) { |
| 107 | 0 | MatchingParam param = (MatchingParam) iterator.next(); |
| 108 | 0 | if (param.getParamName().equals(name)) { |
| 109 | 0 | return param; |
| 110 | |
} |
| 111 | 0 | } |
| 112 | 0 | return null; |
| 113 | |
} |
| 114 | |
} |