use of org.motechproject.mots.domain.District in project mots by motech-implementations.
the class DistrictDataBuilder method buildAsNew.
/**
* Builds instance of {@link District} without id.
*/
public District buildAsNew() {
District district = new District();
district.setName(name);
return district;
}
use of org.motechproject.mots.domain.District in project mots by motech-implementations.
the class DistrictDataBuilder method build.
/**
* Builds instance of {@link District}.
*/
public District build() {
District district = buildAsNew();
district.setId(id);
return district;
}
use of org.motechproject.mots.domain.District in project mots by motech-implementations.
the class LocationImporter method parseChiefdoms.
private void parseChiefdoms(XSSFSheet sheet) {
XSSFRow row;
XSSFCell cell;
Iterator rows = sheet.rowIterator();
HashSet<Chiefdom> newChiefdomSet = new HashSet<>();
while (rows.hasNext()) {
row = (XSSFRow) rows.next();
cell = row.getCell(CHIEFDOM_COL_NUMBER);
if (cell == null) {
continue;
}
String cellText = cell.getStringCellValue();
if (cellText.equals(CHIEFDOM_HEADER) || StringUtils.isEmpty(cellText)) {
continue;
}
Chiefdom chiefdom = new Chiefdom(cellText);
String parentName = row.getCell(DISTRICT_COL_NUMBER).getStringCellValue();
District parent = currentDistrictList.stream().filter(district -> district.getName().equals(parentName)).findFirst().orElseThrow(() -> new RuntimeException(String.format("'%s' Chiefdom parent " + "is not defined properly in spreadsheet", chiefdom.getName())));
chiefdom.setDistrict(parent);
newChiefdomSet.add(chiefdom);
}
newChiefdomSet.forEach(newChiefdom -> {
if (!currentChiefdomList.contains(newChiefdom)) {
locationService.createChiefdom(newChiefdom);
}
});
}
Aggregations