Search in sources :

Example 1 with AdminLevelDTO

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

the class ClusteringOptionsWidget method buildForm.

private void buildForm(Collection<AdminLevelDTO> adminLevels) {
    radios = Lists.newArrayList();
    radios.add(new ClusteringRadio(I18N.CONSTANTS.none(), new NoClustering()));
    radios.add(new ClusteringRadio(I18N.CONSTANTS.automatic(), new AutomaticClustering()));
    for (AdminLevelDTO level : adminLevels) {
        AdministrativeLevelClustering clustering = new AdministrativeLevelClustering();
        clustering.getAdminLevels().add(level.getId());
        radios.add(new ClusteringRadio(level.getName(), clustering));
    }
    radioGroup = new RadioGroup();
    radioGroup.setOrientation(Orientation.VERTICAL);
    radioGroup.setStyleAttribute("padding", "5px");
    for (ClusteringRadio radio : radios) {
        radioGroup.add(radio);
        if (radio.getClustering().equals(value)) {
            radioGroup.setValue(radio);
        }
    }
    add(radioGroup);
    radioGroup.addListener(Events.Change, new Listener<FieldEvent>() {

        @Override
        public void handleEvent(FieldEvent be) {
            ClusteringRadio radio = (ClusteringRadio) radioGroup.getValue();
            setValue(radio.getClustering(), true);
        }
    });
    layout();
// unmask();
}
Also used : AdministrativeLevelClustering(org.activityinfo.legacy.shared.reports.model.clustering.AdministrativeLevelClustering) RadioGroup(com.extjs.gxt.ui.client.widget.form.RadioGroup) AdminLevelDTO(org.activityinfo.legacy.shared.model.AdminLevelDTO) FieldEvent(com.extjs.gxt.ui.client.event.FieldEvent) NoClustering(org.activityinfo.legacy.shared.reports.model.clustering.NoClustering) AutomaticClustering(org.activityinfo.legacy.shared.reports.model.clustering.AutomaticClustering)

Example 2 with AdminLevelDTO

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

the class LocationForm method saveNewLocation.

private void saveNewLocation() {
    if (coordinateFields.validate() && nameField.validate() && axeField.validate()) {
        LocationDTO newLocation = new LocationDTO();
        newLocation.setId(new KeyGenerator().generateInt());
        newLocation.setLocationTypeId(locationType.getId());
        newLocation.setName(nameField.getValue());
        newLocation.setAxe(axeField.getValue());
        newLocation.setLatitude(coordinateFields.getLatitudeField().getValue());
        newLocation.setLongitude(coordinateFields.getLongitudeField().getValue());
        for (AdminLevelDTO level : adminPresenter.getAdminLevels()) {
            newLocation.setAdminEntity(level.getId(), adminPresenter.getAdminEntity(level));
        }
        newLocationPresenter.accept(newLocation);
    }
}
Also used : AdminLevelDTO(org.activityinfo.legacy.shared.model.AdminLevelDTO) KeyGenerator(org.activityinfo.model.legacy.KeyGenerator) LocationDTO(org.activityinfo.legacy.shared.model.LocationDTO)

Example 3 with AdminLevelDTO

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

the class GetAdminLevelsHandler method execute.

@Override
public void execute(GetAdminLevels command, ExecutionContext context, final AsyncCallback<AdminLevelResult> callback) {
    if (CollectionUtil.isEmpty(command.getIndicatorIds())) {
        callback.onSuccess(new AdminLevelResult(new ArrayList<AdminLevelDTO>()));
        return;
    }
    String hasPolygonsSubQuery = "exists (select e.adminentityid from adminentity e " + "where e.adminlevelid=level.adminlevelid and geometry is not null)";
    SqlQuery.select().appendColumn("level.adminlevelId", "id").appendColumn("level.name", "name").appendColumn(hasPolygonsSubQuery, "polygons").from(Tables.INDICATOR, "i").innerJoin(Tables.ACTIVITY, "a").on("i.activityId=a.activityId").innerJoin(Tables.USER_DATABASE, "db").on("a.databaseid=db.databaseid").innerJoin(Tables.COUNTRY, "c").on("db.countryid=c.countryid").innerJoin(Tables.ADMIN_LEVEL, "level").on("level.countryid=c.countryid").where("i.indicatorId").in(command.getIndicatorIds()).groupBy("level.adminlevelid").groupBy("level.name").execute(context.getTransaction(), new SqlResultCallback() {

        @Override
        public void onSuccess(SqlTransaction tx, SqlResultSet results) {
            List<AdminLevelDTO> levels = Lists.newArrayList();
            for (SqlResultSetRow row : results.getRows()) {
                AdminLevelDTO level = new AdminLevelDTO();
                level.setId(row.getInt("id"));
                level.setName(row.getString("name"));
                level.setPolygons(row.getBoolean("polygons"));
                levels.add(level);
            }
            callback.onSuccess(new AdminLevelResult(levels));
        }
    });
}
Also used : SqlResultSet(com.bedatadriven.rebar.sql.client.SqlResultSet) AdminLevelResult(org.activityinfo.legacy.shared.command.result.AdminLevelResult) AdminLevelDTO(org.activityinfo.legacy.shared.model.AdminLevelDTO) ArrayList(java.util.ArrayList) 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 4 with AdminLevelDTO

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

the class AdminFieldSetPresenterTest method testSortingAdminLevel.

@Test
public void testSortingAdminLevel() {
    AdminLevelDTO country = new AdminLevelDTO();
    country.setId(0);
    country.setName("Country");
    AdminLevelDTO state = new AdminLevelDTO();
    state.setId(1);
    state.setName("state");
    state.setParentLevelId(0);
    AdminLevelDTO district = new AdminLevelDTO();
    district.setId(2);
    district.setParentLevelId(1);
    district.setName("District");
    AdminLevelDTO city = new AdminLevelDTO();
    city.setId(3);
    city.setParentLevelId(2);
    city.setName("City");
    AdminLevelDTO region = new AdminLevelDTO();
    region.setId(4);
    region.setParentLevelId(0);
    region.setName("Region");
    AdminLevelDTO northRegion = new AdminLevelDTO();
    northRegion.setId(5);
    northRegion.setParentLevelId(4);
    northRegion.setName("North region");
    AdminLevelDTO southRegion = new AdminLevelDTO();
    southRegion.setId(6);
    southRegion.setParentLevelId(4);
    southRegion.setName("south region");
    AdminLevelDTO southEastArea = new AdminLevelDTO();
    southEastArea.setId(7);
    southEastArea.setParentLevelId(6);
    southEastArea.setName("South east area");
    List<AdminLevelDTO> levels = new ArrayList<AdminLevelDTO>();
    levels.add(city);
    levels.add(southEastArea);
    levels.add(region);
    levels.add(northRegion);
    levels.add(southRegion);
    levels.add(country);
    levels.add(state);
    levels.add(district);
    ArrayList<AdminLevelDTO> sortedLevels = sort(levels);
    assertTrue("country before state", sortedLevels.indexOf(country) < sortedLevels.indexOf(state));
    assertTrue("state before district", sortedLevels.indexOf(state) < sortedLevels.indexOf(district));
    assertTrue("district before city", sortedLevels.indexOf(district) < sortedLevels.indexOf(city));
    assertTrue("country before region", sortedLevels.indexOf(country) < sortedLevels.indexOf(region));
    assertTrue("region before 'north region'", sortedLevels.indexOf(region) < sortedLevels.indexOf(northRegion));
    assertTrue("'north region' before 'south region", sortedLevels.indexOf(northRegion) < sortedLevels.indexOf(southRegion));
    assertTrue("'south region' before 'southEastArea", sortedLevels.indexOf(southRegion) < sortedLevels.indexOf(southEastArea));
}
Also used : AdminLevelDTO(org.activityinfo.legacy.shared.model.AdminLevelDTO) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 5 with AdminLevelDTO

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

the class AdminFieldSetPresenterTest method sort.

private ArrayList<AdminLevelDTO> sort(List<AdminLevelDTO> levels2) {
    ArrayList<AdminLevelDTO> sortedList = new ArrayList<>();
    ArrayList<AdminLevelDTO> sorterList = new ArrayList<>();
    for (AdminLevelDTO level : levels2) {
        if (level.getParentLevelId() == null) {
            sorterList.add(level);
            sortedList.add(level);
        }
    }
    while (levels2.size() != sortedList.size()) {
        ArrayList<AdminLevelDTO> tempList = new ArrayList<>();
        for (AdminLevelDTO dto : sorterList) {
            for (AdminLevelDTO e : levels2) {
                if (e.getParentLevelId() != null) {
                    if (e.getParentLevelId().equals(dto.getId())) {
                        tempList.add(e);
                    }
                }
            }
        }
        sortedList.addAll(tempList);
        sorterList.clear();
        sorterList.addAll(tempList);
    }
    return sortedList;
}
Also used : AdminLevelDTO(org.activityinfo.legacy.shared.model.AdminLevelDTO) ArrayList(java.util.ArrayList)

Aggregations

AdminLevelDTO (org.activityinfo.legacy.shared.model.AdminLevelDTO)8 ArrayList (java.util.ArrayList)3 RadioGroup (com.extjs.gxt.ui.client.widget.form.RadioGroup)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 BaseEvent (com.extjs.gxt.ui.client.event.BaseEvent)1 FieldEvent (com.extjs.gxt.ui.client.event.FieldEvent)1 Radio (com.extjs.gxt.ui.client.widget.form.Radio)1 List (java.util.List)1 AdminLevelResult (org.activityinfo.legacy.shared.command.result.AdminLevelResult)1 LocationDTO (org.activityinfo.legacy.shared.model.LocationDTO)1 AdministrativeLevelClustering (org.activityinfo.legacy.shared.reports.model.clustering.AdministrativeLevelClustering)1 AutomaticClustering (org.activityinfo.legacy.shared.reports.model.clustering.AutomaticClustering)1 NoClustering (org.activityinfo.legacy.shared.reports.model.clustering.NoClustering)1 KeyGenerator (org.activityinfo.model.legacy.KeyGenerator)1 Test (org.junit.Test)1