Search in sources :

Example 1 with InvalidSharedIdException

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

the class QuickShareLinksImpl method readProperty.

/**
 * Download content via shared link.
 * <p>
 * Note: does *not* require authenticated access for (public) shared link.
 *
 * @param sharedId
 * @param renditionId - optional
 * @param parameters {@link Parameters}
 * @return
 * @throws EntityNotFoundException
 */
public BinaryResource readProperty(String sharedId, final String renditionId, final Parameters parameters) throws EntityNotFoundException {
    checkEnabled();
    checkValidShareId(sharedId);
    try {
        Pair<String, NodeRef> pair = quickShareService.getTenantNodeRefFromSharedId(sharedId);
        String networkTenantDomain = pair.getFirst();
        final NodeRef nodeRef = pair.getSecond();
        return TenantUtil.runAsSystemTenant(() -> {
            // belt-and-braces (similar to QuickShareContentGet)
            if (!nodeService.hasAspect(nodeRef, QuickShareModel.ASPECT_QSHARE)) {
                throw new InvalidNodeRefException(nodeRef);
            }
            if (renditionId != null) {
                return renditions.getContent(nodeRef, renditionId, parameters);
            } else {
                return nodes.getContent(nodeRef, parameters, false);
            }
        }, networkTenantDomain);
    } catch (InvalidSharedIdException ex) {
        logger.warn("Unable to find: " + sharedId);
        throw new EntityNotFoundException(sharedId);
    } catch (InvalidNodeRefException inre) {
        logger.warn("Unable to find: " + sharedId + " [" + inre.getNodeRef() + "]");
        throw new EntityNotFoundException(sharedId);
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) InvalidSharedIdException(org.alfresco.service.cmr.quickshare.InvalidSharedIdException) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException)

Example 2 with InvalidSharedIdException

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

the class QuickShareLinksImpl method emailSharedLink.

@Override
public void emailSharedLink(String sharedId, QuickShareLinkEmailRequest emailRequest, Parameters parameters) {
    checkEnabled();
    checkValidShareId(sharedId);
    validateEmailRequest(emailRequest);
    try {
        NodeRef nodeRef = quickShareService.getTenantNodeRefFromSharedId(sharedId).getSecond();
        String sharedNodeName = (String) nodeService.getProperty(nodeRef, ContentModel.PROP_NAME);
        QuickShareEmailRequest request = new QuickShareEmailRequest();
        request.setSharedNodeName(sharedNodeName);
        request.setClient(emailRequest.getClient());
        request.setSharedId(sharedId);
        request.setSenderMessage(emailRequest.getMessage());
        request.setLocale(I18NUtil.parseLocale(emailRequest.getLocale()));
        request.setToEmails(emailRequest.getRecipientEmails());
        quickShareService.sendEmailNotification(request);
    } catch (InvalidSharedIdException ex) {
        throw new EntityNotFoundException(sharedId);
    } catch (InvalidNodeRefException inre) {
        logger.warn("Unable to find: " + sharedId + " [" + inre.getNodeRef() + "]");
        throw new EntityNotFoundException(sharedId);
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) InvalidSharedIdException(org.alfresco.service.cmr.quickshare.InvalidSharedIdException) QuickShareEmailRequest(org.alfresco.repo.quickshare.QuickShareServiceImpl.QuickShareEmailRequest) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException)

Example 3 with InvalidSharedIdException

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

the class QuickShareLinksImpl method getRenditions.

@Override
public CollectionWithPagingInfo<Rendition> getRenditions(String sharedId) {
    checkEnabled();
    checkValidShareId(sharedId);
    try {
        Pair<String, NodeRef> pair = quickShareService.getTenantNodeRefFromSharedId(sharedId);
        String networkTenantDomain = pair.getFirst();
        final NodeRef nodeRef = pair.getSecond();
        return TenantUtil.runAsSystemTenant(() -> {
            Parameters params = getParamsWithCreatedStatus();
            return renditions.getRenditions(nodeRef, params);
        }, networkTenantDomain);
    } catch (InvalidSharedIdException ex) {
        logger.warn("Unable to find: " + sharedId);
        throw new EntityNotFoundException(sharedId);
    } catch (InvalidNodeRefException inre) {
        logger.warn("Unable to find: " + sharedId + " [" + inre.getNodeRef() + "]");
        throw new EntityNotFoundException(sharedId);
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) InvalidSharedIdException(org.alfresco.service.cmr.quickshare.InvalidSharedIdException) Parameters(org.alfresco.rest.framework.resource.parameters.Parameters) SearchParameters(org.alfresco.service.cmr.search.SearchParameters) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException)

Example 4 with InvalidSharedIdException

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

the class QuickShareMetaDataGet method executeImpl.

@Override
protected Map<String, Object> executeImpl(final 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 {
        return quickShareService.getMetaData(sharedId);
    } 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 : InvalidSharedIdException(org.alfresco.service.cmr.quickshare.InvalidSharedIdException) WebScriptException(org.springframework.extensions.webscripts.WebScriptException) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException)

Example 5 with InvalidSharedIdException

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

the class ReadGet method executeImpl.

@Override
protected Map<String, Object> executeImpl(final 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 {
        boolean canRead = quickShareService.canRead(sharedId);
        Map<String, Object> result = new HashMap<String, Object>();
        result.put("canRead", canRead);
        return result;
    } 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 : 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