Search in sources :

Example 16 with StringProperty

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;
}
Also used : GraphObjectMap(org.structr.core.GraphObjectMap) JsonSchema(org.structr.schema.json.JsonSchema) StringProperty(org.structr.core.property.StringProperty) URISyntaxException(java.net.URISyntaxException) RestMethodResult(org.structr.rest.RestMethodResult) Result(org.structr.core.Result)

Example 17 with StringProperty

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);
}
Also used : ArrayProperty(org.structr.core.property.ArrayProperty) GraphObjectMap(org.structr.core.GraphObjectMap) GenericProperty(org.structr.core.property.GenericProperty) StringProperty(org.structr.core.property.StringProperty) LicenseManager(org.structr.api.service.LicenseManager) LinkedList(java.util.LinkedList) RestMethodResult(org.structr.rest.RestMethodResult) Result(org.structr.core.Result)

Example 18 with StringProperty

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);
		}
		*/
}
Also used : Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) StringProperty(org.structr.core.property.StringProperty) GraphObject(org.structr.core.GraphObject) GraphObjectMap(org.structr.core.GraphObjectMap) Iterator(java.util.Iterator) Collection(java.util.Collection) GraphObject(org.structr.core.GraphObject) TestOne(org.structr.core.entity.TestOne) CypherQueryCommand(org.structr.core.graph.CypherQueryCommand) TestSix(org.structr.core.entity.TestSix) Test(org.junit.Test)

Example 19 with StringProperty

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

Example 20 with StringProperty

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);
}
Also used : Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) StringProperty(org.structr.core.property.StringProperty)

Aggregations

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