cancel
Showing results for 
Search instead for 
Did you mean: 

Create rule through webservice

aditya
Champ in-the-making
Champ in-the-making
I wish to create a rule using webservice, can someone point me to relavent documentation or probably an example.

Thanks in advance
Aditya.
1 REPLY 1

lamsao
Champ in-the-making
Champ in-the-making
Hi Aditya,

Below is a working example rule that I've been using for my project.  I don't need to set Parameters, but I have to set it to get the ws working. 
You can try to run and see how it works.

Good luck,
lamsao

Reference ref = new Reference(STORE, null, "app:company_home");
Rule[] rules = WebServiceFactory.getActionService().getRules(ref, null);
Random generator = new Random();
int conditionId = generator.nextInt(1000);
System.out.println("create new rule");
Condition condition = new Condition();
condition.setId(String.valueOf(conditionId));
condition.setConditionName("no-condition");
condition.setParameters(new NamedValue[]{new NamedValue("test", false, Constants.TYPE_CONTENT, null)});
   
NamedValue[] aparameters = new NamedValue[]{new NamedValue("test", false, Constants.TYPE_CONTENT, null)};       
Action newAction = new Action();
newAction.setActionName("extract-metadata");
newAction.setParameters(aparameters);
             
            
Rule rule = new Rule();
rule.setRuleTypes(new String[] {"update", "inbound"});
rule.setTitle("ExtractMetadata");
rule.setAction(newAction);
newAction.setConditions(new Condition[] {condition});
         
WebServiceFactory.getActionService().saveRules(ref, new Rule[] {rule});
rule.setExecuteAsynchronously(true