Search in sources :

Example 1 with Location

use of org.structr.core.entity.Location in project structr by structr.

the class GeoHelper method createLocation.

/**
 * Creates a Location entity for the given geocoding result and returns it.
 *
 * @param coords
 * @return a Location entity for the given geocoding result
 *
 * @throws FrameworkException
 */
public static Location createLocation(final GeoCodingResult coords) throws FrameworkException {
    final PropertyMap props = new PropertyMap();
    double latitude = coords.getLatitude();
    double longitude = coords.getLongitude();
    String type = Location.class.getSimpleName();
    props.put(AbstractNode.type, type);
    props.put(StructrApp.key(Location.class, "latitude"), latitude);
    props.put(StructrApp.key(Location.class, "longitude"), longitude);
    return StructrApp.getInstance().create(Location.class, props);
}
Also used : PropertyMap(org.structr.core.property.PropertyMap) Location(org.structr.core.entity.Location)

Example 2 with Location

use of org.structr.core.entity.Location in project structr by structr.

the class BasicTest method test04CheckNodeEntities.

/**
 * Create a node for each configured entity class and check the type
 */
@Test
public void test04CheckNodeEntities() {
    AccessControlTest.clearResourceAccess();
    final PropertyMap props = new PropertyMap();
    try (final Tx tx = app.tx()) {
        List<Class> entityList = Collections.EMPTY_LIST;
        try {
            entityList = getClasses("org.structr.core.entity");
        } catch (IOException | ClassNotFoundException ex) {
            logger.error("", ex);
        }
        assertTrue(entityList.contains(AbstractNode.class));
        assertTrue(entityList.contains(GenericNode.class));
        assertTrue(entityList.contains(Location.class));
        assertTrue(entityList.contains(ResourceAccess.class));
        // Don't test these, it would fail due to violated constraints
        entityList.remove(TestTwo.class);
        entityList.remove(TestNine.class);
        entityList.remove(SchemaNode.class);
        entityList.remove(SchemaRelationshipNode.class);
        for (Class type : entityList) {
            // Class entityClass = entity.getValue();
            if (AbstractNode.class.isAssignableFrom(type)) {
                props.clear();
                // For Group, fill mandatory fields
                if (type.equals(Group.class)) {
                    props.put(Group.name, "Group-0");
                }
                // For TestSeven, fill mandatory fields
                if (type.equals(TestSeven.class)) {
                    props.put(TestSeven.name, "TestSeven-0");
                }
                // For ResourceAccess, fill mandatory fields
                if (type.equals(ResourceAccess.class)) {
                    props.put(ResourceAccess.signature, "/X");
                    props.put(ResourceAccess.flags, 6L);
                }
                // For DynamicResourceAccess, fill mandatory fields
                if (type.equals(DynamicResourceAccess.class)) {
                    props.put(DynamicResourceAccess.signature, "/Y");
                    props.put(DynamicResourceAccess.flags, 6L);
                }
                // For Localization, fill mandatory fields
                if (type.equals(Localization.class)) {
                /*
						props.put(Localization.name, "localizationKey");
						props.put(Localization.locale, "de_DE");
						*/
                }
                // For Location, set coordinates
                if (type.equals(Location.class)) {
                    props.put(StructrApp.key(Location.class, "latitude"), 12.34);
                    props.put(StructrApp.key(Location.class, "longitude"), 56.78);
                }
                logger.info("Creating node of type {}", type);
                NodeInterface node = app.create(type, props);
                assertTrue(type.getSimpleName().equals(node.getProperty(AbstractNode.type)));
                // Remove mandatory fields for ResourceAccess from props map
                if (type.equals(ResourceAccess.class)) {
                    props.remove(ResourceAccess.signature);
                    props.remove(ResourceAccess.flags);
                }
            }
        }
        tx.success();
    } catch (FrameworkException ex) {
        logger.error(ex.toString());
        logger.warn("", ex);
        fail("Unexpected exception");
    }
}
Also used : ResourceAccess(org.structr.core.entity.ResourceAccess) DynamicResourceAccess(org.structr.core.entity.DynamicResourceAccess) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) AbstractNode(org.structr.core.entity.AbstractNode) GenericNode(org.structr.core.entity.GenericNode) IOException(java.io.IOException) PropertyMap(org.structr.core.property.PropertyMap) NodeInterface(org.structr.core.graph.NodeInterface) Location(org.structr.core.entity.Location) NodeHasLocation(org.structr.core.entity.relationship.NodeHasLocation) Test(org.junit.Test)

Aggregations

Location (org.structr.core.entity.Location)2 PropertyMap (org.structr.core.property.PropertyMap)2 IOException (java.io.IOException)1 Test (org.junit.Test)1 FrameworkException (org.structr.common.error.FrameworkException)1 AbstractNode (org.structr.core.entity.AbstractNode)1 DynamicResourceAccess (org.structr.core.entity.DynamicResourceAccess)1 GenericNode (org.structr.core.entity.GenericNode)1 ResourceAccess (org.structr.core.entity.ResourceAccess)1 NodeHasLocation (org.structr.core.entity.relationship.NodeHasLocation)1 NodeInterface (org.structr.core.graph.NodeInterface)1 Tx (org.structr.core.graph.Tx)1