use of org.alfresco.repo.action.ActionImpl in project alfresco-remote-api by Alfresco.
the class ActionQueuePost method executeImpl.
@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) {
Map<String, Object> model = new HashMap<String, Object>();
// get request parameters
boolean async = Boolean.parseBoolean(req.getParameter("async"));
ActionImpl action = null;
JSONObject json = null;
try {
// read request json
json = new JSONObject(new JSONTokener(req.getContent().getContent()));
// parse request json
action = parseJsonAction(json);
NodeRef actionedUponNode = action.getNodeRef();
// clear nodeRef for action
action.setNodeRef(null);
json.remove("actionedUponNode");
if (async) {
model.put(STATUS, STATUS_QUEUED);
} else {
model.put(STATUS, STATUS_SUCCESS);
}
// Execute action
actionService.executeAction(action, actionedUponNode, true, async);
// Prepair model
model.put("actionedUponNode", actionedUponNode.toString());
model.put("action", json);
} catch (IOException iox) {
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Could not read content from req.", iox);
} catch (JSONException je) {
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Could not parse JSON from req.", je);
}
return model;
}
use of org.alfresco.repo.action.ActionImpl 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