use of org.activityinfo.legacy.shared.command.result.LocationResult in project activityinfo by bedatadriven.
the class CreateLocationHandlerTest method test.
@Test
public void test() throws CommandException {
LocationDTO location = LocationDTOs.newLocation();
execute(new CreateLocation(location));
SearchLocations getLocations = new SearchLocations().setName(location.getName());
LocationResult locations = execute(getLocations);
LocationDTO newLocation = locations.getData().get(0);
assertEquals(location.getName(), newLocation.getName());
assertEquals(location.getAxe(), newLocation.getAxe());
assertEquals(location.getLongitude(), newLocation.getLongitude());
assertEquals(location.getLatitude(), newLocation.getLatitude());
}
use of org.activityinfo.legacy.shared.command.result.LocationResult 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.result.LocationResult 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));
}
use of org.activityinfo.legacy.shared.command.result.LocationResult in project activityinfo by bedatadriven.
the class SearchLocationsHandlerTest method test.
@Test
public void test() throws CommandException {
SearchLocations getLocations = new SearchLocations().setAdminEntityIds(Arrays.asList(3, 12)).setName("Sh");
LocationResult result = execute(getLocations);
assertTrue(result.getData().size() == 1);
}
Aggregations