Commit 0ed0aa67 authored by Hando Lukats's avatar Hando Lukats
Browse files

Merge branch 'TEIS-2379' into 'develop'

Resolve TEIS-2379

Closes TEIS-2379

See merge request teis/riskassessments-service!144
parents 5205acdf f014db41
package ee.sm.ti.teis.riskassessments.riskstatement;
import ee.sm.ti.teis.RiskAssessmentsAppTestBase;
import ee.sm.ti.teis.commongateway.riskassessments.riskstatement.RiskStatementPublicDto;
import ee.sm.ti.teis.commongateway.riskassessments.riskstatement.request.GetRiskStatementsByRiskFactorPublicRequest;
import ee.sm.ti.teis.commongateway.riskassessments.riskstatement.response.GetRiskStatementsByRiskFactorPublicResponse;
import ee.sm.ti.teis.servicecommon.test.ListenerGetListRequestTestBase;
import ee.sm.ti.teis.servicerequest.RequestMetaDTO;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.List;
import java.util.UUID;
import static ee.sm.ti.teis.servicerequest.UserType.OFFICIAL_USER;
import static ee.sm.ti.teis.types.enums.RolePrivilegeCode.TI_MANAGE_RISK_ASSESSMENTS;
import static ee.sm.ti.teis.types.enums.classifier.RiskSettingsStatus.INACTIVE;
import static ee.sm.ti.teis.utils.TestUtils.assertResponseNotFound;
import static ee.sm.ti.teis.utils.TestUtils.createRequestMeta;
import static java.util.UUID.randomUUID;
import static org.assertj.core.api.Assertions.assertThat;
public class GetRiskStatementPublicGwListenerTest extends RiskAssessmentsAppTestBase implements ListenerGetListRequestTestBase {
private static final UUID ACTIVE_RISK_FACTOR_ID = UUID.fromString("06480220-b90d-492b-ac6e-745949039b1a");
private static final UUID NO_RISK_STATEMENTS_RISK_FACTOR_ID = UUID.fromString("a17282ef-012c-4360-a999-f75bd199d06c");
@Autowired
RiskStatementPublicGwListener listener;
GetRiskStatementsByRiskFactorPublicRequest request;
GetRiskStatementsByRiskFactorPublicResponse response;
RequestMetaDTO requestMetaDTO;
@BeforeEach
void setUp() {
request = new GetRiskStatementsByRiskFactorPublicRequest();
requestMetaDTO = createRequestMeta(randomUUID().toString(), OFFICIAL_USER, randomUUID().toString(),
List.of(TI_MANAGE_RISK_ASSESSMENTS.name()));
}
@Override
public void getObjects_deletedRelatedObjectsExcluded_success() {
//not applicable
}
@Override
@Test
public void getObjects_success() {
request.setPayload(ACTIVE_RISK_FACTOR_ID, requestMetaDTO);
response = listener.getRiskStatementSByRiskFactorId(request);
List<RiskStatementPublicDto> payload = response.getPayload();
assertThat(payload).isNotEmpty();
assertThat(payload.stream()
.filter(dto -> INACTIVE.getCode().equals(dto.getStatus().getCode()))
.count()).isEqualTo(0);
}
@Override
@Test
public void getObjects_noResult_success() {
request.setPayload(NO_RISK_STATEMENTS_RISK_FACTOR_ID, requestMetaDTO);
response = listener.getRiskStatementSByRiskFactorId(request);
List<RiskStatementPublicDto> payload = response.getPayload();
assertThat(payload).isEmpty();
}
@Test
public void getObjects_invalidId_notFound() {
request.setPayload(UUID.randomUUID(), requestMetaDTO);
response = listener.getRiskStatementSByRiskFactorId(request);
assertResponseNotFound(response.getError());
}
@Override
public void missingPrivilege_forbidden() {
//not applicable
}
@Override
public void wrongUserType_forbidden() {
//not applicable
}
}
package ee.sm.ti.teis.riskassessments.config;
import ee.sm.ti.teis.commongateway.riskassessments.riskstatement.request.GetRiskStatementsByRiskFactorPublicRequest;
import ee.sm.ti.teis.configuration.QueueList;
import ee.sm.ti.teis.configuration.TeisQueue;
import ee.sm.ti.teis.officegateway.riskassessments.riskstatement.request.CreateRiskStatementRequest;
......@@ -13,11 +14,13 @@ public class RiskStatementQueueConfig implements QueueList {
public static final String GW_CREATE_RISK_STATEMENT_QUEUE = "riskassessments-service.gw.createRiskStatementRequests";
public static final String GW_UPDATE_RISK_STATEMENT_QUEUE = "riskassessments-service.gw.updateRiskStatementRequests";
public static final String GW_DELETE_RISK_STATEMENT_QUEUE = "riskassessments-service.gw.deleteRiskStatementRequests";
public static final String GW_GET_RISK_STATEMENTS_BY_RISK_FACTOR_QUEUE = "riskassessments-service.gw.getRiskStatementsByRiskFactorRequests";
@Override
public void updateQueues(ArrayList<TeisQueue> queues) {
addGwQueue(queues, "gwCreateRiskStatementQueue", CreateRiskStatementRequest.ROUTING_KEY, GW_CREATE_RISK_STATEMENT_QUEUE);
addGwQueue(queues, "gwUpdateRiskStatementQueue", UpdateRiskStatementRequest.ROUTING_KEY, GW_UPDATE_RISK_STATEMENT_QUEUE);
addGwQueue(queues, "gwDeleteRiskStatementQueue", DeleteRiskStatementRequest.ROUTING_KEY, GW_DELETE_RISK_STATEMENT_QUEUE);
addGwQueue(queues, "gwGetRiskStatementsByRiskFactorQueue", GetRiskStatementsByRiskFactorPublicRequest.ROUTING_KEY, GW_GET_RISK_STATEMENTS_BY_RISK_FACTOR_QUEUE);
}
}
package ee.sm.ti.teis.riskassessments.riskstatement;
import ee.sm.ti.teis.commongateway.riskassessments.riskstatement.RiskStatementPublicDto;
import ee.sm.ti.teis.commongateway.riskassessments.riskstatement.request.GetRiskStatementsByRiskFactorPublicRequest;
import ee.sm.ti.teis.commongateway.riskassessments.riskstatement.response.GetRiskStatementsByRiskFactorPublicResponse;
import ee.sm.ti.teis.riskassessments.riskstatement.service.RiskStatementPublicBusinessService;
import ee.sm.ti.teis.servicerequest.RequestMetaDTO;
import lombok.RequiredArgsConstructor;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;
import java.util.List;
import static ee.sm.ti.teis.riskassessments.config.RiskStatementQueueConfig.GW_GET_RISK_STATEMENTS_BY_RISK_FACTOR_QUEUE;
@Component
@RequiredArgsConstructor
public class RiskStatementPublicGwListener {
private final RiskStatementPublicBusinessService service;
@RabbitListener(queues = {GW_GET_RISK_STATEMENTS_BY_RISK_FACTOR_QUEUE})
public GetRiskStatementsByRiskFactorPublicResponse getRiskStatementSByRiskFactorId(
GetRiskStatementsByRiskFactorPublicRequest request) {
RequestMetaDTO requestMetaDTO = request.getRequestMetaDTO();
List<RiskStatementPublicDto> dto = service.getByRiskFactorId(request.getPayload(), requestMetaDTO);
GetRiskStatementsByRiskFactorPublicResponse response = new GetRiskStatementsByRiskFactorPublicResponse();
response.setPayload(dto, requestMetaDTO);
return response;
}
}
package ee.sm.ti.teis.riskassessments.riskstatement.service;
import ee.sm.ti.teis.commongateway.riskassessments.riskstatement.RiskStatementPublicDto;
import ee.sm.ti.teis.riskassessments.riskfactor.service.RiskFactorDataService;
import ee.sm.ti.teis.riskassessments.riskstatement.RiskStatementEntity;
import ee.sm.ti.teis.servicerequest.RequestMetaDTO;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import javax.validation.Valid;
import java.util.List;
import java.util.UUID;
@Service
@RequiredArgsConstructor
@Validated
public class RiskStatementPublicBusinessService {
private final RiskFactorDataService riskFactorDataService;
private final RiskStatementPublicComposeService composeService;
private final RiskStatementDataService dataService;
public List<RiskStatementPublicDto> getByRiskFactorId(@Valid UUID riskFactorId, RequestMetaDTO requestMetaDTO) {
riskFactorDataService.getCurrentById(riskFactorId);
List<RiskStatementEntity> riskStatementEntities = dataService.getCurrentAndActiveByRiskFactorId(riskFactorId);
return composeService.composePublicDtoList(riskStatementEntities, requestMetaDTO);
}
}
......@@ -10,6 +10,11 @@ import ee.sm.ti.teis.servicerequest.RequestMetaDTO;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import java.util.Comparator;
import java.util.List;
import static java.util.stream.Collectors.toList;
@Service
@RequiredArgsConstructor
public class RiskStatementPublicComposeService {
......@@ -26,4 +31,12 @@ public class RiskStatementPublicComposeService {
return dto;
}
public List<RiskStatementPublicDto> composePublicDtoList(List<RiskStatementEntity> entities,
RequestMetaDTO requestMetaDTO) {
return entities.stream()
.map(entity -> composePublicDto(entity, requestMetaDTO))
.sorted(Comparator.comparing(RiskStatementPublicDto::getSeqNo, Comparator.nullsLast(Comparator.naturalOrder())))
.collect(toList());
}
}
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