use of org.structr.core.app.App in project structr by structr.
the class StructrSSHFile method findFile.
public StructrSSHFile findFile(final String path) {
if ("/".equals(path)) {
return getRootFolder();
}
final App app = StructrApp.getInstance(getRootFolder().getSecurityContext());
final boolean isAbsolute = path.startsWith("/");
final String localPath = isAbsolute ? path.substring(1) : path;
final String[] parts = localPath.split("[/]+");
final String localPart = parts[0];
if (".".equals(path)) {
return this;
}
if ("..".equals(path)) {
return parent;
}
if (isAbsolute && parent != null) {
return getRootFolder().findFile(path);
} else {
// look for files/folders without parent
try (final Tx tx = app.tx()) {
for (final Folder folder : getFolders()) {
final String folderName = folder.getName();
if (localPart.equals(folderName)) {
final StructrSSHFile matchingFolder = new StructrSSHFile(this, folderName, folder);
if (parts.length > 1) {
return matchingFolder.findFile(localPath.substring(folderName.length() + 1));
} else {
// match found
return matchingFolder;
}
}
}
for (final File file : getFiles()) {
final String fileName = file.getName();
if (localPart.equals(fileName)) {
if (parts.length > 1) {
throw new IllegalStateException("Found file where folder was expected, aborting.");
}
return new StructrSSHFile(this, fileName, file);
}
}
tx.success();
} catch (FrameworkException fex) {
logger.warn("", fex);
}
}
return new StructrSSHFile(this, path, null);
}
use of org.structr.core.app.App in project structr by structr.
the class StructrShellCommand method start.
@Override
public void start(final Environment env) throws IOException {
env.addSignalListener(this);
final String userName = env.getEnv().get("USER");
if (userName != null) {
final App app = StructrApp.getInstance();
try (final Tx tx = app.tx()) {
user = app.nodeQuery(User.class).andName(userName).getFirst();
if (user != null) {
// set home directory first
if (Settings.FilesystemEnabled.getValue()) {
currentFolder = user.getHomeDirectory();
}
}
tx.success();
} catch (FrameworkException fex) {
logger.warn("", fex);
}
} else {
logger.warn("Cannot start Structr shell, no username set!");
return;
}
if (isInteractive()) {
// abort if no user was found
if (user == null) {
logger.warn("Cannot start Structr shell, user not found for name {}!", userName);
return;
}
final String terminalType = env.getEnv().get("TERM");
if (terminalType != null) {
switch(terminalType) {
case "xterm":
case "vt100":
case "vt220":
term = new XTermTerminalEmulator(in, out, this);
break;
default:
logger.warn("Unsupported terminal type {}, aborting.", terminalType);
break;
}
logger.warn("No terminal type provided, aborting.", terminalType);
}
if (term != null) {
term.start();
term.print("Welcome to ");
term.setBold(true);
term.print("Structr");
term.print(" 2.0");
term.setBold(false);
term.println();
// display first prompt
displayPrompt();
} else {
callback.onExit(1);
}
} else {
// create terminal emulation
term = new XTermTerminalEmulator(in, out, this);
}
}
use of org.structr.core.app.App in project structr by structr.
the class StructrShellCommand method getPrompt.
public String getPrompt() {
final App app = StructrApp.getInstance();
final StringBuilder buf = new StringBuilder();
try (final Tx tx = app.tx()) {
buf.append(user.getName());
buf.append("@structr:");
if (currentFolder != null) {
String folderPart = currentFolder.getPath();
final Folder homeFolder = user.getHomeDirectory();
if (homeFolder != null) {
// replace home directory with ~ if at the beginning of the full path
final String homeFolderPath = homeFolder.getPath();
if (folderPart.startsWith(homeFolderPath)) {
folderPart = "~" + folderPart.substring(homeFolderPath.length());
}
}
buf.append(folderPart);
} else {
buf.append("/");
}
buf.append(user.isAdmin() ? "#" : "$");
buf.append(" ");
tx.success();
} catch (FrameworkException fex) {
logger.warn("", fex);
}
return buf.toString();
}
use of org.structr.core.app.App in project structr by structr.
the class StructrDataFeedsModuleTest method createTestNode.
protected <T extends AbstractNode> T createTestNode(final Class<T> type, final PropertyMap props, final Principal owner) throws FrameworkException {
final App backendApp = StructrApp.getInstance(SecurityContext.getInstance(owner, AccessMode.Backend));
try (final Tx tx = backendApp.tx()) {
final T result = backendApp.create(type, props);
tx.success();
return result;
}
}
use of org.structr.core.app.App in project structr by structr.
the class UpdateFeedAgent method processTask.
@Override
public ReturnValue processTask(final Task<T> task) throws Throwable {
logger.debug("Processing task {}", task.getClass().getName());
final App app = StructrApp.getInstance();
try (final Tx tx = app.tx(true, true, false)) {
for (DataFeed feed : task.getWorkObjects()) {
logger.debug("Updating data feed {} if due", feed.getProperty(DataFeed.name));
feed.updateIfDue();
}
tx.success();
}
return ReturnValue.Success;
}
Aggregations