use of org.structr.core.app.App in project structr by structr.
the class FileSyncWatchEventListener method getOrCreate.
private AbstractFile getOrCreate(final Folder parentFolder, final Path fullPath, final Path relativePath, final boolean doCreate) throws FrameworkException {
final PropertyKey<Boolean> isExternalKey = StructrApp.key(AbstractFile.class, "isExternal");
final PropertyKey<Folder> parentKey = StructrApp.key(AbstractFile.class, "parent");
final String fileName = relativePath.getFileName().toString();
final boolean isFile = !Files.isDirectory(fullPath);
final Class<? extends AbstractFile> type = isFile ? org.structr.web.entity.File.class : Folder.class;
final App app = StructrApp.getInstance();
AbstractFile file = app.nodeQuery(type).and(AbstractFile.name, fileName).and(parentKey, parentFolder).getFirst();
if (file == null && doCreate) {
file = app.create(type, new NodeAttribute<>(AbstractFile.name, fileName), new NodeAttribute<>(parentKey, parentFolder), new NodeAttribute<>(isExternalKey, true));
}
return file;
}
use of org.structr.core.app.App 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.app.App in project structr by structr.
the class UiSyncCommand method doImport.
private void doImport(final String fileName) throws FrameworkException {
final App app = StructrApp.getInstance();
final DatabaseService graphDb = app.getDatabaseService();
SyncCommand.importFromFile(graphDb, securityContext, fileName, true);
// import done, now the ShadowDocument needs some special care. :(
try (final Tx tx = app.tx()) {
final List<ShadowDocument> shadowDocuments = app.nodeQuery(ShadowDocument.class).includeDeletedAndHidden().getAsList();
if (shadowDocuments.size() > 1) {
final PropertyKey<List<DOMNode>> elementsKey = StructrApp.key(Page.class, "elements");
final List<DOMNode> collectiveChildren = new LinkedList<>();
// sort by node id (higher node ID is newer entity)
Collections.sort(shadowDocuments, new Comparator<ShadowDocument>() {
@Override
public int compare(final ShadowDocument t1, final ShadowDocument t2) {
return Long.valueOf(t2.getId()).compareTo(t1.getId());
}
});
final ShadowDocument previousShadowDoc = shadowDocuments.get(0);
final ShadowDocument newShadowDoc = shadowDocuments.get(1);
// collect children of both shadow documents
collectiveChildren.addAll(previousShadowDoc.getProperty(elementsKey));
collectiveChildren.addAll(newShadowDoc.getProperty(elementsKey));
// delete old shadow document
app.delete(previousShadowDoc);
// add children to new shadow document
newShadowDoc.setProperties(securityContext, new PropertyMap(elementsKey, collectiveChildren));
}
tx.success();
}
}
use of org.structr.core.app.App 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.app.App in project structr by structr.
the class AbstractTabCompletionProvider method getTabCompletionForUUIDs.
protected List<TabCompletionResult> getTabCompletionForUUIDs(final SecurityContext securityContext, final String token, final String suffix) {
final List<TabCompletionResult> results = new LinkedList<>();
if (token.length() >= 3) {
final App app = StructrApp.getInstance(securityContext);
try (final Tx tx = app.tx()) {
final String tenantIdentifier = app.getDatabaseService().getTenantIdentifier();
final StringBuilder buf = new StringBuilder();
buf.append("MATCH (n");
if (tenantIdentifier != null) {
buf.append(":");
buf.append(tenantIdentifier);
}
buf.append(") WHERE n.id STARTS WITH {part} RETURN n");
for (final GraphObject obj : app.cypher(buf.toString(), toMap("part", token))) {
results.add(getCompletion(obj.getUuid(), token, suffix));
}
tx.success();
} catch (FrameworkException ignore) {
}
}
return results;
}
Aggregations