cancel
Showing results for 
Search instead for 
Did you mean: 

global rule for adding versionable aspect to contents

msj4u
Champ in-the-making
Champ in-the-making
hi,

i am using following code to create a rule in /app:company_home folder and on children spaces.

rule is created but is not executed as expected.

further more when i try to edit that rule from UI explorer it gives
org.alfresco.error.AlfrescoRuntimeException: 02190269 Rules with non-composite actions are not currently supported by the UI



public boolean createVersionableRule() {
      boolean status = true;
      try {
         Action action = new Action();
         action.setActionName("add-features");
         Condition[] conditions = new Condition[1];
         Condition condition = new Condition();
         condition.setConditionName("no-condition");
         conditions[0] = condition;
         action.setConditions(conditions);
         NamedValue namedValue = new NamedValue();
         namedValue.setName("aspect-name");
         namedValue.setValue(Constants.ASPECT_VERSIONABLE);
         NamedValue[] namedValues = new NamedValue[1];
         namedValues[0] = namedValue;
         action.setParameters(namedValues);
         Rule[] rules = new Rule[1];
         Rule rule = new Rule();
         rule.setAction(action);
         rule.setTitle("Add versionable aspect");
         rule.setDescription("Add the versionable aspect to all the items inthe space");
         rule.setExecuteAsynchronously(false);
         rule.setRuleTypes(new String[]{"inbound"});
         rules[0] = rule;
         Reference reference = new Reference(CMSUtil.SPACE_STORE, CMSUtil.getCompanyHomeUUID(), CMSUtil.DEFAULT_COMPANY_HOME_NAME);
         Rule[] resultList = WebServiceFactory.getActionService().saveRules(reference, rules);
         if(resultList!=null && resultList.length>0) {
            Reference owningReference = resultList[0].getOwningReference();
            Reference ruleReference = resultList[0].getRuleReference();
            log.debug("owningReference " + owningReference.getUuid());
            log.debug("ruleReference " + ruleReference.getUuid());
         }
      } catch(Exception e) {
         status = false;
         log.error("problem in creating versionable rule", e);
      }
      return status;
   }


can somebody help here ?
4 REPLIES 4

kaynezhang
World-Class Innovator
World-Class Innovator
If you want to edit a rule and it's associated action in Explorer ,the rule's action  must be  composite action.

You can modify createVersionableRule() and wrap your action into a composite action.

   Action compositeAction = new Action();
         compositeAction.setActionName("composite-action");
      
         Action action = new Action();

         action.setActionName("add-features");
         Condition[] conditions = new Condition[1];
         Condition condition = new Condition();
         condition.setConditionName("no-condition");
         conditions[0] = condition;
         action.setConditions(conditions);
         NamedValue namedValue = new NamedValue();
         namedValue.setName("aspect-name");
         namedValue.setValue(Constants.ASPECT_VERSIONABLE);
         NamedValue[] namedValues = new NamedValue[1];
         namedValues[0] = namedValue;
         action.setParameters(namedValues);
         
         Action actions[]= new Action[1];
         actions[0]=action;
         
         compositeAction.setActions(actions);
         Rule[] rules = new Rule[1];
         Rule rule = new Rule();
         rule.setAction(compositeAction);
         rule.setTitle("Add versionable aspect");
         rule.setDescription("Add the versionable aspect to all the items inthe space");



msj4u
Champ in-the-making
Champ in-the-making
Thanks,

that worked; but it only apply the rule on the /app:company_home folder but i want to inherit that rule on children folder as well.

Any idea how to do that ?


kaynezhang
World-Class Innovator
World-Class Innovator
Alfresco rule has a property named "isAppliedToChildren " which indicates whether this rule should be applied to the children.But it seems alfresco native webservice dose not expose it .So you cann't make a rule applied to the children through webservice.
You can use webscript api.

msj4u
Champ in-the-making
Champ in-the-making
yes thats seems to be the issue; i have updated the alfresco webservice code to handle this.

Thanks again. Smiley Happy