Search in sources :

Example 1 with GetLocations

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;
}
Also used : Promise(org.activityinfo.promise.Promise) GetLocations(org.activityinfo.legacy.shared.command.GetLocations) ArrayList(java.util.ArrayList) LocationResult(org.activityinfo.legacy.shared.command.result.LocationResult)

Example 2 with GetLocations

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());
}
Also used : GeoPoint(org.activityinfo.model.type.geo.GeoPoint) 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 3 with GetLocations

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();
}
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 4 with GetLocations

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

Example 5 with GetLocations

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

Aggregations

GetLocations (org.activityinfo.legacy.shared.command.GetLocations)5 LocationResult (org.activityinfo.legacy.shared.command.result.LocationResult)4 LocationDTO (org.activityinfo.legacy.shared.model.LocationDTO)4 Test (org.junit.Test)3 FormInstance (org.activityinfo.model.form.FormInstance)2 StringWriter (java.io.StringWriter)1 ArrayList (java.util.ArrayList)1 AdminEntityDTO (org.activityinfo.legacy.shared.model.AdminEntityDTO)1 GeoPoint (org.activityinfo.model.type.geo.GeoPoint)1 Promise (org.activityinfo.promise.Promise)1 Timed (org.activityinfo.server.util.monitoring.Timed)1 JsonGenerator (org.codehaus.jackson.JsonGenerator)1