Search in sources :

Example 1 with SecondaryType

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

the class TestCMIS method checkSecondaryTypes.

private void checkSecondaryTypes(Document doc, Set<String> expectedSecondaryTypes, Set<String> expectedMissingSecondaryTypes) {
    final List<SecondaryType> secondaryTypesList = doc.getSecondaryTypes();
    assertNotNull(secondaryTypesList);
    List<String> secondaryTypes = new AbstractList<String>() {

        @Override
        public String get(int index) {
            SecondaryType type = secondaryTypesList.get(index);
            return type.getId();
        }

        @Override
        public int size() {
            return secondaryTypesList.size();
        }
    };
    if (expectedSecondaryTypes != null) {
        assertTrue("Missing secondary types: " + secondaryTypes, secondaryTypes.containsAll(expectedSecondaryTypes));
    }
    if (expectedMissingSecondaryTypes != null) {
        assertTrue("Expected missing secondary types but at least one is still present: " + secondaryTypes, !secondaryTypes.containsAll(expectedMissingSecondaryTypes));
    }
}
Also used : AbstractList(java.util.AbstractList) SecondaryType(org.apache.chemistry.opencmis.client.api.SecondaryType)

Example 2 with SecondaryType

use of org.apache.chemistry.opencmis.client.api.SecondaryType in project copper-cms by PogeyanOSS.

the class SecondaryTypesTest method checkSecondaryType.

private boolean checkSecondaryType(Document doc, ObjectType secondaryTestType) {
    CmisTestResult f;
    // check if the secondary type is there
    boolean found = false;
    if (doc.getSecondaryTypes() == null) {
        addResult(createResult(FAILURE, "Document does not have the attached secondary type!"));
    } else {
        for (SecondaryType secType : doc.getSecondaryTypes()) {
            if (secondaryTestType.getId().equals(secType.getId())) {
                found = true;
                break;
            }
        }
        f = createResult(FAILURE, "Document does not have the attached secondary type!");
        addResult(assertIsTrue(found, null, f));
    }
    // check properties of secondary type
    if (found) {
        Set<String> secondaryTypeProperties = new HashSet<String>();
        if (secondaryTestType.getPropertyDefinitions() != null) {
            for (PropertyDefinition<?> propDef : secondaryTestType.getPropertyDefinitions().values()) {
                secondaryTypeProperties.add(propDef.getId());
            }
        }
        for (Property<?> prop : doc.getProperties()) {
            secondaryTypeProperties.remove(prop.getId());
        }
        f = createResult(FAILURE, "Documents lacks the following secondary type properties: " + secondaryTypeProperties);
        addResult(assertIsTrue(secondaryTypeProperties.isEmpty(), null, f));
    }
    return found;
}
Also used : SecondaryType(org.apache.chemistry.opencmis.client.api.SecondaryType) CmisTestResult(org.apache.chemistry.opencmis.tck.CmisTestResult) HashSet(java.util.HashSet)

Example 3 with SecondaryType

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

the class TestCMIS method testAspects.

@Test
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) VersionableAspectTest(org.alfresco.repo.version.VersionableAspectTest) Test(org.junit.Test)

Example 4 with SecondaryType

use of org.apache.chemistry.opencmis.client.api.SecondaryType in project copper-cms by PogeyanOSS.

the class SecondaryTypesTest method createDocumentAndAttachSecondaryType.

private void createDocumentAndAttachSecondaryType(Session session, Folder testFolder, ObjectType secondaryTestType) {
    Document doc = createDocument(session, testFolder, "createandattach.txt", "Secondary Type Test");
    Document workDoc = doc;
    try {
        // test if check out is required
        boolean checkedout = false;
        if (needsCheckOut(doc)) {
            workDoc = (Document) session.getObject(doc.checkOut(), SELECT_ALL_NO_CACHE_OC);
            checkedout = true;
        }
        // -- attach secondary type
        List<String> secondaryTypes = new ArrayList<String>();
        // copy already attached secondary types, if there are any
        if (workDoc.getSecondaryTypes() != null) {
            for (SecondaryType secType : workDoc.getSecondaryTypes()) {
                secondaryTypes.add(secType.getId());
            }
        }
        // add the new secondary type
        secondaryTypes.add(secondaryTestType.getId());
        Map<String, Object> properties = new HashMap<String, Object>();
        properties.put(PropertyIds.SECONDARY_OBJECT_TYPE_IDS, secondaryTypes);
        // attach secondary type
        ObjectId newId = workDoc.updateProperties(properties);
        Document newDoc = (Document) session.getObject(newId, SELECT_ALL_NO_CACHE_OC);
        // check if the secondary type is there
        boolean found = checkSecondaryType(newDoc, secondaryTestType);
        // -- detach secondary type
        if (found) {
            detachSecondaryType(session, newDoc, secondaryTestType);
        }
        // cancel a possible check out
        if (checkedout) {
            workDoc.cancelCheckOut();
        }
    } finally {
        deleteObject(doc);
    }
}
Also used : SecondaryType(org.apache.chemistry.opencmis.client.api.SecondaryType) HashMap(java.util.HashMap) ObjectId(org.apache.chemistry.opencmis.client.api.ObjectId) ArrayList(java.util.ArrayList) Document(org.apache.chemistry.opencmis.client.api.Document)

Example 5 with SecondaryType

use of org.apache.chemistry.opencmis.client.api.SecondaryType in project copper-cms by PogeyanOSS.

the class SecondaryTypesTest method detachSecondaryType.

private void detachSecondaryType(Session session, Document doc, ObjectType secondaryTestType) {
    CmisTestResult f;
    List<String> secondaryTypesId = new ArrayList<String>();
    for (SecondaryType secType : doc.getSecondaryTypes()) {
        if (!secondaryTestType.getId().equals(secType.getId())) {
            secondaryTypesId.add(secType.getId());
        }
    }
    Map<String, Object> properties = new HashMap<String, Object>();
    properties.put(PropertyIds.SECONDARY_OBJECT_TYPE_IDS, secondaryTypesId);
    // detach secondary type
    ObjectId newId = doc.updateProperties(properties);
    Document newDoc = (Document) session.getObject(newId, SELECT_ALL_NO_CACHE_OC);
    boolean found = false;
    if (newDoc.getSecondaryTypes() != null) {
        for (SecondaryType secType : newDoc.getSecondaryTypes()) {
            if (secondaryTestType.getId().equals(secType.getId())) {
                found = true;
                break;
            }
        }
    }
    f = createResult(FAILURE, "Document still has the detached secondary type!");
    addResult(assertIsFalse(found, null, f));
    // check properties
    ObjectType primaryType = newDoc.getType();
    List<SecondaryType> secondaryTypes = newDoc.getSecondaryTypes();
    for (Property<?> prop : doc.getProperties()) {
        if (!primaryType.getPropertyDefinitions().containsKey(prop.getId())) {
            f = createResult(FAILURE, "Property '" + prop.getId() + "' is neither defined by the primary type nor by a secondary type!");
            if (secondaryTypes == null) {
                addResult(f);
            } else {
                boolean foundProperty = false;
                for (SecondaryType secondaryType : secondaryTypes) {
                    if (secondaryType.getPropertyDefinitions() != null && secondaryType.getPropertyDefinitions().containsKey(prop.getId())) {
                        foundProperty = true;
                        break;
                    }
                }
                addResult(assertIsTrue(foundProperty, null, f));
            }
        }
    }
}
Also used : SecondaryType(org.apache.chemistry.opencmis.client.api.SecondaryType) HashMap(java.util.HashMap) ObjectId(org.apache.chemistry.opencmis.client.api.ObjectId) ArrayList(java.util.ArrayList) Document(org.apache.chemistry.opencmis.client.api.Document) ObjectType(org.apache.chemistry.opencmis.client.api.ObjectType) CmisTestResult(org.apache.chemistry.opencmis.tck.CmisTestResult)

Aggregations

SecondaryType (org.apache.chemistry.opencmis.client.api.SecondaryType)5 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 Document (org.apache.chemistry.opencmis.client.api.Document)3 AbstractList (java.util.AbstractList)2 HashSet (java.util.HashSet)2 ObjectId (org.apache.chemistry.opencmis.client.api.ObjectId)2 CmisTestResult (org.apache.chemistry.opencmis.tck.CmisTestResult)2 List (java.util.List)1 Map (java.util.Map)1 AlfrescoDocument (org.alfresco.cmis.client.AlfrescoDocument)1 AlfrescoObjectFactoryImpl (org.alfresco.cmis.client.impl.AlfrescoObjectFactoryImpl)1 MimetypeMap (org.alfresco.repo.content.MimetypeMap)1 TenantRunAsWork (org.alfresco.repo.tenant.TenantUtil.TenantRunAsWork)1 VersionableAspectTest (org.alfresco.repo.version.VersionableAspectTest)1 SiteInformation (org.alfresco.rest.api.tests.RepoService.SiteInformation)1 TestNetwork (org.alfresco.rest.api.tests.RepoService.TestNetwork)1 TestPerson (org.alfresco.rest.api.tests.RepoService.TestPerson)1 TestSite (org.alfresco.rest.api.tests.RepoService.TestSite)1 CmisSession (org.alfresco.rest.api.tests.client.PublicApiClient.CmisSession)1