Search in sources :

Example 1 with ObjectInfo

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

the class AlfrescoCmisServiceImpl method getObjectInfo.

protected ObjectInfo getObjectInfo(String repositoryId, String objectId, String filter, IncludeRelationships includeRelationships) {
    ObjectInfo info = objectInfoMap.get(objectId);
    if (info == null) {
        CMISNodeInfo nodeInfo = getOrCreateNodeInfo(objectId);
        if (nodeInfo.getObjectVariant() == CMISObjectVariant.INVALID_ID || nodeInfo.getObjectVariant() == CMISObjectVariant.NOT_EXISTING || nodeInfo.getObjectVariant() == CMISObjectVariant.NOT_A_CMIS_OBJECT || nodeInfo.getObjectVariant() == CMISObjectVariant.PERMISSION_DENIED) {
            info = null;
        } else {
            // object info has not been found -> create one
            try {
                if (filter == null) {
                    filter = MIN_FILTER;
                } else if (!filter.equals("*")) {
                    filter = filter + "," + MIN_FILTER;
                }
                // get the object and its info
                ObjectData object = connector.createCMISObject(nodeInfo, filter, false, includeRelationships, null, false, false);
                info = getObjectInfoIntern(repositoryId, object);
                // add object info
                objectInfoMap.put(objectId, info);
            } catch (Exception e) {
                e.printStackTrace();
                info = null;
            }
        }
    }
    return info;
}
Also used : ObjectData(org.apache.chemistry.opencmis.commons.data.ObjectData) CMISNodeInfo(org.alfresco.opencmis.dictionary.CMISNodeInfo) ObjectInfo(org.apache.chemistry.opencmis.commons.server.ObjectInfo) CmisContentAlreadyExistsException(org.apache.chemistry.opencmis.commons.exceptions.CmisContentAlreadyExistsException) CmisConstraintException(org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException) CmisPermissionDeniedException(org.apache.chemistry.opencmis.commons.exceptions.CmisPermissionDeniedException) CmisRuntimeException(org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException) IOException(java.io.IOException) CmisVersioningException(org.apache.chemistry.opencmis.commons.exceptions.CmisVersioningException) CmisInvalidArgumentException(org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException) FileNotFoundException(org.alfresco.service.cmr.model.FileNotFoundException) CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) CmisStorageException(org.apache.chemistry.opencmis.commons.exceptions.CmisStorageException) CmisStreamNotSupportedException(org.apache.chemistry.opencmis.commons.exceptions.CmisStreamNotSupportedException) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException) ContentIOException(org.alfresco.service.cmr.repository.ContentIOException)

Example 2 with ObjectInfo

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

the class CMISTest method testSetDeleteAppendContentStreamVersioning.

/**
 * Test auto version behavior for setContentStream, deleteContentStream and appendContentStream according to ALF-21852.
 */
@Test
public void testSetDeleteAppendContentStreamVersioning() throws Exception {
    AuthenticationUtil.pushAuthentication();
    AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
    final String DOC1 = "documentProperties1-" + GUID.generate();
    try {
        final FileInfo doc = transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<FileInfo>() {

            @Override
            public FileInfo execute() throws Throwable {
                FileInfo document;
                // create document
                document = fileFolderService.create(repositoryHelper.getCompanyHome(), DOC1, ContentModel.TYPE_CONTENT);
                nodeService.setProperty(document.getNodeRef(), ContentModel.PROP_NAME, DOC1);
                Map<QName, Serializable> props = new HashMap<QName, Serializable>();
                props.put(ContentModel.PROP_TITLE, "Initial Title");
                props.put(ContentModel.PROP_DESCRIPTION, "Initial Description");
                nodeService.addAspect(document.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, true);
                props.put(ContentModel.PROP_AUTO_VERSION_PROPS, true);
                versionService.ensureVersioningEnabled(document.getNodeRef(), props);
                return document;
            }
        });
        withCmisService(new CmisServiceCallback<Void>() {

            @Override
            public Void execute(CmisService cmisService) {
                final String documentNodeRefId = doc.getNodeRef().toString();
                final String repositoryId = cmisService.getRepositoryInfos(null).get(0).getId();
                ObjectInfo objInfoInitialVersion = cmisService.getObjectInfo(repositoryId, documentNodeRefId);
                assertTrue("We had just created the document - it should be version 1.0", objInfoInitialVersion.getId().endsWith("1.0"));
                ContentStreamImpl contentStream = new ContentStreamImpl(null, MimetypeMap.MIMETYPE_TEXT_PLAIN, "Content " + GUID.generate());
                Holder<String> objectIdHolder = new Holder<>(documentNodeRefId);
                // Test setContentStream
                cmisService.setContentStream(repositoryId, objectIdHolder, true, null, contentStream, null);
                assertTrue("The \"output\" parameter should returns the newly created version id: 1.1", objectIdHolder.getValue().endsWith("1.1"));
                // we can use this new version id to get information about the cmis object
                ObjectInfo objInfoAfterSetContentStream = cmisService.getObjectInfo(repositoryId, objectIdHolder.getValue());
                assertTrue("The object info should reflect the version requested: 1.1", objInfoAfterSetContentStream.getId().endsWith("1.1"));
                // Test deleteContentStream
                cmisService.deleteContentStream(repositoryId, objectIdHolder, null, null);
                assertTrue("The \"output\" parameter should returns the newly created version id: 1.2", objectIdHolder.getValue().endsWith("1.2"));
                // we can use this new version id to get information about the cmis object
                objInfoAfterSetContentStream = cmisService.getObjectInfo(repositoryId, objectIdHolder.getValue());
                assertTrue("The object info should reflect the version requested: 1.2", objInfoAfterSetContentStream.getId().endsWith("1.2"));
                // Test appendContentStream
                cmisService.appendContentStream(repositoryId, objectIdHolder, null, contentStream, true, null);
                assertTrue("The \"output\" parameter should returns the newly created version id: 1.3", objectIdHolder.getValue().endsWith("1.3"));
                // we can use this new version id to get information about the cmis object
                objInfoAfterSetContentStream = cmisService.getObjectInfo(repositoryId, objectIdHolder.getValue());
                assertTrue("The object info should reflect the version requested: 1.3", objInfoAfterSetContentStream.getId().endsWith("1.3"));
                return null;
            }
        }, CmisVersion.CMIS_1_1);
    } finally {
        AuthenticationUtil.popAuthentication();
    }
}
Also used : ContentStreamImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.ContentStreamImpl) Serializable(java.io.Serializable) HashMap(java.util.HashMap) QName(org.alfresco.service.namespace.QName) Holder(org.apache.chemistry.opencmis.commons.spi.Holder) ObjectInfo(org.apache.chemistry.opencmis.commons.server.ObjectInfo) FileInfo(org.alfresco.service.cmr.model.FileInfo) 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)

Aggregations

ObjectInfo (org.apache.chemistry.opencmis.commons.server.ObjectInfo)2 IOException (java.io.IOException)1 Serializable (java.io.Serializable)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 CMISNodeInfo (org.alfresco.opencmis.dictionary.CMISNodeInfo)1 MimetypeMap (org.alfresco.repo.content.MimetypeMap)1 VersionableAspectTest (org.alfresco.repo.version.VersionableAspectTest)1 FileInfo (org.alfresco.service.cmr.model.FileInfo)1 FileNotFoundException (org.alfresco.service.cmr.model.FileNotFoundException)1 ContentIOException (org.alfresco.service.cmr.repository.ContentIOException)1 InvalidNodeRefException (org.alfresco.service.cmr.repository.InvalidNodeRefException)1 QName (org.alfresco.service.namespace.QName)1 ObjectData (org.apache.chemistry.opencmis.commons.data.ObjectData)1 CmisConstraintException (org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException)1 CmisContentAlreadyExistsException (org.apache.chemistry.opencmis.commons.exceptions.CmisContentAlreadyExistsException)1 CmisInvalidArgumentException (org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException)1 CmisObjectNotFoundException (org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException)1 CmisPermissionDeniedException (org.apache.chemistry.opencmis.commons.exceptions.CmisPermissionDeniedException)1 CmisRuntimeException (org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException)1