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);
}
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;
}
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;
}
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);
}
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;
}
Aggregations