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