Class LocationService


  • @Service
    public class LocationService
    extends java.lang.Object
    • Constructor Detail

      • LocationService

        public LocationService()
    • Method Detail

      • getDistricts

        public java.util.List<District> getDistricts()
      • getSectors

        public java.util.List<Sector> getSectors()
      • getFacilites

        public java.util.List<Facility> getFacilites()
      • getVillages

        public java.util.List<Village> getVillages()
      • createImportedFacility

        public Facility createImportedFacility​(Facility facility)
      • createImportedVillage

        public Village createImportedVillage​(Village village)
      • createDistrict

        public District createDistrict​(District district)
        Creates IVR group and sets this group to District then saves the district into the db.
        Parameters:
        district - district to save
        Returns:
        saves District
        Throws:
        ChwException - if creating IVR group fails
      • createSector

        public Sector createSector​(Sector sector)
      • searchDistricts

        @PreAuthorize("hasAnyRole(\'ROLE_DISPLAY_FACILITIES\',\'ROLE_MANAGE_FACILITIES\',\'ROLE_MANAGE_OWN_FACILITIES\')")
        public org.springframework.data.domain.Page<District> searchDistricts​(java.lang.String districtName,
                                                                              org.springframework.data.domain.Pageable pageable)
        Finds Districts matching all of the provided parameters. If there are no parameters, return all districts.
        Parameters:
        districtName - name of a District
        pageable - pagination parameters (page size, page number, sort order)
        Returns:
        page with found districts
      • searchSectors

        @PreAuthorize("hasAnyRole(\'ROLE_DISPLAY_FACILITIES\',\'ROLE_MANAGE_FACILITIES\',\'ROLE_MANAGE_OWN_FACILITIES\')")
        public org.springframework.data.domain.Page<Sector> searchSectors​(java.lang.String sectorName,
                                                                          java.lang.String parentDistrict,
                                                                          org.springframework.data.domain.Pageable pageable)
        Finds sectors matching all of the provided parameters. If there are no parameters, return all sectors.
        Parameters:
        pageable - pagination parameters (page size, page number, sort order)
        sectorName - name of sector
        parentDistrict - name of District that may belong to sector
        Returns:
        page with found sectors.
      • searchVillages

        @PreAuthorize("hasAnyRole(\'ROLE_DISPLAY_FACILITIES\',\'ROLE_MANAGE_FACILITIES\',\'ROLE_MANAGE_OWN_FACILITIES\')")
        public org.springframework.data.domain.Page<Village> searchVillages​(java.lang.String villageName,
                                                                            java.lang.String parentFacility,
                                                                            java.lang.String sectorName,
                                                                            java.lang.String districtName,
                                                                            org.springframework.data.domain.Pageable pageable)
        Finds Villages matching all of the provided parameters. If there are no parameters, return all Villages.
        Parameters:
        parentFacility - name of Facility to which a village may belong
        villageName - name of a village
        districtName - name of District to which a village may belong
        sectorName - name of Sector to which a village may belong
        pageable - pagination parameters (page size, page number, sort order)
        Returns:
        page with found villages
      • searchFacilities

        @PreAuthorize("hasAnyRole(\'ROLE_DISPLAY_FACILITIES\',\'ROLE_MANAGE_FACILITIES\',\'ROLE_MANAGE_OWN_FACILITIES\')")
        public org.springframework.data.domain.Page<Facility> searchFacilities​(java.lang.String facilityName,
                                                                               java.lang.String inchargeFullName,
                                                                               java.lang.String inchargePhone,
                                                                               java.lang.String inchargeEmail,
                                                                               java.lang.String parentSector,
                                                                               java.lang.String districtName,
                                                                               org.springframework.data.domain.Pageable pageable)
        Finds Facilitys matching all of the provided parameters. If there are no parameters, return all facilities.
        Parameters:
        pageable - pagination parameters (page size, page number, sort order)
        districtName - name of District that may belong to a facility
        inchargeEmail - email of person in charge
        inchargeFullName - full name of person in charge
        inchargePhone - phone of person in charge
        parentSector - name of Sector that may belong to a facility
        facilityName - name of facility
        Returns:
        page with found facilities
      • createFacility

        @PreAuthorize("hasRole(\'ROLE_CREATE_FACILITIES\')")
        public Facility createFacility​(Facility facility)
      • createVillage

        @PreAuthorize("hasRole(\'ROLE_CREATE_FACILITIES\')")
        public Village createVillage​(Village village)
      • saveDistrict

        @PreAuthorize("hasAnyRole(\'ROLE_MANAGE_FACILITIES\',\'ROLE_MANAGE_OWN_FACILITIES\')")
        public District saveDistrict​(District district)
        Update District.
        Parameters:
        district - District to update
        Returns:
        updated District
      • saveSector

        @PreAuthorize("hasAnyRole(\'ROLE_MANAGE_FACILITIES\',\'ROLE_MANAGE_OWN_FACILITIES\')")
        public Sector saveSector​(Sector sector)
        Update Sector.
        Parameters:
        sector - Sector to update
        Returns:
        updated Sector
      • saveFacility

        @PreAuthorize("hasAnyRole(\'ROLE_MANAGE_FACILITIES\',\'ROLE_MANAGE_OWN_FACILITIES\')")
        public Facility saveFacility​(Facility facility)
        Update Facility.
        Parameters:
        facility - facility to update
        Returns:
        updated Facility
      • saveVillage

        @PreAuthorize("hasAnyRole(\'ROLE_MANAGE_FACILITIES\',\'ROLE_MANAGE_OWN_FACILITIES\')")
        public Village saveVillage​(Village village)
        Update Village.
        Parameters:
        village - Village to update
        Returns:
        updated Village
      • importSectorsFromCsv

        @PreAuthorize("hasRole(\'ROLE_UPLOAD_LOCATION_CSV\')")
        public java.util.Map<java.lang.Integer,​java.lang.String> importSectorsFromCsv​(org.springframework.web.multipart.MultipartFile sectorsCsvFile)
                                                                                     throws java.io.IOException
        Import and save Sector list from CSV file and return list of errors in the file.
        Parameters:
        sectorsCsvFile - CSV file with Sector list
        Returns:
        map with row numbers as keys and errors as values.
        Throws:
        java.io.IOException - in case of file issues
      • importVillagesFromCsv

        @PreAuthorize("hasRole(\'ROLE_UPLOAD_LOCATION_CSV\')")
        public java.util.Map<java.lang.Integer,​java.lang.String> importVillagesFromCsv​(org.springframework.web.multipart.MultipartFile villagesCsvFile)
                                                                                      throws java.io.IOException
        Import and save Village list from CSV file and return list of errors in the file.
        Parameters:
        villagesCsvFile - CSV file with Village list
        Returns:
        map with row numbers as keys and errors as values.
        Throws:
        java.io.IOException - in case of file issues
      • importFacilitiesFromCsv

        @PreAuthorize("hasRole(\'ROLE_UPLOAD_LOCATION_CSV\')")
        public java.util.Map<java.lang.Integer,​java.lang.String> importFacilitiesFromCsv​(org.springframework.web.multipart.MultipartFile facilitiesCsvFile)
                                                                                        throws java.io.IOException
        Import and save Facility list from CSV file and return list of errors in the file.
        Parameters:
        facilitiesCsvFile - CSV file with Facility list
        Returns:
        map with row numbers as keys and errors as values.
        Throws:
        java.io.IOException - in case of file issues
      • getVillage

        @PreAuthorize("hasAnyRole(\'ROLE_DISPLAY_FACILITIES\',\'ROLE_MANAGE_FACILITIES\',\'ROLE_MANAGE_OWN_FACILITIES\')")
        public Village getVillage​(java.util.UUID id)
      • getFacility

        @PreAuthorize("hasAnyRole(\'ROLE_DISPLAY_FACILITIES\',\'ROLE_MANAGE_FACILITIES\',\'ROLE_MANAGE_OWN_FACILITIES\')")
        public Facility getFacility​(java.util.UUID id)
      • getSector

        @PreAuthorize("hasAnyRole(\'ROLE_DISPLAY_FACILITIES\',\'ROLE_MANAGE_FACILITIES\',\'ROLE_MANAGE_OWN_FACILITIES\')")
        public Sector getSector​(java.util.UUID id)
      • getDistrict

        @PreAuthorize("hasAnyRole(\'ROLE_DISPLAY_FACILITIES\',\'ROLE_MANAGE_FACILITIES\',\'ROLE_MANAGE_OWN_FACILITIES\')")
        public District getDistrict​(java.util.UUID id)