use of org.alfresco.repo.action.CompositeActionImpl 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.repo.action.CompositeActionImpl 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