cancel
Showing results for 
Search instead for 
Did you mean: 

How to set a rule dynamically on a space ?

kishore
Champ in-the-making
Champ in-the-making
Hi All,

         As part of task,i need to set a rule dynamically through code so that i can trigger a rule on particular space for the files coming into those space.Bcz at runtime only i will be known on which space i need to set.

      Can anybody suggest atleast give some idea how it can be done.


Thanks in advance,
kishore
2 REPLIES 2

rivetlogic
Champ on-the-rise
Champ on-the-rise
Check out the RuleService:
org.alfresco.service.cmr.rule.RuleService

The RuleService allows you to create rules dynamically and set them to the space of your choice.

For example:

            // Create a condition
            ActionCondition actionCondition = actionService.createActionCondition(NoConditionEvaluator.NAME);
            
            // Create an action
            Action actionAddAspect = actionService.createAction(AddFeaturesActionExecuter.NAME);
            actionAddAspect.setTitle("Add some aspect.");
            actionAddAspect.setExecuteAsynchronously(false);
            actionAddAspect.setParameterValue(AddFeaturesActionExecuter.PARAM_ASPECT_NAME, [aspectQName]);
            actionAddAspect.setParameterValue(AddFeaturesActionExecuter.PARAM_ASPECT_PROPERTIES, [aspectParams]);

            // Create a rule
            Rule rule = ruleService.createRule("inbound");
            rule.setTitle("My New'N'Shiny Inbound Rule");
            rule.applyToChildren(true);
            rule.addActionCondition(actionCondition);
            rule.addAction(actionAddAspect);
            
            ruleService.saveRule([targetNode], rule);

Hope that helps.

–Sumer

clincks
Champ in-the-making
Champ in-the-making
How to filter the rule on a content (not a space)?

Thanks