use of org.structr.core.property.StringProperty in project structr by structr.
the class PropertyViewRestTest method testOutputDepthScriptingPropertyInCustomView.
@Test
public void testOutputDepthScriptingPropertyInCustomView() {
try (final Tx tx = app.tx()) {
app.create(SchemaNode.class, new NodeAttribute<>(AbstractNode.name, "DepthTest"), new NodeAttribute<>(new StringProperty("_depth"), "Function(depth)"), new NodeAttribute<>(new StringProperty("__customView"), "depth, type"));
tx.success();
} catch (Throwable t) {
fail("Unexpected exception.");
}
final String resource = "/DepthTest";
// create entities
RestAssured.given().contentType("application/json; charset=UTF-8").header("Accept", "application/json; charset=UTF-8").body(" { 'name' : 'DepthTest1' } ").expect().statusCode(201).when().post(resource);
RestAssured.given().contentType("application/json; charset=UTF-8").header("Accept", "application/json; charset=UTF-8").body(" { 'name' : 'DepthTest2' } ").expect().statusCode(201).when().post(resource);
// test default view with properties in it
RestAssured.given().contentType("application/json; charset=UTF-8").header("Accept", "application/json; charset=UTF-8").filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(200)).expect().statusCode(200).body("query_time", notNullValue()).body("serialization_time", notNullValue()).body("result_count", equalTo(2)).body("result", hasSize(2)).body("result[0].type", equalTo("DepthTest")).body("result[0].depth", equalTo(0)).body("result[1].type", equalTo("DepthTest")).body("result[1].depth", equalTo(0)).when().get(resource.concat("/customView"));
}
use of org.structr.core.property.StringProperty in project structr by structr.
the class AdvancedSearchTest method testSearchDynamicNodes.
@Test
public void testSearchDynamicNodes() {
try {
SchemaNode node = null;
// setup
try (final Tx tx = app.tx()) {
node = app.create(SchemaNode.class, new NodeAttribute(SchemaNode.name, "TestType"));
node.setProperty(new StringProperty("_test"), "Integer");
tx.success();
}
// fetch dynamic type info
final Class dynamicType = StructrApp.getConfiguration().getNodeEntityClass("TestType");
final PropertyKey testKey = StructrApp.key(dynamicType, "test");
// modify schema node but keep reference to "old" type
try (final Tx tx = app.tx()) {
node.setProperty(new StringProperty("_test2"), "String");
tx.success();
}
// create test nodes
try (final Tx tx = app.tx()) {
app.create(dynamicType, new NodeAttribute(testKey, 10));
app.create(dynamicType, new NodeAttribute(testKey, 11));
app.create(dynamicType, new NodeAttribute(testKey, 12));
tx.success();
}
// query test nodes
try (final Tx tx = app.tx()) {
/*
* If this test fails, the method "allSubtypes" in SearchCommand was not able to identify
* a dynamic type as being assignable to itself. This can happen when the reference to an
* existing dynamic type is used after the type has been modified, because the class
* instances produced by the dynamic schema ClassLoader are not equal even if they have
* the same name and package etc.
*/
assertEquals("Query for dynamic node should return exactly one result: ", 1, app.nodeQuery(dynamicType).and(testKey, 10).getAsList().size());
tx.success();
}
} catch (FrameworkException ex) {
logger.warn("", ex);
fail("Unexpected exception");
}
}
use of org.structr.core.property.StringProperty in project structr by structr.
the class SchemaNode method getPropertyKeys.
@Override
public Set<PropertyKey> getPropertyKeys(final String propertyView) {
final List<PropertyKey> propertyKeys = new LinkedList<>(Iterables.toList(super.getPropertyKeys(propertyView)));
// add "custom" property keys as String properties
for (final String key : SchemaHelper.getProperties(getNode())) {
final PropertyKey newKey = new StringProperty(key);
newKey.setDeclaringClass(getClass());
propertyKeys.add(newKey);
}
Collections.sort(propertyKeys, (o1, o2) -> {
return o1.jsonName().compareTo(o2.jsonName());
});
return new LinkedHashSet<>(propertyKeys);
}
use of org.structr.core.property.StringProperty in project structr by structr.
the class SchemaRelationshipNode method getPropertyKeys.
@Override
public Set<PropertyKey> getPropertyKeys(final String propertyView) {
final Set<PropertyKey> propertyKeys = new LinkedHashSet<>(Iterables.toList(super.getPropertyKeys(propertyView)));
// add "custom" property keys as String properties
for (final String key : SchemaHelper.getProperties(getNode())) {
final PropertyKey newKey = new StringProperty(key);
newKey.setDeclaringClass(getClass());
propertyKeys.add(newKey);
}
return propertyKeys;
}
use of org.structr.core.property.StringProperty in project structr by structr.
the class HttpPutFunction method apply.
@Override
public Object apply(final ActionContext ctx, final Object caller, final Object[] sources) throws FrameworkException {
if (arrayHasMinLengthAndAllElementsNotNull(sources, 2)) {
final String uri = sources[0].toString();
final String body = sources[1].toString();
String contentType = "application/json";
String charset = "utf-8";
// override default content type
if (sources.length >= 3 && sources[2] != null) {
contentType = sources[2].toString();
}
// override default content type
if (sources.length >= 4 && sources[3] != null) {
charset = sources[3].toString();
}
final Map<String, String> responseData = HttpHelper.put(uri, body, null, null, ctx.getHeaders(), charset);
final int statusCode = Integer.parseInt(responseData.get("status"));
responseData.remove("status");
final String responseBody = responseData.get("body");
responseData.remove("body");
final GraphObjectMap response = new GraphObjectMap();
if ("application/json".equals(contentType)) {
final FromJsonFunction fromJsonFunction = new FromJsonFunction();
response.setProperty(new StringProperty("body"), fromJsonFunction.apply(ctx, caller, new Object[] { responseBody }));
} else {
response.setProperty(new StringProperty("body"), responseBody);
}
response.setProperty(new IntProperty("status"), statusCode);
final GraphObjectMap map = new GraphObjectMap();
for (final Map.Entry<String, String> entry : responseData.entrySet()) {
map.put(new StringProperty(entry.getKey()), entry.getValue());
}
response.setProperty(new StringProperty("headers"), map);
return response;
} else {
logParameterError(caller, sources, ctx.isJavaScriptContext());
return usage(ctx.isJavaScriptContext());
}
}
Aggregations