mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
The publish_web_content_processdefinition now always runs the PublishEventAction asynchronously. Added ScriptAction.executeAsynchronously(ScriptNode) method.
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@28975 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -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.
|
||||
*
|
||||
|
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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<ParameterDefinition> paramList)
|
||||
{
|
||||
//NOOP
|
||||
}
|
||||
|
||||
/**
|
||||
* @param nodeService the nodeService to set
|
||||
*/
|
||||
public void setNodeService(NodeService nodeService)
|
||||
{
|
||||
this.nodeService = nodeService;
|
||||
}
|
||||
}
|
@@ -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<WorkflowPath> 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<WorkflowTask> 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<Void>()
|
||||
{
|
||||
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()
|
||||
|
Reference in New Issue
Block a user