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());
}
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());
}
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());
}
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;
}
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;
}
Aggregations