use of org.structr.core.entity.SchemaNode in project structr by structr.
the class RenderContextTest method testScriptEvaluation.
@Test
public void testScriptEvaluation() {
Settings.CypherDebugLogging.setValue(true);
try (final Tx tx = app.tx()) {
// create a Project type
final SchemaNode projectNode = createTestNode(SchemaNode.class, new NodeAttribute<>(StructrApp.key(AbstractNode.class, "name"), "Project"));
// create a Task type with a string property "task"
final SchemaNode taskNode = createTestNode(SchemaNode.class, new NodeAttribute<>(StructrApp.key(AbstractNode.class, "name"), "Task"), new NodeAttribute<>(new StringProperty("_task"), "String"));
// create a schema relationship between them
createTestNode(SchemaRelationshipNode.class, new NodeAttribute<>(StructrApp.key(SchemaRelationshipNode.class, "sourceNode"), projectNode), new NodeAttribute<>(StructrApp.key(SchemaRelationshipNode.class, "targetNode"), taskNode), new NodeAttribute<>(StructrApp.key(SchemaRelationshipNode.class, "relationshipType"), "has"), new NodeAttribute<>(StructrApp.key(SchemaRelationshipNode.class, "sourceMultiplicity"), "1"), new NodeAttribute<>(StructrApp.key(SchemaRelationshipNode.class, "targetMultiplicity"), "*"), new NodeAttribute<>(StructrApp.key(SchemaRelationshipNode.class, "sourceJsonName"), "project"), new NodeAttribute<>(StructrApp.key(SchemaRelationshipNode.class, "targetJsonName"), "tasks"));
tx.success();
} catch (FrameworkException ex) {
logger.warn("", ex);
fail("Unexpected exception");
}
try (final Tx tx = app.tx()) {
// obtain class objects to create instances of the above types
final Class projectType = StructrApp.getConfiguration().getNodeEntityClass("Project");
final Class taskType = StructrApp.getConfiguration().getNodeEntityClass("Task");
final PropertyKey taskKey = StructrApp.key(taskType, "task");
final PropertyKey tasksKey = StructrApp.key(projectType, "tasks");
final List<NodeInterface> tasks = new LinkedList<>();
tasks.add(app.create(taskType, new NodeAttribute<>(StructrApp.key(AbstractNode.class, "name"), "Task 1"), new NodeAttribute<>(taskKey, "Task 1")));
tasks.add(app.create(taskType, new NodeAttribute<>(StructrApp.key(AbstractNode.class, "name"), "Task 2"), new NodeAttribute<>(taskKey, "Task 2")));
tasks.add(app.create(taskType, new NodeAttribute<>(StructrApp.key(AbstractNode.class, "name"), "Task 3"), new NodeAttribute<>(taskKey, "Task 3")));
// create a project and a task
final NodeInterface project = app.create(projectType, new NodeAttribute<>(StructrApp.key(AbstractNode.class, "name"), "project"), new NodeAttribute<>(tasksKey, tasks));
// create an additional test task without a project
final NodeInterface testTask = app.create(taskType, new NodeAttribute<>(StructrApp.key(AbstractNode.class, "name"), "test task"), new NodeAttribute<>(taskKey, "test task"));
final RenderContext renderContext = new RenderContext(securityContext);
renderContext.putDataObject("project", project);
renderContext.putDataObject("task", testTask);
assertEquals("Invalid scripting evaluation result", "", Scripting.replaceVariables(renderContext, null, "${foo.page}"));
assertEquals("Invalid scripting evaluation result", testTask.getUuid(), Scripting.replaceVariables(renderContext, null, "${task}"));
assertEquals("Invalid scripting evaluation result", "test task", Scripting.replaceVariables(renderContext, null, "${task.task}"));
assertEquals("Invalid scripting evaluation result", tasks.toString(), Scripting.replaceVariables(renderContext, null, "${project.tasks}"));
assertEquals("Invalid scripting evaluation result", tasks.get(0).getUuid(), Scripting.replaceVariables(renderContext, null, "${project.tasks[0]}"));
assertEquals("Invalid scripting evaluation result", tasks.get(1).getUuid(), Scripting.replaceVariables(renderContext, null, "${project.tasks[1]}"));
assertEquals("Invalid scripting evaluation result", tasks.get(2).getUuid(), Scripting.replaceVariables(renderContext, null, "${project.tasks[2]}"));
assertEquals("Invalid scripting evaluation result", "", Scripting.replaceVariables(renderContext, null, "${project.tasks[3]}"));
assertEquals("Invalid scripting evaluation result", "Task 1", Scripting.replaceVariables(renderContext, null, "${project.tasks[0].task}"));
assertEquals("Invalid scripting evaluation result", "Task 2", Scripting.replaceVariables(renderContext, null, "${project.tasks[1].task}"));
assertEquals("Invalid scripting evaluation result", "Task 3", Scripting.replaceVariables(renderContext, null, "${project.tasks[2].task}"));
assertEquals("Invalid scripting evaluation result", "", Scripting.replaceVariables(renderContext, null, "${project.tasks[3].task}"));
tx.success();
} catch (FrameworkException ex) {
logger.warn("", ex);
fail("Unexpected exception");
}
}
use of org.structr.core.entity.SchemaNode in project structr by structr.
the class SchemaMethodsTest method test05InheritedSchemaMethodOnBuildinType.
@Test
public void test05InheritedSchemaMethodOnBuildinType() {
final String builtinTypeName = "File";
final String schemaMethodName = "testFileMethod";
User admin = null;
try (final Tx tx = app.tx()) {
admin = createAdminUser();
tx.success();
} catch (Exception ex) {
logger.error("", ex);
}
try (final Tx tx = app.tx()) {
// Add schema method "testFileMethod" to built-in File class
SchemaNode fileNodeDef = app.nodeQuery(SchemaNode.class).andName(builtinTypeName).getFirst();
final PropertyMap testFileMethodProperties = new PropertyMap();
testFileMethodProperties.put(SchemaMethod.name, schemaMethodName);
testFileMethodProperties.put(SchemaMethod.source, "()");
testFileMethodProperties.put(SchemaMethod.schemaNode, fileNodeDef);
SchemaMethod testFileMethod = app.create(SchemaMethod.class, testFileMethodProperties);
tx.success();
} catch (Exception ex) {
logger.error("", ex);
}
try (final Tx tx = app.tx()) {
RestAssured.given().contentType("application/json; charset=UTF-8").filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(200)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(201)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(400)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(404)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(422)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(500)).headers("X-User", ADMIN_USERNAME, "X-Password", ADMIN_PASSWORD).body("{}").expect().statusCode(200).when().post("/Image/" + schemaMethodName);
tx.success();
} catch (FrameworkException ex) {
logger.error(ex.toString());
fail("Unexpected exception");
}
}
use of org.structr.core.entity.SchemaNode in project structr by structr.
the class SchemaMethodsTest method test06InheritedSchemaMethodOnEntityOfBuiltinType.
@Test
public void test06InheritedSchemaMethodOnEntityOfBuiltinType() {
final String builtinTypeName = "File";
final String schemaMethodName = "testFileMethod";
User admin = null;
try (final Tx tx = app.tx()) {
admin = createAdminUser();
tx.success();
} catch (Exception ex) {
logger.error("", ex);
}
try (final Tx tx = app.tx()) {
// Add schema method "testFileMethod" to built-in File class
SchemaNode fileNodeDef = app.nodeQuery(SchemaNode.class).andName(builtinTypeName).getFirst();
final PropertyMap testFileMethodProperties = new PropertyMap();
testFileMethodProperties.put(SchemaMethod.name, schemaMethodName);
testFileMethodProperties.put(SchemaMethod.source, "()");
testFileMethodProperties.put(SchemaMethod.schemaNode, fileNodeDef);
SchemaMethod testFileMethod = app.create(SchemaMethod.class, testFileMethodProperties);
tx.success();
} catch (Exception ex) {
logger.error("", ex);
}
String id = createEntityAsAdmin("Image", "{'name': 'Test Image'}");
try (final Tx tx = app.tx()) {
RestAssured.given().contentType("application/json; charset=UTF-8").filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(200)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(201)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(400)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(404)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(422)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(500)).headers("X-User", ADMIN_USERNAME, "X-Password", ADMIN_PASSWORD).body("{}").expect().statusCode(200).when().post("/Image/" + id + "/" + schemaMethodName);
tx.success();
} catch (FrameworkException ex) {
logger.error(ex.toString());
fail("Unexpected exception");
}
}
use of org.structr.core.entity.SchemaNode in project structr by structr.
the class SchemaMethodsTest method test01SchemaMethodOnBuiltinType.
@Test
public void test01SchemaMethodOnBuiltinType() {
final String builtinTypeName = "File";
final String schemaMethodName = "testFileMethod";
try (final Tx tx = app.tx()) {
// Add schema method "testFileMethod" to built-in File class
SchemaNode fileNodeDef = app.nodeQuery(SchemaNode.class).andName(builtinTypeName).getFirst();
final PropertyMap testFileMethodProperties = new PropertyMap();
testFileMethodProperties.put(SchemaMethod.name, schemaMethodName);
testFileMethodProperties.put(SchemaMethod.source, "()");
testFileMethodProperties.put(SchemaMethod.schemaNode, fileNodeDef);
SchemaMethod testFileMethod = app.create(SchemaMethod.class, testFileMethodProperties);
tx.success();
} catch (Exception ex) {
logger.error("", ex);
}
User admin = null;
try (final Tx tx = app.tx()) {
admin = createAdminUser();
tx.success();
} catch (Exception ex) {
logger.error("", ex);
}
try (final Tx tx = app.tx()) {
RestAssured.given().contentType("application/json; charset=UTF-8").filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(200)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(201)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(400)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(404)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(422)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(500)).headers("X-User", ADMIN_USERNAME, "X-Password", ADMIN_PASSWORD).body("{}").expect().statusCode(200).when().post(builtinTypeName + "/" + schemaMethodName);
tx.success();
} catch (FrameworkException ex) {
logger.error(ex.toString());
fail("Unexpected exception");
}
}
use of org.structr.core.entity.SchemaNode in project structr by structr.
the class CMISRepositoryService method getBaseTypeChildren.
private List<TypeDefinition> getBaseTypeChildren(final BaseTypeId baseTypeId, final Boolean includePropertyDefinitions) {
final ConfigurationProvider config = StructrApp.getConfiguration();
final List<TypeDefinition> result = new LinkedList<>();
final App app = StructrApp.getInstance();
// static definition of base type children, add new types here!
switch(baseTypeId) {
case CMIS_DOCUMENT:
result.add(extendTypeDefinition(File.class, includePropertyDefinitions));
break;
case CMIS_FOLDER:
result.add(extendTypeDefinition(Folder.class, includePropertyDefinitions));
break;
case CMIS_ITEM:
try (final Tx tx = app.tx()) {
for (final SchemaNode schemaNode : app.nodeQuery(SchemaNode.class).sort(AbstractNode.name).getAsList()) {
final Class type = config.getNodeEntityClass(schemaNode.getClassName());
if (type != null) {
final CMISInfo info = getCMISInfo(type);
if (info != null && baseTypeId.equals(info.getBaseTypeId())) {
final TypeDefinition extendedTypeDefinition = extendTypeDefinition(type, includePropertyDefinitions);
if (extendedTypeDefinition != null) {
result.add(extendedTypeDefinition);
}
}
}
}
tx.success();
} catch (final FrameworkException fex) {
logger.warn("", fex);
}
break;
}
return result;
}
Aggregations