Search in sources :

Example 61 with RetryingTransactionCallback

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();
}
Also used : RetryingTransactionCallback(org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback) DeleteRequest(org.springframework.extensions.webscripts.TestWebScriptServer.DeleteRequest)

Example 62 with RetryingTransactionCallback

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);
}
Also used : SiteInfo(org.alfresco.service.cmr.site.SiteInfo) NodeRef(org.alfresco.service.cmr.repository.NodeRef) Serializable(java.io.Serializable) RetryingTransactionCallback(org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback) HashMap(java.util.HashMap) QName(org.alfresco.service.namespace.QName)

Example 63 with RetryingTransactionCallback

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()));
    }
}
Also used : SiteInfo(org.alfresco.service.cmr.site.SiteInfo) RetryingTransactionCallback(org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback)

Example 64 with RetryingTransactionCallback

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
    }
}
Also used : ContentStreamImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.ContentStreamImpl) HashMap(java.util.HashMap) CmisUpdateConflictException(org.apache.chemistry.opencmis.commons.exceptions.CmisUpdateConflictException) MemberOfSite(org.alfresco.rest.api.tests.client.data.MemberOfSite) AlfrescoFolder(org.alfresco.cmis.client.AlfrescoFolder) Folder(org.apache.chemistry.opencmis.client.api.Folder) AlfrescoDocument(org.alfresco.cmis.client.AlfrescoDocument) Document(org.apache.chemistry.opencmis.client.api.Document) NodeRef(org.alfresco.service.cmr.repository.NodeRef) RequestContext(org.alfresco.rest.api.tests.client.RequestContext) Comment(org.alfresco.rest.api.tests.client.data.Comment) AlfrescoObjectFactoryImpl(org.alfresco.cmis.client.impl.AlfrescoObjectFactoryImpl) CmisSession(org.alfresco.rest.api.tests.client.PublicApiClient.CmisSession) Comments(org.alfresco.rest.api.tests.client.PublicApiClient.Comments) FileContentWriter(org.alfresco.repo.content.filestore.FileContentWriter) ContentReader(org.alfresco.service.cmr.repository.ContentReader) Sites(org.alfresco.rest.api.tests.client.PublicApiClient.Sites) ContentWriter(org.alfresco.service.cmr.repository.ContentWriter) FileContentWriter(org.alfresco.repo.content.filestore.FileContentWriter) RetryingTransactionCallback(org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback) TenantRunAsWork(org.alfresco.repo.tenant.TenantUtil.TenantRunAsWork) TestNetwork(org.alfresco.rest.api.tests.RepoService.TestNetwork) VersionableAspectTest(org.alfresco.repo.version.VersionableAspectTest) Test(org.junit.Test)

Example 65 with RetryingTransactionCallback

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());
}
Also used : RecordsManagementAction(org.alfresco.module.org_alfresco_module_rm.action.RecordsManagementAction) AuthenticationUtil(org.alfresco.repo.security.authentication.AuthenticationUtil) RetryingTransactionCallback(org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback)

Aggregations

RetryingTransactionCallback (org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback)78 NodeRef (org.alfresco.service.cmr.repository.NodeRef)44 RetryingTransactionHelper (org.alfresco.repo.transaction.RetryingTransactionHelper)20 FileInfo (org.alfresco.service.cmr.model.FileInfo)20 WebApiDescription (org.alfresco.rest.framework.WebApiDescription)16 HashMap (java.util.HashMap)15 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)15 FacesContext (javax.faces.context.FacesContext)12 QName (org.alfresco.service.namespace.QName)11 Serializable (java.io.Serializable)10 List (java.util.List)9 ArrayList (java.util.ArrayList)8 ContentWriter (org.alfresco.service.cmr.repository.ContentWriter)8 IOException (java.io.IOException)7 FileNotFoundException (org.alfresco.service.cmr.model.FileNotFoundException)7 Test (org.junit.Test)7 WebScriptException (org.springframework.extensions.webscripts.WebScriptException)7 AuthenticationUtil (org.alfresco.repo.security.authentication.AuthenticationUtil)6 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)6 AbstractList (java.util.AbstractList)5