Search in sources :

Example 11 with MemberOfSite

use of org.alfresco.rest.api.tests.client.data.MemberOfSite 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 12 with MemberOfSite

use of org.alfresco.rest.api.tests.client.data.MemberOfSite in project alfresco-remote-api by Alfresco.

the class TestPersonSites method testSitesWithSameTitles.

// ACE-4823
@Test
public void testSitesWithSameTitles() throws Exception {
    // Creates 3 sites
    initializeSites();
    final String site4_name = "d_" + GUID.generate();
    // Same title as site3
    final String site4_title = site3_title;
    final SiteRole site4_role = SiteRole.SiteCollaborator;
    TestSite site4 = TenantUtil.runAsUserTenant(new TenantRunAsWork<TestSite>() {

        @Override
        public TestSite doWork() throws Exception {
            SiteInformation siteInfo = new SiteInformation(site4_name, site4_title, site4_title, SiteVisibility.PRIVATE);
            TestSite site = network1.createSite(siteInfo);
            site.inviteToSite(person32.getId(), site4_role);
            return site;
        }
    }, person31.getId(), network1.getId());
    assertNotNull(site4);
    // paging
    int totalResults = 4;
    Paging paging = getPaging(null, null, totalResults, totalResults);
    // get memberships
    ListResponse<MemberOfSite> resp = getSiteMembershipsForPerson32(null, null, false);
    // check results
    List<MemberOfSite> expectedList = new LinkedList<>();
    expectedList.add(new MemberOfSite(site2, site2_role));
    expectedList.add(new MemberOfSite(site3, site3_role));
    expectedList.add(new MemberOfSite(site4, site4_role));
    expectedList.add(new MemberOfSite(site1, site1_role));
    try {
        checkList(expectedList, paging.getExpectedPaging(), resp);
    } catch (AssertionError error) {
        // Site3 and Site4 have a same title, and as we are sorting on titles (default sorting),
        // we can't guarantee the order in which the sites will
        // return, hence swap the sites and compare again.
        Collections.swap(expectedList, 1, 2);
        checkList(expectedList, paging.getExpectedPaging(), resp);
    }
}
Also used : SiteRole(org.alfresco.rest.api.tests.client.data.SiteRole) TestSite(org.alfresco.rest.api.tests.RepoService.TestSite) Paging(org.alfresco.rest.api.tests.client.PublicApiClient.Paging) MemberOfSite(org.alfresco.rest.api.tests.client.data.MemberOfSite) PublicApiException(org.alfresco.rest.api.tests.client.PublicApiException) LinkedList(java.util.LinkedList) SiteInformation(org.alfresco.rest.api.tests.RepoService.SiteInformation) Test(org.junit.Test)

Example 13 with MemberOfSite

use of org.alfresco.rest.api.tests.client.data.MemberOfSite in project alfresco-remote-api by Alfresco.

the class TestPersonSites method testSortingAndPagingByRoleDesc.

/**
 * Tests the capability to sort and paginate the site memberships associated
 * to a user orderBy = role DESC skip = 1, count = 2
 *
 * @throws Exception
 */
public void testSortingAndPagingByRoleDesc() throws Exception {
    // paging
    int skipCount = 1;
    int maxItems = 2;
    int totalResults = 3;
    Paging paging = getPaging(skipCount, maxItems, totalResults, totalResults);
    // get memberships
    ListResponse<MemberOfSite> resp = getSiteMembershipsForPerson32(paging, "role", false);
    // check results
    List<MemberOfSite> expectedList = new LinkedList<>();
    expectedList.add(new MemberOfSite(site1, site1_role));
    expectedList.add(new MemberOfSite(site3, site3_role));
    checkList(expectedList, paging.getExpectedPaging(), resp);
}
Also used : Paging(org.alfresco.rest.api.tests.client.PublicApiClient.Paging) MemberOfSite(org.alfresco.rest.api.tests.client.data.MemberOfSite) LinkedList(java.util.LinkedList)

Example 14 with MemberOfSite

use of org.alfresco.rest.api.tests.client.data.MemberOfSite in project alfresco-remote-api by Alfresco.

the class TestPersonSites method testSortingAndPagingDefault.

/**
 * Tests the capability to sort and paginate the site memberships associated
 * default sorting (title asc), all results
 *
 * @throws Exception
 */
public void testSortingAndPagingDefault() throws Exception {
    // paging
    int totalResults = 3;
    Paging paging = getPaging(null, null, totalResults, totalResults);
    // get memberships
    ListResponse<MemberOfSite> resp = getSiteMembershipsForPerson32(null, null, false);
    // check results
    List<MemberOfSite> expectedList = new LinkedList<>();
    expectedList.add(new MemberOfSite(site2, site2_role));
    expectedList.add(new MemberOfSite(site3, site3_role));
    expectedList.add(new MemberOfSite(site1, site1_role));
    checkList(expectedList, paging.getExpectedPaging(), resp);
}
Also used : Paging(org.alfresco.rest.api.tests.client.PublicApiClient.Paging) MemberOfSite(org.alfresco.rest.api.tests.client.data.MemberOfSite) LinkedList(java.util.LinkedList)

Example 15 with MemberOfSite

use of org.alfresco.rest.api.tests.client.data.MemberOfSite in project alfresco-remote-api by Alfresco.

the class TestPersonSites method testGetSiteMembershipsWhereSiteVisibilityPublic.

public void testGetSiteMembershipsWhereSiteVisibilityPublic() throws Exception {
    // paging
    int totalResults = 2;
    Paging paging = getPaging(null, null, totalResults, totalResults);
    // list sites
    ListResponse<MemberOfSite> resp = getSiteMembershipsForPerson41(null, SiteVisibility.PUBLIC.name());
    // check results
    List<MemberOfSite> expectedList = getPersonSites(person41, site42, site43);
    checkList(expectedList, paging.getExpectedPaging(), resp);
}
Also used : Paging(org.alfresco.rest.api.tests.client.PublicApiClient.Paging) MemberOfSite(org.alfresco.rest.api.tests.client.data.MemberOfSite)

Aggregations

MemberOfSite (org.alfresco.rest.api.tests.client.data.MemberOfSite)27 Paging (org.alfresco.rest.api.tests.client.PublicApiClient.Paging)14 PublicApiException (org.alfresco.rest.api.tests.client.PublicApiException)12 RequestContext (org.alfresco.rest.api.tests.client.RequestContext)12 Test (org.junit.Test)11 LinkedList (java.util.LinkedList)8 ArrayList (java.util.ArrayList)7 TenantRunAsWork (org.alfresco.repo.tenant.TenantUtil.TenantRunAsWork)7 TestSite (org.alfresco.rest.api.tests.RepoService.TestSite)7 JSONObject (org.json.simple.JSONObject)7 Task (org.activiti.engine.task.Task)6 Sites (org.alfresco.rest.api.tests.client.PublicApiClient.Sites)5 ProcessInfo (org.alfresco.rest.workflow.api.model.ProcessInfo)5 TasksClient (org.alfresco.rest.workflow.api.tests.WorkflowApiClient.TasksClient)5 List (java.util.List)4 TestPerson (org.alfresco.rest.api.tests.RepoService.TestPerson)4 NodeRef (org.alfresco.service.cmr.repository.NodeRef)4 HashMap (java.util.HashMap)3 TestNetwork (org.alfresco.rest.api.tests.RepoService.TestNetwork)3 ListResponse (org.alfresco.rest.api.tests.client.PublicApiClient.ListResponse)3