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:
@@ -73,12 +73,6 @@
|
||||
<property name="workflowEngineId" value="jbpm" />
|
||||
</bean>
|
||||
|
||||
<!-- Check Publishing Dependencies Action -->
|
||||
<bean id="pub_checkPublishingDependencies"
|
||||
class="org.alfresco.repo.publishing.CheckPublishingDependenciesAction" >
|
||||
<property name="nodeService" ref="NodeService" />
|
||||
</bean>
|
||||
|
||||
|
||||
<!-- Publish Event Action -->
|
||||
<bean id="pub_publishEvent" class="org.alfresco.repo.publishing.PublishEventAction" >
|
||||
|
@@ -10,7 +10,7 @@
|
||||
</start-state>
|
||||
|
||||
<decision name="checkForScheduledTime" >
|
||||
<transition name="toCheckDependencies" to="checkDependencies">
|
||||
<transition name="toPublish" to="publish">
|
||||
<condition>#{pubwf_scheduledPublishDate == null}</condition>
|
||||
</transition>
|
||||
<transition name="toWaitForScheduledTime" to="waitForScheduledTime" />
|
||||
@@ -18,7 +18,7 @@
|
||||
|
||||
<task-node name="waitForScheduledTime" end-tasks="true" >
|
||||
<task name="pubwf:wait" >
|
||||
<timer duedate="#{pubwf_scheduledPublishDate}" transition="toCheckDependencies" >
|
||||
<timer duedate="#{pubwf_scheduledPublishDate}" transition="toPublish" >
|
||||
<action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
|
||||
<script>
|
||||
logger.log("Checking dependencies for PUblishing Event: "+ pubwf_publishingEvent);
|
||||
@@ -26,50 +26,7 @@
|
||||
</action>
|
||||
</timer>
|
||||
</task>
|
||||
<transition name="toCheckDependencies" to="checkDependencies" />
|
||||
</task-node>
|
||||
|
||||
<decision name="checkDependencies">
|
||||
<event type="node-enter">
|
||||
<action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
|
||||
<script>
|
||||
<variable name="pubwf_eventStatus" access="write" />
|
||||
<expression>
|
||||
var publishingDependenciesAction = actions.create("pub_checkPublishingDependencies");
|
||||
publishingDependenciesAction.execute(pubwf_publishingEvent);
|
||||
pubwf_publishingEvent.properties["pub:publishingEventStatus"];
|
||||
</expression>
|
||||
</script>
|
||||
</action>
|
||||
</event>
|
||||
<transition name="retry" to="waitAndRetry" />
|
||||
<transition name="publish" to="publish">
|
||||
<condition>#{pubwf_eventStatus == "IN_PROGRESS"}</condition>
|
||||
</transition>
|
||||
<transition name="fail" to="end">
|
||||
<condition>#{pubwf_eventStatus== "FAILED"}</condition>
|
||||
</transition>
|
||||
<transition name="alreadyCompleted" to="end">
|
||||
<condition>#{pubwf_eventStatus== "COMPLETED"}</condition>
|
||||
<action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
|
||||
<script>
|
||||
logger.log("PUblishing Event already completed! Event: "+ pubwf_publishingEvent);
|
||||
</script>
|
||||
</action>
|
||||
</transition>
|
||||
</decision>
|
||||
|
||||
<task-node name="waitAndRetry" end-tasks="true" >
|
||||
<task name="pubwf:wait" >
|
||||
<timer duedate="1 minute" transition="toCheckDependencies" >
|
||||
<action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
|
||||
<script>
|
||||
logger.log("Checking dependencies for PUblishing Event: "+ pubwf_publishingEvent);
|
||||
</script>
|
||||
</action>
|
||||
</timer>
|
||||
</task>
|
||||
<transition name="toCheckDependencies" to="checkDependencies" />
|
||||
<transition name="toPublish" to="publish" />
|
||||
</task-node>
|
||||
|
||||
<node name="publish" >
|
||||
@@ -77,7 +34,7 @@
|
||||
<action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
|
||||
<script>
|
||||
var publishEventAction = actions.create("pub_publishEvent");
|
||||
publishEventAction.execute(pubwf_publishingEvent);
|
||||
publishEventAction.executeAsynchronously(pubwf_publishingEvent);
|
||||
</script>
|
||||
</action>
|
||||
</event>
|
||||
|
@@ -8,9 +8,4 @@
|
||||
<constructor-arg value="org.alfresco.repo.action.executer.ActionExecuter" />
|
||||
</bean>
|
||||
|
||||
<!-- Mock Check Publishing Dependencies -->
|
||||
<bean id="pub_checkPublishingDependencies" class="org.mockito.Mockito" factory-method="mock">
|
||||
<constructor-arg value="org.alfresco.repo.action.executer.ActionExecuter" />
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
|
@@ -142,11 +142,35 @@ public class ScriptAction implements Serializable, Scopeable
|
||||
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,22 +78,13 @@ 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,13 +186,19 @@ 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();
|
||||
@@ -219,6 +215,15 @@ public class PublishWebContentJbpmTest extends BaseSpringTest
|
||||
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