Search in sources :

Example 16 with CmisConstraintException

use of org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException in project copper-cms by PogeyanOSS.

the class ChangeTokenTest method runUpdateFolderTest.

private void runUpdateFolderTest(Session session, Folder testFolder) {
    Folder folder = createFolder(session, testFolder, "folder1");
    try {
        if (folder.getChangeToken() == null) {
            addResult(createResult(SKIPPED, "Repository does not provide change tokens for folders. Test skipped!"));
            return;
        }
        if (!folder.getAllowableActions().getAllowableActions().contains(Action.CAN_UPDATE_PROPERTIES)) {
            addResult(createResult(SKIPPED, "Folder name can't be changed. Test skipped!"));
            return;
        }
        // the first update should succeed
        Map<String, Object> properties2 = new HashMap<String, Object>();
        properties2.put(PropertyIds.NAME, "folder2");
        folder.updateProperties(properties2, false);
        try {
            Map<String, Object> properties3 = new HashMap<String, Object>();
            properties3.put(PropertyIds.NAME, "folder3");
            folder.updateProperties(properties3, false);
            addResult(createResult(FAILURE, "Updating properties a second time with the same change token " + "should result in an UpdateConflict exception!"));
        // } catch (CmisUpdateConflictException e) {
        } catch (CmisConstraintException e) {
        // expected exception
        }
    } finally {
        deleteObject(folder);
    }
}
Also used : HashMap(java.util.HashMap) CmisConstraintException(org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException) Folder(org.apache.chemistry.opencmis.client.api.Folder)

Example 17 with CmisConstraintException

use of org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException in project structr by structr.

the class CMISObjectService method createFolder.

@Override
public String createFolder(final String repositoryId, final Properties properties, final String folderId, final List<String> policies, final Acl addAces, final Acl removeAces, final ExtensionsData extension) {
    final App app = StructrApp.getInstance(securityContext);
    String uuid = null;
    try (final Tx tx = app.tx()) {
        final String objectTypeId = getStringValue(properties, PropertyIds.OBJECT_TYPE_ID);
        final Class type = typeFromObjectTypeId(objectTypeId, BaseTypeId.CMIS_FOLDER, Folder.class);
        // check if type exists
        if (type != null) {
            // check that base type is cmis:folder
            final BaseTypeId baseTypeId = getBaseTypeId(type);
            if (baseTypeId != null && BaseTypeId.CMIS_FOLDER.equals(baseTypeId)) {
                // create folder
                final AbstractFile newFolder = (AbstractFile) app.create(type, PropertyMap.cmisTypeToJavaType(securityContext, type, properties));
                // find and set parent if it exists
                if (!CMISInfo.ROOT_FOLDER_ID.equals(folderId)) {
                    final Folder parent = app.get(Folder.class, folderId);
                    if (parent != null) {
                        newFolder.setParent(parent);
                    } else {
                        throw new CmisObjectNotFoundException("Folder with ID " + folderId + " does not exist");
                    }
                }
                uuid = newFolder.getUuid();
            } else {
                throw new CmisConstraintException("Cannot create cmis:folder of type " + objectTypeId);
            }
        } else {
            throw new CmisObjectNotFoundException("Type with ID " + objectTypeId + " does not exist");
        }
        tx.success();
    } catch (Throwable t) {
        throw new CmisRuntimeException("New folder could not be created: " + t.getMessage());
    }
    return uuid;
}
Also used : App(org.structr.core.app.App) StructrApp(org.structr.core.app.StructrApp) AbstractFile(org.structr.web.entity.AbstractFile) Tx(org.structr.core.graph.Tx) CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) CmisRuntimeException(org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException) CmisConstraintException(org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException) BaseTypeId(org.apache.chemistry.opencmis.commons.enums.BaseTypeId) Folder(org.structr.web.entity.Folder)

Example 18 with CmisConstraintException

use of org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException in project structr by structr.

the class CMISContentStream method getStream.

@Override
public InputStream getStream() {
    try {
        final FileChannel channel = FileChannel.open(file.toPath(), StandardOpenOption.READ);
        final long mappedLength = Math.max(0, Math.min(channel.size() - offset, length));
        final MappedByteBuffer buffer = channel.map(FileChannel.MapMode.READ_ONLY, offset, mappedLength);
        return new MappedInputStream(buffer);
    } catch (IOException ioex) {
        throw new CmisConstraintException(ioex.getMessage());
    }
}
Also used : MappedByteBuffer(java.nio.MappedByteBuffer) FileChannel(java.nio.channels.FileChannel) CmisConstraintException(org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException) IOException(java.io.IOException)

Aggregations

CmisConstraintException (org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException)18 CmisObjectNotFoundException (org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException)6 App (org.structr.core.app.App)6 StructrApp (org.structr.core.app.StructrApp)6 Tx (org.structr.core.graph.Tx)6 Document (org.apache.chemistry.opencmis.client.api.Document)5 CmisInvalidArgumentException (org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException)5 File (java.io.File)4 HashMap (java.util.HashMap)4 Folder (org.apache.chemistry.opencmis.client.api.Folder)4 FrameworkException (org.structr.common.error.FrameworkException)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 IOException (java.io.IOException)3 ContentStreamImpl (org.apache.chemistry.opencmis.commons.impl.dataobjects.ContentStreamImpl)3 AbstractNode (org.structr.core.entity.AbstractNode)3 AbstractFile (org.structr.web.entity.AbstractFile)3 Folder (org.structr.web.entity.Folder)3 InputStream (java.io.InputStream)2 FileChannel (java.nio.channels.FileChannel)2 ObjectId (org.apache.chemistry.opencmis.client.api.ObjectId)2