Skip to content

Commit

Permalink
refactoring WofklowService, changed junit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rsoika committed Jun 7, 2018
1 parent 6abc1b9 commit 6a2a26b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -362,11 +362,11 @@ public List<ItemCollection> getWorkListByGroup(String name, String type, int pag
}

/**
* Returns a collection of workitems belonging to a specified $processID defined
* Returns a collection of workitems belonging to a specified $taskID defined
* by the workflow model. The behaivor is simmilar to the method getWorkList.
*
* @param aID
* = $ProcessID for the workitems to be returned.
* = $taskID for the workitems to be returned.
* @param pageSize
* = optional page count (default 20)
* @param pageIndex
Expand All @@ -389,6 +389,7 @@ public List<ItemCollection> getWorkListByProcessID(int aid, String type, int pag
if (type != null && !"".equals(type)) {
searchTerm += " type:\"" + type + "\" AND ";
}
// need to be fixed during slow migration issue #384
searchTerm += " $processid:\"" + aid + "\" )";
try {
return documentService.find(searchTerm, pageSize, pageIndex, sortBy, sortReverse);
Expand Down Expand Up @@ -448,7 +449,7 @@ public List<ItemCollection> getWorkListByRef(String aref) {

/**
* This returns a list of workflow events assigned to a given workitem. The
* method evaluates the events for the current $modelversion and $processid. The
* method evaluates the events for the current $modelversion and $taskid. The
* result list is filtered by the properties 'keypublicresult' and
* 'keyRestrictedVisibility'.
*
Expand All @@ -466,7 +467,7 @@ public List<ItemCollection> getWorkListByRef(String aref) {
@SuppressWarnings("unchecked")
public List<ItemCollection> getEvents(ItemCollection workitem) throws ModelException {
List<ItemCollection> result = new ArrayList<ItemCollection>();
int processID = workitem.getProcessID();
int processID = workitem.getTaskID();
// verify if version is valid
Model model = modelService.getModelByWorkitem(workitem);

Expand Down Expand Up @@ -536,10 +537,10 @@ public List<ItemCollection> getEvents(ItemCollection workitem) throws ModelExcep
/**
* This method processes a workItem by the WorkflowKernel and saves the workitem
* after the processing was finished successful. The workitem have to provide at
* least the properties '$modelversion', '$processid' and '$activityid'
* least the properties '$modelversion', '$taskid' and '$eventid'
*
* Before the method starts processing the workitem, the method load the current
* instance of the given workitem and compares the property $processID. If it is
* instance of the given workitem and compares the property $taskID. If it is
* not equal the method throws an ProcessingErrorException.
*
* After the workitem was processed successful, the method verifies the property
Expand Down Expand Up @@ -589,14 +590,14 @@ public ItemCollection processWorkItem(ItemCollection workitem)
"WorkflowService: error - $UniqueID (" + workitem.getItemValueInteger(WorkflowKernel.UNIQUEID)
+ ") no Author Access!");

// test if $ProcessID matches current instance
if (workitem.getItemValueInteger("$ProcessID") > 0
&& currentInstance.getItemValueInteger("$ProcessID") != workitem.getItemValueInteger("$ProcessID"))
// test if $taskID matches current instance
if (workitem.getTaskID() > 0
&& currentInstance.getTaskID() != workitem.getTaskID())
throw new ProcessingErrorException(WorkflowService.class.getSimpleName(),
ProcessingErrorException.INVALID_PROCESSID,
"WorkflowService: error - $ProcesssID (" + workitem.getItemValueInteger("$ProcessID")
"WorkflowService: error - $taskID (" + workitem.getTaskID()
+ ") did not match expected $ProcesssID ("
+ currentInstance.getItemValueInteger("$ProcessID") + ")");
+ currentInstance.getTaskID() + ")");

// merge workitem into current instance (issue #86)
// an instance of this WorkItem still exists! so we update the new
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,24 +294,24 @@ public void testProcessTypeAttriubteComplex()
ItemCollection workitem = workflowMockEnvironment.getDatabase().get("W0000-00001");
workitem.removeItem("type");
workitem.replaceItemValue(WorkflowKernel.MODELVERSION, DEFAULT_MODEL_VERSION);
workitem.replaceItemValue(WorkflowKernel.PROCESSID, 100);
workitem.setTaskID(100);

// case 1 - no type attribute
workitem.setEventID(10);
workitem = workflowMockEnvironment.processWorkItem(workitem);
Assert.assertEquals(100, workitem.getProcessID());
Assert.assertEquals(100, workitem.getTaskID());
Assert.assertEquals("", workitem.getType());

// case 2 - workitem
workitem.setEventID(20);
workitem = workflowMockEnvironment.processWorkItem(workitem);
Assert.assertEquals(200, workitem.getProcessID());
Assert.assertEquals(200, workitem.getTaskID());
Assert.assertEquals("workitem", workitem.getType());

// case 3 - workitemdeleted
workitem.setEventID(30);
workitem = workflowMockEnvironment.processWorkItem(workitem);
Assert.assertEquals(200, workitem.getProcessID());
Assert.assertEquals(200, workitem.getTaskID());
Assert.assertEquals("workitemdeleted", workitem.getType());

}
Expand Down

0 comments on commit 6a2a26b

Please sign in to comment.