Search in sources :

Example 26 with CmisService

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

the class CMISTest method testVersioningPropertiesHaveDefaultValue.

/**
 * Test to ensure that versioning properties have default values defined in Alfresco content model.
 * Testing  <b>cm:initialVersion</b>, <b>cm:autoVersion</b> and <b>cm:autoVersionOnUpdateProps</b> properties
 *
 * @throws Exception
 */
@Test
public void testVersioningPropertiesHaveDefaultValue() throws Exception {
    AuthenticationUtil.pushAuthentication();
    AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
    try {
        // Create document via CMIS
        final NodeRef documentNodeRef = withCmisService(new CmisServiceCallback<NodeRef>() {

            @Override
            public NodeRef execute(CmisService cmisService) {
                String repositoryId = cmisService.getRepositoryInfos(null).get(0).getId();
                String rootNodeId = cmisService.getObjectByPath(repositoryId, "/", null, true, IncludeRelationships.NONE, null, false, true, null).getId();
                Collection<PropertyData<?>> propsList = new ArrayList<PropertyData<?>>();
                propsList.add(new PropertyStringImpl(PropertyIds.NAME, "Folder-" + GUID.generate()));
                propsList.add(new PropertyIdImpl(PropertyIds.OBJECT_TYPE_ID, "cmis:folder"));
                String folderId = cmisService.createFolder(repositoryId, new PropertiesImpl(propsList), rootNodeId, null, null, null, null);
                propsList = new ArrayList<PropertyData<?>>();
                propsList.add(new PropertyStringImpl(PropertyIds.NAME, "File-" + GUID.generate()));
                propsList.add(new PropertyIdImpl(PropertyIds.OBJECT_TYPE_ID, "cmis:document"));
                String nodeId = cmisService.createDocument(repositoryId, new PropertiesImpl(propsList), folderId, null, null, null, null, null, null);
                return new NodeRef(nodeId.substring(0, nodeId.indexOf(';')));
            }
        }, CmisVersion.CMIS_1_1);
        // check versioning properties
        transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<List<Void>>() {

            @Override
            public List<Void> execute() throws Throwable {
                assertTrue(nodeService.exists(documentNodeRef));
                assertTrue(nodeService.hasAspect(documentNodeRef, ContentModel.ASPECT_VERSIONABLE));
                AspectDefinition ad = dictionaryService.getAspect(ContentModel.ASPECT_VERSIONABLE);
                Map<QName, org.alfresco.service.cmr.dictionary.PropertyDefinition> properties = ad.getProperties();
                for (QName qName : new QName[] { ContentModel.PROP_INITIAL_VERSION, ContentModel.PROP_AUTO_VERSION, ContentModel.PROP_AUTO_VERSION_PROPS }) {
                    Serializable property = nodeService.getProperty(documentNodeRef, qName);
                    assertNotNull(property);
                    org.alfresco.service.cmr.dictionary.PropertyDefinition pd = properties.get(qName);
                    assertNotNull(pd.getDefaultValue());
                    assertEquals(property, Boolean.parseBoolean(pd.getDefaultValue()));
                }
                return null;
            }
        });
    } finally {
        AuthenticationUtil.popAuthentication();
    }
}
Also used : Serializable(java.io.Serializable) PropertyData(org.apache.chemistry.opencmis.commons.data.PropertyData) ArrayList(java.util.ArrayList) NodeRef(org.alfresco.service.cmr.repository.NodeRef) 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) AspectDefinition(org.alfresco.service.cmr.dictionary.AspectDefinition) PropertyDefinition(org.apache.chemistry.opencmis.commons.definitions.PropertyDefinition) PropertyIdImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyIdImpl) CmisService(org.apache.chemistry.opencmis.commons.server.CmisService) Collection(java.util.Collection) 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 27 with CmisService

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

the class CMISTest method testCreateDocWithVersioningStateNone.

@Test
public void testCreateDocWithVersioningStateNone() throws Exception {
    AuthenticationUtil.pushAuthentication();
    AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
    try {
        // get repository id
        final String repositoryId = withCmisService(new CmisServiceCallback<String>() {

            @Override
            public String execute(CmisService cmisService) {
                List<RepositoryInfo> repositories = cmisService.getRepositoryInfos(null);
                assertTrue(repositories.size() > 0);
                RepositoryInfo repo = repositories.get(0);
                final String repositoryId = repo.getId();
                return repositoryId;
            }
        }, CmisVersion.CMIS_1_1);
        final NodeRef documentNodeRef = withCmisService(new CmisServiceCallback<NodeRef>() {

            @Override
            public NodeRef execute(CmisService cmisService) {
                final PropertiesImpl properties = new PropertiesImpl();
                String objectTypeId = "cmis:document";
                properties.addProperty(new PropertyIdImpl(PropertyIds.OBJECT_TYPE_ID, objectTypeId));
                String fileName = "textFile" + GUID.generate();
                properties.addProperty(new PropertyStringImpl(PropertyIds.NAME, fileName));
                final ContentStreamImpl contentStream = new ContentStreamImpl(fileName, MimetypeMap.MIMETYPE_TEXT_PLAIN, "Simple text plain document");
                String nodeId = cmisService.create(repositoryId, properties, repositoryHelper.getCompanyHome().getId(), contentStream, VersioningState.NONE, null, null);
                return new NodeRef(nodeId.substring(0, nodeId.indexOf(';')));
            }
        }, CmisVersion.CMIS_1_1);
        // check versioning properties
        transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<List<Void>>() {

            @Override
            public List<Void> execute() throws Throwable {
                assertTrue(nodeService.exists(documentNodeRef));
                assertFalse(nodeService.hasAspect(documentNodeRef, ContentModel.ASPECT_VERSIONABLE));
                return null;
            }
        });
    } finally {
        AuthenticationUtil.popAuthentication();
    }
}
Also used : ContentStreamImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.ContentStreamImpl) PropertiesImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertiesImpl) RepositoryInfo(org.apache.chemistry.opencmis.commons.data.RepositoryInfo) PropertyIdImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyIdImpl) NodeRef(org.alfresco.service.cmr.repository.NodeRef) CmisService(org.apache.chemistry.opencmis.commons.server.CmisService) 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) VersionableAspectTest(org.alfresco.repo.version.VersionableAspectTest) Test(org.junit.Test)

Example 28 with CmisService

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

the class CMISTest method testCheckIn.

/**
 * Test for MNT-9203.
 */
@Test
public void testCheckIn() {
    String repositoryId = null;
    ObjectData objectData = null;
    Holder<String> objectId = null;
    CallContext context = new SimpleCallContext("admin", "admin", CmisVersion.CMIS_1_0);
    final String folderName = "testfolder." + GUID.generate();
    final String docName = "testdoc.txt." + GUID.generate();
    final String customModel = "cmistest.model";
    final QName testCustomTypeQName = QName.createQName(customModel, "sop");
    final QName authorisedByQname = QName.createQName(customModel, "authorisedBy");
    AuthenticationUtil.pushAuthentication();
    AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
    try {
        final FileInfo fileInfo = transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<FileInfo>() {

            @Override
            public FileInfo execute() throws Throwable {
                NodeRef companyHomeNodeRef = repositoryHelper.getCompanyHome();
                FileInfo folderInfo = fileFolderService.create(companyHomeNodeRef, folderName, ContentModel.TYPE_FOLDER);
                nodeService.setProperty(folderInfo.getNodeRef(), ContentModel.PROP_NAME, folderName);
                FileInfo fileInfo = fileFolderService.create(folderInfo.getNodeRef(), docName, testCustomTypeQName);
                Map<QName, Serializable> customProperties = new HashMap<QName, Serializable>();
                customProperties.put(authorisedByQname, "customPropertyString");
                customProperties.put(ContentModel.PROP_NAME, docName);
                nodeService.setProperties(fileInfo.getNodeRef(), customProperties);
                return fileInfo;
            }
        });
        CmisService service = factory.getService(context);
        try {
            List<RepositoryInfo> repositories = service.getRepositoryInfos(null);
            assertTrue(repositories.size() > 0);
            RepositoryInfo repo = repositories.get(0);
            repositoryId = repo.getId();
            objectData = service.getObjectByPath(repositoryId, "/" + folderName + "/" + docName, null, true, IncludeRelationships.NONE, null, false, true, null);
            // checkout
            objectId = new Holder<String>(objectData.getId());
            service.checkOut(repositoryId, objectId, null, new Holder<Boolean>(true));
        } finally {
            service.close();
        }
        try {
            service = factory.getService(context);
            PropertyStringImpl prop = new PropertyStringImpl();
            prop.setId("abc:" + authorisedByQname.toPrefixString());
            prop.setValue(null);
            Collection<PropertyData<?>> propsList = new ArrayList<PropertyData<?>>();
            propsList.add(prop);
            Properties properties = new PropertiesImpl(propsList);
            // checkIn on pwc
            service.checkIn(repositoryId, objectId, false, properties, null, null, null, null, null, null);
        } finally {
            service.close();
        }
        // check that value is null
        assertTrue(nodeService.getProperty(fileInfo.getNodeRef(), authorisedByQname) == null);
    } finally {
        AuthenticationUtil.popAuthentication();
    }
}
Also used : Serializable(java.io.Serializable) PropertyData(org.apache.chemistry.opencmis.commons.data.PropertyData) ObjectData(org.apache.chemistry.opencmis.commons.data.ObjectData) ArrayList(java.util.ArrayList) Properties(org.apache.chemistry.opencmis.commons.data.Properties) NodeRef(org.alfresco.service.cmr.repository.NodeRef) FileInfo(org.alfresco.service.cmr.model.FileInfo) PropertyStringImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyStringImpl) PropertiesImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertiesImpl) RepositoryInfo(org.apache.chemistry.opencmis.commons.data.RepositoryInfo) QName(org.alfresco.service.namespace.QName) CallContext(org.apache.chemistry.opencmis.commons.server.CallContext) 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 29 with CmisService

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

the class CMISTest method testCancelCheckout.

/**
 * Test for ALF-16310.
 *
 * Check that, for AtomPub binding, cancel checkout on the originating checked out document i.e. not the working
 * copy throws an exception and does not delete the document.
 */
@SuppressWarnings("unchecked")
@Test
public void testCancelCheckout() {
    final TestContext testContext = new TestContext();
    final String folderName = "testfolder." + GUID.generate();
    final String docName = "testdoc.txt." + GUID.generate();
    AuthenticationUtil.pushAuthentication();
    AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
    try {
        final FileInfo folderInfo = transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<FileInfo>() {

            @Override
            public FileInfo execute() throws Throwable {
                NodeRef companyHomeNodeRef = repositoryHelper.getCompanyHome();
                FileInfo folderInfo = fileFolderService.create(companyHomeNodeRef, folderName, ContentModel.TYPE_FOLDER);
                nodeService.setProperty(folderInfo.getNodeRef(), ContentModel.PROP_NAME, folderName);
                FileInfo fileInfo = fileFolderService.create(folderInfo.getNodeRef(), docName, ContentModel.TYPE_CONTENT);
                nodeService.setProperty(fileInfo.getNodeRef(), ContentModel.PROP_NAME, docName);
                return folderInfo;
            }
        });
        final ObjectData objectData = withCmisService(new CmisServiceCallback<ObjectData>() {

            @Override
            public ObjectData execute(CmisService cmisService) {
                List<RepositoryInfo> repositories = cmisService.getRepositoryInfos(null);
                assertTrue(repositories.size() > 0);
                RepositoryInfo repo = repositories.get(0);
                String repositoryId = repo.getId();
                testContext.setRepositoryId(repositoryId);
                ObjectData objectData = cmisService.getObjectByPath(repositoryId, "/" + folderName + "/" + docName, null, true, IncludeRelationships.NONE, null, false, true, null);
                testContext.setObjectData(objectData);
                // checkout
                Holder<String> objectId = new Holder<String>(objectData.getId());
                testContext.setObjectId(objectId);
                cmisService.checkOut(repositoryId, objectId, null, new Holder<Boolean>(true));
                return objectData;
            }
        });
        // AtomPub cancel checkout
        withCmisService(new CmisServiceCallback<Void>() {

            @Override
            public Void execute(CmisService cmisService) {
                try {
                    // check allowable actions
                    ObjectData originalDoc = cmisService.getObject(testContext.getRepositoryId(), objectData.getId(), null, true, IncludeRelationships.NONE, null, false, true, null);
                    AllowableActions allowableActions = originalDoc.getAllowableActions();
                    assertNotNull(allowableActions);
                    assertFalse(allowableActions.getAllowableActions().contains(Action.CAN_DELETE_OBJECT));
                    // try to cancel the checkout
                    cmisService.deleteObjectOrCancelCheckOut(testContext.getRepositoryId(), objectData.getId(), Boolean.TRUE, null);
                    fail();
                } catch (CmisConstraintException e) {
                // expected
                }
                return null;
            }
        });
        withCmisService(new CmisServiceCallback<Void>() {

            @Override
            public Void execute(CmisService cmisService) {
                // cancel checkout on pwc
                cmisService.deleteObjectOrCancelCheckOut(testContext.getRepositoryId(), testContext.getObjectId().getValue(), Boolean.TRUE, null);
                return null;
            }
        });
        withCmisService(new CmisServiceCallback<Void>() {

            @Override
            public Void execute(CmisService cmisService) {
                // get original document
                ObjectData originalDoc = cmisService.getObject(testContext.getRepositoryId(), objectData.getId(), null, true, IncludeRelationships.NONE, null, false, true, null);
                Map<String, PropertyData<?>> properties = originalDoc.getProperties().getProperties();
                PropertyData<Boolean> isVersionSeriesCheckedOutProp = (PropertyData<Boolean>) properties.get(PropertyIds.IS_VERSION_SERIES_CHECKED_OUT);
                assertNotNull(isVersionSeriesCheckedOutProp);
                Boolean isVersionSeriesCheckedOut = isVersionSeriesCheckedOutProp.getFirstValue();
                assertNotNull(isVersionSeriesCheckedOut);
                assertEquals(Boolean.FALSE, isVersionSeriesCheckedOut);
                return null;
            }
        });
        withCmisService(new CmisServiceCallback<Void>() {

            @Override
            public Void execute(CmisService cmisService) {
                // delete original document
                cmisService.deleteObject(testContext.getRepositoryId(), objectData.getId(), true, null);
                return null;
            }
        });
        List<FileInfo> children = transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<List<FileInfo>>() {

            @Override
            public List<FileInfo> execute() throws Throwable {
                List<FileInfo> children = fileFolderService.list(folderInfo.getNodeRef());
                return children;
            }
        });
        assertEquals(0, children.size());
    } finally {
        AuthenticationUtil.popAuthentication();
    }
}
Also used : PropertyData(org.apache.chemistry.opencmis.commons.data.PropertyData) RepositoryInfo(org.apache.chemistry.opencmis.commons.data.RepositoryInfo) CmisConstraintException(org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException) Holder(org.apache.chemistry.opencmis.commons.spi.Holder) ObjectData(org.apache.chemistry.opencmis.commons.data.ObjectData) NodeRef(org.alfresco.service.cmr.repository.NodeRef) FileInfo(org.alfresco.service.cmr.model.FileInfo) CmisService(org.apache.chemistry.opencmis.commons.server.CmisService) AllowableActions(org.apache.chemistry.opencmis.commons.data.AllowableActions) ObjectInFolderList(org.apache.chemistry.opencmis.commons.data.ObjectInFolderList) ArrayList(java.util.ArrayList) ObjectList(org.apache.chemistry.opencmis.commons.data.ObjectList) List(java.util.List) 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 30 with CmisService

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

the class CMISTest method testOperationsOnReadOnlyLockedNode.

/**
 * Test
 * <ul>
 *   <li>MNT-8825: READ_ONLYLOCK prevent getAllVersions via new CMIS enpoint.</li>
 *   <li>ACE-762: BM-0012: NodeLockedException not handled by CMIS</li>
 * </ul>
 */
@Test
public void testOperationsOnReadOnlyLockedNode() {
    final String folderName = "testfolder." + GUID.generate();
    final String docName = "testdoc.txt." + GUID.generate();
    AuthenticationUtil.pushAuthentication();
    AuthenticationUtil.setAdminUserAsFullyAuthenticatedUser();
    try {
        final FileInfo fileInfo = transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<FileInfo>() {

            @Override
            public FileInfo execute() throws Throwable {
                NodeRef companyHomeNodeRef = repositoryHelper.getCompanyHome();
                FileInfo folderInfo = fileFolderService.create(companyHomeNodeRef, folderName, ContentModel.TYPE_FOLDER);
                nodeService.setProperty(folderInfo.getNodeRef(), ContentModel.PROP_NAME, folderName);
                FileInfo fileInfo = fileFolderService.create(folderInfo.getNodeRef(), docName, ContentModel.TYPE_CONTENT);
                nodeService.setProperty(fileInfo.getNodeRef(), ContentModel.PROP_NAME, docName);
                versionService.createVersion(fileInfo.getNodeRef(), new HashMap<String, Serializable>());
                lockService.lock(fileInfo.getNodeRef(), LockType.READ_ONLY_LOCK, 0, true);
                return fileInfo;
            }
        });
        withCmisService(new CmisServiceCallback<Void>() {

            @Override
            public Void execute(CmisService cmisService) {
                List<RepositoryInfo> repositories = cmisService.getRepositoryInfos(null);
                assertTrue(repositories.size() > 0);
                RepositoryInfo repo = repositories.get(0);
                String repositoryId = repo.getId();
                ObjectData objectData = cmisService.getObjectByPath(repositoryId, "/" + folderName + "/" + docName, null, true, IncludeRelationships.NONE, null, false, true, null);
                // Expect no failure
                cmisService.getAllVersions(repositoryId, objectData.getId(), fileInfo.getNodeRef().getId(), null, true, null);
                return null;
            }
        });
        withCmisService(new CmisServiceCallback<Void>() {

            @Override
            public Void execute(CmisService cmisService) {
                List<RepositoryInfo> repositories = cmisService.getRepositoryInfos(null);
                assertTrue(repositories.size() > 0);
                RepositoryInfo repo = repositories.get(0);
                String repositoryId = repo.getId();
                ObjectData objectData = cmisService.getObjectByPath(repositoryId, "/" + folderName + "/" + docName, null, true, IncludeRelationships.NONE, null, false, true, null);
                String objectId = objectData.getId();
                // Expect failure as the node is locked
                try {
                    cmisService.deleteObject(repositoryId, objectId, true, null);
                    fail("Locked node should not be deletable.");
                } catch (CmisUpdateConflictException e) {
                // Expected
                }
                return null;
            }
        });
    } finally {
        AuthenticationUtil.popAuthentication();
    }
}
Also used : HashMap(java.util.HashMap) RepositoryInfo(org.apache.chemistry.opencmis.commons.data.RepositoryInfo) ObjectData(org.apache.chemistry.opencmis.commons.data.ObjectData) CmisUpdateConflictException(org.apache.chemistry.opencmis.commons.exceptions.CmisUpdateConflictException) NodeRef(org.alfresco.service.cmr.repository.NodeRef) FileInfo(org.alfresco.service.cmr.model.FileInfo) CmisService(org.apache.chemistry.opencmis.commons.server.CmisService) 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