Search in sources :

Example 6 with CmisService

use of org.apache.chemistry.opencmis.commons.server.CmisService in project alfresco-repository by Alfresco.

the class CMISTest method testLastVersionOfVersionSeries.

/**
 * Test to ensure that set of aspect returned by cmisService#getAllVersions for latest version is the same
 * as for the object returned by cmisService#getObjectByPath.
 *
 * See <a href="https://issues.alfresco.com/jira/browse/MNT-9557">MNT-9557</a>
 */
@Test
public void testLastVersionOfVersionSeries() {
    CallContext context = new SimpleCallContext("admin", "admin", CmisVersion.CMIS_1_0);
    AuthenticationUtil.pushAuthentication();
    AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
    final String FOLDER = "testUpdatePropertiesSetDeleteContentVersioning-" + GUID.generate(), DOC = "documentProperties-" + GUID.generate();
    try {
        final NodeRef nodeRef = transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<NodeRef>() {

            @Override
            public NodeRef execute() throws Throwable {
                // create folder
                FileInfo folderInfo = fileFolderService.create(repositoryHelper.getCompanyHome(), FOLDER, ContentModel.TYPE_FOLDER);
                nodeService.setProperty(folderInfo.getNodeRef(), ContentModel.PROP_NAME, FOLDER);
                assertNotNull(folderInfo);
                // create documents
                FileInfo document = fileFolderService.create(folderInfo.getNodeRef(), DOC, ContentModel.TYPE_CONTENT);
                nodeService.setProperty(document.getNodeRef(), ContentModel.PROP_NAME, DOC);
                nodeService.setProperty(document.getNodeRef(), ContentModel.PROP_DESCRIPTION, "Initial doc");
                return document.getNodeRef();
            }
        });
        transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Void>() {

            @Override
            public Void execute() throws Throwable {
                // make sure that there is no version history yet
                assertNull(versionService.getVersionHistory(nodeRef));
                // create a version
                // turn off auto-versioning
                Map<QName, Serializable> props = new HashMap<QName, Serializable>();
                props.put(ContentModel.PROP_INITIAL_VERSION, false);
                props.put(ContentModel.PROP_AUTO_VERSION, false);
                props.put(ContentModel.PROP_AUTO_VERSION_PROPS, false);
                versionService.ensureVersioningEnabled(nodeRef, props);
                return null;
            }
        });
        transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Void>() {

            @Override
            public Void execute() throws Throwable {
                assertNotNull(versionService.getVersionHistory(nodeRef));
                // create another one version
                versionService.createVersion(nodeRef, null);
                return null;
            }
        });
        final String NEW_DOC_NAME = transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<String>() {

            @Override
            public String execute() throws Throwable {
                // add aspect to the node
                String newDocName = DOC + GUID.generate();
                nodeService.addAspect(nodeRef, ContentModel.ASPECT_AUTHOR, null);
                nodeService.setProperty(nodeRef, ContentModel.PROP_NAME, newDocName);
                return newDocName;
            }
        });
        CmisService cmisService = factory.getService(context);
        String repositoryId = cmisService.getRepositoryInfos(null).get(0).getId();
        List<ObjectData> versions = cmisService.getAllVersions(repositoryId, nodeRef.toString(), null, null, null, null);
        assertNotNull(versions);
        // get the latest version
        ObjectData latestVersion = versions.get(0);
        // get the object
        ObjectData object = // cmisService.getObjectOfLatestVersion(repositoryId, nodeRef.toString(), null, false, null, null, null, null, false, false, null);
        cmisService.getObjectByPath(repositoryId, "/" + FOLDER + "/" + NEW_DOC_NAME, null, null, null, null, false, false, null);
        assertNotNull(latestVersion);
        assertNotNull(object);
        Object objectDescriptionString = object.getProperties().getProperties().get("cmis:name").getValues().get(0);
        Object latestVersionDescriptionString = latestVersion.getProperties().getProperties().get("cmis:name").getValues().get(0);
        // ensure that node and latest version both have same description
        assertEquals(objectDescriptionString, latestVersionDescriptionString);
        Set<String> documentAspects = new HashSet<String>();
        for (CmisExtensionElement cmisEE : object.getProperties().getExtensions().get(0).getChildren()) {
            documentAspects.add(cmisEE.getValue());
        }
        Set<String> latestVersionAspects = new HashSet<String>();
        for (CmisExtensionElement cmisEE : latestVersion.getProperties().getExtensions().get(0).getChildren()) {
            latestVersionAspects.add(cmisEE.getValue());
        }
        // ensure that node and latest version both have the same set of aspects
        assertEquals(latestVersionAspects, documentAspects);
    } finally {
        AuthenticationUtil.popAuthentication();
    }
}
Also used : Serializable(java.io.Serializable) QName(org.alfresco.service.namespace.QName) ObjectData(org.apache.chemistry.opencmis.commons.data.ObjectData) CallContext(org.apache.chemistry.opencmis.commons.server.CallContext) NodeRef(org.alfresco.service.cmr.repository.NodeRef) CmisExtensionElement(org.apache.chemistry.opencmis.commons.data.CmisExtensionElement) FileInfo(org.alfresco.service.cmr.model.FileInfo) CmisService(org.apache.chemistry.opencmis.commons.server.CmisService) UnfileObject(org.apache.chemistry.opencmis.commons.enums.UnfileObject) Map(java.util.Map) MimetypeMap(org.alfresco.repo.content.MimetypeMap) HashMap(java.util.HashMap) HashSet(java.util.HashSet) VersionableAspectTest(org.alfresco.repo.version.VersionableAspectTest) Test(org.junit.Test)

Example 7 with CmisService

use of org.apache.chemistry.opencmis.commons.server.CmisService in project alfresco-repository by Alfresco.

the class CMISTest method testUpdatePropertiesSetDeleteContentVersioning.

/**
 * Test to ensure auto version behavior for update properties, set and delete content using both Alfresco and CMIS perspectives.
 * Testing different combinations of <b>cm:initialVersion</b>, <b>cm:autoVersion</b> and <b>cm:autoVersionOnUpdateProps</b> properties
 * <br>
 * OnUpdateProperties MINOR version should be created if <b>cm:initialVersion</b> and <b>cm:autoVersionOnUpdateProps</b> are both TRUE
 * <br>
 * OnContentUpdate MINOR version should be created if <b>cm:initialVersion</b> and <b>cm:autoVersion</b> are both TRUE
 *
 * @throws Exception
 */
@Test
public void testUpdatePropertiesSetDeleteContentVersioning() throws Exception {
    AuthenticationUtil.pushAuthentication();
    AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
    final String FOLDER = "testUpdatePropertiesSetDeleteContentVersioning-" + GUID.generate();
    final String DOC1 = "documentProperties1-" + GUID.generate();
    final String DOC2 = "documentProperties2-" + GUID.generate();
    final String DOC3 = "documentProperties3-" + GUID.generate();
    final String DOC4 = "documentProperties4-" + GUID.generate();
    try {
        final List<FileInfo> docs = transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<List<FileInfo>>() {

            @Override
            public List<FileInfo> execute() throws Throwable {
                // create folder
                FileInfo folderInfo = fileFolderService.create(repositoryHelper.getCompanyHome(), FOLDER, ContentModel.TYPE_FOLDER);
                nodeService.setProperty(folderInfo.getNodeRef(), ContentModel.PROP_NAME, FOLDER);
                assertNotNull(folderInfo);
                FileInfo document;
                List<FileInfo> docs = new ArrayList<FileInfo>();
                // create documents
                document = fileFolderService.create(folderInfo.getNodeRef(), DOC1, ContentModel.TYPE_CONTENT);
                nodeService.setProperty(document.getNodeRef(), ContentModel.PROP_NAME, DOC1);
                docs.add(document);
                document = fileFolderService.create(folderInfo.getNodeRef(), DOC2, ContentModel.TYPE_CONTENT);
                nodeService.setProperty(document.getNodeRef(), ContentModel.PROP_NAME, DOC2);
                docs.add(document);
                document = fileFolderService.create(folderInfo.getNodeRef(), DOC3, ContentModel.TYPE_CONTENT);
                nodeService.setProperty(document.getNodeRef(), ContentModel.PROP_NAME, DOC3);
                docs.add(document);
                document = fileFolderService.create(folderInfo.getNodeRef(), DOC4, ContentModel.TYPE_CONTENT);
                nodeService.setProperty(document.getNodeRef(), ContentModel.PROP_NAME, DOC4);
                docs.add(document);
                Map<QName, Serializable> props = new HashMap<QName, Serializable>();
                props.put(ContentModel.PROP_TITLE, "Initial Title");
                props.put(ContentModel.PROP_DESCRIPTION, "Initial Description");
                for (FileInfo fileInfo : docs) {
                    nodeService.addAspect(fileInfo.getNodeRef(), ContentModel.ASPECT_TITLED, props);
                }
                // apply versionable aspect with properties
                props = new HashMap<QName, Serializable>();
                // ContentModel.PROP_INITIAL_VERSION always true
                props.put(ContentModel.PROP_INITIAL_VERSION, true);
                props.put(ContentModel.PROP_AUTO_VERSION, false);
                props.put(ContentModel.PROP_AUTO_VERSION_PROPS, false);
                versionService.ensureVersioningEnabled(docs.get(0).getNodeRef(), props);
                props.put(ContentModel.PROP_AUTO_VERSION, false);
                props.put(ContentModel.PROP_AUTO_VERSION_PROPS, true);
                versionService.ensureVersioningEnabled(docs.get(1).getNodeRef(), props);
                props.put(ContentModel.PROP_AUTO_VERSION, true);
                props.put(ContentModel.PROP_AUTO_VERSION_PROPS, false);
                versionService.ensureVersioningEnabled(docs.get(2).getNodeRef(), props);
                props.put(ContentModel.PROP_AUTO_VERSION, true);
                props.put(ContentModel.PROP_AUTO_VERSION_PROPS, true);
                versionService.ensureVersioningEnabled(docs.get(3).getNodeRef(), props);
                return docs;
            }
        });
        assertVersions(docs.get(0).getNodeRef(), "1.0", VersionType.MAJOR);
        assertVersions(docs.get(1).getNodeRef(), "1.0", VersionType.MAJOR);
        assertVersions(docs.get(2).getNodeRef(), "1.0", VersionType.MAJOR);
        assertVersions(docs.get(3).getNodeRef(), "1.0", VersionType.MAJOR);
        // update node properties using Alfresco
        transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<List<Void>>() {

            @Override
            public List<Void> execute() throws Throwable {
                for (FileInfo fileInfo : docs) {
                    Map<QName, Serializable> props = nodeService.getProperties(fileInfo.getNodeRef());
                    props.put(ContentModel.PROP_DESCRIPTION, "description-" + GUID.generate());
                    props.put(ContentModel.PROP_TITLE, "title-" + GUID.generate());
                    nodeService.setProperties(fileInfo.getNodeRef(), props);
                }
                return null;
            }
        });
        assertVersions(docs.get(0).getNodeRef(), "1.0", VersionType.MAJOR);
        assertVersions(docs.get(1).getNodeRef(), "1.1", VersionType.MINOR);
        assertVersions(docs.get(2).getNodeRef(), "1.0", VersionType.MAJOR);
        assertVersions(docs.get(3).getNodeRef(), "1.1", VersionType.MINOR);
        // update properties using CMIS perspective
        final String repositoryId = withCmisService(new CmisServiceCallback<String>() {

            @Override
            public String execute(CmisService cmisService) {
                String repositoryId = cmisService.getRepositoryInfos(null).get(0).getId();
                for (FileInfo fileInfo : docs) {
                    PropertiesImpl properties = new PropertiesImpl();
                    properties.addProperty(new PropertyStringImpl(PropertyIds.DESCRIPTION, "description-" + GUID.generate()));
                    cmisService.updateProperties(repositoryId, new Holder<String>(fileInfo.getNodeRef().toString()), null, properties, null);
                }
                // This extra check was added due to MNT-16641.
                {
                    PropertiesImpl properties = new PropertiesImpl();
                    properties.addProperty(new PropertyStringImpl(PropertyIds.SECONDARY_OBJECT_TYPE_IDS, "P:cm:lockable"));
                    Set<QName> existingAspects = nodeService.getAspects(docs.get(0).getNodeRef());
                    cmisService.updateProperties(repositoryId, new Holder<String>(docs.get(0).getNodeRef().toString()), null, properties, null);
                    Set<QName> updatedAspects = nodeService.getAspects(docs.get(0).getNodeRef());
                    updatedAspects.removeAll(existingAspects);
                    assertEquals(ContentModel.ASPECT_LOCKABLE, updatedAspects.iterator().next());
                }
                return repositoryId;
            }
        }, CmisVersion.CMIS_1_1);
        assertVersions(docs.get(0).getNodeRef(), "1.0", VersionType.MAJOR);
        assertVersions(docs.get(1).getNodeRef(), "1.2", VersionType.MINOR);
        assertVersions(docs.get(2).getNodeRef(), "1.0", VersionType.MAJOR);
        assertVersions(docs.get(3).getNodeRef(), "1.2", VersionType.MINOR);
        // CMIS setContentStream
        withCmisService(new CmisServiceCallback<Void>() {

            @Override
            public Void execute(CmisService cmisService) {
                for (FileInfo fileInfo : docs) {
                    ContentStreamImpl contentStream = new ContentStreamImpl(null, MimetypeMap.MIMETYPE_TEXT_PLAIN, "Content " + GUID.generate());
                    cmisService.setContentStream(repositoryId, new Holder<String>(fileInfo.getNodeRef().toString()), true, null, contentStream, null);
                }
                return null;
            }
        }, CmisVersion.CMIS_1_1);
        assertVersions(docs.get(0).getNodeRef(), "1.0", VersionType.MAJOR);
        assertVersions(docs.get(1).getNodeRef(), "1.2", VersionType.MINOR);
        assertVersions(docs.get(2).getNodeRef(), "1.1", VersionType.MINOR);
        assertVersions(docs.get(3).getNodeRef(), "1.3", VersionType.MINOR);
        // update content using Alfresco
        transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<List<Void>>() {

            @Override
            public List<Void> execute() throws Throwable {
                for (FileInfo fileInfo : docs) {
                    ContentWriter writer = contentService.getWriter(fileInfo.getNodeRef(), ContentModel.PROP_CONTENT, true);
                    writer.putContent("Content " + GUID.generate());
                }
                return null;
            }
        });
        assertVersions(docs.get(0).getNodeRef(), "1.0", VersionType.MAJOR);
        assertVersions(docs.get(1).getNodeRef(), "1.2", VersionType.MINOR);
        assertVersions(docs.get(2).getNodeRef(), "1.2", VersionType.MINOR);
        assertVersions(docs.get(3).getNodeRef(), "1.4", VersionType.MINOR);
        // CMIS deleteContentStream
        withCmisService(new CmisServiceCallback<Void>() {

            @Override
            public Void execute(CmisService cmisService) {
                for (FileInfo fileInfo : docs) {
                    cmisService.deleteContentStream(repositoryId, new Holder<String>(fileInfo.getNodeRef().toString()), null, null);
                }
                return null;
            }
        }, CmisVersion.CMIS_1_1);
        assertVersions(docs.get(0).getNodeRef(), "1.0", VersionType.MAJOR);
        assertVersions(docs.get(1).getNodeRef(), "1.2", VersionType.MINOR);
        assertVersions(docs.get(2).getNodeRef(), "1.3", VersionType.MINOR);
        assertVersions(docs.get(3).getNodeRef(), "1.5", VersionType.MINOR);
    } finally {
        AuthenticationUtil.popAuthentication();
    }
}
Also used : ContentStreamImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.ContentStreamImpl) Serializable(java.io.Serializable) HashMap(java.util.HashMap) FileInfo(org.alfresco.service.cmr.model.FileInfo) PropertyStringImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyStringImpl) ObjectInFolderList(org.apache.chemistry.opencmis.commons.data.ObjectInFolderList) ArrayList(java.util.ArrayList) ObjectList(org.apache.chemistry.opencmis.commons.data.ObjectList) List(java.util.List) PropertiesImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertiesImpl) QName(org.alfresco.service.namespace.QName) Holder(org.apache.chemistry.opencmis.commons.spi.Holder) ContentWriter(org.alfresco.service.cmr.repository.ContentWriter) CmisService(org.apache.chemistry.opencmis.commons.server.CmisService) 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 8 with CmisService

use of org.apache.chemistry.opencmis.commons.server.CmisService in project alfresco-repository by Alfresco.

the class CMISTest method testGetRepositoryInfos.

/**
 * ALF-20389 Test Alfresco cmis stream interceptor that checks content stream for mimetype. Only ContentStreamImpl extensions should take palace.
 */
@Test
public void testGetRepositoryInfos() {
    boolean cmisEx = false;
    List<RepositoryInfo> infoDataList = null;
    try {
        infoDataList = withCmisService(new CmisServiceCallback<List<RepositoryInfo>>() {

            @Override
            public List<RepositoryInfo> execute(CmisService cmisService) {
                ExtensionDataImpl result = new ExtensionDataImpl();
                List<CmisExtensionElement> extensions = new ArrayList<CmisExtensionElement>();
                result.setExtensions(extensions);
                return cmisService.getRepositoryInfos(result);
            }
        });
    } catch (CmisRuntimeException e) {
        cmisEx = true;
    }
    assertNotNull(cmisEx ? "CmisRuntimeException was thrown. Please, take a look on ALF-20389" : "No CMIS repository information was retrieved", infoDataList);
}
Also used : CmisExtensionElement(org.apache.chemistry.opencmis.commons.data.CmisExtensionElement) CmisService(org.apache.chemistry.opencmis.commons.server.CmisService) CmisRuntimeException(org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException) RepositoryInfo(org.apache.chemistry.opencmis.commons.data.RepositoryInfo) ArrayList(java.util.ArrayList) ExtensionDataImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.ExtensionDataImpl) VersionableAspectTest(org.alfresco.repo.version.VersionableAspectTest) Test(org.junit.Test)

Example 9 with CmisService

use of org.apache.chemistry.opencmis.commons.server.CmisService in project alfresco-repository by Alfresco.

the class CMISTest method testACE2904.

/**
 * ACE-2904
 */
@Test
public void testACE2904() {
    // Basic CMIS Types                                                               // Additional types from Content Model
    final String[] types = { "cmis:document", "cmis:relationship", "cmis:folder", "cmis:policy", "cmis:item", "R:cm:replaces", "P:cm:author", "I:cm:cmobject" };
    final String[] displayNames = { "Document", "Relationship", "Folder", "Policy", "Item Type", "Replaces", "Author", "Object" };
    final String[] descriptions = { "Document Type", "Relationship Type", "Folder Type", "Policy Type", "CMIS Item", "Replaces", "Author", "I:cm:cmobject" };
    CmisServiceCallback<String> callback = new CmisServiceCallback<String>() {

        @Override
        public String execute(CmisService cmisService) {
            List<RepositoryInfo> repositories = cmisService.getRepositoryInfos(null);
            assertTrue(repositories.size() > 0);
            RepositoryInfo repo = repositories.get(0);
            String repositoryId = repo.getId();
            for (int i = 0; i < types.length; i++) {
                TypeDefinition def = cmisService.getTypeDefinition(repositoryId, types[i], null);
                assertNotNull("The " + types[i] + " type is not defined", def);
                assertNotNull("The display name is incorrect. Please, refer to ACE-2904.", def.getDisplayName());
                assertEquals("The display name is incorrect. Please, refer to ACE-2904.", def.getDisplayName(), displayNames[i]);
                assertEquals("The description is incorrect. Please, refer to ACE-2904.", def.getDescription(), descriptions[i]);
                for (PropertyDefinition<?> property : def.getPropertyDefinitions().values()) {
                    assertNotNull("Property definition dispaly name is incorrect. Please, refer to ACE-2904.", property.getDisplayName());
                    assertNotNull("Property definition description is incorrect. Please, refer to ACE-2904.", property.getDescription());
                }
            }
            return "";
        }
    };
    // Lets test types for cmis 1.1 and cmis 1.0
    withCmisService(callback, CmisVersion.CMIS_1_1);
    withCmisService(callback, CmisVersion.CMIS_1_0);
}
Also used : CmisService(org.apache.chemistry.opencmis.commons.server.CmisService) RepositoryInfo(org.apache.chemistry.opencmis.commons.data.RepositoryInfo) TypeDefinition(org.apache.chemistry.opencmis.commons.definitions.TypeDefinition) VersionableAspectTest(org.alfresco.repo.version.VersionableAspectTest) Test(org.junit.Test)

Example 10 with CmisService

use of org.apache.chemistry.opencmis.commons.server.CmisService in project alfresco-repository by Alfresco.

the class CMISTest method testRemoveACL.

/**
 * MNT-10165: Check that all concomitant basic CMIS permissions are deleted
 * when permission is deleted vai CMIS 1.1 API. For Atom binding it applies
 * new set of permissions instead of deleting the old ones.
 */
@Test
public void testRemoveACL() throws Exception {
    AuthenticationUtil.pushAuthentication();
    AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
    final String groupName = "group" + GUID.generate();
    final String testGroup = PermissionService.GROUP_PREFIX + groupName;
    try {
        // preconditions: create test document
        if (!authorityService.authorityExists(testGroup)) {
            authorityService.createAuthority(AuthorityType.GROUP, groupName);
        }
        final FileInfo document = transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<FileInfo>() {

            @Override
            public FileInfo execute() throws Throwable {
                NodeRef companyHomeNodeRef = repositoryHelper.getCompanyHome();
                String folderName = GUID.generate();
                FileInfo folderInfo = fileFolderService.create(companyHomeNodeRef, folderName, ContentModel.TYPE_FOLDER);
                nodeService.setProperty(folderInfo.getNodeRef(), ContentModel.PROP_NAME, folderName);
                assertNotNull(folderInfo);
                String docName = GUID.generate();
                FileInfo document = fileFolderService.create(folderInfo.getNodeRef(), docName, ContentModel.TYPE_CONTENT);
                assertNotNull(document);
                nodeService.setProperty(document.getNodeRef(), ContentModel.PROP_NAME, docName);
                return document;
            }
        });
        Set<AccessPermission> permissions = permissionService.getAllSetPermissions(document.getNodeRef());
        assertEquals(permissions.size(), 1);
        AccessPermission current = permissions.iterator().next();
        assertEquals(current.getAuthority(), "GROUP_EVERYONE");
        assertEquals(current.getPermission(), "Consumer");
        // add group1 with Coordinator permissions
        permissionService.setPermission(document.getNodeRef(), testGroup, PermissionService.COORDINATOR, true);
        permissions = permissionService.getAllSetPermissions(document.getNodeRef());
        Map<String, String> docPermissions = new HashMap<String, String>();
        for (AccessPermission permission : permissions) {
            docPermissions.put(permission.getAuthority(), permission.getPermission());
        }
        assertTrue(docPermissions.keySet().contains(testGroup));
        assertEquals(docPermissions.get(testGroup), PermissionService.COORDINATOR);
        // update permissions for group1 via CMIS 1.1 API
        withCmisService(new CmisServiceCallback<Void>() {

            @Override
            public Void execute(CmisService cmisService) {
                List<RepositoryInfo> repositories = cmisService.getRepositoryInfos(null);
                assertNotNull(repositories);
                assertTrue(repositories.size() > 0);
                RepositoryInfo repo = repositories.iterator().next();
                String repositoryId = repo.getId();
                String docIdStr = document.getNodeRef().toString();
                // when removing Coordinator ACE there are only inherited permissions
                // so empty list of direct permissions is sent to be set
                AccessControlListImpl acesToPut = new AccessControlListImpl();
                List<Ace> acesList = Collections.emptyList();
                acesToPut.setAces(acesList);
                cmisService.applyAcl(repositoryId, docIdStr, acesToPut, AclPropagation.REPOSITORYDETERMINED);
                return null;
            }
        }, CmisVersion.CMIS_1_1);
        // check that permissions are the same as they were before Coordinator was added
        permissions = permissionService.getAllSetPermissions(document.getNodeRef());
        docPermissions = new HashMap<String, String>();
        for (AccessPermission permission : permissions) {
            docPermissions.put(permission.getAuthority(), permission.getPermission());
        }
        assertFalse(docPermissions.keySet().contains(testGroup));
        assertEquals(permissions.size(), 1);
        current = permissions.iterator().next();
        assertEquals(current.getAuthority(), "GROUP_EVERYONE");
        assertEquals(current.getPermission(), "Consumer");
    } catch (CmisConstraintException e) {
        fail(e.toString());
    } finally {
        if (authorityService.authorityExists(testGroup)) {
            authorityService.deleteAuthority(testGroup);
        }
        AuthenticationUtil.popAuthentication();
    }
}
Also used : HashMap(java.util.HashMap) RepositoryInfo(org.apache.chemistry.opencmis.commons.data.RepositoryInfo) CmisConstraintException(org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException) AccessPermission(org.alfresco.service.cmr.security.AccessPermission) NodeRef(org.alfresco.service.cmr.repository.NodeRef) FileInfo(org.alfresco.service.cmr.model.FileInfo) CmisService(org.apache.chemistry.opencmis.commons.server.CmisService) AccessControlListImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.AccessControlListImpl) ObjectInFolderList(org.apache.chemistry.opencmis.commons.data.ObjectInFolderList) ArrayList(java.util.ArrayList) ObjectList(org.apache.chemistry.opencmis.commons.data.ObjectList) List(java.util.List) VersionableAspectTest(org.alfresco.repo.version.VersionableAspectTest) Test(org.junit.Test)

Aggregations

CmisService (org.apache.chemistry.opencmis.commons.server.CmisService)31 VersionableAspectTest (org.alfresco.repo.version.VersionableAspectTest)30 Test (org.junit.Test)30 ArrayList (java.util.ArrayList)26 List (java.util.List)23 ObjectInFolderList (org.apache.chemistry.opencmis.commons.data.ObjectInFolderList)23 ObjectList (org.apache.chemistry.opencmis.commons.data.ObjectList)23 RepositoryInfo (org.apache.chemistry.opencmis.commons.data.RepositoryInfo)23 FileInfo (org.alfresco.service.cmr.model.FileInfo)18 NodeRef (org.alfresco.service.cmr.repository.NodeRef)17 ObjectData (org.apache.chemistry.opencmis.commons.data.ObjectData)14 HashMap (java.util.HashMap)11 PropertiesImpl (org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertiesImpl)11 Holder (org.apache.chemistry.opencmis.commons.spi.Holder)11 PropertyStringImpl (org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyStringImpl)10 Map (java.util.Map)9 MimetypeMap (org.alfresco.repo.content.MimetypeMap)9 QName (org.alfresco.service.namespace.QName)8 ContentStreamImpl (org.apache.chemistry.opencmis.commons.impl.dataobjects.ContentStreamImpl)8 PropertyIdImpl (org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyIdImpl)8