Search in sources :

Example 46 with NodeRef

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

the class RepoStore method getAllDocumentPaths.

/* (non-Javadoc)
     * @see org.alfresco.web.scripts.Store#getAllDocumentPaths()
     */
public String[] getAllDocumentPaths() {
    return AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork<String[]>() {

        public String[] doWork() throws Exception {
            return retryingTransactionHelper.doInTransaction(new RetryingTransactionCallback<String[]>() {

                public String[] execute() throws Exception {
                    int baseDirLength = getBaseDir().length() + 1;
                    List<String> documentPaths;
                    NodeRef repoStoreRootNodeRef = nodeService.getRootNode(repoStore);
                    List<NodeRef> nodeRefs = searchService.selectNodes(repoStoreRootNodeRef, repoPath + "//*[subtypeOf('{http://www.alfresco.org/model/content/1.0}content')]\"", new QueryParameterDefinition[] {}, namespaceService, false, SearchService.LANGUAGE_XPATH);
                    documentPaths = new ArrayList<String>(nodeRefs.size());
                    for (NodeRef nodeRef : nodeRefs) {
                        if (isContentPresent(nodeRef)) {
                            String nodeDir = getPath(nodeRef);
                            documentPaths.add(nodeDir.substring(baseDirLength));
                        }
                    }
                    return documentPaths.toArray(new String[documentPaths.size()]);
                }
            }, true, false);
        }
    }, AuthenticationUtil.getSystemUserName());
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) AuthenticationUtil(org.alfresco.repo.security.authentication.AuthenticationUtil) RetryingTransactionCallback(org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback) FileNotFoundException(org.alfresco.service.cmr.model.FileNotFoundException) IOException(java.io.IOException) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) WebScriptException(org.springframework.extensions.webscripts.WebScriptException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 47 with NodeRef

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

the class RepoStore method getScriptDocumentPaths.

/* (non-Javadoc)
     * @see org.alfresco.web.scripts.Store#getScriptDocumentPaths(org.alfresco.web.scripts.WebScript)
     */
public String[] getScriptDocumentPaths(final WebScript script) {
    return AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork<String[]>() {

        public String[] doWork() throws Exception {
            return retryingTransactionHelper.doInTransaction(new RetryingTransactionCallback<String[]>() {

                public String[] execute() throws Exception {
                    int baseDirLength = getBaseDir().length() + 1;
                    List<String> documentPaths = null;
                    String scriptPath = script.getDescription().getScriptPath();
                    NodeRef scriptNodeRef = (scriptPath.length() == 0) ? getBaseNodeRef() : findNodeRef(scriptPath);
                    if (scriptNodeRef != null) {
                        org.alfresco.service.cmr.repository.Path repoScriptPath = nodeService.getPath(scriptNodeRef);
                        String id = script.getDescription().getId().substring(scriptPath.length() + (scriptPath.length() > 0 ? 1 : 0));
                        NodeRef repoStoreRootNodeRef = nodeService.getRootNode(repoStore);
                        List<NodeRef> nodeRefs = searchService.selectNodes(repoStoreRootNodeRef, repoScriptPath.toPrefixString(namespaceService) + "//*[like(@cm:name, '" + SearchLanguageConversion.convert(SearchLanguageConversion.DEF_LUCENE, SearchLanguageConversion.DEF_XPATH_LIKE, id + "*") + "', false)]", new QueryParameterDefinition[] {}, namespaceService, false, SearchService.LANGUAGE_XPATH);
                        documentPaths = new ArrayList<String>(nodeRefs.size());
                        for (NodeRef nodeRef : nodeRefs) {
                            if (isContentPresent(nodeRef)) {
                                String name = (String) nodeService.getProperty(nodeRef, ContentModel.PROP_NAME);
                                if (name.startsWith(id)) {
                                    String nodeDir = getPath(nodeRef);
                                    String documentPath = nodeDir.substring(baseDirLength);
                                    documentPaths.add(documentPath);
                                }
                            }
                        }
                    // String query = "+PATH:\"" + repoScriptPath.toPrefixString(namespaceService) +
                    // "//*\" +QNAME:" + lucenifyNamePattern(id) + "*";
                    // ResultSet resultSet = searchService.query(repoStore, SearchService.LANGUAGE_LUCENE, query);
                    // try
                    // {
                    // documentPaths = new ArrayList<String>(resultSet.length());
                    // List<NodeRef> nodes = resultSet.getNodeRefs();
                    // for (NodeRef nodeRef : nodes)
                    // {
                    // String name = (String)nodeService.getProperty(nodeRef, ContentModel.PROP_NAME);
                    // if (name.startsWith(id))
                    // {
                    // String nodeDir = getPath(nodeRef);
                    // String documentPath = nodeDir.substring(baseDirLength);
                    // documentPaths.add(documentPath);
                    // }
                    // }
                    // }
                    // finally
                    // {
                    // resultSet.close();
                    // }
                    }
                    return documentPaths != null ? documentPaths.toArray(new String[documentPaths.size()]) : new String[0];
                }
            }, true, false);
        }
    }, AuthenticationUtil.getSystemUserName());
}
Also used : FileNotFoundException(org.alfresco.service.cmr.model.FileNotFoundException) IOException(java.io.IOException) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) WebScriptException(org.springframework.extensions.webscripts.WebScriptException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) NodeRef(org.alfresco.service.cmr.repository.NodeRef) AuthenticationUtil(org.alfresco.repo.security.authentication.AuthenticationUtil) RetryingTransactionCallback(org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback)

Example 48 with NodeRef

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

the class RepoStore method getDocument.

/* (non-Javadoc)
     * @see org.alfresco.web.scripts.Store#getDescriptionDocument(java.lang.String)
     */
public InputStream getDocument(final String documentPath) throws IOException {
    return AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork<InputStream>() {

        public InputStream doWork() throws Exception {
            return retryingTransactionHelper.doInTransaction(new RetryingTransactionCallback<InputStream>() {

                public InputStream execute() throws Exception {
                    NodeRef nodeRef = findNodeRef(documentPath);
                    if (nodeRef == null) {
                        throw new IOException("Document " + documentPath + " does not exist.");
                    }
                    ContentReader reader = contentService.getReader(nodeRef, ContentModel.PROP_CONTENT);
                    if (reader == null || !reader.exists()) {
                        throw new IOException("Failed to read content at " + documentPath + " (content reader does not exist)");
                    }
                    return reader.getContentInputStream();
                }
            }, true, false);
        }
    }, AuthenticationUtil.getSystemUserName());
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) AuthenticationUtil(org.alfresco.repo.security.authentication.AuthenticationUtil) RetryingTransactionCallback(org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback) InputStream(java.io.InputStream) ContentReader(org.alfresco.service.cmr.repository.ContentReader) IOException(java.io.IOException) FileNotFoundException(org.alfresco.service.cmr.model.FileNotFoundException) IOException(java.io.IOException) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) WebScriptException(org.springframework.extensions.webscripts.WebScriptException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 49 with NodeRef

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

the class RepoStore method getBaseNodeRef.

private NodeRef getBaseNodeRef() {
    String tenantDomain = tenantAdminService.getCurrentUserDomain();
    NodeRef baseNodeRef = baseNodeRefs.get(tenantDomain);
    if (baseNodeRef == null) {
        baseNodeRef = AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork<NodeRef>() {

            public NodeRef doWork() throws Exception {
                return retryingTransactionHelper.doInTransaction(new RetryingTransactionCallback<NodeRef>() {

                    public NodeRef execute() throws Exception {
                        NodeRef repoStoreRootNodeRef = nodeService.getRootNode(repoStore);
                        List<NodeRef> nodeRefs = searchService.selectNodes(repoStoreRootNodeRef, repoPath, new QueryParameterDefinition[] {}, namespaceService, false, SearchService.LANGUAGE_XPATH);
                        if (nodeRefs.size() == 1) {
                            return nodeRefs.get(0);
                        } else if (nodeRefs.size() > 1) {
                            throw new WebScriptException("Web Script Store " + repoStore.toString() + repoPath + " must exist; multiple entries found.");
                        } else {
                            throw new WebScriptException("Web Script Store " + repoStore.toString() + repoPath + " must exist; it was not found");
                        }
                    }
                }, true, false);
            }
        }, AuthenticationUtil.getSystemUserName());
        // TODO clear on deleteTenant
        baseNodeRefs.put(tenantDomain, baseNodeRef);
    }
    return baseNodeRef;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) WebScriptException(org.springframework.extensions.webscripts.WebScriptException) ArrayList(java.util.ArrayList) List(java.util.List) FileNotFoundException(org.alfresco.service.cmr.model.FileNotFoundException) IOException(java.io.IOException) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) WebScriptException(org.springframework.extensions.webscripts.WebScriptException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) QueryParameterDefinition(org.alfresco.service.cmr.search.QueryParameterDefinition)

Example 50 with NodeRef

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

the class RunningActionsPost method identifyAction.

@Override
protected Action identifyAction(WebScriptRequest req, Status status, Cache cache) {
    // Which action did they ask for?
    String nodeRef = req.getParameter("nodeRef");
    if (nodeRef == null) {
        try {
            JSONObject json = new JSONObject(new JSONTokener(req.getContent().getContent()));
            if (!json.has("nodeRef")) {
                throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Could not find required 'nodeRef' parameter");
            }
            nodeRef = json.getString("nodeRef");
        } catch (IOException iox) {
            throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Could not read content from request.", iox);
        } catch (JSONException je) {
            throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Could not parse JSON from request.", je);
        }
    }
    // Does it exist in the repo?
    NodeRef actionNodeRef = new NodeRef(nodeRef);
    if (!nodeService.exists(actionNodeRef)) {
        return null;
    }
    // Load the specified action
    Action action = runtimeActionService.createAction(actionNodeRef);
    return action;
}
Also used : JSONTokener(org.json.JSONTokener) NodeRef(org.alfresco.service.cmr.repository.NodeRef) Action(org.alfresco.service.cmr.action.Action) JSONObject(org.json.JSONObject) WebScriptException(org.springframework.extensions.webscripts.WebScriptException) JSONException(org.json.JSONException) IOException(java.io.IOException)

Aggregations

NodeRef (org.alfresco.service.cmr.repository.NodeRef)1239 HashMap (java.util.HashMap)244 QName (org.alfresco.service.namespace.QName)242 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)209 Test (org.junit.Test)195 ArrayList (java.util.ArrayList)159 Serializable (java.io.Serializable)136 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)104 BaseUnitTest (org.alfresco.module.org_alfresco_module_rm.test.util.BaseUnitTest)101 FileInfo (org.alfresco.service.cmr.model.FileInfo)82 Map (java.util.Map)81 Node (org.alfresco.web.bean.repository.Node)81 JSONObject (org.json.JSONObject)80 WebScriptException (org.springframework.extensions.webscripts.WebScriptException)74 FacesContext (javax.faces.context.FacesContext)61 InvalidNodeRefException (org.alfresco.service.cmr.repository.InvalidNodeRefException)59 List (java.util.List)58 IOException (java.io.IOException)55 ContentWriter (org.alfresco.service.cmr.repository.ContentWriter)52 Date (java.util.Date)51