Search in sources :

Example 1 with Facility

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

Example 2 with Facility

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

Example 3 with 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));
}
Also used : Facility(org.motechproject.mots.domain.Facility) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

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

Example 5 with Facility

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

Aggregations

Facility (org.motechproject.mots.domain.Facility)14 HashSet (java.util.HashSet)3 UUID (java.util.UUID)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 Chiefdom (org.motechproject.mots.domain.Chiefdom)2 Community (org.motechproject.mots.domain.Community)2 FacilityType (org.motechproject.mots.domain.enums.FacilityType)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)2 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)2 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 Arrays (java.util.Arrays)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1