mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
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:
@@ -86,13 +86,13 @@ public abstract class ContentModelFormPersister<T> implements FormPersister<T>
|
|||||||
case PROPERTY:
|
case PROPERTY:
|
||||||
return addProperty(keyInfo.getQName(), fieldData);
|
return addProperty(keyInfo.getQName(), fieldData);
|
||||||
case TRANSIENT_PROPERTY:
|
case TRANSIENT_PROPERTY:
|
||||||
return addTransientProperty(keyInfo.getFieldName(), fieldData);
|
return updateTransientProperty(keyInfo.getFieldName(), fieldData);
|
||||||
default: // Handle properties
|
default: // Handle properties
|
||||||
return changeAssociation(keyInfo, fieldData);
|
return changeAssociation(keyInfo, fieldData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean addTransientProperty(String fieldName, FieldData fieldData)
|
protected boolean updateTransientProperty(String fieldName, FieldData fieldData)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@@ -22,6 +22,7 @@ package org.alfresco.repo.forms.processor.workflow;
|
|||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.alfresco.repo.forms.FormData.FieldData;
|
||||||
import org.alfresco.repo.forms.processor.node.ItemData;
|
import org.alfresco.repo.forms.processor.node.ItemData;
|
||||||
import org.alfresco.service.cmr.dictionary.DictionaryService;
|
import org.alfresco.service.cmr.dictionary.DictionaryService;
|
||||||
import org.alfresco.service.cmr.repository.NodeRef;
|
import org.alfresco.service.cmr.repository.NodeRef;
|
||||||
@@ -39,6 +40,7 @@ import org.apache.commons.logging.Log;
|
|||||||
public class TaskFormPersister extends ContentModelFormPersister<WorkflowTask>
|
public class TaskFormPersister extends ContentModelFormPersister<WorkflowTask>
|
||||||
{
|
{
|
||||||
private final TaskUpdater updater;
|
private final TaskUpdater updater;
|
||||||
|
private String transitionId = null;
|
||||||
|
|
||||||
public TaskFormPersister(ItemData<WorkflowTask> itemData,
|
public TaskFormPersister(ItemData<WorkflowTask> itemData,
|
||||||
NamespaceService namespaceService,
|
NamespaceService namespaceService,
|
||||||
@@ -110,13 +112,40 @@ public class TaskFormPersister extends ContentModelFormPersister<WorkflowTask>
|
|||||||
return false;
|
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)
|
/* (non-Javadoc)
|
||||||
* @see org.alfresco.repo.forms.processor.workflow.ContentModelFormPersister#persist()
|
* @see org.alfresco.repo.forms.processor.workflow.ContentModelFormPersister#persist()
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public WorkflowTask persist()
|
public WorkflowTask persist()
|
||||||
{
|
{
|
||||||
|
if(transitionId == null)
|
||||||
|
{
|
||||||
return updater.update();
|
return updater.update();
|
||||||
|
}
|
||||||
|
else if(transitionId.isEmpty())
|
||||||
|
{
|
||||||
|
return updater.transition();
|
||||||
|
}
|
||||||
|
return updater.transition(transitionId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -28,7 +28,11 @@ package org.alfresco.repo.forms.processor.workflow;
|
|||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.Matchers.any;
|
||||||
import static org.mockito.Matchers.anyMap;
|
import static org.mockito.Matchers.anyMap;
|
||||||
import static org.mockito.Matchers.anyString;
|
import static org.mockito.Matchers.anyString;
|
||||||
|
import static org.mockito.Matchers.eq;
|
||||||
import static org.mockito.Mockito.mock;
|
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 static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
@@ -333,6 +337,25 @@ public class TaskFormProcessorTest extends TestCase
|
|||||||
assertTrue(nodeRefs.contains(new NodeRef(nodeRef2)));
|
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)
|
private void processPersist(String dataKey, String value)
|
||||||
{
|
{
|
||||||
FormData data = new FormData();
|
FormData data = new FormData();
|
||||||
@@ -589,6 +612,9 @@ public class TaskFormProcessorTest extends TestCase
|
|||||||
return newTask;
|
return newTask;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
when(service.endTask(eq(TASK_ID), anyString()))
|
||||||
|
.thenReturn(newTask);
|
||||||
return service;
|
return service;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -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
|
* accumulates a set of updates to a task and then commits all the updates when
|
||||||
* the update() method is called.
|
* the update() method is called.
|
||||||
*
|
*
|
||||||
|
* @since 3.4
|
||||||
* @author Nick Smith
|
* @author Nick Smith
|
||||||
*/
|
*/
|
||||||
public class TaskUpdater
|
public class TaskUpdater
|
||||||
@@ -127,6 +128,16 @@ public class TaskUpdater
|
|||||||
packageMgr.removeItems(items);
|
packageMgr.removeItems(items);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public WorkflowTask transition()
|
||||||
|
{
|
||||||
|
return transition(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public WorkflowTask transition(String transitionId)
|
||||||
|
{
|
||||||
|
return workflowService.endTask(taskId, transitionId);
|
||||||
|
}
|
||||||
|
|
||||||
public WorkflowTask update()
|
public WorkflowTask update()
|
||||||
{
|
{
|
||||||
WorkflowTask task = workflowService.getTaskById(taskId);
|
WorkflowTask task = workflowService.getTaskById(taskId);
|
||||||
|
@@ -128,6 +128,7 @@ public class WorkflowTask
|
|||||||
public String toString()
|
public String toString()
|
||||||
{
|
{
|
||||||
String propCount = (properties == null) ? "null" : "" + properties.size();
|
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 + "]";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user