Search in sources :

Example 6 with InvalidNodeRefException

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

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

Example 8 with InvalidNodeRefException

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

the class ShareContentGet 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 {
        Pair<String, NodeRef> pair = quickShareService.getTenantNodeRefFromSharedId(sharedId);
        final String tenantDomain = pair.getFirst();
        final NodeRef nodeRef = pair.getSecond();
        String siteId = siteService.getSiteShortName(nodeRef);
        Map<String, Object> model = new HashMap<String, Object>(3);
        model.put("sharedId", sharedId);
        model.put("nodeRef", nodeRef.toString());
        model.put("siteId", siteId);
        model.put("tenantDomain", tenantDomain);
        if (logger.isInfoEnabled()) {
            logger.info("QuickShare - get shared context: " + sharedId + " [" + model + "]");
        }
        return model;
    } 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) WebScriptException(org.springframework.extensions.webscripts.WebScriptException) HashMap(java.util.HashMap) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException)

Example 9 with InvalidNodeRefException

use of org.alfresco.service.cmr.repository.InvalidNodeRefException in project acs-community-packaging by Alfresco.

the class BrowseBean method queryBrowseNodes.

// ------------------------------------------------------------------------------
// Helper methods
/**
 * Query a list of nodes for the specified parent node Id
 *
 * @param parentNodeId     Id of the parent node or null for the root node
 */
private void queryBrowseNodes(String parentNodeId) {
    long startTime = 0;
    if (logger.isDebugEnabled())
        startTime = System.currentTimeMillis();
    UserTransaction tx = null;
    try {
        FacesContext context = FacesContext.getCurrentInstance();
        tx = Repository.getUserTransaction(context, true);
        tx.begin();
        NodeRef parentRef;
        if (parentNodeId == null) {
            // no specific parent node specified - use the root node
            parentRef = this.getNodeService().getRootNode(Repository.getStoreRef());
        } else {
            // build a NodeRef for the specified Id and our store
            parentRef = new NodeRef(Repository.getStoreRef(), parentNodeId);
        }
        List<FileInfo> children = null;
        FileFilterMode.setClient(Client.webclient);
        try {
            children = this.getFileFolderService().list(parentRef);
        } finally {
            FileFilterMode.clearClient();
        }
        this.containerNodes = new ArrayList<Node>(children.size());
        this.contentNodes = new ArrayList<Node>(children.size());
        // in case of dynamic config, only lookup once
        Set<NodeEventListener> nodeEventListeners = getNodeEventListeners();
        for (FileInfo fileInfo : children) {
            // create our Node representation from the NodeRef
            NodeRef nodeRef = fileInfo.getNodeRef();
            // find it's type so we can see if it's a node we are interested in
            QName type = this.getNodeService().getType(nodeRef);
            // make sure the type is defined in the data dictionary
            TypeDefinition typeDef = this.getDictionaryService().getType(type);
            if (typeDef != null) {
                MapNode node = null;
                // look for File content node
                if (this.getDictionaryService().isSubClass(type, ContentModel.TYPE_CONTENT)) {
                    // create our Node representation
                    node = new MapNode(nodeRef, this.getNodeService(), fileInfo.getProperties());
                    setupCommonBindingProperties(node);
                    this.contentNodes.add(node);
                } else // look for Space folder node
                if (this.getDictionaryService().isSubClass(type, ContentModel.TYPE_FOLDER) == true && this.getDictionaryService().isSubClass(type, ContentModel.TYPE_SYSTEM_FOLDER) == false) {
                    // create our Node representation
                    node = new MapNode(nodeRef, this.getNodeService(), fileInfo.getProperties());
                    node.addPropertyResolver("icon", this.resolverSpaceIcon);
                    node.addPropertyResolver("smallIcon", this.resolverSmallIcon);
                    this.containerNodes.add(node);
                } else // look for File Link object node
                if (ApplicationModel.TYPE_FILELINK.equals(type)) {
                    // create our File Link Node representation
                    node = new MapNode(nodeRef, this.getNodeService(), fileInfo.getProperties());
                    // only display the user has the permissions to navigate to the target of the link
                    NodeRef destRef = (NodeRef) node.getProperties().get(ContentModel.PROP_LINK_DESTINATION);
                    if (destRef != null && new Node(destRef).hasPermission(PermissionService.READ) == true) {
                        node.addPropertyResolver("url", this.resolverLinkUrl);
                        node.addPropertyResolver("downloadUrl", this.resolverLinkDownload);
                        node.addPropertyResolver("webdavUrl", this.resolverLinkWebdavUrl);
                        node.addPropertyResolver("cifsPath", this.resolverLinkCifsPath);
                        node.addPropertyResolver("fileType16", this.resolverFileType16);
                        node.addPropertyResolver("fileType32", this.resolverFileType32);
                        node.addPropertyResolver("lang", this.resolverLang);
                        this.contentNodes.add(node);
                    }
                } else if (ApplicationModel.TYPE_FOLDERLINK.equals(type)) {
                    // create our Folder Link Node representation
                    node = new MapNode(nodeRef, this.getNodeService(), fileInfo.getProperties());
                    // only display the user has the permissions to navigate to the target of the link
                    NodeRef destRef = (NodeRef) node.getProperties().get(ContentModel.PROP_LINK_DESTINATION);
                    if (destRef != null && new Node(destRef).hasPermission(PermissionService.READ) == true) {
                        node.addPropertyResolver("icon", this.resolverSpaceIcon);
                        node.addPropertyResolver("smallIcon", this.resolverSmallIcon);
                        this.containerNodes.add(node);
                    }
                }
                // inform any listeners that a Node wrapper has been created
                if (node != null) {
                    for (NodeEventListener listener : nodeEventListeners) {
                        listener.created(node, type);
                    }
                }
            } else {
                if (logger.isWarnEnabled())
                    logger.warn("Found invalid object in database: id = " + nodeRef + ", type = " + type);
            }
        }
        // commit the transaction
        tx.commit();
    } catch (InvalidNodeRefException refErr) {
        Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_NODEREF), new Object[] { refErr.getNodeRef() }), refErr);
        this.containerNodes = Collections.<Node>emptyList();
        this.contentNodes = Collections.<Node>emptyList();
        try {
            if (tx != null) {
                tx.rollback();
            }
        } catch (Exception tex) {
        }
    } catch (Throwable err) {
        Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_GENERIC), err.getMessage()), err);
        this.containerNodes = Collections.<Node>emptyList();
        this.contentNodes = Collections.<Node>emptyList();
        try {
            if (tx != null) {
                tx.rollback();
            }
        } catch (Exception tex) {
        }
    }
    if (logger.isDebugEnabled()) {
        long endTime = System.currentTimeMillis();
        logger.debug("Time to query and build map nodes: " + (endTime - startTime) + "ms");
    }
}
Also used : UserTransaction(javax.transaction.UserTransaction) FacesContext(javax.faces.context.FacesContext) QName(org.alfresco.service.namespace.QName) Node(org.alfresco.web.bean.repository.Node) MapNode(org.alfresco.web.bean.repository.MapNode) MapNode(org.alfresco.web.bean.repository.MapNode) SearcherException(org.alfresco.repo.search.SearcherException) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException) AbortProcessingException(javax.faces.event.AbortProcessingException) IOException(java.io.IOException) TypeDefinition(org.alfresco.service.cmr.dictionary.TypeDefinition) NodeRef(org.alfresco.service.cmr.repository.NodeRef) FileInfo(org.alfresco.service.cmr.model.FileInfo) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException)

Example 10 with InvalidNodeRefException

use of org.alfresco.service.cmr.repository.InvalidNodeRefException in project acs-community-packaging by Alfresco.

the class BrowseBean method setupContentAction.

/**
 * Public helper to setup action pages with content context
 *
 * @param id     of the content node to setup context for
 */
public void setupContentAction(String id, boolean invalidate) {
    if (id != null && id.length() != 0) {
        if (logger.isDebugEnabled())
            logger.debug("Setup for action, setting current document to: " + id);
        try {
            // create the node ref, then our node representation
            NodeRef ref = new NodeRef(Repository.getStoreRef(), id);
            Node node = new MapNode(ref);
            // store the URL to for downloading the content
            if (ApplicationModel.TYPE_FILELINK.equals(node.getType())) {
                node.addPropertyResolver("url", this.resolverLinkDownload);
                node.addPropertyResolver("downloadUrl", this.resolverLinkDownload);
            } else {
                node.addPropertyResolver("url", this.resolverDownload);
                node.addPropertyResolver("downloadUrl", this.resolverDownload);
            }
            node.addPropertyResolver("webdavUrl", this.resolverWebdavUrl);
            node.addPropertyResolver("cifsPath", this.resolverCifsPath);
            node.addPropertyResolver("fileType32", this.resolverFileType32);
            node.addPropertyResolver("mimetype", this.resolverMimetype);
            node.addPropertyResolver("encoding", this.resolverEncoding);
            node.addPropertyResolver("size", this.resolverSize);
            node.addPropertyResolver("lang", this.resolverLang);
            for (NodeEventListener listener : getNodeEventListeners()) {
                listener.created(node, node.getType());
            }
            // get hold of the DocumentDetailsDialog and reset it
            DocumentDetailsDialog docDetails = (DocumentDetailsDialog) FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("DocumentDetailsDialog");
            if (docDetails != null) {
                docDetails.reset();
            }
            // remember the document
            setDocument(node);
            // setup the dispatch context in case it is required
            this.navigator.setupDispatchContext(node);
        } catch (InvalidNodeRefException refErr) {
            Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_NODEREF), new Object[] { id }));
            throw new AbortProcessingException("Invalid node reference");
        }
    } else {
        setDocument(null);
    }
    // clear the UI state in preparation for finishing the next action
    if (invalidate == true) {
        // use the context service to notify all registered beans
        UIContextService.getInstance(FacesContext.getCurrentInstance()).notifyBeans();
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) DocumentDetailsDialog(org.alfresco.web.bean.content.DocumentDetailsDialog) Node(org.alfresco.web.bean.repository.Node) MapNode(org.alfresco.web.bean.repository.MapNode) AbortProcessingException(javax.faces.event.AbortProcessingException) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException) MapNode(org.alfresco.web.bean.repository.MapNode)

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