Search in sources :

Example 1 with GeoPoint

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());
    }
}
Also used : GeoPoint(org.activityinfo.model.type.geo.GeoPoint)

Example 2 with GeoPoint

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());
}
Also used : GeoPoint(org.activityinfo.model.type.geo.GeoPoint) GetLocations(org.activityinfo.legacy.shared.command.GetLocations) FormInstance(org.activityinfo.model.form.FormInstance) LocationDTO(org.activityinfo.legacy.shared.model.LocationDTO) LocationResult(org.activityinfo.legacy.shared.command.result.LocationResult) Test(org.junit.Test)

Example 3 with GeoPoint

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);
}
Also used : GeoPoint(org.activityinfo.model.type.geo.GeoPoint) SqlInsert(org.activityinfo.store.mysql.update.SqlInsert) GeoPoint(org.activityinfo.model.type.geo.GeoPoint)

Example 4 with GeoPoint

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);
    }
}
Also used : GeoPoint(org.activityinfo.model.type.geo.GeoPoint) SqlUpdate(org.activityinfo.store.mysql.update.SqlUpdate) GeoPoint(org.activityinfo.model.type.geo.GeoPoint)

Example 5 with GeoPoint

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());
        }
    }));
}
Also used : GeoPoint(org.activityinfo.model.type.geo.GeoPoint) ResultSet(java.sql.ResultSet) FieldValue(org.activityinfo.model.type.FieldValue)

Aggregations

GeoPoint (org.activityinfo.model.type.geo.GeoPoint)10 FormInstance (org.activityinfo.model.form.FormInstance)3 ResourceId (org.activityinfo.model.resource.ResourceId)3 Test (org.junit.Test)3 FormRecord (org.activityinfo.model.form.FormRecord)2 EnumValue (org.activityinfo.model.type.enumerated.EnumValue)2 LocalDate (org.activityinfo.model.type.time.LocalDate)2 ResultSet (java.sql.ResultSet)1 GetLocations (org.activityinfo.legacy.shared.command.GetLocations)1 LocationResult (org.activityinfo.legacy.shared.command.result.LocationResult)1 LocationDTO (org.activityinfo.legacy.shared.model.LocationDTO)1 RecordUpdate (org.activityinfo.model.resource.RecordUpdate)1 FieldValue (org.activityinfo.model.type.FieldValue)1 RecordRef (org.activityinfo.model.type.RecordRef)1 ReferenceValue (org.activityinfo.model.type.ReferenceValue)1 Quantity (org.activityinfo.model.type.number.Quantity)1 SqlInsert (org.activityinfo.store.mysql.update.SqlInsert)1 SqlUpdate (org.activityinfo.store.mysql.update.SqlUpdate)1 Updater (org.activityinfo.store.query.server.Updater)1 FormStorage (org.activityinfo.store.spi.FormStorage)1