Search in sources :

Example 6 with District

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;
}
Also used : District(org.motechproject.mots.domain.District)

Example 7 with 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;
}
Also used : District(org.motechproject.mots.domain.District)

Example 8 with 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);
        }
    });
}
Also used : XSSFRow(org.apache.poi.xssf.usermodel.XSSFRow) Iterator(java.util.Iterator) XSSFCell(org.apache.poi.xssf.usermodel.XSSFCell) District(org.motechproject.mots.domain.District) Chiefdom(org.motechproject.mots.domain.Chiefdom) HashSet(java.util.HashSet)

Aggregations

District (org.motechproject.mots.domain.District)8 HashSet (java.util.HashSet)3 Iterator (java.util.Iterator)2 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)2 XSSFCell (org.apache.poi.xssf.usermodel.XSSFCell)2 XSSFRow (org.apache.poi.xssf.usermodel.XSSFRow)2 Test (org.junit.Test)2 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 List (java.util.List)1 Optional (java.util.Optional)1 Set (java.util.Set)1 UUID (java.util.UUID)1 EntityManager (javax.persistence.EntityManager)1 CriteriaQuery (javax.persistence.criteria.CriteriaQuery)1 Predicate (javax.persistence.criteria.Predicate)1 Assert.assertEquals (org.junit.Assert.assertEquals)1 Assert.assertTrue (org.junit.Assert.assertTrue)1 Before (org.junit.Before)1 RunWith (org.junit.runner.RunWith)1