Commit b6b0400c authored by Hando Lukats's avatar Hando Lukats
Browse files

Merge branch 'develop' of...

Merge branch 'develop' of https://gitlab.sotsiaalministeerium.ee/teis/riskassessments-service into TEIS-2380
parents e02c76f4 0ed0aa67
......@@ -2,5 +2,5 @@ theGroup=ee.sm.ti.teis
theVersion=1.5.0-SNAPSHOT
commonsVersion=1.27.0-SNAPSHOT
officeApiGatewayVersion=1.27.0-SNAPSHOT
filesVersion=1.19.0
filesVersion=1.21.0-SNAPSHOT
pluginVersion=1.3.0
......@@ -20,7 +20,6 @@ import static ee.sm.ti.teis.types.enums.ObjectStatus.CURRENT;
import static ee.sm.ti.teis.types.enums.RolePrivilegeCode.EX_VIEW_RISK_ASSESSMENTS;
import static ee.sm.ti.teis.types.enums.RolePrivilegeCode.TI_VIEW_RISK_ASSESSMENTS;
import static ee.sm.ti.teis.types.enums.classifier.RiskSettingsStatus.ACTIVE;
import static ee.sm.ti.teis.utils.TestUtils.assertResponseForbidden;
import static ee.sm.ti.teis.utils.TestUtils.createRequestMeta;
import static java.util.UUID.randomUUID;
import static org.assertj.core.api.Assertions.assertThat;
......@@ -74,26 +73,6 @@ public class BusinessTypesPublicGwListenerTest extends RiskAssessmentsAppTestBas
assertThat(dto.getObjectStatus()).isEqualTo(CURRENT);
}
@Test
public void getBusinessTypes_isPersonType_wrongPrivilege_forbidden() {
request.getRequestMetaDTO().setUserType(PERSON);
request.getRequestMetaDTO().setPrivileges(List.of(TI_VIEW_RISK_ASSESSMENTS.name()));
BusinessTypesPublicResponse response = listener.getBusinessTypes(request);
assertResponseForbidden(response.getError());
}
@Test
public void getBusinessTypes_isOfficialType_wrongPrivilege_forbidden() {
request.getRequestMetaDTO().setUserType(OFFICIAL_USER);
request.getRequestMetaDTO().setPrivileges(List.of(EX_VIEW_RISK_ASSESSMENTS.name()));
BusinessTypesPublicResponse response = listener.getBusinessTypes(request);
assertResponseForbidden(response.getError());
}
@Test
public void getBusinessTypes_includeInactive_success() {
request.getRequestMetaDTO().setUserType(PERSON);
......
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);
}
}
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
}
}
......@@ -30,7 +30,6 @@ import static ee.sm.ti.teis.logging.LoggingHelper.logAdminAlertMessage;
import static ee.sm.ti.teis.servicerequest.UserType.SYSTEM;
import static ee.sm.ti.teis.types.enums.FileScanStatusType.CLEAN;
import static ee.sm.ti.teis.types.enums.FileStatusType.*;
import static ee.sm.ti.teis.types.enums.ObjectStatus.CURRENT;
import static java.util.Collections.emptyList;
import static java.util.UUID.randomUUID;
import static liquibase.util.file.FilenameUtils.getBaseName;
......@@ -72,7 +71,7 @@ public class InitialFileUploadService {
filesInFolder.forEach(file -> {
UUID fileId = UUID.fromString(getBaseName(file.getName()));
fileReferenceRepository.findByFileIdAndObjectTypeAndObjectStatus(fileId, objectType.getId(), CURRENT)
fileReferenceRepository.findByIdAndObjectType(fileId, objectType.getId())
.ifPresentOrElse(
fileReference -> {
if (PENDING.equals(fileReference.getFileStatus()) || ACTIVE.equals(fileReference.getFileStatus())) {
......
......@@ -26,8 +26,6 @@ public class BusinessTypePublicGwListener {
private final BusinessTypePublicBusinessService service;
@RabbitListener(queues = {GW_BUSINESS_TYPES_QUEUE})
@PreAuthorize("@accessController.hasAnyPrivilege('TI_VIEW_RISK_ASSESSMENTS', #request.requestMetaDTO.companyId, " +
"'EX_VIEW_RISK_ASSESSMENTS', null)")
public BusinessTypesPublicResponse getBusinessTypes(BusinessTypesPublicRequest request) {
RequestMetaDTO requestMetaDTO = request.getRequestMetaDTO();
List<BusinessTypePublicLightDto> dtoList = service.getBusinessTypes(request.getPayload(), requestMetaDTO);
......
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);
}
}
......@@ -7,7 +7,6 @@ import ee.sm.ti.teis.riskassessments.riskfactor.service.RiskFactorPublicBusiness
import ee.sm.ti.teis.servicerequest.RequestMetaDTO;
import lombok.RequiredArgsConstructor;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Component;
import java.util.List;
......@@ -21,8 +20,6 @@ public class RiskFactorPublicGwListener {
private final RiskFactorPublicBusinessService service;
@RabbitListener(queues = {GW_RISK_FACTORS_QUEUE})
@PreAuthorize("@accessController.hasAnyPrivilege('TI_VIEW_RISK_ASSESSMENTS', #request.requestMetaDTO.companyId, " +
"'EX_VIEW_RISK_ASSESSMENTS', null)")
public RiskFactorsPublicResponse getRiskFactors(RiskFactorsPublicRequest request) {
RequestMetaDTO requestMetaDTO = request.getRequestMetaDTO();
List<RiskFactorPublicDto> dtoList = service.getRiskFactors(request.getPayload(), requestMetaDTO);
......
......@@ -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 distinct 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 distinct 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);
}
}
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