Search in sources :

Example 11 with InvalidSharedIdException

use of org.alfresco.service.cmr.quickshare.InvalidSharedIdException in project alfresco-remote-api by Alfresco.

the class UnshareContentDelete method executeImpl.

@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) {
    if (!isEnabled()) {
        throw new WebScriptException(HttpServletResponse.SC_FORBIDDEN, "QuickShare is disabled system-wide");
    }
    // create map of params (template vars)
    Map<String, String> params = req.getServiceMatch().getTemplateVars();
    final String sharedId = params.get("shared_id");
    if (sharedId == null) {
        throw new WebScriptException(HttpServletResponse.SC_BAD_REQUEST, "A valid sharedId must be specified !");
    }
    try {
        NodeRef nodeRef = quickShareService.getTenantNodeRefFromSharedId(sharedId).getSecond();
        String sharedBy = (String) nodeService.getProperty(nodeRef, QuickShareModel.PROP_QSHARE_SHAREDBY);
        if (!quickShareService.canDeleteSharedLink(nodeRef, sharedBy)) {
            throw new WebScriptException(HttpServletResponse.SC_FORBIDDEN, "Can't perform unshare action: " + sharedId);
        }
        quickShareService.unshareContent(sharedId);
        Map<String, Object> model = new HashMap<>(1);
        model.put("success", Boolean.TRUE);
        return model;
    } catch (InvalidSharedIdException ex) {
        logger.error("Unable to find: " + sharedId);
        throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Unable to find: " + sharedId);
    } catch (InvalidNodeRefException inre) {
        logger.error("Unable to find: " + sharedId + " [" + inre.getNodeRef() + "]");
        throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Unable to find: " + sharedId);
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) InvalidSharedIdException(org.alfresco.service.cmr.quickshare.InvalidSharedIdException) WebScriptException(org.springframework.extensions.webscripts.WebScriptException) HashMap(java.util.HashMap) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException)

Aggregations

InvalidSharedIdException (org.alfresco.service.cmr.quickshare.InvalidSharedIdException)11 InvalidNodeRefException (org.alfresco.service.cmr.repository.InvalidNodeRefException)11 NodeRef (org.alfresco.service.cmr.repository.NodeRef)8 EntityNotFoundException (org.alfresco.rest.framework.core.exceptions.EntityNotFoundException)7 WebScriptException (org.springframework.extensions.webscripts.WebScriptException)4 HashMap (java.util.HashMap)3 QuickShareLink (org.alfresco.rest.api.model.QuickShareLink)2 PermissionDeniedException (org.alfresco.rest.framework.core.exceptions.PermissionDeniedException)2 Parameters (org.alfresco.rest.framework.resource.parameters.Parameters)2 SearchParameters (org.alfresco.service.cmr.search.SearchParameters)2 IOException (java.io.IOException)1 Serializable (java.io.Serializable)1 QuickShareLinkExpiryActionException (org.alfresco.repo.quickshare.QuickShareLinkExpiryActionException)1 QuickShareEmailRequest (org.alfresco.repo.quickshare.QuickShareServiceImpl.QuickShareEmailRequest)1 AccessDeniedException (org.alfresco.repo.security.permissions.AccessDeniedException)1 TenantUtil (org.alfresco.repo.tenant.TenantUtil)1 ContentInfo (org.alfresco.rest.api.model.ContentInfo)1 Node (org.alfresco.rest.api.model.Node)1 UserInfo (org.alfresco.rest.api.model.UserInfo)1 ConstraintViolatedException (org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException)1