use of org.kie.api.definition.process.WorkflowProcess in project jbpm by kiegroup.
the class ProcessBuilderImpl method buildProcess.
public void buildProcess(final Process process, Resource resource) {
if (resource != null) {
((org.jbpm.process.core.Process) process).setResource(resource);
}
boolean hasErrors = false;
ProcessValidator validator = ProcessValidatorRegistry.getInstance().getValidator(process, resource);
if (validator == null) {
logger.warn("Could not find validator for process {}.", ((Process) process).getType());
logger.warn("Continuing without validation of the process {} [{}]", process.getName(), process.getId());
} else {
ProcessValidationError[] errors = validator.validateProcess((WorkflowProcess) process);
if (errors.length != 0) {
hasErrors = true;
for (int i = 0; i < errors.length; i++) {
this.errors.add(new ParserError(resource, errors[i].toString(), -1, -1));
}
}
}
if (!hasErrors) {
// generate and add rule for process
String rules = "package " + process.getPackageName() + "\n";
// NPE for validator
if (validator != null && validator.compilationSupported()) {
rules = generateRules(process);
}
try {
knowledgeBuilder.addPackageFromDrl(new StringReader(rules), resource);
} catch (IOException e) {
// should never occur
logger.error("IOException during addPackageFromDRL", e);
} catch (DroolsParserException e) {
// should never occur
logger.error("DroolsParserException during addPackageFromDRL", e);
}
PackageRegistry pkgRegistry = this.knowledgeBuilder.getPackageRegistry(process.getPackageName());
if (pkgRegistry != null) {
InternalKnowledgePackage p = pkgRegistry.getPackage();
if (p != null) {
if (validator != null) {
// NPE for validator
if (validator.compilationSupported()) {
ProcessDescr processDescr = new ProcessDescr();
processDescr.setName(process.getPackageName() + "." + process.getName());
processDescr.setResource(resource);
processDescr.setProcessId(process.getId());
DialectCompiletimeRegistry dialectRegistry = pkgRegistry.getDialectCompiletimeRegistry();
Dialect dialect = dialectRegistry.getDialect("java");
dialect.init(processDescr);
ProcessBuildContext buildContext = new ProcessBuildContext(this.knowledgeBuilder, p, process, processDescr, dialectRegistry, dialect);
buildContexts((ContextContainer) process, buildContext);
if (process instanceof WorkflowProcess) {
buildNodes((WorkflowProcess) process, buildContext);
}
}
Process duplicateProcess = p.getRuleFlows().get(process.getId());
if (duplicateProcess != null) {
Resource duplicatedResource = duplicateProcess.getResource();
if (resource == null || duplicatedResource == null || duplicatedResource.getSourcePath() == null || duplicatedResource.getSourcePath().equals(resource.getSourcePath())) {
this.errors.add(new DuplicateProcess(process, this.knowledgeBuilder.getBuilderConfiguration()));
} else {
this.errors.add(new ParserError(resource, "Process with same id already exists: " + process.getId(), -1, -1));
}
}
p.addProcess(process);
// NPE for validator
if (validator.compilationSupported()) {
pkgRegistry.compileAll();
pkgRegistry.getDialectRuntimeRegistry().onBeforeExecute();
}
}
}
} else {
// name of the process
throw new RuntimeException("invalid package name");
}
}
}
use of org.kie.api.definition.process.WorkflowProcess in project jbpm by kiegroup.
the class LaneHandler method start.
@SuppressWarnings("unchecked")
public Object start(final String uri, final String localName, final Attributes attrs, final ExtensibleXmlParser parser) throws SAXException {
parser.startElementBuilder(localName, attrs);
String id = attrs.getValue("id");
String name = attrs.getValue("name");
WorkflowProcess process = (WorkflowProcess) parser.getParent();
List<Lane> lanes = (List<Lane>) ((RuleFlowProcess) process).getMetaData(LaneHandler.LANES);
if (lanes == null) {
lanes = new ArrayList<Lane>();
((RuleFlowProcess) process).setMetaData(LaneHandler.LANES, lanes);
}
Lane lane = new Lane(id);
lane.setName(name);
lanes.add(lane);
return lane;
}
use of org.kie.api.definition.process.WorkflowProcess in project jbpm by kiegroup.
the class WorkflowProcessInstanceUpgrader method upgradeProcessInstance.
public static void upgradeProcessInstance(KieRuntime kruntime, long processInstanceId, String processId, Map<String, Long> nodeMapping) {
if (nodeMapping == null) {
nodeMapping = new HashMap<String, Long>();
}
WorkflowProcessInstanceImpl processInstance = (WorkflowProcessInstanceImpl) kruntime.getProcessInstance(processInstanceId);
if (processInstance == null) {
throw new IllegalArgumentException("Could not find process instance " + processInstanceId);
}
if (processId == null) {
throw new IllegalArgumentException("Null process id");
}
WorkflowProcess process = (WorkflowProcess) kruntime.getKieBase().getProcess(processId);
if (process == null) {
throw new IllegalArgumentException("Could not find process " + processId);
}
if (processInstance.getProcessId().equals(processId)) {
return;
}
synchronized (processInstance) {
org.kie.api.definition.process.Process oldProcess = processInstance.getProcess();
processInstance.disconnect();
processInstance.setProcess(oldProcess);
updateNodeInstances(processInstance, nodeMapping);
processInstance.setKnowledgeRuntime((InternalKnowledgeRuntime) kruntime);
processInstance.setProcess(process);
processInstance.reconnect();
}
}
use of org.kie.api.definition.process.WorkflowProcess in project jbpm by kiegroup.
the class MigrateProcessInstanceCommand method execute.
public Void execute(Context context) {
KieSession ksession = ((RegistryContext) context).lookup(KieSession.class);
WorkflowProcessInstanceImpl processInstance = (WorkflowProcessInstanceImpl) ksession.getProcessInstance(processInstanceId);
if (processInstance == null) {
throw new IllegalArgumentException("Could not find process instance " + processInstanceId);
}
if (processId == null) {
throw new IllegalArgumentException("Null process id");
}
WorkflowProcess process = (WorkflowProcess) ksession.getKieBase().getProcess(processId);
if (process == null) {
throw new IllegalArgumentException("Could not find process " + processId);
}
if (processInstance.getProcessId().equals(processId)) {
return null;
}
synchronized (processInstance) {
org.kie.api.definition.process.Process oldProcess = processInstance.getProcess();
processInstance.disconnect();
processInstance.setProcess(oldProcess);
if (nodeMapping == null) {
nodeMapping = new HashMap<String, Long>();
}
updateNodeInstances(processInstance, nodeMapping);
processInstance.setKnowledgeRuntime((InternalKnowledgeRuntime) ksession);
processInstance.setProcess(process);
processInstance.reconnect();
}
return null;
}
use of org.kie.api.definition.process.WorkflowProcess in project jbpm by kiegroup.
the class WorkflowProcessInstanceUpgrader method upgradeProcessInstanceByNodeNames.
/**
* Do the same as upgradeProcessInstance() but user provides mapping by node names, not by node id's
* @param kruntime
* @param activeProcessId
* @param newProcessId
* @param nodeNamesMapping
*/
public static void upgradeProcessInstanceByNodeNames(KieRuntime kruntime, Long fromProcessId, String toProcessId, Map<String, String> nodeNamesMapping) {
Map<String, Long> nodeIdMapping = new HashMap<String, Long>();
String fromProcessIdString = kruntime.getProcessInstance(fromProcessId).getProcessId();
Process processFrom = kruntime.getKieBase().getProcess(fromProcessIdString);
Process processTo = kruntime.getKieBase().getProcess(toProcessId);
for (Map.Entry<String, String> entry : nodeNamesMapping.entrySet()) {
String from = null;
Long to = null;
if (processFrom instanceof WorkflowProcess) {
from = getNodeId(((WorkflowProcess) processFrom).getNodes(), entry.getKey(), true);
} else if (processFrom instanceof RuleFlowProcess) {
from = getNodeId(((RuleFlowProcess) processFrom).getNodes(), entry.getKey(), true);
} else if (processFrom != null) {
throw new IllegalArgumentException("Suported processes are WorkflowProcess and RuleFlowProcess, it was:" + processFrom.getClass());
} else {
throw new IllegalArgumentException("Can not find process with id: " + fromProcessIdString);
}
if (processTo instanceof WorkflowProcess) {
to = Long.valueOf(getNodeId(((WorkflowProcess) processTo).getNodes(), entry.getValue(), false));
} else if (processTo instanceof RuleFlowProcess) {
to = Long.valueOf(getNodeId(((RuleFlowProcess) processTo).getNodes(), entry.getValue(), false));
} else if (processTo != null) {
throw new IllegalArgumentException("Suported processes are WorkflowProcess and RuleFlowProcess, it was:" + processTo.getClass());
} else {
throw new IllegalArgumentException("Can not find process with id: " + toProcessId);
}
nodeIdMapping.put(from, to);
}
upgradeProcessInstance(kruntime, fromProcessId, toProcessId, nodeIdMapping);
}
Aggregations