From bfcfcf5e3b4301bc94c27f47bfda61693edf3595 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Sat, 12 Apr 2014 17:55:28 +0200 Subject: wip --- calamus-engine/pom.xml | 390 +++++++++++++ .../main/java/io/trygvis/engine/CalamusJbpm.java | 69 +++ .../src/main/java/io/trygvis/engine/Main.java | 13 + .../src/main/java/io/trygvis/engine/MqClient.java | 73 +++ .../trygvis/engine/RestartAppWorkItemHandler.java | 24 + .../trygvis/engine/UpgradeAppWorkItemHandler.java | 24 + .../io/trygvis/engine/service/AppInstance.java | 7 + .../java/io/trygvis/engine/service/AppService.java | 15 + calamus-engine/src/main/resources/Deploy.bpmn2 | 132 +++++ .../resources/META-INF/AppctlWorkDefinitions.wid | 19 + .../src/main/resources/META-INF/persistence.xml | 31 + .../main/resources/db/postgresql-jbpm-schema.sql | 633 +++++++++++++++++++++ .../main/resources/db/quartz_tables_postgres.sql | 165 ++++++ calamus-engine/src/main/resources/jndi.properties | 1 + .../src/test/java/io/trygvis/engine/MyTest.java | 90 +++ 15 files changed, 1686 insertions(+) create mode 100755 calamus-engine/pom.xml create mode 100644 calamus-engine/src/main/java/io/trygvis/engine/CalamusJbpm.java create mode 100644 calamus-engine/src/main/java/io/trygvis/engine/Main.java create mode 100644 calamus-engine/src/main/java/io/trygvis/engine/MqClient.java create mode 100644 calamus-engine/src/main/java/io/trygvis/engine/RestartAppWorkItemHandler.java create mode 100644 calamus-engine/src/main/java/io/trygvis/engine/UpgradeAppWorkItemHandler.java create mode 100644 calamus-engine/src/main/java/io/trygvis/engine/service/AppInstance.java create mode 100644 calamus-engine/src/main/java/io/trygvis/engine/service/AppService.java create mode 100644 calamus-engine/src/main/resources/Deploy.bpmn2 create mode 100644 calamus-engine/src/main/resources/META-INF/AppctlWorkDefinitions.wid create mode 100644 calamus-engine/src/main/resources/META-INF/persistence.xml create mode 100644 calamus-engine/src/main/resources/db/postgresql-jbpm-schema.sql create mode 100644 calamus-engine/src/main/resources/db/quartz_tables_postgres.sql create mode 100644 calamus-engine/src/main/resources/jndi.properties create mode 100644 calamus-engine/src/test/java/io/trygvis/engine/MyTest.java (limited to 'calamus-engine') diff --git a/calamus-engine/pom.xml b/calamus-engine/pom.xml new file mode 100755 index 0000000..4923295 --- /dev/null +++ b/calamus-engine/pom.xml @@ -0,0 +1,390 @@ + + 4.0.0 + + io.trygvis.calamus + calamus + 1.0-SNAPSHOT + + io.trygvis.jbpm-sandbox + calamus-engine + + 1.8 + 1.8 + UTF-8 + + 5.9.1 + + 4.2.11.Final + 1.7.4 + 1.0.9 + 6.1.0.Beta2 + 6.1.0.Beta2 + + 1.1.0.Final + 1.0.0.Final + 3.1.0.Final + 3.2.0.Final + 1.3.161 + 2.1.4 + 1.0.0.CR7 + + + + + + org.drools + drools-bom + pom + ${drools.version} + import + + + org.jbpm + jbpm-bom + pom + ${drools.version} + import + + + org.jboss.arquillian + arquillian-bom + 1.1.0.Final + import + pom + + + + org.hibernate + hibernate-entitymanager + ${hibernate.version} + + + org.hibernate + hibernate-core + ${hibernate.version} + + + commons-io + commons-io + 2.1 + + + commons-codec + commons-codec + 1.4 + + + org.apache.maven.wagon + wagon-provider-api + 2.4 + + + javax.activation + activation + 1.1.1 + + + + org.slf4j + slf4j-api + ${slf4j.version} + + + org.slf4j + jcl-over-slf4j + ${slf4j.version} + + + + javax.enterprise + cdi-api + 1.1-20130918 + + + + junit + junit + 4.11 + + + org.apache.httpcomponents + httpcore + 4.1.2 + + + org.javassist + javassist + 3.18.1-GA + + + org.codehaus.plexus + plexus-utils + 3.0.8 + + + org.sonatype.sisu + sisu-inject-plexus + 2.3.0 + + + org.jboss.logging + jboss-logging + 3.1.0.GA + + + + + + + + + org.apache.activemq + activemq-client + ${version.activemq} + + + org.apache.activemq + activemq-pool + ${version.activemq} + + + + org.kie + kie-api + + + org.jbpm + jbpm-flow + + + org.jbpm + jbpm-bpmn2 + + + org.jbpm + jbpm-flow-builder + + + org.jbpm + jbpm-runtime-manager + + + javax.transaction + jta + + + org.hibernate.javax.persistence + hibernate-jpa-2.0-api + + + commons-logging + commons-logging + + + + + org.jbpm + jbpm-human-task-core + + + org.hibernate.javax.persistence + hibernate-jpa-2.0-api + + + + + org.jbpm + jbpm-workitems + ${jbpm.version} + + + commons-logging + commons-logging + + + + + org.jbpm + jbpm-audit + + + org.hibernate.javax.persistence + hibernate-jpa-2.0-api + + + + + + org.jbpm + jbpm-shared-services + ${jbpm.version} + + + javax.transaction + jta + + + org.hibernate.javax.persistence + hibernate-jpa-2.0-api + + + + + org.jbpm + jbpm-test + + + javax.transaction + jta + + + org.hibernate.javax.persistence + hibernate-jpa-2.0-api + + + + + + org.slf4j + slf4j-api + + + org.slf4j + jcl-over-slf4j + + + ch.qos.logback + logback-classic + 1.0.9 + + + javax.enterprise + cdi-api + + + org.jboss.weld.se + weld-se-core + 1.1.13.Final + + + org.hibernate + hibernate-entitymanager + + + org.hibernate + hibernate-core + + + com.h2database + h2 + 1.3.168 + + + org.postgresql + postgresql + 9.3-1101-jdbc41 + + + org.codehaus.btm + btm + ${btm.version} + + + javax.transaction + jta + + + + + + + + + junit + junit + + + + + + + + org.apache.maven.plugins + maven-enforcer-plugin + + + + enforce + + + + + + + org.hibernate.javax.persistence:hibernate-jpa-2.1-api + javax.transaction:jta + commons-logging:commons-logging + org.slf4j:slf4j-log4j12 + log4j:log4j + postgresql:postgresql + + + + + + + + + + diff --git a/calamus-engine/src/main/java/io/trygvis/engine/CalamusJbpm.java b/calamus-engine/src/main/java/io/trygvis/engine/CalamusJbpm.java new file mode 100644 index 0000000..0a7be62 --- /dev/null +++ b/calamus-engine/src/main/java/io/trygvis/engine/CalamusJbpm.java @@ -0,0 +1,69 @@ +package io.trygvis.engine; + +import bitronix.tm.TransactionManagerServices; +import bitronix.tm.resource.jdbc.PoolingDataSource; +import org.jbpm.bpmn2.handler.ServiceTaskHandler; +import org.jbpm.process.audit.AuditLoggerFactory; +import org.kie.api.KieBase; +import org.kie.api.runtime.Environment; +import org.kie.api.runtime.EnvironmentName; +import org.kie.api.runtime.process.ProcessInstance; +import org.kie.internal.KnowledgeBaseFactory; +import org.kie.internal.io.ResourceFactory; +import org.kie.internal.persistence.jpa.JPAKnowledgeService; +import org.kie.internal.runtime.StatefulKnowledgeSession; +import org.kie.internal.utils.KieHelper; + +import javax.persistence.EntityManagerFactory; +import javax.persistence.Persistence; + +public class CalamusJbpm { + private final StatefulKnowledgeSession session; + + public static enum CalamusProcess { + DEPLOY("io.trygvis.bpm.Deploy"); + + private String name; + + CalamusProcess(String name) { + this.name = name; + } + } + + public CalamusJbpm() { + PoolingDataSource ds = new PoolingDataSource(); + ds.setUniqueName("jdbc/jbpm-ds"); + ds.setClassName(bitronix.tm.resource.jdbc.lrc.LrcXADataSource.class.getCanonicalName()); + ds.setMaxPoolSize(3); + ds.setAllowLocalTransactions(true); + ds.getDriverProperties().put("user", "jbpm"); + ds.getDriverProperties().put("password", "jbpm"); + ds.getDriverProperties().put("url", "jdbc:postgresql://localhost/jbpm"); + ds.getDriverProperties().put("driverClassName", org.postgresql.Driver.class.getCanonicalName()); + ds.init(); + + EntityManagerFactory emf = Persistence.createEntityManagerFactory("org.jbpm.persistence.jpa"); + Environment env = KnowledgeBaseFactory.newEnvironment(); + env.set(EnvironmentName.ENTITY_MANAGER_FACTORY, emf); + env.set(EnvironmentName.TRANSACTION_MANAGER, TransactionManagerServices.getTransactionManager()); + + KieBase kieBase = new KieHelper() + .addResource(ResourceFactory.newClassPathResource("Deploy.bpmn2")) + .build(); + + session = JPAKnowledgeService.newStatefulKnowledgeSession(kieBase, null, env); + session.addEventListener(AuditLoggerFactory.newJPAInstance(env)); + + session.getWorkItemManager().registerWorkItemHandler("Service Task", new ServiceTaskHandler()); + session.getWorkItemManager().registerWorkItemHandler("Upgrade App", new UpgradeAppWorkItemHandler()); + session.getWorkItemManager().registerWorkItemHandler("Restart App", new RestartAppWorkItemHandler()); + } + + public StatefulKnowledgeSession getSession() { + return session; + } + + public void startProcess(CalamusProcess process) { + ProcessInstance processInstance = session.startProcess(process.name); + } +} diff --git a/calamus-engine/src/main/java/io/trygvis/engine/Main.java b/calamus-engine/src/main/java/io/trygvis/engine/Main.java new file mode 100644 index 0000000..bc322e8 --- /dev/null +++ b/calamus-engine/src/main/java/io/trygvis/engine/Main.java @@ -0,0 +1,13 @@ +package io.trygvis.engine; + +import static io.trygvis.engine.CalamusJbpm.CalamusProcess.DEPLOY; + +public class Main { + public static void main(String[] args) { + CalamusJbpm jbpm = new CalamusJbpm(); + + MqClient mqClient = new MqClient(jbpm.getSession(), "tcp://localhost:61616"); + + jbpm.startProcess(DEPLOY); + } +} diff --git a/calamus-engine/src/main/java/io/trygvis/engine/MqClient.java b/calamus-engine/src/main/java/io/trygvis/engine/MqClient.java new file mode 100644 index 0000000..b609c9f --- /dev/null +++ b/calamus-engine/src/main/java/io/trygvis/engine/MqClient.java @@ -0,0 +1,73 @@ +package io.trygvis.engine; + +import org.apache.activemq.ActiveMQConnectionFactory; +import org.kie.internal.runtime.StatefulKnowledgeSession; + +import javax.jms.Connection; +import javax.jms.Destination; +import javax.jms.JMSException; +import javax.jms.MapMessage; +import javax.jms.Message; +import javax.jms.MessageConsumer; +import javax.jms.MessageListener; +import javax.jms.Session; + +import static javax.jms.Session.AUTO_ACKNOWLEDGE; + +public class MqClient implements AutoCloseable { + + private Connection connection; +// private final ActiveMQConnectionFactory connectionFactory; +// private final StatefulKnowledgeSession jbpm; + + public MqClient(final StatefulKnowledgeSession jbpm, String brukerUrl) { +// this.jbpm = jbpm; + ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(brukerUrl); + + try { + connection = connectionFactory.createConnection(); + connection.start(); + + Session session = connection.createSession(false, AUTO_ACKNOWLEDGE); + + Destination destination = session.createQueue("jenkins.build-result"); + + MessageConsumer consumer = session.createConsumer(destination); + consumer.setMessageListener(new MessageListener() { + @Override + public void onMessage(Message message) { + if (!(message instanceof MapMessage)) { + return; + } + + MapMessage m = (MapMessage) message; + + try { + String jobName = m.getString("jobName"); + int buildNumber = m.getInt("buildNumber"); + String result = m.getString("result"); + +/* + String type; + Object event; + long processInstanceId; + jbpm.signalEvent(type, event, processInstanceId); +*/ + } catch (JMSException e) { + e.printStackTrace(); + } + } + }); + } catch (JMSException e) { + e.printStackTrace(); + } + } + + @Override + public void close() throws Exception { + if (connection != null) { + connection.close(); + this.connection = null; + } + } +} diff --git a/calamus-engine/src/main/java/io/trygvis/engine/RestartAppWorkItemHandler.java b/calamus-engine/src/main/java/io/trygvis/engine/RestartAppWorkItemHandler.java new file mode 100644 index 0000000..98733c7 --- /dev/null +++ b/calamus-engine/src/main/java/io/trygvis/engine/RestartAppWorkItemHandler.java @@ -0,0 +1,24 @@ +package io.trygvis.engine; + +import org.kie.api.runtime.process.WorkItem; +import org.kie.api.runtime.process.WorkItemHandler; +import org.kie.api.runtime.process.WorkItemManager; + +import java.util.HashMap; +import java.util.Map; + +public class RestartAppWorkItemHandler implements WorkItemHandler { + + @Override + public void executeWorkItem(WorkItem workItem, WorkItemManager manager) { + System.out.println("RestartAppWorkItemHandler.executeWorkItem"); + + Map results = new HashMap<>(); + manager.completeWorkItem(workItem.getId(), results); + } + + @Override + public void abortWorkItem(WorkItem workItem, WorkItemManager manager) { + System.out.println("RestartAppWorkItemHandler.abortWorkItem"); + } +} diff --git a/calamus-engine/src/main/java/io/trygvis/engine/UpgradeAppWorkItemHandler.java b/calamus-engine/src/main/java/io/trygvis/engine/UpgradeAppWorkItemHandler.java new file mode 100644 index 0000000..6202d6b --- /dev/null +++ b/calamus-engine/src/main/java/io/trygvis/engine/UpgradeAppWorkItemHandler.java @@ -0,0 +1,24 @@ +package io.trygvis.engine; + +import org.kie.api.runtime.process.WorkItem; +import org.kie.api.runtime.process.WorkItemHandler; +import org.kie.api.runtime.process.WorkItemManager; + +import java.util.HashMap; +import java.util.Map; + +public class UpgradeAppWorkItemHandler implements WorkItemHandler { + + @Override + public void executeWorkItem(WorkItem workItem, WorkItemManager manager) { + System.out.println("UpgradeAppWorkItemHandler.executeWorkItem"); + + Map results = new HashMap<>(); + manager.completeWorkItem(workItem.getId(), results); + } + + @Override + public void abortWorkItem(WorkItem workItem, WorkItemManager manager) { + System.out.println("UpgradeAppWorkItemHandler.abortWorkItem"); + } +} diff --git a/calamus-engine/src/main/java/io/trygvis/engine/service/AppInstance.java b/calamus-engine/src/main/java/io/trygvis/engine/service/AppInstance.java new file mode 100644 index 0000000..0badb8c --- /dev/null +++ b/calamus-engine/src/main/java/io/trygvis/engine/service/AppInstance.java @@ -0,0 +1,7 @@ +package io.trygvis.engine.service; + +public class AppInstance { + private String name; + private String host; + private String path; +} diff --git a/calamus-engine/src/main/java/io/trygvis/engine/service/AppService.java b/calamus-engine/src/main/java/io/trygvis/engine/service/AppService.java new file mode 100644 index 0000000..3ccde2b --- /dev/null +++ b/calamus-engine/src/main/java/io/trygvis/engine/service/AppService.java @@ -0,0 +1,15 @@ +package io.trygvis.engine.service; + +public class AppService { + public void installApp(AppInstance instance) { + System.out.println("AppService.installApp"); + } + + public void restartApp(AppInstance instance) { + System.out.println("AppService.restartApp"); + } + + public void waitForUp(AppInstance instance) { + System.out.println("AppService.waitForAppUp"); + } +} diff --git a/calamus-engine/src/main/resources/Deploy.bpmn2 b/calamus-engine/src/main/resources/Deploy.bpmn2 new file mode 100644 index 0000000..2e29859 --- /dev/null +++ b/calamus-engine/src/main/resources/Deploy.bpmn2 @@ -0,0 +1,132 @@ + + + + + + + + + + AppInstance + + + AppInstance + + + AppInstance + + + + asd + + + + + + + SequenceFlow_1 + + + + + SequenceFlow_1 + SequenceFlow_3 + + + + + _DataInput_18 + _DataInput_19 + + + + + _DataInput_18 + + + _DataInput_19 + + + + + SequenceFlow_3 + SequenceFlow_4 + + + + + _DataInput_20 + _DataInput_21 + + + + + _DataInput_20 + + + _DataInput_21 + + + + + SequenceFlow_4 + SequenceFlow_5 + + + DataOutput_4 + appInstance + + + DataOutput_4 + + + + + + SequenceFlow_5 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/calamus-engine/src/main/resources/META-INF/AppctlWorkDefinitions.wid b/calamus-engine/src/main/resources/META-INF/AppctlWorkDefinitions.wid new file mode 100644 index 0000000..62ce4a1 --- /dev/null +++ b/calamus-engine/src/main/resources/META-INF/AppctlWorkDefinitions.wid @@ -0,0 +1,19 @@ +import org.drools.core.process.core.datatype.impl.type.StringDataType; +[ + [ + "name" : "Upgrade App", + "parameters" : [ + "Host" : new StringDataType(), + "Path" : new StringDataType(), + ], + "displayName" : "Upgrade app" + ], + [ + "name" : "Restart App", + "parameters" : [ + "Host" : new StringDataType(), + "Path" : new StringDataType(), + ], + "displayName" : "Restart app" + ] +] diff --git a/calamus-engine/src/main/resources/META-INF/persistence.xml b/calamus-engine/src/main/resources/META-INF/persistence.xml new file mode 100644 index 0000000..a8a11af --- /dev/null +++ b/calamus-engine/src/main/resources/META-INF/persistence.xml @@ -0,0 +1,31 @@ + + + + org.hibernate.ejb.HibernatePersistence + jdbc/jbpm-ds + META-INF/JBPMorm.xml + org.drools.persistence.info.SessionInfo + org.drools.persistence.info.WorkItemInfo + org.jbpm.persistence.processinstance.ProcessInstanceInfo + org.jbpm.persistence.correlation.CorrelationKeyInfo + org.jbpm.persistence.correlation.CorrelationPropertyInfo + org.jbpm.process.audit.ProcessInstanceLog + org.jbpm.process.audit.NodeInstanceLog + org.jbpm.process.audit.VariableInstanceLog + org.jbpm.runtime.manager.impl.jpa.ContextMappingInfo + + + + + + + + + + diff --git a/calamus-engine/src/main/resources/db/postgresql-jbpm-schema.sql b/calamus-engine/src/main/resources/db/postgresql-jbpm-schema.sql new file mode 100644 index 0000000..e13e6fb --- /dev/null +++ b/calamus-engine/src/main/resources/db/postgresql-jbpm-schema.sql @@ -0,0 +1,633 @@ +CREATE TABLE Attachment ( + AttachmentId INT8 NOT NULL, + accessType INT4, + attachedAt TIMESTAMP, + attachmentContentId INT8 NOT NULL, + contentType VARCHAR(255), + name VARCHAR(255), + attachment_size INT4, + attachedBy_id VARCHAR(255), + TaskData_Attachments_Id INT8, + PRIMARY KEY (AttachmentId) +); + +CREATE TABLE BAMTaskSummary ( + BAMTaskId INT8 NOT NULL, + createdDate TIMESTAMP, + duration INT8, + endDate TIMESTAMP, + processInstanceId INT8 NOT NULL, + startDate TIMESTAMP, + status VARCHAR(255), + taskId INT8 NOT NULL, + taskName VARCHAR(255), + userId VARCHAR(255), + PRIMARY KEY (BAMTaskId) +); + +CREATE TABLE BooleanExpression ( + id INT8 NOT NULL, + expression TEXT, + type VARCHAR(255), + Escalation_Constraints_Id INT8, + PRIMARY KEY (id) +); + +CREATE TABLE Content ( + id INT8 NOT NULL, + content OID, +-- content BYTEA, + PRIMARY KEY (id) +); + +CREATE TABLE ContextMappingInfo ( + mappingId INT8 NOT NULL, + CONTEXT_ID VARCHAR(255) NOT NULL, + KSESSION_ID INT4 NOT NULL, + OPTLOCK INT4, + PRIMARY KEY (mappingId) +); + +CREATE TABLE CorrelationKeyInfo ( + keyId INT8 NOT NULL, + name VARCHAR(255), + processInstanceId INT8 NOT NULL, + OPTLOCK INT4, + PRIMARY KEY (keyId) +); + +CREATE TABLE CorrelationPropertyInfo ( + propertyId INT8 NOT NULL, + name VARCHAR(255), + value VARCHAR(255), + OPTLOCK INT4, + correlationKey_keyId INT8, + PRIMARY KEY (propertyId) +); + +CREATE TABLE Deadline ( + id INT8 NOT NULL, + deadline_date TIMESTAMP, + escalated INT2, + Deadlines_StartDeadLine_Id INT8, + Deadlines_EndDeadLine_Id INT8, + PRIMARY KEY (id) +); + +CREATE TABLE Delegation_delegates ( + task_id INT8 NOT NULL, + entity_id VARCHAR(255) NOT NULL +); + +CREATE TABLE ErrorInfo ( + id INT8 NOT NULL, + message VARCHAR(255), + stacktrace VARCHAR(5000), + timestamp TIMESTAMP, + REQUEST_ID INT8 NOT NULL, + PRIMARY KEY (id) +); + +CREATE TABLE Escalation ( + id INT8 NOT NULL, + name VARCHAR(255), + Deadline_Escalation_Id INT8, + PRIMARY KEY (id) +); + +CREATE TABLE EventTypes ( + InstanceId INT8 NOT NULL, + eventTypes VARCHAR(255) +); + +CREATE TABLE I18NText ( + I18NTextId INT8 NOT NULL, + language VARCHAR(255), + shortText VARCHAR(255), + text TEXT, + Task_Subjects_Id INT8, + Task_Names_Id INT8, + Task_Descriptions_Id INT8, + Reassignment_Documentation_Id INT8, + Notification_Subjects_Id INT8, + Notification_Names_Id INT8, + Notification_Documentation_Id INT8, + Notification_Descriptions_Id INT8, + Deadline_Documentation_Id INT8, + PRIMARY KEY (I18NTextId) +); + +CREATE TABLE NodeInstanceLog ( + id INT8 NOT NULL, + connection VARCHAR(255), + log_date TIMESTAMP, + externalId VARCHAR(255), + nodeId VARCHAR(255), + nodeInstanceId VARCHAR(255), + nodeName VARCHAR(255), + nodeType VARCHAR(255), + processId VARCHAR(255), + processInstanceId INT8 NOT NULL, + type INT4 NOT NULL, + workItemId INT8, + PRIMARY KEY (id) +); + +CREATE TABLE Notification ( + DTYPE VARCHAR(31) NOT NULL, + NotificationId INT8 NOT NULL, + priority INT4 NOT NULL, + Escalation_Notifications_Id INT8, + PRIMARY KEY (NotificationId) +); + +CREATE TABLE Notification_BAs ( + task_id INT8 NOT NULL, + entity_id VARCHAR(255) NOT NULL +); + +CREATE TABLE Notification_Recipients ( + task_id INT8 NOT NULL, + entity_id VARCHAR(255) NOT NULL +); + +CREATE TABLE Notification_email_header ( + Notification_NotificationId INT8 NOT NULL, + emailHeaders_id INT8 NOT NULL, + mapkey VARCHAR(255) NOT NULL, + PRIMARY KEY (Notification_NotificationId, mapkey) +); + +CREATE TABLE OrganizationalEntity ( + DTYPE VARCHAR(31) NOT NULL, + id VARCHAR(255) NOT NULL, + PRIMARY KEY (id) +); + +CREATE TABLE PeopleAssignments_BAs ( + task_id INT8 NOT NULL, + entity_id VARCHAR(255) NOT NULL +); + +CREATE TABLE PeopleAssignments_ExclOwners ( + task_id INT8 NOT NULL, + entity_id VARCHAR(255) NOT NULL +); + +CREATE TABLE PeopleAssignments_PotOwners ( + task_id INT8 NOT NULL, + entity_id VARCHAR(255) NOT NULL +); + +CREATE TABLE PeopleAssignments_Recipients ( + task_id INT8 NOT NULL, + entity_id VARCHAR(255) NOT NULL +); + +CREATE TABLE PeopleAssignments_Stakeholders ( + task_id INT8 NOT NULL, + entity_id VARCHAR(255) NOT NULL +); + +CREATE TABLE ProcessInstanceInfo ( + InstanceId INT8 NOT NULL, + lastModificationDate TIMESTAMP, + lastReadDate TIMESTAMP, + processId VARCHAR(255), + processInstanceByteArray OID, +-- processInstanceByteArray BYTEA, + startDate TIMESTAMP, + state INT4 NOT NULL, + OPTLOCK INT4, + PRIMARY KEY (InstanceId) +); + +CREATE TABLE ProcessInstanceLog ( + id INT8 NOT NULL, + duration INT8, + end_date TIMESTAMP, + externalId VARCHAR(255), + user_identity VARCHAR(255), + outcome VARCHAR(255), + parentProcessInstanceId INT8, + processId VARCHAR(255), + processInstanceId INT8 NOT NULL, + processName VARCHAR(255), + processVersion VARCHAR(255), + start_date TIMESTAMP, + status INT4, + PRIMARY KEY (id) +); + +CREATE TABLE Reassignment ( + id INT8 NOT NULL, + Escalation_Reassignments_Id INT8, + PRIMARY KEY (id) +); + +CREATE TABLE Reassignment_potentialOwners ( + task_id INT8 NOT NULL, + entity_id VARCHAR(255) NOT NULL +); + +CREATE TABLE RequestInfo ( + id INT8 NOT NULL, + commandName VARCHAR(255), + deploymentId VARCHAR(255), + executions INT4 NOT NULL, + businessKey VARCHAR(255), + message VARCHAR(255), + requestData OID, +-- requestData BYTEA, + responseData OID, +-- responseData BYTEA, + retries INT4 NOT NULL, + status VARCHAR(255), + timestamp TIMESTAMP, + PRIMARY KEY (id) +); + +CREATE TABLE SessionInfo ( + id INT4 NOT NULL, + lastModificationDate TIMESTAMP, + rulesByteArray OID, +-- rulesByteArray BYTEA, + startDate TIMESTAMP, + OPTLOCK INT4, + PRIMARY KEY (id) +); + +CREATE TABLE Task ( + TaskId INT8 NOT NULL, + archived INT2, + allowedToDelegate VARCHAR(255), + formName VARCHAR(255), + priority INT4 NOT NULL, + subTaskStrategy VARCHAR(255), + activationTime TIMESTAMP, + createdOn TIMESTAMP, + deploymentId VARCHAR(255), + documentAccessType INT4, + documentContentId INT8 NOT NULL, + documentType VARCHAR(255), + expirationTime TIMESTAMP, + faultAccessType INT4, + faultContentId INT8 NOT NULL, + faultName VARCHAR(255), + faultType VARCHAR(255), + outputAccessType INT4, + outputContentId INT8 NOT NULL, + outputType VARCHAR(255), + parentId INT8 NOT NULL, + previousStatus INT4, + processId VARCHAR(255), + processInstanceId INT8 NOT NULL, + processSessionId INT4 NOT NULL, + skipable BOOLEAN NOT NULL, + status VARCHAR(255), + workItemId INT8 NOT NULL, + taskType VARCHAR(255), + OPTLOCK INT4, + taskInitiator_id VARCHAR(255), + actualOwner_id VARCHAR(255), + createdBy_id VARCHAR(255), + PRIMARY KEY (TaskId) +); + +CREATE TABLE TaskDef ( + TaskDefId INT8 NOT NULL, + name VARCHAR(255), + priority INT4 NOT NULL, + PRIMARY KEY (TaskDefId) +); + +CREATE TABLE TaskEvent ( + id INT8 NOT NULL, + logTime TIMESTAMP, + taskId INT8, + type VARCHAR(255), + userId VARCHAR(255), + PRIMARY KEY (id) +); + +CREATE TABLE VariableInstanceLog ( + id INT8 NOT NULL, + log_date TIMESTAMP, + externalId VARCHAR(255), + oldValue VARCHAR(255), + processId VARCHAR(255), + processInstanceId INT8 NOT NULL, + value VARCHAR(255), + variableId VARCHAR(255), + variableInstanceId VARCHAR(255), + PRIMARY KEY (id) +); + +CREATE TABLE WorkItemInfo ( + workItemId INT8 NOT NULL, + creationDate TIMESTAMP, + name VARCHAR(255), + processInstanceId INT8 NOT NULL, + state INT8 NOT NULL, + OPTLOCK INT4, + workItemByteArray OID, +-- workItemByteArray BYTEA, + PRIMARY KEY (workItemId) +); + +CREATE TABLE email_header ( + id INT8 NOT NULL, + body TEXT, + fromAddress VARCHAR(255), + language VARCHAR(255), + replyToAddress VARCHAR(255), + subject VARCHAR(255), + PRIMARY KEY (id) +); + +CREATE TABLE task_comment ( + id INT8 NOT NULL, + addedAt TIMESTAMP, + text TEXT, + addedBy_id VARCHAR(255), + TaskData_Comments_Id INT8, + PRIMARY KEY (id) +); + +ALTER TABLE Attachment +ADD CONSTRAINT FK1C93543D937BFB5 +FOREIGN KEY (attachedBy_id) +REFERENCES OrganizationalEntity; + +ALTER TABLE Attachment +ADD CONSTRAINT FK1C9354333CA892A +FOREIGN KEY (TaskData_Attachments_Id) +REFERENCES Task; + +ALTER TABLE BooleanExpression +ADD CONSTRAINT FKE3D208C06C97C90E +FOREIGN KEY (Escalation_Constraints_Id) +REFERENCES Escalation; + +ALTER TABLE CorrelationPropertyInfo +ADD CONSTRAINT FK761452A5D87156ED +FOREIGN KEY (correlationKey_keyId) +REFERENCES CorrelationKeyInfo; + +ALTER TABLE Deadline +ADD CONSTRAINT FK21DF3E78A9FE0EF4 +FOREIGN KEY (Deadlines_StartDeadLine_Id) +REFERENCES Task; + +ALTER TABLE Deadline +ADD CONSTRAINT FK21DF3E78695E4DDB +FOREIGN KEY (Deadlines_EndDeadLine_Id) +REFERENCES Task; + +ALTER TABLE Delegation_delegates +ADD CONSTRAINT FK47485D5772B3A123 +FOREIGN KEY (entity_id) +REFERENCES OrganizationalEntity; + +ALTER TABLE Delegation_delegates +ADD CONSTRAINT FK47485D57786553A5 +FOREIGN KEY (task_id) +REFERENCES Task; + +ALTER TABLE ErrorInfo +ADD CONSTRAINT FK8B1186B6724A467 +FOREIGN KEY (REQUEST_ID) +REFERENCES RequestInfo; + +ALTER TABLE Escalation +ADD CONSTRAINT FK67B2C6B5D1E5CC1 +FOREIGN KEY (Deadline_Escalation_Id) +REFERENCES Deadline; + +ALTER TABLE EventTypes +ADD CONSTRAINT FKB0E5621F7665489A +FOREIGN KEY (InstanceId) +REFERENCES ProcessInstanceInfo; + +ALTER TABLE I18NText +ADD CONSTRAINT FK2349686BF4ACCD69 +FOREIGN KEY (Task_Subjects_Id) +REFERENCES Task; + +ALTER TABLE I18NText +ADD CONSTRAINT FK2349686B424B187C +FOREIGN KEY (Task_Names_Id) +REFERENCES Task; + +ALTER TABLE I18NText +ADD CONSTRAINT FK2349686BAB648139 +FOREIGN KEY (Task_Descriptions_Id) +REFERENCES Task; + +ALTER TABLE I18NText +ADD CONSTRAINT FK2349686BB340A2AA +FOREIGN KEY (Reassignment_Documentation_Id) +REFERENCES Reassignment; + +ALTER TABLE I18NText +ADD CONSTRAINT FK2349686BF0CDED35 +FOREIGN KEY (Notification_Subjects_Id) +REFERENCES Notification; + +ALTER TABLE I18NText +ADD CONSTRAINT FK2349686BCC03ED3C +FOREIGN KEY (Notification_Names_Id) +REFERENCES Notification; + +ALTER TABLE I18NText +ADD CONSTRAINT FK2349686B77C1C08A +FOREIGN KEY (Notification_Documentation_Id) +REFERENCES Notification; + +ALTER TABLE I18NText +ADD CONSTRAINT FK2349686B18DDFE05 +FOREIGN KEY (Notification_Descriptions_Id) +REFERENCES Notification; + +ALTER TABLE I18NText +ADD CONSTRAINT FK2349686B78AF072A +FOREIGN KEY (Deadline_Documentation_Id) +REFERENCES Deadline; + +ALTER TABLE Notification +ADD CONSTRAINT FK2D45DD0BC0C0F29C +FOREIGN KEY (Escalation_Notifications_Id) +REFERENCES Escalation; + +ALTER TABLE Notification_BAs +ADD CONSTRAINT FK2DD68EE072B3A123 +FOREIGN KEY (entity_id) +REFERENCES OrganizationalEntity; + +ALTER TABLE Notification_BAs +ADD CONSTRAINT FK2DD68EE093F2090B +FOREIGN KEY (task_id) +REFERENCES Notification; + +ALTER TABLE Notification_Recipients +ADD CONSTRAINT FK98FD214E72B3A123 +FOREIGN KEY (entity_id) +REFERENCES OrganizationalEntity; + +ALTER TABLE Notification_Recipients +ADD CONSTRAINT FK98FD214E93F2090B +FOREIGN KEY (task_id) +REFERENCES Notification; + +ALTER TABLE Notification_email_header +ADD CONSTRAINT UK_F30FE3446CEA0510 UNIQUE (emailHeaders_id); + +ALTER TABLE Notification_email_header +ADD CONSTRAINT FKF30FE3448BED1339 +FOREIGN KEY (emailHeaders_id) +REFERENCES email_header; + +ALTER TABLE Notification_email_header +ADD CONSTRAINT FKF30FE344DD2D7416 +FOREIGN KEY (Notification_NotificationId) +REFERENCES Notification; + +ALTER TABLE PeopleAssignments_BAs +ADD CONSTRAINT FK9D8CF4EC72B3A123 +FOREIGN KEY (entity_id) +REFERENCES OrganizationalEntity; + +ALTER TABLE PeopleAssignments_BAs +ADD CONSTRAINT FK9D8CF4EC786553A5 +FOREIGN KEY (task_id) +REFERENCES Task; + +ALTER TABLE PeopleAssignments_ExclOwners +ADD CONSTRAINT FKC77B97E472B3A123 +FOREIGN KEY (entity_id) +REFERENCES OrganizationalEntity; + +ALTER TABLE PeopleAssignments_ExclOwners +ADD CONSTRAINT FKC77B97E4786553A5 +FOREIGN KEY (task_id) +REFERENCES Task; + +ALTER TABLE PeopleAssignments_PotOwners +ADD CONSTRAINT FK1EE418D72B3A123 +FOREIGN KEY (entity_id) +REFERENCES OrganizationalEntity; + +ALTER TABLE PeopleAssignments_PotOwners +ADD CONSTRAINT FK1EE418D786553A5 +FOREIGN KEY (task_id) +REFERENCES Task; + +ALTER TABLE PeopleAssignments_Recipients +ADD CONSTRAINT FKC6F615C272B3A123 +FOREIGN KEY (entity_id) +REFERENCES OrganizationalEntity; + +ALTER TABLE PeopleAssignments_Recipients +ADD CONSTRAINT FKC6F615C2786553A5 +FOREIGN KEY (task_id) +REFERENCES Task; + +ALTER TABLE PeopleAssignments_Stakeholders +ADD CONSTRAINT FK482F79D572B3A123 +FOREIGN KEY (entity_id) +REFERENCES OrganizationalEntity; + +ALTER TABLE PeopleAssignments_Stakeholders +ADD CONSTRAINT FK482F79D5786553A5 +FOREIGN KEY (task_id) +REFERENCES Task; + +ALTER TABLE Reassignment +ADD CONSTRAINT FK724D056062A1E871 +FOREIGN KEY (Escalation_Reassignments_Id) +REFERENCES Escalation; + +ALTER TABLE Reassignment_potentialOwners +ADD CONSTRAINT FK90B59CFF72B3A123 +FOREIGN KEY (entity_id) +REFERENCES OrganizationalEntity; + +ALTER TABLE Reassignment_potentialOwners +ADD CONSTRAINT FK90B59CFF35D2FEE0 +FOREIGN KEY (task_id) +REFERENCES Reassignment; + +ALTER TABLE Task +ADD CONSTRAINT FK27A9A53C55C806 +FOREIGN KEY (taskInitiator_id) +REFERENCES OrganizationalEntity; + +ALTER TABLE Task +ADD CONSTRAINT FK27A9A5B723BE8B +FOREIGN KEY (actualOwner_id) +REFERENCES OrganizationalEntity; + +ALTER TABLE Task +ADD CONSTRAINT FK27A9A55427E8F1 +FOREIGN KEY (createdBy_id) +REFERENCES OrganizationalEntity; + +ALTER TABLE task_comment +ADD CONSTRAINT FK61F475A57A3215D9 +FOREIGN KEY (addedBy_id) +REFERENCES OrganizationalEntity; + +ALTER TABLE task_comment +ADD CONSTRAINT FK61F475A5F510CB46 +FOREIGN KEY (TaskData_Comments_Id) +REFERENCES Task; + +CREATE SEQUENCE ATTACHMENT_ID_SEQ; + +CREATE SEQUENCE BAM_TASK_ID_SEQ; + +CREATE SEQUENCE BOOLEANEXPR_ID_SEQ; + +CREATE SEQUENCE COMMENT_ID_SEQ; + +CREATE SEQUENCE CONTENT_ID_SEQ; + +CREATE SEQUENCE CONTEXT_MAPPING_INFO_ID_SEQ; + +CREATE SEQUENCE CORRELATION_KEY_ID_SEQ; + +CREATE SEQUENCE CORRELATION_PROP_ID_SEQ; + +CREATE SEQUENCE DEADLINE_ID_SEQ; + +CREATE SEQUENCE EMAILNOTIFHEAD_ID_SEQ; + +CREATE SEQUENCE ERROR_INFO_ID_SEQ; + +CREATE SEQUENCE ESCALATION_ID_SEQ; + +CREATE SEQUENCE I18NTEXT_ID_SEQ; + +CREATE SEQUENCE NODE_INST_LOG_ID_SEQ; + +CREATE SEQUENCE NOTIFICATION_ID_SEQ; + +CREATE SEQUENCE PROCESS_INSTANCE_INFO_ID_SEQ; + +CREATE SEQUENCE PROC_INST_LOG_ID_SEQ; + +CREATE SEQUENCE REASSIGNMENT_ID_SEQ; + +CREATE SEQUENCE REQUEST_INFO_ID_SEQ; + +CREATE SEQUENCE SESSIONINFO_ID_SEQ; + +CREATE SEQUENCE TASK_DEF_ID_SEQ; + +CREATE SEQUENCE TASK_EVENT_ID_SEQ; + +CREATE SEQUENCE TASK_ID_SEQ; + +CREATE SEQUENCE VAR_INST_LOG_ID_SEQ; + +CREATE SEQUENCE WORKITEMINFO_ID_SEQ; diff --git a/calamus-engine/src/main/resources/db/quartz_tables_postgres.sql b/calamus-engine/src/main/resources/db/quartz_tables_postgres.sql new file mode 100644 index 0000000..fd4466f --- /dev/null +++ b/calamus-engine/src/main/resources/db/quartz_tables_postgres.sql @@ -0,0 +1,165 @@ +-- Thanks to Patrick Lightbody for submitting this... +-- +-- In your Quartz properties file, you'll need to set +-- org.quartz.jobStore.driverDelegateClass = org.quartz.impl.jdbcjobstore.PostgreSQLDelegate + + +CREATE TABLE qrtz_job_details + ( + JOB_NAME VARCHAR(200) NOT NULL, + JOB_GROUP VARCHAR(200) NOT NULL, + DESCRIPTION VARCHAR(250) NULL, + JOB_CLASS_NAME VARCHAR(250) NOT NULL, + IS_DURABLE BOOL NOT NULL, + IS_VOLATILE BOOL NOT NULL, + IS_STATEFUL BOOL NOT NULL, + REQUESTS_RECOVERY BOOL NOT NULL, + JOB_DATA BYTEA NULL, + PRIMARY KEY (JOB_NAME,JOB_GROUP) +); + +CREATE TABLE qrtz_job_listeners + ( + JOB_NAME VARCHAR(200) NOT NULL, + JOB_GROUP VARCHAR(200) NOT NULL, + JOB_LISTENER VARCHAR(200) NOT NULL, + PRIMARY KEY (JOB_NAME,JOB_GROUP,JOB_LISTENER), + FOREIGN KEY (JOB_NAME,JOB_GROUP) + REFERENCES QRTZ_JOB_DETAILS(JOB_NAME,JOB_GROUP) +); + +CREATE TABLE qrtz_triggers + ( + TRIGGER_NAME VARCHAR(200) NOT NULL, + TRIGGER_GROUP VARCHAR(200) NOT NULL, + JOB_NAME VARCHAR(200) NOT NULL, + JOB_GROUP VARCHAR(200) NOT NULL, + IS_VOLATILE BOOL NOT NULL, + DESCRIPTION VARCHAR(250) NULL, + NEXT_FIRE_TIME BIGINT NULL, + PREV_FIRE_TIME BIGINT NULL, + PRIORITY INTEGER NULL, + TRIGGER_STATE VARCHAR(16) NOT NULL, + TRIGGER_TYPE VARCHAR(8) NOT NULL, + START_TIME BIGINT NOT NULL, + END_TIME BIGINT NULL, + CALENDAR_NAME VARCHAR(200) NULL, + MISFIRE_INSTR SMALLINT NULL, + JOB_DATA BYTEA NULL, + PRIMARY KEY (TRIGGER_NAME,TRIGGER_GROUP), + FOREIGN KEY (JOB_NAME,JOB_GROUP) + REFERENCES QRTZ_JOB_DETAILS(JOB_NAME,JOB_GROUP) +); + +CREATE TABLE qrtz_simple_triggers + ( + TRIGGER_NAME VARCHAR(200) NOT NULL, + TRIGGER_GROUP VARCHAR(200) NOT NULL, + REPEAT_COUNT BIGINT NOT NULL, + REPEAT_INTERVAL BIGINT NOT NULL, + TIMES_TRIGGERED BIGINT NOT NULL, + PRIMARY KEY (TRIGGER_NAME,TRIGGER_GROUP), + FOREIGN KEY (TRIGGER_NAME,TRIGGER_GROUP) + REFERENCES QRTZ_TRIGGERS(TRIGGER_NAME,TRIGGER_GROUP) +); + +CREATE TABLE qrtz_cron_triggers + ( + TRIGGER_NAME VARCHAR(200) NOT NULL, + TRIGGER_GROUP VARCHAR(200) NOT NULL, + CRON_EXPRESSION VARCHAR(120) NOT NULL, + TIME_ZONE_ID VARCHAR(80), + PRIMARY KEY (TRIGGER_NAME,TRIGGER_GROUP), + FOREIGN KEY (TRIGGER_NAME,TRIGGER_GROUP) + REFERENCES QRTZ_TRIGGERS(TRIGGER_NAME,TRIGGER_GROUP) +); + +CREATE TABLE qrtz_blob_triggers + ( + TRIGGER_NAME VARCHAR(200) NOT NULL, + TRIGGER_GROUP VARCHAR(200) NOT NULL, + BLOB_DATA BYTEA NULL, + PRIMARY KEY (TRIGGER_NAME,TRIGGER_GROUP), + FOREIGN KEY (TRIGGER_NAME,TRIGGER_GROUP) + REFERENCES QRTZ_TRIGGERS(TRIGGER_NAME,TRIGGER_GROUP) +); + +CREATE TABLE qrtz_trigger_listeners + ( + TRIGGER_NAME VARCHAR(200) NOT NULL, + TRIGGER_GROUP VARCHAR(200) NOT NULL, + TRIGGER_LISTENER VARCHAR(200) NOT NULL, + PRIMARY KEY (TRIGGER_NAME,TRIGGER_GROUP,TRIGGER_LISTENER), + FOREIGN KEY (TRIGGER_NAME,TRIGGER_GROUP) + REFERENCES QRTZ_TRIGGERS(TRIGGER_NAME,TRIGGER_GROUP) +); + + +CREATE TABLE qrtz_calendars + ( + CALENDAR_NAME VARCHAR(200) NOT NULL, + CALENDAR BYTEA NOT NULL, + PRIMARY KEY (CALENDAR_NAME) +); + + +CREATE TABLE qrtz_paused_trigger_grps + ( + TRIGGER_GROUP VARCHAR(200) NOT NULL, + PRIMARY KEY (TRIGGER_GROUP) +); + +CREATE TABLE qrtz_fired_triggers + ( + ENTRY_ID VARCHAR(95) NOT NULL, + TRIGGER_NAME VARCHAR(200) NOT NULL, + TRIGGER_GROUP VARCHAR(200) NOT NULL, + IS_VOLATILE BOOL NOT NULL, + INSTANCE_NAME VARCHAR(200) NOT NULL, + FIRED_TIME BIGINT NOT NULL, + PRIORITY INTEGER NOT NULL, + STATE VARCHAR(16) NOT NULL, + JOB_NAME VARCHAR(200) NULL, + JOB_GROUP VARCHAR(200) NULL, + IS_STATEFUL BOOL NULL, + REQUESTS_RECOVERY BOOL NULL, + PRIMARY KEY (ENTRY_ID) +); + +CREATE TABLE qrtz_scheduler_state + ( + INSTANCE_NAME VARCHAR(200) NOT NULL, + LAST_CHECKIN_TIME BIGINT NOT NULL, + CHECKIN_INTERVAL BIGINT NOT NULL, + PRIMARY KEY (INSTANCE_NAME) +); + +CREATE TABLE qrtz_locks + ( + LOCK_NAME VARCHAR(40) NOT NULL, + PRIMARY KEY (LOCK_NAME) +); + + +INSERT INTO qrtz_locks values('TRIGGER_ACCESS'); +INSERT INTO qrtz_locks values('JOB_ACCESS'); +INSERT INTO qrtz_locks values('CALENDAR_ACCESS'); +INSERT INTO qrtz_locks values('STATE_ACCESS'); +INSERT INTO qrtz_locks values('MISFIRE_ACCESS'); + +create index idx_qrtz_j_req_recovery on qrtz_job_details(REQUESTS_RECOVERY); +create index idx_qrtz_t_next_fire_time on qrtz_triggers(NEXT_FIRE_TIME); +create index idx_qrtz_t_state on qrtz_triggers(TRIGGER_STATE); +create index idx_qrtz_t_nft_st on qrtz_triggers(NEXT_FIRE_TIME,TRIGGER_STATE); +create index idx_qrtz_t_volatile on qrtz_triggers(IS_VOLATILE); +create index idx_qrtz_ft_trig_name on qrtz_fired_triggers(TRIGGER_NAME); +create index idx_qrtz_ft_trig_group on qrtz_fired_triggers(TRIGGER_GROUP); +create index idx_qrtz_ft_trig_nm_gp on qrtz_fired_triggers(TRIGGER_NAME,TRIGGER_GROUP); +create index idx_qrtz_ft_trig_volatile on qrtz_fired_triggers(IS_VOLATILE); +create index idx_qrtz_ft_trig_inst_name on qrtz_fired_triggers(INSTANCE_NAME); +create index idx_qrtz_ft_job_name on qrtz_fired_triggers(JOB_NAME); +create index idx_qrtz_ft_job_group on qrtz_fired_triggers(JOB_GROUP); +create index idx_qrtz_ft_job_stateful on qrtz_fired_triggers(IS_STATEFUL); +create index idx_qrtz_ft_job_req_recovery on qrtz_fired_triggers(REQUESTS_RECOVERY); + +commit; diff --git a/calamus-engine/src/main/resources/jndi.properties b/calamus-engine/src/main/resources/jndi.properties new file mode 100644 index 0000000..ae8a6fb --- /dev/null +++ b/calamus-engine/src/main/resources/jndi.properties @@ -0,0 +1 @@ +java.naming.factory.initial=bitronix.tm.jndi.BitronixInitialContextFactory diff --git a/calamus-engine/src/test/java/io/trygvis/engine/MyTest.java b/calamus-engine/src/test/java/io/trygvis/engine/MyTest.java new file mode 100644 index 0000000..8c170ea --- /dev/null +++ b/calamus-engine/src/test/java/io/trygvis/engine/MyTest.java @@ -0,0 +1,90 @@ +package io.trygvis.engine; + +import bitronix.tm.TransactionManagerServices; +import bitronix.tm.resource.jdbc.PoolingDataSource; +import org.jbpm.bpmn2.handler.ServiceTaskHandler; +import org.jbpm.process.audit.AuditLoggerFactory; +import org.junit.Before; +import org.junit.Test; +import org.kie.api.KieBase; +import org.kie.api.definition.process.Process; +import org.kie.api.runtime.Environment; +import org.kie.api.runtime.EnvironmentName; +import org.kie.api.runtime.KieSession; +import org.kie.api.runtime.process.ProcessInstance; +import org.kie.internal.KnowledgeBaseFactory; +import org.kie.internal.io.ResourceFactory; +import org.kie.internal.persistence.jpa.JPAKnowledgeService; +import org.kie.internal.runtime.StatefulKnowledgeSession; +import org.kie.internal.utils.KieHelper; + +import javax.persistence.EntityManagerFactory; +import javax.persistence.Persistence; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; + +public class MyTest { + + StatefulKnowledgeSession session; + +// @Before +// public void setUp() throws Exception { +// PoolingDataSource ds = new PoolingDataSource(); +// ds.setUniqueName("jdbc/jbpm-ds"); +// ds.setClassName(bitronix.tm.resource.jdbc.lrc.LrcXADataSource.class.getCanonicalName()); +// ds.setMaxPoolSize(3); +// ds.setAllowLocalTransactions(true); +// ds.getDriverProperties().put("user", "jbpm"); +// ds.getDriverProperties().put("password", "jbpm"); +// ds.getDriverProperties().put("url", "jdbc:postgresql://localhost/jbpm"); +// ds.getDriverProperties().put("driverClassName", org.postgresql.Driver.class.getCanonicalName()); +// ds.init(); +// +// EntityManagerFactory emf = Persistence.createEntityManagerFactory("org.jbpm.persistence.jpa"); +// Environment env = KnowledgeBaseFactory.newEnvironment(); +// env.set(EnvironmentName.ENTITY_MANAGER_FACTORY, emf); +// env.set(EnvironmentName.TRANSACTION_MANAGER, TransactionManagerServices.getTransactionManager()); +// +// KieBase kieBase = new KieHelper() +// .addResource(ResourceFactory.newClassPathResource("Deploy.bpmn2")) +// .build(); +// +// // create a new knowledge session that uses JPA to store the runtime state +// session = JPAKnowledgeService.newStatefulKnowledgeSession(kieBase, null, env); +// session.addEventListener(AuditLoggerFactory.newJPAInstance(env)); +// +// session.getWorkItemManager().registerWorkItemHandler("Service Task", new ServiceTaskHandler()); +// session.getWorkItemManager().registerWorkItemHandler("Upgrade App", new UpgradeAppWorkItemHandler()); +// session.getWorkItemManager().registerWorkItemHandler("Restart App", new RestartAppWorkItemHandler()); +// } + + @Test + public void testDeploy() { +/* + ProcessInstance processInstance = session.startProcess("io.trygvis.bpm.Deploy"); + +// assertProcessInstanceCompleted(processInstance.getId(), session); + + System.out.println("processInstance = " + processInstance); + System.out.println("processInstance.getProcessId() = " + processInstance.getProcessId()); + System.out.println("processInstance.getState() = " + processInstance.getState()); + + Process process = session.getKieBase().getProcess(processInstance.getProcessId()); + System.out.println("process = " + process); + System.out.println("process.getType() = " + process.getType()); +*/ + } + + public static void assertProcessInstanceCompleted(long processInstanceId, KieSession ksession) { + assertNull(ksession.getProcessInstance(processInstanceId)); + } + + public static void assertProcessInstanceAborted(long processInstanceId, KieSession ksession) { + assertNull(ksession.getProcessInstance(processInstanceId)); + } + + public static void assertProcessInstanceActive(long processInstanceId, KieSession ksession) { + assertNotNull(ksession.getProcessInstance(processInstanceId)); + } +} -- cgit v1.2.3