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