Java Code Examples for org.alfresco.service.cmr.action.Action#setCompensatingAction()
The following examples show how to use
org.alfresco.service.cmr.action.Action#setCompensatingAction() .
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 |
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: ThumbnailHelper.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
private static void decorateAction(ThumbnailDefinition thumbnailDef, Action action, ActionService actionService) { final FailureHandlingOptions failureOptions = thumbnailDef.getFailureHandlingOptions(); long retryPeriod = failureOptions == null ? FailureHandlingOptions.DEFAULT_PERIOD : failureOptions.getRetryPeriod() * 1000l; int retryCount = failureOptions == null ? FailureHandlingOptions.DEFAULT_RETRY_COUNT : failureOptions.getRetryCount(); long quietPeriod = failureOptions == null ? FailureHandlingOptions.DEFAULT_PERIOD : failureOptions.getQuietPeriod() * 1000l; boolean quietPeriodRetriesEnabled = failureOptions == null ? FailureHandlingOptions.DEFAULT_QUIET_PERIOD_RETRIES_ENABLED : failureOptions.getQuietPeriodRetriesEnabled(); // The thumbnail/action should only be run if it is eligible. Map<String, Serializable> failedThumbnailConditionParams = new HashMap<String, Serializable>(); failedThumbnailConditionParams.put(NodeEligibleForRethumbnailingEvaluator.PARAM_THUMBNAIL_DEFINITION_NAME, thumbnailDef.getName()); failedThumbnailConditionParams.put(NodeEligibleForRethumbnailingEvaluator.PARAM_RETRY_PERIOD, retryPeriod); failedThumbnailConditionParams.put(NodeEligibleForRethumbnailingEvaluator.PARAM_RETRY_COUNT, retryCount); failedThumbnailConditionParams.put(NodeEligibleForRethumbnailingEvaluator.PARAM_QUIET_PERIOD, quietPeriod); failedThumbnailConditionParams.put(NodeEligibleForRethumbnailingEvaluator.PARAM_QUIET_PERIOD_RETRIES_ENABLED, quietPeriodRetriesEnabled); ActionCondition thumbnailCondition = actionService.createActionCondition(NodeEligibleForRethumbnailingEvaluator.NAME, failedThumbnailConditionParams); // If it is run and if it fails, then we want a compensating action to run which will mark // the source node as having failed to produce a thumbnail. Action applyBrokenThumbnail = actionService.createAction("add-failed-thumbnail"); applyBrokenThumbnail.setParameterValue(AddFailedThumbnailActionExecuter.PARAM_THUMBNAIL_DEFINITION_NAME, thumbnailDef.getName()); applyBrokenThumbnail.setParameterValue(AddFailedThumbnailActionExecuter.PARAM_FAILURE_DATETIME, new Date()); action.addActionCondition(thumbnailCondition); action.setCompensatingAction(applyBrokenThumbnail); }
Example 3
Source File: ActionServiceImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
/** * 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 4
Source File: SimpleTemplateActionDefinition.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
/** * Generate the action from the template using the context node. */ public Action getAction(NodeRef nodeRef) { // Get the action definition. We can not go to the service are some are not exposed. // So we find them from the application context. ActionExecuter actionExecutor = (ActionExecuter)applicationContext.getBean(getActionName()); ActionDefinition actionDefinition = actionExecutor.getActionDefinition(); // Build the base action Action action = actionService.createAction(getActionName()); // Go through the template definitions and set the values. for (String paramName : parameterTemplates.keySet()) { // Fetch the template. Need to de-escape things put in to work // around it not being possible to disable SPEL for one bean String template = parameterTemplates.get(paramName); if(template.contains("\\$\\{") || template.contains("\\#\\{")) { template = template.replace("\\$\\{", "${"); template = template.replace("\\#\\{", "#{"); if(template.contains("\\}")) { template = template.replace("\\}", "}"); } } // Transform the template String stringValue = templateService.processTemplateString( getTemplateActionModelFactory().getTemplateEngine(), template, getTemplateActionModelFactory().getModel(nodeRef)); // Find the data type from the action defintion DataTypeDefinition dataTypeDef; if (actionDefinition.getParameterDefintion(paramName) != null) { dataTypeDef = dictionaryService.getDataType( actionDefinition.getParameterDefintion(paramName).getType()); } // Fall back to the DD using the property name of it is not defined // This is sometimes used for setting a property to a value. // There can be no definition for such an ad hoc property. else { dataTypeDef = dictionaryService.getProperty(QName.createQName(paramName)).getDataType(); } // Convert the template result into the correct type and set the parameter Object value = DefaultTypeConverter.INSTANCE.convert(dataTypeDef, stringValue); if (value instanceof Serializable) { action.setParameterValue(paramName, (Serializable) value); } } // If there is a compensating action then set it. if (getCompensatingTemplateCompositeActionDefinition() != null) { action.setCompensatingAction(getCompensatingTemplateCompositeActionDefinition().getAction(nodeRef)); } return action; }
Example 5
Source File: ActionServiceImplTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
/** * 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 6
Source File: ActionServiceImplTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
/** * 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; } }); }