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