Search in sources :

Example 1 with AdminEntityDTO

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

the class AdminFilterPanel method getSelection.

/**
 * @return the list of AdminEntityDTOs that user has selected with which the
 * filter should be restricted
 */
public List<AdminEntityDTO> getSelection() {
    List<AdminEntityDTO> checked = tree.getCheckedSelection();
    List<AdminEntityDTO> selected = new ArrayList<AdminEntityDTO>();
    for (AdminEntityDTO entity : checked) {
        selected.add(entity);
    }
    return selected;
}
Also used : AdminEntityDTO(org.activityinfo.legacy.shared.model.AdminEntityDTO) ArrayList(java.util.ArrayList)

Example 2 with AdminEntityDTO

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

the class GetLocationsHandler method execute.

@Override
public void execute(final GetLocations command, final ExecutionContext context, final AsyncCallback<LocationResult> callback) {
    if (!command.hasLocationIds() && command.getLocationTypeId() == null) {
        callback.onSuccess(new LocationResult());
        return;
    }
    final Map<Integer, LocationDTO> dtos = new HashMap<>();
    SqlQuery query = SqlQuery.select("locationID", "name", "axe", "x", "y", "workflowStatusId", "LocationTypeId").from(Tables.LOCATION, "Location");
    if (!command.getLocationIds().isEmpty()) {
        query.where("LocationId").in(command.getLocationIds());
    }
    if (command.getLocationTypeId() != null) {
        query.where("locationTypeId").equalTo(command.getLocationTypeId());
    }
    query.where("workflowstatusid").equalTo("validated");
    query.execute(context.getTransaction(), new SqlResultCallback() {

        @Override
        public void onSuccess(SqlTransaction tx, SqlResultSet results) {
            for (SqlResultSetRow row : results.getRows()) {
                final LocationDTO dto = new LocationDTO();
                dto.setId(row.getInt("locationID"));
                dto.setName(row.getString("name"));
                dto.setAxe(row.getString("axe"));
                dto.setWorkflowStatusId(row.getString("workflowStatusId"));
                dto.setLocationTypeId(row.getInt("LocationTypeId"));
                if (!row.isNull("x") && !row.isNull("y")) {
                    dto.setLatitude(row.getDouble("y"));
                    dto.setLongitude(row.getDouble("x"));
                }
                dtos.put(dto.getId(), dto);
            }
            SqlQuery query = SqlQuery.select().appendColumn("AdminEntity.AdminEntityId", "adminEntityId").appendColumn("AdminEntity.Name", "name").appendColumn("AdminEntity.AdminLevelId", "levelId").appendColumn("AdminEntity.AdminEntityParentId", "parentId").appendColumn("link.LocationID", "locationId").from(Tables.LOCATION_ADMIN_LINK, "link").leftJoin(Tables.ADMIN_ENTITY, "AdminEntity").on("link.AdminEntityId=AdminEntity.AdminEntityId").whereTrue("AdminEntity.AdminEntityId is not null");
            if (!command.getLocationIds().isEmpty()) {
                query.where("link.LocationId").in(command.getLocationIds());
            }
            if (command.getLocationTypeId() != null) {
                query.leftJoin(Tables.LOCATION, "Location").on("link.LocationId=Location.LocationId");
                query.where("Location.LocationTypeId").equalTo(command.getLocationTypeId());
            }
            query.execute(context.getTransaction(), new SqlResultCallback() {

                @Override
                public void onSuccess(SqlTransaction tx, SqlResultSet results) {
                    for (SqlResultSetRow row : results.getRows()) {
                        AdminEntityDTO entity = new AdminEntityDTO();
                        entity.setId(row.getInt("adminEntityId"));
                        entity.setName(row.getString("name"));
                        entity.setLevelId(row.getInt("levelId"));
                        if (!row.isNull("parentId")) {
                            entity.setParentId(row.getInt("parentId"));
                        }
                        LocationDTO dto = dtos.get(row.getInt("locationId"));
                        if (dto != null) {
                            dto.setAdminEntity(entity.getLevelId(), entity);
                        }
                    }
                    List<LocationDTO> list = new ArrayList<>(dtos.values());
                    callback.onSuccess(new LocationResult(list));
                }
            });
        }
    });
}
Also used : SqlQuery(com.bedatadriven.rebar.sql.client.query.SqlQuery) HashMap(java.util.HashMap) AdminEntityDTO(org.activityinfo.legacy.shared.model.AdminEntityDTO) ArrayList(java.util.ArrayList) SqlTransaction(com.bedatadriven.rebar.sql.client.SqlTransaction) SqlResultSetRow(com.bedatadriven.rebar.sql.client.SqlResultSetRow) LocationResult(org.activityinfo.legacy.shared.command.result.LocationResult) SqlResultSet(com.bedatadriven.rebar.sql.client.SqlResultSet) SqlResultCallback(com.bedatadriven.rebar.sql.client.SqlResultCallback) LocationDTO(org.activityinfo.legacy.shared.model.LocationDTO)

Example 3 with AdminEntityDTO

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

the class AdminLevelClusterer method cluster.

@Override
public List<Cluster> cluster(TiledMap map, List<PointValue> points) {
    // admin entity id -> cluster
    Map<Integer, Cluster> adminClusters = new HashMap<Integer, Cluster>();
    for (PointValue pv : points) {
        AdminEntityDTO entity = getAdminEntityId(pv);
        if (entity != null) {
            Cluster cluster = adminClusters.get(entity.getId());
            if (cluster == null) {
                cluster = new Cluster(pv);
                cluster.setPoint(adminCenter(map, entity));
                cluster.setTitle(entity.getName());
                adminClusters.put(entity.getId(), cluster);
            } else {
                cluster.addPointValue(pv);
            }
        }
    }
    ArrayList<Cluster> clusters = Lists.newArrayList();
    // update centers of clusters based on points, if any
    for (Cluster cluster : adminClusters.values()) {
        updateCenter(cluster);
        if (cluster.hasPoint()) {
            clusters.add(cluster);
        }
    }
    radiiCalculator.calculate(clusters);
    return clusters;
}
Also used : HashMap(java.util.HashMap) PointValue(org.activityinfo.legacy.shared.reports.model.PointValue) AdminEntityDTO(org.activityinfo.legacy.shared.model.AdminEntityDTO)

Example 4 with AdminEntityDTO

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

the class GetAdminEntitiesHandlerTest method testChildQuery.

@Test
public void testChildQuery() throws Exception {
    GetAdminEntities cmd = new GetAdminEntities(2, 2);
    AdminEntityResult result = execute(cmd);
    assertThat(result.getData().size(), equalTo(3));
    AdminEntityDTO kalehe = result.getData().get(0);
    assertThat(kalehe.getName(), equalTo("Kalehe"));
    assertThat(kalehe.getBounds(), is(not(nullValue())));
    assertThat(kalehe.getBounds().getMinLon(), equalTo(-44d));
    assertThat(kalehe.getBounds().getMinLat(), equalTo(-22d));
    assertThat(kalehe.getBounds().getMaxLon(), equalTo(33.5d));
    assertThat(kalehe.getBounds().getMaxLat(), equalTo(40d));
}
Also used : AdminEntityDTO(org.activityinfo.legacy.shared.model.AdminEntityDTO) AdminEntityResult(org.activityinfo.legacy.shared.command.result.AdminEntityResult) GetAdminEntities(org.activityinfo.legacy.shared.command.GetAdminEntities) Test(org.junit.Test)

Example 5 with AdminEntityDTO

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

the class AdminFieldSetPresenterTest method expectSelections.

private void expectSelections(Collection<AdminEntityDTO> values) {
    resetToDefault(selectionListener);
    for (AdminEntityDTO entity : values) {
        selectionListener.handleEvent(eq(new AdminLevelSelectionEvent(entity.getLevelId(), entity)));
    }
    replay(selectionListener);
}
Also used : 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