use of org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback 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.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback 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.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback 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.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback in project alfresco-remote-api by Alfresco.
the class LockMethodTest method testMNT_11990.
@Test
public void testMNT_11990() throws Exception {
MockHttpServletRequest lockRequest = new MockHttpServletRequest();
lockRequest.addHeader(WebDAV.HEADER_TIMEOUT, WebDAV.SECOND + 3600);
lockRequest.addHeader(WebDAV.HEADER_IF, "(<" + WebDAV.makeLockToken(fileNodeRef, userName) + ">)");
lockRequest.setRequestURI("/" + TEST_FILE_NAME);
lockMethod.setDetails(lockRequest, new MockHttpServletResponse(), davHelper, folderNodeRef);
lockMethod.parseRequestHeaders();
lockMethod.parseRequestBody();
RetryingTransactionCallback<Void> lockExecuteImplCallBack = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
try {
lockMethod.executeImpl();
fail("Lock should not be refreshed for non-locked file.");
} catch (WebDAVServerException e) {
assertEquals(e.getHttpStatusCode(), HttpServletResponse.SC_BAD_REQUEST);
}
return null;
}
};
// try to refresh lock for non-locked node
this.transactionService.getRetryingTransactionHelper().doInTransaction(lockExecuteImplCallBack);
}
use of org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback in project alfresco-remote-api by Alfresco.
the class LockMethodTest method testMNT_12425.
@Test
public void testMNT_12425() throws Exception {
MockHttpServletRequest lockRequest = new MockHttpServletRequest();
MockHttpServletResponse lockResponse = new MockHttpServletResponse();
// refresh lock set to 1 hour
lockRequest.addHeader(WebDAV.HEADER_TIMEOUT, WebDAV.SECOND + 3600);
lockRequest.addHeader(WebDAV.HEADER_IF, "(<" + WebDAV.makeLockToken(fileNodeRef, userName) + ">)");
// specify path to non-existing file
lockRequest.setRequestURI("/" + TEST_NEW_FOLDER_NAME + "/" + TEST_NEW_FILE_NAME);
lockMethod.setDetails(lockRequest, lockResponse, davHelper, folderNodeRef);
lockMethod.parseRequestHeaders();
RetryingTransactionCallback<Void> lockExecuteImplCallBack = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
try {
lockMethod.executeImpl();
fail("Refresh lock for non-exisitent resource should fail.");
} catch (WebDAVServerException e) {
assertEquals(HttpServletResponse.SC_FORBIDDEN, e.getHttpStatusCode());
}
return null;
}
};
// try to lock non-existent file
this.transactionService.getRetryingTransactionHelper().doInTransaction(lockExecuteImplCallBack);
}
Aggregations