Search in sources :

Example 1 with QuickShareLinkExpiryActionException

use of org.alfresco.repo.quickshare.QuickShareLinkExpiryActionException in project alfresco-remote-api by Alfresco.

the class QuickShareLinksImpl method create.

/**
 * Create quick share.
 * <p>
 * Requires authenticated access.
 *
 * @param nodeIds
 * @param parameters
 * @return
 */
public List<QuickShareLink> create(List<QuickShareLink> nodeIds, Parameters parameters) {
    checkEnabled();
    List<QuickShareLink> result = new ArrayList<>(nodeIds.size());
    List<String> includeParam = parameters != null ? parameters.getInclude() : Collections.<String>emptyList();
    for (QuickShareLink qs : nodeIds) {
        String nodeId = qs.getNodeId();
        if (nodeId == null) {
            throw new InvalidArgumentException("A valid nodeId must be specified !");
        }
        NodeRef nodeRef = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, nodeId);
        try {
            // Note: will throw InvalidNodeRefException (=> 404) if node does not exist
            String sharedId = (String) nodeService.getProperty(nodeRef, QuickShareModel.PROP_QSHARE_SHAREDID);
            if (sharedId != null) {
                throw new ConstraintViolatedException("sharedId already exists: " + nodeId + " [" + sharedId + "]");
            }
            // Note: since we already check node exists above, we can assume that InvalidNodeRefException (=> 404) here means not content (see type check)
            try {
                QuickShareDTO qsDto = quickShareService.shareContent(nodeRef, qs.getExpiresAt());
                result.add(getQuickShareInfo(qsDto.getId(), false, includeParam));
            } catch (InvalidNodeRefException inre) {
                throw new InvalidArgumentException("Unable to create shared link to non-file content: " + nodeId);
            } catch (QuickShareLinkExpiryActionException ex) {
                throw new InvalidArgumentException(ex.getMessage());
            }
        } catch (AccessDeniedException ade) {
            throw new PermissionDeniedException("Unable to create shared link to node that does not exist: " + nodeId);
        } catch (InvalidNodeRefException inre) {
            logger.warn("Unable to create shared link: [" + nodeRef + "]");
            throw new EntityNotFoundException(nodeId);
        }
    }
    return result;
}
Also used : AccessDeniedException(org.alfresco.repo.security.permissions.AccessDeniedException) ArrayList(java.util.ArrayList) QuickShareLinkExpiryActionException(org.alfresco.repo.quickshare.QuickShareLinkExpiryActionException) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) ConstraintViolatedException(org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException) NodeRef(org.alfresco.service.cmr.repository.NodeRef) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) QuickShareDTO(org.alfresco.service.cmr.quickshare.QuickShareDTO) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException) PermissionDeniedException(org.alfresco.rest.framework.core.exceptions.PermissionDeniedException) QuickShareLink(org.alfresco.rest.api.model.QuickShareLink)

Aggregations

ArrayList (java.util.ArrayList)1 QuickShareLinkExpiryActionException (org.alfresco.repo.quickshare.QuickShareLinkExpiryActionException)1 AccessDeniedException (org.alfresco.repo.security.permissions.AccessDeniedException)1 QuickShareLink (org.alfresco.rest.api.model.QuickShareLink)1 ConstraintViolatedException (org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException)1 EntityNotFoundException (org.alfresco.rest.framework.core.exceptions.EntityNotFoundException)1 InvalidArgumentException (org.alfresco.rest.framework.core.exceptions.InvalidArgumentException)1 PermissionDeniedException (org.alfresco.rest.framework.core.exceptions.PermissionDeniedException)1 QuickShareDTO (org.alfresco.service.cmr.quickshare.QuickShareDTO)1 InvalidNodeRefException (org.alfresco.service.cmr.repository.InvalidNodeRefException)1 NodeRef (org.alfresco.service.cmr.repository.NodeRef)1