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