Search in sources :

Example 6 with GeoPoint

use of org.activityinfo.model.type.geo.GeoPoint in project activityinfo by bedatadriven.

the class CurlExamplesGenerator method getRecord.

public static Example getRecord() {
    ResourceId formId = ResourceId.generateId();
    ResourceId recordId = ResourceId.generateId();
    FormRecord.Builder record = new FormRecord.Builder();
    record.setFormId(formId);
    record.setRecordId(recordId);
    record.setFieldValue(ResourceId.generateId(), TextValue.valueOf("Text Value"));
    record.setFieldValue(ResourceId.generateId(), new Quantity(1500));
    record.setFieldValue(ResourceId.generateId(), new LocalDate(2016, 10, 5));
    record.setFieldValue(ResourceId.generateId(), new GeoPoint(52.078663, 4.288788));
    record.setFieldValue(ResourceId.generateId(), new EnumValue(ResourceId.generateId()));
    return new Example(String.format("curl https://www.activityinfo.org/resources/form/%s/record/%s", formId, recordId), record.build().toJson());
}
Also used : GeoPoint(org.activityinfo.model.type.geo.GeoPoint) ResourceId(org.activityinfo.model.resource.ResourceId) EnumValue(org.activityinfo.model.type.enumerated.EnumValue) Quantity(org.activityinfo.model.type.number.Quantity) FormRecord(org.activityinfo.model.form.FormRecord) LocalDate(org.activityinfo.model.type.time.LocalDate)

Example 7 with GeoPoint

use of org.activityinfo.model.type.geo.GeoPoint in project activityinfo by bedatadriven.

the class CreateSiteTest method persistSite.

@Test
public void persistSite() {
    ResourceId locationClassId = CuidAdapter.locationFormClass(1);
    FormInstance location = new FormInstance(CuidAdapter.generateLocationCuid(), locationClassId);
    location.set(field(locationClassId, CuidAdapter.NAME_FIELD), "Virunga");
    location.set(field(locationClassId, CuidAdapter.AXE_FIELD), "Goma - Rutshuru");
    location.set(field(locationClassId, CuidAdapter.GEOMETRY_FIELD), new GeoPoint(27.432, 1.23));
    assertResolves(locator.persist(location));
    int databaseId = 1;
    ResourceId formClassId = CuidAdapter.activityFormClass(1);
    FormInstance instance = new FormInstance(CuidAdapter.generateSiteCuid(), formClassId);
    instance.set(field(formClassId, LOCATION_FIELD), new ReferenceValue(new RecordRef(locationClassId, location.getId())));
    instance.set(field(formClassId, PARTNER_FIELD), CuidAdapter.partnerRef(databaseId, 1));
    instance.set(field(formClassId, START_DATE_FIELD), new LocalDate(2008, 12, 1));
    instance.set(field(formClassId, END_DATE_FIELD), new LocalDate(2009, 1, 3));
    instance.set(indicatorField(1), 996.0);
    instance.set(attributeField(1), new EnumValue(CuidAdapter.attributeId(1), CuidAdapter.attributeField(2)));
    instance.set(commentsField(1), "objection!");
    instance.set(field(formClassId, PROJECT_FIELD), CuidAdapter.projectRef(PROJECT_DOMAIN, 1));
    assertResolves(locator.persist(instance));
}
Also used : GeoPoint(org.activityinfo.model.type.geo.GeoPoint) ResourceId(org.activityinfo.model.resource.ResourceId) ReferenceValue(org.activityinfo.model.type.ReferenceValue) EnumValue(org.activityinfo.model.type.enumerated.EnumValue) RecordRef(org.activityinfo.model.type.RecordRef) FormInstance(org.activityinfo.model.form.FormInstance) LocalDate(org.activityinfo.model.type.time.LocalDate) GeoPoint(org.activityinfo.model.type.geo.GeoPoint) Test(org.junit.Test)

Example 8 with GeoPoint

use of org.activityinfo.model.type.geo.GeoPoint in project activityinfo by bedatadriven.

the class MySqlUpdateTest method updateLocation.

@Test
public void updateLocation() throws SQLException {
    ResourceId recordId = CuidAdapter.cuid(LOCATION_DOMAIN, 1);
    ResourceId formId = CuidAdapter.locationFormClass(1);
    RecordUpdate update = new RecordUpdate();
    update.setFormId(formId);
    update.setRecordId(recordId);
    update.setFieldValue(CuidAdapter.field(formId, CuidAdapter.NAME_FIELD), TextValue.valueOf("New Name"));
    Updater updater = updater();
    updater.executeChange(update);
    newRequest();
    FormStorage formStorage = catalog.getForm(formId).get();
    FormRecord record = formStorage.get(recordId).get();
    FormInstance typedRecord = FormInstance.toFormInstance(formStorage.getFormClass(), record);
    GeoPoint point = (GeoPoint) typedRecord.get(CuidAdapter.field(formId, CuidAdapter.GEOMETRY_FIELD));
    assertThat(point, not(nullValue()));
}
Also used : GeoPoint(org.activityinfo.model.type.geo.GeoPoint) RecordUpdate(org.activityinfo.model.resource.RecordUpdate) TypedRecordUpdate(org.activityinfo.store.spi.TypedRecordUpdate) FormStorage(org.activityinfo.store.spi.FormStorage) ResourceId(org.activityinfo.model.resource.ResourceId) Updater(org.activityinfo.store.query.server.Updater) FormRecord(org.activityinfo.model.form.FormRecord) FormInstance(org.activityinfo.model.form.FormInstance) Test(org.junit.Test)

Example 9 with GeoPoint

use of org.activityinfo.model.type.geo.GeoPoint in project activityinfo by bedatadriven.

the class GeoPointWidget method updateModel.

private void updateModel() {
    latitude.parseAndValidate();
    longitude.parseAndValidate();
    if (latitude.empty && longitude.empty) {
        // If both coordinates are empty, consider this to
        // be an empty field and clear the field validation messages
        // (the form may still mark this field as a whole if the field is
        // required, but we don't have to deal with that here)
        latitude.field.clearInvalid();
        longitude.field.clearInvalid();
        updater.update(FieldInput.EMPTY);
    } else {
        if (latitude.valid && longitude.valid) {
            updater.update(new FieldInput(new GeoPoint(latitude.value, longitude.value)));
        } else {
            latitude.markInvalidIfEmpty();
            longitude.markInvalidIfEmpty();
            updater.update(FieldInput.INVALID_INPUT);
        }
    }
}
Also used : GeoPoint(org.activityinfo.model.type.geo.GeoPoint) FieldInput(org.activityinfo.ui.client.input.model.FieldInput)

Example 10 with GeoPoint

use of org.activityinfo.model.type.geo.GeoPoint in project activityinfo by bedatadriven.

the class GeographicPointImporter method updateInstance.

@Override
public boolean updateInstance(SourceRow row, FormInstance instance) {
    final boolean isLatOk = validateCoordinate(row, 0).isPersistable();
    final boolean isLonOk = validateCoordinate(row, 1).isPersistable();
    if (isLatOk && isLonOk) {
        double latitude = parseCoordinate(row, 0);
        double longitude = parseCoordinate(row, 1);
        instance.set(fieldId, new GeoPoint(latitude, longitude));
        return true;
    }
    return false;
}
Also used : GeoPoint(org.activityinfo.model.type.geo.GeoPoint)

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