use of org.motechproject.mots.domain.Facility in project mots by motech-implementations.
the class FacilityRepositoryIntegrationTest method shouldFindFacilityByName.
@Test
public void shouldFindFacilityByName() {
// when
Page<Facility> result = facilityRepository.search(null, facility1.getName(), null, null, null, null, null);
// then
assertThat(result.getTotalElements(), is(1L));
Facility foundFacility = result.getContent().get(0);
assertThat(foundFacility.getName(), is(facility1.getName()));
}
use of org.motechproject.mots.domain.Facility in project mots by motech-implementations.
the class FacilityDataBuilder method buildAsNew.
/**
* Builds instance of {@link Facility} without id.
*/
public Facility buildAsNew() {
Facility facility = new Facility();
facility.setFacilityId(facilityId);
facility.setName(name);
facility.setType(facilityType);
facility.setChiefdom(chiefdom);
return facility;
}
use of org.motechproject.mots.domain.Facility in project mots by motech-implementations.
the class LocationController method saveFacility.
/**
* Update Facility.
* @param id id of Facility to update
* @param facilityCreationDto DTO of Facility to be updated
* @return updated Facility
*/
@RequestMapping(value = "/facility/{id}", method = RequestMethod.PUT)
@ResponseStatus(HttpStatus.OK)
@ResponseBody
public FacilityCreationDto saveFacility(@PathVariable("id") UUID id, @RequestBody @Valid FacilityCreationDto facilityCreationDto, BindingResult bindingResult) {
checkBindingResult(bindingResult);
Facility facility = locationService.getFacility(id);
locationMapper.updateFacilityFromDto(facilityCreationDto, facility);
return locationMapper.toFacilityCreationDto(locationService.saveFacility(facility));
}
use of org.motechproject.mots.domain.Facility 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.Facility in project mots by motech-implementations.
the class LocationImporter method parseCommunities.
private void parseCommunities(XSSFSheet sheet) {
XSSFRow row;
XSSFCell cell;
Iterator rows = sheet.rowIterator();
HashSet<Community> newCommunitySet = new HashSet<>();
while (rows.hasNext()) {
row = (XSSFRow) rows.next();
cell = row.getCell(COMMUNITY_COL_NUMBER);
if (cell == null) {
continue;
}
String cellText = cell.getStringCellValue();
if (cellText.equals(COMMUNITY_HEADER) || StringUtils.isEmpty(cellText)) {
continue;
}
Community community = new Community(cellText);
String parentFacilityName = row.getCell(FACILITY_COL_NUMBER).getStringCellValue();
String parentChiefdomName = row.getCell(CHIEFDOM_COL_NUMBER).getStringCellValue();
String parentDistrictName = row.getCell(DISTRICT_COL_NUMBER).getStringCellValue();
Facility parent = currentFacilityList.stream().filter(facility -> facility.getName().equals(parentFacilityName) && facility.getChiefdom().getName().equals(parentChiefdomName) && facility.getChiefdom().getDistrict().getName().equals(parentDistrictName)).findFirst().orElseThrow(() -> new RuntimeException(String.format("'%s' Community parent " + "is not defined properly in spreadsheet", community.getName())));
community.setFacility(parent);
newCommunitySet.add(community);
}
newCommunitySet.forEach(newCommunity -> {
if (!currentCommunityList.contains(newCommunity)) {
locationService.createImportedCommunity(newCommunity);
}
});
}
Aggregations