Search in sources :

Example 6 with AdminEntityDTO

use of org.activityinfo.legacy.shared.model.AdminEntityDTO in project activityinfo by bedatadriven.

the class GetAdminEntitiesHandler method toEntity.

public static AdminEntityDTO toEntity(SqlResultSetRow row) {
    AdminEntityDTO entity = new AdminEntityDTO();
    entity.setId(row.getInt("adminEntityId"));
    entity.setName(row.getString("name"));
    entity.setLevelId(row.getInt("adminLevelId"));
    entity.setLevelName(row.getString("levelName"));
    if (!row.isNull("adminEntityParentId")) {
        entity.setParentId(row.getInt("adminEntityParentId"));
    }
    Extents bounds = Extents.empty();
    if (!row.isNull("x1")) {
        bounds.setMinLon(row.getDouble("x1"));
        bounds.setMinLat(row.getDouble("y1"));
        bounds.setMaxLon(row.getDouble("x2"));
        bounds.setMaxLat(row.getDouble("y2"));
        entity.setBounds(bounds);
    }
    return entity;
}
Also used : AdminEntityDTO(org.activityinfo.legacy.shared.model.AdminEntityDTO) Extents(org.activityinfo.model.type.geo.Extents)

Example 7 with AdminEntityDTO

use of org.activityinfo.legacy.shared.model.AdminEntityDTO in project activityinfo by bedatadriven.

the class GetAdminEntitiesHandler method execute.

@Override
public void execute(GetAdminEntities cmd, ExecutionContext context, final AsyncCallback<AdminEntityResult> callback) {
    SqlQuery query = SqlQuery.select("AdminEntity.adminEntityId", "AdminEntity.name", "AdminEntity.adminLevelId", "AdminEntity.adminEntityParentId", "x1", "y1", "x2", "y2").from(Tables.ADMIN_ENTITY, "AdminEntity").whereTrue("not AdminEntity.deleted");
    query.orderBy("AdminEntity.name");
    if (cmd.getLevelId() != null) {
        query.where("AdminEntity.AdminLevelId").equalTo(cmd.getLevelId());
    } else {
        query.leftJoin(Tables.ADMIN_LEVEL, "level").on("AdminEntity.AdminLevelID=level.AdminLevelId");
        query.appendColumn("level.name", "levelName");
    }
    if (cmd.getEntityIds() != null && !cmd.getEntityIds().isEmpty()) {
        query.where("AdminEntity.AdminEntityId").in(cmd.getEntityIds());
    }
    if (cmd.getParentId() != null) {
        if (cmd.getParentId() == GetAdminEntities.ROOT) {
            query.where("AdminEntity.AdminEntityParentId IS NULL");
        } else {
            query.where("AdminEntity.AdminEntityParentId").equalTo(cmd.getParentId());
        }
    }
    if (cmd.getFilter() != null) {
        Filter filter = cmd.getFilter();
        if (filter.isRestricted(DimensionType.Activity) || filter.isRestricted(DimensionType.Database) || filter.isRestricted(DimensionType.Indicator)) {
            SqlQuery subQuery = SqlQuery.select("link.AdminEntityId").from(Tables.SITE, "site").leftJoin(Tables.LOCATION, "Location").on("Location.LocationId = site.LocationId").leftJoin(Tables.LOCATION_ADMIN_LINK, "link").on("link.LocationId = Location.LocationId");
            if (filter.isRestricted(DimensionType.Activity)) {
                subQuery.where("site.ActivityId").in(filter.getRestrictions(DimensionType.Activity));
            }
            if (filter.isRestricted(DimensionType.Database)) {
                subQuery.leftJoin(Tables.ACTIVITY, "activity").on("site.ActivityId=activity.ActivityId").where("activity.DatabaseId").in(filter.getRestrictions(DimensionType.Database));
            }
            if (filter.isRestricted(DimensionType.Indicator)) {
                subQuery.leftJoin(Tables.REPORTING_PERIOD, "rp").on("site.siteId=rp.SiteId").leftJoin(Tables.INDICATOR_VALUE, "iv").on("iv.reportingPeriodId=rp.reportingPeriodId").where("iv.indicatorId").in(filter.getRestrictions(DimensionType.Indicator));
            }
            query.where("AdminEntity.AdminEntityId").in(subQuery);
        }
    }
    if (cmd.getFilter() != null && cmd.getFilter().isRestricted(DimensionType.AdminLevel)) {
        if (cmd.getLevelId() == null) {
            query.where("AdminEntityId").in(cmd.getFilter().getRestrictions(DimensionType.AdminLevel));
        } else {
            SqlQuery subQuery = SqlQuery.select("adminEntityId").from(Tables.ADMIN_ENTITY, "AdminEntity").where("AdminLevelId").equalTo(cmd.getLevelId()).where("AdminEntityId").in(cmd.getFilter().getRestrictions(DimensionType.AdminLevel));
            query.where("AdminEntity.AdminEntityId").in(subQuery);
        }
    }
    query.execute(context.getTransaction(), new SqlResultCallback() {

        @Override
        public void onSuccess(SqlTransaction tx, SqlResultSet results) {
            final List<AdminEntityDTO> entities = new ArrayList<AdminEntityDTO>();
            Set<String> names = Sets.newHashSet();
            Set<String> duplicates = Sets.newHashSet();
            for (SqlResultSetRow row : results.getRows()) {
                AdminEntityDTO entity = toEntity(row);
                if (!names.add(entity.getName())) {
                    duplicates.add(entity.getName());
                }
                entities.add(entity);
            }
            for (int i = 0; i != entities.size(); ++i) {
                if (duplicates.contains(entities.get(i).getName())) {
                    String levelName = results.getRow(i).getString("levelName");
                    entities.get(i).setName(entities.get(i).getName() + " [" + levelName + "]");
                }
            }
            callback.onSuccess(new AdminEntityResult(entities));
        }
    });
}
Also used : SqlQuery(com.bedatadriven.rebar.sql.client.query.SqlQuery) Set(java.util.Set) SqlResultSet(com.bedatadriven.rebar.sql.client.SqlResultSet) AdminEntityDTO(org.activityinfo.legacy.shared.model.AdminEntityDTO) SqlTransaction(com.bedatadriven.rebar.sql.client.SqlTransaction) SqlResultSetRow(com.bedatadriven.rebar.sql.client.SqlResultSetRow) SqlResultSet(com.bedatadriven.rebar.sql.client.SqlResultSet) Filter(org.activityinfo.legacy.shared.command.Filter) AdminEntityResult(org.activityinfo.legacy.shared.command.result.AdminEntityResult) SqlResultCallback(com.bedatadriven.rebar.sql.client.SqlResultCallback) ArrayList(java.util.ArrayList) List(java.util.List)

Example 8 with AdminEntityDTO

use of org.activityinfo.legacy.shared.model.AdminEntityDTO 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 9 with AdminEntityDTO

use of org.activityinfo.legacy.shared.model.AdminEntityDTO in project activityinfo by bedatadriven.

the class AdminEntityBinding method extractFieldData.

@Override
public BaseModelData[] extractFieldData(BaseModelData[] dataArray, ColumnSet columnSet) {
    ColumnView adminEntityId = columnSet.getColumnView(ADMIN_ENTITY_ID_COLUMN.asExpression());
    ColumnView adminEntityName = columnSet.getColumnView(ADMIN_ENTITY_NAME_COLUMN.asExpression());
    for (int i = 0; i < columnSet.getNumRows(); i++) {
        if (adminEntityId.isMissing(i)) {
            continue;
        }
        AdminEntityDTO adminEntity = new AdminEntityDTO(adminLevel, CuidAdapter.getLegacyIdFromCuid(adminEntityId.getString(i)), adminEntityName.getString(i));
        adminEntity.setLevelName(adminLevelName);
        if (adminLevelParentId != null) {
            adminEntity.setParentId(CuidAdapter.getLegacyIdFromCuid(adminLevelParentId));
        }
        dataArray[i].set(AdminLevelDTO.getPropertyName(adminEntity.getLevelId()), adminEntity);
    }
    return dataArray;
}
Also used : AdminEntityDTO(org.activityinfo.legacy.shared.model.AdminEntityDTO) ColumnView(org.activityinfo.model.query.ColumnView)

Example 10 with AdminEntityDTO

use of org.activityinfo.legacy.shared.model.AdminEntityDTO in project activityinfo by bedatadriven.

the class AdminFilterPanel method applyFilter.

private void applyFilter() {
    List<AdminEntityDTO> selection = getSelection();
    value = new Filter();
    for (AdminEntityDTO entity : selection) {
        value.addRestriction(DimensionType.AdminLevel, entity.getId());
    }
    ValueChangeEvent.fire(this, value);
    filterToolBar.setRemoveFilterEnabled(true);
}
Also used : Filter(org.activityinfo.legacy.shared.command.Filter) AdminEntityDTO(org.activityinfo.legacy.shared.model.AdminEntityDTO)

Aggregations

AdminEntityDTO (org.activityinfo.legacy.shared.model.AdminEntityDTO)14 AdminEntityResult (org.activityinfo.legacy.shared.command.result.AdminEntityResult)4 ArrayList (java.util.ArrayList)3 Filter (org.activityinfo.legacy.shared.command.Filter)3 GetAdminEntities (org.activityinfo.legacy.shared.command.GetAdminEntities)3 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 HashMap (java.util.HashMap)2 LocationResult (org.activityinfo.legacy.shared.command.result.LocationResult)2 LocationDTO (org.activityinfo.legacy.shared.model.LocationDTO)2 FitLayout (com.extjs.gxt.ui.client.widget.layout.FitLayout)1 StringWriter (java.io.StringWriter)1 List (java.util.List)1 Set (java.util.Set)1 GetLocations (org.activityinfo.legacy.shared.command.GetLocations)1 AdminMarker (org.activityinfo.legacy.shared.reports.content.AdminMarker)1 PointValue (org.activityinfo.legacy.shared.reports.model.PointValue)1