10-03-2008 03:12 AM
10-08-2010 04:20 AM
var jsonRule = {
title: "Sample Rule",
description: "Sample rule creation",
ruleType: ["inbound"],
applyToChildren: true,
executeAsynchronously: false,
disabled: false,
action :
{
actionDefinitionName: "composite-action",
actions:
[
{
actionDefinitionName: "script",
parameterValues:
{
'script-ref': "workspace://SpacesStore/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
}
}
],
conditions:
[
{
conditionDefinitionName: "no-condition",
parameterValues: {}
}
]
}
};
var jsonRuleBody = jsonUtils.toJSONString(jsonRule);
var uri = '/api/node/workspace/SpacesStore/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/ruleset/rules';
uri += '?alf_ticket=' + session.getTicket();
var rsp = remote.connect('alfresco').post(uri, jsonRuleBody, 'application/json');
07-27-2011 05:16 AM
You can create rules programatically by using the following java code.
I don't know how to do it wid javascript.
For ex: If u want to create rule which converts the arriving document to pdf, u can do it programmatically as follows.
private void setupSpaceRuleConvToPDF(NodeRef data){
Rule rule=new Rule();
rule.setRuleType("inbound");
rule.setTitle("Transform to PDF n copy to Data-PDF");
rule.setDescription("Transform to PDF n copy to Data-PDF");
rule.applyToChildren(false);
// rule.setExecuteAsynchronously(true);
System.out.println("Rule creation started…Part-II");
CompositeAction compositeAction = getActionService().createCompositeAction();
rule.setAction(compositeAction);
ActionCondition actionCondition = getActionService().createActionCondition("no-condition");
actionCondition.setParameterValues(new HashMap());
compositeAction.addActionCondition(actionCondition);
IHandler handler=null;
Map repoActionParams = new HashMap();
Map actionParams=new HashMap();
NodeRef destination = new NodeRef(Repository.getStoreRef(),(String)getNodeService().getProperty(data, ContentModel.ASPECT_COPIEDFROM));
actionParams.put("actionName", "transform");
actionParams.put("transformer", "application/pdf");
actionParams.put("destinationLocation",destination); // prntDestinationNodeRef
actionParams.put("actionSummary", "Transform and copy content to a specific space");
try {
handler=(IHandler)Class.forName("org.alfresco.web.bean.actions.handlers.TransformHandler").newInstance();
} catch (Exception e) {
System.out.println("Class Generation Exception:"+e);
}
if(handler != null){
handler.prepareForSave(actionParams, repoActionParams);
}
//System.out.println("B4 saving action");
Action action = getActionService().createAction("transform");
action.setParameterValues(repoActionParams);
compositeAction.addAction(action);
getRuleService().saveRule(data, rule);
}
08-22-2011 03:01 PM
Hi,
I want to create a rule on a node, from a java backed web script…
I tried the code below in my script but some function are undefined (eg getActionService())
Can someone help me please, I'm a noob on alfresco's java developpment,You can create rules programatically by using the following java code.
I don't know how to do it wid javascript.
For ex: If u want to create rule which converts the arriving document to pdf, u can do it programmatically as follows.
private void setupSpaceRuleConvToPDF(NodeRef data){
Rule rule=new Rule();
rule.setRuleType("inbound");
rule.setTitle("Transform to PDF n copy to Data-PDF");
rule.setDescription("Transform to PDF n copy to Data-PDF");
rule.applyToChildren(false);
// rule.setExecuteAsynchronously(true);
System.out.println("Rule creation started…Part-II");
CompositeAction compositeAction = getActionService().createCompositeAction();
rule.setAction(compositeAction);
ActionCondition actionCondition = getActionService().createActionCondition("no-condition");
actionCondition.setParameterValues(new HashMap());
compositeAction.addActionCondition(actionCondition);
IHandler handler=null;
Map repoActionParams = new HashMap();
Map actionParams=new HashMap();
NodeRef destination = new NodeRef(Repository.getStoreRef(),(String)getNodeService().getProperty(data, ContentModel.ASPECT_COPIEDFROM));
actionParams.put("actionName", "transform");
actionParams.put("transformer", "application/pdf");
actionParams.put("destinationLocation",destination); // prntDestinationNodeRef
actionParams.put("actionSummary", "Transform and copy content to a specific space");
try {
handler=(IHandler)Class.forName("org.alfresco.web.bean.actions.handlers.TransformHandler").newInstance();
} catch (Exception e) {
System.out.println("Class Generation Exception:"+e);
}
if(handler != null){
handler.prepareForSave(actionParams, repoActionParams);
}
//System.out.println("B4 saving action");
Action action = getActionService().createAction("transform");
action.setParameterValues(repoActionParams);
compositeAction.addAction(action);
getRuleService().saveRule(data, rule);
}
Thanks!
05-15-2012 09:37 AM
Repository.getActionService()
08-02-2015 05:17 PM
ServiceRegistry
to your JavaScript somehow, and you need to use the <a href="https://github.com/share-extras/js-console">JavaScript Console</a>. I would advise against injecting the ServiceRegistry
as a root object, as that opens up a huge can of security worms. Injecting your own bean, which does some security checks (eg admin only) is less bad, but still a little evil. Take care, and/or don't go there to start with… Or just inject in the action and rules services securely. Next up, you need to work out the action parameters and condition parameters. These are not fun to do by hand, best bet is to set up a rule much like you want with the UI, then use the node browser to see how that gets turned into composites and name/values.Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.