use of org.structr.core.app.App in project structr by structr.
the class SchemaJsonResource method doPost.
@Override
public RestMethodResult doPost(Map<String, Object> propertySet) throws FrameworkException {
if (propertySet != null && propertySet.containsKey("schema")) {
final App app = StructrApp.getInstance(securityContext);
String schemaJson = (String) propertySet.get("schema");
try {
StructrSchema.replaceDatabaseSchema(app, StructrSchema.createFromSource(schemaJson));
} catch (URISyntaxException | InvalidSchemaException ex) {
logger.error("Error while importing JsonSchema: " + ex.getMessage());
}
return new RestMethodResult(200, "Schema import started");
}
return new RestMethodResult(400, "Invalid request body. Specify schema json string as 'schema' in request body.");
}
use of org.structr.core.app.App in project structr by structr.
the class SchemaMethodResource method doPost.
@Override
public RestMethodResult doPost(final Map<String, Object> propertySet) throws FrameworkException {
final App app = StructrApp.getInstance(securityContext);
RestMethodResult result = null;
if (source != null) {
try (final Tx tx = app.tx()) {
result = SchemaMethodResource.invoke(securityContext, null, source, propertySet, methodResource.getUriPart());
tx.success();
}
}
if (result == null) {
throw new IllegalPathException("Type and method name do not match the given path.");
}
return result;
}
use of org.structr.core.app.App 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;
}
use of org.structr.core.app.App in project structr by structr.
the class LogResource method doPost.
@Override
public RestMethodResult doPost(Map<String, Object> propertySet) throws FrameworkException {
final HttpServletRequest request = securityContext.getRequest();
if (request != null) {
// initialize?!
if ("true".equals(request.getParameter("initialize"))) {
final String filesPath = Settings.FilesPath.getValue();
try (final Context context = new Context(1000)) {
collectFilesAndStore(context, new File(filesPath + SUBJECTS).toPath(), 0);
} catch (FrameworkException fex) {
logger.warn("", fex);
}
return new RestMethodResult(200);
}
final String subjectId = (String) propertySet.get(subjectProperty.jsonName());
final String objectId = (String) propertySet.get(objectProperty.jsonName());
final String action = (String) propertySet.get(actionProperty.jsonName());
final String message = (String) propertySet.get(messageProperty.jsonName());
if (subjectId != null && objectId != null && action != null) {
final App app = StructrApp.getInstance(securityContext);
LogEvent event = null;
try (final Tx tx = app.tx()) {
final PropertyMap properties = new PropertyMap();
properties.put(LogEvent.timestampProperty, new Date());
properties.put(LogEvent.actionProperty, action);
properties.put(LogEvent.subjectProperty, subjectId);
properties.put(LogEvent.objectProperty, objectId);
properties.put(LogEvent.messageProperty, message);
properties.put(LogEvent.visibleToPublicUsers, true);
properties.put(LogEvent.visibleToAuthenticatedUsers, true);
event = app.create(LogEvent.class, properties);
tx.success();
}
final RestMethodResult result = new RestMethodResult(201);
result.addContent(event);
return result;
} else {
final ErrorBuffer errorBuffer = new ErrorBuffer();
if (StringUtils.isEmpty(subjectId)) {
errorBuffer.add(new EmptyPropertyToken("LogFile", subjectProperty));
}
if (StringUtils.isEmpty(objectId)) {
errorBuffer.add(new EmptyPropertyToken("LogFile", objectProperty));
}
if (StringUtils.isEmpty(action)) {
errorBuffer.add(new EmptyPropertyToken("LogFile", actionProperty));
}
throw new FrameworkException(422, "Log entry must consist of at least subjectId, objectId and action", errorBuffer);
}
}
// no request object, this is fatal
throw new FrameworkException(500, "No request object present, aborting.");
}
use of org.structr.core.app.App in project structr by structr.
the class SnapshotCommand method addSnapshot.
private void addSnapshot(final String fileName) throws FrameworkException {
final App app = StructrApp.getInstance();
// isolate write output
try (final Tx tx = app.tx()) {
if (fileName != null) {
final File snapshotFile = locateFile(fileName, false);
try (final Reader reader = new FileReader(snapshotFile)) {
final JsonSchema schema = StructrSchema.createFromSource(reader);
StructrSchema.extendDatabaseSchema(app, schema);
} catch (InvalidSchemaException iex) {
throw new FrameworkException(422, iex.getMessage());
}
} else {
throw new FrameworkException(422, "Please supply schema snapshot name to add to database.");
}
tx.success();
} catch (IOException | URISyntaxException ioex) {
logger.warn("", ioex);
}
}
Aggregations