From 7992f174cf4e47dd3e67326a488576ccb7104b1a Mon Sep 17 00:00:00 2001 From: Cristian Turlica Date: Fri, 20 May 2016 13:17:01 +0000 Subject: [PATCH] Merged 5.1.N (5.1.2) to 5.2.N (5.2.1) 127262 arebegea: Merged 5.0.N (5.0.4) to 5.1.N (5.1.2) 127234 cpopa: MNT-16063 : Activiti workflows without userTask does not work - Prevent tasks retrieval from finished executions git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@127287 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../repo/workflow/WorkflowBuilder.java | 4 +- ...bstractWorkflowServiceIntegrationTest.java | 3 + ...ctivitiWorkflowServiceIntegrationTest.java | 72 ++++++++++++------- .../testWorkflowNoUserTasks.bpmn20.xml | 16 +++++ 4 files changed, 69 insertions(+), 26 deletions(-) create mode 100644 source/test-resources/activiti/testWorkflowNoUserTasks.bpmn20.xml diff --git a/source/java/org/alfresco/repo/workflow/WorkflowBuilder.java b/source/java/org/alfresco/repo/workflow/WorkflowBuilder.java index 027762226a..bd92639ed6 100644 --- a/source/java/org/alfresco/repo/workflow/WorkflowBuilder.java +++ b/source/java/org/alfresco/repo/workflow/WorkflowBuilder.java @@ -100,7 +100,9 @@ public class WorkflowBuilder NodeRef packageRef = packageMgr.create(packageNode); params.put(WorkflowModel.ASSOC_PACKAGE, packageRef); WorkflowPath path = workflowService.startWorkflow(definition.getId(), params); - signalStartTask(path); + if (path.isActive()){ + signalStartTask(path); + } return path.getInstance(); } diff --git a/source/test-java/org/alfresco/repo/workflow/AbstractWorkflowServiceIntegrationTest.java b/source/test-java/org/alfresco/repo/workflow/AbstractWorkflowServiceIntegrationTest.java index 0b81f0f353..5d788c4632 100644 --- a/source/test-java/org/alfresco/repo/workflow/AbstractWorkflowServiceIntegrationTest.java +++ b/source/test-java/org/alfresco/repo/workflow/AbstractWorkflowServiceIntegrationTest.java @@ -35,6 +35,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import org.activiti.engine.HistoryService; import org.alfresco.error.AlfrescoRuntimeException; import org.alfresco.model.ContentModel; import org.alfresco.repo.content.MimetypeMap; @@ -97,6 +98,7 @@ public abstract class AbstractWorkflowServiceIntegrationTest extends BaseSpringT protected ServiceRegistry serviceRegistry; protected WorkflowTestHelper wfTestHelper; protected TransactionServiceImpl transactionService; + protected HistoryService historyService; public void testDeployWorkflowDefinition() { @@ -1341,6 +1343,7 @@ public abstract class AbstractWorkflowServiceIntegrationTest extends BaseSpringT this.workflowService = serviceRegistry.getWorkflowService(); this.authenticationComponent = (AuthenticationComponent) applicationContext.getBean("authenticationComponent"); this.nodeService = serviceRegistry.getNodeService(); + this.historyService = (HistoryService) applicationContext.getBean("activitiHistoryService"); Repository repositoryHelper = (Repository) applicationContext.getBean("repositoryHelper"); this.companyHome = repositoryHelper.getCompanyHome(); try diff --git a/source/test-java/org/alfresco/repo/workflow/activiti/ActivitiWorkflowServiceIntegrationTest.java b/source/test-java/org/alfresco/repo/workflow/activiti/ActivitiWorkflowServiceIntegrationTest.java index c41b5c7c4b..8d740a40d0 100644 --- a/source/test-java/org/alfresco/repo/workflow/activiti/ActivitiWorkflowServiceIntegrationTest.java +++ b/source/test-java/org/alfresco/repo/workflow/activiti/ActivitiWorkflowServiceIntegrationTest.java @@ -1,28 +1,28 @@ -/* - * #%L - * Alfresco Repository - * %% - * Copyright (C) 2005 - 2016 Alfresco Software Limited - * %% - * This file is part of the Alfresco software. - * If the software was purchased under a paid Alfresco license, the terms of - * the paid license agreement will prevail. Otherwise, the software is - * provided under the following open source license terms: - * - * 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 . - * #L% - */ +/* + * #%L + * Alfresco Repository + * %% + * Copyright (C) 2005 - 2016 Alfresco Software Limited + * %% + * This file is part of the Alfresco software. + * If the software was purchased under a paid Alfresco license, the terms of + * the paid license agreement will prevail. Otherwise, the software is + * provided under the following open source license terms: + * + * 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 . + * #L% + */ package org.alfresco.repo.workflow.activiti; @@ -35,11 +35,13 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import org.activiti.engine.history.HistoricProcessInstance; import org.alfresco.model.ContentModel; import org.alfresco.repo.content.MimetypeMap; import org.alfresco.repo.security.authentication.AuthenticationUtil; import org.alfresco.repo.security.permissions.AccessDeniedException; import org.alfresco.repo.workflow.AbstractWorkflowServiceIntegrationTest; +import org.alfresco.repo.workflow.WorkflowBuilder; import org.alfresco.repo.workflow.WorkflowModel; import org.alfresco.service.cmr.dictionary.PropertyDefinition; import org.alfresco.service.cmr.dictionary.TypeDefinition; @@ -638,6 +640,26 @@ public class ActivitiWorkflowServiceIntegrationTest extends AbstractWorkflowServ assertNotNull(completed); } + public void testBuildWorkflowWithNoUserTasks() throws Exception + { + // Deploy a definition containing only a service task + WorkflowDefinition testDefinition = deployDefinition("activiti/testWorkflowNoUserTasks.bpmn20.xml"); + WorkflowBuilder builder = new WorkflowBuilder(testDefinition, workflowService, nodeService, null); + // Build a workflow + WorkflowInstance builtInstance = builder.build(); + assertNotNull(builtInstance); + + // Check that there is no active workflow for the deployed definition(it should have finished already due to absence of user tasks) + List activeInstances = workflowService.getActiveWorkflows(testDefinition.getId()); + assertNotNull(activeInstances); + assertEquals(0, activeInstances.size()); + + // Check that there's a historic record of our 'only service task' workflow being run. + HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery() + .finishedAfter(builtInstance.getStartDate()) + .singleResult(); + assertNotNull(historicProcessInstance); + } @Override protected String getEngine() diff --git a/source/test-resources/activiti/testWorkflowNoUserTasks.bpmn20.xml b/source/test-resources/activiti/testWorkflowNoUserTasks.bpmn20.xml new file mode 100644 index 0000000000..2d370380b5 --- /dev/null +++ b/source/test-resources/activiti/testWorkflowNoUserTasks.bpmn20.xml @@ -0,0 +1,16 @@ + + + + + + + + + logger.log("Hello World"); + + + + + + +