org.drools.bpmn2.legacy.beta1.UserTaskHandler Maven / Gradle / Ivy
/**
* Copyright 2010 JBoss Inc
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.drools.bpmn2.legacy.beta1;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.drools.process.core.Work;
import org.drools.process.core.impl.WorkImpl;
import org.drools.workflow.core.Node;
import org.drools.workflow.core.node.HumanTaskNode;
import org.drools.workflow.core.node.WorkItemNode;
import org.drools.xml.ExtensibleXmlParser;
import org.w3c.dom.Element;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
public class UserTaskHandler extends TaskHandler {
protected Node createNode(Attributes attrs) {
return new HumanTaskNode();
}
@SuppressWarnings("unchecked")
public Class generateNodeFor() {
return HumanTaskNode.class;
}
protected void handleNode(final Node node, final Element element, final String uri,
final String localName, final ExtensibleXmlParser parser) throws SAXException {
super.handleNode(node, element, uri, localName, parser);
HumanTaskNode humanTaskNode = (HumanTaskNode) node;
Work work = new WorkImpl();
work.setName("Human Task");
humanTaskNode.setWork(work);
Map dataInputs = new HashMap();
Map dataOutputs = new HashMap();
List owners = new ArrayList();
org.w3c.dom.Node xmlNode = element.getFirstChild();
while (xmlNode != null) {
String nodeName = xmlNode.getNodeName();
if ("ioSpecification".equals(nodeName)) {
readIoSpecification(xmlNode, dataInputs, dataOutputs);
} else if ("dataInputAssociation".equals(nodeName)) {
readDataInputAssociation(xmlNode, humanTaskNode, dataInputs);
} else if ("dataOutputAssociation".equals(nodeName)) {
readDataOutputAssociation(xmlNode, humanTaskNode, dataOutputs);
} else if ("potentialOwner".equals(nodeName)) {
owners.add(readPotentialOwner(xmlNode, humanTaskNode));
}
xmlNode = xmlNode.getNextSibling();
}
if (owners.size() > 0) {
String owner = owners.get(0);
for (int i = 1; i < owners.size(); i++) {
owner += "," + owners.get(i);
}
humanTaskNode.getWork().setParameter("ActorId", owner);
}
}
protected String readPotentialOwner(org.w3c.dom.Node xmlNode, HumanTaskNode humanTaskNode) {
return xmlNode.getFirstChild().getFirstChild().getFirstChild().getTextContent();
}
public void writeNode(Node node, StringBuilder xmlDump, boolean includeMeta) {
HumanTaskNode humanTaskNode = (HumanTaskNode) node;
writeNode("userTask", humanTaskNode, xmlDump, includeMeta);
xmlDump.append("implementation=\"humanTaskWebService\" >" + EOL);
writeIO(humanTaskNode, xmlDump);
String ownerString = (String) humanTaskNode.getWork().getParameter("ActorId");
if (ownerString != null) {
String[] owners = ownerString.split(",");
for (String owner: owners) {
xmlDump.append(
" " + EOL +
" " + EOL +
" " + owner + " " + EOL +
" " + EOL +
" " + EOL);
}
}
endNode("userTask", xmlDump);
}
protected void writeIO(WorkItemNode workItemNode, StringBuilder xmlDump) {
xmlDump.append(" " + EOL);
for (Map.Entry entry: workItemNode.getInMappings().entrySet()) {
xmlDump.append(" " + EOL);
}
for (Map.Entry entry: workItemNode.getWork().getParameters().entrySet()) {
if (!"ActorId".equals(entry.getKey()) && entry.getValue() != null) {
xmlDump.append(" " + EOL);
}
}
for (Map.Entry entry: workItemNode.getOutMappings().entrySet()) {
xmlDump.append(" " + EOL);
}
xmlDump.append(" " + EOL);
for (Map.Entry entry: workItemNode.getInMappings().entrySet()) {
xmlDump.append(" " + XmlBPMNProcessDumper.getUniqueNodeId(workItemNode) + "_" + entry.getKey() + "Input " + EOL);
}
for (Map.Entry entry: workItemNode.getWork().getParameters().entrySet()) {
if (!"ActorId".equals(entry.getKey()) && entry.getValue() != null) {
xmlDump.append(" " + XmlBPMNProcessDumper.getUniqueNodeId(workItemNode) + "_" + entry.getKey() + "Input " + EOL);
}
}
xmlDump.append(
" " + EOL);
xmlDump.append(" " + EOL);
for (Map.Entry entry: workItemNode.getOutMappings().entrySet()) {
xmlDump.append(" " + XmlBPMNProcessDumper.getUniqueNodeId(workItemNode) + "_" + entry.getKey() + "Output " + EOL);
}
xmlDump.append(
" " + EOL);
xmlDump.append(
" " + EOL);
for (Map.Entry entry: workItemNode.getWork().getParameters().entrySet()) {
if (!"ActorId".equals(entry.getKey()) && entry.getValue() != null) {
xmlDump.append(
" " + EOL);
}
}
for (Map.Entry entry: workItemNode.getInMappings().entrySet()) {
xmlDump.append(" " + EOL);
xmlDump.append(
" " + XmlBPMNProcessDumper.getUniqueNodeId(workItemNode) + "_" + entry.getValue() + " " + EOL +
" " + XmlBPMNProcessDumper.getUniqueNodeId(workItemNode) + "_" + entry.getKey() + " " + EOL);
xmlDump.append(" " + EOL);
}
for (Map.Entry entry: workItemNode.getWork().getParameters().entrySet()) {
if (!"ActorId".equals(entry.getKey()) && entry.getValue() != null) {
xmlDump.append(" " + EOL);
xmlDump.append(
" " + EOL +
" " + entry.getValue().toString() + " " + EOL +
" " + XmlBPMNProcessDumper.getUniqueNodeId(workItemNode) + "_" + entry.getKey() + "Input " + EOL +
" " + EOL +
" " + XmlBPMNProcessDumper.getUniqueNodeId(workItemNode) + "_" + entry.getKey() + " " + EOL +
" " + XmlBPMNProcessDumper.getUniqueNodeId(workItemNode) + "_" + entry.getKey() + "Input " + EOL);
xmlDump.append(" " + EOL);
}
}
for (Map.Entry entry: workItemNode.getOutMappings().entrySet()) {
xmlDump.append(" " + EOL);
xmlDump.append(
" " + XmlBPMNProcessDumper.getUniqueNodeId(workItemNode) + "_" + entry.getKey() + " " + EOL +
" " + XmlBPMNProcessDumper.getUniqueNodeId(workItemNode) + "_" + entry.getValue() + " " + EOL);
xmlDump.append(" " + EOL);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy