Search in sources :

Example 6 with ActionServiceException

use of org.alfresco.service.cmr.action.ActionServiceException in project alfresco-repository by Alfresco.

the class CompareMimeTypeEvaluator method evaluateImpl.

/**
 * @see org.alfresco.repo.action.evaluator.ActionConditionEvaluatorAbstractBase#evaluateImpl(org.alfresco.service.cmr.action.ActionCondition, org.alfresco.service.cmr.repository.NodeRef)
 */
public boolean evaluateImpl(ActionCondition actionCondition, NodeRef actionedUponNodeRef) {
    QName propertyQName = (QName) actionCondition.getParameterValue(ComparePropertyValueEvaluator.PARAM_PROPERTY);
    if (propertyQName == null) {
        // Default to the standard content property
        actionCondition.setParameterValue(ComparePropertyValueEvaluator.PARAM_PROPERTY, ContentModel.PROP_CONTENT);
    } else {
        // Ensure that we are dealing with a content property
        QName propertyTypeQName = null;
        PropertyDefinition propertyDefintion = this.dictionaryService.getProperty(propertyQName);
        if (propertyDefintion != null) {
            propertyTypeQName = propertyDefintion.getDataType().getName();
            if (DataTypeDefinition.CONTENT.equals(propertyTypeQName) == false) {
                throw new ActionServiceException(ERRID_NOT_A_CONTENT_TYPE);
            }
        } else {
            throw new ActionServiceException(ERRID_NO_PROPERTY_DEFINTION_FOUND);
        }
    }
    // Set the operation to equals
    actionCondition.setParameterValue(ComparePropertyValueEvaluator.PARAM_OPERATION, ComparePropertyValueOperation.EQUALS.toString());
    // Set the content property to be MIMETYPE
    actionCondition.setParameterValue(ComparePropertyValueEvaluator.PARAM_CONTENT_PROPERTY, ContentPropertyName.MIME_TYPE.toString());
    return super.evaluateImpl(actionCondition, actionedUponNodeRef);
}
Also used : QName(org.alfresco.service.namespace.QName) PropertyDefinition(org.alfresco.service.cmr.dictionary.PropertyDefinition) ActionServiceException(org.alfresco.service.cmr.action.ActionServiceException)

Example 7 with ActionServiceException

use of org.alfresco.service.cmr.action.ActionServiceException in project alfresco-repository by Alfresco.

the class ExporterActionExecuter method executeImpl.

/**
 * @see org.alfresco.repo.action.executer.ActionExecuter#execute(Action, NodeRef)
 */
public void executeImpl(Action ruleAction, NodeRef actionedUponNodeRef) {
    File zipFile = null;
    try {
        String packageName = (String) ruleAction.getParameterValue(PARAM_PACKAGE_NAME);
        File dataFile = new File(packageName);
        File contentDir = new File(packageName);
        // create a temporary file to hold the zip
        zipFile = TempFileProvider.createTempFile(TEMP_FILE_PREFIX, ACPExportPackageHandler.ACP_EXTENSION);
        ACPExportPackageHandler zipHandler = new ACPExportPackageHandler(new FileOutputStream(zipFile), dataFile, contentDir, mimetypeService);
        ExporterCrawlerParameters params = new ExporterCrawlerParameters();
        boolean includeChildren = true;
        Boolean withKids = (Boolean) ruleAction.getParameterValue(PARAM_INCLUDE_CHILDREN);
        if (withKids != null) {
            includeChildren = withKids.booleanValue();
        }
        params.setCrawlChildNodes(includeChildren);
        boolean includeSelf = false;
        Boolean andMe = (Boolean) ruleAction.getParameterValue(PARAM_INCLUDE_SELF);
        if (andMe != null) {
            includeSelf = andMe.booleanValue();
        }
        params.setCrawlSelf(includeSelf);
        params.setExportFrom(new Location(actionedUponNodeRef));
        // perform the actual export
        this.exporterService.exportView(zipHandler, params, null);
        // now the export is done we need to create a node in the repository
        // to hold the exported package
        NodeRef zip = createExportZip(ruleAction, actionedUponNodeRef);
        ContentWriter writer = this.contentService.getWriter(zip, ContentModel.PROP_CONTENT, true);
        writer.setEncoding((String) ruleAction.getParameterValue(PARAM_ENCODING));
        writer.setMimetype(MimetypeMap.MIMETYPE_ACP);
        writer.putContent(zipFile);
    } catch (FileNotFoundException fnfe) {
        throw new ActionServiceException("export.package.error", fnfe);
    } finally {
        // try and delete the temporary file
        if (zipFile != null) {
            zipFile.delete();
        }
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) ContentWriter(org.alfresco.service.cmr.repository.ContentWriter) ACPExportPackageHandler(org.alfresco.repo.exporter.ACPExportPackageHandler) FileOutputStream(java.io.FileOutputStream) FileNotFoundException(java.io.FileNotFoundException) ExporterCrawlerParameters(org.alfresco.service.cmr.view.ExporterCrawlerParameters) File(java.io.File) Location(org.alfresco.service.cmr.view.Location) ActionServiceException(org.alfresco.service.cmr.action.ActionServiceException)

Example 8 with ActionServiceException

use of org.alfresco.service.cmr.action.ActionServiceException in project alfresco-repository by Alfresco.

the class DatePropertyValueComparator method compare.

/**
 * @see org.alfresco.repo.action.evaluator.compare.PropertyValueComparator#compare(java.io.Serializable, java.io.Serializable, org.alfresco.repo.action.evaluator.compare.ComparePropertyValueOperation)
 */
public boolean compare(Serializable propertyValue, Serializable compareValue, ComparePropertyValueOperation operation) {
    boolean result = false;
    if (operation == null) {
        operation = ComparePropertyValueOperation.EQUALS;
    }
    Date propertyDate = getDate(propertyValue);
    Date compareDate = getDate(compareValue);
    switch(operation) {
        case EQUALS:
            {
                result = propertyDate.equals(compareDate);
                break;
            }
        case LESS_THAN:
            {
                result = propertyDate.before(compareDate);
                break;
            }
        case LESS_THAN_EQUAL:
            {
                result = (propertyDate.equals(compareDate) || propertyDate.before(compareDate));
                break;
            }
        case GREATER_THAN:
            {
                result = propertyDate.after(compareDate);
                break;
            }
        case GREATER_THAN_EQUAL:
            {
                result = (propertyDate.equals(compareDate) || propertyDate.after(compareDate));
                break;
            }
        default:
            {
                // Raise an invalid operation exception
                throw new ActionServiceException(MSGID_INVALID_OPERATION, new Object[] { operation.toString() });
            }
    }
    return result;
}
Also used : Date(java.util.Date) ActionServiceException(org.alfresco.service.cmr.action.ActionServiceException)

Example 9 with ActionServiceException

use of org.alfresco.service.cmr.action.ActionServiceException in project alfresco-repository by Alfresco.

the class RuleServiceImpl method getSavedRuleFolderAssoc.

/**
 * Gets the saved rule folder reference
 *
 * @param nodeRef    the node reference
 * @return            the node reference
 */
public ChildAssociationRef getSavedRuleFolderAssoc(NodeRef nodeRef) {
    ChildAssociationRef result = null;
    List<ChildAssociationRef> assocs = this.runtimeNodeService.getChildAssocs(nodeRef, RuleModel.ASSOC_RULE_FOLDER, RuleModel.ASSOC_RULE_FOLDER);
    if (assocs.size() > 1) {
        throw new ActionServiceException("There is more than one rule folder, which is invalid.");
    } else if (assocs.size() == 1) {
        result = assocs.get(0);
    }
    return result;
}
Also used : ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) ActionServiceException(org.alfresco.service.cmr.action.ActionServiceException)

Example 10 with ActionServiceException

use of org.alfresco.service.cmr.action.ActionServiceException in project alfresco-repository by Alfresco.

the class ActionServiceImpl method getQueue.

/**
 * Get the queue to use for asynchronous execution of the given action.
 */
private AsynchronousActionExecutionQueue getQueue(Action action) {
    ActionExecuter executer = (ActionExecuter) this.applicationContext.getBean(action.getActionDefinitionName());
    AsynchronousActionExecutionQueue queue = null;
    String queueName = executer.getQueueName();
    if (queueName == null) {
        queue = asynchronousActionExecutionQueues.get("");
    } else {
        queue = asynchronousActionExecutionQueues.get(queueName);
    }
    if (queue == null) {
        // can't get queue
        throw new ActionServiceException("Unable to get AsynchronousActionExecutionQueue name: " + queueName);
    }
    return queue;
}
Also used : ActionExecuter(org.alfresco.repo.action.executer.ActionExecuter) ActionServiceException(org.alfresco.service.cmr.action.ActionServiceException)

Aggregations

ActionServiceException (org.alfresco.service.cmr.action.ActionServiceException)13 ActionConditionImpl (org.alfresco.repo.action.ActionConditionImpl)4 BaseSpringTest (org.alfresco.util.BaseSpringTest)4 Test (org.junit.Test)4 Date (java.util.Date)3 NodeRef (org.alfresco.service.cmr.repository.NodeRef)3 PropertyDefinition (org.alfresco.service.cmr.dictionary.PropertyDefinition)2 ContentWriter (org.alfresco.service.cmr.repository.ContentWriter)2 QName (org.alfresco.service.namespace.QName)2 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 FileOutputStream (java.io.FileOutputStream)1 Serializable (java.io.Serializable)1 ExecutionException (java.util.concurrent.ExecutionException)1 FutureTask (java.util.concurrent.FutureTask)1 ComparePropertyValueOperation (org.alfresco.repo.action.evaluator.compare.ComparePropertyValueOperation)1 ContentPropertyName (org.alfresco.repo.action.evaluator.compare.ContentPropertyName)1 PropertyValueComparator (org.alfresco.repo.action.evaluator.compare.PropertyValueComparator)1 ActionExecuter (org.alfresco.repo.action.executer.ActionExecuter)1 ACPExportPackageHandler (org.alfresco.repo.exporter.ACPExportPackageHandler)1