Search in sources :

Example 6 with App

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

the class FlushCachesCommand method flushAll.

public static void flushAll() {
    NodeWrapper.clearCache();
    RelationshipWrapper.clearCache();
    AccessPathCache.invalidate();
    App app = StructrApp.getInstance();
    app.invalidateCache();
}
Also used : StructrApp(org.structr.core.app.StructrApp) App(org.structr.core.app.App)

Example 7 with App

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

the class BulkDeleteCommand method bulkDelete.

public void bulkDelete(final Iterator<GraphObject> iterator) throws FrameworkException {
    final App app = StructrApp.getInstance(securityContext);
    final long count = bulkGraphOperation(securityContext, iterator, 1000, "DeleteObjects", new BulkGraphOperation<GraphObject>() {

        @Override
        public void handleGraphObject(final SecurityContext securityContext, final GraphObject obj) {
            try {
                if (obj.isNode()) {
                    final AbstractNode node = (AbstractNode) obj;
                    if (!node.isGranted(Permission.delete, securityContext)) {
                        logger.warn("Could not delete {} because {} has no delete permission", obj.getUuid(), securityContext.getUser(false));
                    } else {
                        app.delete((NodeInterface) obj);
                    }
                } else {
                    app.delete((RelationshipInterface) obj);
                }
            } catch (FrameworkException fex) {
                logger.warn("Unable to delete node {}: {}", obj.getUuid(), fex.toString());
            }
        }

        @Override
        public void handleThrowable(SecurityContext securityContext, Throwable t, GraphObject node) {
            logger.warn("Unable to delete node {}", node.getUuid());
        }

        @Override
        public void handleTransactionFailure(SecurityContext securityContext, Throwable t) {
            logger.warn("Unable to delete nodes {}", t.toString());
        }
    });
    info("Done with deleting {} nodes", count);
}
Also used : StructrApp(org.structr.core.app.StructrApp) App(org.structr.core.app.App) FrameworkException(org.structr.common.error.FrameworkException) AbstractNode(org.structr.core.entity.AbstractNode) SecurityContext(org.structr.common.SecurityContext) GraphObject(org.structr.core.GraphObject)

Example 8 with App

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

the class TemplateFunction method apply.

@Override
public Object apply(final ActionContext ctx, final Object caller, final Object[] sources) throws FrameworkException {
    if (sources == null || sources != null && sources.length != 3) {
        logParameterError(caller, sources, ctx.isJavaScriptContext());
        return usage(ctx.isJavaScriptContext());
    }
    try {
        if (!(arrayHasLengthAndAllElementsNotNull(sources, 3) && sources[2] instanceof GraphObject)) {
            return null;
        }
        final Class type = StructrApp.getConfiguration().getNodeEntityClass("MailTemplate");
        final PropertyKey<String> localeKey = StructrApp.key(type, "locale");
        final PropertyKey<String> textKey = StructrApp.key(type, "text");
        final App app = StructrApp.getInstance(ctx.getSecurityContext());
        final String name = sources[0].toString();
        final String locale = sources[1].toString();
        final GraphObject template = app.nodeQuery(type).andName(name).and(localeKey, locale).getFirst();
        final GraphObject templateInstance = (GraphObject) sources[2];
        if (template != null) {
            final String text = template.getProperty(textKey);
            if (text != null) {
                // recursive replacement call, be careful here
                return Scripting.replaceVariables(ctx, templateInstance, text);
            }
        } else {
            logger.warn("No MailTemplate found for parameters: {}", getParametersAsString(sources));
        }
    } catch (final IllegalArgumentException e) {
        logParameterError(caller, sources, ctx.isJavaScriptContext());
        return usage(ctx.isJavaScriptContext());
    }
    return "";
}
Also used : StructrApp(org.structr.core.app.StructrApp) App(org.structr.core.app.App) GraphObject(org.structr.core.GraphObject)

Example 9 with App

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

the class StructrLDAPWrapper method getRoot.

private LDAPNode getRoot() throws FrameworkException {
    final Class type = StructrApp.getConfiguration().getNodeEntityClass("LDAPNode");
    final App app = app();
    LDAPNode root = (LDAPNode) app.nodeQuery(type).andName(partitionId).getFirst();
    if (root == null) {
        root = app.create(type, new NodeAttribute<>(StructrApp.key(LDAPNode.class, "name"), partitionId), new NodeAttribute<>(StructrApp.key(LDAPNode.class, "isRoot"), true));
    }
    return root;
}
Also used : StructrApp(org.structr.core.app.StructrApp) App(org.structr.core.app.App) LDAPNode(org.structr.ldap.entity.LDAPNode) NodeAttribute(org.structr.core.graph.NodeAttribute)

Example 10 with App

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

the class ParseJavaFunction method apply.

@Override
public Object apply(final ActionContext ctx, final Object caller, final Object[] sources) throws FrameworkException {
    try {
        if (!(arrayHasLengthAndAllElementsNotNull(sources, 1) && sources[0] instanceof String)) {
            return null;
        }
        try {
            final SecurityContext securityContext = ctx.getSecurityContext();
            final App app = StructrApp.getInstance(securityContext);
            // Parse string as Java code
            final String resultJson = new GsonBuilder().setPrettyPrinting().create().toJson(new JavaParserModule(app).parse((String) sources[0]).get());
            return resultJson;
        } catch (final ParseProblemException ex) {
            logException(caller, ex, sources);
        }
    } catch (final IllegalArgumentException e) {
        logParameterError(caller, sources, ctx.isJavaScriptContext());
        return usage(ctx.isJavaScriptContext());
    }
    return "";
}
Also used : StructrApp(org.structr.core.app.StructrApp) App(org.structr.core.app.App) GsonBuilder(com.google.gson.GsonBuilder) SecurityContext(org.structr.common.SecurityContext) ParseProblemException(com.github.javaparser.ParseProblemException)

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