Search in sources :

Example 1 with ActionExecuter

use of org.alfresco.repo.action.executer.ActionExecuter in project alfresco-repository by Alfresco.

the class XmlMetadataExtracterTest method testLifecycleOfXmlMetadataExtraction.

/**
 * Tests metadata extraction using an action with an EAGER MetadataExtracter for XML.
 */
public void testLifecycleOfXmlMetadataExtraction() throws Exception {
    NodeService nodeService = serviceRegistry.getNodeService();
    ContentService contentService = serviceRegistry.getContentService();
    ActionExecuter executer = (ActionExecuter) ctx.getBean("extract-metadata");
    Action action = new ActionImpl(null, GUID.generate(), SetPropertyValueActionExecuter.NAME, null);
    StoreRef storeRef = new StoreRef("test", getName());
    NodeRef rootNodeRef = null;
    if (nodeService.exists(storeRef)) {
        rootNodeRef = nodeService.getRootNode(storeRef);
    } else {
        nodeService.createStore("test", getName());
        rootNodeRef = nodeService.getRootNode(storeRef);
    }
    // Set up some properties
    PropertyMap properties = new PropertyMap();
    properties.put(ContentModel.PROP_TITLE, "My title");
    properties.put(ContentModel.PROP_DESCRIPTION, "My description");
    NodeRef contentNodeRef = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, getName()), ContentModel.TYPE_CONTENT, properties).getChildRef();
    // Add some content
    ContentReader alfrescoModelReader = getReader(FILE_ALFRESCO_MODEL);
    assertTrue(alfrescoModelReader.exists());
    ContentWriter writer = contentService.getWriter(contentNodeRef, ContentModel.PROP_CONTENT, true);
    writer.setEncoding("UTF-8");
    writer.setMimetype(MimetypeMap.MIMETYPE_XML);
    writer.putContent(alfrescoModelReader);
    // Execute the action
    executer.execute(action, contentNodeRef);
    // Check the node's properties.  The EAGER overwrite policy should have replaced the required
    // properties.
    String checkTitle = (String) nodeService.getProperty(contentNodeRef, ContentModel.PROP_TITLE);
    String checkDescription = (String) nodeService.getProperty(contentNodeRef, ContentModel.PROP_DESCRIPTION);
    assertEquals("fm:forummodel", checkTitle);
    assertEquals("Forum Model", checkDescription);
}
Also used : StoreRef(org.alfresco.service.cmr.repository.StoreRef) NodeRef(org.alfresco.service.cmr.repository.NodeRef) Action(org.alfresco.service.cmr.action.Action) ContentWriter(org.alfresco.service.cmr.repository.ContentWriter) FileContentWriter(org.alfresco.repo.content.filestore.FileContentWriter) PropertyMap(org.alfresco.util.PropertyMap) NodeService(org.alfresco.service.cmr.repository.NodeService) FileContentReader(org.alfresco.repo.content.filestore.FileContentReader) ContentReader(org.alfresco.service.cmr.repository.ContentReader) ActionImpl(org.alfresco.repo.action.ActionImpl) ContentService(org.alfresco.service.cmr.repository.ContentService) ActionExecuter(org.alfresco.repo.action.executer.ActionExecuter) SetPropertyValueActionExecuter(org.alfresco.repo.action.executer.SetPropertyValueActionExecuter)

Example 2 with ActionExecuter

use of org.alfresco.repo.action.executer.ActionExecuter in project alfresco-repository by Alfresco.

the class ActionServiceImpl method getActionDefinition.

/**
 * @see org.alfresco.service.cmr.action.ActionService#getActionDefinition(java.lang.String)
 */
public ActionDefinition getActionDefinition(String name) {
    // get direct access to action definition (i.e. ignoring public flag of
    // executer)
    ActionDefinition definition = null;
    Object bean = this.applicationContext.getBean(name);
    if (bean != null && bean instanceof ActionExecuter) {
        ActionExecuter executer = (ActionExecuter) bean;
        definition = executer.getActionDefinition();
    }
    return definition;
}
Also used : ActionExecuter(org.alfresco.repo.action.executer.ActionExecuter) ActionDefinition(org.alfresco.service.cmr.action.ActionDefinition)

Example 3 with ActionExecuter

use of org.alfresco.repo.action.executer.ActionExecuter 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)

Example 4 with ActionExecuter

use of org.alfresco.repo.action.executer.ActionExecuter in project alfresco-repository by Alfresco.

the class ActionServiceImpl method directActionExecution.

/**
 * @see org.alfresco.repo.action.RuntimeActionService#directActionExecution(org.alfresco.service.cmr.action.Action,
 *      org.alfresco.service.cmr.repository.NodeRef)
 */
public void directActionExecution(Action action, NodeRef actionedUponNodeRef) {
    // Debug output
    if (logger.isDebugEnabled()) {
        logger.debug("The action is being executed as the user: " + this.authenticationContext.getCurrentUserName());
    }
    // Get the action executer and execute
    ActionExecuter executer = (ActionExecuter) this.applicationContext.getBean(action.getActionDefinitionName());
    executer.execute(action, actionedUponNodeRef);
}
Also used : ActionExecuter(org.alfresco.repo.action.executer.ActionExecuter)

Example 5 with ActionExecuter

use of org.alfresco.repo.action.executer.ActionExecuter in project alfresco-repository by Alfresco.

the class SimpleTemplateActionDefinition method getAction.

/**
 * 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());
        } else // 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.
        {
            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;
}
Also used : Action(org.alfresco.service.cmr.action.Action) Serializable(java.io.Serializable) ActionExecuter(org.alfresco.repo.action.executer.ActionExecuter) DataTypeDefinition(org.alfresco.service.cmr.dictionary.DataTypeDefinition) ActionDefinition(org.alfresco.service.cmr.action.ActionDefinition)

Aggregations

ActionExecuter (org.alfresco.repo.action.executer.ActionExecuter)5 Action (org.alfresco.service.cmr.action.Action)2 ActionDefinition (org.alfresco.service.cmr.action.ActionDefinition)2 Serializable (java.io.Serializable)1 ActionImpl (org.alfresco.repo.action.ActionImpl)1 SetPropertyValueActionExecuter (org.alfresco.repo.action.executer.SetPropertyValueActionExecuter)1 FileContentReader (org.alfresco.repo.content.filestore.FileContentReader)1 FileContentWriter (org.alfresco.repo.content.filestore.FileContentWriter)1 ActionServiceException (org.alfresco.service.cmr.action.ActionServiceException)1 DataTypeDefinition (org.alfresco.service.cmr.dictionary.DataTypeDefinition)1 ContentReader (org.alfresco.service.cmr.repository.ContentReader)1 ContentService (org.alfresco.service.cmr.repository.ContentService)1 ContentWriter (org.alfresco.service.cmr.repository.ContentWriter)1 NodeRef (org.alfresco.service.cmr.repository.NodeRef)1 NodeService (org.alfresco.service.cmr.repository.NodeService)1 StoreRef (org.alfresco.service.cmr.repository.StoreRef)1 PropertyMap (org.alfresco.util.PropertyMap)1