diff --git a/config/alfresco/web-publishing-context.xml b/config/alfresco/web-publishing-context.xml index 2fb0134cb5..e494746980 100644 --- a/config/alfresco/web-publishing-context.xml +++ b/config/alfresco/web-publishing-context.xml @@ -72,12 +72,6 @@ - - - - - diff --git a/config/alfresco/workflow/publish_web_content_processdefinition.xml b/config/alfresco/workflow/publish_web_content_processdefinition.xml index 8fb16dbc46..4f40203872 100644 --- a/config/alfresco/workflow/publish_web_content_processdefinition.xml +++ b/config/alfresco/workflow/publish_web_content_processdefinition.xml @@ -9,8 +9,8 @@ - - + + #{pubwf_scheduledPublishDate == null} @@ -18,7 +18,7 @@ - + - - - - - #{pubwf_eventStatus == "IN_PROGRESS"} - - - #{pubwf_eventStatus== "FAILED"} - - - #{pubwf_eventStatus== "COMPLETED"} - - - - - - - - - - - - - - - + @@ -77,7 +34,7 @@ diff --git a/config/test/alfresco/test-web-publishing--workflow-context.xml b/config/test/alfresco/test-web-publishing--workflow-context.xml index 7530b9d01d..763df59851 100644 --- a/config/test/alfresco/test-web-publishing--workflow-context.xml +++ b/config/test/alfresco/test-web-publishing--workflow-context.xml @@ -8,9 +8,4 @@ - - - - - diff --git a/source/java/org/alfresco/repo/jscript/ScriptAction.java b/source/java/org/alfresco/repo/jscript/ScriptAction.java index dbf6b18316..2f13c1f747 100644 --- a/source/java/org/alfresco/repo/jscript/ScriptAction.java +++ b/source/java/org/alfresco/repo/jscript/ScriptAction.java @@ -141,12 +141,36 @@ public class ScriptAction implements Serializable, Scopeable // Reset the actioned upon node node.reset(); } + + /** + * Execute action. The existing transaction will be joined. + * + * @param node + * the node to execute action upon + */ + @SuppressWarnings("synthetic-access") + public void executeAsynchronously(ScriptNode node) + { + performParamConversionForRepo(); + executeAsynchronouslyImpl(node); + + // Parameters may have been updated by action execution, so reset cache + this.parameters = null; + + // Reset the actioned upon node + node.reset(); + } protected void executeImpl(ScriptNode node) { actionService.executeAction(action, node.getNodeRef()); } + protected void executeAsynchronouslyImpl(ScriptNode node) + { + actionService.executeAction(action, node.getNodeRef(), true, true); + } + /** * Execute action, optionally starting a new, potentially read-only transaction. * diff --git a/source/java/org/alfresco/repo/publishing/CheckPublishingDependenciesAction.java b/source/java/org/alfresco/repo/publishing/CheckPublishingDependenciesAction.java deleted file mode 100644 index fa072addd2..0000000000 --- a/source/java/org/alfresco/repo/publishing/CheckPublishingDependenciesAction.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * 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 . - */ - -package org.alfresco.repo.publishing; - -import static org.alfresco.repo.publishing.PublishingModel.PROP_PUBLISHING_EVENT_STATUS; -import static org.alfresco.repo.publishing.PublishingModel.TYPE_PUBLISHING_EVENT; - -import java.util.List; - -import org.alfresco.repo.action.executer.ActionExecuter; -import org.alfresco.repo.action.executer.ActionExecuterAbstractBase; -import org.alfresco.service.cmr.action.Action; -import org.alfresco.service.cmr.action.ParameterDefinition; -import org.alfresco.service.cmr.publishing.PublishingEvent.Status; -import org.alfresco.service.cmr.repository.NodeRef; -import org.alfresco.service.cmr.repository.NodeService; -import org.alfresco.service.namespace.QName; - -/** - * This {@link ActionExecuter} checks the status of the publishing event - * dependencies and sets the pub:publishingEventStatus property accordingly. - * - * @author Nick Smith - * @since 4.0 - * - */ -public class CheckPublishingDependenciesAction extends ActionExecuterAbstractBase -{ - private NodeService nodeService; - - /** - * {@inheritDoc} - */ - @Override - protected void executeImpl(Action action, NodeRef node) - { - QName nodeType = nodeService.getType(node); - if(TYPE_PUBLISHING_EVENT.equals(nodeType)) - { - nodeService.setProperty(node, PROP_PUBLISHING_EVENT_STATUS, Status.IN_PROGRESS); - } - } - - /** - * {@inheritDoc} - */ - @Override - protected void addParameterDefinitions(List paramList) - { - //NOOP - } - - /** - * @param nodeService the nodeService to set - */ - public void setNodeService(NodeService nodeService) - { - this.nodeService = nodeService; - } -} diff --git a/source/java/org/alfresco/repo/publishing/PublishWebContentJbpmTest.java b/source/java/org/alfresco/repo/publishing/PublishWebContentJbpmTest.java index cf960f46ff..82bb0d0489 100644 --- a/source/java/org/alfresco/repo/publishing/PublishWebContentJbpmTest.java +++ b/source/java/org/alfresco/repo/publishing/PublishWebContentJbpmTest.java @@ -62,6 +62,9 @@ import org.alfresco.util.GUID; import org.junit.After; import org.junit.Before; import org.junit.Test; +import org.mockito.Mockito; +import org.mockito.invocation.InvocationOnMock; +import org.mockito.stubbing.Answer; /** * @author Nick Smith @@ -75,23 +78,14 @@ public class PublishWebContentJbpmTest extends BaseSpringTest private ServiceRegistry serviceRegistry; private Repository repositoryHelper; private ActionExecuter publishEventAction; - private ActionExecuter checkPublishingDependenciesAction; private NodeService nodeService; private WorkflowService workflowService; private RetryingTransactionHelper transactionHelper; private NodeRef event; private String instanceId; - - @Override - protected String[] getConfigLocations() - { - return new String[] - { - ApplicationContextHelper.CONFIG_LOCATIONS[0], "classpath:test/alfresco/test-web-publishing--workflow-context.xml" - }; - } - + private long threadId; + @Test public void testProcessTimers() throws Exception { @@ -106,41 +100,40 @@ public class PublishWebContentJbpmTest extends BaseSpringTest // Wait for scheduled time to elapse. Thread.sleep(10000); - // Check the Publish Event Action was called - verify(checkPublishingDependenciesAction).execute(any(Action.class), any(NodeRef.class)); - - // Should now be waiting to retry - checkNode("waitAndRetry"); - - // Set Status to IN_PROGRESS - nodeService.setProperty(event, PROP_PUBLISHING_EVENT_STATUS, Status.IN_PROGRESS.name()); - // Wait for retry - Thread.sleep(65000); - // Should have ended - WorkflowInstance instance = workflowService.getWorkflowById(instanceId); - assertFalse("Workflow should have ended!", instance.isActive()); - } - - @Test - public void testProcessPublishPath() throws Exception - { - // Set Status to IN_PROGRESS - nodeService.setProperty(event, PROP_PUBLISHING_EVENT_STATUS, Status.IN_PROGRESS.name()); - - Calendar schedule = Calendar.getInstance(); - schedule.add(Calendar.SECOND, 1); - - startWorkflowAndCommit(schedule); - - Thread.sleep(2000); - - // Should have ended - WorkflowInstance instance = workflowService.getWorkflowById(instanceId); - assertFalse("Workflow should have ended!", instance.isActive()); + checkEnded(instanceId); // Check the Publish Event Action was called verify(publishEventAction).execute(any(Action.class), any(NodeRef.class)); + + assertFalse("The action should be run from a different Thread!", Thread.currentThread().getId()==threadId); + } + + public void testProcessNoSchedule() throws Exception + { + startWorkflowAndCommit(null); + + // Wait for async action to execute + Thread.sleep(500); + + // Should have ended + checkEnded(instanceId); + + // Check the Publish Event Action was called + verify(publishEventAction).execute(any(Action.class), any(NodeRef.class)); + + assertFalse("The action should be run from a different Thread!", Thread.currentThread().getId()==threadId); + } + + private void checkEnded(String instanceId2) + { + WorkflowInstance instance = workflowService.getWorkflowById(instanceId2); + if(instance.isActive()) + { + List paths = workflowService.getWorkflowPaths(instance.getId()); + String nodeName = paths.get(0).getNode().getName(); + fail("Workflow should have ended! At node: " +nodeName); + } } private void startWorkflowAndCommit(final Calendar scheduledTime) @@ -152,10 +145,7 @@ public class PublishWebContentJbpmTest extends BaseSpringTest WorkflowPath path = startWorkflow(scheduledTime); // End the Start task. - List tasks = workflowService.getTasksForWorkflowPath(path.getId()); - assertNotNull(tasks); - assertEquals(1, tasks.size()); - WorkflowTask startTask = tasks.get(0); + WorkflowTask startTask = workflowService.getStartTask(path.getInstance().getId()); workflowService.endTask(startTask.getId(), null); return null; } @@ -196,14 +186,20 @@ public class PublishWebContentJbpmTest extends BaseSpringTest serviceRegistry = (ServiceRegistry)getApplicationContext().getBean("ServiceRegistry"); repositoryHelper = (Repository) getApplicationContext().getBean("repositoryHelper"); publishEventAction = (ActionExecuter) getApplicationContext().getBean("pub_publishEvent"); - checkPublishingDependenciesAction = (ActionExecuter) getApplicationContext().getBean("pub_checkPublishingDependencies"); - reset(checkPublishingDependenciesAction); reset(publishEventAction); ActionDefinition actionDef = mock(ActionDefinition.class); when(publishEventAction.getActionDefinition()).thenReturn(actionDef); - when(checkPublishingDependenciesAction.getActionDefinition()).thenReturn(actionDef); - + // Record thread action is run in. + Mockito.doAnswer(new Answer() + { + public Void answer(InvocationOnMock invocation) throws Throwable + { + threadId = Thread.currentThread().getId(); + return null; + } + }).when(publishEventAction).execute(any(Action.class), any(NodeRef.class)); + this.workflowService = serviceRegistry.getWorkflowService(); this.nodeService = serviceRegistry.getNodeService(); this.transactionHelper = serviceRegistry.getRetryingTransactionHelper(); @@ -218,6 +214,15 @@ public class PublishWebContentJbpmTest extends BaseSpringTest ChildAssociationRef eventAssoc = nodeService.createNode(companyHome, ASSOC_CONTAINS, assocName, TYPE_PUBLISHING_EVENT, props); this.event = eventAssoc.getChildRef(); } + + @Override + protected String[] getConfigLocations() + { + return new String[] + { + ApplicationContextHelper.CONFIG_LOCATIONS[0], "classpath:test/alfresco/test-web-publishing--workflow-context.xml" + }; + } @After public void onTearDown()