Search in sources :

Example 31 with CmisObjectNotFoundException

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

the class CreateAndDeleteTypeTest method createTypeWithoutProperties.

private void createTypeWithoutProperties(Session session, ObjectType parentType) {
    CmisTestResult failure = null;
    // define the type
    DocumentTypeDefinitionImpl newTypeDef = createDocumentTypeDefinition(session, "tck:testid_without_properties", parentType);
    // create the type
    ObjectType newType = createType(session, newTypeDef);
    if (newType == null) {
        return;
    }
    // get the type
    ObjectType newType2 = null;
    try {
        newType2 = session.getTypeDefinition(newType.getId());
        // assert type definitions
        failure = createResult(FAILURE, "The type definition returned by createType() doesn't match the type definition returned by getTypeDefinition()!");
        addResult(assertEquals(newType, newType2, null, failure));
    } catch (CmisObjectNotFoundException e) {
        addResult(createResult(FAILURE, "Newly created type can not be fetched. Id: " + newType.getId(), e, false));
    }
    // delete the type
    deleteType(session, newType.getId());
}
Also used : ObjectType(org.apache.chemistry.opencmis.client.api.ObjectType) CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) CmisTestResult(org.apache.chemistry.opencmis.tck.CmisTestResult) DocumentTypeDefinitionImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.DocumentTypeDefinitionImpl)

Example 32 with CmisObjectNotFoundException

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

the class CMISAclService method applyAcl.

/**
 * Applies the given Acl exclusively, i.e. removes all other permissions / grants first.
 *
 * @param repositoryId
 * @param objectId
 * @param acl
 * @param aclPropagation
 *
 * @return the resulting Acl
 */
public Acl applyAcl(final String repositoryId, final String objectId, final Acl acl, final AclPropagation aclPropagation) {
    final App app = StructrApp.getInstance(securityContext);
    try (final Tx tx = app.tx()) {
        final AbstractNode node = app.get(AbstractNode.class, objectId);
        if (node != null) {
            node.revokeAll();
            // process add ACL entries
            for (final Ace toAdd : acl.getAces()) {
                applyAce(node, toAdd, false);
            }
            tx.success();
            // return the wrapper which implements the Acl interface
            return CMISObjectWrapper.wrap(node, null, false);
        }
    } catch (FrameworkException fex) {
        logger.warn("", fex);
    }
    throw new CmisObjectNotFoundException("Object with ID " + objectId + " does not exist");
}
Also used : StructrApp(org.structr.core.app.StructrApp) App(org.structr.core.app.App) Ace(org.apache.chemistry.opencmis.commons.data.Ace) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) AbstractNode(org.structr.core.entity.AbstractNode)

Example 33 with CmisObjectNotFoundException

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

the class CMISNavigationService method getChildrenQuery.

public Query<AbstractFile> getChildrenQuery(final App app, final String folderId) throws FrameworkException {
    final Query<AbstractFile> query = app.nodeQuery(AbstractFile.class).sort(AbstractNode.name);
    final PropertyKey<Folder> parent = StructrApp.key(AbstractFile.class, "parent");
    final PropertyKey<Boolean> hasParent = StructrApp.key(AbstractFile.class, "hasParent");
    final PropertyKey<Boolean> isThumbnail = StructrApp.key(Image.class, "isThumbnail");
    if (CMISInfo.ROOT_FOLDER_ID.equals(folderId)) {
        query.and(hasParent, false).and(isThumbnail, false);
    } else {
        final Folder folder = app.get(Folder.class, folderId);
        if (folder != null) {
            query.and(parent, folder).and(isThumbnail, false);
        } else {
            throw new CmisObjectNotFoundException("Folder with ID " + folderId + " does not exist");
        }
    }
    return query;
}
Also used : AbstractFile(org.structr.web.entity.AbstractFile) CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) CMISRootFolder(org.structr.files.cmis.repository.CMISRootFolder) Folder(org.structr.web.entity.Folder)

Example 34 with CmisObjectNotFoundException

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

the class CMISNavigationService method getFolderTree.

@Override
public List<ObjectInFolderContainer> getFolderTree(final String repositoryId, final String folderId, final BigInteger depth, final String filter, final Boolean includeAllowableActions, final IncludeRelationships includeRelationships, final String renditionFilter, final Boolean includePathSegment, final ExtensionsData extension) {
    final PropertyKey<Folder> parentKey = StructrApp.key(AbstractFile.class, "parent");
    final List<ObjectInFolderContainer> result = new LinkedList<>();
    final App app = StructrApp.getInstance();
    try (final Tx tx = app.tx()) {
        int maxDepth = Integer.MAX_VALUE;
        if (depth != null && depth.intValue() >= 0) {
            maxDepth = depth.intValue();
        }
        if (CMISInfo.ROOT_FOLDER_ID.equals(folderId)) {
            for (final Folder folder : app.nodeQuery(Folder.class).and(parentKey, null).sort(AbstractNode.name).getAsList()) {
                recursivelyCollectFolderTree(result, folder, maxDepth, 1, includeAllowableActions);
            }
        } else {
            final Folder folder = app.get(Folder.class, folderId);
            if (folder != null) {
                final List<Folder> children = Iterables.toList(folder.getFolders());
                Collections.sort(children, new GraphObjectComparator(AbstractNode.name, false));
                for (final Folder child : children) {
                    recursivelyCollectFolderTree(result, child, maxDepth, 1, includeAllowableActions);
                }
            } else {
                throw new CmisObjectNotFoundException("Folder with ID " + folderId + " does not exist");
            }
        }
        tx.success();
    } catch (final FrameworkException fex) {
        logger.warn("", fex);
    }
    return result;
}
Also used : StructrApp(org.structr.core.app.StructrApp) App(org.structr.core.app.App) Tx(org.structr.core.graph.Tx) CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) FrameworkException(org.structr.common.error.FrameworkException) GraphObjectComparator(org.structr.common.GraphObjectComparator) CMISRootFolder(org.structr.files.cmis.repository.CMISRootFolder) Folder(org.structr.web.entity.Folder) ObjectInFolderContainer(org.apache.chemistry.opencmis.commons.data.ObjectInFolderContainer) LinkedList(java.util.LinkedList)

Example 35 with CmisObjectNotFoundException

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

the class CMISObjectService method createDocumentFromSource.

@Override
public String createDocumentFromSource(String repositoryId, String sourceId, Properties properties, String folderId, VersioningState versioningState, List<String> policies, Acl addAces, Acl removeAces, ExtensionsData extension) {
    // copy existing document
    final App app = StructrApp.getInstance(securityContext);
    String uuid = null;
    try (final Tx tx = app.tx()) {
        final File existingDocument = app.get(File.class, sourceId);
        if (existingDocument != null) {
            try (final InputStream inputStream = existingDocument.getInputStream()) {
                final ContentStreamImpl copyContentStream = new ContentStreamImpl();
                copyContentStream.setFileName(existingDocument.getName());
                copyContentStream.setMimeType(existingDocument.getContentType());
                copyContentStream.setLength(BigInteger.valueOf(existingDocument.getSize()));
                copyContentStream.setStream(inputStream);
                uuid = createDocument(repositoryId, properties, folderId, copyContentStream, versioningState, policies, addAces, removeAces, extension);
            }
        } else {
            throw new CmisObjectNotFoundException("Document with ID " + sourceId + " does not exist");
        }
        tx.success();
    } catch (Throwable t) {
        throw new CmisRuntimeException("New document could not be created: " + t.getMessage());
    }
    return uuid;
}
Also used : App(org.structr.core.app.App) StructrApp(org.structr.core.app.StructrApp) ContentStreamImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.ContentStreamImpl) Tx(org.structr.core.graph.Tx) CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) CmisRuntimeException(org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException) InputStream(java.io.InputStream) 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