use of org.motechproject.mots.domain.enums.FacilityType in project mots by motech-implementations.
the class LocationImporter method parseFacilities.
private void parseFacilities(XSSFSheet sheet) {
XSSFRow row;
XSSFCell cell;
Iterator rows = sheet.rowIterator();
HashSet<Facility> newFacilitySet = new HashSet<>();
DataFormatter fmt = new DataFormatter();
while (rows.hasNext()) {
row = (XSSFRow) rows.next();
cell = row.getCell(FACILITY_COL_NUMBER);
if (cell == null) {
continue;
}
String cellText = cell.getStringCellValue();
if (cellText.equals(FACILITY_HEADER) || StringUtils.isEmpty(cellText)) {
continue;
}
String facilityId = fmt.formatCellValue(row.getCell(ID_FACILITY_COL_NUMBER));
FacilityType facilityType = FacilityType.getByDisplayName(row.getCell(NAME_FACILITY_COL_NUMBER).getStringCellValue());
Facility facility = new Facility(cellText, facilityType, facilityId);
String parentChiefdomName = row.getCell(CHIEFDOM_COL_NUMBER).getStringCellValue();
String parentDistrictName = row.getCell(DISTRICT_COL_NUMBER).getStringCellValue();
Chiefdom parent = currentChiefdomList.stream().filter(chiefdom -> chiefdom.getName().equals(parentChiefdomName) && chiefdom.getDistrict().getName().equals(parentDistrictName)).findFirst().orElseThrow(() -> new RuntimeException(String.format("'%s' Facility parent " + "is not defined properly in spreadsheet", facility.getName())));
facility.setChiefdom(parent);
newFacilitySet.add(facility);
}
newFacilitySet.forEach(newFacility -> {
if (!currentFacilityList.contains(newFacility)) {
locationService.createImportedFacility(newFacility);
}
});
}
use of org.motechproject.mots.domain.enums.FacilityType in project mots by motech-implementations.
the class FacilityRepositoryImpl method prepareQuery.
private <T> CriteriaQuery<T> prepareQuery(CriteriaQuery<T> query, String facilityId, String facilityName, String facilityType, String inchargeFullName, String parentChiefdom, String districtName, boolean count, Pageable pageable) throws IllegalArgumentException {
CriteriaBuilder builder = entityManager.getCriteriaBuilder();
Root<Facility> root = query.from(Facility.class);
if (count) {
CriteriaQuery<Long> countQuery = (CriteriaQuery<Long>) query;
query = (CriteriaQuery<T>) countQuery.select(builder.count(root));
}
Predicate predicate = builder.conjunction();
if (facilityId != null) {
predicate = builder.and(predicate, builder.like(root.get(FACILITY_ID), '%' + facilityId + '%'));
}
if (facilityName != null) {
predicate = builder.and(predicate, builder.like(root.get(NAME), '%' + facilityName + '%'));
}
if (facilityType != null) {
FacilityType validFacilityType = FacilityType.valueOf(facilityType.toUpperCase());
predicate = builder.and(predicate, builder.equal(root.get(FACILITY_TYPE), validFacilityType));
}
if (inchargeFullName != null) {
predicate = builder.and(predicate, builder.like(root.get(INCHARGE).get(FIRST_NAME), '%' + inchargeFullName + '%'));
predicate = builder.or(predicate, builder.like(root.get(INCHARGE).get(SECOND_NAME), '%' + inchargeFullName + '%'));
predicate = builder.or(predicate, builder.like(root.get(INCHARGE).get(OTHER_NAME), '%' + inchargeFullName + '%'));
}
if (parentChiefdom != null) {
predicate = builder.and(predicate, builder.like(root.get(CHIEFDOM).get(NAME), '%' + parentChiefdom + '%'));
}
if (districtName != null) {
predicate = builder.and(predicate, builder.like(root.get(CHIEFDOM).get(DISTRICT).get(NAME), '%' + districtName + '%'));
}
query.where(predicate);
if (!count && pageable != null && pageable.getSort() != null) {
query = addSortProperties(query, root, pageable);
}
return query;
}
Aggregations