Search in sources :

Example 1 with DeleteLinksStatusReport

use of org.alfresco.service.cmr.repository.DeleteLinksStatusReport in project alfresco-remote-api by Alfresco.

the class DocLinksDelete method executeImpl.

@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) {
    NodeRef destinationNodeRef = null;
    /* Parse the template vars */
    Map<String, String> templateVars = req.getServiceMatch().getTemplateVars();
    destinationNodeRef = parseNodeRefFromTemplateArgs(templateVars);
    /* Delete links */
    DeleteLinksStatusReport report;
    try {
        report = documentLinkService.deleteLinksToDocument(destinationNodeRef);
    } catch (IllegalArgumentException ex) {
        throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Invalid Arguments: " + ex.getMessage());
    } catch (AccessDeniedException e) {
        throw new WebScriptException(Status.STATUS_FORBIDDEN, "You don't have permission to perform this operation");
    }
    /* Build response */
    Map<String, Object> model = new HashMap<String, Object>();
    model.put("total_count", report.getTotalLinksFoundCount());
    model.put("deleted_count", report.getDeletedLinksCount());
    Map<String, String> errorDetails = new HashMap<String, String>();
    Iterator<Entry<NodeRef, Throwable>> it = report.getErrorDetails().entrySet().iterator();
    while (it.hasNext()) {
        Map.Entry<NodeRef, Throwable> pair = it.next();
        Throwable th = pair.getValue();
        errorDetails.put(pair.getKey().toString(), th.getMessage());
    }
    model.put("error_details", errorDetails);
    return model;
}
Also used : AccessDeniedException(org.alfresco.repo.security.permissions.AccessDeniedException) HashMap(java.util.HashMap) NodeRef(org.alfresco.service.cmr.repository.NodeRef) Entry(java.util.Map.Entry) WebScriptException(org.springframework.extensions.webscripts.WebScriptException) DeleteLinksStatusReport(org.alfresco.service.cmr.repository.DeleteLinksStatusReport) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

HashMap (java.util.HashMap)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 AccessDeniedException (org.alfresco.repo.security.permissions.AccessDeniedException)1 DeleteLinksStatusReport (org.alfresco.service.cmr.repository.DeleteLinksStatusReport)1 NodeRef (org.alfresco.service.cmr.repository.NodeRef)1 WebScriptException (org.springframework.extensions.webscripts.WebScriptException)1