Java Code Examples for org.alfresco.service.cmr.action.Action#setExecuteAsynchronously()

The following examples show how to use org.alfresco.service.cmr.action.Action#setExecuteAsynchronously() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ActionImplTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void testSimpleProperties()
{
    Action action = (Action)create();
    
    // Check the default values
    assertFalse(action.getExecuteAsychronously());
    assertNull(action.getCompensatingAction());
    
    // Set some values
    action.setTitle("title");
    action.setDescription("description");
    action.setExecuteAsynchronously(true);
    Action compensatingAction = new ActionImpl(null, GUID.generate(), "actionDefintionName", null);
    action.setCompensatingAction(compensatingAction);
    
    // Check the values have been set
    assertEquals("title", action.getTitle());
    assertEquals("description", action.getDescription());
    assertTrue(action.getExecuteAsychronously());
    assertEquals(compensatingAction, action.getCompensatingAction());
}
 
Example 2
Source File: ActionServiceImplTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
public void testOwningNodeRef()
{
    // Create the action
    Action action = this.actionService.createAction(AddFeaturesActionExecuter.NAME);
    String actionId = action.getId();
    
    // Set the parameters of the action
    action.setParameterValue(AddFeaturesActionExecuter.PARAM_ASPECT_NAME, ContentModel.ASPECT_VERSIONABLE);
    
    // Set the title and description of the action
    action.setTitle("title");
    action.setDescription("description");
    action.setExecuteAsynchronously(true);
    
    // Check the owning node ref
    //assertNull(action.getOwningNodeRef());
            
    // Save the action
    this.actionService.saveAction(this.nodeRef, action);
    
    // Get the action
    this.actionService.getAction(this.nodeRef, actionId);        
}
 
Example 3
Source File: ActionServiceImplTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void xtestAsyncLoadTest()
{
    // TODO this is very weak .. how do we improve this ???
    
    Action action = this.actionService.createAction(AddFeaturesActionExecuter.NAME);
    action.setParameterValue(AddFeaturesActionExecuter.PARAM_ASPECT_NAME, ContentModel.ASPECT_VERSIONABLE);
    action.setExecuteAsynchronously(true);
    
    for (int i = 0; i < 1000; i++)
    {
        this.actionService.executeAction(action, this.nodeRef);
    }

    TestTransaction.flagForCommit();
    TestTransaction.end();
    
    // TODO how do we assess whether the large number of actions stacked cause a problem ??
}
 
Example 4
Source File: LocalActionServiceHelper.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void executeAction(NodeRef downloadNode)
{
    Action action = localActionService.createAction("createDownloadArchiveAction");
    action.setExecuteAsynchronously(true);
    
    localActionService.executeAction(action, downloadNode);
}
 
Example 5
Source File: RepoTransferReceiverImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void commitAsync(String transferId)
{
    /**
     * A side-effect of checking the lock here is that the lock timeout is suspended.
     *
     */
    Lock lock = checkLock(transferId);
    try
    {
        progressMonitor.updateStatus(transferId, Status.COMMIT_REQUESTED);
        Action commitAction = actionService.createAction(TransferCommitActionExecuter.NAME);
        commitAction.setParameterValue(TransferCommitActionExecuter.PARAM_TRANSFER_ID, transferId);
        commitAction.setExecuteAsynchronously(true);
        actionService.executeAction(commitAction, new NodeRef(transferId));
        if (log.isDebugEnabled())
        {
            log.debug("Registered transfer commit for asynchronous execution: " + transferId);
        }
    }
    catch (Exception error)
    {
        /**
         * Error somewhere in the action service?
         */
        //TODO consider whether the methods in this class should be retried/retryable..

        // need to re-enable the lock timeout otherwise we will hold the lock forever...
        lock.enableLockTimeout();

        throw new TransferException(MSG_ERROR_WHILE_COMMITTING_TRANSFER, new Object[]{transferId}, error);
    }

    /**
     * Lock intentionally not re-enabled here
     */
}
 
Example 6
Source File: ActionServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Populates the action properties from the node reference
 * 
 * @param actionNodeRef the action node reference
 * @param action the action
 */
private void populateActionProperties(NodeRef actionNodeRef, Action action)
{
    Map<QName, Serializable> props = this.nodeService.getProperties(actionNodeRef);

    action.setTitle((String) props.get(ActionModel.PROP_ACTION_TITLE));
    action.setDescription((String) props.get(ActionModel.PROP_ACTION_DESCRIPTION));

    Boolean trackStatusObj = (Boolean) props.get(ActionModel.PROP_TRACK_STATUS);
    action.setTrackStatus(trackStatusObj);              // Allowed to be null

    Boolean executeAsynchObj = (Boolean) props.get(ActionModel.PROP_EXECUTE_ASYNCHRONOUSLY);
    boolean executeAsynch = executeAsynchObj == null ? false : executeAsynchObj.booleanValue();
    action.setExecuteAsynchronously(executeAsynch);

    ((ActionImpl) action).setCreator((String) props.get(ContentModel.PROP_CREATOR));
    ((ActionImpl) action).setCreatedDate((Date) props.get(ContentModel.PROP_CREATED));
    ((ActionImpl) action).setModifier((String) props.get(ContentModel.PROP_MODIFIER));
    ((ActionImpl) action).setModifiedDate((Date) props.get(ContentModel.PROP_MODIFIED));
    
    ((ActionImpl) action).setExecutionStartDate((Date) props.get(ActionModel.PROP_EXECUTION_START_DATE));
    ((ActionImpl) action).setExecutionEndDate((Date) props.get(ActionModel.PROP_EXECUTION_END_DATE));
    ((ActionImpl) action).setExecutionStatus(ActionStatus.valueOf(props.get(ActionModel.PROP_EXECUTION_ACTION_STATUS)));
    ((ActionImpl) action).setExecutionFailureMessage((String) props.get(ActionModel.PROP_EXECUTION_FAILURE_MESSAGE));

    // Get the compensating action
    List<ChildAssociationRef> assocs = this.nodeService.getChildAssocs(actionNodeRef, RegexQNamePattern.MATCH_ALL,
                ActionModel.ASSOC_COMPENSATING_ACTION);
    if (assocs.size() != 0)
    {
        Action compensatingAction = createAction(assocs.get(0).getChildRef());
        action.setCompensatingAction(compensatingAction);
    }
}
 
Example 7
Source File: ActionServiceImplTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Test asynchronous execute action
 */
@Test
public void testAsyncExecuteAction()
{
    assertFalse(this.nodeService.hasAspect(this.nodeRef, ContentModel.ASPECT_VERSIONABLE));
    
    Action action = this.actionService.createAction(AddFeaturesActionExecuter.NAME);
    action.setParameterValue(AddFeaturesActionExecuter.PARAM_ASPECT_NAME, ContentModel.ASPECT_CLASSIFIABLE);
    action.setExecuteAsynchronously(true);
    
    this.actionService.executeAction(action, this.nodeRef);

    TestTransaction.flagForCommit();
    TestTransaction.end();
    
    final NodeService finalNodeService = this.nodeService;
    final NodeRef finalNodeRef = this.nodeRef;
    
    postAsyncActionTest(
            this.transactionService,
            1000l, 
            10, 
            new AsyncTest()
            {
                public String executeTest() 
                {
                    boolean result = finalNodeService.hasAspect(finalNodeRef, ContentModel.ASPECT_CLASSIFIABLE);
                    return result ? null : "Expected aspect Classifiable";
                };
            });
}
 
Example 8
Source File: InvitationServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void rejectModeratedInvitation(String siteName, String invitee, String role, String reviewer, String resourceType, String reviewComments)
{
    // Do nothing if emails disabled.
    if (isSendEmails() == false)
    {
        return;
    }

    // send email to the invitee if possible - but don't fail the rejection if email cannot be sent
    try
    {
        // Build our model
        Map<String, Serializable> model = new HashMap<String, Serializable>(8, 1.0f);
        model.put("resourceName", siteName);
        model.put("resourceType", resourceType);
        model.put("inviteeRole", role);
        model.put("reviewComments", reviewComments);
        model.put("reviewer", reviewer);
        model.put("inviteeUserName", invitee);

        // Process the template
        // Note - because we use a classpath template, rather than a Data Dictionary
        // one, we can't have the MailActionExecutor do the template for us
        String emailMsg = templateService.processTemplate("freemarker", REJECT_TEMPLATE, model);

        // Send
        Action emailAction = actionService.createAction("mail");
        emailAction.setParameterValue(MailActionExecuter.PARAM_TO, nodeService.getProperty(personService.getPerson(invitee), ContentModel.PROP_EMAIL));
        emailAction.setParameterValue(MailActionExecuter.PARAM_FROM, nodeService.getProperty(personService.getPerson(reviewer), ContentModel.PROP_EMAIL));
        // TODO Localize this.
        emailAction.setParameterValue(MailActionExecuter.PARAM_SUBJECT, "Rejected invitation to web site:" + siteName);
        emailAction.setParameterValue(MailActionExecuter.PARAM_TEXT, emailMsg);
        emailAction.setExecuteAsynchronously(true);
        actionService.executeAction(emailAction, null);
    }
    catch (Exception e)
    {
        // Swallow exception
        logger.error("unable to send reject email", e);
    }
}
 
Example 9
Source File: ActionServiceImplTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Test saving an action with no conditions.  Includes testing storage and retrieval 
 * of compensating actions.
 */
@Test
public void testSaveActionNoCondition()
{
    // Create the action
    Action action = this.actionService.createAction(AddFeaturesActionExecuter.NAME);
    String actionId = action.getId();
    
    // Set the parameters of the action
    action.setParameterValue(AddFeaturesActionExecuter.PARAM_ASPECT_NAME, ContentModel.ASPECT_VERSIONABLE);
    
    // Set the title and description of the action
    action.setTitle("title");
    action.setDescription("description");
    action.setExecuteAsynchronously(true);
            
    // Save the action
    this.actionService.saveAction(this.nodeRef, action);
    
    // Get the action
    Action savedAction = this.actionService.getAction(this.nodeRef, actionId);
    
    // Check the action 
    assertEquals(action.getId(), savedAction.getId());
    assertEquals(action.getActionDefinitionName(), savedAction.getActionDefinitionName());
    
    // Check the properties
    assertEquals("title", savedAction.getTitle());
    assertEquals("description", savedAction.getDescription());
    assertTrue(savedAction.getExecuteAsychronously());
    
    // Check that the compensating action has not been set
    assertNull(savedAction.getCompensatingAction());
    
    // Check the properties
    assertEquals(1, savedAction.getParameterValues().size());
    assertEquals(ContentModel.ASPECT_VERSIONABLE, savedAction.getParameterValue(AddFeaturesActionExecuter.PARAM_ASPECT_NAME));
            
    // Check the conditions
    assertNotNull(savedAction.getActionConditions());
    assertEquals(0, savedAction.getActionConditions().size());
    
    // Edit the properties of the action        
    Map<QName, Serializable> properties = new HashMap<QName, Serializable>(1);
    properties.put(ContentModel.PROP_NAME, "testName");
    action.setParameterValue(AddFeaturesActionExecuter.PARAM_ASPECT_NAME, ContentModel.ASPECT_AUDITABLE);
    
    // Set the compensating action
    Action compensatingAction = this.actionService.createAction(AddFeaturesActionExecuter.NAME);
    compensatingAction.setParameterValue(AddFeaturesActionExecuter.PARAM_ASPECT_NAME, ContentModel.ASPECT_VERSIONABLE);
    action.setCompensatingAction(compensatingAction);
    
    this.actionService.saveAction(this.nodeRef, action);
    Action savedAction2 = this.actionService.getAction(this.nodeRef, actionId);
    
    // Check the updated properties
    assertEquals(1, savedAction2.getParameterValues().size());
    assertEquals(ContentModel.ASPECT_AUDITABLE, savedAction2.getParameterValue(AddFeaturesActionExecuter.PARAM_ASPECT_NAME));
    
    // Check the compensating action
    Action savedCompensatingAction = savedAction2.getCompensatingAction();
    assertNotNull(savedCompensatingAction);
    assertEquals(compensatingAction, savedCompensatingAction);
    assertEquals(AddFeaturesActionExecuter.NAME, savedCompensatingAction.getActionDefinitionName());
    assertEquals(ContentModel.ASPECT_VERSIONABLE, savedCompensatingAction.getParameterValue(AddFeaturesActionExecuter.PARAM_ASPECT_NAME));
    
    // Change the details of the compensating action (edit and remove)
    compensatingAction.setParameterValue(AddFeaturesActionExecuter.PARAM_ASPECT_NAME, ContentModel.ASPECT_CLASSIFIABLE);
    this.actionService.saveAction(this.nodeRef, action);
    Action savedAction3 = this.actionService.getAction(this.nodeRef, actionId);
    Action savedCompensatingAction2 = savedAction3.getCompensatingAction();
    assertNotNull(savedCompensatingAction2);
    assertEquals(compensatingAction, savedCompensatingAction2);
    assertEquals(AddFeaturesActionExecuter.NAME, savedCompensatingAction2.getActionDefinitionName());
    assertEquals(ContentModel.ASPECT_CLASSIFIABLE, savedCompensatingAction2.getParameterValue(AddFeaturesActionExecuter.PARAM_ASPECT_NAME));
    action.setCompensatingAction(null);
    this.actionService.saveAction(this.nodeRef, action);
    Action savedAction4 = this.actionService.getAction(this.nodeRef, actionId);
    assertNull(savedAction4.getCompensatingAction());
    
    //System.out.println(NodeStoreInspector.dumpNodeStore(this.nodeService, this.testStoreRef));
}
 
Example 10
Source File: ActionServiceImplTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Test the compensating action
 */
@Test
public void testCompensatingAction()
{
    // Create actions that are going to fail
    final Action fatalAction = createFailingMoveAction(true);
    final Action nonfatalAction = createFailingMoveAction(false);
    fatalAction.setTitle("fatal title");
    nonfatalAction.setTitle("non-fatal title");
    
    // Create the compensating actions
    Action compensatingAction = actionService.createAction(AddFeaturesActionExecuter.NAME);
    compensatingAction.setParameterValue(AddFeaturesActionExecuter.PARAM_ASPECT_NAME, ContentModel.ASPECT_CLASSIFIABLE);
    compensatingAction.setTitle("title");
    fatalAction.setCompensatingAction(compensatingAction);
    
    Action compensatingAction2 = actionService.createAction(AddFeaturesActionExecuter.NAME);
    compensatingAction2.setParameterValue(AddFeaturesActionExecuter.PARAM_ASPECT_NAME, ContentModel.ASPECT_TEMPORARY);
    compensatingAction2.setTitle("title");
    nonfatalAction.setCompensatingAction(compensatingAction2);
    
    
    // Set the actions to execute asynchronously
    fatalAction.setExecuteAsynchronously(true);
    nonfatalAction.setExecuteAsynchronously(true);
    
    this.actionService.executeAction(fatalAction, this.nodeRef);
    this.actionService.executeAction(nonfatalAction, this.nodeRef);

    TestTransaction.flagForCommit();
    TestTransaction.end();
    
    postAsyncActionTest(
            this.transactionService,
            1000, 
            10, 
            new AsyncTest()
            {
                public String executeTest() 
                {
                    boolean fatalCompensatingActionRun = ActionServiceImplTest.this.nodeService.hasAspect(nodeRef, ContentModel.ASPECT_CLASSIFIABLE);
                    
                    boolean nonFatalCompensatingActionRun = ActionServiceImplTest.this.nodeService.hasAspect(nodeRef, ContentModel.ASPECT_TEMPORARY);
                    
                    StringBuilder result = new StringBuilder();
                    if (!fatalCompensatingActionRun)
                    {
                        result.append("Expected aspect Classifiable.");
                    }
                    if (nonFatalCompensatingActionRun)
                    {
                        result.append(" Did not expect aspect Temporary");
                    }
                    
                    return ( !fatalCompensatingActionRun || nonFatalCompensatingActionRun ? result.toString() : null);
                };
            });
    
    // Modify the compensating action so that it will also fail
    compensatingAction.setParameterValue(AddFeaturesActionExecuter.PARAM_ASPECT_NAME, QName.createQName("{test}badAspect"));
    
    this.transactionService.getRetryingTransactionHelper().doInTransaction(
            new RetryingTransactionCallback<Object>()
            {
                public Object execute()
                {                        
                    try
                    {
                        ActionServiceImplTest.this.actionService.executeAction(fatalAction, ActionServiceImplTest.this.nodeRef);
                    }
                    catch (RuntimeException exception)
                    {
                        // The exception should have been ignored and execution continued
                        exception.printStackTrace();
                        fail("An exception should not have been raised here.");
                    }
                    return null;
                }
                
            });
    
}
 
Example 11
Source File: ExecuteAllRulesActionExecuterTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Test for MNT-13055:
 * 
 * We create a folder structure thus:
 * <pre>
 * rootFolder (rule: add an aspect)
 * |
 * +- folderA ("do not inherit rules" + link to rootFolder's rule set) 
 *    |
 *    +- fileA
 *    |
 *    +- folderB
 *       |
 *       +- fileB 
 * </pre>
 * This test case specifies a rule on rootFolder that adds an aspect to all files within.
 * folderA has the ignoreInheritedRules aspect applied, but also links to rootFolder's rule set.
 * <p>
 * We then explicitly execute folderA's rules, including for subfolders. Ultimately, we want to
 * know that fileB did indeed have the ruleset executed on it, and therefore gained the classifiable aspect.
 */
public void testRulesFireOnNonInheritedFolderUsingLinkedRuleSetInstead()
{
    final NodeRef rootFolder = this.nodeService.createNode(
            this.rootNodeRef,
            ContentModel.ASSOC_CHILDREN,
            QName.createQName("{test}rootFolderForTest"),
            ContentModel.TYPE_FOLDER).getChildRef();
    
    final NodeRef folderA = fileFolderService.
            create(rootFolder, "folderA", ContentModel.TYPE_FOLDER).getNodeRef();
    
    // Set folderA to "Don't Inherit Rules".
    nodeService.addAspect(folderA, ASPECT_IGNORE_INHERITED_RULES, Collections.emptyMap());
    
    NodeRef fileA = createFile(folderA, "fileA.txt").getNodeRef();
    
    final NodeRef folderB = fileFolderService.
            create(folderA, "folderB", ContentModel.TYPE_FOLDER).getNodeRef();
    
    NodeRef fileB = createFile(folderB, "fileB.txt").getNodeRef();
    
    // Create a rule on rootFolder
    Rule rule = new Rule();
    rule.setRuleType(RuleType.INBOUND);
    Action action = actionService.createAction(AddFeaturesActionExecuter.NAME);
    action.setParameterValue(AddFeaturesActionExecuter.PARAM_ASPECT_NAME, ContentModel.ASPECT_CLASSIFIABLE);
    rule.setAction(action);
    // It mustn't matter whether this rule "applies to children", since we'll explicitly
    // run it on "the folder and its subfolders".
    rule.applyToChildren(false);
    rule.setExecuteAsynchronously(false);
    ruleService.enableRule(rule);
    ruleService.saveRule(rootFolder, rule);

    // Link to Rule Set of rootFolder to folderA
    Action linkAction = actionService.createAction(LinkRules.NAME);
    linkAction.setParameterValue(LinkRules.PARAM_LINK_FROM_NODE, rootFolder);
    linkAction.setExecuteAsynchronously(false);
    actionService.executeAction(linkAction, folderA);
    
    TestTransaction.flagForCommit();
    TestTransaction.end();

    transactionHelper.doInTransaction(() -> {
        assertFalse(nodeService.hasAspect(folderA, ContentModel.ASPECT_CLASSIFIABLE));
        assertFalse(nodeService.hasAspect(fileA, ContentModel.ASPECT_CLASSIFIABLE));
        assertFalse(nodeService.hasAspect(folderB, ContentModel.ASPECT_CLASSIFIABLE));
        assertFalse(nodeService.hasAspect(fileB, ContentModel.ASPECT_CLASSIFIABLE));
        return null;
    });
    
    
    // rootFolder: "Run rule for this folder and its subfolders".
    transactionHelper.doInTransaction(() -> {
        Map<String, Serializable> actionParams = new HashMap<>();
        actionParams.put(ExecuteAllRulesActionExecuter.PARAM_RUN_ALL_RULES_ON_CHILDREN, true);
        // In Share, when you manually trigger rules on a folder, this parameter (execute-inherited-rules)
        // will be false if the aspect rule:ignoreInheritedRules is present, and true otherwise.
        actionParams.put(ExecuteAllRulesActionExecuter.PARAM_EXECUTE_INHERITED_RULES, false);
        Action rulesAction = actionService.createAction(ExecuteAllRulesActionExecuter.NAME, actionParams);
        executer.execute(rulesAction, folderA);
        return null;
    });

    transactionHelper.doInTransaction(() -> {
        // We're running the rule on folderA, so the folder itself won't be processed.
        assertFalse(nodeService.hasAspect(folderA, ContentModel.ASPECT_CLASSIFIABLE));
        
        // The contents of folderA will all have the aspect added.
        assertTrue(nodeService.hasAspect(fileA, ContentModel.ASPECT_CLASSIFIABLE));
        assertTrue(nodeService.hasAspect(folderB, ContentModel.ASPECT_CLASSIFIABLE));
        // The contents of folderB will all have the aspect added.
        assertTrue(nodeService.hasAspect(fileB, ContentModel.ASPECT_CLASSIFIABLE));
        return null;
    });
}