Search in sources :

Example 26 with WebScriptException

use of org.springframework.extensions.webscripts.WebScriptException in project alfresco-remote-api by Alfresco.

the class RuleDelete 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 ruleToDelete = null;
    // get all rules for given nodeRef
    List<Rule> rules = ruleService.getRules(nodeRef, false);
    // filter by rule id
    for (Rule rule : rules) {
        if (rule.getNodeRef().getId().equalsIgnoreCase(ruleId)) {
            ruleToDelete = rule;
            break;
        }
    }
    if (ruleToDelete == null) {
        throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Unable to find rule with id: " + ruleId);
    }
    // delete rule
    ruleService.removeRule(nodeRef, ruleToDelete);
    return model;
}
Also used : 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 27 with WebScriptException

use of org.springframework.extensions.webscripts.WebScriptException 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 28 with WebScriptException

use of org.springframework.extensions.webscripts.WebScriptException in project alfresco-remote-api by Alfresco.

the class AbstractSiteWebScript method executeImpl.

@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) {
    // Grab the site
    String siteName = req.getServiceMatch().getTemplateVars().get("shortname");
    SiteInfo site = siteService.getSite(siteName);
    if (site == null) {
        throw new WebScriptException(Status.STATUS_NOT_FOUND, "No Site found with that short name");
    }
    // Process
    return executeImpl(site, req, status, cache);
}
Also used : SiteInfo(org.alfresco.service.cmr.site.SiteInfo) WebScriptException(org.springframework.extensions.webscripts.WebScriptException)

Example 29 with WebScriptException

use of org.springframework.extensions.webscripts.WebScriptException in project alfresco-remote-api by Alfresco.

the class AclsReadersGet method buildModel.

private Map<String, Object> buildModel(WebScriptRequest req) throws JSONException, IOException {
    List<Long> aclIds = null;
    Content content = req.getContent();
    if (content == null) {
        throw new WebScriptException("Request content is empty");
    }
    JSONObject o = new JSONObject(content.getContent());
    JSONArray aclIdsJSON = o.has("aclIds") ? o.getJSONArray("aclIds") : null;
    if (aclIdsJSON == null) {
        throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Parameter 'aclIds' not provided in request content.");
    } else if (aclIdsJSON.length() == 0) {
        throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Parameter 'aclIds' must hold from 1 or more IDs.");
    }
    aclIds = new ArrayList<Long>(aclIdsJSON.length());
    for (int i = 0; i < aclIdsJSON.length(); i++) {
        aclIds.add(aclIdsJSON.getLong(i));
    }
    // Request according to the paging query style required
    List<AclReaders> aclsReaders = solrTrackingComponent.getAclsReaders(aclIds);
    Map<String, Object> model = new HashMap<String, Object>(1, 1.0f);
    model.put("aclsReaders", aclsReaders);
    if (logger.isDebugEnabled()) {
        logger.debug("Result: \n\tRequest: " + req + "\n\tModel: " + model);
    }
    return model;
}
Also used : HashMap(java.util.HashMap) JSONArray(org.json.JSONArray) WebScriptException(org.springframework.extensions.webscripts.WebScriptException) JSONObject(org.json.JSONObject) Content(org.springframework.extensions.surf.util.Content) JSONObject(org.json.JSONObject) AclReaders(org.alfresco.repo.solr.AclReaders)

Example 30 with WebScriptException

use of org.springframework.extensions.webscripts.WebScriptException in project alfresco-remote-api by Alfresco.

the class AlfrescoModelGet method handle.

private void handle(WebScriptRequest req, WebScriptResponse res) throws JSONException, IOException {
    // create map of template vars
    String modelQName = req.getParameter("modelQName");
    if (modelQName == null) {
        throw new WebScriptException(Status.STATUS_BAD_REQUEST, "URL parameter 'modelQName' not provided.");
    }
    ModelDefinition.XMLBindingType bindingType = ModelDefinition.XMLBindingType.DEFAULT;
    AlfrescoModel model = solrTrackingComponent.getModel(QName.createQName(modelQName));
    res.setHeader("XAlfresco-modelChecksum", String.valueOf(model.getModelDef().getChecksum(bindingType)));
    model.getModelDef().toXML(bindingType, res.getOutputStream());
}
Also used : WebScriptException(org.springframework.extensions.webscripts.WebScriptException) ModelDefinition(org.alfresco.service.cmr.dictionary.ModelDefinition) AlfrescoModel(org.alfresco.repo.solr.AlfrescoModel)

Aggregations

WebScriptException (org.springframework.extensions.webscripts.WebScriptException)204 HashMap (java.util.HashMap)94 NodeRef (org.alfresco.service.cmr.repository.NodeRef)67 IOException (java.io.IOException)60 JSONException (org.json.JSONException)48 JSONObject (org.json.JSONObject)44 ArrayList (java.util.ArrayList)32 QName (org.alfresco.service.namespace.QName)31 JSONTokener (org.json.JSONTokener)29 JSONObject (org.json.simple.JSONObject)25 JSONArray (org.json.JSONArray)18 Map (java.util.Map)12 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)11 SiteInfo (org.alfresco.service.cmr.site.SiteInfo)11 StoreRef (org.alfresco.service.cmr.repository.StoreRef)10 File (java.io.File)9 Date (java.util.Date)8 JSONParser (org.json.simple.parser.JSONParser)8 Serializable (java.io.Serializable)7 InvalidNodeRefException (org.alfresco.service.cmr.repository.InvalidNodeRefException)7