use of org.alfresco.service.cmr.rule.Rule in project alfresco-remote-api by Alfresco.
the class AbstractRuleWebScript method parseJsonRule.
protected Rule parseJsonRule(JSONObject jsonRule) throws JSONException {
Rule result = new Rule();
if (jsonRule.has("title") == false || jsonRule.getString("title").length() == 0) {
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Title missing when creating rule");
}
result.setTitle(jsonRule.getString("title"));
result.setDescription(jsonRule.has("description") ? jsonRule.getString("description") : "");
if (jsonRule.has("ruleType") == false || jsonRule.getJSONArray("ruleType").length() == 0) {
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Rule type missing when creating rule");
}
JSONArray types = jsonRule.getJSONArray("ruleType");
List<String> ruleTypes = new ArrayList<String>();
for (int i = 0; i < types.length(); i++) {
ruleTypes.add(types.getString(i));
}
result.setRuleTypes(ruleTypes);
result.applyToChildren(jsonRule.has("applyToChildren") ? jsonRule.getBoolean("applyToChildren") : false);
result.setExecuteAsynchronously(jsonRule.has("executeAsynchronously") ? jsonRule.getBoolean("executeAsynchronously") : false);
result.setRuleDisabled(jsonRule.has("disabled") ? jsonRule.getBoolean("disabled") : false);
JSONObject jsonAction = jsonRule.getJSONObject("action");
// parse action object
Action ruleAction = parseJsonAction(jsonAction);
result.setAction(ruleAction);
return result;
}
use of org.alfresco.service.cmr.rule.Rule in project alfresco-remote-api by Alfresco.
the class InheritedRulesGet 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
NodeRef nodeRef = parseRequestForNodeRef(req);
String ruleType = req.getParameter("ruleType");
RuleType type = ruleService.getRuleType(ruleType);
if (type == null) {
ruleType = null;
}
// get all rules (including inherited) filtered by rule type
List<Rule> inheritedRules = ruleService.getRules(nodeRef, true, ruleType);
// get owned rules (excluding inherited) filtered by rule type
List<Rule> ownedRules = ruleService.getRules(nodeRef, false, ruleType);
// remove owned rules
inheritedRules.removeAll(ownedRules);
List<RuleRef> inheritedRuleRefs = new ArrayList<RuleRef>();
for (Rule rule : inheritedRules) {
inheritedRuleRefs.add(new RuleRef(rule, fileFolderService.getFileInfo(ruleService.getOwningNodeRef(rule))));
}
model.put("inheritedRuleRefs", inheritedRuleRefs);
return model;
}
use of org.alfresco.service.cmr.rule.Rule in project alfresco-remote-api by Alfresco.
the class RulePost 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
NodeRef nodeRef = parseRequestForNodeRef(req);
Rule rule = null;
JSONObject json = null;
try {
// read request json
json = new JSONObject(new JSONTokener(req.getContent().getContent()));
// parse request json
rule = parseJsonRule(json);
// check the rule
checkRule(rule);
// create rule
ruleService.saveRule(nodeRef, rule);
RuleRef ruleRef = new RuleRef(rule, fileFolderService.getFileInfo(ruleService.getOwningNodeRef(rule)));
model.put("ruleRef", ruleRef);
} 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.service.cmr.rule.Rule in project alfresco-remote-api by Alfresco.
the class RulePut 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
NodeRef nodeRef = parseRequestForNodeRef(req);
Map<String, String> templateVars = req.getServiceMatch().getTemplateVars();
String ruleId = templateVars.get("rule_id");
Rule ruleToUpdate = null;
// get all rules for given nodeRef
List<Rule> rules = ruleService.getRules(nodeRef);
// filter by rule id
for (Rule rule : rules) {
if (rule.getNodeRef().getId().equalsIgnoreCase(ruleId)) {
ruleToUpdate = rule;
break;
}
}
if (ruleToUpdate == null) {
throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Unable to find rule with id: " + ruleId);
}
JSONObject json = null;
try {
// read request json
json = new JSONObject(new JSONTokener(req.getContent().getContent()));
// parse request json
updateRuleFromJSON(json, ruleToUpdate);
// check the rule
checkRule(ruleToUpdate);
// save changes
ruleService.saveRule(nodeRef, ruleToUpdate);
RuleRef updatedRuleRef = new RuleRef(ruleToUpdate, fileFolderService.getFileInfo(ruleService.getOwningNodeRef(ruleToUpdate)));
model.put("ruleRef", updatedRuleRef);
} 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.service.cmr.rule.Rule in project alfresco-remote-api by Alfresco.
the class RulesGet 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
NodeRef nodeRef = parseRequestForNodeRef(req);
String ruleType = req.getParameter("ruleType");
RuleType type = ruleService.getRuleType(ruleType);
if (type == null) {
ruleType = null;
}
// get all rules (excluding inherited) filtered by rule type
List<Rule> rules = ruleService.getRules(nodeRef, false, ruleType);
List<RuleRef> ruleRefs = new ArrayList<RuleRef>();
for (Rule rule : rules) {
ruleRefs.add(new RuleRef(rule, fileFolderService.getFileInfo(ruleService.getOwningNodeRef(rule))));
}
model.put("ruleRefs", ruleRefs);
return model;
}
Aggregations