cancel
Showing results for 
Search instead for 
Did you mean: 

Adding a rule to a folder

doblek
Champ in-the-making
Champ in-the-making
Hi all,

I'm trying to add the following rule to a folder using WebServices:
When some content (placed at this folder, let's call it folder «A») is checked out, the working copy must be placed at another folder (let's call it «B»).
but i don't see how  Smiley Surprisedops:

I don't know even if what I'm trying to achieve is possible since I don't see any condition that indicates "checked-out content".
How can i retrieve the working copy and move it to the desired folder?


It could be nice either if content could have an aspect applied telling it has been approved so it could be moved to another folder… Is it possible to create this new aspect? How could it be used as condition?

Any suggestion will be much appreciated…

Regards,
Enrique
5 REPLIES 5

sam69
Champ in-the-making
Champ in-the-making
Hi,
I am aslo trying to add a rule using webservice, but I am confronted (again) with the lack of documentation…
So sorry, I can't really help you at the moment, but I hope someone else will 😉

I have found a sample for creating a rule :

// Create the action
        NamedValue[] parameters = new NamedValue[]{new NamedValue("aspect-name", false, Constants.ASPECT_CLASSIFIABLE, null)};       
        Action newAction = new Action();
        newAction.setActionName("add-features");
        newAction.setParameters(parameters);
       
        // Create the rule
        Rule newRule = new Rule();
        newRule.setRuleTypes(new String[]{"incomming"});
        newRule.setTitle("This rule adds the classificable aspect");
        newRule.setAction(newAction);
       
        // Save the rule
        Rule[] saveResults1 = this.actionService.saveRules(BaseWebServiceSystemTest.contentReference, new Rule[]{newRule});
It looks simple, but I didn't manage to find a file where all the constants enum (like ActionName, RuleType etc…) are repertoried. It looks like it's hard written in the code on each class 😞
Does anybody can explain us where to find the possible constants values?

Cheers,
Samuel

doblek
Champ in-the-making
Champ in-the-making
Hi Samuel,

Yes, documentation about adding rules through "web services" is still little and sometimes leads to some mistakes (for example, there is an atribute for conditions and actions —called "ID"— that is supposed to be read-only, but whenever you want to create a condition or an action, you have to write something in it if you don't want to get an error…)

I didn't find those constants you were searching in any file, so I wrote a code to get some info about them… (Sorry, traces are in Spanish, but I think you can get it right… If don't, let me know, and I translate them for you)

Actions
ActionItemDefinition[] actions = WebServiceFactory.getActionService().getActionDefinitions();
trace += "Existen "+ actions.length + " definiciones de acciones.<BR>";
for (int j=0; j<=(actions.length-1); j++){
trace += "Definición("+j+"): "+actions[j].getName() + " | " + actions[j].getType().toString()+"<BR>";
}

Conditions
ActionItemDefinition[] conditions = WebServiceFactory.getActionService().getConditionDefinitions();
trace += "Existen "+ conditions.length + " definiciones de condiciones.<BR>";
for (int j=0; j<=(conditions.length-1); j++){
trace += "Definición("+j+"): "+conditions[j].getName() + " | " + conditions[j].getType().toString() + "<BR>";
}

Rule types
RuleType[] array = WebServiceFactory.getActionService().getRuleTypes();
trace += "Existen "+ array.length + " tipos de reglas:<BR>";
for (int j=0; j<=(array.length-1); j++){
trace += "Regla("+j+"): "+array[j].getName() + " | " + array[j].getDisplayLabel()+"<BR>";
}

And this is what I got:
Actions
Existen 15 definiciones de acciones.
Definición(0): transform | action
Definición(1): script | action
Definición(2): copy | action
Definición(3): add-features | action
Definición(4): link-category | action
Definición(5): simple-workflow | action
Definición(6): mail | action
Definición(7): import | action
Definición(8): extract-metadata | action
Definición(9): check-out | action
Definición(10): remove-features | action
Definición(11): check-in | action
Definición(12): specialise-type | action
Definición(13): transform-image | action
Definición(14): move | action

Conditions
Existen 6 definiciones de condiciones.
Definición(0): compare-property-value | condition
Definición(1): in-category | condition
Definición(2): no-condition | condition
Definición(3): has-aspect | condition
Definición(4): compare-mime-type | condition
Definición(5): is-subtype | condition

Rule types
Existen 3 tipos de reglas:
Regla(0): update | Update
Regla(1): outbound | Outbound
Regla(2): inbound | Inbound

I've already found that example 😃 In fact, I've been using it in order to get my rule running, but still no success…

I was trying to insert a rule in a folder that adds versionable aspect to the all content created in it or uploaded to it:
//Condition
trace += "Trying to create the condition…";
Condition condition = new Condition();
condition.setId("1");
condition.setConditionName("is-subtype");
condition.setInvertCondition(false);
condition.setParameters(new NamedValue[]{new NamedValue("is-subtype", false, Constants.TYPE_CONTENT, null)});
trace += "Done!<BR>";

//Action
trace += "Trying to create the action…";
NamedValue[] parameters = new NamedValue[]{new NamedValue("aspect-name", false, Constants.ASPECT_VERSIONABLE, null)};
Action cvs_action = new Action();
cvs_action.setId("1");
cvs_action.setActionName("add-features");
cvs_action.setActionReference(folder_ref);
cvs_action.setParameters(parameters);
cvs_action.setConditions(new Condition[]{condition});
trace += "Done!<BR>";

//Rule
trace += "Trying to create the rule…";
Rule cvs_rule = new Rule();
cvs_rule.setRuleTypes(new String[]{"Inbound"});
cvs_rule.setTitle("Versioning");
cvs_rule.setDescription("All content in this folder has \"Version History\"");
cvs_rule.setRuleReference(folder_ref);
cvs_rule.setAction(cvs_action);
trace += "Done!<BR>";

//Saving rule
trace += "Trying to save the rule…";
WebServiceFactory.getActionService().saveRules(folder_ref, new Rule[]{cvs_rule});
trace += "Done!<BR>";

But it crashes saying:
ERROR: org.xml.sax.SAXException: Invalid element in org.alfresco.repo.webservice.action.Rule - ruleReference

Any idea about why I can't save this rule against that node reference??
Does anybody see what I'm doing wrong?

Thanks again.

Regards,
Enrique

PS: sorry for my English

doblek
Champ in-the-making
Champ in-the-making
Hi all again,

I've managed at last to create a rule in folder that adds versionable aspect to the content.
The problem was a little bit strange… I was using Alfresco 1.3 (because I couldn't upgrade to 1.4 Smiley Surprisedops: ) and "web-service-client.jar" from 1.4. Until this moment, I didn't have any particular or big problem using web services; but "Action", "Condition" and "Rule" classes from "org.alfresco.webservice.action" package in version 1.4 are very different from those same classes in version 1.3. So I've downgraded the "web-service-client" library and it seems to work 😃

I have a problem now setting the condition to the rule… The rule is saved against the proper folder and the action is well performed (I've tested this removing the condition), but when I try to create new content specifying the condition it says:

[size=75]Please correct the errors below then click Finish.
A system error happened during the operation: Transaction didn't commit: A value for the mandatory parameter type has not been set on the rule item is-subtype
[/size]

I think I made a mistake with the condition parameter… but I'm not sure… Does anybody know how should I say to Alfresco that I want to apply this rule only to those items in folder which are "content"?

This is the code I'm using actually:
//Condition
Condition condition = new Condition();
condition.setId("1");
condition.setConditionName("is-subtype");
condition.setInvertCondition(false);
condition.setParameters(new NamedValue[]{new NamedValue("is-subtype", false, Constants.TYPE_CONTENT, null)});
//Action
NamedValue[] parameters = new NamedValue[]{new NamedValue("aspect-name", false, Constants.ASPECT_VERSIONABLE, null)};
Action cvs_action = new Action();
cvs_action.setId("1");
cvs_action.setActionName("add-features");
cvs_action.setTitle("Add version to content");
cvs_action.setDescription("This action will add versionable aspect to every content in the folder, so every file will have version history");
cvs_action.setExecuteAsynchronously(false);
cvs_action.setReference(published_folder);
cvs_action.setParameters(parameters);
//Rule
Rule cvs_rule = new Rule();
cvs_rule.setRuleType("inbound");
cvs_rule.setTitle("Versioning");
cvs_rule.setDescription("All content in this folder has \"Version History\"");
cvs_rule.setReference(published_folder);
cvs_rule.setConditions(new Condition[]{condition});
cvs_rule.setActions(new Action[]{cvs_action});
//Saving rule
WebServiceFactory.getActionService().saveRules(published_folder, new Rule[]{cvs_rule});

Any suggestion appreciated.

Regards,
Enrique

jgreen
Champ in-the-making
Champ in-the-making
I have a similar issue, in that I use a rule to specialize the content type, which has a versionable as a mandatory aspect (inherited from a more general doc type).  I believe that the problem is that an initial Version is not being set due to the way that the aspect is being applied to the content.

The content is created and specialized correctly, and can even be read but changes to the content result in the same error you appear to be seeing.

If I get a solution, I'll let you know.

doblek
Champ in-the-making
Champ in-the-making
Hi,

I think I've finally been successful in adding the rule to the space… 😃

The problem was (as I supposed) that I was making a mistake when creating the condition to the rule…
When you have decided the action/condition you want to run by setting the ActionName or ConditionName (chosing one from the list I write here in a former post), you have to create the parameters that are needed for that specific action/condition carefully. That is: the number of parameters, the parameterName and parameterValue are specific for the action/condition chosen.
It's a little bit hard and wide to describe all the parameters for each action/condition, but I could try to help anyone if I'm asked… 😃 Maybe I could try to write a doc and send it to an admin (that revises it and publishes it in the wiki), but I do not have too much time Smiley Frustrated

However, I'm having problems with IDs… I don't trust in the solution I've reached… But I've started another thread in the forum and maybe someone can give us insight on that matter…
Finally, this is the code that worked for me (adds a rule that gives versionable aspect to every content created in a folder):
//UUID objects
UUID condition_id = UUID.randomUUID();
UUID action_id = UUID.randomUUID();
//Condition
Condition condition = new Condition();
condition.setId(condition_id.toString());
condition.setConditionName("is-subtype");
condition.setInvertCondition(false);
condition.setParameters(new NamedValue[]{new NamedValue("type", false, Constants.TYPE_CONTENT, null)});
//Action
NamedValue[] parameters = new NamedValue[]{new NamedValue("aspect-name", false, Constants.ASPECT_VERSIONABLE, null)};
Action cvs_action = new Action();
cvs_action.setId(action_id.toString());
cvs_action.setActionName("add-features");
cvs_action.setTitle("Add version to content");
cvs_action.setDescription("This action will add versionable aspect to every content in the folder, so every file will have version history");
cvs_action.setExecuteAsynchronously(false);
cvs_action.setReference(published_folder);
cvs_action.setParameters(parameters);
//Rule
Rule cvs_rule = new Rule();
cvs_rule.setRuleType("inbound");
cvs_rule.setTitle("Versioning");
cvs_rule.setDescription("All content in this folder has \"Version History\"");
cvs_rule.setReference(published_folder);
cvs_rule.setConditions(new Condition[]{condition});
cvs_rule.setActions(new Action[]{cvs_action});
//Saving rule
WebServiceFactory.getActionService().saveRules(published_folder, new Rule[]{cvs_rule});

Regards,
Enrique