use of org.alfresco.repo.web.scripts.rule.ruleset.RuleRef in project alfresco-remote-api by Alfresco.
the class RuleGet method executeImpl.
@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) {
Map<String, Object> model = new HashMap<String, Object>();
NodeRef nodeRef = parseRequestForNodeRef(req);
// get request parameters
Map<String, String> templateVars = req.getServiceMatch().getTemplateVars();
String ruleId = templateVars.get("rule_id");
Rule ruleToReturn = 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)) {
ruleToReturn = rule;
break;
}
}
if (ruleToReturn == null) {
throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Unable to find rule with id: " + ruleId);
}
RuleRef ruleRefToReturn = new RuleRef(ruleToReturn, fileFolderService.getFileInfo(ruleService.getOwningNodeRef(ruleToReturn)));
model.put("ruleRef", ruleRefToReturn);
return model;
}
use of org.alfresco.repo.web.scripts.rule.ruleset.RuleRef in project alfresco-remote-api by Alfresco.
the class RulesetGet 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;
}
RuleSet ruleset = new RuleSet();
// get all "owned" rules
List<Rule> ownedRules = ruleService.getRules(nodeRef, false, ruleType);
// get all rules (including inherited)
List<Rule> inheritedRules = ruleService.getRules(nodeRef, true, ruleType);
// remove "owned" rules
inheritedRules.removeAll(ownedRules);
List<RuleRef> rulesToSet = new ArrayList<RuleRef>();
for (Rule rule : ownedRules) {
rulesToSet.add(new RuleRef(rule, fileFolderService.getFileInfo(ruleService.getOwningNodeRef(rule))));
}
ruleset.setRules(rulesToSet);
List<RuleRef> inheritedRulesToSet = new ArrayList<RuleRef>();
for (Rule rule : inheritedRules) {
inheritedRulesToSet.add(new RuleRef(rule, fileFolderService.getFileInfo(ruleService.getOwningNodeRef(rule))));
}
ruleset.setInheritedRules(inheritedRulesToSet);
ruleset.setLinkedToRuleSet(ruleService.getLinkedToRuleNode(nodeRef));
ruleset.setLinkedFromRuleSets(ruleService.getLinkedFromRuleNodes(nodeRef));
ruleset.setRulesetNodeRef(nodeRef);
model.put("ruleset", ruleset);
return model;
}
use of org.alfresco.repo.web.scripts.rule.ruleset.RuleRef 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.repo.web.scripts.rule.ruleset.RuleRef 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.repo.web.scripts.rule.ruleset.RuleRef 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;
}
Aggregations