cancel
Showing results for 
Search instead for 
Did you mean: 

A Rule to Add Rules to a Space

hyperation
Champ on-the-rise
Champ on-the-rise
Hi Everyone,

What I am trying to do:

Create a Rule in a space that adds rules to sub-spaces within this space.

Example:
When a space is created in "this" space, a rule is applied to it.

–>Packets
—->packet01 (attaches a rule for this space)
—->packet02 (attaches a rule for this space)

Thanks
Hyperation Smiley Happy
1 REPLY 1

sanket
Champ on-the-rise
Champ on-the-rise
I have used the following code for it. When I create a space, a rule (Transform n copy content to PDF) is automatically applied to it and its sub-spaces.

private void setupSpaceRuleConvToPDF(NodeRef nodeRef1){
      
      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(true);
       // 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();
       
       
       
        actionParams.put("actionName", "transform");
        actionParams.put("transformer", "application/pdf");
        actionParams.put("destinationLocation",nodeRef1 ); // 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(nodeRef1, rule);
   }

Hope, it helps you. U'll need to import d necessary classes.
Thanks.