Search in sources :

Example 1 with GetLocationsResult

use of org.activityinfo.shared.command.GetLocations.GetLocationsResult in project activityinfo by bedatadriven.

the class GetLocationsHandler method execute.

@Override
public void execute(final GetLocations command, final ExecutionContext context, final AsyncCallback<GetLocationsResult> callback) {
    if (command.hasLocationIds()) {
        final Map<Integer, LocationDTO> dtos = new HashMap<Integer, LocationDTO>();
        SqlQuery.select("locationID", "name", "axe", "x", "y").from(Tables.LOCATION).where("locationId").in(command.getLocationIds()).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"));
                    if (!row.isNull("x") && !row.isNull("y")) {
                        dto.setLatitude(row.getDouble("y"));
                        dto.setLongitude(row.getDouble("x"));
                    }
                    dtos.put(dto.getId(), dto);
                }
                SqlQuery.select().appendColumn("AdminEntity.AdminEntityId", "adminEntityId").appendColumn("AdminEntity.Name", "name").appendColumn("AdminEntity.AdminLevelId", "levelId").appendColumn("link.LocationID", "locationId").from(Tables.LOCATION_ADMIN_LINK, "link").leftJoin(Tables.ADMIN_ENTITY, "AdminEntity").on("link.AdminEntityId=AdminEntity.AdminEntityId").where("link.LocationId").in(command.getLocationIds()).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"));
                            LocationDTO dto = dtos.get(row.getInt("locationId"));
                            if (dto != null) {
                                dto.setAdminEntity(entity.getLevelId(), entity);
                            }
                        }
                        List<LocationDTO> list = new ArrayList<LocationDTO>(dtos.values());
                        callback.onSuccess(new GetLocationsResult(list));
                    }
                });
            }
        });
    } else {
        callback.onSuccess(new GetLocationsResult());
    }
}
Also used : HashMap(java.util.HashMap) AdminEntityDTO(org.activityinfo.shared.dto.AdminEntityDTO) ArrayList(java.util.ArrayList) SqlTransaction(com.bedatadriven.rebar.sql.client.SqlTransaction) SqlResultSetRow(com.bedatadriven.rebar.sql.client.SqlResultSetRow) GetLocationsResult(org.activityinfo.shared.command.GetLocations.GetLocationsResult) SqlResultSet(com.bedatadriven.rebar.sql.client.SqlResultSet) SqlResultCallback(com.bedatadriven.rebar.sql.client.SqlResultCallback) LocationDTO(org.activityinfo.shared.dto.LocationDTO)

Example 2 with GetLocationsResult

use of org.activityinfo.shared.command.GetLocations.GetLocationsResult in project activityinfo by bedatadriven.

the class SiteHistoryTab method setSite.

// retrieve all needed data: sitehistoryresult, schema, and locations
public void setSite(final SiteDTO site) {
    renderLoading();
    dispatcher.execute(new GetSiteHistory(site.getId()), new AsyncCallback<GetSiteHistoryResult>() {

        @Override
        public void onFailure(Throwable caught) {
            renderNotAvailable(site);
        }

        @Override
        public void onSuccess(final GetSiteHistoryResult historyResult) {
            if (historyResult.hasHistories()) {
                dispatcher.execute(new GetLocations(historyResult.collectLocationIds()), new AsyncCallback<GetLocationsResult>() {

                    @Override
                    public void onFailure(Throwable caught) {
                        renderNotAvailable(site);
                    }

                    @Override
                    public void onSuccess(final GetLocationsResult locationsResult) {
                        dispatcher.execute(new GetSchema(), new AsyncCallback<SchemaDTO>() {

                            @Override
                            public void onFailure(Throwable caught) {
                                renderNotAvailable(site);
                            }

                            @Override
                            public void onSuccess(SchemaDTO schema) {
                                render(schema, locationsResult.getLocations(), site, historyResult.getSiteHistories());
                            }
                        });
                    }
                });
            } else {
                renderNotAvailable(site);
            }
        }
    });
}
Also used : GetLocations(org.activityinfo.shared.command.GetLocations) AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) GetLocationsResult(org.activityinfo.shared.command.GetLocations.GetLocationsResult) GetSiteHistory(org.activityinfo.shared.command.GetSiteHistory) GetSchema(org.activityinfo.shared.command.GetSchema) SchemaDTO(org.activityinfo.shared.dto.SchemaDTO) GetSiteHistoryResult(org.activityinfo.shared.command.GetSiteHistory.GetSiteHistoryResult)

Aggregations

GetLocationsResult (org.activityinfo.shared.command.GetLocations.GetLocationsResult)2 SqlResultCallback (com.bedatadriven.rebar.sql.client.SqlResultCallback)1 SqlResultSet (com.bedatadriven.rebar.sql.client.SqlResultSet)1 SqlResultSetRow (com.bedatadriven.rebar.sql.client.SqlResultSetRow)1 SqlTransaction (com.bedatadriven.rebar.sql.client.SqlTransaction)1 AsyncCallback (com.google.gwt.user.client.rpc.AsyncCallback)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 GetLocations (org.activityinfo.shared.command.GetLocations)1 GetSchema (org.activityinfo.shared.command.GetSchema)1 GetSiteHistory (org.activityinfo.shared.command.GetSiteHistory)1 GetSiteHistoryResult (org.activityinfo.shared.command.GetSiteHistory.GetSiteHistoryResult)1 AdminEntityDTO (org.activityinfo.shared.dto.AdminEntityDTO)1 LocationDTO (org.activityinfo.shared.dto.LocationDTO)1 SchemaDTO (org.activityinfo.shared.dto.SchemaDTO)1