use of org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback in project alfresco-remote-api by Alfresco.
the class InvitationWebScriptTest method tearDown.
@Override
protected void tearDown() throws Exception {
super.tearDown();
this.authenticationComponent.setCurrentUser(AuthenticationUtil.getAdminUserName());
RetryingTransactionCallback<Void> deleteCallback = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
personService.deletePerson(userOne);
personService.deletePerson(userTwo);
personService.deletePerson(userThree);
return null;
}
};
transactionService.getRetryingTransactionHelper().doInTransaction(deleteCallback);
// Tidy-up any sites created during the execution of the test
for (String shortName : this.createdSites) {
sendRequest(new DeleteRequest(URL_SITES + "/" + shortName), 0);
}
// Clear the list
this.createdSites.clear();
// Clear the list
this.createdInvitations.clear();
}
use of org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback in project alfresco-remote-api by Alfresco.
the class DiscussionRestApiTest method setUp.
// General methods
@Override
protected void setUp() throws Exception {
super.setUp();
this.authenticationService = (MutableAuthenticationService) getServer().getApplicationContext().getBean("AuthenticationService");
this.authenticationComponent = (AuthenticationComponent) getServer().getApplicationContext().getBean("authenticationComponent");
this.policyBehaviourFilter = (BehaviourFilter) getServer().getApplicationContext().getBean("policyBehaviourFilter");
this.transactionService = (TransactionService) getServer().getApplicationContext().getBean("transactionService");
this.permissionService = (PermissionService) getServer().getApplicationContext().getBean("PermissionService");
this.personService = (PersonService) getServer().getApplicationContext().getBean("PersonService");
this.siteService = (SiteService) getServer().getApplicationContext().getBean("SiteService");
this.nodeService = (NodeService) getServer().getApplicationContext().getBean("NodeService");
this.internalNodeService = (NodeService) getServer().getApplicationContext().getBean("nodeService");
this.nodeArchiveService = (NodeArchiveService) getServer().getApplicationContext().getBean("nodeArchiveService");
// Authenticate as user
this.authenticationComponent.setCurrentUser(AuthenticationUtil.getAdminUserName());
// Create test site
// - only create the site if it doesn't already exist
SiteInfo siteInfo = this.siteService.getSite(SITE_SHORT_NAME_DISCUSSION);
if (siteInfo == null) {
siteInfo = this.siteService.createSite("DiscussionSitePreset", SITE_SHORT_NAME_DISCUSSION, "DiscussionSiteTitle", "DiscussionSiteDescription", SiteVisibility.PUBLIC);
}
final NodeRef siteNodeRef = siteInfo.getNodeRef();
// Create the forum
final String forumNodeName = "TestForum";
FORUM_NODE = nodeService.getChildByName(siteInfo.getNodeRef(), ContentModel.ASSOC_CONTAINS, forumNodeName);
if (FORUM_NODE == null) {
FORUM_NODE = transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<NodeRef>() {
@Override
public NodeRef execute() throws Throwable {
Map<QName, Serializable> props = new HashMap<QName, Serializable>(5);
props.put(ContentModel.PROP_NAME, forumNodeName);
props.put(ContentModel.PROP_TITLE, forumNodeName);
return nodeService.createNode(siteNodeRef, ContentModel.ASSOC_CONTAINS, QName.createQName(forumNodeName), ForumModel.TYPE_FORUM, props).getChildRef();
}
});
}
// Create users
createUser(USER_ONE, SiteModel.SITE_COLLABORATOR, SITE_SHORT_NAME_DISCUSSION);
createUser(USER_TWO, SiteModel.SITE_CONTRIBUTOR, SITE_SHORT_NAME_DISCUSSION);
// Do tests as inviter user
this.authenticationComponent.setCurrentUser(USER_ONE);
}
use of org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback in project alfresco-remote-api by Alfresco.
the class DiscussionRestApiTest method tearDown.
@Override
protected void tearDown() throws Exception {
super.tearDown();
// admin user required to delete user
this.authenticationComponent.setCurrentUser(AuthenticationUtil.getAdminUserName());
// delete the discussions users
if (personService.personExists(USER_ONE)) {
personService.deletePerson(USER_ONE);
}
if (this.authenticationService.authenticationExists(USER_ONE)) {
this.authenticationService.deleteAuthentication(USER_ONE);
}
if (personService.personExists(USER_TWO)) {
personService.deletePerson(USER_TWO);
}
if (this.authenticationService.authenticationExists(USER_TWO)) {
this.authenticationService.deleteAuthentication(USER_TWO);
}
SiteInfo siteInfo = this.siteService.getSite(SITE_SHORT_NAME_DISCUSSION);
if (siteInfo != null) {
// delete discussions test site
RetryingTransactionCallback<Void> deleteCallback = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
siteService.deleteSite(SITE_SHORT_NAME_DISCUSSION);
return null;
}
};
transactionService.getRetryingTransactionHelper().doInTransaction(deleteCallback);
nodeArchiveService.purgeArchivedNode(nodeArchiveService.getArchivedNode(siteInfo.getNodeRef()));
}
}
use of org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback in project alfresco-remote-api by Alfresco.
the class TestCMIS method testScenario1.
/**
* Tests CMIS and non-CMIS public api interactions
*/
@SuppressWarnings("deprecation")
@Test
public void testScenario1() throws Exception {
final TestNetwork network1 = getTestFixture().getRandomNetwork();
Iterator<String> personIt = network1.getPersonIds().iterator();
final String person = personIt.next();
assertNotNull(person);
Sites sitesProxy = publicApiClient.sites();
Comments commentsProxy = publicApiClient.comments();
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person));
CmisSession cmisSession = publicApiClient.createPublicApiCMISSession(Binding.atom, CMIS_VERSION_10, AlfrescoObjectFactoryImpl.class.getName());
ListResponse<MemberOfSite> sites = sitesProxy.getPersonSites(person, null);
assertTrue(sites.getList().size() > 0);
MemberOfSite siteMember = sites.getList().get(0);
String siteId = siteMember.getSite().getSiteId();
Folder documentLibrary = (Folder) cmisSession.getObjectByPath("/Sites/" + siteId + "/documentLibrary");
System.out.println("documentLibrary id = " + documentLibrary.getId());
Map<String, String> fileProps = new HashMap<String, String>();
{
fileProps.put(PropertyIds.OBJECT_TYPE_ID, TYPE_CMIS_DOCUMENT);
fileProps.put(PropertyIds.NAME, "mydoc-" + GUID.generate() + ".txt");
}
ContentStreamImpl fileContent = new ContentStreamImpl();
{
ContentWriter writer = new FileContentWriter(TempFileProvider.createTempFile(GUID.generate(), ".txt"));
writer.putContent("Ipsum and so on");
ContentReader reader = writer.getReader();
fileContent.setMimeType(MimetypeMap.MIMETYPE_TEXT_PLAIN);
fileContent.setStream(reader.getContentInputStream());
}
Document doc = documentLibrary.createDocument(fileProps, fileContent, VersioningState.MAJOR);
System.out.println("Document id = " + doc.getId());
Comment c = commentsProxy.createNodeComment(doc.getId(), new Comment("comment title 1", "comment 1"));
System.out.println("Comment = " + c);
// Now lock the document
String nodeRefStr = (String) doc.getPropertyValue("alfcmis:nodeRef");
final NodeRef nodeRef = new NodeRef(nodeRefStr);
final TenantRunAsWork<Void> runAsWork = new TenantRunAsWork<Void>() {
@Override
public Void doWork() throws Exception {
lockService.lock(nodeRef, LockType.WRITE_LOCK);
return null;
}
};
RetryingTransactionCallback<Void> txnWork = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
TenantUtil.runAsUserTenant(runAsWork, "bob", network1.getId());
return null;
}
};
transactionHelper.doInTransaction(txnWork);
// Now attempt to update the document's metadata
try {
doc.delete();
} catch (CmisUpdateConflictException e) {
// Expected: ACE-762 BM-0012: NodeLockedException not handled by CMIS
}
}
use of org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback in project records-management by Alfresco.
the class RMActionProxyFactoryBean method registerAction.
/**
* Register the action
*/
public void registerAction() {
AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork<Void>() {
public Void doWork() {
transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Void>() {
public Void execute() throws Throwable {
RecordsManagementAction action = (RecordsManagementAction) getObject();
recordsManagementActionService.register(action);
return null;
}
});
return null;
}
}, AuthenticationUtil.getSystemUserName());
}
Aggregations