use of org.structr.schema.json.InvalidSchemaException 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.schema.json.InvalidSchemaException 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);
}
}
use of org.structr.schema.json.InvalidSchemaException in project structr by structr.
the class SnapshotCommand method purgeLocalSchema.
private void purgeLocalSchema() throws FrameworkException {
final App app = StructrApp.getInstance();
// isolate write output
try (final Tx tx = app.tx()) {
try {
final JsonSchema schema = StructrSchema.createEmptySchema();
StructrSchema.replaceDatabaseSchema(app, schema);
} catch (InvalidSchemaException iex) {
throw new FrameworkException(422, iex.getMessage());
}
tx.success();
} catch (URISyntaxException use) {
logger.warn("", use);
}
}
use of org.structr.schema.json.InvalidSchemaException in project structr by structr.
the class SchemaTest method test02SimpleSymmetricReferences.
@Test
public void test02SimpleSymmetricReferences() {
// we need to wait for the schema service to be initialized here.. :(
try {
Thread.sleep(1000);
} catch (Throwable t) {
}
try {
final JsonSchema sourceSchema = StructrSchema.createFromDatabase(app);
final JsonObjectType project = sourceSchema.addType("Project");
final JsonObjectType task = sourceSchema.addType("Task");
// create relation
final JsonReferenceType rel = project.relate(task, "has", Cardinality.OneToMany, "project", "tasks");
rel.setName("ProjectTasks");
final String schema = sourceSchema.toString();
System.out.println(schema);
// test map paths
final Map<String, Object> map = new GsonBuilder().create().fromJson(schema, Map.class);
mapPathValue(map, "definitions.Project.type", "object");
mapPathValue(map, "definitions.Project.properties.tasks.$link", "#/definitions/ProjectTasks");
mapPathValue(map, "definitions.Project.properties.tasks.items.$ref", "#/definitions/Task");
mapPathValue(map, "definitions.Project.properties.tasks.type", "array");
mapPathValue(map, "definitions.ProjectTasks.$source", "#/definitions/Project");
mapPathValue(map, "definitions.ProjectTasks.$target", "#/definitions/Task");
mapPathValue(map, "definitions.ProjectTasks.cardinality", "OneToMany");
mapPathValue(map, "definitions.ProjectTasks.rel", "has");
mapPathValue(map, "definitions.ProjectTasks.sourceName", "project");
mapPathValue(map, "definitions.ProjectTasks.targetName", "tasks");
mapPathValue(map, "definitions.ProjectTasks.type", "object");
mapPathValue(map, "definitions.Task.type", "object");
mapPathValue(map, "definitions.Task.properties.project.$link", "#/definitions/ProjectTasks");
mapPathValue(map, "definitions.Task.properties.project.$ref", "#/definitions/Project");
mapPathValue(map, "definitions.Task.properties.project.type", "object");
// test
compareSchemaRoundtrip(sourceSchema);
} catch (FrameworkException | InvalidSchemaException | URISyntaxException ex) {
logger.warn("", ex);
fail("Unexpected exception.");
}
}
use of org.structr.schema.json.InvalidSchemaException in project structr by structr.
the class SchemaJsonImporter method importSchemaJson.
public static void importSchemaJson(final String source) throws FrameworkException {
// nothing to do
if (StringUtils.isBlank(source)) {
return;
}
final App app = StructrApp.getInstance();
// isolate write output
try (final Tx tx = app.tx()) {
final JsonSchema schema;
try {
schema = StructrSchema.createFromSource(source);
} catch (InvalidSchemaException | URISyntaxException ex) {
throw new FrameworkException(422, ex.getMessage());
}
try {
StructrSchema.extendDatabaseSchema(app, schema);
} catch (URISyntaxException ex) {
throw new FrameworkException(422, ex.getMessage());
}
tx.success();
}
}
Aggregations