Search in sources :

Example 1 with AdminEntityResult

use of org.activityinfo.shared.command.result.AdminEntityResult in project activityinfo by bedatadriven.

the class AdminEntityProxy method load.

@Override
protected void load(Object loadConfig, final AsyncCallback<ListResult<AdminEntityDTO>> callback) {
    GetAdminEntities query = new GetAdminEntities(levelId);
    query.setParentId(parentId);
    dispatcher.execute(query, new AsyncCallback<AdminEntityResult>() {

        @Override
        public void onFailure(Throwable caught) {
            callback.onFailure(caught);
        }

        @Override
        public void onSuccess(AdminEntityResult result) {
            callback.onSuccess(result);
        }
    });
}
Also used : AdminEntityResult(org.activityinfo.shared.command.result.AdminEntityResult) GetAdminEntities(org.activityinfo.shared.command.GetAdminEntities)

Example 2 with AdminEntityResult

use of org.activityinfo.shared.command.result.AdminEntityResult 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");
    if (CollectionUtil.isNotEmpty(cmd.getCountryIds())) {
        query.leftJoin(Tables.ADMIN_LEVEL, "AdminLevel").on("AdminLevel.AdminLevelId=AdminEntity.AdminLevelId");
        query.where("AdminLevel.CountryId").in(cmd.getCountryIds());
        if (cmd.getParentId() == null && cmd.getLevelId() == null) {
            query.where("AdminLevel.ParentId is null");
        }
        query.orderBy("AdminLevel.CountryId");
    }
    query.orderBy("AdminEntity.name");
    if (cmd.getLevelId() != null) {
        query.where("AdminEntity.AdminLevelId").equalTo(cmd.getLevelId());
    }
    if (cmd.getParentId() != null) {
        query.where("AdminEntity.AdminEntityParentId").equalTo(cmd.getParentId());
    }
    if (cmd.getFilter() != null && cmd.getFilter().isRestricted(DimensionType.Activity)) {
        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").where("site.ActivityId").in(cmd.getFilter().getRestrictions(DimensionType.Activity));
        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>();
            for (SqlResultSetRow row : results.getRows()) {
                entities.add(toEntity(row));
            }
            callback.onSuccess(new AdminEntityResult(entities));
        }
    });
}
Also used : SqlResultSet(com.bedatadriven.rebar.sql.client.SqlResultSet) SqlQuery(com.bedatadriven.rebar.sql.client.query.SqlQuery) AdminEntityDTO(org.activityinfo.shared.dto.AdminEntityDTO) AdminEntityResult(org.activityinfo.shared.command.result.AdminEntityResult) SqlResultCallback(com.bedatadriven.rebar.sql.client.SqlResultCallback) SqlTransaction(com.bedatadriven.rebar.sql.client.SqlTransaction) ArrayList(java.util.ArrayList) List(java.util.List) SqlResultSetRow(com.bedatadriven.rebar.sql.client.SqlResultSetRow)

Example 3 with AdminEntityResult

use of org.activityinfo.shared.command.result.AdminEntityResult 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.shared.dto.AdminEntityDTO) AdminEntityResult(org.activityinfo.shared.command.result.AdminEntityResult) GetAdminEntities(org.activityinfo.shared.command.GetAdminEntities) Test(org.junit.Test)

Example 4 with AdminEntityResult

use of org.activityinfo.shared.command.result.AdminEntityResult in project activityinfo by bedatadriven.

the class GetAdminEntitiesHandlerTest method testSiteQuery.

@Test
public void testSiteQuery() throws Exception {
    GetAdminEntities cmd = new GetAdminEntities();
    cmd.setLevelId(1);
    cmd.setFilter(Filter.filter().onActivity(2));
    AdminEntityResult result = execute(cmd);
    assertThat(result.getData().size(), equalTo(2));
}
Also used : AdminEntityResult(org.activityinfo.shared.command.result.AdminEntityResult) GetAdminEntities(org.activityinfo.shared.command.GetAdminEntities) Test(org.junit.Test)

Example 5 with AdminEntityResult

use of org.activityinfo.shared.command.result.AdminEntityResult in project activityinfo by bedatadriven.

the class GetAdminEntitiesHandlerTest method testRootLevelQuery.

@Test
public void testRootLevelQuery() throws Exception {
    GetAdminEntities cmd = new GetAdminEntities(PROVINCE);
    AdminEntityResult result = execute(cmd);
    assertThat(result.getData().size(), equalTo(4));
}
Also used : AdminEntityResult(org.activityinfo.shared.command.result.AdminEntityResult) GetAdminEntities(org.activityinfo.shared.command.GetAdminEntities) Test(org.junit.Test)

Aggregations

AdminEntityResult (org.activityinfo.shared.command.result.AdminEntityResult)7 GetAdminEntities (org.activityinfo.shared.command.GetAdminEntities)6 AdminEntityDTO (org.activityinfo.shared.dto.AdminEntityDTO)4 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)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 SqlQuery (com.bedatadriven.rebar.sql.client.query.SqlQuery)1 AsyncCallback (com.google.gwt.user.client.rpc.AsyncCallback)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Set (java.util.Set)1 GetSchema (org.activityinfo.shared.command.GetSchema)1 SchemaDTO (org.activityinfo.shared.dto.SchemaDTO)1 AdminMarker (org.activityinfo.shared.report.content.AdminMarker)1