TaskFormProcessor now sucessfully persists transitions, i.e. if a task form is persisted with a transition specified then the task will be ended with the specified transition.

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@21380 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
N Smith
2010-07-23 14:47:16 +00:00
parent 1d8563c867
commit 5f93b51bc7
5 changed files with 70 additions and 3 deletions

View File

@@ -86,13 +86,13 @@ public abstract class ContentModelFormPersister<T> implements FormPersister<T>
case PROPERTY:
return addProperty(keyInfo.getQName(), fieldData);
case TRANSIENT_PROPERTY:
return addTransientProperty(keyInfo.getFieldName(), fieldData);
return updateTransientProperty(keyInfo.getFieldName(), fieldData);
default: // Handle properties
return changeAssociation(keyInfo, fieldData);
}
}
protected boolean addTransientProperty(String fieldName, FieldData fieldData)
protected boolean updateTransientProperty(String fieldName, FieldData fieldData)
{
return false;
}

View File

@@ -22,6 +22,7 @@ package org.alfresco.repo.forms.processor.workflow;
import java.io.Serializable;
import java.util.List;
import org.alfresco.repo.forms.FormData.FieldData;
import org.alfresco.repo.forms.processor.node.ItemData;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.repository.NodeRef;
@@ -39,6 +40,7 @@ import org.apache.commons.logging.Log;
public class TaskFormPersister extends ContentModelFormPersister<WorkflowTask>
{
private final TaskUpdater updater;
private String transitionId = null;
public TaskFormPersister(ItemData<WorkflowTask> itemData,
NamespaceService namespaceService,
@@ -110,13 +112,40 @@ public class TaskFormPersister extends ContentModelFormPersister<WorkflowTask>
return false;
}
/* (non-Javadoc)
* @see org.alfresco.repo.forms.processor.workflow.ContentModelFormPersister#addTransientProperty(java.lang.String, org.alfresco.repo.forms.FormData.FieldData)
*/
@Override
protected boolean updateTransientProperty(String fieldName, FieldData fieldData)
{
if(TransitionFieldProcessor.KEY.equals(fieldName))
{
Object value = fieldData.getValue();
if(value == null)
{
value = "";
}
transitionId = value.toString();
return true;
}
return false;
}
/* (non-Javadoc)
* @see org.alfresco.repo.forms.processor.workflow.ContentModelFormPersister#persist()
*/
@Override
public WorkflowTask persist()
{
if(transitionId == null)
{
return updater.update();
}
else if(transitionId.isEmpty())
{
return updater.transition();
}
return updater.transition(transitionId);
}

View File

@@ -28,7 +28,11 @@ package org.alfresco.repo.forms.processor.workflow;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyMap;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import java.io.Serializable;
@@ -333,6 +337,25 @@ public class TaskFormProcessorTest extends TestCase
assertTrue(nodeRefs.contains(new NodeRef(nodeRef2)));
}
@SuppressWarnings("unchecked")
public void testPersistTransitions() throws Exception
{
// Check updates but doesn't transition if no transition prop set.
processPersist("prop_bpm_foo", "foo");
// Check endTask is never called.
verify(workflowService, times(1)).updateTask(eq(TASK_ID), anyMap(), anyMap(), anyMap());
verify(workflowService, never()).endTask(eq(TASK_ID), anyString());
// Check default transition.
String dataKey =FormFieldConstants.PROP_DATA_PREFIX+TransitionFieldProcessor.KEY;
processPersist(dataKey, null);
verify(workflowService, times(1)).endTask(TASK_ID, null);
// Check specific transition.
processPersist(dataKey, "foo");
verify(workflowService, times(1)).endTask(TASK_ID, "foo");
}
private void processPersist(String dataKey, String value)
{
FormData data = new FormData();
@@ -589,6 +612,9 @@ public class TaskFormProcessorTest extends TestCase
return newTask;
}
});
when(service.endTask(eq(TASK_ID), anyString()))
.thenReturn(newTask);
return service;
}

View File

@@ -43,6 +43,7 @@ import org.apache.commons.logging.LogFactory;
* accumulates a set of updates to a task and then commits all the updates when
* the update() method is called.
*
* @since 3.4
* @author Nick Smith
*/
public class TaskUpdater
@@ -127,6 +128,16 @@ public class TaskUpdater
packageMgr.removeItems(items);
}
public WorkflowTask transition()
{
return transition(null);
}
public WorkflowTask transition(String transitionId)
{
return workflowService.endTask(taskId, transitionId);
}
public WorkflowTask update()
{
WorkflowTask task = workflowService.getTaskById(taskId);

View File

@@ -128,6 +128,7 @@ public class WorkflowTask
public String toString()
{
String propCount = (properties == null) ? "null" : "" + properties.size();
return "WorkflowTask[id=" + id + ",title=" + title + ",state=" + state + ",props=" + propCount + ",def=" + definition + ",path=" + path.toString() + "]";
String pathString = path==null ? "null" : path.toString();
return "WorkflowTask[id=" + id + ",title=" + title + ",state=" + state + ",props=" + propCount + ",def=" + definition + ",path=" + pathString + "]";
}
}