use of org.jbpm.process.core.datatype.impl.type.ObjectDataType in project jbpm by kiegroup.
the class DataStoreHandler method start.
public Object start(final String uri, final String localName, final Attributes attrs, final ExtensibleXmlParser parser) throws SAXException {
parser.startElementBuilder(localName, attrs);
DataStore store = new DataStore();
store.setId(attrs.getValue("id"));
store.setName(attrs.getValue("name"));
final String itemSubjectRef = attrs.getValue("itemSubjectRef");
store.setItemSubjectRef(itemSubjectRef);
Map<String, ItemDefinition> itemDefinitions = (Map<String, ItemDefinition>) ((ProcessBuildData) parser.getData()).getMetaData("ItemDefinitions");
// retrieve type from item definition
// FIXME we bypass namespace resolving here. That's not a good idea when we start having several documents, with imports.
String localItemSubjectRef = itemSubjectRef.substring(itemSubjectRef.indexOf(":") + 1);
DataType dataType = new ObjectDataType();
if (itemDefinitions != null) {
ItemDefinition itemDefinition = itemDefinitions.get(localItemSubjectRef);
if (itemDefinition != null) {
dataType = new ObjectDataType(itemDefinition.getStructureRef(), parser.getClassLoader());
}
}
store.setType(dataType);
Definitions parent = (Definitions) parser.getParent();
List<DataStore> dataStores = parent.getDataStores();
if (dataStores == null) {
dataStores = new ArrayList<DataStore>();
parent.setDataStores(dataStores);
}
dataStores.add(store);
return store;
}
use of org.jbpm.process.core.datatype.impl.type.ObjectDataType in project jbpm by kiegroup.
the class AbstractNodeHandler method getDataType.
protected DataType getDataType(String itemSubjectRef, Map<String, ItemDefinition> itemDefinitions, ClassLoader cl) {
DataType dataType = new ObjectDataType();
if (itemDefinitions == null) {
return dataType;
}
ItemDefinition itemDefinition = itemDefinitions.get(itemSubjectRef);
if (itemDefinition != null) {
String structureRef = itemDefinition.getStructureRef();
if ("java.lang.Boolean".equals(structureRef) || "Boolean".equals(structureRef)) {
dataType = new BooleanDataType();
} else if ("java.lang.Integer".equals(structureRef) || "Integer".equals(structureRef)) {
dataType = new IntegerDataType();
} else if ("java.lang.Float".equals(structureRef) || "Float".equals(structureRef)) {
dataType = new FloatDataType();
} else if ("java.lang.String".equals(structureRef) || "String".equals(structureRef)) {
dataType = new StringDataType();
} else if ("java.lang.Object".equals(structureRef) || "Object".equals(structureRef)) {
dataType = new ObjectDataType(structureRef);
} else {
dataType = new ObjectDataType(structureRef, cl);
}
}
return dataType;
}
use of org.jbpm.process.core.datatype.impl.type.ObjectDataType in project jbpm by kiegroup.
the class EventTest method testEvent1.
@Test
public void testEvent1() {
RuleFlowProcess process = new RuleFlowProcess();
process.setId("org.drools.core.process.event");
process.setName("Event Process");
List<Variable> variables = new ArrayList<Variable>();
Variable variable = new Variable();
variable.setName("event");
ObjectDataType personDataType = new ObjectDataType();
personDataType.setClassName("org.drools.Person");
variable.setType(personDataType);
variables.add(variable);
process.getVariableScope().setVariables(variables);
StartNode startNode = new StartNode();
startNode.setName("Start");
startNode.setId(1);
process.addNode(startNode);
MilestoneNode milestoneNode = new MilestoneNode();
milestoneNode.setName("Milestone");
milestoneNode.setConstraint("eval(false)");
milestoneNode.setId(2);
process.addNode(milestoneNode);
new ConnectionImpl(startNode, Node.CONNECTION_DEFAULT_TYPE, milestoneNode, Node.CONNECTION_DEFAULT_TYPE);
EventNode eventNode = new EventNode();
EventTypeFilter eventFilter = new EventTypeFilter();
eventFilter.setType("myEvent");
eventNode.addEventFilter(eventFilter);
eventNode.setVariableName("event");
eventNode.setId(3);
process.addNode(eventNode);
final List<String> myList = new ArrayList<String>();
ActionNode actionNode = new ActionNode();
actionNode.setName("Print");
DroolsAction action = new DroolsConsequenceAction("java", null);
action.setMetaData("Action", new Action() {
public void execute(ProcessContext context) throws Exception {
logger.info("Detected event for person {}", ((Person) context.getVariable("event")).getName());
myList.add("Executed action");
}
});
actionNode.setAction(action);
actionNode.setId(4);
process.addNode(actionNode);
new ConnectionImpl(eventNode, Node.CONNECTION_DEFAULT_TYPE, actionNode, Node.CONNECTION_DEFAULT_TYPE);
Join join = new Join();
join.setName("XOR Join");
join.setType(Join.TYPE_XOR);
join.setId(5);
process.addNode(join);
new ConnectionImpl(milestoneNode, Node.CONNECTION_DEFAULT_TYPE, join, Node.CONNECTION_DEFAULT_TYPE);
new ConnectionImpl(actionNode, Node.CONNECTION_DEFAULT_TYPE, join, Node.CONNECTION_DEFAULT_TYPE);
EndNode endNode = new EndNode();
endNode.setName("EndNode");
endNode.setId(6);
process.addNode(endNode);
new ConnectionImpl(join, Node.CONNECTION_DEFAULT_TYPE, endNode, Node.CONNECTION_DEFAULT_TYPE);
KieSession ksession = createKieSession(process);
TestProcessEventListener procEventListener = new TestProcessEventListener();
ksession.addEventListener(procEventListener);
ProcessInstance processInstance = ksession.startProcess("org.drools.core.process.event");
assertEquals(0, myList.size());
Person jack = new Person();
jack.setName("Jack");
processInstance.signalEvent("myEvent", jack);
assertEquals(1, myList.size());
assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState());
verifyEventHistory(test1EventOrder, procEventListener.getEventHistory());
}
use of org.jbpm.process.core.datatype.impl.type.ObjectDataType in project jbpm by kiegroup.
the class EventTest method testEvent4.
@Test
public void testEvent4() {
RuleFlowProcess process = new RuleFlowProcess();
process.setId("org.drools.core.process.event");
process.setName("Event Process");
List<Variable> variables = new ArrayList<Variable>();
Variable variable = new Variable();
variable.setName("event");
ObjectDataType personDataType = new ObjectDataType();
personDataType.setClassName("org.drools.Person");
variable.setType(personDataType);
variables.add(variable);
process.getVariableScope().setVariables(variables);
StartNode startNode = new StartNode();
startNode.setName("Start");
startNode.setId(1);
process.addNode(startNode);
EventNode eventNode = new EventNode();
EventTypeFilter eventFilter = new EventTypeFilter();
eventFilter.setType("myEvent");
eventNode.addEventFilter(eventFilter);
eventNode.setId(3);
process.addNode(eventNode);
final List<String> myList = new ArrayList<String>();
ActionNode actionNode = new ActionNode();
actionNode.setName("Print");
DroolsAction action = new DroolsConsequenceAction("java", null);
action.setMetaData("Action", new Action() {
public void execute(ProcessContext context) throws Exception {
myList.add("Executed action");
}
});
actionNode.setAction(action);
actionNode.setId(4);
process.addNode(actionNode);
new ConnectionImpl(eventNode, Node.CONNECTION_DEFAULT_TYPE, actionNode, Node.CONNECTION_DEFAULT_TYPE);
EventNode eventNode2 = new EventNode();
eventFilter = new EventTypeFilter();
eventFilter.setType("myEvent");
eventNode2.addEventFilter(eventFilter);
eventNode2.setId(5);
process.addNode(eventNode2);
ActionNode actionNode2 = new ActionNode();
actionNode2.setName("Print");
action = new DroolsConsequenceAction("java", null);
action.setMetaData("Action", new Action() {
public void execute(ProcessContext context) throws Exception {
myList.add("Executed action");
}
});
actionNode2.setAction(action);
actionNode2.setId(6);
process.addNode(actionNode2);
new ConnectionImpl(eventNode2, Node.CONNECTION_DEFAULT_TYPE, actionNode2, Node.CONNECTION_DEFAULT_TYPE);
Join join = new Join();
join.setName("AND Join");
join.setType(Join.TYPE_AND);
join.setId(7);
process.addNode(join);
new ConnectionImpl(startNode, Node.CONNECTION_DEFAULT_TYPE, join, Node.CONNECTION_DEFAULT_TYPE);
new ConnectionImpl(actionNode, Node.CONNECTION_DEFAULT_TYPE, join, Node.CONNECTION_DEFAULT_TYPE);
new ConnectionImpl(actionNode2, Node.CONNECTION_DEFAULT_TYPE, join, Node.CONNECTION_DEFAULT_TYPE);
EndNode endNode = new EndNode();
endNode.setName("EndNode");
endNode.setId(8);
process.addNode(endNode);
new ConnectionImpl(join, Node.CONNECTION_DEFAULT_TYPE, endNode, Node.CONNECTION_DEFAULT_TYPE);
KieSession ksession = createKieSession(process);
TestProcessEventListener procEventListener = new TestProcessEventListener();
ksession.addEventListener(procEventListener);
ProcessInstance processInstance = ksession.startProcess("org.drools.core.process.event");
assertEquals(0, myList.size());
processInstance.signalEvent("myEvent", null);
assertEquals(2, myList.size());
assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState());
verifyEventHistory(test4EventOrder, procEventListener.getEventHistory());
}
use of org.jbpm.process.core.datatype.impl.type.ObjectDataType in project jbpm by kiegroup.
the class EventTest method testEvent2.
@Test
public void testEvent2() {
RuleFlowProcess process = new RuleFlowProcess();
process.setId("org.drools.core.process.event");
process.setName("Event Process");
List<Variable> variables = new ArrayList<Variable>();
Variable variable = new Variable();
variable.setName("event");
ObjectDataType personDataType = new ObjectDataType();
personDataType.setClassName("org.drools.Person");
variable.setType(personDataType);
variables.add(variable);
process.getVariableScope().setVariables(variables);
StartNode startNode = new StartNode();
startNode.setName("Start");
startNode.setId(1);
process.addNode(startNode);
MilestoneNode milestoneNode = new MilestoneNode();
milestoneNode.setName("Milestone");
milestoneNode.setConstraint("eval(false)");
milestoneNode.setId(2);
process.addNode(milestoneNode);
new ConnectionImpl(startNode, Node.CONNECTION_DEFAULT_TYPE, milestoneNode, Node.CONNECTION_DEFAULT_TYPE);
EndNode endNode = new EndNode();
endNode.setName("EndNode");
endNode.setId(3);
process.addNode(endNode);
new ConnectionImpl(milestoneNode, Node.CONNECTION_DEFAULT_TYPE, endNode, Node.CONNECTION_DEFAULT_TYPE);
EventNode eventNode = new EventNode();
EventTypeFilter eventFilter = new EventTypeFilter();
eventFilter.setType("myEvent");
eventNode.addEventFilter(eventFilter);
eventNode.setVariableName("event");
eventNode.setId(4);
process.addNode(eventNode);
final List<String> myList = new ArrayList<String>();
ActionNode actionNode = new ActionNode();
actionNode.setName("Print");
DroolsAction action = new DroolsConsequenceAction("java", null);
action.setMetaData("Action", new Action() {
public void execute(ProcessContext context) throws Exception {
logger.info("Detected event for person {}", ((Person) context.getVariable("event")).getName());
myList.add("Executed action");
}
});
actionNode.setAction(action);
actionNode.setId(5);
process.addNode(actionNode);
new ConnectionImpl(eventNode, Node.CONNECTION_DEFAULT_TYPE, actionNode, Node.CONNECTION_DEFAULT_TYPE);
EndNode endNode2 = new EndNode();
endNode2.setName("EndNode");
endNode2.setTerminate(false);
endNode2.setId(6);
process.addNode(endNode2);
new ConnectionImpl(actionNode, Node.CONNECTION_DEFAULT_TYPE, endNode2, Node.CONNECTION_DEFAULT_TYPE);
KieSession ksession = createKieSession(process);
TestProcessEventListener procEventListener = new TestProcessEventListener();
ksession.addEventListener(procEventListener);
ProcessInstance processInstance = ksession.startProcess("org.drools.core.process.event");
assertEquals(0, myList.size());
Person jack = new Person();
jack.setName("Jack");
processInstance.signalEvent("myEvent", jack);
assertEquals(1, myList.size());
Person john = new Person();
john.setName("John");
processInstance.signalEvent("myEvent", john);
assertEquals(2, myList.size());
verifyEventHistory(test2EventOrder, procEventListener.getEventHistory());
}
Aggregations