Skip to content

Commit

Permalink
MOSIP-29472 Added API /locations/immediatechildren/{locationcode} (mo…
Browse files Browse the repository at this point in the history
…sip#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
  • Loading branch information
kameshsr authored and GOKULRAJ136 committed Feb 7, 2024
1 parent b93e479 commit 265b728
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 2 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);
}

}

0 comments on commit 265b728

Please sign in to comment.