From 265b728361867f338b30d2762640cd2e98afb50c Mon Sep 17 00:00:00 2001 From: kameshsr <47484458+kameshsr@users.noreply.github.com> Date: Tue, 26 Sep 2023 13:01:28 +0530 Subject: [PATCH] MOSIP-29472 Added API /locations/immediatechildren/{locationcode} (#904) * MOSIP-29472 Create API dynamicfields/all. * MOSIP-29472 Create API dynamicfields/all. * MOSIP-29472 Create API dynamicfields/all. * MOSIP-29472 Covered Junit for Dynamic field all API. * MOSIP-29472 Covered Junit for Dynamic field all API. * MOSIP-29472 Changed logic as per review comment. * MOSIP-29472 Changed logic as per review comment. * MOSIP-29472 Changed logic as per review comment. * MOSIP-29472 Added API {{url}}/v1/masterdata/locations/immediatechildren/{locationCode}. * MOSIP-29472 Removed un-used class. * MOSIP-29472 Added Junit for new API /immediatechildren/locationcode * MOSIP-29472 Added Junit for new API /immediatechildren/locationcode * MOSIP-29472 Added Junit for new API /immediatechildren/locationcode * MOSIP-29472 Added Junit for new API /immediatechildren/locationcode * MOSIP-29472 Added Junit for new API /immediatechildren/locationcode --- .../controller/LocationController.java | 17 +++++++++++++ .../repository/LocationRepository.java | 3 +++ .../masterdata/service/LocationService.java | 1 + .../service/impl/LocationServiceImpl.java | 24 +++++++++++++++++-- .../controller/LocationControllerTest.java | 8 +++++++ 5 files changed, 51 insertions(+), 2 deletions(-) diff --git a/admin/kernel-masterdata-service/src/main/java/io/mosip/kernel/masterdata/controller/LocationController.java b/admin/kernel-masterdata-service/src/main/java/io/mosip/kernel/masterdata/controller/LocationController.java index 9be30f376f9..7db7db9bd5e 100644 --- a/admin/kernel-masterdata-service/src/main/java/io/mosip/kernel/masterdata/controller/LocationController.java +++ b/admin/kernel-masterdata-service/src/main/java/io/mosip/kernel/masterdata/controller/LocationController.java @@ -230,6 +230,23 @@ public ResponseWrapper getImmediateChildrenByLocCodeAndLang return responseWrapper; } + /** + * + * @param locationCode location code + * @param languageCodes language codes + * @return list of location hierarchies + */ + @ResponseFilter + @GetMapping(value = "/immediatechildren/{locationcode}") + public ResponseWrapper getImmediateChildrenByLocCode( + @PathVariable("locationcode") String locationCode, @RequestParam("languageCodes") List languageCodes) { + + ResponseWrapper responseWrapper = new ResponseWrapper<>(); + responseWrapper + .setResponse(locationHierarchyService.getImmediateChildrenByLocCode(locationCode, languageCodes)); + return responseWrapper; + } + /** * checks whether the given location name is valid or not * diff --git a/admin/kernel-masterdata-service/src/main/java/io/mosip/kernel/masterdata/repository/LocationRepository.java b/admin/kernel-masterdata-service/src/main/java/io/mosip/kernel/masterdata/repository/LocationRepository.java index c47876bd38b..419735474e2 100644 --- a/admin/kernel-masterdata-service/src/main/java/io/mosip/kernel/masterdata/repository/LocationRepository.java +++ b/admin/kernel-masterdata-service/src/main/java/io/mosip/kernel/masterdata/repository/LocationRepository.java @@ -160,4 +160,7 @@ List findLocationByHierarchyLevelStartsWith(Short hierarchyLevel, Stri @Query(value = "FROM Location l where l.langCode=?1 and l.hierarchyLevel=?2") List getAllLocationsByLangCodeWithHierarchyLevel(String langCode, Short level); + @Query(value = "FROM Location l WHERE parentLocCode = ?1 AND l.langCode IN (?2) AND (l.isDeleted IS NULL OR l.isDeleted = false) AND l.isActive = true") + List findLocationHierarchyByParentLocCode(String parentLocCode, List languageCodes); + } diff --git a/admin/kernel-masterdata-service/src/main/java/io/mosip/kernel/masterdata/service/LocationService.java b/admin/kernel-masterdata-service/src/main/java/io/mosip/kernel/masterdata/service/LocationService.java index 74f52bc059c..e2c8a0d0452 100644 --- a/admin/kernel-masterdata-service/src/main/java/io/mosip/kernel/masterdata/service/LocationService.java +++ b/admin/kernel-masterdata-service/src/main/java/io/mosip/kernel/masterdata/service/LocationService.java @@ -137,4 +137,5 @@ public interface LocationService { public FilterResponseCodeDto locFilterValues(FilterValueDto filterValueDto); + LocationResponseDto getImmediateChildrenByLocCode(String locationCode, List languageCodes); } diff --git a/admin/kernel-masterdata-service/src/main/java/io/mosip/kernel/masterdata/service/impl/LocationServiceImpl.java b/admin/kernel-masterdata-service/src/main/java/io/mosip/kernel/masterdata/service/impl/LocationServiceImpl.java index 7cad5c2ea24..d3dd6c8fd76 100644 --- a/admin/kernel-masterdata-service/src/main/java/io/mosip/kernel/masterdata/service/impl/LocationServiceImpl.java +++ b/admin/kernel-masterdata-service/src/main/java/io/mosip/kernel/masterdata/service/impl/LocationServiceImpl.java @@ -5,10 +5,8 @@ import java.util.Collections; import java.util.List; import java.util.Map; -import java.util.Objects; import java.util.Set; import java.util.TreeMap; -import java.util.stream.Collectors; import io.mosip.kernel.masterdata.dto.response.*; import org.springframework.beans.factory.annotation.Autowired; @@ -958,4 +956,26 @@ public FilterResponseCodeDto locFilterValues(FilterValueDto filterValueDto) { } return filterResponseDto; } + + + @Override + public LocationResponseDto getImmediateChildrenByLocCode(String locationCode, List languageCodes) { + List locationlist = null; + LocationResponseDto locationHierarchyResponseDto = new LocationResponseDto(); + try { + locationlist = locationRepository.findLocationHierarchyByParentLocCode(locationCode, languageCodes); + + } catch (DataAccessException | DataAccessLayerException e) { + throw new MasterDataServiceException(LocationErrorCode.LOCATION_FETCH_EXCEPTION.getErrorCode(), + LocationErrorCode.LOCATION_FETCH_EXCEPTION.getErrorMessage() + ExceptionUtils.parseException(e)); + } + + if (locationlist.isEmpty()) { + throw new DataNotFoundException(LocationErrorCode.LOCATION_NOT_FOUND_EXCEPTION.getErrorCode(), + LocationErrorCode.LOCATION_NOT_FOUND_EXCEPTION.getErrorMessage()); + } + List locationDtoList = MapperUtils.mapAll(locationlist, LocationDto.class); + locationHierarchyResponseDto.setLocations(locationDtoList); + return locationHierarchyResponseDto; + } } diff --git a/admin/kernel-masterdata-service/src/test/java/io/mosip/kernel/masterdata/test/controller/LocationControllerTest.java b/admin/kernel-masterdata-service/src/test/java/io/mosip/kernel/masterdata/test/controller/LocationControllerTest.java index eb693eddf38..ed32cf0b380 100644 --- a/admin/kernel-masterdata-service/src/test/java/io/mosip/kernel/masterdata/test/controller/LocationControllerTest.java +++ b/admin/kernel-masterdata-service/src/test/java/io/mosip/kernel/masterdata/test/controller/LocationControllerTest.java @@ -674,4 +674,12 @@ public void t021updateLocationStatusFailTest() throws Exception { } + @Test + @WithUserDetails("global-admin") + public void t021getImmediateChildrenByLocCode() throws Exception { + + MasterDataTest + .checkResponse(mockMvc.perform(MockMvcRequestBuilders.get("/locations/immediatechildren/RSK?languageCodes=eng,tam")).andReturn(), null); + } + }