From cb0a19410ea758675e01f6093c0ad1c803b2f4e0 Mon Sep 17 00:00:00 2001 From: jensp Date: Mon, 12 Sep 2016 15:44:45 +0000 Subject: [PATCH] CCM NG: Added references from Workflow to the WorkflowTemplate used to create the workflow. git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@4293 8810af33-2d31-482b-a856-94f89814c4df --- .../main/java/org/libreccm/workflow/Workflow.java | 13 +++++++++++++ .../h2/V7_0_0_7__add_workflow_template_id.sql | 10 ++++++++++ .../pgsql/V7_0_0_7__add_workflow_template_id.sql | 10 ++++++++++ .../libreccm/workflow/EqualsAndHashCodeTest.java | 10 +++++++++- .../scripts/create_ccm_core_schema.sql | 6 ++++++ .../scripts/create_ccm_core_schema.sql | 7 ++++++- 6 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 ccm-core/src/main/resources/db/migrations/org/libreccm/ccm_core/h2/V7_0_0_7__add_workflow_template_id.sql create mode 100644 ccm-core/src/main/resources/db/migrations/org/libreccm/ccm_core/pgsql/V7_0_0_7__add_workflow_template_id.sql diff --git a/ccm-core/src/main/java/org/libreccm/workflow/Workflow.java b/ccm-core/src/main/java/org/libreccm/workflow/Workflow.java index 76603de9d..28fd30937 100644 --- a/ccm-core/src/main/java/org/libreccm/workflow/Workflow.java +++ b/ccm-core/src/main/java/org/libreccm/workflow/Workflow.java @@ -39,6 +39,7 @@ import javax.persistence.Inheritance; import javax.persistence.InheritanceType; import javax.persistence.JoinColumn; import javax.persistence.JoinTable; +import javax.persistence.ManyToOne; import javax.persistence.OneToMany; import javax.persistence.Table; @@ -58,6 +59,10 @@ public class Workflow implements Serializable { @GeneratedValue(strategy = GenerationType.AUTO) private long workflowId; + @ManyToOne + @JoinColumn(name = "TEMPLATE_ID") + private WorkflowTemplate template; + @Embedded @AssociationOverride( name = "values", @@ -95,6 +100,14 @@ public class Workflow implements Serializable { public void setWorkflowId(final long workflowId) { this.workflowId = workflowId; } + + public WorkflowTemplate getTemplate() { + return template; + } + + protected void setTemplate(final WorkflowTemplate template) { + this.template = template; + } public LocalizedString getName() { return name; diff --git a/ccm-core/src/main/resources/db/migrations/org/libreccm/ccm_core/h2/V7_0_0_7__add_workflow_template_id.sql b/ccm-core/src/main/resources/db/migrations/org/libreccm/ccm_core/h2/V7_0_0_7__add_workflow_template_id.sql new file mode 100644 index 000000000..792f8fc58 --- /dev/null +++ b/ccm-core/src/main/resources/db/migrations/org/libreccm/ccm_core/h2/V7_0_0_7__add_workflow_template_id.sql @@ -0,0 +1,10 @@ +-- Adds a foreign key column which references the workflow template used +-- to create a workflow + +alter table CCM_CORE.WORKFLOWS + add column TEMPLATE_ID int8; + +alter table CCM_CORE.WORKFLOWS + add constraint FKol71r1t83h0qe65gglq43far2 + foreign key (template_id) + references CCM_CORE.WORKFLOW_TEMPLATES; \ No newline at end of file diff --git a/ccm-core/src/main/resources/db/migrations/org/libreccm/ccm_core/pgsql/V7_0_0_7__add_workflow_template_id.sql b/ccm-core/src/main/resources/db/migrations/org/libreccm/ccm_core/pgsql/V7_0_0_7__add_workflow_template_id.sql new file mode 100644 index 000000000..2521b5bb0 --- /dev/null +++ b/ccm-core/src/main/resources/db/migrations/org/libreccm/ccm_core/pgsql/V7_0_0_7__add_workflow_template_id.sql @@ -0,0 +1,10 @@ +-- Adds a foreign key column which references the workflow template used +-- to create a workflow + +alter table CCM_CORE.WORKFLOWS + add column TEMPLATE_ID bigint; + +alter table CCM_CORE.WORKFLOWS + add constraint FKol71r1t83h0qe65gglq43far2 + foreign key (template_id) + references CCM_CORE.WORKFLOW_TEMPLATES; \ No newline at end of file diff --git a/ccm-core/src/test/java/org/libreccm/workflow/EqualsAndHashCodeTest.java b/ccm-core/src/test/java/org/libreccm/workflow/EqualsAndHashCodeTest.java index 1b2e7504f..0e7303b87 100644 --- a/ccm-core/src/test/java/org/libreccm/workflow/EqualsAndHashCodeTest.java +++ b/ccm-core/src/test/java/org/libreccm/workflow/EqualsAndHashCodeTest.java @@ -29,6 +29,7 @@ import org.libreccm.testutils.EqualsVerifier; import java.util.Arrays; import java.util.Collection; +import java.util.Locale; /** * @@ -89,12 +90,19 @@ public class EqualsAndHashCodeTest extends EqualsVerifier { final User user2 = new TestUser(); user2.setName("user2"); + final WorkflowTemplate template1 = new WorkflowTemplate(); + template1.getName().addValue(Locale.ENGLISH, "Template 1"); + + final WorkflowTemplate template2 = new WorkflowTemplate(); + template1.getName().addValue(Locale.ENGLISH, "Template 2"); + verifier .withPrefabValues(UserTask.class, userTask1, userTask2) .withPrefabValues(Role.class, role1, role2) .withPrefabValues(Task.class, task1, task2) .withPrefabValues(Group.class, group1, group2) - .withPrefabValues(User.class, user1, user2); + .withPrefabValues(User.class, user1, user2) + .withPrefabValues(WorkflowTemplate.class, template1, template2); } /** diff --git a/ccm-core/src/test/resources-wildfly8-managed-h2-mem/scripts/create_ccm_core_schema.sql b/ccm-core/src/test/resources-wildfly8-managed-h2-mem/scripts/create_ccm_core_schema.sql index 1a168e197..5749aa06b 100644 --- a/ccm-core/src/test/resources-wildfly8-managed-h2-mem/scripts/create_ccm_core_schema.sql +++ b/ccm-core/src/test/resources-wildfly8-managed-h2-mem/scripts/create_ccm_core_schema.sql @@ -580,6 +580,7 @@ CREATE SCHEMA ccm_core; create table ccm_core.workflows ( workflow_id bigint not null, + template_id bigint, primary key (workflow_id) ); @@ -1080,4 +1081,9 @@ CREATE SCHEMA ccm_core; foreign key (workflow_id) references ccm_core.workflows; + alter table CCM_CORE.WORKFLOWS + add constraint FKol71r1t83h0qe65gglq43far2 + foreign key (template_id) + references CCM_CORE.WORKFLOW_TEMPLATES; + create sequence hibernate_sequence start with 1 increment by 1; \ No newline at end of file diff --git a/ccm-core/src/test/resources-wildfly8-remote-pgsql/scripts/create_ccm_core_schema.sql b/ccm-core/src/test/resources-wildfly8-remote-pgsql/scripts/create_ccm_core_schema.sql index 4d0978ce7..3787a39fc 100644 --- a/ccm-core/src/test/resources-wildfly8-remote-pgsql/scripts/create_ccm_core_schema.sql +++ b/ccm-core/src/test/resources-wildfly8-remote-pgsql/scripts/create_ccm_core_schema.sql @@ -1123,4 +1123,9 @@ create sequence hibernate_sequence start 1 increment 1; alter table CCM_CORE.WORKFLOW_USER_TASKS add constraint FKefpdf9ojplu7loo31hfm0wl2h foreign key (TASK_ID) - references CCM_CORE.WORKFLOW_TASKS; \ No newline at end of file + references CCM_CORE.WORKFLOW_TASKS; + + alter table CCM_CORE.WORKFLOWS + add constraint FKol71r1t83h0qe65gglq43far2 + foreign key (template_id) + references CCM_CORE.WORKFLOW_TEMPLATES; \ No newline at end of file