Search in sources :

Example 16 with CmisObjectNotFoundException

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

the class CMISAclService method applyAce.

// ----- private methods -----
private void applyAce(final AccessControllable node, final Ace toAdd, final boolean revoke) throws FrameworkException {
    final String principalId = toAdd.getPrincipalId();
    final List<String> permissions = toAdd.getPermissions();
    final Principal principal = CMISObjectWrapper.translateUsernameToPrincipal(principalId);
    if (principal != null) {
        for (final String permissionString : permissions) {
            final Permission permission = Permissions.valueOf(permissionString);
            if (permission != null) {
                if (revoke) {
                    node.revoke(permission, principal);
                } else {
                    node.grant(permission, principal);
                }
            } else {
                throw new CmisInvalidArgumentException("Permission with ID " + permissionString + " does not exist");
            }
        }
    } else {
        throw new CmisObjectNotFoundException("Principal with ID " + principalId + " does not exist");
    }
}
Also used : CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) Permission(org.structr.common.Permission) CmisInvalidArgumentException(org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException) Principal(org.structr.core.entity.Principal)

Example 17 with CmisObjectNotFoundException

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

the class CMISObjectService method getObject.

@Override
public ObjectData getObject(final String repositoryId, final String objectId, final String propertyFilter, final Boolean includeAllowableActions, final IncludeRelationships includeRelationships, final String renditionFilter, final Boolean includePolicyIds, final Boolean includeAcl, final ExtensionsData extension) {
    final App app = StructrApp.getInstance();
    try (final Tx tx = app.tx()) {
        final AbstractNode obj = app.get(AbstractNode.class, objectId);
        if (obj != null) {
            final ObjectData data = CMISObjectWrapper.wrap(obj, propertyFilter, includeAllowableActions);
            tx.success();
            return data;
        }
    } catch (Throwable t) {
        logger.warn("", t);
    }
    throw new CmisObjectNotFoundException("Object with ID " + objectId + " does not exist");
}
Also used : App(org.structr.core.app.App) StructrApp(org.structr.core.app.StructrApp) Tx(org.structr.core.graph.Tx) CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) AbstractNode(org.structr.core.entity.AbstractNode) ObjectData(org.apache.chemistry.opencmis.commons.data.ObjectData)

Example 18 with CmisObjectNotFoundException

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

the class CMISObjectService method updateProperties.

@Override
public void updateProperties(final String repositoryId, final Holder<String> objectId, final Holder<String> changeToken, final Properties properties, final ExtensionsData extension) {
    final App app = StructrApp.getInstance();
    final String id = objectId.getValue();
    try (final Tx tx = app.tx()) {
        final AbstractNode obj = app.get(AbstractNode.class, id);
        if (obj != null) {
            final PropertyMap propertyMap = PropertyMap.cmisTypeToJavaType(securityContext, obj.getClass(), properties);
            if (propertyMap != null) {
                obj.setProperties(securityContext, propertyMap);
            }
        } else {
            throw new CmisObjectNotFoundException("Object with ID " + objectId + " does not exist");
        }
        tx.success();
    } catch (FrameworkException fex) {
        throw new CmisConstraintException(fex.getMessage(), fex);
    }
}
Also used : App(org.structr.core.app.App) StructrApp(org.structr.core.app.StructrApp) PropertyMap(org.structr.core.property.PropertyMap) Tx(org.structr.core.graph.Tx) CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) FrameworkException(org.structr.common.error.FrameworkException) AbstractNode(org.structr.core.entity.AbstractNode) CmisConstraintException(org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException)

Example 19 with CmisObjectNotFoundException

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

the class CMISObjectService method deleteTree.

@Override
public FailedToDeleteData deleteTree(final String repositoryId, final String folderId, final Boolean allVersions, final UnfileObject unfileObjects, final Boolean continueOnFailure, final ExtensionsData extension) {
    if (UnfileObject.UNFILE.equals(unfileObjects)) {
        throw new CmisNotSupportedException("Unfiling not supported");
    }
    final App app = StructrApp.getInstance(securityContext);
    final FailedToDeleteDataImpl result = new FailedToDeleteDataImpl();
    result.setIds(new LinkedList<String>());
    try (final Tx tx = app.tx()) {
        final Folder folder = app.get(Folder.class, folderId);
        if (folder != null) {
            recursivelyCheckAndDeleteFiles(app, result, folder, continueOnFailure);
        } else {
            throw new CmisObjectNotFoundException("Folder with ID " + folderId + " does not exist");
        }
        tx.success();
    } catch (final FrameworkException fex) {
        logger.warn("", fex);
    }
    return result;
}
Also used : CmisNotSupportedException(org.apache.chemistry.opencmis.commons.exceptions.CmisNotSupportedException) App(org.structr.core.app.App) StructrApp(org.structr.core.app.StructrApp) Tx(org.structr.core.graph.Tx) CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) FrameworkException(org.structr.common.error.FrameworkException) FailedToDeleteDataImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.FailedToDeleteDataImpl) Folder(org.structr.web.entity.Folder)

Example 20 with CmisObjectNotFoundException

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

the class CMISObjectService method createDocument.

@Override
public String createDocument(final String repositoryId, final Properties properties, final String folderId, final ContentStream contentStream, final VersioningState versioningState, final List<String> policies, final Acl addAces, final Acl removeAces, final ExtensionsData extension) {
    final App app = StructrApp.getInstance(securityContext);
    File newFile = null;
    String uuid = null;
    try (final Tx tx = app.tx()) {
        final String objectTypeId = getStringValue(properties, PropertyIds.OBJECT_TYPE_ID);
        final String fileName = getStringValue(properties, PropertyIds.NAME);
        final Class type = typeFromObjectTypeId(objectTypeId, BaseTypeId.CMIS_DOCUMENT, File.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_DOCUMENT.equals(baseTypeId)) {
                final String mimeType = contentStream != null ? contentStream.getMimeType() : null;
                // create file
                newFile = FileHelper.createFile(securityContext, new byte[0], mimeType, type, fileName);
                if (newFile != null) {
                    // 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) {
                            newFile.setParent(parent);
                        } else {
                            throw new CmisObjectNotFoundException("Folder with ID " + folderId + " does not exist");
                        }
                    }
                    uuid = newFile.getUuid();
                    if (contentStream != null) {
                        final InputStream inputStream = contentStream.getStream();
                        if (inputStream != null) {
                            // copy file and update metadata
                            try (final OutputStream outputStream = newFile.getOutputStream(false, false)) {
                                IOUtils.copy(inputStream, outputStream);
                            }
                            inputStream.close();
                            FileHelper.updateMetadata(newFile);
                        }
                    }
                }
            } else {
                throw new CmisConstraintException("Cannot create cmis:document of type " + objectTypeId);
            }
        } else {
            throw new CmisObjectNotFoundException("Type with ID " + objectTypeId + " does not exist");
        }
        tx.success();
    } catch (Throwable t) {
        throw new CmisRuntimeException("New document could not be created: " + t.getMessage());
    }
    // start indexing after transaction is finished
    if (newFile != null) {
        newFile.notifyUploadCompletion();
    }
    return uuid;
}
Also used : App(org.structr.core.app.App) StructrApp(org.structr.core.app.StructrApp) Tx(org.structr.core.graph.Tx) CmisRuntimeException(org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException) InputStream(java.io.InputStream) CmisConstraintException(org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException) OutputStream(java.io.OutputStream) BaseTypeId(org.apache.chemistry.opencmis.commons.enums.BaseTypeId) Folder(org.structr.web.entity.Folder) CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) AbstractFile(org.structr.web.entity.AbstractFile) File(org.structr.web.entity.File)

Aggregations

CmisObjectNotFoundException (org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException)37 App (org.structr.core.app.App)12 StructrApp (org.structr.core.app.StructrApp)12 Tx (org.structr.core.graph.Tx)12 CmisTestResult (org.apache.chemistry.opencmis.tck.CmisTestResult)11 CmisObject (org.apache.chemistry.opencmis.client.api.CmisObject)9 ObjectType (org.apache.chemistry.opencmis.client.api.ObjectType)9 HashMap (java.util.HashMap)7 CmisBaseException (org.apache.chemistry.opencmis.commons.exceptions.CmisBaseException)7 CmisConstraintException (org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException)7 IOException (java.io.IOException)6 FrameworkException (org.structr.common.error.FrameworkException)6 AbstractFile (org.structr.web.entity.AbstractFile)6 FileableCmisObject (org.apache.chemistry.opencmis.client.api.FileableCmisObject)5 Folder (org.apache.chemistry.opencmis.client.api.Folder)5 CmisInvalidArgumentException (org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException)5 ArrayList (java.util.ArrayList)4 Document (org.apache.chemistry.opencmis.client.api.Document)4 ContentStream (org.apache.chemistry.opencmis.commons.data.ContentStream)4 DocumentTypeDefinition (org.apache.chemistry.opencmis.commons.definitions.DocumentTypeDefinition)4