Search in sources :

Example 56 with Document

use of org.apache.chemistry.opencmis.client.api.Document in project alfresco-remote-api by Alfresco.

the class TestCMIS method testSecondaryTypes.

@Test
public void testSecondaryTypes() throws Exception {
    final TestNetwork network1 = getTestFixture().getRandomNetwork();
    String username = "user" + System.currentTimeMillis();
    PersonInfo personInfo = new PersonInfo(username, username, username, TEST_PASSWORD, null, null, null, null, null, null, null);
    TestPerson person1 = network1.createUser(personInfo);
    String person1Id = person1.getId();
    final String siteName = "site" + System.currentTimeMillis();
    TenantUtil.runAsUserTenant(new TenantRunAsWork<NodeRef>() {

        @Override
        public NodeRef doWork() throws Exception {
            SiteInformation siteInfo = new SiteInformation(siteName, siteName, siteName, SiteVisibility.PRIVATE);
            TestSite site = repoService.createSite(null, siteInfo);
            String name = GUID.generate();
            NodeRef folderNodeRef = repoService.createFolder(site.getContainerNodeRef(DOCUMENT_LIBRARY_CONTAINER_NAME), name);
            return folderNodeRef;
        }
    }, person1Id, network1.getId());
    // Create a document...
    publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1Id));
    CmisSession cmisSession = publicApiClient.createPublicApiCMISSession(Binding.atom, CMIS_VERSION_11);
    Folder docLibrary = (Folder) cmisSession.getObjectByPath("/Sites/" + siteName + "/documentLibrary");
    String name = "mydoc-" + GUID.generate() + ".txt";
    final List<String> secondaryTypes = new ArrayList<String>();
    secondaryTypes.add("P:cm:summarizable");
    Map<String, Object> properties = new HashMap<String, Object>();
    {
        // create a document with 2 aspects
        properties.put(PropertyIds.OBJECT_TYPE_ID, TYPE_CMIS_DOCUMENT);
        properties.put(PropertyIds.SECONDARY_OBJECT_TYPE_IDS, secondaryTypes);
        properties.put("cm:summary", "My summary");
        properties.put(PropertyIds.NAME, name);
    }
    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 = docLibrary.createDocument(properties, fileContent, VersioningState.MAJOR);
    {
        // check that the secondary types and properties are present
        {
            checkSecondaryTypes(doc, Collections.singleton("P:cm:summarizable"), null);
            String summary = (String) doc.getProperty("cm:summary").getFirstValue();
            assertEquals("My summary", summary);
        }
        {
            doc = (Document) cmisSession.getObjectByPath("/Sites/" + siteName + "/documentLibrary/" + name);
            checkSecondaryTypes(doc, Collections.singleton("P:cm:summarizable"), null);
            String summary = (String) doc.getProperty("cm:summary").getFirstValue();
            assertEquals("My summary", summary);
        }
    }
    // update property and check
    {
        properties = new HashMap<String, Object>();
        {
            properties.put("cm:summary", "My updated summary");
        }
        doc.updateProperties(properties);
        {
            doc = (Document) cmisSession.getObjectByPath("/Sites/" + siteName + "/documentLibrary/" + name);
            checkSecondaryTypes(doc, Collections.singleton("P:cm:summarizable"), null);
            String summary = (String) doc.getProperty("cm:summary").getFirstValue();
            assertEquals("My updated summary", summary);
        }
        {
            checkSecondaryTypes(doc, Collections.singleton("P:cm:summarizable"), null);
            String summary = (String) doc.getProperty("cm:summary").getFirstValue();
            assertEquals("My updated summary", summary);
        }
    }
}
Also used : ContentStreamImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.ContentStreamImpl) CmisSession(org.alfresco.rest.api.tests.client.PublicApiClient.CmisSession) HashMap(java.util.HashMap) TestSite(org.alfresco.rest.api.tests.RepoService.TestSite) FileContentWriter(org.alfresco.repo.content.filestore.FileContentWriter) ContentReader(org.alfresco.service.cmr.repository.ContentReader) ArrayList(java.util.ArrayList) 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) CmisUpdateConflictException(org.apache.chemistry.opencmis.commons.exceptions.CmisUpdateConflictException) CmisConstraintException(org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException) CmisPermissionDeniedException(org.apache.chemistry.opencmis.commons.exceptions.CmisPermissionDeniedException) CmisInvalidArgumentException(org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException) PublicApiException(org.alfresco.rest.api.tests.client.PublicApiException) CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) NodeRef(org.alfresco.service.cmr.repository.NodeRef) ContentWriter(org.alfresco.service.cmr.repository.ContentWriter) FileContentWriter(org.alfresco.repo.content.filestore.FileContentWriter) SiteInformation(org.alfresco.rest.api.tests.RepoService.SiteInformation) TestNetwork(org.alfresco.rest.api.tests.RepoService.TestNetwork) FileableCmisObject(org.apache.chemistry.opencmis.client.api.FileableCmisObject) CmisObject(org.apache.chemistry.opencmis.client.api.CmisObject) RequestContext(org.alfresco.rest.api.tests.client.RequestContext) TestPerson(org.alfresco.rest.api.tests.RepoService.TestPerson) VersionableAspectTest(org.alfresco.repo.version.VersionableAspectTest) Test(org.junit.Test)

Example 57 with Document

use of org.apache.chemistry.opencmis.client.api.Document in project alfresco-remote-api by Alfresco.

the class TestCMIS method aPrivateCopyShouldAllowTheAdditionOfAspects_CMIS_1_1_Version.

/**
 * <p>Related to REPO-4613.</p>
 * <p>A checkout should not lock the private working copy.</p>
 * <p>Adding aspects or properties to a pwc should remain possible after a checkout.</p>
 * @throws Exception
 */
@Test
public void aPrivateCopyShouldAllowTheAdditionOfAspects_CMIS_1_1_Version() throws Exception {
    final String aspectName = "P:cm:summarizable";
    final String propertyName = "cm:summary";
    final String propertyValue = "My summary";
    final TestNetwork network1 = getTestFixture().getRandomNetwork();
    String username = "user" + System.currentTimeMillis();
    PersonInfo personInfo = new PersonInfo(username, username, username, TEST_PASSWORD, null, null, null, null, null, null, null);
    TestPerson person1 = network1.createUser(personInfo);
    String person1Id = person1.getId();
    final String siteName = "site" + System.currentTimeMillis();
    TenantUtil.runAsUserTenant(new TenantRunAsWork<NodeRef>() {

        @Override
        public NodeRef doWork() throws Exception {
            SiteInformation siteInfo = new SiteInformation(siteName, siteName, siteName, SiteVisibility.PRIVATE);
            TestSite site = repoService.createSite(null, siteInfo);
            String name = GUID.generate();
            NodeRef folderNodeRef = repoService.createFolder(site.getContainerNodeRef(DOCUMENT_LIBRARY_CONTAINER_NAME), name);
            return folderNodeRef;
        }
    }, person1Id, network1.getId());
    // Create a document...
    publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1Id));
    CmisSession cmisSession = publicApiClient.createPublicApiCMISSession(Binding.atom, CMIS_VERSION_11);
    Folder folder = (Folder) cmisSession.getObjectByPath(String.format(DOCUMENT_LIBRARY_PATH_PATTERN, siteName));
    String fileName = String.format(TEST_DOCUMENT_NAME_PATTERN, GUID.generate());
    // Create a document...
    publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1Id));
    HashMap<String, Object> props = new HashMap<>();
    props.put(PropertyIds.OBJECT_TYPE_ID, TYPE_CMIS_DOCUMENT);
    props.put(PropertyIds.NAME, fileName);
    final ContentStream cs = new ContentStreamImpl(fileName, "text/plain", "This is just a test");
    final Document document = folder.createDocument(props, cs, VersioningState.MAJOR);
    ObjectId pwcObjectId = document.checkOut();
    CmisObject cmisObject = cmisSession.getObject(pwcObjectId.getId());
    final Document pwc = (Document) cmisObject;
    List<Object> aspects = pwc.getProperty(PropertyIds.SECONDARY_OBJECT_TYPE_IDS).getValues();
    // asserts that we have the right aspect for the private working copy
    assertTrue(aspects.contains("P:cm:workingcopy"));
    aspects.add(aspectName);
    props = new HashMap<>();
    props.put(PropertyIds.SECONDARY_OBJECT_TYPE_IDS, aspects);
    props.put(propertyName, propertyValue);
    pwc.updateProperties(props);
    final ObjectId id = pwc.checkIn(true, null, null, "CheckIn comment");
    Document checkedInDocument = (Document) cmisSession.getObject(id.getId());
    List<String> secondaryTypeIds = checkedInDocument.getPropertyValue(PropertyIds.SECONDARY_OBJECT_TYPE_IDS);
    // asserts the new aspect has been added to the original copy, via the check in from the private copy
    assertTrue(secondaryTypeIds.contains(aspectName));
    assertEquals(checkedInDocument.getPropertyValue(propertyName), propertyValue);
}
Also used : ContentStreamImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.ContentStreamImpl) CmisSession(org.alfresco.rest.api.tests.client.PublicApiClient.CmisSession) HashMap(java.util.HashMap) ObjectId(org.apache.chemistry.opencmis.client.api.ObjectId) TestSite(org.alfresco.rest.api.tests.RepoService.TestSite) 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) CmisUpdateConflictException(org.apache.chemistry.opencmis.commons.exceptions.CmisUpdateConflictException) CmisConstraintException(org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException) CmisPermissionDeniedException(org.apache.chemistry.opencmis.commons.exceptions.CmisPermissionDeniedException) CmisInvalidArgumentException(org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException) PublicApiException(org.alfresco.rest.api.tests.client.PublicApiException) CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) NodeRef(org.alfresco.service.cmr.repository.NodeRef) ContentStream(org.apache.chemistry.opencmis.commons.data.ContentStream) SiteInformation(org.alfresco.rest.api.tests.RepoService.SiteInformation) TestNetwork(org.alfresco.rest.api.tests.RepoService.TestNetwork) FileableCmisObject(org.apache.chemistry.opencmis.client.api.FileableCmisObject) CmisObject(org.apache.chemistry.opencmis.client.api.CmisObject) FileableCmisObject(org.apache.chemistry.opencmis.client.api.FileableCmisObject) CmisObject(org.apache.chemistry.opencmis.client.api.CmisObject) RequestContext(org.alfresco.rest.api.tests.client.RequestContext) TestPerson(org.alfresco.rest.api.tests.RepoService.TestPerson) VersionableAspectTest(org.alfresco.repo.version.VersionableAspectTest) Test(org.junit.Test)

Example 58 with Document

use of org.apache.chemistry.opencmis.client.api.Document in project alfresco-remote-api by Alfresco.

the class TestCMIS method testMNT_10687.

/* MNT-10687 related test - appendContent to PWC CMIS 1.1 */
@Test
public void testMNT_10687() throws Exception {
    final TestNetwork network1 = getTestFixture().getRandomNetwork();
    String username = "user" + System.currentTimeMillis();
    PersonInfo personInfo = new PersonInfo(username, username, username, TEST_PASSWORD, null, null, null, null, null, null, null);
    TestPerson person1 = network1.createUser(personInfo);
    String person1Id = person1.getId();
    final String siteName = "site" + System.currentTimeMillis();
    TenantUtil.runAsUserTenant(new TenantRunAsWork<NodeRef>() {

        @Override
        public NodeRef doWork() throws Exception {
            SiteInformation siteInfo = new SiteInformation(siteName, siteName, siteName, SiteVisibility.PRIVATE);
            TestSite site = repoService.createSite(null, siteInfo);
            String name = GUID.generate();
            NodeRef folderNodeRef = repoService.createFolder(site.getContainerNodeRef(DOCUMENT_LIBRARY_CONTAINER_NAME), name);
            return folderNodeRef;
        }
    }, person1Id, network1.getId());
    // Create a document...
    publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1Id));
    CmisSession cmisSession = publicApiClient.createPublicApiCMISSession(Binding.atom, CMIS_VERSION_11);
    Folder docLibrary = (Folder) cmisSession.getObjectByPath("/Sites/" + siteName + "/documentLibrary");
    String name = "mydoc-" + GUID.generate() + ".txt";
    Map<String, Object> properties = new HashMap<String, Object>();
    {
        properties.put(PropertyIds.OBJECT_TYPE_ID, TYPE_CMIS_DOCUMENT);
        properties.put(PropertyIds.NAME, name);
    }
    ContentStreamImpl fileContent = new ContentStreamImpl();
    {
        ContentWriter writer = new FileContentWriter(TempFileProvider.createTempFile(GUID.generate(), ".txt"));
        writer.putContent("Ipsum");
        ContentReader reader = writer.getReader();
        fileContent.setMimeType(MimetypeMap.MIMETYPE_TEXT_PLAIN);
        fileContent.setStream(reader.getContentInputStream());
    }
    /* Create document */
    Document doc = docLibrary.createDocument(properties, fileContent, VersioningState.MAJOR);
    /* Checkout document */
    ObjectId pwcId = doc.checkOut();
    Document pwc = (Document) cmisSession.getObject(pwcId.getId());
    /* append content to PWC */
    fileContent = new ContentStreamImpl();
    {
        ContentWriter writer = new FileContentWriter(TempFileProvider.createTempFile(GUID.generate(), ".txt"));
        writer.putContent(" and so on");
        ContentReader reader = writer.getReader();
        fileContent.setMimeType(MimetypeMap.MIMETYPE_TEXT_PLAIN);
        fileContent.setStream(reader.getContentInputStream());
    }
    pwc.appendContentStream(fileContent, true);
    pwc.checkIn(false, null, null, "Check In");
    ContentStream contentStream = doc.getObjectOfLatestVersion(false).getContentStream();
    InputStream in = contentStream.getStream();
    StringWriter writer = new StringWriter();
    IOUtils.copy(in, writer, "UTF-8");
    String content = writer.toString();
    assertEquals("Ipsum and so on", content);
}
Also used : ContentStreamImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.ContentStreamImpl) HashMap(java.util.HashMap) 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) ContentStream(org.apache.chemistry.opencmis.commons.data.ContentStream) StringWriter(java.io.StringWriter) SiteInformation(org.alfresco.rest.api.tests.RepoService.SiteInformation) RequestContext(org.alfresco.rest.api.tests.client.RequestContext) CmisSession(org.alfresco.rest.api.tests.client.PublicApiClient.CmisSession) ObjectId(org.apache.chemistry.opencmis.client.api.ObjectId) TestSite(org.alfresco.rest.api.tests.RepoService.TestSite) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) FileContentWriter(org.alfresco.repo.content.filestore.FileContentWriter) ContentReader(org.alfresco.service.cmr.repository.ContentReader) CmisUpdateConflictException(org.apache.chemistry.opencmis.commons.exceptions.CmisUpdateConflictException) CmisConstraintException(org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException) CmisPermissionDeniedException(org.apache.chemistry.opencmis.commons.exceptions.CmisPermissionDeniedException) CmisInvalidArgumentException(org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException) PublicApiException(org.alfresco.rest.api.tests.client.PublicApiException) CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) ContentWriter(org.alfresco.service.cmr.repository.ContentWriter) FileContentWriter(org.alfresco.repo.content.filestore.FileContentWriter) TestNetwork(org.alfresco.rest.api.tests.RepoService.TestNetwork) FileableCmisObject(org.apache.chemistry.opencmis.client.api.FileableCmisObject) CmisObject(org.apache.chemistry.opencmis.client.api.CmisObject) TestPerson(org.alfresco.rest.api.tests.RepoService.TestPerson) VersionableAspectTest(org.alfresco.repo.version.VersionableAspectTest) Test(org.junit.Test)

Example 59 with Document

use of org.apache.chemistry.opencmis.client.api.Document 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 60 with Document

use of org.apache.chemistry.opencmis.client.api.Document in project alfresco-remote-api by Alfresco.

the class TestCMIS method testAspects.

@Test
@Ignore("Quarantined since 24 Sep 2018. TestCMIS.testAspects:1546->checkSecondaryTypes:492 Missing secondary types: [P:cm:titled, P:sys:localized]")
public void testAspects() throws Exception {
    final TestNetwork network1 = getTestFixture().getRandomNetwork();
    String username = "user" + System.currentTimeMillis();
    PersonInfo personInfo = new PersonInfo(username, username, username, TEST_PASSWORD, null, null, null, null, null, null, null);
    TestPerson person1 = network1.createUser(personInfo);
    String person1Id = person1.getId();
    final List<NodeRef> folders = new ArrayList<NodeRef>();
    final List<NodeRef> documents = new ArrayList<NodeRef>();
    TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>() {

        @Override
        public Void doWork() throws Exception {
            String siteName = "site" + System.currentTimeMillis();
            SiteInformation siteInfo = new SiteInformation(siteName, siteName, siteName, SiteVisibility.PRIVATE);
            TestSite site = repoService.createSite(null, siteInfo);
            String name = GUID.generate();
            NodeRef folderNodeRef = repoService.createFolder(site.getContainerNodeRef(DOCUMENT_LIBRARY_CONTAINER_NAME), name);
            folders.add(folderNodeRef);
            for (int i = 0; i < 3; i++) {
                name = GUID.generate();
                NodeRef docNodeRef = repoService.createDocument(folderNodeRef, name, "test content");
                assertFalse(repoService.getAspects(docNodeRef).contains(ContentModel.ASPECT_TITLED));
                documents.add(docNodeRef);
            }
            return null;
        }
    }, person1Id, network1.getId());
    final NodeRef doc1NodeRef = documents.get(0);
    final NodeRef doc2NodeRef = documents.get(1);
    final NodeRef doc3NodeRef = documents.get(2);
    publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1Id));
    CmisSession atomCmisSession10 = publicApiClient.createPublicApiCMISSession(Binding.atom, CMIS_VERSION_10, AlfrescoObjectFactoryImpl.class.getName());
    CmisSession atomCmisSession11 = publicApiClient.createPublicApiCMISSession(Binding.atom, CMIS_VERSION_11);
    CmisSession browserCmisSession11 = publicApiClient.createPublicApiCMISSession(Binding.browser, CMIS_VERSION_11);
    // Test that adding aspects works for both 1.0 and 1.1
    // 1.0
    {
        AlfrescoDocument doc = (AlfrescoDocument) atomCmisSession10.getObject(doc1NodeRef.getId());
        doc = (AlfrescoDocument) doc.addAspect("P:cm:titled");
        TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>() {

            @Override
            public Void doWork() throws Exception {
                Set<QName> aspects = repoService.getAspects(doc1NodeRef);
                assertTrue("Missing aspect in current set " + aspects, aspects.contains(ContentModel.ASPECT_TITLED));
                return null;
            }
        }, person1Id, network1.getId());
        doc.removeAspect("P:cm:titled");
        TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>() {

            @Override
            public Void doWork() throws Exception {
                Set<QName> aspects = repoService.getAspects(doc1NodeRef);
                assertFalse("Unexpected aspect in current set " + aspects, aspects.contains(ContentModel.ASPECT_TITLED));
                return null;
            }
        }, person1Id, network1.getId());
    }
    // 1.1 atom (secondary types)
    {
        final Document doc = (Document) atomCmisSession11.getObject(doc2NodeRef.getId());
        final List<SecondaryType> secondaryTypesList = doc.getSecondaryTypes();
        final List<String> secondaryTypes = new ArrayList<String>();
        if (secondaryTypesList != null) {
            for (SecondaryType secondaryType : secondaryTypesList) {
                secondaryTypes.add(secondaryType.getId());
            }
        }
        secondaryTypes.add("P:sys:temporary");
        secondaryTypes.add("P:cm:titled");
        Map<String, Object> properties = new HashMap<String, Object>();
        {
            // create a document with 2 secondary types
            properties.put(PropertyIds.SECONDARY_OBJECT_TYPE_IDS, secondaryTypes);
        }
        Document doc1 = (Document) doc.updateProperties(properties);
        checkSecondaryTypes(doc1, new HashSet<String>(Arrays.asList(new String[] { "P:sys:temporary", "P:cm:titled" })), null);
        TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>() {

            @Override
            public Void doWork() throws Exception {
                Set<QName> aspects = repoService.getAspects(doc2NodeRef);
                assertTrue("Missing aspects in current set " + aspects, aspects.contains(ContentModel.ASPECT_TITLED));
                assertTrue("Missing aspects in current set " + aspects, aspects.contains(ContentModel.ASPECT_TEMPORARY));
                return null;
            }
        }, person1Id, network1.getId());
        secondaryTypes.add("P:cm:author");
        properties = new HashMap<String, Object>();
        {
            // create a document with 2 secondary types
            properties.put(PropertyIds.SECONDARY_OBJECT_TYPE_IDS, secondaryTypes);
        }
        Document doc2 = (Document) doc1.updateProperties(properties);
        checkSecondaryTypes(doc2, new HashSet<String>(Arrays.asList(new String[] { "P:sys:temporary", "P:cm:titled", "P:cm:author" })), null);
        TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>() {

            @Override
            public Void doWork() throws Exception {
                Set<QName> aspects = repoService.getAspects(doc2NodeRef);
                String title = (String) repoService.getProperty(doc2NodeRef, ContentModel.PROP_TITLE);
                assertTrue("Missing aspects in current set " + aspects, aspects.contains(ContentModel.ASPECT_AUTHOR));
                assertTrue("Missing aspects in current set " + aspects, aspects.contains(ContentModel.ASPECT_TEMPORARY));
                assertTrue("Missing aspects in current set " + aspects, aspects.contains(ContentModel.ASPECT_TITLED));
                assertEquals(null, title);
                return null;
            }
        }, person1Id, network1.getId());
        // remove a secondary type
        secondaryTypes.remove("P:cm:titled");
        properties = new HashMap<String, Object>();
        {
            properties.put(PropertyIds.SECONDARY_OBJECT_TYPE_IDS, secondaryTypes);
        }
        Document doc3 = (Document) doc2.updateProperties(properties);
        checkSecondaryTypes(doc3, new HashSet<String>(Arrays.asList(new String[] { "P:sys:temporary", "P:cm:author" })), new HashSet<String>(Arrays.asList(new String[] { "P:cm:titled" })));
        TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>() {

            @Override
            public Void doWork() throws Exception {
                Set<QName> aspects = repoService.getAspects(doc2NodeRef);
                String title = (String) repoService.getProperty(doc2NodeRef, ContentModel.PROP_TITLE);
                assertTrue("Missing aspects in current set " + aspects, aspects.contains(ContentModel.ASPECT_AUTHOR));
                assertTrue("Missing aspects in current set " + aspects, aspects.contains(ContentModel.ASPECT_TEMPORARY));
                assertFalse("Unexpected aspect in current set " + aspects, aspects.contains(ContentModel.ASPECT_TITLED));
                assertEquals(null, title);
                return null;
            }
        }, person1Id, network1.getId());
    }
    // 1.1 browser (secondary types)
    {
        Document doc = (Document) browserCmisSession11.getObject(doc3NodeRef.getId());
        final List<SecondaryType> secondaryTypesList = doc.getSecondaryTypes();
        final List<String> secondaryTypes = new ArrayList<String>();
        if (secondaryTypesList != null) {
            for (SecondaryType secondaryType : secondaryTypesList) {
                secondaryTypes.add(secondaryType.getId());
            }
        }
        secondaryTypes.add("P:sys:temporary");
        secondaryTypes.add("P:cm:titled");
        Map<String, Object> properties = new HashMap<String, Object>();
        {
            // create a document with 2 secondary types
            properties.put(PropertyIds.SECONDARY_OBJECT_TYPE_IDS, secondaryTypes);
        }
        Document doc1 = (Document) doc.updateProperties(properties);
        checkSecondaryTypes(doc1, new HashSet<String>(Arrays.asList(new String[] { "P:sys:temporary", "P:cm:titled" })), null);
        TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>() {

            @Override
            public Void doWork() throws Exception {
                Set<QName> aspects = repoService.getAspects(doc3NodeRef);
                assertTrue("Missing aspects in current set " + aspects, aspects.contains(ContentModel.ASPECT_TITLED));
                assertTrue("Missing aspects in current set " + aspects, aspects.contains(ContentModel.ASPECT_TEMPORARY));
                return null;
            }
        }, person1Id, network1.getId());
        secondaryTypes.add("P:cm:author");
        properties = new HashMap<String, Object>();
        {
            // create a document with 2 secondary types
            properties.put(PropertyIds.SECONDARY_OBJECT_TYPE_IDS, secondaryTypes);
        }
        Document doc2 = (Document) doc1.updateProperties(properties);
        checkSecondaryTypes(doc2, new HashSet<String>(Arrays.asList(new String[] { "P:sys:temporary", "P:cm:titled", "P:cm:author" })), null);
        TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>() {

            @Override
            public Void doWork() throws Exception {
                Set<QName> aspects = repoService.getAspects(doc3NodeRef);
                assertTrue("Missing aspects in current set " + aspects, aspects.contains(ContentModel.ASPECT_TITLED));
                assertTrue("Missing aspects in current set " + aspects, aspects.contains(ContentModel.ASPECT_TEMPORARY));
                assertTrue("Missing aspects in current set " + aspects, aspects.contains(ContentModel.ASPECT_AUTHOR));
                return null;
            }
        }, person1Id, network1.getId());
        secondaryTypes.remove("P:cm:titled");
        properties = new HashMap<String, Object>();
        {
            // create a document with 2 secondary types
            properties.put(PropertyIds.SECONDARY_OBJECT_TYPE_IDS, secondaryTypes);
        }
        Document doc3 = (Document) doc2.updateProperties(properties);
        checkSecondaryTypes(doc3, new HashSet<String>(Arrays.asList(new String[] { "P:sys:temporary", "P:cm:author" })), new HashSet<String>(Arrays.asList(new String[] { "P:cm:titled" })));
        TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>() {

            @Override
            public Void doWork() throws Exception {
                Set<QName> aspects = repoService.getAspects(doc3NodeRef);
                assertTrue("Missing aspects in current set " + aspects, aspects.contains(ContentModel.ASPECT_AUTHOR));
                assertTrue("Missing aspects in current set " + aspects, aspects.contains(ContentModel.ASPECT_TEMPORARY));
                assertFalse("Unexpected aspect in current set " + aspects, aspects.contains(ContentModel.ASPECT_TITLED));
                return null;
            }
        }, person1Id, network1.getId());
    }
}
Also used : AlfrescoDocument(org.alfresco.cmis.client.AlfrescoDocument) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) AlfrescoDocument(org.alfresco.cmis.client.AlfrescoDocument) Document(org.apache.chemistry.opencmis.client.api.Document) NodeRef(org.alfresco.service.cmr.repository.NodeRef) SiteInformation(org.alfresco.rest.api.tests.RepoService.SiteInformation) ArrayList(java.util.ArrayList) AbstractList(java.util.AbstractList) List(java.util.List) RequestContext(org.alfresco.rest.api.tests.client.RequestContext) HashSet(java.util.HashSet) AlfrescoObjectFactoryImpl(org.alfresco.cmis.client.impl.AlfrescoObjectFactoryImpl) CmisSession(org.alfresco.rest.api.tests.client.PublicApiClient.CmisSession) SecondaryType(org.apache.chemistry.opencmis.client.api.SecondaryType) TestSite(org.alfresco.rest.api.tests.RepoService.TestSite) QName(org.alfresco.service.namespace.QName) CmisUpdateConflictException(org.apache.chemistry.opencmis.commons.exceptions.CmisUpdateConflictException) CmisConstraintException(org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException) CmisPermissionDeniedException(org.apache.chemistry.opencmis.commons.exceptions.CmisPermissionDeniedException) CmisInvalidArgumentException(org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException) PublicApiException(org.alfresco.rest.api.tests.client.PublicApiException) CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) TenantRunAsWork(org.alfresco.repo.tenant.TenantUtil.TenantRunAsWork) TestNetwork(org.alfresco.rest.api.tests.RepoService.TestNetwork) FileableCmisObject(org.apache.chemistry.opencmis.client.api.FileableCmisObject) CmisObject(org.apache.chemistry.opencmis.client.api.CmisObject) TestPerson(org.alfresco.rest.api.tests.RepoService.TestPerson) Map(java.util.Map) MimetypeMap(org.alfresco.repo.content.MimetypeMap) HashMap(java.util.HashMap) Ignore(org.junit.Ignore) VersionableAspectTest(org.alfresco.repo.version.VersionableAspectTest) Test(org.junit.Test)

Aggregations

Document (org.apache.chemistry.opencmis.client.api.Document)110 Folder (org.apache.chemistry.opencmis.client.api.Folder)64 HashMap (java.util.HashMap)43 CmisObject (org.apache.chemistry.opencmis.client.api.CmisObject)43 CmisTestResult (org.apache.chemistry.opencmis.tck.CmisTestResult)40 ContentStream (org.apache.chemistry.opencmis.commons.data.ContentStream)37 ContentStreamImpl (org.apache.chemistry.opencmis.commons.impl.dataobjects.ContentStreamImpl)32 CmisObjectNotFoundException (org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException)29 ByteArrayInputStream (java.io.ByteArrayInputStream)27 ObjectId (org.apache.chemistry.opencmis.client.api.ObjectId)25 DocumentTypeDefinition (org.apache.chemistry.opencmis.commons.definitions.DocumentTypeDefinition)23 CmisConstraintException (org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException)21 CmisInvalidArgumentException (org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException)20 IOException (java.io.IOException)19 InputStream (java.io.InputStream)19 ArrayList (java.util.ArrayList)19 Session (org.apache.chemistry.opencmis.client.api.Session)19 CmisPermissionDeniedException (org.apache.chemistry.opencmis.commons.exceptions.CmisPermissionDeniedException)19 Test (org.junit.Test)19 NodeRef (org.alfresco.service.cmr.repository.NodeRef)17