Search in sources :

Example 1 with InvalidNodeRefException

use of org.alfresco.service.cmr.repository.InvalidNodeRefException 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 InvalidNodeRefException

use of org.alfresco.service.cmr.repository.InvalidNodeRefException 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)

Example 3 with InvalidNodeRefException

use of org.alfresco.service.cmr.repository.InvalidNodeRefException 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 4 with InvalidNodeRefException

use of org.alfresco.service.cmr.repository.InvalidNodeRefException 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 5 with InvalidNodeRefException

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

the class ResultMapper method getNode.

/**
 * Builds a node representation based on a ResultSetRow;
 * @param searchRequestContext
 * @param aRow
 * @param params
 * @param mapUserInfo
 * @param isHistory
 * @return Node
 */
public Node getNode(ResultSetRow aRow, Params params, Map<String, UserInfo> mapUserInfo, boolean isHistory) {
    String nodeStore = storeMapper.getStore(aRow.getNodeRef());
    if (isHistory)
        nodeStore = HISTORY;
    Node aNode = null;
    switch(nodeStore) {
        case LIVE_NODES:
            aNode = nodes.getFolderOrDocument(aRow.getNodeRef(), null, null, params.getInclude(), mapUserInfo);
            break;
        case HISTORY:
            aNode = nodes.getFolderOrDocument(aRow.getNodeRef(), null, null, params.getInclude(), mapUserInfo);
            break;
        case VERSIONS:
            Map<QName, Serializable> properties = serviceRegistry.getNodeService().getProperties(aRow.getNodeRef());
            NodeRef frozenNodeRef = ((NodeRef) properties.get(Version2Model.PROP_QNAME_FROZEN_NODE_REF));
            String versionLabelId = (String) properties.get(Version2Model.PROP_QNAME_VERSION_LABEL);
            Version v = null;
            try {
                if (frozenNodeRef != null && versionLabelId != null) {
                    v = nodeVersions.findVersion(frozenNodeRef.getId(), versionLabelId);
                    aNode = nodes.getFolderOrDocument(v.getFrozenStateNodeRef(), null, null, params.getInclude(), mapUserInfo);
                }
            } catch (EntityNotFoundException | InvalidNodeRefException e) {
                // Solr says there is a node but we can't find it
                logger.debug("Failed to find a versioned node with id of " + frozenNodeRef + " this is probably because the original node has been deleted.");
            }
            if (v != null && aNode != null) {
                nodeVersions.mapVersionInfo(v, aNode, aRow.getNodeRef());
                aNode.setNodeId(frozenNodeRef.getId());
                aNode.setVersionLabel(versionLabelId);
            }
            break;
        case DELETED:
            try {
                aNode = deletedNodes.getDeletedNode(aRow.getNodeRef().getId(), params, false, mapUserInfo);
            } catch (EntityNotFoundException enfe) {
                // Solr says there is a deleted node but we can't find it, we want the rest of the search to return so lets ignore it.
                logger.debug("Failed to find a deleted node with id of " + aRow.getNodeRef().getId());
            }
            break;
    }
    if (aNode != null) {
        aNode.setLocation(nodeStore);
    }
    return aNode;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) Serializable(java.io.Serializable) Version(org.alfresco.service.cmr.version.Version) QName(org.alfresco.service.namespace.QName) Node(org.alfresco.rest.api.model.Node) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException)

Aggregations

InvalidNodeRefException (org.alfresco.service.cmr.repository.InvalidNodeRefException)61 NodeRef (org.alfresco.service.cmr.repository.NodeRef)49 Node (org.alfresco.web.bean.repository.Node)21 FacesContext (javax.faces.context.FacesContext)20 UserTransaction (javax.transaction.UserTransaction)16 MapNode (org.alfresco.web.bean.repository.MapNode)12 InvalidSharedIdException (org.alfresco.service.cmr.quickshare.InvalidSharedIdException)10 EntityNotFoundException (org.alfresco.rest.framework.core.exceptions.EntityNotFoundException)9 QName (org.alfresco.service.namespace.QName)9 IOException (java.io.IOException)8 HashMap (java.util.HashMap)8 AbortProcessingException (javax.faces.event.AbortProcessingException)8 AccessDeniedException (org.alfresco.repo.security.permissions.AccessDeniedException)8 UIActionLink (org.alfresco.web.ui.common.component.UIActionLink)8 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)7 WebScriptException (org.springframework.extensions.webscripts.WebScriptException)7 Serializable (java.io.Serializable)5 ArrayList (java.util.ArrayList)4 List (java.util.List)4 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)4