private WorkflowAttributeDefinition.Builder getWorkflowAttributeDefinitionVO( String attributeName, WorkflowDocument document) { for (WorkflowAttributeDefinition attributeDefinition : document.getAttributeDefinitions()) { if (attributeDefinition.getAttributeName().equals(attributeName)) { return WorkflowAttributeDefinition.Builder.create(attributeDefinition); } } return WorkflowAttributeDefinition.Builder.create(attributeName); }
public void updateDOM(Document dom, Element configElement, EDLContext edlContext) { // String action = // edlContext.getRequestParser().getPropertyValueAsString(WorkflowDocumentActions.USER_ACTION_REQUEST_KEY); // we don't want to clear the attribute content if they are just opening up the document to view // it! if (!edlContext.getUserAction().isLoadAction()) { RequestParser requestParser = edlContext.getRequestParser(); try { WorkflowDocument document = (WorkflowDocument) requestParser.getAttribute(RequestParser.WORKFLOW_DOCUMENT_SESSION_KEY); // clear attribute content so that duplicate attribute values are not added during // submission of a new EDL form values version document.clearAttributeContent(); Document edlDef = EdlServiceLocator.getEDocLiteService() .getDefinitionXml(edlContext.getEdocLiteAssociation()); XPath xpath = XPathHelper.newXPath(edlDef); NodeList attributeNodes = (NodeList) xpath.evaluate("/edl/attributes/attribute", edlDef, XPathConstants.NODESET); for (int index = 0; index < attributeNodes.getLength(); index++) { Element attributeElem = (Element) attributeNodes.item(index); String attributeName = attributeElem.getAttribute("name"); WorkflowAttributeDefinition.Builder attributeDefBuilder = getWorkflowAttributeDefinitionVO(attributeName, document); NodeList fieldNodes = (NodeList) xpath.evaluate("./field", attributeElem, XPathConstants.NODESET); for (int fIndex = 0; fIndex < fieldNodes.getLength(); fIndex++) { Element fieldElem = (Element) fieldNodes.item(fIndex); String edlField = fieldElem.getAttribute("edlField"); String attributeField = fieldElem.getAttribute("attributeField"); PropertyDefinition property = attributeDefBuilder.getPropertyDefinition(attributeField); String value = requestParser.getParameterValue(edlField); if (property == null) { property = PropertyDefinition.create(attributeField, value); } else { // modify the current property attributeDefBuilder.getPropertyDefinitions().remove(property); property = PropertyDefinition.create(property.getName(), value); } attributeDefBuilder.addPropertyDefinition(property); } // validate if they are taking an action on the document (i.e. it's annotatable) boolean curAttrValid = true; if (edlContext.getUserAction().isValidatableAction()) { List<? extends RemotableAttributeErrorContract> errors = document.validateAttributeDefinition(attributeDefBuilder.build()); if (!errors.isEmpty()) { edlContext.setInError(true); curAttrValid = false; } Map<String, String> fieldErrors = (Map<String, String>) edlContext .getRequestParser() .getAttribute(RequestParser.GLOBAL_FIELD_ERRORS_KEY); for (RemotableAttributeErrorContract error : errors) { fieldErrors.put(error.getAttributeName(), error.getMessage()); } } if (curAttrValid) { if (edlContext.getUserAction().isValidatableAction()) { for (int fIndex = 0; fIndex < fieldNodes.getLength(); fIndex++) { Element fieldElem = (Element) fieldNodes.item(fIndex); String edlField = fieldElem.getAttribute("edlField"); String attributeField = fieldElem.getAttribute("attributeField"); PropertyDefinition property = attributeDefBuilder.getPropertyDefinition(attributeField); String value = requestParser.getParameterValue(edlField); if (property == null) { property = PropertyDefinition.create(attributeField, value); } else { // modify the current property attributeDefBuilder.getPropertyDefinitions().remove(property); property = PropertyDefinition.create(property.getName(), value); } attributeDefBuilder.addPropertyDefinition(property); } WorkflowAttributeDefinition attributeDef = attributeDefBuilder.build(); document.addAttributeDefinition(attributeDef); } } } } catch (Exception e) { if (e instanceof RuntimeException) { throw (RuntimeException) e; } throw new WorkflowRuntimeException("Failed to process attribute.", e); } } }