Skip to content

Commit

Permalink
MOSIP-29472 Added API /locations/immediatechildren/{locationcode} (#904)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
kameshsr authored Sep 26, 2023
1 parent b33ef47 commit 50a1dbd
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,23 @@ public ResponseWrapper<LocationResponseDto> getImmediateChildrenByLocCodeAndLang
return responseWrapper;
}

/**
*
* @param locationCode location code
* @param languageCodes language codes
* @return list of location hierarchies
*/
@ResponseFilter
@GetMapping(value = "/immediatechildren/{locationcode}")
public ResponseWrapper<LocationResponseDto> getImmediateChildrenByLocCode(
@PathVariable("locationcode") String locationCode, @RequestParam("languageCodes") List<String> languageCodes) {

ResponseWrapper<LocationResponseDto> responseWrapper = new ResponseWrapper<>();
responseWrapper
.setResponse(locationHierarchyService.getImmediateChildrenByLocCode(locationCode, languageCodes));
return responseWrapper;
}

/**
* checks whether the given location name is valid or not
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,7 @@ List<Location> findLocationByHierarchyLevelStartsWith(Short hierarchyLevel, Stri
@Query(value = "FROM Location l where l.langCode=?1 and l.hierarchyLevel=?2")
List<Location> 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<Location> findLocationHierarchyByParentLocCode(String parentLocCode, List<String> languageCodes);

}
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,5 @@ public interface LocationService {

public FilterResponseCodeDto locFilterValues(FilterValueDto filterValueDto);

LocationResponseDto getImmediateChildrenByLocCode(String locationCode, List<String> languageCodes);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -958,4 +956,26 @@ public FilterResponseCodeDto locFilterValues(FilterValueDto filterValueDto) {
}
return filterResponseDto;
}


@Override
public LocationResponseDto getImmediateChildrenByLocCode(String locationCode, List<String> languageCodes) {
List<Location> 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<LocationDto> locationDtoList = MapperUtils.mapAll(locationlist, LocationDto.class);
locationHierarchyResponseDto.setLocations(locationDtoList);
return locationHierarchyResponseDto;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import java.time.Month;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import io.mosip.kernel.core.exception.ServiceError;
Expand Down Expand Up @@ -3105,4 +3104,28 @@ public void validateRegCenterUpdateTest() {
Assert.assertEquals("KER-MSD-259", serviceErrors.get(4).getErrorCode());
}

@Test
public void getImmediateChildrenByLocCodeTest() {
Mockito.when(locationHierarchyRepository
.findLocationHierarchyByParentLocCode(Mockito.anyString(), Mockito.anyList()))
.thenReturn(locationHierarchies);
Assert.assertEquals("IND", locationHierarchyService.getImmediateChildrenByLocCode("KAR", List.of("eng")).getLocations().get(0).getCode());
}

@Test(expected = MasterDataServiceException.class)
public void getImmediateChildrenByLocCodeTestExceptionTest() {
Mockito.when(locationHierarchyRepository
.findLocationHierarchyByParentLocCode(Mockito.anyString(), Mockito.anyList()))
.thenThrow(DataRetrievalFailureException.class);
locationHierarchyService.getImmediateChildrenByLocCode("KAR", List.of("eng"));
}

@Test(expected = DataNotFoundException.class)
public void getImmediateChildrenByLocCodeTestDataExceptionTest() {
Mockito.when(locationHierarchyRepository
.findLocationHierarchyByParentLocCode(Mockito.anyString(), Mockito.anyList()))
.thenReturn(new ArrayList<Location>());
locationHierarchyService.getImmediateChildrenByLocCode("KAR", List.of("eng"));
}

}

0 comments on commit 50a1dbd

Please sign in to comment.