use of org.structr.core.property.StringProperty in project structr by structr.
the class SchemaJsonResource method doGet.
@Override
public Result doGet(PropertyKey sortKey, boolean sortDescending, int pageSize, int page) throws FrameworkException {
final GraphObjectMap schema = new GraphObjectMap();
int resultCount = 0;
try {
final JsonSchema jsonSchema = StructrSchema.createFromDatabase(StructrApp.getInstance());
schema.setProperty(new StringProperty("schema"), jsonSchema.toString());
resultCount = 1;
} catch (URISyntaxException ex) {
logger.error("Error while creating JsonSchema: " + ex.getMessage());
}
Result res = new Result(schema, true);
res.setRawResultCount(resultCount);
return res;
}
use of org.structr.core.property.StringProperty in project structr by structr.
the class EnvResource method doGet.
@Override
public Result doGet(PropertyKey sortKey, boolean sortDescending, int pageSize, int page) throws FrameworkException {
final List<GraphObjectMap> resultList = new LinkedList<>();
final GraphObjectMap info = new GraphObjectMap();
info.setProperty(new GenericProperty("modules"), VersionHelper.getModules());
info.setProperty(new GenericProperty("components"), VersionHelper.getComponents());
info.setProperty(new StringProperty("classPath"), VersionHelper.getClassPath());
info.setProperty(new StringProperty("instanceName"), VersionHelper.getInstanceName());
info.setProperty(new StringProperty("instanceStage"), VersionHelper.getInstanceStage());
info.setProperty(new ArrayProperty("mainMenu", String.class), VersionHelper.getMenuEntries());
final LicenseManager licenseManager = Services.getInstance().getLicenseManager();
if (licenseManager != null) {
info.setProperty(new StringProperty("edition"), licenseManager.getEdition());
info.setProperty(new StringProperty("licensee"), licenseManager.getLicensee());
info.setProperty(new StringProperty("hostId"), licenseManager.getHardwareFingerprint());
info.setProperty(new StringProperty("startDate"), licenseManager.getStartDate());
info.setProperty(new StringProperty("endDate"), licenseManager.getEndDate());
} else {
info.setProperty(new StringProperty("edition"), "Community");
info.setProperty(new StringProperty("licensee"), "Unlicensed");
}
resultList.add(info);
return new Result(resultList, resultList.size(), false, false);
}
use of org.structr.core.property.StringProperty in project structr by structr.
the class CypherTest method testCypherResultWrapping.
@Test
public void testCypherResultWrapping() {
try (final Tx tx = app.tx()) {
List<TestOne> testOnes = createTestNodes(TestOne.class, 10);
List<TestSix> testSixs = createTestNodes(TestSix.class, 10);
for (final TestOne testOne : testOnes) {
testOne.setProperty(TestOne.manyToManyTestSixs, testSixs);
}
tx.success();
} catch (FrameworkException ex) {
logger.warn("", ex);
fail("Unexpected exception");
}
try (final Tx tx = app.tx()) {
final List<GraphObject> result = app.command(CypherQueryCommand.class).execute("MATCH (n:TestOne) RETURN DISTINCT n");
assertEquals("Invalid wrapped cypher query result", 10, result.size());
for (final GraphObject obj : result) {
System.out.println(obj);
assertEquals("Invalid wrapped cypher query result", TestOne.class, obj.getClass());
}
tx.success();
} catch (FrameworkException ex) {
logger.error("", ex);
}
try (final Tx tx = app.tx()) {
final List<GraphObject> result = app.command(CypherQueryCommand.class).execute("MATCH (n:TestOne)-[r]-(m:TestSix) RETURN DISTINCT n, r, m ");
final Iterator<GraphObject> it = result.iterator();
assertEquals("Invalid wrapped cypher query result", 300, result.size());
while (it.hasNext()) {
// n
assertEquals("Invalid wrapped cypher query result", TestOne.class, it.next().getClass());
// r
assertEquals("Invalid wrapped cypher query result", SixOneManyToMany.class, it.next().getClass());
// m
assertEquals("Invalid wrapped cypher query result", TestSix.class, it.next().getClass());
}
tx.success();
} catch (FrameworkException ex) {
logger.error("", ex);
}
try (final Tx tx = app.tx()) {
final List<GraphObject> result = app.command(CypherQueryCommand.class).execute("MATCH p = (n:TestOne)-[r]-(m:TestSix) RETURN p ");
assertEquals("Invalid wrapped cypher query result", 100, result.size());
for (final GraphObject obj : result) {
assertEquals("Invalid wrapped cypher query result", GraphObjectMap.class, obj.getClass());
}
tx.success();
} catch (FrameworkException ex) {
logger.error("", ex);
}
try (final Tx tx = app.tx()) {
final List<GraphObject> result = app.command(CypherQueryCommand.class).execute("MATCH p = (n:TestOne)-[r]-(m:TestSix) RETURN { nodes: nodes(p), rels: relationships(p) } ");
assertEquals("Invalid wrapped cypher query result", 100, result.size());
for (final GraphObject obj : result) {
assertEquals("Invalid wrapped cypher query result", GraphObjectMap.class, obj.getClass());
final Object nodes = obj.getProperty(new StringProperty("nodes"));
final Object rels = obj.getProperty(new StringProperty("rels"));
assertTrue("Invalid wrapped cypher query result", nodes instanceof Collection);
assertTrue("Invalid wrapped cypher query result", rels instanceof Collection);
final Iterator it = ((Collection) nodes).iterator();
while (it.hasNext()) {
assertEquals("Invalid wrapped cypher query result", TestOne.class, it.next().getClass());
assertEquals("Invalid wrapped cypher query result", TestSix.class, it.next().getClass());
}
for (final Object node : ((Collection) rels)) {
assertEquals("Invalid wrapped cypher query result", SixOneManyToMany.class, node.getClass());
}
}
tx.success();
} catch (FrameworkException ex) {
logger.error("", ex);
}
try (final Tx tx = app.tx()) {
final List<GraphObject> result = app.command(CypherQueryCommand.class).execute("MATCH p = (n:TestOne)-[r]-(m:TestSix) RETURN DISTINCT { path: p, value: 12 } ");
assertEquals("Invalid wrapped cypher query result", 100, result.size());
final Iterator it = result.iterator();
while (it.hasNext()) {
final Object path = it.next();
final Object value = it.next();
assertEquals("Invalid wrapped cypher query result", GraphObjectMap.class, path.getClass());
assertEquals("Invalid wrapped cypher query result", GraphObjectMap.class, value.getClass());
assertEquals("Invalid wrapped cypher query result", 12L, ((GraphObjectMap) value).getProperty(new StringProperty("value")));
}
tx.success();
} catch (FrameworkException ex) {
logger.error("", ex);
}
try (final Tx tx = app.tx()) {
final List<GraphObject> result = app.command(CypherQueryCommand.class).execute("MATCH p = (n:TestOne)-[r]-(m:TestSix) RETURN { nodes: { x : { y : { z : nodes(p) } } } } ");
assertEquals("Invalid wrapped cypher query result", 100, result.size());
for (final GraphObject obj : result) {
assertEquals("Invalid wrapped cypher query result", GraphObjectMap.class, obj.getClass());
final Object nodes = obj.getProperty(new StringProperty("nodes"));
assertTrue("Invalid wrapped cypher query result", nodes instanceof GraphObjectMap);
final Object x = ((GraphObjectMap) nodes).getProperty(new StringProperty("x"));
assertTrue("Invalid wrapped cypher query result", x instanceof GraphObjectMap);
final Object y = ((GraphObjectMap) x).getProperty(new StringProperty("y"));
assertTrue("Invalid wrapped cypher query result", y instanceof GraphObjectMap);
final Object z = ((GraphObjectMap) y).getProperty(new StringProperty("z"));
assertTrue("Invalid wrapped cypher query result", z instanceof Collection);
}
tx.success();
} catch (FrameworkException ex) {
logger.error("", ex);
}
/*
try (final Tx tx = app.tx()) {
final List<GraphObject> result = app.command(CypherQueryCommand.class).execute("MATCH p = (n:TestOne)-[r]-(m:TestSix) RETURN p");
assertEquals("Invalid wrapped cypher query result", 100, result.size());
for (final GraphObject obj : result) {
assertEquals("Invalid wrapped cypher query result", GraphObjectMap.class, obj.getClass());
final Object paths = obj.getProperty(new StringProperty("p"));
assertTrue("Invalid wrapped cypher query result", paths instanceof Iterable);
final Iterator it = ((Iterable)paths).iterator();
while (it.hasNext()) {
assertEquals("Invalid wrapped cypher query result", TestOne.class, it.next().getClass()); // n
assertEquals("Invalid wrapped cypher query result", SixOneManyToMany.class, it.next().getClass()); // r
assertEquals("Invalid wrapped cypher query result", TestSix.class, it.next().getClass()); // m
}
}
tx.success();
} catch (FrameworkException ex) {
logger.error("", ex);
}
*/
}
use of org.structr.core.property.StringProperty in project structr by structr.
the class SearchAndSortingTest method test03SearchRelationship.
@Test
public void test03SearchRelationship() {
try {
final NodeHasLocation rel = createTestRelationships(NodeHasLocation.class, 1).get(0);
final PropertyKey key1 = new StringProperty("jghsdkhgshdhgsdjkfgh").indexed();
final Class type = NodeHasLocation.class;
final String val1 = "54354354546806849870";
final Result<RelationshipInterface> result;
try (final Tx tx = app.tx()) {
rel.setProperty(key1, val1);
tx.success();
}
try (final Tx tx = app.tx()) {
assertTrue(rel.getProperty(key1).equals(val1));
result = app.relationshipQuery(type).and(key1, val1).getResult();
assertTrue(result.size() == 1);
assertTrue(result.get(0).equals(rel));
}
final String val2 = "ölllldjöoa8w4rasf";
try (final Tx tx = app.tx()) {
rel.setProperty(key1, val2);
tx.success();
}
assertTrue(result.size() == 1);
assertTrue(result.get(0).equals(rel));
} catch (FrameworkException ex) {
logger.warn("", ex);
logger.error(ex.toString());
fail("Unexpected exception");
}
}
use of org.structr.core.property.StringProperty in project structr by structr.
the class ValidationTest method createTypeWithProperty.
private Class createTypeWithProperty(final String typeName, final String keyName, final String keyType) {
try (final Tx tx = app.tx()) {
app.create(SchemaNode.class, new NodeAttribute<>(AbstractNode.name, typeName), new NodeAttribute<>(new StringProperty("_" + keyName), keyType));
tx.success();
} catch (FrameworkException fex) {
logger.warn("", fex);
fail("Unexpected exception.");
}
return StructrApp.getConfiguration().getNodeEntityClass(typeName);
}
Aggregations