Search in sources :

Example 1 with GenericProperty

use of org.structr.core.property.GenericProperty in project structr by structr.

the class AdvancedSchemaTest method test04SchemaPropertyOrderInCustomViews.

@Test
public void test04SchemaPropertyOrderInCustomViews() {
    try (final Tx tx = app.tx()) {
        createAdminUser();
        createResourceAccess("_schema", UiAuthenticator.AUTH_USER_GET);
        tx.success();
    } catch (Exception ex) {
        logger.error("", ex);
    }
    final GenericProperty jsonName = new GenericProperty("jsonName");
    SchemaView testView = null;
    String id = null;
    try (final Tx tx = app.tx()) {
        // create test type
        final SchemaNode test = app.create(SchemaNode.class, "Test");
        // create view with sort order
        testView = app.create(SchemaView.class, new NodeAttribute<>(SchemaView.name, "test"), new NodeAttribute<>(SchemaView.schemaNode, test), new NodeAttribute<>(SchemaView.sortOrder, "one, two, three, four, id, type, name"), new NodeAttribute<>(SchemaView.nonGraphProperties, "id, type, name"));
        final List<SchemaView> list = new LinkedList<>();
        list.add(testView);
        // create properties
        app.create(SchemaProperty.class, new NodeAttribute<>(SchemaProperty.schemaNode, test), new NodeAttribute<>(SchemaProperty.schemaViews, list), new NodeAttribute<>(SchemaProperty.propertyType, "String"), new NodeAttribute<>(SchemaProperty.name, "one"));
        app.create(SchemaProperty.class, new NodeAttribute<>(SchemaProperty.schemaNode, test), new NodeAttribute<>(SchemaProperty.schemaViews, list), new NodeAttribute<>(SchemaProperty.propertyType, "String"), new NodeAttribute<>(SchemaProperty.name, "two"));
        app.create(SchemaProperty.class, new NodeAttribute<>(SchemaProperty.schemaNode, test), new NodeAttribute<>(SchemaProperty.schemaViews, list), new NodeAttribute<>(SchemaProperty.propertyType, "String"), new NodeAttribute<>(SchemaProperty.name, "three"));
        app.create(SchemaProperty.class, new NodeAttribute<>(SchemaProperty.schemaNode, test), new NodeAttribute<>(SchemaProperty.schemaViews, list), new NodeAttribute<>(SchemaProperty.propertyType, "String"), new NodeAttribute<>(SchemaProperty.name, "four"));
        tx.success();
    } catch (FrameworkException fex) {
        fex.printStackTrace();
    }
    final Class type = StructrApp.getConfiguration().getNodeEntityClass("Test");
    final List<PropertyKey> list = new LinkedList<>(StructrApp.getConfiguration().getPropertySet(type, "test"));
    Assert.assertEquals("Invalid number of properties in sorted view", 7, list.size());
    Assert.assertEquals("one", list.get(0).dbName());
    Assert.assertEquals("two", list.get(1).dbName());
    Assert.assertEquals("three", list.get(2).dbName());
    Assert.assertEquals("four", list.get(3).dbName());
    Assert.assertEquals("id", list.get(4).dbName());
    Assert.assertEquals("type", list.get(5).dbName());
    Assert.assertEquals("name", list.get(6).dbName());
    try (final Tx tx = app.tx()) {
        // modify sort order
        testView.setProperty(SchemaView.sortOrder, "type, one, id, two, three, four, name");
        // create test entity
        final NodeInterface node = app.create(StructrApp.getConfiguration().getNodeEntityClass("Test"));
        id = node.getUuid();
        tx.success();
    } catch (FrameworkException fex) {
        fex.printStackTrace();
    }
    final List<PropertyKey> list2 = new LinkedList<>(StructrApp.getConfiguration().getPropertySet(type, "test"));
    Assert.assertEquals("Invalid number of properties in sorted view", 7, list2.size());
    Assert.assertEquals("type", list2.get(0).dbName());
    Assert.assertEquals("one", list2.get(1).dbName());
    Assert.assertEquals("id", list2.get(2).dbName());
    Assert.assertEquals("two", list2.get(3).dbName());
    Assert.assertEquals("three", list2.get(4).dbName());
    Assert.assertEquals("four", list2.get(5).dbName());
    Assert.assertEquals("name", list2.get(6).dbName());
    // test schema resource
    RestAssured.given().contentType("application/json; charset=UTF-8").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).expect().statusCode(200).body("result", hasSize(7)).body("result[0].jsonName", equalTo("type")).body("result[1].jsonName", equalTo("one")).body("result[2].jsonName", equalTo("id")).body("result[3].jsonName", equalTo("two")).body("result[4].jsonName", equalTo("three")).body("result[5].jsonName", equalTo("four")).body("result[6].jsonName", equalTo("name")).when().get("/_schema/Test/test");
    // test actual REST resource (not easy to extract and verify
    // JSON property order, that's why we're using replaceAll and
    // string comparison..
    final String[] actual = 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).expect().statusCode(200).when().get("/Test/test").body().asString().replaceAll("[\\s]+", "").split("[\\W]+");
    // we can only test the actual ORDER of the JSON result object by splitting it on whitespace and validating the resulting array
    assertEquals("Invalid JSON result for sorted property view", "", actual[0]);
    assertEquals("Invalid JSON result for sorted property view", "query_time", actual[1]);
    assertEquals("Invalid JSON result for sorted property view", "0", actual[2]);
    assertEquals("Invalid JSON result for sorted property view", "result_count", actual[4]);
    assertEquals("Invalid JSON result for sorted property view", "1", actual[5]);
    assertEquals("Invalid JSON result for sorted property view", "result", actual[6]);
    assertEquals("Invalid JSON result for sorted property view", "type", actual[7]);
    assertEquals("Invalid JSON result for sorted property view", "Test", actual[8]);
    assertEquals("Invalid JSON result for sorted property view", "one", actual[9]);
    assertEquals("Invalid JSON result for sorted property view", "null", actual[10]);
    assertEquals("Invalid JSON result for sorted property view", "id", actual[11]);
    assertEquals("Invalid JSON result for sorted property view", id, actual[12]);
    assertEquals("Invalid JSON result for sorted property view", "two", actual[13]);
    assertEquals("Invalid JSON result for sorted property view", "null", actual[14]);
    assertEquals("Invalid JSON result for sorted property view", "three", actual[15]);
    assertEquals("Invalid JSON result for sorted property view", "null", actual[16]);
    assertEquals("Invalid JSON result for sorted property view", "four", actual[17]);
    assertEquals("Invalid JSON result for sorted property view", "null", actual[18]);
    assertEquals("Invalid JSON result for sorted property view", "name", actual[19]);
    assertEquals("Invalid JSON result for sorted property view", "null", actual[20]);
    assertEquals("Invalid JSON result for sorted property view", "serialization_time", actual[21]);
    // try built-in function
    try {
        final List<GraphObjectMap> list3 = (List) new TypeInfoFunction().apply(new ActionContext(securityContext), null, new Object[] { "Test", "test" });
        Assert.assertEquals("Invalid number of properties in sorted view", 7, list2.size());
        Assert.assertEquals("type", list3.get(0).get(jsonName));
        Assert.assertEquals("one", list3.get(1).get(jsonName));
        Assert.assertEquals("id", list3.get(2).get(jsonName));
        Assert.assertEquals("two", list3.get(3).get(jsonName));
        Assert.assertEquals("three", list3.get(4).get(jsonName));
        Assert.assertEquals("four", list3.get(5).get(jsonName));
        Assert.assertEquals("name", list3.get(6).get(jsonName));
    } catch (FrameworkException fex) {
        fex.printStackTrace();
    }
    // try scripting call
    try {
        final List<GraphObjectMap> list4 = (List) Scripting.evaluate(new ActionContext(securityContext), null, "${type_info('Test', 'test')}", "test");
        Assert.assertEquals("Invalid number of properties in sorted view", 7, list2.size());
        Assert.assertEquals("type", list4.get(0).get(jsonName));
        Assert.assertEquals("one", list4.get(1).get(jsonName));
        Assert.assertEquals("id", list4.get(2).get(jsonName));
        Assert.assertEquals("two", list4.get(3).get(jsonName));
        Assert.assertEquals("three", list4.get(4).get(jsonName));
        Assert.assertEquals("four", list4.get(5).get(jsonName));
        Assert.assertEquals("name", list4.get(6).get(jsonName));
    } catch (FrameworkException fex) {
        fex.printStackTrace();
    }
}
Also used : NodeAttribute(org.structr.core.graph.NodeAttribute) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) ActionContext(org.structr.schema.action.ActionContext) FrameworkException(org.structr.common.error.FrameworkException) LinkedList(java.util.LinkedList) SchemaView(org.structr.core.entity.SchemaView) SchemaNode(org.structr.core.entity.SchemaNode) TypeInfoFunction(org.structr.core.function.TypeInfoFunction) GraphObjectMap(org.structr.core.GraphObjectMap) GenericProperty(org.structr.core.property.GenericProperty) LinkedList(java.util.LinkedList) List(java.util.List) PropertyKey(org.structr.core.property.PropertyKey) NodeInterface(org.structr.core.graph.NodeInterface) FrontendTest(org.structr.web.basic.FrontendTest) ResourceAccessTest(org.structr.web.basic.ResourceAccessTest) Test(org.junit.Test)

Example 2 with GenericProperty

use of org.structr.core.property.GenericProperty in project structr by structr.

the class AdvancedSchemaTest method testSchemaPropertyOrderInInheritedViews.

@Test
public void testSchemaPropertyOrderInInheritedViews() {
    try (final Tx tx = app.tx()) {
        createAdminUser();
        createResourceAccess("_schema", UiAuthenticator.AUTH_USER_GET);
        tx.success();
    } catch (Exception ex) {
        logger.error("", ex);
    }
    final GenericProperty jsonName = new GenericProperty("jsonName");
    SchemaView testView = null;
    String id = null;
    try (final Tx tx = app.tx()) {
        final SchemaNode testBase = app.create(SchemaNode.class, "TestBase");
        final SchemaNode test = app.create(SchemaNode.class, new NodeAttribute<>(SchemaNode.name, "Test"), new NodeAttribute<>(SchemaNode.extendsClass, "org.structr.dynamic.TestBase"));
        // create view with sort order
        testView = app.create(SchemaView.class, new NodeAttribute<>(SchemaView.name, "test"), new NodeAttribute<>(SchemaView.schemaNode, test), new NodeAttribute<>(SchemaView.sortOrder, "one, two, three, four, id, type, name"), new NodeAttribute<>(SchemaView.nonGraphProperties, "id, type, name"));
        final List<SchemaView> list = new LinkedList<>();
        list.add(testView);
        // create properties
        app.create(SchemaProperty.class, new NodeAttribute<>(SchemaProperty.schemaNode, testBase), new NodeAttribute<>(SchemaProperty.schemaViews, list), new NodeAttribute<>(SchemaProperty.propertyType, "String"), new NodeAttribute<>(SchemaProperty.name, "one"));
        app.create(SchemaProperty.class, new NodeAttribute<>(SchemaProperty.schemaNode, testBase), new NodeAttribute<>(SchemaProperty.schemaViews, list), new NodeAttribute<>(SchemaProperty.propertyType, "String"), new NodeAttribute<>(SchemaProperty.name, "two"));
        app.create(SchemaProperty.class, new NodeAttribute<>(SchemaProperty.schemaNode, testBase), new NodeAttribute<>(SchemaProperty.schemaViews, list), new NodeAttribute<>(SchemaProperty.propertyType, "String"), new NodeAttribute<>(SchemaProperty.name, "three"));
        app.create(SchemaProperty.class, new NodeAttribute<>(SchemaProperty.schemaNode, testBase), new NodeAttribute<>(SchemaProperty.schemaViews, list), new NodeAttribute<>(SchemaProperty.propertyType, "String"), new NodeAttribute<>(SchemaProperty.name, "four"));
        tx.success();
    } catch (FrameworkException fex) {
        fex.printStackTrace();
    }
    final Class type = StructrApp.getConfiguration().getNodeEntityClass("Test");
    final List<PropertyKey> list = new LinkedList<>(StructrApp.getConfiguration().getPropertySet(type, "test"));
    Assert.assertEquals("Invalid number of properties in sorted view", 7, list.size());
    Assert.assertEquals("one", list.get(0).dbName());
    Assert.assertEquals("two", list.get(1).dbName());
    Assert.assertEquals("three", list.get(2).dbName());
    Assert.assertEquals("four", list.get(3).dbName());
    Assert.assertEquals("id", list.get(4).dbName());
    Assert.assertEquals("type", list.get(5).dbName());
    Assert.assertEquals("name", list.get(6).dbName());
    try (final Tx tx = app.tx()) {
        // modify sort order
        testView.setProperty(SchemaView.sortOrder, "type, one, id, two, three, four, name");
        // create test entity
        final NodeInterface node = app.create(StructrApp.getConfiguration().getNodeEntityClass("Test"));
        id = node.getUuid();
        tx.success();
    } catch (FrameworkException fex) {
        fex.printStackTrace();
    }
    final List<PropertyKey> list2 = new LinkedList<>(StructrApp.getConfiguration().getPropertySet(type, "test"));
    Assert.assertEquals("Invalid number of properties in sorted view", 7, list2.size());
    Assert.assertEquals("type", list2.get(0).dbName());
    Assert.assertEquals("one", list2.get(1).dbName());
    Assert.assertEquals("id", list2.get(2).dbName());
    Assert.assertEquals("two", list2.get(3).dbName());
    Assert.assertEquals("three", list2.get(4).dbName());
    Assert.assertEquals("four", list2.get(5).dbName());
    Assert.assertEquals("name", list2.get(6).dbName());
    // test schema resource
    RestAssured.given().contentType("application/json; charset=UTF-8").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).expect().statusCode(200).body("result", hasSize(7)).body("result[0].jsonName", equalTo("type")).body("result[1].jsonName", equalTo("one")).body("result[2].jsonName", equalTo("id")).body("result[3].jsonName", equalTo("two")).body("result[4].jsonName", equalTo("three")).body("result[5].jsonName", equalTo("four")).body("result[6].jsonName", equalTo("name")).when().get("/_schema/Test/test");
    // test actual REST resource (not easy to extract and verify
    // JSON property order, that's why we're using replaceAll and
    // string comparison..
    final String[] actual = 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).expect().statusCode(200).when().get("/Test/test").body().asString().replaceAll("[\\s]+", "").split("[\\W]+");
    // we can only test the actual ORDER of the JSON result object by splitting it on whitespace and validating the resulting array
    assertEquals("Invalid JSON result for sorted property view", "", actual[0]);
    assertEquals("Invalid JSON result for sorted property view", "query_time", actual[1]);
    assertEquals("Invalid JSON result for sorted property view", "0", actual[2]);
    assertEquals("Invalid JSON result for sorted property view", "result_count", actual[4]);
    assertEquals("Invalid JSON result for sorted property view", "1", actual[5]);
    assertEquals("Invalid JSON result for sorted property view", "result", actual[6]);
    assertEquals("Invalid JSON result for sorted property view", "type", actual[7]);
    assertEquals("Invalid JSON result for sorted property view", "Test", actual[8]);
    assertEquals("Invalid JSON result for sorted property view", "one", actual[9]);
    assertEquals("Invalid JSON result for sorted property view", "null", actual[10]);
    assertEquals("Invalid JSON result for sorted property view", "id", actual[11]);
    assertEquals("Invalid JSON result for sorted property view", id, actual[12]);
    assertEquals("Invalid JSON result for sorted property view", "two", actual[13]);
    assertEquals("Invalid JSON result for sorted property view", "null", actual[14]);
    assertEquals("Invalid JSON result for sorted property view", "three", actual[15]);
    assertEquals("Invalid JSON result for sorted property view", "null", actual[16]);
    assertEquals("Invalid JSON result for sorted property view", "four", actual[17]);
    assertEquals("Invalid JSON result for sorted property view", "null", actual[18]);
    assertEquals("Invalid JSON result for sorted property view", "name", actual[19]);
    assertEquals("Invalid JSON result for sorted property view", "null", actual[20]);
    assertEquals("Invalid JSON result for sorted property view", "serialization_time", actual[21]);
    // try built-in function
    try {
        final List<GraphObjectMap> list3 = (List) new TypeInfoFunction().apply(new ActionContext(securityContext), null, new Object[] { "Test", "test" });
        Assert.assertEquals("Invalid number of properties in sorted view", 7, list2.size());
        Assert.assertEquals("type", list3.get(0).get(jsonName));
        Assert.assertEquals("one", list3.get(1).get(jsonName));
        Assert.assertEquals("id", list3.get(2).get(jsonName));
        Assert.assertEquals("two", list3.get(3).get(jsonName));
        Assert.assertEquals("three", list3.get(4).get(jsonName));
        Assert.assertEquals("four", list3.get(5).get(jsonName));
        Assert.assertEquals("name", list3.get(6).get(jsonName));
    } catch (FrameworkException fex) {
        fex.printStackTrace();
    }
    // try scripting call
    try {
        final List<GraphObjectMap> list4 = (List) Scripting.evaluate(new ActionContext(securityContext), null, "${type_info('Test', 'test')}", "test");
        Assert.assertEquals("Invalid number of properties in sorted view", 7, list2.size());
        Assert.assertEquals("type", list4.get(0).get(jsonName));
        Assert.assertEquals("one", list4.get(1).get(jsonName));
        Assert.assertEquals("id", list4.get(2).get(jsonName));
        Assert.assertEquals("two", list4.get(3).get(jsonName));
        Assert.assertEquals("three", list4.get(4).get(jsonName));
        Assert.assertEquals("four", list4.get(5).get(jsonName));
        Assert.assertEquals("name", list4.get(6).get(jsonName));
    } catch (FrameworkException fex) {
        fex.printStackTrace();
    }
}
Also used : NodeAttribute(org.structr.core.graph.NodeAttribute) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) ActionContext(org.structr.schema.action.ActionContext) FrameworkException(org.structr.common.error.FrameworkException) LinkedList(java.util.LinkedList) SchemaView(org.structr.core.entity.SchemaView) SchemaNode(org.structr.core.entity.SchemaNode) TypeInfoFunction(org.structr.core.function.TypeInfoFunction) GraphObjectMap(org.structr.core.GraphObjectMap) GenericProperty(org.structr.core.property.GenericProperty) LinkedList(java.util.LinkedList) List(java.util.List) PropertyKey(org.structr.core.property.PropertyKey) NodeInterface(org.structr.core.graph.NodeInterface) FrontendTest(org.structr.web.basic.FrontendTest) ResourceAccessTest(org.structr.web.basic.ResourceAccessTest) Test(org.junit.Test)

Example 3 with GenericProperty

use of org.structr.core.property.GenericProperty in project structr by structr.

the class CypherQueryCommand method handleObject.

final Object handleObject(final NodeFactory nodeFactory, final RelationshipFactory relFactory, final String key, final Object value, boolean includeHiddenAndDeleted, boolean publicOnly, int level) throws FrameworkException {
    GraphObject graphObject = null;
    if (value instanceof Node) {
        graphObject = nodeFactory.instantiate((Node) value, includeHiddenAndDeleted, publicOnly);
    } else if (value instanceof Relationship) {
        graphObject = relFactory.instantiate((Relationship) value);
    } else if (value instanceof Map) {
        final Map<String, Object> valueMap = (Map<String, Object>) value;
        graphObject = new GraphObjectMap();
        for (final Entry<String, Object> valueEntry : valueMap.entrySet()) {
            final String valueKey = valueEntry.getKey();
            final Object valueValue = valueEntry.getValue();
            graphObject.setProperty(new GenericProperty(valueKey), handleObject(nodeFactory, relFactory, valueKey, valueValue, includeHiddenAndDeleted, publicOnly, level + 1));
        }
    } else if (value instanceof Collection) {
        final Collection<Object> valueCollection = (Collection<Object>) value;
        final List<Object> collection = new LinkedList<>();
        for (final Object valueEntry : valueCollection) {
            collection.add(handleObject(nodeFactory, relFactory, null, valueEntry, includeHiddenAndDeleted, publicOnly, level + 1));
        }
        return collection;
    } else if (level == 0) {
        graphObject = new GraphObjectMap();
        graphObject.setProperty(new GenericProperty(key), value);
    } else {
        return value;
    }
    return graphObject;
}
Also used : Node(org.structr.api.graph.Node) GraphObject(org.structr.core.GraphObject) Relationship(org.structr.api.graph.Relationship) GraphObjectMap(org.structr.core.GraphObjectMap) GenericProperty(org.structr.core.property.GenericProperty) Collection(java.util.Collection) GraphObject(org.structr.core.GraphObject) List(java.util.List) LinkedList(java.util.LinkedList) Map(java.util.Map) GraphObjectMap(org.structr.core.GraphObjectMap)

Example 4 with GenericProperty

use of org.structr.core.property.GenericProperty in project structr by structr.

the class FileImportVisitor method handleDeferredFiles.

public void handleDeferredFiles() {
    final Class<Relation> relType = StructrApp.getConfiguration().getRelationshipEntityClass("AbstractMinifiedFileMINIFICATIONFile");
    final PropertyKey<Integer> positionKey = StructrApp.key(relType, "position");
    if (!this.deferredFiles.isEmpty()) {
        for (File file : this.deferredFiles) {
            try (final Tx tx = app.tx(true, false, false)) {
                // set properties from files.json
                final PropertyMap fileProperties = getPropertiesForFileOrFolder(file.getPath());
                final PropertyKey<Map<String, String>> sourcesPropertyKey = new GenericProperty("minificationSources");
                Map<String, String> sourcesConfig = fileProperties.get(sourcesPropertyKey);
                fileProperties.remove(sourcesPropertyKey);
                file.unlockSystemPropertiesOnce();
                file.setProperties(securityContext, fileProperties);
                for (String positionString : sourcesConfig.keySet()) {
                    final Integer position = Integer.parseInt(positionString);
                    final String sourcePath = sourcesConfig.get(positionString);
                    final AbstractFile source = FileHelper.getFileByAbsolutePath(securityContext, sourcePath);
                    if (source != null) {
                        app.create(app.get(AbstractMinifiedFile.class, file.getUuid()), (File) source, relType, new PropertyMap(positionKey, position));
                    } else {
                        logger.warn("Source file {} for minified file {} at position {} not found - please verify that it is included in the export", sourcePath, file.getPath(), positionString);
                    }
                }
                tx.success();
            } catch (FrameworkException fxe) {
            }
        }
    }
}
Also used : AbstractFile(org.structr.web.entity.AbstractFile) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) Relation(org.structr.core.entity.Relation) PropertyMap(org.structr.core.property.PropertyMap) GenericProperty(org.structr.core.property.GenericProperty) AbstractMinifiedFile(org.structr.web.entity.AbstractMinifiedFile) AbstractFile(org.structr.web.entity.AbstractFile) AbstractMinifiedFile(org.structr.web.entity.AbstractMinifiedFile) File(org.structr.web.entity.File) HashMap(java.util.HashMap) PropertyMap(org.structr.core.property.PropertyMap) Map(java.util.Map)

Example 5 with GenericProperty

use of org.structr.core.property.GenericProperty in project structr by structr.

the class DOMNode method render.

static void render(final DOMNode thisNode, final RenderContext renderContext, final int depth) throws FrameworkException {
    final SecurityContext securityContext = renderContext.getSecurityContext();
    if (!securityContext.isVisible(thisNode)) {
        return;
    }
    final GraphObject details = renderContext.getDetailsDataObject();
    final boolean detailMode = details != null;
    if (detailMode && thisNode.hideOnDetail()) {
        return;
    }
    if (!detailMode && thisNode.hideOnIndex()) {
        return;
    }
    final EditMode editMode = renderContext.getEditMode(securityContext.getUser(false));
    if (EditMode.RAW.equals(editMode) || EditMode.WIDGET.equals(editMode) || EditMode.DEPLOYMENT.equals(editMode)) {
        thisNode.renderContent(renderContext, depth);
    } else {
        final String subKey = thisNode.getDataKey();
        if (StringUtils.isNotBlank(subKey)) {
            final GraphObject currentDataNode = renderContext.getDataObject();
            // fetch (optional) list of external data elements
            final Iterable<GraphObject> listData = checkListSources(thisNode, securityContext, renderContext);
            final PropertyKey propertyKey;
            if (thisNode.renderDetails() && detailMode) {
                renderContext.setDataObject(details);
                renderContext.putDataObject(subKey, details);
                thisNode.renderContent(renderContext, depth);
            } else {
                if (Iterables.isEmpty(listData) && currentDataNode != null) {
                    // There are two alternative ways of retrieving sub elements:
                    // First try to get generic properties,
                    // if that fails, try to create a propertyKey for the subKey
                    final Object elements = currentDataNode.getProperty(new GenericProperty(subKey));
                    renderContext.setRelatedProperty(new GenericProperty(subKey));
                    renderContext.setSourceDataObject(currentDataNode);
                    if (elements != null) {
                        if (elements instanceof Iterable) {
                            for (Object o : (Iterable) elements) {
                                if (o instanceof GraphObject) {
                                    GraphObject graphObject = (GraphObject) o;
                                    renderContext.putDataObject(subKey, graphObject);
                                    thisNode.renderContent(renderContext, depth);
                                }
                            }
                        }
                    } else {
                        propertyKey = StructrApp.getConfiguration().getPropertyKeyForJSONName(currentDataNode.getClass(), subKey, false);
                        renderContext.setRelatedProperty(propertyKey);
                        if (propertyKey != null) {
                            final Object value = currentDataNode.getProperty(propertyKey);
                            if (value != null) {
                                if (value instanceof Iterable) {
                                    for (final Object o : ((Iterable) value)) {
                                        if (o instanceof GraphObject) {
                                            renderContext.putDataObject(subKey, (GraphObject) o);
                                            thisNode.renderContent(renderContext, depth);
                                        }
                                    }
                                }
                            }
                        }
                    }
                    // reset data node in render context
                    renderContext.setDataObject(currentDataNode);
                    renderContext.setRelatedProperty(null);
                } else {
                    renderContext.setListSource(listData);
                    thisNode.renderNodeList(securityContext, renderContext, depth, subKey);
                }
            }
        } else {
            thisNode.renderContent(renderContext, depth);
        }
    }
}
Also used : SecurityContext(org.structr.common.SecurityContext) GenericProperty(org.structr.core.property.GenericProperty) EditMode(org.structr.web.common.RenderContext.EditMode) GraphObject(org.structr.core.GraphObject) GraphObject(org.structr.core.GraphObject) PropertyKey(org.structr.core.property.PropertyKey)

Aggregations

GenericProperty (org.structr.core.property.GenericProperty)16 GraphObjectMap (org.structr.core.GraphObjectMap)12 LinkedList (java.util.LinkedList)9 GraphObject (org.structr.core.GraphObject)8 PropertyKey (org.structr.core.property.PropertyKey)7 List (java.util.List)5 Map (java.util.Map)5 HashMap (java.util.HashMap)4 FrameworkException (org.structr.common.error.FrameworkException)4 Result (org.structr.core.Result)4 NodeInterface (org.structr.core.graph.NodeInterface)4 Tx (org.structr.core.graph.Tx)4 RestMethodResult (org.structr.rest.RestMethodResult)4 LinkedHashMap (java.util.LinkedHashMap)3 LinkedHashSet (java.util.LinkedHashSet)3 TreeMap (java.util.TreeMap)3 Test (org.junit.Test)3 SchemaNode (org.structr.core.entity.SchemaNode)3 SchemaView (org.structr.core.entity.SchemaView)3 TypeInfoFunction (org.structr.core.function.TypeInfoFunction)3