Search in sources :

Example 1 with CmisExtensionElement

use of org.apache.chemistry.opencmis.commons.data.CmisExtensionElement 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 2 with CmisExtensionElement

use of org.apache.chemistry.opencmis.commons.data.CmisExtensionElement 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 3 with CmisExtensionElement

use of org.apache.chemistry.opencmis.commons.data.CmisExtensionElement 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)

Example 4 with CmisExtensionElement

use of org.apache.chemistry.opencmis.commons.data.CmisExtensionElement in project alfresco-repository by Alfresco.

the class CMISTest method testExtensionDataIsReturnedViaCmis1_1.

/**
 * MNT-11876 : Test that Alfresco CMIS 1.1 Implementation is returning aspect and aspect properties as extension data
 * @throws Exception
 */
@Test
public void testExtensionDataIsReturnedViaCmis1_1() throws Exception {
    AuthenticationUtil.pushAuthentication();
    AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
    final String FOLDER = "testExtensionDataIsReturnedViaCmis1_1-" + GUID.generate();
    final String CONTENT = FOLDER + "-file";
    try {
        transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Void>() {

            @Override
            public Void 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 document
                FileInfo document = fileFolderService.create(folderInfo.getNodeRef(), CONTENT, ContentModel.TYPE_CONTENT);
                assertNotNull(document);
                nodeService.setProperty(document.getNodeRef(), ContentModel.PROP_NAME, CONTENT);
                // apply aspect with properties
                Map<QName, Serializable> props = new HashMap<QName, Serializable>();
                props.put(ContentModel.PROP_LATITUDE, Double.valueOf(1.0d));
                props.put(ContentModel.PROP_LONGITUDE, Double.valueOf(1.0d));
                nodeService.addAspect(document.getNodeRef(), ContentModel.ASPECT_GEOGRAPHIC, props);
                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();
                // get object data
                ObjectData objectData = cmisService.getObjectByPath(repositoryId, "/" + FOLDER + "/" + CONTENT, null, true, IncludeRelationships.NONE, null, false, true, null);
                return objectData;
            }
        }, CmisVersion.CMIS_1_1);
        // get extension data from object properties
        List<CmisExtensionElement> extensions = objectData.getProperties().getExtensions().iterator().next().getChildren();
        Set<String> appliedAspects = new HashSet<String>();
        Set<String> aspectProperties = new HashSet<String>();
        for (CmisExtensionElement extension : extensions) {
            if (CMISConnector.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"));
                    aspectProperties.add(cmisAspectProperty.get("propertyDefinitionId"));
                }
            } else if (CMISConnector.APPLIED_ASPECTS.equals(extension.getName())) {
                appliedAspects.add(extension.getValue());
            }
        }
        // extension data should contain applied aspects and aspect properties
        assertTrue("Extensions should contain " + ContentModel.ASPECT_GEOGRAPHIC, appliedAspects.contains("P:cm:geographic"));
        assertTrue("Extensions should contain " + ContentModel.PROP_LATITUDE, aspectProperties.contains("cm:latitude"));
        assertTrue("Extensions should contain " + ContentModel.PROP_LONGITUDE, aspectProperties.contains("cm:longitude"));
    } finally {
        AuthenticationUtil.popAuthentication();
    }
}
Also used : Serializable(java.io.Serializable) RepositoryInfo(org.apache.chemistry.opencmis.commons.data.RepositoryInfo) QName(org.alfresco.service.namespace.QName) ObjectData(org.apache.chemistry.opencmis.commons.data.ObjectData) 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) 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 5 with CmisExtensionElement

use of org.apache.chemistry.opencmis.commons.data.CmisExtensionElement 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)

Aggregations

CmisExtensionElement (org.apache.chemistry.opencmis.commons.data.CmisExtensionElement)11 ArrayList (java.util.ArrayList)10 List (java.util.List)8 HashMap (java.util.HashMap)7 ObjectList (org.apache.chemistry.opencmis.commons.data.ObjectList)7 Serializable (java.io.Serializable)6 VersionableAspectTest (org.alfresco.repo.version.VersionableAspectTest)5 QName (org.alfresco.service.namespace.QName)5 CmisService (org.apache.chemistry.opencmis.commons.server.CmisService)5 Test (org.junit.Test)5 Collections.singletonList (java.util.Collections.singletonList)4 Map (java.util.Map)4 FileInfo (org.alfresco.service.cmr.model.FileInfo)4 RepositoryInfo (org.apache.chemistry.opencmis.commons.data.RepositoryInfo)4 CmisConstraintException (org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException)4 CmisExtensionElementImpl (org.apache.chemistry.opencmis.commons.impl.dataobjects.CmisExtensionElementImpl)4 HashSet (java.util.HashSet)3 MimetypeMap (org.alfresco.repo.content.MimetypeMap)3 NodeRef (org.alfresco.service.cmr.repository.NodeRef)3 ObjectData (org.apache.chemistry.opencmis.commons.data.ObjectData)3