use of org.motechproject.mots.domain.Chiefdom in project mots by motech-implementations.
the class ChiefdomDataBuilder method build.
/**
* Builds instance of {@link Chiefdom}.
*/
public Chiefdom build() {
Chiefdom chiefdom = buildAsNew();
chiefdom.setId(id);
return chiefdom;
}
use of org.motechproject.mots.domain.Chiefdom 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.Chiefdom in project mots by motech-implementations.
the class ChiefdomDataBuilder method buildAsNew.
/**
* Builds instance of {@link Chiefdom} without id.
*/
public Chiefdom buildAsNew() {
Chiefdom chiefdom = new Chiefdom();
chiefdom.setName(name);
chiefdom.setDistrict(district);
return chiefdom;
}
use of org.motechproject.mots.domain.Chiefdom in project mots by motech-implementations.
the class ChiefdomRepositoryIntegrationTest method shouldFindChiefdomByName.
@Test
public void shouldFindChiefdomByName() {
// when
Page<Chiefdom> result = chiefdomRepository.search(chiefdom1.getName(), null, null);
// then
assertThat(result.getTotalElements(), is(1L));
Chiefdom foundChiefdom = result.getContent().get(0);
assertThat(foundChiefdom.getName(), is(chiefdom1.getName()));
}
use of org.motechproject.mots.domain.Chiefdom in project mots by motech-implementations.
the class FacilityUniquenessValidator method isValid.
@Override
public boolean isValid(FacilityCreationDto facilityCreationDto, ConstraintValidatorContext context) {
if (StringUtils.isNotEmpty(facilityCreationDto.getChiefdomId()) && ValidationUtils.isValidUuidString(facilityCreationDto.getChiefdomId()) && StringUtils.isNotEmpty(facilityCreationDto.getName())) {
String name = facilityCreationDto.getName();
UUID chiefdomId = UUID.fromString(facilityCreationDto.getChiefdomId());
Chiefdom chiefdom = chiefdomRepository.findOne(chiefdomId);
Optional<Facility> existing = facilityRepository.findByNameAndChiefdom(name, chiefdom);
if (// when edit facility allows change
existing.isPresent() && !existing.get().getId().toString().equals(facilityCreationDto.getId())) {
String message = String.format(ValidationMessages.NOT_UNIQUE_FACILITY, existing.get().getName());
context.disableDefaultConstraintViolation();
ValidationUtils.addDefaultViolationMessageToInnerField(context, NAME, message);
return false;
}
}
return true;
}
Aggregations