Search in sources :

Example 6 with LocationResult

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

Example 7 with LocationResult

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();
}
Also used : StringWriter(java.io.StringWriter) GetLocations(org.activityinfo.legacy.shared.command.GetLocations) AdminEntityDTO(org.activityinfo.legacy.shared.model.AdminEntityDTO) JsonGenerator(org.codehaus.jackson.JsonGenerator) LocationDTO(org.activityinfo.legacy.shared.model.LocationDTO) LocationResult(org.activityinfo.legacy.shared.command.result.LocationResult) Timed(org.activityinfo.server.util.monitoring.Timed)

Example 8 with LocationResult

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));
}
Also used : 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 9 with LocationResult

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);
}
Also used : LocationResult(org.activityinfo.legacy.shared.command.result.LocationResult) Test(org.junit.Test)

Aggregations

LocationResult (org.activityinfo.legacy.shared.command.result.LocationResult)9 LocationDTO (org.activityinfo.legacy.shared.model.LocationDTO)6 GetLocations (org.activityinfo.legacy.shared.command.GetLocations)4 Test (org.junit.Test)4 SqlResultCallback (com.bedatadriven.rebar.sql.client.SqlResultCallback)2 SqlResultSet (com.bedatadriven.rebar.sql.client.SqlResultSet)2 SqlResultSetRow (com.bedatadriven.rebar.sql.client.SqlResultSetRow)2 SqlTransaction (com.bedatadriven.rebar.sql.client.SqlTransaction)2 SqlQuery (com.bedatadriven.rebar.sql.client.query.SqlQuery)2 ArrayList (java.util.ArrayList)2 AdminEntityDTO (org.activityinfo.legacy.shared.model.AdminEntityDTO)2 FormInstance (org.activityinfo.model.form.FormInstance)2 StringWriter (java.io.StringWriter)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Nullable (javax.annotation.Nullable)1 Filter (org.activityinfo.legacy.shared.command.Filter)1 GeoPoint (org.activityinfo.model.type.geo.GeoPoint)1 Promise (org.activityinfo.promise.Promise)1