use of org.structr.core.entity.SchemaMethod in project structr by structr.
the class StructrSchemaMethodsPath method getDirectoryStream.
@Override
public DirectoryStream<Path> getDirectoryStream(final DirectoryStream.Filter<? super Path> filter) {
if (schemaNode != null) {
return new DirectoryStream() {
boolean closed = false;
@Override
public Iterator iterator() {
final App app = StructrApp.getInstance(fs.getSecurityContext());
final List<StructrPath> nodes = new LinkedList<>();
try (final Tx tx = app.tx()) {
for (final SchemaMethod schemaMethod : schemaNode.getProperty(SchemaNode.schemaMethods)) {
// schema methods have a virtual file name so that external editors don't get confused
String name = schemaMethod.getProperty(SchemaMethod.virtualFileName);
if (name == null) {
// no virtual file name set, use real name
name = schemaMethod.getName();
}
nodes.add(new StructrSchemaMethodPath(fs, StructrSchemaMethodsPath.this, schemaNode, name));
}
tx.success();
} catch (FrameworkException fex) {
logger.warn("", fex);
}
return nodes.iterator();
}
@Override
public void close() throws IOException {
closed = true;
}
};
}
return null;
}
use of org.structr.core.entity.SchemaMethod in project structr by structr.
the class SchemaHelper method extractMethods.
public static void extractMethods(final AbstractSchemaNode entity, final Map<String, List<ActionEntry>> actions) throws FrameworkException {
final PropertyContainer propertyContainer = entity.getPropertyContainer();
for (final String rawActionName : getActions(propertyContainer)) {
if (propertyContainer.hasProperty(rawActionName)) {
final String value = propertyContainer.getProperty(rawActionName).toString();
if (entity instanceof AbstractSchemaNode) {
final AbstractSchemaNode schemaNode = (AbstractSchemaNode) entity;
final App app = StructrApp.getInstance();
final String methodName = rawActionName.substring(3);
if (app.nodeQuery(SchemaMethod.class).and(SchemaMethod.schemaNode, schemaNode).and(AbstractNode.name, methodName).getFirst() == null) {
app.create(SchemaMethod.class, new NodeAttribute<>(SchemaMethod.schemaNode, schemaNode), new NodeAttribute<>(SchemaMethod.name, methodName), new NodeAttribute<>(SchemaMethod.source, value));
schemaNode.removeProperty(new StringProperty(rawActionName));
}
}
}
}
final List<SchemaMethod> schemaMethods = entity.getSchemaMethods();
if (schemaMethods != null) {
for (final SchemaMethod schemaMethod : schemaMethods) {
final ActionEntry entry = schemaMethod.getActionEntry(entity);
final String name = entry.getName();
List<ActionEntry> actionList = actions.get(name);
if (actionList == null) {
actionList = new LinkedList<>();
actions.put(name, actionList);
}
actionList.add(entry);
Collections.sort(actionList);
}
}
}
use of org.structr.core.entity.SchemaMethod in project structr by structr.
the class StructrGlobalSchemaMethods method deserialize.
void deserialize(final App app) throws FrameworkException {
try (final Tx tx = app.tx()) {
for (final SchemaMethod schemaMethod : app.nodeQuery(SchemaMethod.class).and(SchemaMethod.schemaNode, null).sort(SchemaMethod.name).getAsList()) {
final Map<String, Object> entry = new TreeMap<>();
globalMethods.add(entry);
entry.put("name", schemaMethod.getProperty(SchemaMethod.name));
entry.put("comment", schemaMethod.getProperty(SchemaMethod.comment));
entry.put("source", schemaMethod.getProperty(SchemaMethod.source));
entry.put("virtualFileName", schemaMethod.getProperty(SchemaMethod.virtualFileName));
entry.put("visibleToAuthenticatedUsers", schemaMethod.getProperty(SchemaMethod.visibleToAuthenticatedUsers));
entry.put("visibleToPublicUsers", schemaMethod.getProperty(SchemaMethod.visibleToPublicUsers));
}
tx.success();
}
}
use of org.structr.core.entity.SchemaMethod 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.entity.SchemaMethod in project structr by structr.
the class GlobalSchemaMethodResource method checkAndConfigure.
@Override
public boolean checkAndConfigure(final String part, final SecurityContext securityContext, final HttpServletRequest request) {
this.securityContext = securityContext;
final App app = StructrApp.getInstance(securityContext);
try (final Tx tx = app.tx()) {
final List<SchemaMethod> methods = app.nodeQuery(SchemaMethod.class).andName(part).and(SchemaMethod.schemaNode, null).getAsList();
tx.success();
if (!methods.isEmpty()) {
this.methodName = part;
return true;
}
} catch (FrameworkException fex) {
fex.printStackTrace();
}
return false;
}
Aggregations