Search in sources :

Example 66 with App

use of org.structr.core.app.App in project structr by structr.

the class CMISObjectService method getContentStream.

@Override
public ContentStream getContentStream(final String repositoryId, final String objectId, final String streamId, final BigInteger offset, final BigInteger length, final ExtensionsData extension) {
    final App app = StructrApp.getInstance();
    ContentStreamImpl result = null;
    try (final Tx tx = app.tx()) {
        final File file = app.get(File.class, objectId);
        if (file != null) {
            return new CMISContentStream(file, offset, length);
        }
        tx.success();
    } catch (Throwable t) {
        logger.warn("", t);
    }
    if (result != null) {
        return result;
    }
    throw new CmisObjectNotFoundException("Object with ID " + objectId + " does not exist");
}
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) AbstractFile(org.structr.web.entity.AbstractFile) File(org.structr.web.entity.File) CMISContentStream(org.structr.files.cmis.wrapper.CMISContentStream)

Example 67 with App

use of org.structr.core.app.App in project structr by structr.

the class CMISObjectService method getObjectByPath.

@Override
public ObjectData getObjectByPath(final String repositoryId, final String path, final String propertyFilter, final Boolean includeAllowableActions, final IncludeRelationships includeRelationships, final String renditionFilter, final Boolean includePolicyIds, final Boolean includeAcl, final ExtensionsData extension) {
    final PropertyKey<String> pathKey = StructrApp.key(AbstractFile.class, "path");
    final App app = StructrApp.getInstance();
    ObjectData result = null;
    try (final Tx tx = app.tx()) {
        final AbstractFile file = app.nodeQuery(AbstractFile.class).and(pathKey, path).getFirst();
        if (file != null) {
            result = CMISObjectWrapper.wrap(file, propertyFilter, includeAllowableActions);
        }
        tx.success();
    } catch (Throwable t) {
        logger.warn("", t);
    }
    if (result != null) {
        return result;
    }
    throw new CmisObjectNotFoundException("Object with path " + path + " does not exist");
}
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) ObjectData(org.apache.chemistry.opencmis.commons.data.ObjectData)

Example 68 with App

use of org.structr.core.app.App in project structr by structr.

the class CMISObjectService method bulkUpdateProperties.

@Override
public List<BulkUpdateObjectIdAndChangeToken> bulkUpdateProperties(final String repositoryId, final List<BulkUpdateObjectIdAndChangeToken> objectIdsAndChangeTokens, final Properties properties, final List<String> addSecondaryTypeIds, final List<String> removeSecondaryTypeIds, final ExtensionsData extension) {
    final List<BulkUpdateObjectIdAndChangeToken> result = new LinkedList<>();
    final App app = StructrApp.getInstance(securityContext);
    try (final Tx tx = app.tx()) {
        for (final BulkUpdateObjectIdAndChangeToken token : objectIdsAndChangeTokens) {
            final AbstractNode obj = app.get(AbstractNode.class, token.getId());
            if (obj != null) {
                final PropertyMap propertyMap = PropertyMap.cmisTypeToJavaType(securityContext, obj.getClass(), properties);
                if (propertyMap != null) {
                    obj.setProperties(securityContext, propertyMap);
                }
                result.add(token);
            }
        }
        tx.success();
    } catch (FrameworkException fex) {
        throw new CmisConstraintException(fex.getMessage(), fex);
    }
    return result;
}
Also used : App(org.structr.core.app.App) StructrApp(org.structr.core.app.StructrApp) BulkUpdateObjectIdAndChangeToken(org.apache.chemistry.opencmis.commons.data.BulkUpdateObjectIdAndChangeToken) PropertyMap(org.structr.core.property.PropertyMap) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) AbstractNode(org.structr.core.entity.AbstractNode) CmisConstraintException(org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException) LinkedList(java.util.LinkedList)

Example 69 with App

use of org.structr.core.app.App in project structr by structr.

the class CMISObjectService method deleteObject.

@Override
public void deleteObject(String repositoryId, String objectId, Boolean allVersions, ExtensionsData extension) {
    final App app = StructrApp.getInstance(securityContext);
    try (final Tx tx = app.tx()) {
        final Principal principal = securityContext.getUser(false);
        final AbstractNode obj = app.get(AbstractNode.class, objectId);
        if (obj != null) {
            if (principal.isGranted(Permission.delete, securityContext)) {
                if (obj.isNode()) {
                    // getSyncNode() returns the node or null
                    app.delete(obj.getSyncNode());
                } else {
                    // getSyncRelationship() return the relationship or null
                    app.delete(obj.getSyncRelationship());
                }
            } else {
                throw new CmisPermissionDeniedException("Cannot delete object with ID " + objectId);
            }
        } 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) 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) CmisPermissionDeniedException(org.apache.chemistry.opencmis.commons.exceptions.CmisPermissionDeniedException) Principal(org.structr.core.entity.Principal)

Example 70 with App

use of org.structr.core.app.App in project structr by structr.

the class DirectoryWatchService method startService.

@Override
public void startService() throws Exception {
    try {
        final Path dir = Paths.get(Settings.FilesPath.getValue());
        this.watchService = dir.getFileSystem().newWatchService();
        logger.info("Watch service successfully registered");
    } catch (IOException ioex) {
        ioex.printStackTrace();
    }
    final PropertyKey<String> mountTargetKey = StructrApp.key(Folder.class, "mountTarget");
    final App app = StructrApp.getInstance();
    try (final Tx tx = app.tx(false, false, false)) {
        // find all folders with mount targets and mount them
        for (final Folder folder : app.nodeQuery(Folder.class).notBlank(mountTargetKey).getAsList()) {
            mountFolder(folder);
        }
        tx.success();
    }
    running = true;
    this.start();
}
Also used : Path(java.nio.file.Path) StructrApp(org.structr.core.app.StructrApp) App(org.structr.core.app.App) Tx(org.structr.core.graph.Tx) IOException(java.io.IOException) Folder(org.structr.web.entity.Folder)

Aggregations

App (org.structr.core.app.App)296 StructrApp (org.structr.core.app.StructrApp)294 Tx (org.structr.core.graph.Tx)201 FrameworkException (org.structr.common.error.FrameworkException)176 LinkedList (java.util.LinkedList)60 SecurityContext (org.structr.common.SecurityContext)56 PropertyMap (org.structr.core.property.PropertyMap)41 Folder (org.structr.web.entity.Folder)38 GraphObject (org.structr.core.GraphObject)35 Principal (org.structr.core.entity.Principal)31 IOException (java.io.IOException)30 AbstractFile (org.structr.web.entity.AbstractFile)27 AbstractNode (org.structr.core.entity.AbstractNode)26 Test (org.junit.Test)24 NodeAttribute (org.structr.core.graph.NodeAttribute)24 File (org.structr.web.entity.File)23 NodeInterface (org.structr.core.graph.NodeInterface)22 SchemaNode (org.structr.core.entity.SchemaNode)19 PropertyKey (org.structr.core.property.PropertyKey)17 Map (java.util.Map)16