Search in sources :

Example 81 with App

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

the class Actions method callWithSecurityContext.

public static Object callWithSecurityContext(final String key, final SecurityContext securityContext, final Map<String, Object> parameters) throws FrameworkException, UnlicensedException {
    final App app = StructrApp.getInstance(securityContext);
    // we might want to introduce caching here at some point in the future..
    // Cache can be invalidated when the schema is rebuilt for example..
    final List<SchemaMethod> methods = app.nodeQuery(SchemaMethod.class).andName(key).getAsList();
    if (methods.isEmpty()) {
        if (!NOTIFICATION_LOGIN.equals(key) && !NOTIFICATION_LOGOUT.equals(key)) {
            logger.warn("Tried to call method {} but no SchemaMethod entity was found.", key);
        }
    } else {
        for (final SchemaMethod method : methods) {
            // only call methods that are NOT part of a schema node
            final AbstractSchemaNode entity = method.getProperty(SchemaMethod.schemaNode);
            if (entity == null) {
                final String source = method.getProperty(SchemaMethod.source);
                if (source != null) {
                    return Actions.execute(securityContext, null, "${" + source + "}", parameters, method.getName());
                } else {
                    logger.warn("Schema method {} has no source code, will NOT be executed.", key);
                }
            } else {
                logger.warn("Schema method {} is attached to an entity, will NOT be executed.", key);
            }
        }
    }
    return null;
}
Also used : StructrApp(org.structr.core.app.StructrApp) App(org.structr.core.app.App) SchemaMethod(org.structr.core.entity.SchemaMethod) AbstractSchemaNode(org.structr.core.entity.AbstractSchemaNode)

Example 82 with App

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

the class DeleteSchemaNodeWhenMissingPackage method handleMigration.

@Override
public void handleMigration(final ErrorToken errorToken) throws FrameworkException {
    final Object messageObject = errorToken.getDetail();
    if (messageObject != null) {
        final String message = (String) messageObject;
        final Matcher matcher = PATTERN.matcher(message);
        if (matcher.matches()) {
            logger.info("Identified missing package {}, deleting entity {}", matcher.group(1), errorToken.getType());
            final App app = StructrApp.getInstance();
            final String name = errorToken.getType();
            final SchemaNode schemaNode = app.nodeQuery(SchemaNode.class).andName(name).getFirst();
            if (schemaNode != null) {
                logger.info("Deleting erroneous schema entity {}", schemaNode.getName());
                app.delete(schemaNode);
            } else {
                logger.info("No SchemaNode with name {} found, cannot delete.", name);
            }
        }
    }
}
Also used : StructrApp(org.structr.core.app.StructrApp) App(org.structr.core.app.App) SchemaNode(org.structr.core.entity.SchemaNode) Matcher(java.util.regex.Matcher)

Example 83 with App

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

the class ExtendNotionPropertyWithUuid method handleMigration.

@Override
public void handleMigration(final ErrorToken errorToken) throws FrameworkException {
    final Object messageObject = errorToken.getDetail();
    if (messageObject != null) {
        final String message = (String) messageObject;
        if (message.startsWith("Invalid notion property expression for property ") && message.endsWith(".")) {
            if (errorToken instanceof InvalidPropertySchemaToken) {
                final App app = StructrApp.getInstance();
                final InvalidPropertySchemaToken token = (InvalidPropertySchemaToken) errorToken;
                final String typeName = token.getType();
                final String propertyName = token.getProperty();
                final SchemaNode type = app.nodeQuery(SchemaNode.class).andName(typeName).getFirst();
                if (type != null) {
                    final SchemaProperty property = app.nodeQuery(SchemaProperty.class).and(SchemaProperty.schemaNode, type).and(SchemaProperty.name, propertyName).getFirst();
                    if (property != null) {
                        // load format property
                        final String format = property.getProperty(SchemaProperty.format);
                        // store corrected version of format property
                        property.setProperty(SchemaProperty.format, format + ", id");
                    }
                }
            }
        }
    }
}
Also used : StructrApp(org.structr.core.app.StructrApp) App(org.structr.core.app.App) SchemaNode(org.structr.core.entity.SchemaNode) SchemaProperty(org.structr.core.entity.SchemaProperty) InvalidPropertySchemaToken(org.structr.common.error.InvalidPropertySchemaToken)

Example 84 with App

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

the class RelationshipResource method doGet.

@Override
public Result doGet(final PropertyKey sortKey, final boolean sortDescending, final int pageSize, final int page) throws FrameworkException {
    // fetch all results, paging is applied later
    final List<? extends GraphObject> results = wrappedResource.doGet(null, false, NodeFactory.DEFAULT_PAGE_SIZE, NodeFactory.DEFAULT_PAGE).getResults();
    final App app = StructrApp.getInstance();
    if (results != null && !results.isEmpty()) {
        try {
            final List<GraphObject> resultList = new LinkedList<>();
            for (GraphObject obj : results) {
                if (obj instanceof AbstractNode) {
                    final List<? extends RelationshipInterface> relationships = Direction.INCOMING.equals(direction) ? Iterables.toList(((AbstractNode) obj).getIncomingRelationships()) : Iterables.toList(((AbstractNode) obj).getOutgoingRelationships());
                    if (relationships != null) {
                        boolean filterInternalRelationshipTypes = false;
                        if (securityContext != null && securityContext.getRequest() != null) {
                            final String filterInternal = securityContext.getRequest().getParameter(REQUEST_PARAMETER_FILTER_INTERNAL_RELATIONSHIP_TYPES);
                            if (filterInternal != null) {
                                filterInternalRelationshipTypes = "true".equals(filterInternal);
                            }
                        }
                        // the result set using the request parameter "filterInternal=true"
                        if (filterInternalRelationshipTypes) {
                            for (final RelationshipInterface rel : relationships) {
                                if (!rel.isInternal()) {
                                    resultList.add(rel);
                                }
                            }
                        } else {
                            resultList.addAll(relationships);
                        }
                    }
                }
            }
            final int rawResultCount = resultList.size();
            return new Result(PagingHelper.subList(resultList, pageSize, page), rawResultCount, true, false);
        } catch (Throwable t) {
            logger.warn("Exception while fetching relationships", t);
        }
    } else {
        logger.info("No results from parent..");
    }
    throw new IllegalPathException(getResourceSignature() + " can only be applied to a non-empty resource");
}
Also used : StructrApp(org.structr.core.app.StructrApp) App(org.structr.core.app.App) IllegalPathException(org.structr.rest.exception.IllegalPathException) AbstractNode(org.structr.core.entity.AbstractNode) GraphObject(org.structr.core.GraphObject) LinkedList(java.util.LinkedList) Result(org.structr.core.Result) RelationshipInterface(org.structr.core.graph.RelationshipInterface)

Example 85 with App

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

the class Resource method doDelete.

public RestMethodResult doDelete() throws FrameworkException {
    final App app = StructrApp.getInstance(securityContext);
    Iterable<GraphObject> results = null;
    // catch 204, DELETE must return 200 if resource is empty
    try (final Tx tx = app.tx(false, false, false)) {
        results = doGet(null, false, NodeFactory.DEFAULT_PAGE_SIZE, NodeFactory.DEFAULT_PAGE).getResults();
        tx.success();
    } catch (final NoResultsException nre) {
        results = null;
    }
    if (results != null) {
        app.command(BulkDeleteCommand.class).bulkDelete(results.iterator());
    }
    return new RestMethodResult(HttpServletResponse.SC_OK);
}
Also used : StructrApp(org.structr.core.app.StructrApp) App(org.structr.core.app.App) NoResultsException(org.structr.rest.exception.NoResultsException) Tx(org.structr.core.graph.Tx) BulkDeleteCommand(org.structr.core.graph.BulkDeleteCommand) GraphObject(org.structr.core.GraphObject) RestMethodResult(org.structr.rest.RestMethodResult)

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