Commit 946465b2 authored by Hando Lukats's avatar Hando Lukats
Browse files

TEIS-2378 updated getRiskFactors method to include optional parameter businessTypeId

parent ba03c428
package ee.sm.ti.teis.riskassessments.riskfactor;
import ee.sm.ti.teis.RiskAssessmentsAppTestBase;
import ee.sm.ti.teis.commongateway.riskassessments.riskfactor.dto.GetRiskFactorsPublicRequestDto;
import ee.sm.ti.teis.commongateway.riskassessments.riskfactor.dto.RiskFactorPublicDto;
import ee.sm.ti.teis.commongateway.riskassessments.riskfactor.request.RiskFactorsPublicRequest;
import ee.sm.ti.teis.commongateway.riskassessments.riskfactor.response.RiskFactorsPublicResponse;
......@@ -37,9 +38,12 @@ public class RiskFactorsPublicGwListenerTest extends RiskAssessmentsAppTestBase
RiskFactorsPublicRequest request;
RequestMetaDTO requestMetaDTO;
GetRiskFactorsPublicRequestDto requestDto;
RiskFactorsPublicResponse response;
@BeforeEach
void setUp() {
requestDto = GetRiskFactorsPublicRequestDto.builder().build();
request = new RiskFactorsPublicRequest();
requestMetaDTO = createRequestMeta(randomUUID().toString(), OFFICIAL_USER, randomUUID().toString(),
List.of(TI_VIEW_RISK_ASSESSMENTS.name()));
......@@ -48,7 +52,8 @@ public class RiskFactorsPublicGwListenerTest extends RiskAssessmentsAppTestBase
@Test
public void getRiskFactors_success() {
RiskFactorsPublicResponse response = listener.getRiskFactors(request);
request.setPayload(requestDto, requestMetaDTO);
response = listener.getRiskFactors(request);
List<RiskFactorPublicDto> dtoList = response.getPayload();
......@@ -86,8 +91,9 @@ public class RiskFactorsPublicGwListenerTest extends RiskAssessmentsAppTestBase
@Test
public void getRiskFactors_includeInactive_success() {
request.setPayload(true, requestMetaDTO);
RiskFactorsPublicResponse response = listener.getRiskFactors(request);
requestDto.setIncludeInactive(true);
request.setPayload(requestDto, requestMetaDTO);
response = listener.getRiskFactors(request);
List<RiskFactorPublicDto> dtoList = response.getPayload();
......@@ -97,4 +103,36 @@ public class RiskFactorsPublicGwListenerTest extends RiskAssessmentsAppTestBase
.extracting("id")
.contains(UUID.fromString("e8e6ce28-010b-4715-bad5-cbd7e8384294"));
}
@Test
public void getActiveRiskFactors_byBusinessTypeId_success() {
requestDto.setIncludeInactive(false);
requestDto.setBusinessTypeId(UUID.fromString("ab5fee67-85e0-410a-a1b4-1dd12c9ab730"));
request.setPayload(requestDto, requestMetaDTO);
response = listener.getRiskFactors(request);
List<RiskFactorPublicDto> dtoList = response.getPayload();
assertThat(dtoList.size()).isGreaterThanOrEqualTo(1);
assertThat(dtoList.stream()
.filter(dto -> INACTIVE.getCode().equals(dto.getStatus().getCode()))
.count()).isEqualTo(0);
}
@Test
public void getAllRiskFactors_byBusinessTypeId_success() {
requestDto.setIncludeInactive(true);
requestDto.setBusinessTypeId(UUID.fromString("ab5fee67-85e0-410a-a1b4-1dd12c9ab730"));
request.setPayload(requestDto, requestMetaDTO);
response = listener.getRiskFactors(request);
List<RiskFactorPublicDto> dtoList = response.getPayload();
assertThat(dtoList.size()).isGreaterThanOrEqualTo(1);
assertThat(dtoList.stream()
.filter(dto -> INACTIVE.getCode().equals(dto.getStatus().getCode()))
.count()).isGreaterThan(0);
}
}
......@@ -75,4 +75,23 @@ public interface RiskFactorRepository extends CrudRepository<RiskFactorEntity, U
"and riskFactor.status = :status " +
"and riskFactor.general = true ")
List<RiskFactorEntity> queryCurrentGeneralByStatus(String status);
@Query("select riskFactor " +
"from RiskFactorEntity riskFactor " +
" left join BusinessTypeRiskFactorEntity businessTypeRiskFactor " +
" on riskFactor.id = businessTypeRiskFactor.riskFactorId " +
"where businessTypeRiskFactor.businessTypeId = :businessTypeId " +
"and riskFactor.objectStatus = 'CURRENT'" +
"and riskFactor.status = :status " +
"order by riskFactor.name")
List<RiskFactorEntity> queryCurrentActiveByBusinessTypeId(UUID businessTypeId, String status);
@Query("select riskFactor " +
"from RiskFactorEntity riskFactor " +
" left join BusinessTypeRiskFactorEntity businessTypeRiskFactor " +
" on riskFactor.id = businessTypeRiskFactor.riskFactorId " +
"where businessTypeRiskFactor.businessTypeId = :businessTypeId " +
"and riskFactor.objectStatus = 'CURRENT'" +
"order by riskFactor.name")
List<RiskFactorEntity> queryAllByBusinessTypeId(UUID businessTypeId);
}
......@@ -56,4 +56,14 @@ public class RiskFactorDataService {
public RiskFactorEntity save(RiskFactorEntity entity) {
return repository.save(entity);
}
public List<RiskFactorEntity> getCurrentActiveByBusinessTypeId(UUID businessTypeId) {
return repository.queryCurrentActiveByBusinessTypeId(businessTypeId, ACTIVE.getId());
}
public List<RiskFactorEntity> getAllByBusinessTypeId(UUID businessTypeId) {
return repository.queryAllByBusinessTypeId(businessTypeId);
}
}
package ee.sm.ti.teis.riskassessments.riskfactor.service;
import ee.sm.ti.teis.commongateway.riskassessments.riskfactor.dto.GetRiskFactorsPublicRequestDto;
import ee.sm.ti.teis.commongateway.riskassessments.riskfactor.dto.RiskFactorPublicDto;
import ee.sm.ti.teis.riskassessments.riskfactor.entity.RiskFactorEntity;
import ee.sm.ti.teis.servicerequest.RequestMetaDTO;
......@@ -17,15 +18,22 @@ public class RiskFactorPublicBusinessService {
private final RiskFactorDataService dataService;
private final RiskFactorPublicComposeService composeService;
public List<RiskFactorPublicDto> getRiskFactors(Boolean includeInactive, RequestMetaDTO requestMetaDTO) {
public List<RiskFactorPublicDto> getRiskFactors(GetRiskFactorsPublicRequestDto requestDto,
RequestMetaDTO requestMetaDTO) {
List<RiskFactorEntity> entities;
if (isTrue(includeInactive)) {
entities = dataService.getAllCurrent();
if (requestDto.getBusinessTypeId() == null) {
if (isTrue(requestDto.getIncludeInactive())) {
entities = dataService.getAllCurrent();
} else {
entities = dataService.getAllCurrentActive();
}
} else {
entities = dataService.getAllCurrentActive();
if (isTrue(requestDto.getIncludeInactive())) {
entities = dataService.getAllByBusinessTypeId(requestDto.getBusinessTypeId());
} else {
entities = dataService.getCurrentActiveByBusinessTypeId(requestDto.getBusinessTypeId());
}
}
return composeService.composeDtoList(entities, requestMetaDTO);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment