Search in sources :

Example 1 with RuleRef

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;
}
Also used : RuleRef(org.alfresco.repo.web.scripts.rule.ruleset.RuleRef) NodeRef(org.alfresco.service.cmr.repository.NodeRef) WebScriptException(org.springframework.extensions.webscripts.WebScriptException) HashMap(java.util.HashMap) Rule(org.alfresco.service.cmr.rule.Rule)

Example 2 with RuleRef

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;
}
Also used : RuleRef(org.alfresco.repo.web.scripts.rule.ruleset.RuleRef) NodeRef(org.alfresco.service.cmr.repository.NodeRef) RuleSet(org.alfresco.repo.web.scripts.rule.ruleset.RuleSet) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) RuleType(org.alfresco.service.cmr.rule.RuleType) Rule(org.alfresco.service.cmr.rule.Rule)

Example 3 with RuleRef

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;
}
Also used : RuleRef(org.alfresco.repo.web.scripts.rule.ruleset.RuleRef) NodeRef(org.alfresco.service.cmr.repository.NodeRef) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) RuleType(org.alfresco.service.cmr.rule.RuleType) Rule(org.alfresco.service.cmr.rule.Rule)

Example 4 with RuleRef

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;
}
Also used : JSONTokener(org.json.JSONTokener) RuleRef(org.alfresco.repo.web.scripts.rule.ruleset.RuleRef) NodeRef(org.alfresco.service.cmr.repository.NodeRef) JSONObject(org.json.JSONObject) WebScriptException(org.springframework.extensions.webscripts.WebScriptException) HashMap(java.util.HashMap) JSONException(org.json.JSONException) JSONObject(org.json.JSONObject) Rule(org.alfresco.service.cmr.rule.Rule) IOException(java.io.IOException)

Example 5 with RuleRef

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;
}
Also used : HashMap(java.util.HashMap) JSONException(org.json.JSONException) IOException(java.io.IOException) JSONTokener(org.json.JSONTokener) RuleRef(org.alfresco.repo.web.scripts.rule.ruleset.RuleRef) NodeRef(org.alfresco.service.cmr.repository.NodeRef) WebScriptException(org.springframework.extensions.webscripts.WebScriptException) JSONObject(org.json.JSONObject) JSONObject(org.json.JSONObject) Rule(org.alfresco.service.cmr.rule.Rule)

Aggregations

HashMap (java.util.HashMap)6 RuleRef (org.alfresco.repo.web.scripts.rule.ruleset.RuleRef)6 NodeRef (org.alfresco.service.cmr.repository.NodeRef)6 Rule (org.alfresco.service.cmr.rule.Rule)6 ArrayList (java.util.ArrayList)3 RuleType (org.alfresco.service.cmr.rule.RuleType)3 WebScriptException (org.springframework.extensions.webscripts.WebScriptException)3 IOException (java.io.IOException)2 JSONException (org.json.JSONException)2 JSONObject (org.json.JSONObject)2 JSONTokener (org.json.JSONTokener)2 RuleSet (org.alfresco.repo.web.scripts.rule.ruleset.RuleSet)1