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();
}
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);
}
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 "";
}
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;
}
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 "";
}
Aggregations