ALF-9693: Social publishing now using the activiti process definition + fixed issue with activiti process without wait-state

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@30078 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Frederik Heremans
2011-08-26 07:52:20 +00:00
parent b8d0df0c95
commit 578a58bbc8
12 changed files with 566 additions and 224 deletions

View File

@@ -46,6 +46,7 @@ import org.activiti.engine.history.HistoricProcessInstance;
import org.activiti.engine.history.HistoricTaskInstance;
import org.activiti.engine.history.HistoricTaskInstanceQuery;
import org.activiti.engine.impl.RepositoryServiceImpl;
import org.activiti.engine.impl.bpmn.behavior.ReceiveTaskActivityBehavior;
import org.activiti.engine.impl.bpmn.behavior.UserTaskActivityBehavior;
import org.activiti.engine.impl.bpmn.deployer.BpmnDeployer;
import org.activiti.engine.impl.bpmn.diagram.ProcessDiagramGenerator;
@@ -597,6 +598,16 @@ public class ActivitiWorkflowEngine extends BPMEngine implements WorkflowEngine
}
return null;
}
private boolean isReceiveTask(PvmActivity act)
{
if(act instanceof ActivityImpl)
{
ActivityImpl actImpl = (ActivityImpl) act;
return (actImpl.getActivityBehavior() instanceof ReceiveTaskActivityBehavior);
}
return false;
}
private Collection<PvmActivity> findUserTasks(PvmActivity startEvent)
{
@@ -608,6 +619,17 @@ public class ActivitiWorkflowEngine extends BPMEngine implements WorkflowEngine
return userTasks.values();
}
private boolean isFirstActivity(PvmActivity activity, ReadOnlyProcessDefinition procDef)
{
if(procDef.getInitial().getOutgoingTransitions().size() == 1)
{
if(procDef.getInitial().getOutgoingTransitions().get(0).getDestination().equals(activity)) {
return true;
}
}
return false;
}
private void findUserTasks(PvmActivity currentActivity, Map<String, PvmActivity> userTasks)
{
@@ -974,10 +996,14 @@ public class ActivitiWorkflowEngine extends BPMEngine implements WorkflowEngine
// Start the process-instance
ProcessInstance instance = runtimeService.startProcessInstanceById(processDefId, variables);
// Set ID of workflowinstance after ProcessInstance is created
runtimeService.setVariable(instance.getId(), WorkflowConstants.PROP_WORKFLOW_INSTANCE_ID, createGlobalId(instance.getId()));
return typeConverter.convert((Execution)instance);
if(instance.isEnded())
{
return typeConverter.buildCompletedPath(instance.getId(), instance.getId());
}
else
{
return typeConverter.convert((Execution)instance);
}
}
catch (ActivitiException ae)
{
@@ -1299,8 +1325,35 @@ public class ActivitiWorkflowEngine extends BPMEngine implements WorkflowEngine
// Set start task end date on the process
runtimeService.setVariable(processInstanceId, ActivitiConstants.PROP_START_TASK_END_DATE, new Date());
// Return virtual start task for the execution, it's safe to use the processInstanceId
return typeConverter.getVirtualStartTask(processInstanceId, false);
// Check if the current activity is a signalTask and the first activity in the process,
// this is a workaround for processes without any task/waitstates that should otherwise end
// when they are started.
ProcessInstance processInstance = activitiUtil.getProcessInstance(processInstanceId);
String currentActivity = ((ExecutionEntity)processInstance).getActivityId();
ReadOnlyProcessDefinition procDef = activitiUtil.getDeployedProcessDefinition(processInstance.getProcessDefinitionId());
PvmActivity activity = procDef.findActivity(currentActivity);
if(isReceiveTask(activity) && isFirstActivity(activity, procDef))
{
// Signal the process to start flowing, beginning from the recieve task
runtimeService.signal(processInstanceId);
// It's possible the process has ended after signalling the receive task
processInstance = activitiUtil.getProcessInstance(processInstanceId);
if(processInstance != null) {
return typeConverter.getVirtualStartTask(processInstanceId, false);
}
else
{
return typeConverter.getVirtualStartTask(activitiUtil.getHistoricProcessInstance(processInstanceId));
}
}
else
{
// Return virtual start task for the execution, it's safe to use the processInstanceId
return typeConverter.getVirtualStartTask(processInstanceId, false);
}
}
/**

View File

@@ -18,6 +18,7 @@
*/
package org.alfresco.repo.workflow.activiti;
import org.activiti.engine.delegate.ExecutionListener;
import org.activiti.engine.delegate.TaskListener;
import org.activiti.engine.impl.bpmn.behavior.UserTaskActivityBehavior;
import org.activiti.engine.impl.bpmn.parser.BpmnParseListener;
@@ -42,6 +43,7 @@ public class AddTaskListenerParseListener implements BpmnParseListener
{
private TaskListener completeTaskListener;
private TaskListener createTaskListener;
private ExecutionListener processCreateListener;
@Override
public void parseUserTask(Element userTaskElement, ScopeImpl scope, ActivityImpl activity)
@@ -64,7 +66,7 @@ public class AddTaskListenerParseListener implements BpmnParseListener
@Override
public void parseProcess(Element processElement, ProcessDefinitionEntity processDefinition)
{
// Nothing to do here
processDefinition.addExecutionListener(ExecutionListener.EVENTNAME_START, processCreateListener);
}
@Override
@@ -196,5 +198,10 @@ public class AddTaskListenerParseListener implements BpmnParseListener
{
this.createTaskListener = createTaskListener;
}
public void setProcessCreateListener(ExecutionListener processCreateListener)
{
this.processCreateListener = processCreateListener;
}
}

View File

@@ -19,6 +19,7 @@
package org.alfresco.repo.workflow.activiti.listener;
import java.util.Calendar;
import java.util.Date;
import org.activiti.engine.delegate.DelegateExecution;
@@ -61,7 +62,19 @@ public class ConvertDateToISO8601 implements ExecutionListener
throw new IllegalArgumentException("Both fields 'source' and 'target' shoudl be set");
}
Date dateToConvert = (Date) execution.getVariable(sourceVarName);
Object dateVar = execution.getVariable(sourceVarName);
Date dateToConvert = null;
// Accept null, Date or Calendar as value
if(dateVar != null) {
if(dateVar instanceof Date) {
dateToConvert = (Date) execution.getVariable(sourceVarName);
} else if(dateVar instanceof Calendar) {
dateToConvert = ((Calendar) execution.getVariable(sourceVarName)).getTime();
} else {
throw new IllegalArgumentException("Variable with name: " + sourceVarName + " must be a Date or a Calendar");
}
}
if(dateToConvert != null) {
// Convert the date to ISO-8601 format
String convertedDate = ISO8601DateFormat.format(dateToConvert);

View File

@@ -0,0 +1,44 @@
/*
* Copyright (C) 2005-2011 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.repo.workflow.activiti.listener;
import org.activiti.engine.delegate.DelegateExecution;
import org.activiti.engine.delegate.ExecutionListener;
import org.alfresco.repo.workflow.BPMEngineRegistry;
import org.alfresco.repo.workflow.WorkflowConstants;
import org.alfresco.repo.workflow.activiti.ActivitiConstants;
/**
* An {@link ExecutionListener} that set all additional variables that are needed
* when process starts.
*
* @author Frederik Heremans
*/
public class ProcessStartExecutionListener implements ExecutionListener
{
public void notify(DelegateExecution execution) throws Exception
{
// Add the workflow ID
execution.setVariable(WorkflowConstants.PROP_WORKFLOW_INSTANCE_ID, BPMEngineRegistry
.createGlobalId(ActivitiConstants.ENGINE_ID, execution.getId()));
}
}