use of org.structr.schema.json.JsonSchema in project structr by structr.
the class SchemaJsonResource method doGet.
@Override
public Result doGet(PropertyKey sortKey, boolean sortDescending, int pageSize, int page) throws FrameworkException {
final GraphObjectMap schema = new GraphObjectMap();
int resultCount = 0;
try {
final JsonSchema jsonSchema = StructrSchema.createFromDatabase(StructrApp.getInstance());
schema.setProperty(new StringProperty("schema"), jsonSchema.toString());
resultCount = 1;
} catch (URISyntaxException ex) {
logger.error("Error while creating JsonSchema: " + ex.getMessage());
}
Result res = new Result(schema, true);
res.setRawResultCount(resultCount);
return res;
}
use of org.structr.schema.json.JsonSchema 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.JsonSchema 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.JsonSchema in project structr by structr.
the class SystemTest method testGrantFunctionPerformance.
@Test
public void testGrantFunctionPerformance() {
// test setup, create a supernode with 10000 relationships
try (final Tx tx = app.tx()) {
// create test group
app.create(Group.class, "group");
JsonSchema schema = StructrSchema.createFromDatabase(app);
schema.addType("GrantTest").addMethod("onCreation", "grant(first(find('Group')), this, 'read')", "");
StructrSchema.replaceDatabaseSchema(app, schema);
tx.success();
} catch (Throwable fex) {
fail("Unexpected exception");
}
final Class type = StructrApp.getConfiguration().getNodeEntityClass("GrantTest");
try (final Tx tx = app.tx()) {
final long t0 = System.currentTimeMillis();
for (int i = 0; i < 10000; i++) {
app.create(type, "test" + i);
}
final long t1 = System.currentTimeMillis();
System.out.println((t1 - t0) + " ms");
tx.success();
} catch (Throwable fex) {
fail("Unexpected exception");
}
}
use of org.structr.schema.json.JsonSchema 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.");
}
}
Aggregations