use of org.activityinfo.model.type.geo.GeoPoint in project activityinfo by bedatadriven.
the class GeoPointWidget method init.
@Override
public void init(FieldValue value) {
if (value instanceof GeoPoint) {
GeoPoint pointValue = (GeoPoint) value;
latitude.init(pointValue.getLatitude());
longitude.init(pointValue.getLongitude());
}
}
use of org.activityinfo.model.type.geo.GeoPoint in project activityinfo by bedatadriven.
the class ResourceLocatorAdaptorTest method persistLocation.
@Test
public void persistLocation() {
FormInstance instance = new FormInstance(newLegacyFormInstanceId(HEALTH_CENTER_CLASS), HEALTH_CENTER_CLASS);
instance.set(field(HEALTH_CENTER_CLASS, NAME_FIELD), "CS Ubuntu");
instance.set(field(HEALTH_CENTER_CLASS, GEOMETRY_FIELD), new GeoPoint(-1, 13));
instance.set(field(HEALTH_CENTER_CLASS, ADMIN_FIELD), entityRef(TERRITOIRE, IRUMU));
assertResolves(locator.persist(instance));
// ensure that everything worked out
GetLocations query = new GetLocations(getLegacyIdFromCuid(instance.getId()));
LocationResult result = execute(query);
LocationDTO location = result.getData().get(0);
assertThat(location.getName(), equalTo("CS Ubuntu"));
assertThat(location.getAdminEntity(1).getName(), equalTo("Ituri"));
assertThat(location.getAdminEntity(2).getName(), equalTo("Irumu"));
assertThat(location.getLatitude(), equalTo(-1d));
assertThat(location.getLongitude(), equalTo(13d));
// remove location
assertResolves(locator.remove(HEALTH_CENTER_CLASS, instance.getId()));
// check whether location is removed
result = execute(query);
assertThat(result.getData(), IsEmptyCollection.empty());
}
use of org.activityinfo.model.type.geo.GeoPoint in project activityinfo by bedatadriven.
the class LocationFormStorage method add.
@Override
public void add(TypedRecordUpdate update) {
long newVersion = incrementVersion();
int locationId = CuidAdapter.getLegacyIdFromCuid(update.getRecordId());
SqlInsert insert = SqlInsert.insertInto("location");
insert.value("locationTypeId", locationTypeId);
insert.value("locationId", locationId);
insert.value("timeEdited", System.currentTimeMillis());
insert.value("version", newVersion);
insert.value("name", getName(update), 50);
insert.value("axe", getAxe(update), 50);
GeoPoint point = (GeoPoint) update.getChangedFieldValues().get(pointFieldId);
if (point != null) {
insert.value("x", point.getLongitude());
insert.value("y", point.getLatitude());
}
insert.execute(executor);
Set<Integer> adminEntities = fetchParents(getAdminEntities(update));
insertAdminLinks(locationId, adminEntities);
}
use of org.activityinfo.model.type.geo.GeoPoint in project activityinfo by bedatadriven.
the class LocationFormStorage method update.
@Override
public void update(TypedRecordUpdate update) {
long newVersion = incrementVersion();
int locationId = CuidAdapter.getLegacyIdFromCuid(update.getRecordId());
SqlUpdate sql = SqlUpdate.update("location");
sql.where("locationId", locationId);
sql.set("timeEdited", System.currentTimeMillis());
sql.set("version", newVersion);
if (update.isDeleted()) {
sql.set("workflowStatusId", "rejected");
} else {
sql.set("name", getName(update), 50);
sql.set("axe", getAxe(update), 50);
if (update.getChangedFieldValues().containsKey(pointFieldId)) {
GeoPoint point = (GeoPoint) update.getChangedFieldValues().get(pointFieldId);
if (point == null) {
sql.set("x", null);
sql.set("y", null);
} else {
sql.set("x", point.getLongitude());
sql.set("y", point.getLatitude());
}
}
}
sql.execute(executor);
if (!update.isDeleted()) {
Set<Integer> adminEntities = fetchParents(getAdminEntities(update));
updateAdminLinks(locationId, adminEntities);
}
}
use of org.activityinfo.model.type.geo.GeoPoint in project activityinfo by bedatadriven.
the class TableMappingBuilder method addGeoPoint.
public void addGeoPoint(FormField field) {
add(new FieldMapping(field, Arrays.asList("x", "y"), new FieldValueConverter() {
@Override
public FieldValue toFieldValue(ResultSet rs, int index) throws SQLException {
double lat = rs.getDouble(index + 1);
if (rs.wasNull()) {
return null;
}
double lon = rs.getDouble(index);
if (rs.wasNull()) {
return null;
}
return new GeoPoint(lat, lon);
}
@Override
public Collection<Double> toParameters(FieldValue value) {
GeoPoint pointValue = (GeoPoint) value;
return Arrays.asList(pointValue.getLongitude(), pointValue.getLatitude());
}
}));
}
Aggregations