From a911cb0acb4f4dafd16525754282c756627e96b0 Mon Sep 17 00:00:00 2001 From: Ralph Soika Date: Thu, 7 Jun 2018 22:46:01 +0200 Subject: [PATCH] refactoring WofklowKernel, changed junit tests #388 --- .../org/imixs/workflow/WorkflowKernel.java | 31 +++++++++---------- .../org/imixs/workflow/WorkflowManager.java | 6 ++-- .../imixs/workflow/TestItemCollection.java | 2 +- .../imixs/workflow/TestWorkflowKernel.java | 8 ++--- .../workflow/TestWorkflowKernelModels.java | 29 ++++++++--------- 5 files changed, 35 insertions(+), 41 deletions(-) diff --git a/imixs-workflow-core/src/main/java/org/imixs/workflow/WorkflowKernel.java b/imixs-workflow-core/src/main/java/org/imixs/workflow/WorkflowKernel.java index 59869e9f7..7cf17ae7a 100644 --- a/imixs-workflow-core/src/main/java/org/imixs/workflow/WorkflowKernel.java +++ b/imixs-workflow-core/src/main/java/org/imixs/workflow/WorkflowKernel.java @@ -73,8 +73,8 @@ public class WorkflowKernel { public static final String WORKITEMID = "$workitemid"; public static final String MODELVERSION = "$modelversion"; + @Deprecated public static final String PROCESSID = "$processid"; - //public static final String ACTIVITYID = "$activityid"; public static final String TASKID = "$taskid"; public static final String EVENTID = "$eventid"; @@ -257,16 +257,16 @@ public ItemCollection process(final ItemCollection workitem) throws PluginExcept throw new ProcessingErrorException(WorkflowKernel.class.getSimpleName(), UNDEFINED_WORKITEM, "processing error: workitem is null"); - // check $processID - if (workitem.getItemValueInteger(PROCESSID) <= 0) + // check $TaskID + if (workitem.getTaskID() <= 0) throw new ProcessingErrorException(WorkflowKernel.class.getSimpleName(), UNDEFINED_PROCESSID, - "processing error: $processid undefined (" + workitem.getItemValueInteger(PROCESSID) + ")"); + "processing error: $taskID undefined (" + workitem.getTaskID() + ")"); // check $eventId if (workitem.getEventID() <= 0) throw new ProcessingErrorException(WorkflowKernel.class.getSimpleName(), UNDEFINED_ACTIVITYID, - "processing error: $eventid undefined (" + workitem.getEventID() + ")"); + "processing error: $eventID undefined (" + workitem.getEventID() + ")"); ItemCollection documentResult = new ItemCollection(workitem); @@ -323,7 +323,7 @@ public ItemCollection findNextTask(ItemCollection documentContext, ItemCollectio ItemCollection itemColNextTask = null; int iNewProcessID = event.getItemValueInteger("numnextprocessid"); - logger.finest("......next $processid=" + iNewProcessID + ""); + logger.finest("......next $taskID=" + iNewProcessID + ""); // test if we have an conditional exclusive Task exits... itemColNextTask = findConditionalExclusiveTask(event, documentContext); @@ -406,7 +406,7 @@ private ItemCollection updateEventList(final ItemCollection documentContext) { * Before a plug-in is called the method updates the 'type' attribute defined by * the next Task. * - * After all plug-ins are processed, the attributes $processid, $workflowstatus + * After all plug-ins are processed, the attributes $taskID, $workflowstatus * and $workflowgroup are updated. * * If an FollowUp Activity is defined (keyFollowUp="1" & numNextActivityID>0) @@ -419,8 +419,8 @@ private ItemCollection processEvent(final ItemCollection documentContext, final ItemCollection documentResult = documentContext; // log the general processing message String msg = "processing=" + documentContext.getItemValueString(UNIQUEID) + ", MODELVERSION=" - + documentContext.getItemValueString(MODELVERSION) + ", $processid=" - + documentContext.getItemValueInteger(PROCESSID) + ", $eventid=" + + documentContext.getItemValueString(MODELVERSION) + ", $taskID=" + + documentContext.getTaskID() + ", $eventID=" + documentContext.getEventID(); if (ctx == null) { @@ -464,10 +464,9 @@ private ItemCollection processEvent(final ItemCollection documentContext, final // instance. evaluateSplitEvent(event, documentResult); - // Update the attributes $ProcessID and $WorkflowStatus - documentResult.replaceItemValue(PROCESSID, - Integer.valueOf(itemColNextTask.getItemValueInteger("numprocessid"))); - logger.finest("......new $processid=" + documentResult.getTaskID()); + // Update the attributes $taskID and $WorkflowStatus + documentResult.setTaskID(Integer.valueOf(itemColNextTask.getItemValueInteger("numprocessid"))); + logger.finest("......new $taskID=" + documentResult.getTaskID()); documentResult.replaceItemValue(WORKFLOWSTATUS, itemColNextTask.getItemValueString("txtname")); logger.finest("......new $workflowStatus=" + documentResult.getItemValueString(WORKFLOWSTATUS)); // update deprecated attributes txtworkflowStatus and txtworkflowGroup @@ -696,10 +695,8 @@ private void evaluateSplitEvent(ItemCollection event, ItemCollection documentCon // clone current instance to a new version... ItemCollection cloned = createVersion(documentContext); logger.finest("......created new version=" + cloned.getUniqueID()); - // set new $processid - cloned.replaceItemValue(PROCESSID, - Integer.valueOf(itemColNextTask.getItemValueInteger("numprocessid"))); - + // set new $taskID + cloned.setTaskID(Integer.valueOf(itemColNextTask.getItemValueInteger("numprocessid"))); cloned.setEventID(eventID); // add temporary attribute $isversion... cloned.replaceItemValue(ISVERSION, true); diff --git a/imixs-workflow-core/src/main/java/org/imixs/workflow/WorkflowManager.java b/imixs-workflow-core/src/main/java/org/imixs/workflow/WorkflowManager.java index 2faa62fe2..3510079e4 100644 --- a/imixs-workflow-core/src/main/java/org/imixs/workflow/WorkflowManager.java +++ b/imixs-workflow-core/src/main/java/org/imixs/workflow/WorkflowManager.java @@ -48,18 +48,18 @@ public interface WorkflowManager { /** * This method processes a workItem. The workItem needs at least provide the - * valid attributes $ProcessID and $EventID (integer values) to identify + * valid attributes $taskID and $EventID (integer values) to identify * the current processEntity the workItem belongs to and the concrete * activtyEntity which should be processed by the wokflowManager * implementation. If the workItem is new the method creates a new instance - * for the corresoponding process. + * for the corresponding process. * * The method is responsible to persist the workItem after successfully * processing. The method returns the workItem with additional workflow * informations defined by the workfowManager Implementation. * * The Method throws an InvalidWorkitemException if the provided workItem is - * invalid or the provided attributes $ProcessID and $EventID (integer) + * invalid or the provided attributes $taskID and $EventID (integer) * did not match an valid modelEntity the workItem can be processed to. * * @param workitem diff --git a/imixs-workflow-core/src/test/java/org/imixs/workflow/TestItemCollection.java b/imixs-workflow-core/src/test/java/org/imixs/workflow/TestItemCollection.java index 990e9e9d0..a20320236 100644 --- a/imixs-workflow-core/src/test/java/org/imixs/workflow/TestItemCollection.java +++ b/imixs-workflow-core/src/test/java/org/imixs/workflow/TestItemCollection.java @@ -433,7 +433,7 @@ public void testBasicAttributes() { ItemCollection itemCollection1 = new ItemCollection(); itemCollection1.replaceItemValue(WorkflowKernel.MODELVERSION, "1.0.0"); - itemCollection1.replaceItemValue(WorkflowKernel.PROCESSID, 100); + itemCollection1.replaceItemValue(WorkflowKernel.TASKID, 100); itemCollection1.replaceItemValue(WorkflowKernel.EVENTID, 10); itemCollection1.replaceItemValue(WorkflowKernel.TYPE, "workitem_test"); itemCollection1.replaceItemValue(WorkflowKernel.UNIQUEID, "ABC-123"); diff --git a/imixs-workflow-core/src/test/java/org/imixs/workflow/TestWorkflowKernel.java b/imixs-workflow-core/src/test/java/org/imixs/workflow/TestWorkflowKernel.java index 13de68455..f0ed753ad 100644 --- a/imixs-workflow-core/src/test/java/org/imixs/workflow/TestWorkflowKernel.java +++ b/imixs-workflow-core/src/test/java/org/imixs/workflow/TestWorkflowKernel.java @@ -65,7 +65,7 @@ public void testProcess() { ItemCollection itemCollectionProcessed=null; ItemCollection itemCollection = new ItemCollection(); itemCollection.replaceItemValue("txtTitel", "Hello"); - itemCollection.replaceItemValue("$processid", 100); + itemCollection.setTaskID(100); itemCollection.setEventID(10); itemCollection.replaceItemValue("$modelversion", MokModel.DEFAULT_MODEL_VERSION); @@ -85,7 +85,7 @@ public void testProcess() { } Assert.assertEquals(1, itemCollectionProcessed.getItemValueInteger("runs")); - Assert.assertEquals(100, itemCollectionProcessed.getItemValueInteger("$processid")); + Assert.assertEquals(100, itemCollectionProcessed.getTaskID()); // initial and processed workitems are not the same and not equals! Assert.assertNotSame(itemCollection, itemCollectionProcessed); @@ -139,7 +139,7 @@ public void testProcessWithDeprecatedField() { public void testProcessNullPlugin() { ItemCollection itemCollection = new ItemCollection(); itemCollection.replaceItemValue("txtTitel", "Hello"); - itemCollection.replaceItemValue("$processid", 100); + itemCollection.setTaskID(100); itemCollection.setEventID(10); itemCollection.replaceItemValue("$modelversion", MokModel.DEFAULT_MODEL_VERSION); @@ -205,7 +205,7 @@ public void testForward() { public void testFollowup() { ItemCollection itemCollection = new ItemCollection(); itemCollection.replaceItemValue("txtTitel", "Hello"); - itemCollection.replaceItemValue("$processid", 100); + itemCollection.setTaskID(100); itemCollection.setEventID(11); itemCollection.replaceItemValue("$modelversion", MokModel.DEFAULT_MODEL_VERSION); diff --git a/imixs-workflow-core/src/test/java/org/imixs/workflow/TestWorkflowKernelModels.java b/imixs-workflow-core/src/test/java/org/imixs/workflow/TestWorkflowKernelModels.java index 208a40079..c5383e41c 100644 --- a/imixs-workflow-core/src/test/java/org/imixs/workflow/TestWorkflowKernelModels.java +++ b/imixs-workflow-core/src/test/java/org/imixs/workflow/TestWorkflowKernelModels.java @@ -81,7 +81,7 @@ public void testSimpleModel() { itemCollection = kernel.process(itemCollection); Assert.assertEquals("Hello", itemCollection.getItemValueString("txttitel")); - Assert.assertEquals(1100, itemCollection.getProcessID()); + Assert.assertEquals(1100, itemCollection.getTaskID()); } catch (Exception e) { Assert.fail(); @@ -108,7 +108,7 @@ public void testTicketModel() { ItemCollection itemCollection = new ItemCollection(); itemCollection.replaceItemValue("txtTitel", "Hello"); - itemCollection.replaceItemValue("$processid", 1100); + itemCollection.setTaskID(1100); itemCollection.setEventID(20); itemCollection.replaceItemValue("$modelversion", MokModel.DEFAULT_MODEL_VERSION); @@ -116,7 +116,7 @@ public void testTicketModel() { itemCollection = kernel.process(itemCollection); Assert.assertEquals("Hello", itemCollection.getItemValueString("txttitel")); - Assert.assertEquals(1200, itemCollection.getProcessID()); + Assert.assertEquals(1200, itemCollection.getTaskID()); } catch (Exception e) { Assert.fail(); @@ -146,7 +146,7 @@ public void testConditionalEventModel1() { // test Condition 1 ItemCollection itemCollection = new ItemCollection(); itemCollection.replaceItemValue("txtTitel", "Hello"); - itemCollection.replaceItemValue("$processid", 1000); + itemCollection.setTaskID(1000); itemCollection.setEventID(10); itemCollection.replaceItemValue("$modelversion", MokModel.DEFAULT_MODEL_VERSION); @@ -154,12 +154,12 @@ public void testConditionalEventModel1() { itemCollection = kernel.process(itemCollection); Assert.assertEquals("Hello", itemCollection.getItemValueString("txttitel")); - Assert.assertEquals(1200, itemCollection.getProcessID()); + Assert.assertEquals(1200, itemCollection.getTaskID()); // test Condition 2 itemCollection = new ItemCollection(); itemCollection.replaceItemValue("txtTitel", "Hello"); - itemCollection.replaceItemValue("$processid", 1000); + itemCollection.setTaskID(1000); itemCollection.setEventID(10); itemCollection.replaceItemValue("$modelversion", MokModel.DEFAULT_MODEL_VERSION); @@ -168,7 +168,7 @@ public void testConditionalEventModel1() { itemCollection = kernel.process(itemCollection); Assert.assertEquals("Hello", itemCollection.getItemValueString("txttitel")); - Assert.assertEquals(1100, itemCollection.getProcessID()); + Assert.assertEquals(1100, itemCollection.getTaskID()); } catch (Exception e) { Assert.fail(); @@ -199,7 +199,7 @@ public void testConditionalEventModel2() { // test Condition 1 ItemCollection itemCollection = new ItemCollection(); itemCollection.replaceItemValue("txtTitel", "Hello"); - itemCollection.replaceItemValue("$processid", 1000); + itemCollection.setTaskID(1000); itemCollection.setEventID(10); itemCollection.replaceItemValue("$modelversion", MokModel.DEFAULT_MODEL_VERSION); @@ -207,21 +207,18 @@ public void testConditionalEventModel2() { itemCollection = kernel.process(itemCollection); Assert.assertEquals("Hello", itemCollection.getItemValueString("txttitel")); - Assert.assertEquals(1100, itemCollection.getProcessID()); + Assert.assertEquals(1100, itemCollection.getTaskID()); // test Condition 2 - itemCollection = new ItemCollection(); + itemCollection = new ItemCollection().model(MokModel.DEFAULT_MODEL_VERSION).task(1000).event(10); itemCollection.replaceItemValue("txtTitel", "Hello"); - itemCollection.replaceItemValue("$processid", 1000); - itemCollection.setEventID(10); - itemCollection.replaceItemValue("$modelversion", MokModel.DEFAULT_MODEL_VERSION); itemCollection.replaceItemValue("_budget", 99); itemCollection = kernel.process(itemCollection); Assert.assertEquals("Hello", itemCollection.getItemValueString("txttitel")); - Assert.assertEquals(1200, itemCollection.getProcessID()); + Assert.assertEquals(1200, itemCollection.getTaskID()); } catch (Exception e) { Assert.fail(); @@ -258,7 +255,7 @@ public void testSplitEventModel1() { itemCollection = kernel.process(itemCollection); Assert.assertEquals("Hello", itemCollection.getItemValueString("_subject")); - Assert.assertEquals(1100, itemCollection.getProcessID()); + Assert.assertEquals(1100, itemCollection.getTaskID()); Assert.assertEquals(10, itemCollection.getItemValueInteger("$lastEvent")); // test new version... @@ -268,7 +265,7 @@ public void testSplitEventModel1() { ItemCollection version = versions.get(0); Assert.assertEquals("Hello", version.getItemValueString("_subject")); - Assert.assertEquals(1200, version.getProcessID()); + Assert.assertEquals(1200, version.getTaskID()); // $lastEvent should be 20 Assert.assertEquals(20, version.getItemValueInteger("$lastEvent"));