use of org.alfresco.service.cmr.action.ActionCondition in project acs-community-packaging by Alfresco.
the class CreateRuleWizard method setupRule.
// ------------------------------------------------------------------------------
// Helper methods
/**
* Sets up the given rule using the current state of the wizard
*
* @param context FacesContext
* @param rule The rule to setup
* @param outcome The default outcome
* @return The outcome
*/
@SuppressWarnings("unchecked")
protected String setupRule(FacesContext context, Rule rule, String outcome) {
if (logger.isDebugEnabled())
logger.debug("Saving Rules - setupRule");
// setup the rule and add it to the space
rule.setTitle(this.title);
rule.setDescription(this.description);
rule.applyToChildren(this.applyToSubSpaces);
rule.setExecuteAsynchronously(this.runInBackground);
rule.setRuleDisabled(this.ruleDisabled);
CompositeAction compositeAction = this.getActionService().createCompositeAction();
rule.setAction(compositeAction);
int i = 1;
// add all the conditions to the rule
for (Object condParamsObj : this.allConditionsPropertiesList) {
if (logger.isDebugEnabled())
logger.debug("Saving Condition " + i++ + " of " + this.allConditionsPropertiesList.size());
Map<String, Serializable> uiConditionParams = (Map<String, Serializable>) condParamsObj;
ActionCondition condition = createCondition(uiConditionParams);
if (condition instanceof CompositeActionCondition) {
CompositeActionCondition compositeCondition = (CompositeActionCondition) condition;
List<Map<String, Serializable>> subconditionProps = (List<Map<String, Serializable>>) uiConditionParams.get(CompositeConditionHandler.PROP_COMPOSITE_CONDITION);
int j = 1;
compositeCondition.setORCondition(((Boolean) uiConditionParams.get(CompositeConditionHandler.PROP_CONDITION_OR)).booleanValue());
compositeCondition.setInvertCondition((((Boolean) uiConditionParams.get(CompositeConditionHandler.PROP_CONDITION_NOT)).booleanValue()));
for (Map<String, Serializable> props : subconditionProps) {
if (logger.isDebugEnabled())
logger.debug("Saving Composite Condition " + j++ + " of " + subconditionProps.size());
compositeCondition.addActionCondition(createCondition(props));
}
}
compositeAction.addActionCondition(condition);
}
// add all the actions to the rule
for (Map<String, Serializable> actionParams : this.allActionsProperties) {
// use the base class version of buildActionParams(), but for this
// we need
// to setup the currentActionProperties and action variables
String actionName = (String) actionParams.get(PROP_ACTION_NAME);
this.action = actionName;
// get the action handler to prepare for the save
Map<String, Serializable> repoActionParams = new HashMap<String, Serializable>();
IHandler handler = this.actionHandlers.get(this.action);
if (handler != null) {
handler.prepareForSave(actionParams, repoActionParams);
}
// add the action to the rule
Action action = this.getActionService().createAction(actionName);
action.setParameterValues(repoActionParams);
compositeAction.addAction(action);
}
return outcome;
}
use of org.alfresco.service.cmr.action.ActionCondition in project acs-community-packaging by Alfresco.
the class EditRuleWizard method populateConditions.
protected void populateConditions(FacesContext context, CompositeAction compositeAction) {
// populate the conditions list with maps of properties representing each condition
List<ActionCondition> conditions = compositeAction.getActionConditions();
for (ActionCondition toplevel_condition : conditions) {
this.selectedCondition = toplevel_condition.getActionConditionDefinitionName();
this.currentConditionProperties = new HashMap<String, Serializable>();
if (logger.isDebugEnabled())
logger.debug("Preparing for Edit Condition " + this.selectedCondition);
if (toplevel_condition instanceof CompositeActionCondition) {
if (logger.isDebugEnabled())
logger.debug("\tDetected CompositeCondition");
CompositeActionCondition compositeCondition = (CompositeActionCondition) toplevel_condition;
this.currentCompositeConditionPropertiesList = new ArrayList<Map<String, Serializable>>();
for (ActionCondition subcondition : compositeCondition.getActionConditions()) {
if (logger.isDebugEnabled())
logger.debug("\tSetting ... SubConditions " + subcondition.getActionConditionDefinitionName());
this.selectedCondition = subcondition.getActionConditionDefinitionName();
Map<String, Serializable> subConditionProperties = new HashMap<String, Serializable>();
populateProperties(context, subcondition, subConditionProperties);
this.currentCompositeConditionPropertiesList.add(subConditionProperties);
}
this.selectedCondition = CompositeConditionHandler.NAME;
this.currentConditionProperties.put(CompositeConditionHandler.PROP_COMPOSITE_CONDITION, (Serializable) this.currentCompositeConditionPropertiesList);
populateProperties(context, compositeCondition, currentConditionProperties);
} else
populateProperties(context, toplevel_condition, this.currentConditionProperties);
// add the populated currentConditionProperties to the list
this.allConditionsPropertiesList.add(this.currentConditionProperties);
printConditionState();
}
}
use of org.alfresco.service.cmr.action.ActionCondition in project acs-community-packaging by Alfresco.
the class CreateRuleWizard method createCondition.
private ActionCondition createCondition(Map<String, Serializable> uiConditionParams) {
// get the condition handler to prepare for the save
String conditionName = (String) uiConditionParams.get(PROP_CONDITION_NAME);
Map<String, Serializable> repoCondParams = new HashMap<String, Serializable>();
if (logger.isDebugEnabled()) {
logger.debug("\tSaving " + conditionName);
}
IHandler handler = this.conditionHandlers.get(conditionName);
if (handler != null) {
handler.prepareForSave(uiConditionParams, repoCondParams);
}
// add the condition to the rule
ActionCondition condition = this.getActionService().createActionCondition(conditionName);
condition.setParameterValues(repoCondParams);
// specify whether the condition result should be inverted
Boolean not = (Boolean) uiConditionParams.get(BaseConditionHandler.PROP_CONDITION_NOT);
if (not == null) {
logger.warn("Property missing NOT parameter value (currently null)");
not = Boolean.TRUE;
}
condition.setInvertCondition(((Boolean) not).booleanValue());
return condition;
}
use of org.alfresco.service.cmr.action.ActionCondition in project alfresco-remote-api by Alfresco.
the class AbstractRuleWebScript method parseJsonAction.
protected ActionImpl parseJsonAction(JSONObject jsonAction) throws JSONException {
ActionImpl result = null;
String actionId = jsonAction.has("id") ? jsonAction.getString("id") : GUID.generate();
if (jsonAction.getString("actionDefinitionName").equalsIgnoreCase("composite-action")) {
result = new CompositeActionImpl(null, actionId);
} else {
result = new ActionImpl(null, actionId, jsonAction.getString("actionDefinitionName"));
}
// Post Action Queue parameter
if (jsonAction.has("actionedUponNode")) {
NodeRef actionedUponNode = new NodeRef(jsonAction.getString("actionedUponNode"));
result.setNodeRef(actionedUponNode);
}
if (jsonAction.has("description")) {
result.setDescription(jsonAction.getString("description"));
}
if (jsonAction.has("title")) {
result.setTitle(jsonAction.getString("title"));
}
if (jsonAction.has("parameterValues")) {
JSONObject jsonParameterValues = jsonAction.getJSONObject("parameterValues");
result.setParameterValues(parseJsonParameterValues(jsonParameterValues, result.getActionDefinitionName(), true));
}
if (jsonAction.has("executeAsync")) {
result.setExecuteAsynchronously(jsonAction.getBoolean("executeAsync"));
}
if (jsonAction.has("runAsUser")) {
result.setRunAsUser(jsonAction.getString("runAsUser"));
}
if (jsonAction.has("actions")) {
JSONArray jsonActions = jsonAction.getJSONArray("actions");
for (int i = 0; i < jsonActions.length(); i++) {
JSONObject innerJsonAction = jsonActions.getJSONObject(i);
Action innerAction = parseJsonAction(innerJsonAction);
// we assume that only composite-action contains actions json array, so should be no cast exception
((CompositeActionImpl) result).addAction(innerAction);
}
}
if (jsonAction.has("conditions")) {
JSONArray jsonConditions = jsonAction.getJSONArray("conditions");
for (int i = 0; i < jsonConditions.length(); i++) {
JSONObject jsonCondition = jsonConditions.getJSONObject(i);
// parse action conditions
ActionCondition actionCondition = parseJsonActionCondition(jsonCondition);
result.getActionConditions().add(actionCondition);
}
}
if (jsonAction.has("compensatingAction")) {
Action compensatingAction = parseJsonAction(jsonAction.getJSONObject("compensatingAction"));
result.setCompensatingAction(compensatingAction);
}
return result;
}
use of org.alfresco.service.cmr.action.ActionCondition in project alfresco-remote-api by Alfresco.
the class RulePut method updateActionFromJson.
protected Action updateActionFromJson(JSONObject jsonAction, ActionImpl actionToUpdate) throws JSONException {
ActionImpl result = null;
if (jsonAction.has("id")) {
// update existing action
result = actionToUpdate;
} else {
// create new object as id was not sent by client
result = parseJsonAction(jsonAction);
return result;
}
if (jsonAction.has("description")) {
result.setDescription(jsonAction.getString("description"));
}
if (jsonAction.has("title")) {
result.setTitle(jsonAction.getString("title"));
}
if (jsonAction.has("parameterValues")) {
JSONObject jsonParameterValues = jsonAction.getJSONObject("parameterValues");
result.setParameterValues(parseJsonParameterValues(jsonParameterValues, result.getActionDefinitionName(), true));
}
if (jsonAction.has("executeAsync")) {
result.setExecuteAsynchronously(jsonAction.getBoolean("executeAsync"));
}
if (jsonAction.has("runAsUser")) {
result.setRunAsUser(jsonAction.getString("runAsUser"));
}
if (jsonAction.has("actions")) {
JSONArray jsonActions = jsonAction.getJSONArray("actions");
if (jsonActions.length() == 0) {
// empty array was sent -> clear list
((CompositeActionImpl) result).getActions().clear();
} else {
List<Action> existingActions = ((CompositeActionImpl) result).getActions();
List<Action> newActions = new ArrayList<Action>();
for (int i = 0; i < jsonActions.length(); i++) {
JSONObject innerJsonAction = jsonActions.getJSONObject(i);
if (innerJsonAction.has("id")) {
// update existing object
String actionId = innerJsonAction.getString("id");
Action existingAction = getAction(existingActions, actionId);
existingActions.remove(existingAction);
Action updatedAction = updateActionFromJson(innerJsonAction, (ActionImpl) existingAction);
newActions.add(updatedAction);
} else {
// create new action as id was not sent
newActions.add(parseJsonAction(innerJsonAction));
}
}
existingActions.clear();
for (Action action : newActions) {
existingActions.add(action);
}
}
}
if (jsonAction.has("conditions")) {
JSONArray jsonConditions = jsonAction.getJSONArray("conditions");
if (jsonConditions.length() == 0) {
// empty array was sent -> clear list
result.getActionConditions().clear();
} else {
List<ActionCondition> existingConditions = result.getActionConditions();
List<ActionCondition> newConditions = new ArrayList<ActionCondition>();
for (int i = 0; i < jsonConditions.length(); i++) {
JSONObject jsonCondition = jsonConditions.getJSONObject(i);
if (jsonCondition.has("id")) {
// update existing object
String conditionId = jsonCondition.getString("id");
ActionCondition existingCondition = getCondition(existingConditions, conditionId);
existingConditions.remove(existingCondition);
ActionCondition updatedActionCondition = updateActionConditionFromJson(jsonCondition, (ActionConditionImpl) existingCondition);
newConditions.add(updatedActionCondition);
} else {
// create new object as id was not sent
newConditions.add(parseJsonActionCondition(jsonCondition));
}
}
existingConditions.clear();
for (ActionCondition condition : newConditions) {
existingConditions.add(condition);
}
}
}
if (jsonAction.has("compensatingAction")) {
JSONObject jsonCompensatingAction = jsonAction.getJSONObject("compensatingAction");
Action compensatingAction = updateActionFromJson(jsonCompensatingAction, (ActionImpl) actionToUpdate.getCompensatingAction());
actionToUpdate.setCompensatingAction(compensatingAction);
}
return result;
}
Aggregations