use of org.structr.core.graph.NodeInterface in project structr by structr.
the class UiSyncCommand method doExport.
// ----- private methods -----
private void doExport(final String fileName) throws FrameworkException {
// collect all nodes etc that belong to the frontend (including files)
// and export them to the given output file
final Set<RelationshipInterface> rels = new LinkedHashSet<>();
final Set<NodeInterface> nodes = new LinkedHashSet<>();
final Set<String> filePaths = new LinkedHashSet<>();
final App app = StructrApp.getInstance();
try (final Tx tx = app.tx()) {
// collect folders that are marked for export
for (final Folder folder : app.nodeQuery(Folder.class).and(StructrApp.key(Folder.class, "includeInFrontendExport"), true).getAsList()) {
collectDataRecursively(app, folder, nodes, rels, filePaths);
}
// collect pages (including files, shared components etc.)
for (final Page page : app.nodeQuery(Page.class).getAsList()) {
collectDataRecursively(app, page, nodes, rels, filePaths);
}
SyncCommand.exportToFile(fileName, nodes, rels, filePaths, true);
tx.success();
}
}
use of org.structr.core.graph.NodeInterface in project structr by structr.
the class UserConsoleCommand method handleDelete.
private void handleDelete(final SecurityContext securityContext, final Writable writable, final String name, final String confirm) throws FrameworkException, IOException {
if (StringUtils.isEmpty(name)) {
throw new FrameworkException(422, "Missing user name for delete command.");
}
final Class<? extends NodeInterface> type = StructrApp.getConfiguration().getNodeEntityClass("User");
final App app = StructrApp.getInstance(securityContext);
if (type != null) {
try (final Tx tx = app.tx()) {
NodeInterface user = app.nodeQuery(type).andName(name).getFirst();
if (user == null) {
user = app.get(type, name);
}
if (user != null) {
if (user.getProperty(Principal.ownedNodes).isEmpty()) {
app.delete(user);
writable.println("User deleted.");
} else {
final String hash = user.getUuid().substring(7, 11);
if (confirm == null || !confirm.equals(hash)) {
writable.print("User '");
writable.print(name);
writable.print("' has owned nodes, please confirm deletion with 'user delete ");
writable.print(name);
writable.print(" ");
writable.print(hash);
writable.println("'.");
} else {
app.delete(user);
writable.println("User deleted.");
}
}
} else {
throw new FrameworkException(422, "User " + name + " not found.");
}
tx.success();
}
} else {
throw new FrameworkException(422, "Cannot delete user, no User class found.");
}
}
use of org.structr.core.graph.NodeInterface in project structr by structr.
the class GetIncomingRelationshipsFunction method apply.
@Override
public Object apply(final ActionContext ctx, final Object caller, final Object[] sources) throws FrameworkException {
final List<AbstractRelationship> list = new ArrayList<>();
if (arrayHasMinLengthAndMaxLengthAndAllElementsNotNull(sources, 2, 3)) {
final Object source = sources[0];
final Object target = sources[1];
AbstractNode sourceNode = null;
AbstractNode targetNode = null;
if (source instanceof AbstractNode && target instanceof AbstractNode) {
sourceNode = (AbstractNode) source;
targetNode = (AbstractNode) target;
} else {
logger.warn("Error: entities are not nodes. Parameters: {}", getParametersAsString(sources));
return "Error: entities are not nodes.";
}
if (sources.length == 2) {
for (final AbstractRelationship rel : sourceNode.getIncomingRelationships()) {
final NodeInterface s = rel.getSourceNode();
final NodeInterface t = rel.getTargetNode();
// We need to check if current user can see source and target node which is often not the case for OWNS or SECURITY rels
if (s != null && t != null && s.equals(targetNode) && t.equals(sourceNode)) {
list.add(rel);
}
}
} else if (sources.length == 3) {
// dont try to create the relClass because we would need to do that both ways!!! otherwise it just fails if the nodes are in the "wrong" order (see tests:890f)
final String relType = (String) sources[2];
for (final AbstractRelationship rel : sourceNode.getIncomingRelationships()) {
final NodeInterface s = rel.getSourceNode();
final NodeInterface t = rel.getTargetNode();
// We need to check if current user can see source and target node which is often not the case for OWNS or SECURITY rels
if (s != null && t != null && rel.getRelType().name().equals(relType) && s.equals(targetNode) && t.equals(sourceNode)) {
list.add(rel);
}
}
}
} else {
logParameterError(caller, sources, ctx.isJavaScriptContext());
}
return list;
}
use of org.structr.core.graph.NodeInterface in project structr by structr.
the class HasIncomingRelationshipFunction method apply.
@Override
public Object apply(final ActionContext ctx, final Object caller, final Object[] sources) throws FrameworkException {
if (arrayHasMinLengthAndMaxLengthAndAllElementsNotNull(sources, 2, 3)) {
final Object source = sources[0];
final Object target = sources[1];
AbstractNode sourceNode = null;
AbstractNode targetNode = null;
if (source instanceof AbstractNode && target instanceof AbstractNode) {
sourceNode = (AbstractNode) source;
targetNode = (AbstractNode) target;
} else {
logger.warn("Error: entities are not nodes. Parameters: {}", getParametersAsString(sources));
return "Error: entities are not nodes.";
}
if (sources.length == 2) {
for (final AbstractRelationship rel : sourceNode.getIncomingRelationships()) {
final NodeInterface s = rel.getSourceNode();
final NodeInterface t = rel.getTargetNode();
// We need to check if current user can see source and target node which is often not the case for OWNS or SECURITY rels
if (s != null & t != null && s.equals(targetNode) && t.equals(sourceNode)) {
return true;
}
}
} else if (sources.length == 3) {
// dont try to create the relClass because we would need to do that both ways!!! otherwise it just fails if the nodes are in the "wrong" order (see tests:890f)
final String relType = (String) sources[2];
for (final AbstractRelationship rel : sourceNode.getIncomingRelationships()) {
final NodeInterface s = rel.getSourceNode();
final NodeInterface t = rel.getTargetNode();
// We need to check if current user can see source and target node which is often not the case for OWNS or SECURITY rels
if (s != null & t != null && rel.getRelType().name().equals(relType) && s.equals(targetNode) && t.equals(sourceNode)) {
return true;
}
}
}
} else {
logParameterError(caller, sources, ctx.isJavaScriptContext());
}
return false;
}
use of org.structr.core.graph.NodeInterface in project structr by structr.
the class HasOutgoingRelationshipFunction method apply.
@Override
public Object apply(final ActionContext ctx, final Object caller, final Object[] sources) throws FrameworkException {
if (arrayHasMinLengthAndMaxLengthAndAllElementsNotNull(sources, 2, 3)) {
final Object source = sources[0];
final Object target = sources[1];
AbstractNode sourceNode = null;
AbstractNode targetNode = null;
if (source instanceof AbstractNode && target instanceof AbstractNode) {
sourceNode = (AbstractNode) source;
targetNode = (AbstractNode) target;
} else {
logger.warn("Error: entities are not nodes. Parameters: {}", getParametersAsString(sources));
return "Error: entities are not nodes.";
}
if (sources.length == 2) {
for (final AbstractRelationship rel : sourceNode.getOutgoingRelationships()) {
final NodeInterface s = rel.getSourceNode();
final NodeInterface t = rel.getTargetNode();
// We need to check if current user can see source and target node which is often not the case for OWNS or SECURITY rels
if (s != null & t != null && s.equals(sourceNode) && t.equals(targetNode)) {
return true;
}
}
} else if (sources.length == 3) {
// dont try to create the relClass because we would need to do that both ways!!! otherwise it just fails if the nodes are in the "wrong" order (see tests:890f)
final String relType = (String) sources[2];
for (final AbstractRelationship rel : sourceNode.getOutgoingRelationships()) {
final NodeInterface s = rel.getSourceNode();
final NodeInterface t = rel.getTargetNode();
// We need to check if current user can see source and target node which is often not the case for OWNS or SECURITY rels
if (s != null & t != null && rel.getRelType().name().equals(relType) && s.equals(sourceNode) && t.equals(targetNode)) {
return true;
}
}
}
} else {
logParameterError(caller, sources, ctx.isJavaScriptContext());
}
return false;
}
Aggregations