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();
}
}
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();
}
}
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());
}
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();
}
}
Aggregations