Search in sources :

Example 1 with TypeInfoFunction

use of org.structr.core.function.TypeInfoFunction 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 TypeInfoFunction

use of org.structr.core.function.TypeInfoFunction 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 TypeInfoFunction

use of org.structr.core.function.TypeInfoFunction in project structr by structr.

the class CoreModule method onLoad.

@Override
public void onLoad(final LicenseManager licenseManager) {
    final boolean licensed = licenseManager == null || licenseManager.isEdition(LicenseManager.Basic);
    // Basic Edition
    Functions.put(licensed, LicenseManager.Basic, "error", new ErrorFunction());
    Functions.put(licensed, LicenseManager.Basic, "config", new ConfigFunction());
    Functions.put(licensed, LicenseManager.Basic, "changelog", new ChangelogFunction());
    Functions.put(licensed, LicenseManager.Basic, "serverlog", new ServerLogFunction());
    Functions.put(licensed, LicenseManager.Basic, "grant", new GrantFunction());
    Functions.put(licensed, LicenseManager.Basic, "revoke", new RevokeFunction());
    Functions.put(licensed, LicenseManager.Basic, "is_allowed", new IsAllowedFunction());
    Functions.put(licensed, LicenseManager.Basic, "add_to_group", new AddToGroupFunction());
    Functions.put(licensed, LicenseManager.Basic, "remove_from_group", new RemoveFromGroupFunction());
    Functions.put(licensed, LicenseManager.Basic, "is_in_group", new IsInGroupFunction());
    Functions.put(licensed, LicenseManager.Basic, "localize", new LocalizeFunction());
    Functions.put(licensed, LicenseManager.Basic, "call", new CallFunction());
    Functions.put(licensed, LicenseManager.Basic, "call_privileged", new CallPrivilegedFunction());
    Functions.put(licensed, LicenseManager.Basic, "exec", new ExecFunction());
    Functions.put(licensed, LicenseManager.Basic, "exec_binary", new ExecBinaryFunction());
    Functions.put(licensed, LicenseManager.Basic, "unlock_readonly_properties_once", new UnlockReadonlyPropertiesFunction());
    Functions.put(licensed, LicenseManager.Basic, "unlock_system_properties_once", new UnlockSystemPropertiesFunction());
    Functions.put(licensed, LicenseManager.Basic, "set_privileged", new SetPrivilegedFunction());
    Functions.put(licensed, LicenseManager.Basic, "find_privileged", new PrivilegedFindFunction());
    Functions.put(licensed, LicenseManager.Basic, "read", new ReadFunction());
    Functions.put(licensed, LicenseManager.Basic, "write", new WriteFunction());
    Functions.put(licensed, LicenseManager.Basic, "append", new AppendFunction());
    Functions.put(licensed, LicenseManager.Basic, "xml", new XmlFunction());
    Functions.put(licensed, LicenseManager.Basic, "xpath", new XPathFunction());
    Functions.put(licensed, LicenseManager.Basic, "geocode", new GeocodeFunction());
    Functions.put(licensed, LicenseManager.Basic, "instantiate", new InstantiateFunction());
    Functions.put(licensed, LicenseManager.Basic, "property_info", new PropertyInfoFunction());
    Functions.put(licensed, LicenseManager.Basic, "type_info", new TypeInfoFunction());
    Functions.put(licensed, LicenseManager.Basic, "enum_info", new EnumInfoFunction());
    Functions.put(licensed, LicenseManager.Basic, "disable_notifications", new DisableNotificationsFunction());
    Functions.put(licensed, LicenseManager.Basic, "enable_notifications", new EnableNotificationsFunction());
    Functions.put(licensed, LicenseManager.Basic, "r", new RInterpreterFunction());
    Functions.put(licensed, LicenseManager.Basic, "evaluate_script", new EvaluateScriptFunction());
    Functions.put(licensed, LicenseManager.Basic, "ancestor_types", new AncestorTypesFunction());
    Functions.put(licensed, LicenseManager.Basic, "inheriting_types", new InheritingTypesFunction());
    Functions.put(licensed, LicenseManager.Basic, "template", new TemplateFunction());
    Functions.put(licensed, LicenseManager.Basic, "jdbc", new JdbcFunction());
    // Community Edition
    Functions.put(true, LicenseManager.Community, "cypher", new CypherFunction());
    Functions.put(true, LicenseManager.Community, "md5", new MD5Function());
    Functions.put(true, LicenseManager.Community, "upper", new UpperFunction());
    Functions.put(true, LicenseManager.Community, "lower", new LowerFunction());
    Functions.put(true, LicenseManager.Community, "join", new JoinFunction());
    Functions.put(true, LicenseManager.Community, "concat", new ConcatFunction());
    Functions.put(true, LicenseManager.Community, "split", new SplitFunction());
    Functions.put(true, LicenseManager.Community, "split_regex", new SplitRegexFunction());
    Functions.put(true, LicenseManager.Community, "abbr", new AbbrFunction());
    Functions.put(true, LicenseManager.Community, "capitalize", new CapitalizeFunction());
    Functions.put(true, LicenseManager.Community, "titleize", new TitleizeFunction());
    Functions.put(true, LicenseManager.Community, "num", new NumFunction());
    Functions.put(true, LicenseManager.Community, "int", new IntFunction());
    Functions.put(true, LicenseManager.Community, "random", new RandomFunction());
    Functions.put(true, LicenseManager.Community, "rint", new RintFunction());
    Functions.put(true, LicenseManager.Community, "index_of", new IndexOfFunction());
    Functions.put(true, LicenseManager.Community, "contains", new ContainsFunction());
    Functions.put(true, LicenseManager.Community, "copy_permissions", new CopyPermissionsFunction());
    Functions.put(true, LicenseManager.Community, "substring", new SubstringFunction());
    Functions.put(true, LicenseManager.Community, "length", new LengthFunction());
    Functions.put(true, LicenseManager.Community, "replace", new ReplaceFunction());
    Functions.put(true, LicenseManager.Community, "trim", new TrimFunction());
    Functions.put(true, LicenseManager.Community, "clean", new CleanFunction());
    Functions.put(true, LicenseManager.Community, "coalesce", new CoalesceFunction());
    Functions.put(true, LicenseManager.Community, "urlencode", new UrlEncodeFunction());
    Functions.put(true, LicenseManager.Community, "escape_javascript", new EscapeJavascriptFunction());
    Functions.put(true, LicenseManager.Community, "escape_json", new EscapeJsonFunction());
    Functions.put(true, LicenseManager.Community, "empty", new EmptyFunction());
    Functions.put(true, LicenseManager.Community, "equal", new EqualFunction());
    Functions.put(true, LicenseManager.Community, "eq", new EqualFunction());
    Functions.put(true, LicenseManager.Community, "add", new AddFunction());
    Functions.put(true, LicenseManager.Community, "double_sum", new DoubleSumFunction());
    Functions.put(true, LicenseManager.Community, "int_sum", new IntSumFunction());
    Functions.put(true, LicenseManager.Community, "is_collection", new IsCollectionFunction());
    Functions.put(true, LicenseManager.Community, "is_entity", new IsEntityFunction());
    Functions.put(true, LicenseManager.Community, "extract", new ExtractFunction());
    Functions.put(true, LicenseManager.Community, "merge", new MergeFunction());
    Functions.put(true, LicenseManager.Community, "merge_unique", new MergeUniqueFunction());
    Functions.put(true, LicenseManager.Community, "complement", new ComplementFunction());
    Functions.put(true, LicenseManager.Community, "unwind", new UnwindFunction());
    Functions.put(true, LicenseManager.Community, "sort", new SortFunction());
    Functions.put(true, LicenseManager.Community, "lt", new LtFunction());
    Functions.put(true, LicenseManager.Community, "gt", new GtFunction());
    Functions.put(true, LicenseManager.Community, "lte", new LteFunction());
    Functions.put(true, LicenseManager.Community, "gte", new GteFunction());
    Functions.put(true, LicenseManager.Community, "subt", new SubtFunction());
    Functions.put(true, LicenseManager.Community, "mult", new MultFunction());
    Functions.put(true, LicenseManager.Community, "quot", new QuotFunction());
    Functions.put(true, LicenseManager.Community, "div", new DivFunction());
    Functions.put(true, LicenseManager.Community, "mod", new ModFunction());
    Functions.put(true, LicenseManager.Community, "floor", new FloorFunction());
    Functions.put(true, LicenseManager.Community, "ceil", new CeilFunction());
    Functions.put(true, LicenseManager.Community, "round", new RoundFunction());
    Functions.put(true, LicenseManager.Community, "max", new MaxFunction());
    Functions.put(true, LicenseManager.Community, "min", new MinFunction());
    Functions.put(true, LicenseManager.Community, "date_format", new DateFormatFunction());
    Functions.put(true, LicenseManager.Community, "parse_date", new ParseDateFunction());
    Functions.put(true, LicenseManager.Community, "to_date", new ToDateFunction());
    Functions.put(true, LicenseManager.Community, "number_format", new NumberFormatFunction());
    Functions.put(true, LicenseManager.Community, "parse_number", new ParseNumberFunction());
    Functions.put(true, LicenseManager.Community, "not", new NotFunction());
    Functions.put(true, LicenseManager.Community, "and", new AndFunction());
    Functions.put(true, LicenseManager.Community, "or", new OrFunction());
    Functions.put(true, LicenseManager.Community, "get", new GetFunction());
    Functions.put(true, LicenseManager.Community, "get_or_null", new GetOrNullFunction());
    Functions.put(true, LicenseManager.Community, "size", new SizeFunction());
    Functions.put(true, LicenseManager.Community, "first", new FirstFunction());
    Functions.put(true, LicenseManager.Community, "last", new LastFunction());
    Functions.put(true, LicenseManager.Community, "nth", new NthFunction());
    Functions.put(true, LicenseManager.Community, "get_counter", new GetCounterFunction());
    Functions.put(true, LicenseManager.Community, "inc_counter", new IncCounterFunction());
    Functions.put(true, LicenseManager.Community, "reset_counter", new ResetCounterFunction());
    Functions.put(true, LicenseManager.Community, "merge_properties", new MergePropertiesFunction());
    Functions.put(true, LicenseManager.Community, "keys", new KeysFunction());
    Functions.put(true, LicenseManager.Community, "values", new ValuesFunction());
    Functions.put(true, LicenseManager.Community, "timer", new TimerFunction());
    Functions.put(true, LicenseManager.Community, "str_replace", new StrReplaceFunction());
    Functions.put(true, LicenseManager.Community, "search", new SearchFunction());
    Functions.put(true, LicenseManager.Community, "incoming", new IncomingFunction());
    Functions.put(true, LicenseManager.Community, "outgoing", new OutgoingFunction());
    Functions.put(true, LicenseManager.Community, "has_relationship", new HasRelationshipFunction());
    Functions.put(true, LicenseManager.Community, "has_outgoing_relationship", new HasOutgoingRelationshipFunction());
    Functions.put(true, LicenseManager.Community, "has_incoming_relationship", new HasIncomingRelationshipFunction());
    Functions.put(true, LicenseManager.Community, "get_relationships", new GetRelationshipsFunction());
    Functions.put(true, LicenseManager.Community, "get_outgoing_relationships", new GetOutgoingRelationshipsFunction());
    Functions.put(true, LicenseManager.Community, "get_incoming_relationships", new GetIncomingRelationshipsFunction());
    Functions.put(true, LicenseManager.Community, "retrieve", new RetrieveFunction());
    Functions.put(true, LicenseManager.Community, "store", new StoreFunction());
    Functions.put(true, LicenseManager.Community, "print", new PrintFunction());
    Functions.put(true, LicenseManager.Community, "log", new LogFunction());
    Functions.put(true, LicenseManager.Community, "find", new FindFunction());
    Functions.put(true, LicenseManager.Community, "get_or_create", new GetOrCreateFunction());
    Functions.put(true, LicenseManager.Community, "find_relationship", new FindRelationshipFunction());
    Functions.put(true, LicenseManager.Community, "starts_with", new StartsWithFunction());
    Functions.put(true, LicenseManager.Community, "ends_with", new EndsWithFunction());
    Functions.put(true, LicenseManager.Community, "base64encode", new Base64EncodeFunction());
    Functions.put(true, LicenseManager.Community, "base64decode", new Base64DecodeFunction());
    // ----- BEGIN functions with side effects -----
    Functions.put(true, LicenseManager.Community, "set", new SetFunction());
    Functions.put(true, LicenseManager.Community, "create", new CreateFunction());
    Functions.put(true, LicenseManager.Community, "delete", new DeleteFunction());
    Functions.put(true, LicenseManager.Community, "create_relationship", new CreateRelationshipFunction());
}
Also used : HasRelationshipFunction(org.structr.core.function.HasRelationshipFunction) LowerFunction(org.structr.core.function.LowerFunction) IsCollectionFunction(org.structr.core.function.IsCollectionFunction) XmlFunction(org.structr.core.function.XmlFunction) CypherFunction(org.structr.core.function.CypherFunction) ResetCounterFunction(org.structr.core.function.ResetCounterFunction) PrivilegedFindFunction(org.structr.core.function.PrivilegedFindFunction) FindFunction(org.structr.core.function.FindFunction) ExecFunction(org.structr.core.function.ExecFunction) GetIncomingRelationshipsFunction(org.structr.core.function.GetIncomingRelationshipsFunction) InheritingTypesFunction(org.structr.core.function.InheritingTypesFunction) SplitFunction(org.structr.core.function.SplitFunction) GetOutgoingRelationshipsFunction(org.structr.core.function.GetOutgoingRelationshipsFunction) EqualFunction(org.structr.core.function.EqualFunction) PrintFunction(org.structr.core.function.PrintFunction) OutgoingFunction(org.structr.core.function.OutgoingFunction) SortFunction(org.structr.core.function.SortFunction) ServerLogFunction(org.structr.core.function.ServerLogFunction) IncomingFunction(org.structr.core.function.IncomingFunction) NotFunction(org.structr.core.function.NotFunction) GetOrCreateFunction(org.structr.core.function.GetOrCreateFunction) MergeFunction(org.structr.core.function.MergeFunction) EnableNotificationsFunction(org.structr.core.function.EnableNotificationsFunction) GrantFunction(org.structr.core.function.GrantFunction) LastFunction(org.structr.core.function.LastFunction) StrReplaceFunction(org.structr.core.function.StrReplaceFunction) AndFunction(org.structr.core.function.AndFunction) AddToGroupFunction(org.structr.core.function.AddToGroupFunction) SubtFunction(org.structr.core.function.SubtFunction) AbbrFunction(org.structr.core.function.AbbrFunction) GteFunction(org.structr.core.function.GteFunction) MergeUniqueFunction(org.structr.core.function.MergeUniqueFunction) GetRelationshipsFunction(org.structr.core.function.GetRelationshipsFunction) IntFunction(org.structr.core.function.IntFunction) EscapeJavascriptFunction(org.structr.core.function.EscapeJavascriptFunction) ParseNumberFunction(org.structr.core.function.ParseNumberFunction) RintFunction(org.structr.core.function.RintFunction) FirstFunction(org.structr.core.function.FirstFunction) AppendFunction(org.structr.core.function.AppendFunction) AncestorTypesFunction(org.structr.core.function.AncestorTypesFunction) NumberFormatFunction(org.structr.core.function.NumberFormatFunction) RevokeFunction(org.structr.core.function.RevokeFunction) ToDateFunction(org.structr.core.function.ToDateFunction) GetCounterFunction(org.structr.core.function.GetCounterFunction) CopyPermissionsFunction(org.structr.core.function.CopyPermissionsFunction) ValuesFunction(org.structr.core.function.ValuesFunction) EscapeJsonFunction(org.structr.core.function.EscapeJsonFunction) Base64DecodeFunction(org.structr.core.function.Base64DecodeFunction) UnlockSystemPropertiesFunction(org.structr.core.function.UnlockSystemPropertiesFunction) IsAllowedFunction(org.structr.core.function.IsAllowedFunction) IndexOfFunction(org.structr.core.function.IndexOfFunction) MinFunction(org.structr.core.function.MinFunction) GetOrNullFunction(org.structr.core.function.GetOrNullFunction) MultFunction(org.structr.core.function.MultFunction) WriteFunction(org.structr.core.function.WriteFunction) LtFunction(org.structr.core.function.LtFunction) RandomFunction(org.structr.core.function.RandomFunction) CallFunction(org.structr.core.function.CallFunction) ModFunction(org.structr.core.function.ModFunction) IncCounterFunction(org.structr.core.function.IncCounterFunction) CreateRelationshipFunction(org.structr.core.function.CreateRelationshipFunction) ErrorFunction(org.structr.core.function.ErrorFunction) RetrieveFunction(org.structr.core.function.RetrieveFunction) CapitalizeFunction(org.structr.core.function.CapitalizeFunction) CallPrivilegedFunction(org.structr.core.function.CallPrivilegedFunction) TypeInfoFunction(org.structr.core.function.TypeInfoFunction) SetFunction(org.structr.core.function.SetFunction) ParseDateFunction(org.structr.core.function.ParseDateFunction) ServerLogFunction(org.structr.core.function.ServerLogFunction) LogFunction(org.structr.core.function.LogFunction) UnlockReadonlyPropertiesFunction(org.structr.core.function.UnlockReadonlyPropertiesFunction) ReadFunction(org.structr.core.function.ReadFunction) JoinFunction(org.structr.core.function.JoinFunction) GeocodeFunction(org.structr.core.function.GeocodeFunction) EndsWithFunction(org.structr.core.function.EndsWithFunction) ConfigFunction(org.structr.core.function.ConfigFunction) ExecBinaryFunction(org.structr.core.function.ExecBinaryFunction) JdbcFunction(org.structr.core.function.JdbcFunction) DoubleSumFunction(org.structr.core.function.DoubleSumFunction) PropertyInfoFunction(org.structr.core.function.PropertyInfoFunction) GetOrCreateFunction(org.structr.core.function.GetOrCreateFunction) CreateFunction(org.structr.core.function.CreateFunction) SplitRegexFunction(org.structr.core.function.SplitRegexFunction) UrlEncodeFunction(org.structr.core.function.UrlEncodeFunction) ConcatFunction(org.structr.core.function.ConcatFunction) FloorFunction(org.structr.core.function.FloorFunction) GtFunction(org.structr.core.function.GtFunction) ChangelogFunction(org.structr.core.function.ChangelogFunction) ExtractFunction(org.structr.core.function.ExtractFunction) SizeFunction(org.structr.core.function.SizeFunction) IsEntityFunction(org.structr.core.function.IsEntityFunction) UpperFunction(org.structr.core.function.UpperFunction) QuotFunction(org.structr.core.function.QuotFunction) RoundFunction(org.structr.core.function.RoundFunction) SetPrivilegedFunction(org.structr.core.function.SetPrivilegedFunction) EnumInfoFunction(org.structr.core.function.EnumInfoFunction) TemplateFunction(org.structr.core.function.TemplateFunction) Base64EncodeFunction(org.structr.core.function.Base64EncodeFunction) InstantiateFunction(org.structr.core.function.InstantiateFunction) IsInGroupFunction(org.structr.core.function.IsInGroupFunction) TrimFunction(org.structr.core.function.TrimFunction) OrFunction(org.structr.core.function.OrFunction) ContainsFunction(org.structr.core.function.ContainsFunction) StoreFunction(org.structr.core.function.StoreFunction) TitleizeFunction(org.structr.core.function.TitleizeFunction) CoalesceFunction(org.structr.core.function.CoalesceFunction) GetFunction(org.structr.core.function.GetFunction) HasIncomingRelationshipFunction(org.structr.core.function.HasIncomingRelationshipFunction) MergePropertiesFunction(org.structr.core.function.MergePropertiesFunction) StrReplaceFunction(org.structr.core.function.StrReplaceFunction) ReplaceFunction(org.structr.core.function.ReplaceFunction) TimerFunction(org.structr.core.function.TimerFunction) StartsWithFunction(org.structr.core.function.StartsWithFunction) RInterpreterFunction(org.structr.core.function.RInterpreterFunction) SubstringFunction(org.structr.core.function.SubstringFunction) NumFunction(org.structr.core.function.NumFunction) MD5Function(org.structr.core.function.MD5Function) NthFunction(org.structr.core.function.NthFunction) FindRelationshipFunction(org.structr.core.function.FindRelationshipFunction) LengthFunction(org.structr.core.function.LengthFunction) SearchFunction(org.structr.core.function.SearchFunction) AddFunction(org.structr.core.function.AddFunction) RemoveFromGroupFunction(org.structr.core.function.RemoveFromGroupFunction) LteFunction(org.structr.core.function.LteFunction) EvaluateScriptFunction(org.structr.core.function.EvaluateScriptFunction) LocalizeFunction(org.structr.core.function.LocalizeFunction) XPathFunction(org.structr.core.function.XPathFunction) MaxFunction(org.structr.core.function.MaxFunction) KeysFunction(org.structr.core.function.KeysFunction) DateFormatFunction(org.structr.core.function.DateFormatFunction) PrivilegedFindFunction(org.structr.core.function.PrivilegedFindFunction) HasOutgoingRelationshipFunction(org.structr.core.function.HasOutgoingRelationshipFunction) EmptyFunction(org.structr.core.function.EmptyFunction) ComplementFunction(org.structr.core.function.ComplementFunction) DisableNotificationsFunction(org.structr.core.function.DisableNotificationsFunction) IntSumFunction(org.structr.core.function.IntSumFunction) DivFunction(org.structr.core.function.DivFunction) DeleteFunction(org.structr.core.function.DeleteFunction) UnwindFunction(org.structr.core.function.UnwindFunction) CleanFunction(org.structr.core.function.CleanFunction) CeilFunction(org.structr.core.function.CeilFunction)

Example 4 with TypeInfoFunction

use of org.structr.core.function.TypeInfoFunction in project structr by structr.

the class AdvancedSchemaTest method test04SchemaPropertyOrderInBuiltInViews.

@Test
public void test04SchemaPropertyOrderInBuiltInViews() {
    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");
    SchemaNode test = null;
    String id = null;
    try (final Tx tx = app.tx()) {
        // create test type
        test = app.create(SchemaNode.class, "Test");
        tx.success();
    } catch (FrameworkException fex) {
        fex.printStackTrace();
    }
    try (final Tx tx = app.tx()) {
        // create view with sort order
        final List<SchemaView> list = test.getProperty(SchemaNode.schemaViews);
        // 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, "public"));
    Assert.assertEquals("Invalid number of properties in sorted view", 6, list.size());
    Assert.assertEquals("id", list.get(0).dbName());
    Assert.assertEquals("type", list.get(1).dbName());
    Assert.assertEquals("one", list.get(2).dbName());
    Assert.assertEquals("two", list.get(3).dbName());
    Assert.assertEquals("three", list.get(4).dbName());
    Assert.assertEquals("four", list.get(5).dbName());
    try (final Tx tx = app.tx()) {
        for (final SchemaView testView : test.getProperty(SchemaNode.schemaViews)) {
            // 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"));
        // save UUID for later
        id = node.getUuid();
        tx.success();
    } catch (FrameworkException fex) {
        fex.printStackTrace();
    }
    final List<PropertyKey> list2 = new LinkedList<>(StructrApp.getConfiguration().getPropertySet(type, "public"));
    Assert.assertEquals("Invalid number of properties in sorted view", 6, list2.size());
    Assert.assertEquals("id", list2.get(0).dbName());
    Assert.assertEquals("type", list2.get(1).dbName());
    Assert.assertEquals("one", 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());
    // 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(6)).body("result[0].jsonName", equalTo("id")).body("result[1].jsonName", equalTo("type")).body("result[2].jsonName", equalTo("one")).body("result[3].jsonName", equalTo("two")).body("result[4].jsonName", equalTo("three")).body("result[5].jsonName", equalTo("four")).when().get("/_schema/Test/public");
    // 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").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", "id", actual[7]);
    assertEquals("Invalid JSON result for sorted property view", id, actual[8]);
    assertEquals("Invalid JSON result for sorted property view", "type", actual[9]);
    assertEquals("Invalid JSON result for sorted property view", "Test", actual[10]);
    assertEquals("Invalid JSON result for sorted property view", "one", actual[11]);
    assertEquals("Invalid JSON result for sorted property view", "null", 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", "serialization_time", actual[19]);
    // try built-in function
    try {
        final List<GraphObjectMap> list3 = (List) new TypeInfoFunction().apply(new ActionContext(securityContext), null, new Object[] { "Test", "public" });
        Assert.assertEquals("Invalid number of properties in sorted view", 6, list3.size());
        Assert.assertEquals("id", list3.get(0).get(jsonName));
        Assert.assertEquals("type", list3.get(1).get(jsonName));
        Assert.assertEquals("one", 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));
    } catch (FrameworkException fex) {
        fex.printStackTrace();
    }
    // try scripting call
    try {
        final List<GraphObjectMap> list4 = (List) Scripting.evaluate(new ActionContext(securityContext), null, "${type_info('Test', 'public')}", "test");
        Assert.assertEquals("Invalid number of properties in sorted view", 6, list4.size());
        Assert.assertEquals("id", list4.get(0).get(jsonName));
        Assert.assertEquals("type", list4.get(1).get(jsonName));
        Assert.assertEquals("one", 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));
    } catch (FrameworkException fex) {
        fex.printStackTrace();
    }
}
Also used : 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)

Aggregations

TypeInfoFunction (org.structr.core.function.TypeInfoFunction)4 LinkedList (java.util.LinkedList)3 List (java.util.List)3 Test (org.junit.Test)3 FrameworkException (org.structr.common.error.FrameworkException)3 GraphObjectMap (org.structr.core.GraphObjectMap)3 SchemaNode (org.structr.core.entity.SchemaNode)3 SchemaView (org.structr.core.entity.SchemaView)3 NodeInterface (org.structr.core.graph.NodeInterface)3 Tx (org.structr.core.graph.Tx)3 GenericProperty (org.structr.core.property.GenericProperty)3 PropertyKey (org.structr.core.property.PropertyKey)3 ActionContext (org.structr.schema.action.ActionContext)3 FrontendTest (org.structr.web.basic.FrontendTest)3 ResourceAccessTest (org.structr.web.basic.ResourceAccessTest)3 NodeAttribute (org.structr.core.graph.NodeAttribute)2 AbbrFunction (org.structr.core.function.AbbrFunction)1 AddFunction (org.structr.core.function.AddFunction)1 AddToGroupFunction (org.structr.core.function.AddToGroupFunction)1 AncestorTypesFunction (org.structr.core.function.AncestorTypesFunction)1