Search in sources :

Example 11 with CmisService

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

the class CMISTest method testDeleteFolder.

/**
 * Test for ALF-18151.
 */
@Test
public void testDeleteFolder() {
    AuthenticationUtil.pushAuthentication();
    AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
    final Map<FileInfo, Boolean> testFolderMap = new HashMap<FileInfo, Boolean>(4);
    try {
        // create folder with file
        String folderName = "testfolder" + GUID.generate();
        String docName = "testdoc.txt" + GUID.generate();
        FileInfo folder = createContent(folderName, docName, false);
        testFolderMap.put(folder, Boolean.FALSE);
        // create empty folder
        String folderNameEmpty = "testfolder_empty1" + GUID.generate();
        FileInfo folderEmpty = createContent(folderNameEmpty, null, false);
        testFolderMap.put(folderEmpty, Boolean.TRUE);
        // create folder with file
        String folderNameRule = "testfolde_rule" + GUID.generate();
        String docNameRule = "testdoc_rule.txt" + GUID.generate();
        FileInfo folderWithRule = createContent(folderNameRule, docNameRule, true);
        testFolderMap.put(folderWithRule, Boolean.FALSE);
        // create empty folder
        String folderNameEmptyRule = "testfolde_empty_rule1" + GUID.generate();
        FileInfo folderEmptyWithRule = createContent(folderNameEmptyRule, null, true);
        testFolderMap.put(folderEmptyWithRule, Boolean.TRUE);
        withCmisService(new CmisServiceCallback<Void>() {

            @Override
            public Void execute(CmisService cmisService) {
                List<RepositoryInfo> repositories = cmisService.getRepositoryInfos(null);
                RepositoryInfo repo = repositories.get(0);
                String repositoryId = repo.getId();
                for (Map.Entry<FileInfo, Boolean> entry : testFolderMap.entrySet()) {
                    ObjectData objectData = cmisService.getObjectByPath(repositoryId, "/" + entry.getKey().getName(), null, true, IncludeRelationships.NONE, null, false, true, null);
                    Holder<String> objectId = new Holder<String>(objectData.getId());
                    try {
                        // delete folder
                        cmisService.deleteObjectOrCancelCheckOut(repositoryId, objectId.getValue(), Boolean.TRUE, null);
                    } catch (CmisConstraintException ex) {
                        assertTrue(!entry.getValue());
                        continue;
                    }
                    assertTrue(entry.getValue());
                }
                return null;
            }
        });
    } finally {
        for (Map.Entry<FileInfo, Boolean> entry : testFolderMap.entrySet()) {
            if (fileFolderService.exists(entry.getKey().getNodeRef())) {
                fileFolderService.delete(entry.getKey().getNodeRef());
            }
        }
        AuthenticationUtil.popAuthentication();
    }
}
Also used : HashMap(java.util.HashMap) 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) 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) 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 12 with CmisService

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

the class CMISTest method testMNT9090.

@Test
public void testMNT9090() throws Exception {
    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();
                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 fileInfo = fileFolderService.create(folderInfo.getNodeRef(), docName, ContentModel.TYPE_CONTENT);
                assertNotNull(fileInfo);
                nodeService.setProperty(fileInfo.getNodeRef(), ContentModel.PROP_NAME, docName);
                QName ASPECT_AUDIO = QName.createQName(NamespaceService.AUDIO_MODEL_1_0_URI, "audio");
                Map<QName, Serializable> aspectProperties = new HashMap<QName, Serializable>();
                nodeService.addAspect(fileInfo.getNodeRef(), ASPECT_AUDIO, aspectProperties);
                return fileInfo;
            }
        });
        withCmisService(new CmisServiceCallback<Void>() {

            @Override
            public Void execute(CmisService cmisService) {
                // get repository id
                List<RepositoryInfo> repositories = cmisService.getRepositoryInfos(null);
                assertTrue(repositories.size() > 0);
                RepositoryInfo repo = repositories.get(0);
                String repositoryId = repo.getId();
                String objectIdStr = fileInfo.getNodeRef().toString();
                Holder<String> objectId = new Holder<String>(objectIdStr);
                // try to overflow the value
                Object value = BigInteger.valueOf(Integer.MAX_VALUE + 1l);
                Properties properties = new PropertiesImpl();
                List<CmisExtensionElement> extensions = new ArrayList<CmisExtensionElement>();
                CmisExtensionElement valueElem = new CmisExtensionElementImpl(CMISConnector.ALFRESCO_EXTENSION_NAMESPACE, "value", null, value.toString());
                List<CmisExtensionElement> valueElems = new ArrayList<CmisExtensionElement>();
                valueElems.add(valueElem);
                List<CmisExtensionElement> children = new ArrayList<CmisExtensionElement>();
                Map<String, String> attributes = new HashMap<String, String>();
                attributes.put("propertyDefinitionId", "audio:trackNumber");
                children.add(new CmisExtensionElementImpl(CMISConnector.ALFRESCO_EXTENSION_NAMESPACE, "propertyInteger", attributes, valueElems));
                List<CmisExtensionElement> propertyValuesExtension = new ArrayList<CmisExtensionElement>();
                propertyValuesExtension.add(new CmisExtensionElementImpl(CMISConnector.ALFRESCO_EXTENSION_NAMESPACE, CMISConnector.PROPERTIES, null, children));
                CmisExtensionElement setAspectsExtension = new CmisExtensionElementImpl(CMISConnector.ALFRESCO_EXTENSION_NAMESPACE, CMISConnector.SET_ASPECTS, null, propertyValuesExtension);
                extensions.add(setAspectsExtension);
                properties.setExtensions(extensions);
                // should throw a CMISConstraintException
                cmisService.updateProperties(repositoryId, objectId, null, properties, null);
                fail();
                return null;
            }
        }, CmisVersion.CMIS_1_0);
    } catch (CmisConstraintException e) {
        assertTrue(e.getMessage().startsWith("Value is out of range for property"));
    // ok
    } finally {
        AuthenticationUtil.popAuthentication();
    }
}
Also used : Serializable(java.io.Serializable) Properties(org.apache.chemistry.opencmis.commons.data.Properties) CmisExtensionElementImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.CmisExtensionElementImpl) NodeRef(org.alfresco.service.cmr.repository.NodeRef) FileInfo(org.alfresco.service.cmr.model.FileInfo) 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) RepositoryInfo(org.apache.chemistry.opencmis.commons.data.RepositoryInfo) QName(org.alfresco.service.namespace.QName) CmisConstraintException(org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException) Holder(org.apache.chemistry.opencmis.commons.spi.Holder) CmisExtensionElement(org.apache.chemistry.opencmis.commons.data.CmisExtensionElement) 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) VersionableAspectTest(org.alfresco.repo.version.VersionableAspectTest) Test(org.junit.Test)

Example 13 with CmisService

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

the class CMISTest method withCmisService.

private <T extends Object> T withCmisService(CmisServiceCallback<T> callback, CmisVersion cmisVersion) {
    CmisService cmisService = null;
    try {
        CallContext context = new SimpleCallContext("admin", "admin", cmisVersion);
        cmisService = factory.getService(context);
        T ret = callback.execute(cmisService);
        return ret;
    } finally {
        if (cmisService != null) {
            cmisService.close();
        }
    }
}
Also used : CmisService(org.apache.chemistry.opencmis.commons.server.CmisService) CallContext(org.apache.chemistry.opencmis.commons.server.CallContext)

Example 14 with CmisService

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

the class CMISTest method testModelAvailability.

/**
 * Test for MNT-10537.
 */
@Test
public void testModelAvailability() throws Exception {
    final WorkflowDeployer testWorkflowDeployer = new WorkflowDeployer();
    // setup dependencies
    testWorkflowDeployer.setTransactionService(transactionService);
    testWorkflowDeployer.setWorkflowService(workflowService);
    testWorkflowDeployer.setWorkflowAdminService(workflowAdminService);
    testWorkflowDeployer.setAuthenticationContext(authenticationContext);
    testWorkflowDeployer.setDictionaryDAO(dictionaryDAO);
    testWorkflowDeployer.setTenantAdminService(tenantAdminService);
    testWorkflowDeployer.setTenantService(tenantService);
    testWorkflowDeployer.setNodeService(nodeService);
    testWorkflowDeployer.setNamespaceService(namespaceService);
    testWorkflowDeployer.setSearchService(searchService);
    // populate workflow parameters
    java.util.Properties props = new java.util.Properties();
    props.setProperty(WorkflowDeployer.ENGINE_ID, "activiti");
    props.setProperty(WorkflowDeployer.LOCATION, "activiti/testCustomActiviti.bpmn20.xml");
    props.setProperty(WorkflowDeployer.MIMETYPE, "text/xml");
    props.setProperty(WorkflowDeployer.REDEPLOY, Boolean.FALSE.toString());
    List<java.util.Properties> definitions = new ArrayList<java.util.Properties>(1);
    definitions.add(props);
    testWorkflowDeployer.setWorkflowDefinitions(definitions);
    List<String> models = new ArrayList<String>(1);
    models.add("activiti/testWorkflowModel.xml");
    testWorkflowDeployer.setModels(models);
    // deploy test workflow
    RetryingTransactionHelper txnHelper = transactionService.getRetryingTransactionHelper();
    txnHelper.setForceWritable(true);
    txnHelper.doInTransaction(new RetryingTransactionCallback<Object>() {

        @Override
        public Object execute() throws Throwable {
            return AuthenticationUtil.runAs(new RunAsWork<Object>() {

                public Object doWork() {
                    testWorkflowDeployer.init();
                    return null;
                }
            }, AuthenticationUtil.getSystemUserName());
        }
    }, false, true);
    org.alfresco.service.cmr.dictionary.TypeDefinition startTaskTypeDefinition = this.dictionaryService.getType(TEST_START_TASK);
    org.alfresco.service.cmr.dictionary.TypeDefinition workflowTaskTypeDefinition = this.dictionaryService.getType(TEST_WORKFLOW_TASK);
    // check that workflow types were correctly bootstrapped
    assertNotNull(startTaskTypeDefinition);
    assertNotNull(workflowTaskTypeDefinition);
    // caches are refreshed asynchronously
    Thread.sleep(5000);
    // check that loaded model is available via CMIS API
    CallContext context = new SimpleCallContext("admin", "admin", CmisVersion.CMIS_1_1);
    CmisService service = factory.getService(context);
    try {
        List<RepositoryInfo> repositories = service.getRepositoryInfos(null);
        assertTrue(repositories.size() > 0);
        List<TypeDefinitionContainer> container = service.getTypeDescendants(repositories.get(0).getId(), null, new BigInteger("-1"), true, null);
        assertTrue("Workflow model haven't been loaded", container.toString().contains("testwf:startTaskVarScriptAssign"));
    } finally {
        service.close();
    }
}
Also used : WorkflowDeployer(org.alfresco.repo.workflow.WorkflowDeployer) RetryingTransactionHelper(org.alfresco.repo.transaction.RetryingTransactionHelper) RunAsWork(org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork) TenantRunAsWork(org.alfresco.repo.tenant.TenantUtil.TenantRunAsWork) ArrayList(java.util.ArrayList) Properties(org.apache.chemistry.opencmis.commons.data.Properties) TypeDefinitionContainer(org.apache.chemistry.opencmis.commons.definitions.TypeDefinitionContainer) RepositoryInfo(org.apache.chemistry.opencmis.commons.data.RepositoryInfo) CallContext(org.apache.chemistry.opencmis.commons.server.CallContext) CmisService(org.apache.chemistry.opencmis.commons.server.CmisService) BigInteger(java.math.BigInteger) UnfileObject(org.apache.chemistry.opencmis.commons.enums.UnfileObject) VersionableAspectTest(org.alfresco.repo.version.VersionableAspectTest) Test(org.junit.Test)

Example 15 with CmisService

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

the class CMISTest method testMNT10021.

/**
 * CMIS 1.0 aspect properties should provide the following CMIS attributes:
 * propertyDefinitionId, displayName, localName, queryName
 */
@Test
public void testMNT10021() throws Exception {
    final String folderName = "testfolder." + GUID.generate();
    final String docName = "testdoc.txt." + GUID.generate();
    AuthenticationUtil.pushAuthentication();
    AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
    try {
        transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Void>() {

            @Override
            public Void execute() throws Throwable {
                NodeRef companyHomeNodeRef = repositoryHelper.getCompanyHome();
                FileInfo folderInfo = fileFolderService.create(companyHomeNodeRef, folderName, ContentModel.TYPE_FOLDER);
                nodeService.setProperty(folderInfo.getNodeRef(), ContentModel.PROP_NAME, folderName);
                assertNotNull(folderInfo);
                FileInfo document = fileFolderService.create(folderInfo.getNodeRef(), docName, ContentModel.TYPE_CONTENT);
                assertNotNull(document);
                nodeService.setProperty(document.getNodeRef(), ContentModel.PROP_NAME, docName);
                // lock adds aspects to the document with properties: lockIsDeep, lockOwner, lockType, expiryDate, lockLifetime
                lockService.lock(document.getNodeRef(), LockType.READ_ONLY_LOCK, 0, true);
                return null;
            }
        });
        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();
                ObjectData objectData = cmisService.getObjectByPath(repositoryId, "/" + folderName + "/" + docName, null, true, IncludeRelationships.NONE, null, false, true, null);
                return objectData;
            }
        }, CmisVersion.CMIS_1_0);
        List<CmisExtensionElement> propertyExtensionList = objectData.getProperties().getExtensions();
        assertEquals("propertyExtensionList should be singletonList", propertyExtensionList.size(), 1);
        List<CmisExtensionElement> extensions = propertyExtensionList.iterator().next().getChildren();
        for (CmisExtensionElement extension : extensions) {
            if ("properties".equals(extension.getName())) {
                // check properties extension
                List<CmisExtensionElement> propExtensions = extension.getChildren();
                assertTrue("cmisObject should contain aspect properties", propExtensions.size() > 0);
                for (CmisExtensionElement prop : propExtensions) {
                    Map<String, String> cmisAspectProperty = prop.getAttributes();
                    Set<String> cmisAspectPropertyNames = cmisAspectProperty.keySet();
                    assertTrue("propertyDefinitionId attribute should be present", cmisAspectPropertyNames.contains("propertyDefinitionId"));
                    assertTrue("queryName attribute should be present", cmisAspectPropertyNames.contains("queryName"));
                    // optional values that are present for test document
                    assertTrue("displayName attribute should be present for property of test node", cmisAspectPropertyNames.contains("displayName"));
                    assertTrue("localName attribute should be present for property of test node", cmisAspectPropertyNames.contains("localName"));
                    assertEquals(cmisAspectPropertyNames.size(), 4);
                    // check values
                    for (String aspectPropertyName : cmisAspectPropertyNames) {
                        String value = cmisAspectProperty.get(aspectPropertyName);
                        assertTrue("value for " + aspectPropertyName + " should be present", value != null && value.length() > 0);
                    }
                }
            }
        }
    } catch (CmisConstraintException e) {
        fail(e.toString());
    } finally {
        AuthenticationUtil.popAuthentication();
    }
}
Also used : RepositoryInfo(org.apache.chemistry.opencmis.commons.data.RepositoryInfo) CmisConstraintException(org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException) ObjectData(org.apache.chemistry.opencmis.commons.data.ObjectData) 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) 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