Skip to content

Commit

Permalink
Merge pull request #686 from Shilpa-Manjunath/locdev
Browse files Browse the repository at this point in the history
Mosip 19954 Issue when we create a location with the same name with d…
  • Loading branch information
nayakrounak authored Mar 9, 2022
2 parents 4a2f29f + 6673540 commit 0b28f84
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,10 @@ List<Location> findLocationByHierarchyLevelStartsWith(Short hierarchyLevel, Stri
@Query(value = "FROM Location l where l.code=?1 and l.langCode=?2 and (l.isDeleted is null or l.isDeleted=false) and isActive=true")
Location findLocationByCodeAndLanguageCodeAndIsActiveTrue(String locCode, String languagecode);

@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);

@Query("FROM Location l WHERE l.name=?1 AND l.parentLocCode=?2 AND l.hierarchyLevel=?3 AND l.langCode=?4 AND (l.isDeleted is null or l.isDeleted=false)" )
List<Location> findByNameParentCodeAndLevelLangCode(String name, String parentCode,Short hierarchyLevel, String langCode);

}
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,9 @@ public LocationPostResponseDto createLocation(LocationCreateDto dto) {
throw new RequestException(LocationErrorCode.INVALID_HIERARCY_LEVEL.getErrorCode(),
LocationErrorCode.INVALID_HIERARCY_LEVEL.getErrorMessage());
}
List<Location> list = locationRepository.findByNameAndLevelLangCode(dto.getName(),
dto.getHierarchyLevel(), dto.getLangCode());
List<Location> list =(null!=dto.getParentLocCode() && !dto.getParentLocCode().isEmpty())?locationRepository.findByNameParentCodeAndLevelLangCode(dto.getName(),dto.getParentLocCode(),
dto.getHierarchyLevel(), dto.getLangCode()):locationRepository.findByNameAndLevelLangCode(dto.getName(),
dto.getHierarchyLevel(), dto.getLangCode());
if (list != null && !list.isEmpty()) {
auditUtil.auditRequest(
String.format(MasterDataConstant.FAILURE_CREATE, LocationDto.class.getSimpleName()),
Expand Down Expand Up @@ -311,8 +312,9 @@ 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 0b28f84

Please sign in to comment.