use of org.activityinfo.legacy.shared.command.GetLocations in project activityinfo by bedatadriven.
the class LocationFilterPanel method applyInternalValue.
private Promise<LocationResult> applyInternalValue() {
Promise<LocationResult> promise = new Promise<>();
promise.then(new Function<LocationResult, Object>() {
@Override
public Object apply(LocationResult input) {
filterToolBar.setApplyFilterEnabled(false);
filterToolBar.setRemoveFilterEnabled(value.isRestricted(DimensionType.Location));
store.removeAll();
store.add(input.getData());
return null;
}
});
dispatcher.execute(new GetLocations(new ArrayList<>(value.getRestrictions(DimensionType.Location))), promise);
return promise;
}
use of org.activityinfo.legacy.shared.command.GetLocations 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.legacy.shared.command.GetLocations in project activityinfo by bedatadriven.
the class LocationsResource method query.
@GET
@Timed(name = "api.rest.locations.get")
@Produces(MediaType.APPLICATION_JSON)
public Response query(@QueryParam("type") int typeId) throws IOException {
GetLocations query = new GetLocations();
query.setLocationTypeId(typeId);
LocationResult result = dispatcher.execute(query);
StringWriter writer = new StringWriter();
JsonGenerator json = Jackson.createJsonFactory(writer);
json.writeStartArray();
for (LocationDTO location : result.getData()) {
json.writeStartObject();
json.writeNumberField("id", location.getId());
json.writeStringField("name", location.getName());
if (location.hasAxe()) {
json.writeStringField("code", location.getAxe());
}
if (location.hasCoordinates()) {
json.writeNumberField("latitude", location.getLatitude());
json.writeNumberField("longitude", location.getLongitude());
}
if (!location.getAdminEntities().isEmpty()) {
json.writeObjectFieldStart("adminEntities");
for (AdminEntityDTO entity : location.getAdminEntities()) {
json.writeFieldName(Integer.toString(entity.getLevelId()));
json.writeStartObject();
json.writeNumberField("id", entity.getId());
json.writeStringField("name", entity.getName());
json.writeEndObject();
}
json.writeEndObject();
}
json.writeEndObject();
}
json.writeEndArray();
json.close();
return Response.ok(writer.toString()).type(MediaType.APPLICATION_JSON_TYPE).build();
}
use of org.activityinfo.legacy.shared.command.GetLocations in project activityinfo by bedatadriven.
the class GetLocationsTest method testGetLocation.
@Test
public void testGetLocation() {
setUser(1);
LocationDTO location = execute(new GetLocations(1)).getData().get(0);
assertThat(location, notNullValue());
assertThat(location.getName(), equalTo("Penekusu Kivu"));
assertThat(location.getAxe(), nullValue());
assertThat(location.getAdminEntity(1).getName(), equalTo("Sud Kivu"));
assertThat(location.getAdminEntity(2).getName(), equalTo("Shabunda"));
}
use of org.activityinfo.legacy.shared.command.GetLocations in project activityinfo by bedatadriven.
the class ResourceLocatorAdaptorTest method updateLocation.
@Test
public void updateLocation() {
// <location locationId="1" name="Penekusu Kivu" locationTypeId="1"
// X="1.532" Y="27.323" timeEdited="1"/>
// <locationAdminLink locationId="1" adminEntityId="2"/>
// <locationAdminLink locationId="1" adminEntityId="12"/>
FormInstance instance = assertResolves(locator.getFormInstance(HEALTH_CENTER_CLASS, locationInstanceId(1)));
instance.set(field(HEALTH_CENTER_CLASS, NAME_FIELD), "New Penekusu");
assertResolves(locator.persist(instance));
GetLocations query = new GetLocations(1);
LocationResult result = execute(query);
LocationDTO location = result.getData().get(0);
assertThat(location.getName(), equalTo("New Penekusu"));
assertThat(location.getLocationTypeId(), equalTo(1));
assertThat(location.getLatitude(), equalTo(27.323));
assertThat(location.getLongitude(), equalTo(1.532));
// 12 admin level is not returned because we eliminate redundant information org.activityinfo.store.mysql.side.AdminColumnBuilder.emit(int[])
assertThat(location.getAdminEntity(1).getId(), equalTo(2));
}
Aggregations