use of org.alfresco.service.cmr.action.ActionServiceException in project alfresco-repository by Alfresco.
the class AbstractTransformationRenderingEngine method render.
/*
* (non-Javadoc)
* @see org.alfresco.repo.rendition.executer.AbstractRenderingEngine#render(org.alfresco.repo.rendition.executer.AbstractRenderingEngine.RenderingContext)
*/
@Override
protected void render(RenderingContext context) {
ContentReader contentReader = context.makeContentReader();
// There will have been an exception if there is no content data so contentReader is not null.
String contentUrl = contentReader.getContentUrl();
String sourceMimeType = contentReader.getMimetype();
String targetMimeType = getTargetMimeType(context);
// The child NodeRef gets created here
TransformationOptions transformationOptions = getTransformOptions(context);
long sourceSizeInBytes = contentReader.getSize();
Map<String, String> options = converter.getOptions(transformationOptions, sourceMimeType, targetMimeType);
NodeRef sourceNodeRef = transformationOptions.getSourceNodeRef();
if (!synchronousTransformClient.isSupported(sourceMimeType, sourceSizeInBytes, contentUrl, targetMimeType, options, null, sourceNodeRef)) {
String optionsString = TransformerDebug.toString(options);
throw new RenditionServiceException(String.format(NOT_TRANSFORMABLE_MESSAGE_PATTERN, sourceMimeType, targetMimeType, optionsString));
}
long startTime = new Date().getTime();
boolean actionCancelled = false;
boolean actionCompleted = false;
// Cache the execution summary to get details later
ExecutionSummary executionSummary = null;
try {
executionSummary = getExecutionSummary(context);
} catch (ActionServiceException e) {
if (logger.isInfoEnabled()) {
logger.info("Cancelling of multiple concurrent action instances " + "currently unsupported, this action can't be cancelled");
}
}
// Call the transform in a different thread so we can move on if cancelled
FutureTask<ContentWriter> transformTask = new FutureTask<ContentWriter>(new TransformationCallable(contentReader, targetMimeType, transformationOptions, context, AuthenticationUtil.getFullyAuthenticatedUser()));
getExecutorService().execute(transformTask);
// Start checking for cancellation or timeout
while (true) {
try {
Thread.sleep(CANCELLED_ACTION_POLLING_INTERVAL);
if (transformTask.isDone()) {
actionCompleted = true;
break;
}
// Check timeout in case transformer doesn't obey it
if (transformationOptions.getTimeoutMs() > 0 && new Date().getTime() - startTime > (transformationOptions.getTimeoutMs() + CANCELLED_ACTION_POLLING_INTERVAL)) {
// We hit a timeout, let the transform thread continue but results will be ignored
if (logger.isDebugEnabled()) {
logger.debug("Transformation did not obey timeout limit, " + "rendition action is moving on");
}
break;
}
if (executionSummary != null) {
ExecutionDetails executionDetails = actionTrackingService.getExecutionDetails(executionSummary);
if (executionDetails != null) {
actionCancelled = executionDetails.isCancelRequested();
if (actionCancelled) {
if (logger.isDebugEnabled()) {
logger.debug("Cancelling transformation");
}
transformTask.cancel(true);
break;
}
}
}
} catch (InterruptedException e) {
// entire thread was asked to stop
actionCancelled = true;
transformTask.cancel(true);
break;
}
}
if (actionCancelled) {
throw new RenditionCancelledException("Rendition action cancelled");
}
if (!actionCompleted && !actionCancelled) {
throw new RenditionServiceException("Transformation failed to obey timeout limit");
}
if (actionCompleted) {
// Copy content from temp writer to real writer
ContentWriter writer = context.makeContentWriter();
try {
// We should not need another timeout here, things should be ready for us
ContentWriter tempTarget = transformTask.get();
if (tempTarget == null) {
// We should never be in this state, but just in case
throw new RenditionServiceException("Target of transformation not present");
}
writer.putContent(tempTarget.getReader().getContentInputStream());
} catch (ExecutionException e) {
// Unwrap our cause and throw that
Throwable transformException = e.getCause();
if (transformException instanceof RuntimeException) {
throw (RuntimeException) e.getCause();
}
throw new RenditionServiceException(TRANSFORMING_ERROR_MESSAGE + e.getCause().getMessage(), e.getCause());
} catch (InterruptedException e) {
// We were asked to stop
transformTask.cancel(true);
}
}
}
use of org.alfresco.service.cmr.action.ActionServiceException in project alfresco-repository by Alfresco.
the class ComparePropertyValueEvaluatorTest method testTextComparison.
/**
* Test text comparison
*/
@Test
public void testTextComparison() {
ActionConditionImpl condition = new ActionConditionImpl(GUID.generate(), ComparePropertyValueEvaluator.NAME);
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_PROPERTY, PROP_TEXT);
// Test default operations implied by presence and position of *
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, "*.doc");
assertTrue(this.evaluator.evaluate(condition, this.nodeRef));
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, "*.xls");
assertFalse(this.evaluator.evaluate(condition, this.nodeRef));
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, "my*");
assertTrue(this.evaluator.evaluate(condition, this.nodeRef));
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, "bad*");
assertFalse(this.evaluator.evaluate(condition, this.nodeRef));
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, "Document");
assertTrue(this.evaluator.evaluate(condition, this.nodeRef));
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, "bobbins");
assertFalse(this.evaluator.evaluate(condition, this.nodeRef));
// Test equals operator
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_OPERATION, ComparePropertyValueOperation.EQUALS.toString());
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, TEXT_VALUE);
assertTrue(this.evaluator.evaluate(condition, this.nodeRef));
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, "bobbins");
assertFalse(this.evaluator.evaluate(condition, this.nodeRef));
// Test contains operator
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_OPERATION, ComparePropertyValueOperation.CONTAINS.toString());
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, "Document");
assertTrue(this.evaluator.evaluate(condition, this.nodeRef));
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, "bobbins");
assertFalse(this.evaluator.evaluate(condition, this.nodeRef));
// Test begins operator
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_OPERATION, ComparePropertyValueOperation.BEGINS.toString());
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, "my");
assertTrue(this.evaluator.evaluate(condition, this.nodeRef));
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, "bobbins");
assertFalse(this.evaluator.evaluate(condition, this.nodeRef));
// Test ends operator
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_OPERATION, ComparePropertyValueOperation.ENDS.toString());
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, "doc");
assertTrue(this.evaluator.evaluate(condition, this.nodeRef));
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, "bobbins");
assertFalse(this.evaluator.evaluate(condition, this.nodeRef));
// Ensure other operators are invalid
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_OPERATION, ComparePropertyValueOperation.GREATER_THAN.toString());
try {
this.evaluator.evaluate(condition, this.nodeRef);
fail("An exception should have been raised here.");
} catch (ActionServiceException exception) {
exception.printStackTrace();
}
;
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_OPERATION, ComparePropertyValueOperation.GREATER_THAN_EQUAL.toString());
try {
this.evaluator.evaluate(condition, this.nodeRef);
fail("An exception should have been raised here.");
} catch (ActionServiceException exception) {
}
;
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_OPERATION, ComparePropertyValueOperation.LESS_THAN.toString());
try {
this.evaluator.evaluate(condition, this.nodeRef);
fail("An exception should have been raised here.");
} catch (ActionServiceException exception) {
}
;
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_OPERATION, ComparePropertyValueOperation.LESS_THAN_EQUAL.toString());
try {
this.evaluator.evaluate(condition, this.nodeRef);
fail("An exception should have been raised here.");
} catch (ActionServiceException exception) {
}
;
}
use of org.alfresco.service.cmr.action.ActionServiceException in project alfresco-repository by Alfresco.
the class ComparePropertyValueEvaluatorTest method testOtherComparison.
/**
* Test comparison of properties that do not have a registered comparitor
*/
@Test
public void testOtherComparison() {
NodeRef badNodeRef = new NodeRef(this.testStoreRef, "badId");
ActionConditionImpl condition = new ActionConditionImpl(GUID.generate(), ComparePropertyValueEvaluator.NAME);
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_PROPERTY, PROP_NODEREF);
// Test default operation
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, this.nodeValue);
assertTrue(this.evaluator.evaluate(condition, this.nodeRef));
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, badNodeRef);
assertFalse(this.evaluator.evaluate(condition, this.nodeRef));
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, "this isn't even the correct type!");
assertFalse(this.evaluator.evaluate(condition, this.nodeRef));
// Test equals operation
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_OPERATION, ComparePropertyValueOperation.EQUALS.toString());
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, this.nodeValue);
assertTrue(this.evaluator.evaluate(condition, this.nodeRef));
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, badNodeRef);
assertFalse(this.evaluator.evaluate(condition, this.nodeRef));
// Ensure other operators are invalid
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_OPERATION, ComparePropertyValueOperation.BEGINS.toString());
try {
this.evaluator.evaluate(condition, this.nodeRef);
fail("An exception should have been raised here.");
} catch (ActionServiceException exception) {
exception.printStackTrace();
}
;
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_OPERATION, ComparePropertyValueOperation.ENDS.toString());
try {
this.evaluator.evaluate(condition, this.nodeRef);
fail("An exception should have been raised here.");
} catch (ActionServiceException exception) {
}
;
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_OPERATION, ComparePropertyValueOperation.CONTAINS.toString());
try {
this.evaluator.evaluate(condition, this.nodeRef);
fail("An exception should have been raised here.");
} catch (ActionServiceException exception) {
}
;
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_OPERATION, ComparePropertyValueOperation.GREATER_THAN.toString());
try {
this.evaluator.evaluate(condition, this.nodeRef);
fail("An exception should have been raised here.");
} catch (ActionServiceException exception) {
}
;
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_OPERATION, ComparePropertyValueOperation.GREATER_THAN_EQUAL.toString());
try {
this.evaluator.evaluate(condition, this.nodeRef);
fail("An exception should have been raised here.");
} catch (ActionServiceException exception) {
}
;
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_OPERATION, ComparePropertyValueOperation.LESS_THAN.toString());
try {
this.evaluator.evaluate(condition, this.nodeRef);
fail("An exception should have been raised here.");
} catch (ActionServiceException exception) {
}
;
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_OPERATION, ComparePropertyValueOperation.LESS_THAN_EQUAL.toString());
try {
this.evaluator.evaluate(condition, this.nodeRef);
fail("An exception should have been raised here.");
} catch (ActionServiceException exception) {
}
;
}
use of org.alfresco.service.cmr.action.ActionServiceException in project alfresco-repository by Alfresco.
the class ComparePropertyValueEvaluatorTest method testDateComparison.
/**
* Test date comparison
*/
@Test
public void testDateComparison() {
ActionConditionImpl condition = new ActionConditionImpl(GUID.generate(), ComparePropertyValueEvaluator.NAME);
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_PROPERTY, PROP_DATETIME);
// Test the default operation
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, this.dateValue);
assertTrue(this.evaluator.evaluate(condition, this.nodeRef));
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, new Date());
assertFalse(this.evaluator.evaluate(condition, this.nodeRef));
// Test the equals operation
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_OPERATION, ComparePropertyValueOperation.EQUALS.toString());
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, this.dateValue);
assertTrue(this.evaluator.evaluate(condition, this.nodeRef));
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, new Date());
assertFalse(this.evaluator.evaluate(condition, this.nodeRef));
// Test equals greater than operation
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_OPERATION, ComparePropertyValueOperation.GREATER_THAN.toString());
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, this.beforeDateValue);
assertTrue(this.evaluator.evaluate(condition, this.nodeRef));
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, this.afterDateValue);
assertFalse(this.evaluator.evaluate(condition, this.nodeRef));
// Test equals greater than operation
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_OPERATION, ComparePropertyValueOperation.GREATER_THAN_EQUAL.toString());
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, this.beforeDateValue);
assertTrue(this.evaluator.evaluate(condition, this.nodeRef));
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, this.dateValue);
assertTrue(this.evaluator.evaluate(condition, this.nodeRef));
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, this.afterDateValue);
assertFalse(this.evaluator.evaluate(condition, this.nodeRef));
// Test equals less than operation
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_OPERATION, ComparePropertyValueOperation.LESS_THAN.toString());
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, this.afterDateValue);
assertTrue(this.evaluator.evaluate(condition, this.nodeRef));
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, this.beforeDateValue);
assertFalse(this.evaluator.evaluate(condition, this.nodeRef));
// Test equals less than equals operation
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_OPERATION, ComparePropertyValueOperation.LESS_THAN_EQUAL.toString());
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, this.afterDateValue);
assertTrue(this.evaluator.evaluate(condition, this.nodeRef));
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, this.dateValue);
assertTrue(this.evaluator.evaluate(condition, this.nodeRef));
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, this.beforeDateValue);
assertFalse(this.evaluator.evaluate(condition, this.nodeRef));
// Ensure other operators are invalid
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_OPERATION, ComparePropertyValueOperation.BEGINS.toString());
try {
this.evaluator.evaluate(condition, this.nodeRef);
fail("An exception should have been raised here.");
} catch (ActionServiceException exception) {
exception.printStackTrace();
}
;
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_OPERATION, ComparePropertyValueOperation.ENDS.toString());
try {
this.evaluator.evaluate(condition, this.nodeRef);
fail("An exception should have been raised here.");
} catch (ActionServiceException exception) {
}
;
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_OPERATION, ComparePropertyValueOperation.CONTAINS.toString());
try {
this.evaluator.evaluate(condition, this.nodeRef);
fail("An exception should have been raised here.");
} catch (ActionServiceException exception) {
}
;
}
use of org.alfresco.service.cmr.action.ActionServiceException in project alfresco-repository by Alfresco.
the class ActionServiceImpl method executeActionImpl.
@Override
public void executeActionImpl(Action action, NodeRef actionedUponNodeRef, boolean checkConditions, boolean executedAsynchronously, Set<String> actionChain) {
if (logger.isDebugEnabled() == true) {
StringBuilder builder = new StringBuilder("Execute action impl action chain = ");
if (actionChain == null) {
builder.append("null");
} else {
for (String value : actionChain) {
builder.append(value).append(" ");
}
}
logger.debug(builder.toString());
logger.debug("Current action = " + action.getId());
}
// MNT-15365
if (actionedUponNodeRef != null && !this.nodeService.exists(actionedUponNodeRef)) {
if (logger.isDebugEnabled() == true) {
logger.debug("Node = " + actionedUponNodeRef.getId() + " skip action because node doesn't exist");
}
return;
}
// get the current user early in case the process fails and we are
// unable to do it later
String currentUserName = this.authenticationContext.getCurrentUserName();
if (actionChain == null || actionChain.contains(action.getId()) == false) {
if (logger.isDebugEnabled() == true) {
logger.debug("Doing executeActionImpl");
}
try {
Set<String> origActionChain = null;
if (actionChain == null) {
actionChain = new HashSet<String>();
} else {
origActionChain = new HashSet<String>(actionChain);
}
actionChain.add(action.getId());
this.currentActionChain.set(actionChain);
if (logger.isDebugEnabled() == true) {
logger.debug("Adding " + action.getActionDefinitionName() + ", " + action.getId() + " to action chain.");
}
try {
// Check and execute now
if (checkConditions == false || evaluateAction(action, actionedUponNodeRef) == true) {
if (getTrackStatus(action)) {
// Mark the action as starting
actionTrackingService.recordActionExecuting(action, actionedUponNodeRef);
}
RunningAction runningAction = monitor.actionStarted(action);
try {
// Execute the action
directActionExecution(action, actionedUponNodeRef);
} catch (Throwable e) {
runningAction.setException(e);
throw e;
} finally {
monitor.actionCompleted(runningAction);
}
if (getTrackStatus(action)) {
// Mark it as having worked
actionTrackingService.recordActionComplete(action);
}
}
} finally {
if (origActionChain == null) {
this.currentActionChain.remove();
} else {
this.currentActionChain.set(origActionChain);
}
if (logger.isDebugEnabled() == true) {
logger.debug("Resetting the action chain.");
}
}
} catch (ActionServiceTransientException transientException) {
// but which will not lead to the execution of any compensating action
if (getTrackStatus(action)) {
actionTrackingService.recordActionFailure(action, transientException);
}
} catch (Throwable exception) {
// which can handle the rethrown exception.
if (executedAsynchronously == true) {
// If one is specified, queue the compensating action ready
// for execution
Action compensatingAction = action.getCompensatingAction();
if (compensatingAction != null) {
// Set the current user & tenant. These should be the same for the primary action and the compensating action.
((ActionImpl) compensatingAction).setRunAsUser(currentUserName);
((ActionImpl) compensatingAction).setTenantId(((ActionImpl) action).getTenantId());
queueAction(compensatingAction, actionedUponNodeRef);
}
}
if (getTrackStatus(action)) {
// Have the failure logged on the action
actionTrackingService.recordActionFailure(action, exception);
}
// Rethrow the exception
if (exception instanceof RuntimeException) {
throw (RuntimeException) exception;
} else {
throw new ActionServiceException(ERR_FAIL, exception);
}
}
}
}
Aggregations