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;
}
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;
}
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);
}
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;
}
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());
}
Aggregations