Search in sources :

Example 31 with StringProperty

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"));
}
Also used : Tx(org.structr.core.graph.Tx) StringProperty(org.structr.core.property.StringProperty) Test(org.junit.Test)

Example 32 with StringProperty

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");
    }
}
Also used : SchemaNode(org.structr.core.entity.SchemaNode) NodeAttribute(org.structr.core.graph.NodeAttribute) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) StringProperty(org.structr.core.property.StringProperty) PropertyKey(org.structr.core.property.PropertyKey) Test(org.junit.Test) IndexingTest(org.structr.rest.common.IndexingTest)

Example 33 with StringProperty

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);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) StringProperty(org.structr.core.property.StringProperty) PropertyKey(org.structr.core.property.PropertyKey) LinkedList(java.util.LinkedList)

Example 34 with StringProperty

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;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) StringProperty(org.structr.core.property.StringProperty) PropertyKey(org.structr.core.property.PropertyKey)

Example 35 with StringProperty

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());
    }
}
Also used : IntProperty(org.structr.core.property.IntProperty) GraphObjectMap(org.structr.core.GraphObjectMap) StringProperty(org.structr.core.property.StringProperty) Map(java.util.Map) GraphObjectMap(org.structr.core.GraphObjectMap)

Aggregations

StringProperty (org.structr.core.property.StringProperty)53 FrameworkException (org.structr.common.error.FrameworkException)28 Tx (org.structr.core.graph.Tx)28 Test (org.junit.Test)26 PropertyKey (org.structr.core.property.PropertyKey)22 GraphObject (org.structr.core.GraphObject)14 GraphObjectMap (org.structr.core.GraphObjectMap)14 StructrTest (org.structr.common.StructrTest)11 LinkedList (java.util.LinkedList)10 NodeAttribute (org.structr.core.graph.NodeAttribute)10 SchemaNode (org.structr.core.entity.SchemaNode)9 List (java.util.List)8 AbstractNode (org.structr.core.entity.AbstractNode)7 NodeInterface (org.structr.core.graph.NodeInterface)7 StructrUiTest (org.structr.web.StructrUiTest)7 Map (java.util.Map)6 ErrorToken (org.structr.common.error.ErrorToken)6 IntProperty (org.structr.core.property.IntProperty)6 LinkedHashSet (java.util.LinkedHashSet)5 App (org.structr.core.app.App)5