Skip to content

Commit

Permalink
Merge pull request #674 from Shilpa-Manjunath/loc
Browse files Browse the repository at this point in the history
Added query in the location service
  • Loading branch information
nayakrounak authored Mar 2, 2022
2 parents 9a9a62b + 3757958 commit 4c7c6bc
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ List<Location> findLocationByHierarchyLevelStartsWith(Short hierarchyLevel, Stri
@Query("FROM Location l WHERE l.name=?1 AND l.hierarchyLevel=?2 AND l.langCode=?3 AND NOT code=?4")
List<Location> findByNameAndLevelLangCodeNotCode(String name,Short hierarchyLevel, String langCode, String code);

@Query("FROM Location l WHERE l.name=?1 AND l.parentLocCode=?5 AND l.hierarchyLevel=?2 AND l.langCode=?3 AND NOT code=?4")
List<Location> findByNameParentlocCodeAndLevelLangCodeNotCode(String name,Short hierarchyLevel, String langCode, String code,String parentLocCode);


/**
* give list of the immediate Locations for the given parent location code
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,10 @@ public LocationPutResponseDto updateLocationDetails(LocationDto locationDto) {
throw new RequestException(LocationErrorCode.INVALID_HIERARCY_LEVEL.getErrorCode(),
LocationErrorCode.INVALID_HIERARCY_LEVEL.getErrorMessage());
}
List<Location> list = locationRepository.findByNameAndLevelLangCodeNotCode(locationDto.getName(),
locationDto.getHierarchyLevel(), locationDto.getLangCode(), locationDto.getCode());
List<Location> list = (null==locationDto.getParentLocCode() || locationDto.getParentLocCode().isEmpty())? locationRepository.findByNameAndLevelLangCodeNotCode(locationDto.getName(),
locationDto.getHierarchyLevel(), locationDto.getLangCode(), locationDto.getCode()):locationRepository.findByNameParentlocCodeAndLevelLangCodeNotCode(locationDto.getName(),
locationDto.getHierarchyLevel(), locationDto.getLangCode(), locationDto.getCode(),locationDto.getParentLocCode());

if (list != null && !list.isEmpty()) {
auditUtil.auditRequest(
String.format(MasterDataConstant.FAILURE_CREATE, LocationDto.class.getSimpleName()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ public void updateLocationAlreadyExistsUnderHeirarchyExceptionTest() throws Exce
String requestJson = mapper.writeValueAsString(request);
when(repo.findLocationHierarchyByCodeAndLanguageCode(Mockito.any(), Mockito.any()))
.thenReturn(Arrays.asList(location1));
when(repo.findByNameParentlocCodeAndLevelLangCodeNotCode(Mockito.any(),Mockito.any(),Mockito.any(), Mockito.any(),Mockito.any())).thenReturn(Arrays.asList(location1));
when(repo.findByNameAndLevelLangCodeNotCode(Mockito.any(),Mockito.any(),Mockito.any(), Mockito.any())).thenReturn(Arrays.asList(location1));
mockMvc.perform(put("/locations").contentType(MediaType.APPLICATION_JSON).content(requestJson))
.andExpect(status().isOk());
Expand Down

0 comments on commit 4c7c6bc

Please sign in to comment.