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