Skip to content

Commit

Permalink
feat: add mandatory tests for issuers
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreaDel03 committed Oct 16, 2024
1 parent e4c7179 commit 34d89a8
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,20 @@
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.http.converter.HttpMessageNotReadableException;
import org.springframework.lang.NonNull;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.context.request.WebRequest;
import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler;

import com.fasterxml.jackson.databind.exc.InvalidFormatException;

import static it.finanze.sanita.fse2.ms.iniclient.enums.ErrorClassEnum.*;

import java.util.Arrays;

/**
* Exceptions Handler.
*/
Expand Down Expand Up @@ -118,4 +123,24 @@ protected ResponseEntity<ErrorResponseDTO> handleGenericException(final Exceptio
return new ResponseEntity<>(response, HttpStatus.BAD_REQUEST);
}

@Override
protected ResponseEntity<Object> handleHttpMessageNotReadable(HttpMessageNotReadableException ex, HttpHeaders headers, HttpStatus status, WebRequest request) {

LogTraceInfoDTO traceInfo = getLogTraceInfo();

ErrorDTO error = new ErrorDTO();
if (ex.getCause() instanceof InvalidFormatException) {
InvalidFormatException invalidFormatException = (InvalidFormatException) ex.getCause();
if (invalidFormatException.getTargetType().isEnum()) {
String invalidValue = invalidFormatException.getValue().toString();
String errorMessage = String.format("Invalid value '%s' for enum. Allowed values are: %s",
invalidValue, Arrays.toString(invalidFormatException.getTargetType().getEnumConstants()));
error = new ErrorDTO(INVALID_INPUT.getType(), INVALID_INPUT.getTitle(), errorMessage, INVALID_INPUT.getInstance());
}
}

ErrorResponseDTO response = new ErrorResponseDTO(traceInfo, error);
return new ResponseEntity<>(error, HttpStatus.BAD_REQUEST);
}

}
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package it.finanze.sanita.fse2.ms.iniclient.dto;

import com.mongodb.lang.Nullable;

import it.finanze.sanita.fse2.ms.iniclient.enums.TestTypeEnum;
import it.finanze.sanita.fse2.ms.iniclient.validators.ValidMiddlewareIssuer;
import lombok.*;

import java.util.List;

import javax.validation.constraints.NotBlank;

@Data
Expand Down Expand Up @@ -35,4 +39,6 @@ public class IssuerCreateRequestDTO {
private String pazienteCf;

private boolean readyToScan;

private List<TestTypeEnum> mandatoryTests;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package it.finanze.sanita.fse2.ms.iniclient.enums;

public enum TestTypeEnum {

CREATE,
REPLACE,
UPDATE,
DELETE;

}
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
package it.finanze.sanita.fse2.ms.iniclient.repository.entity;

import com.mongodb.lang.Nullable;

import it.finanze.sanita.fse2.ms.iniclient.enums.TestTypeEnum;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Arrays;
import java.util.List;

import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.data.mongodb.core.mapping.Field;
Expand All @@ -21,6 +27,7 @@ public class IssuerETY {
public static final String PAZIENTE_CF = "pazienteCf";
public static final String EMAIL_SENT = "isEmailSent";
public static final String READY_TO_SCAN = "readyToScan";
public static final String MANDATORY_TESTS = "mandatoryTests";



Expand Down Expand Up @@ -55,5 +62,8 @@ public class IssuerETY {

@Field(name = EMAIL_SENT)
private boolean emailSent;

@Field(name = MANDATORY_TESTS)
private List<TestTypeEnum> mandatoryTests = Arrays.asList(TestTypeEnum.values());

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import it.finanze.sanita.fse2.ms.iniclient.dto.IssuersDTO;
import it.finanze.sanita.fse2.ms.iniclient.dto.response.IssuerDeleteResponseDTO;
import it.finanze.sanita.fse2.ms.iniclient.dto.response.IssuerResponseDTO;
import it.finanze.sanita.fse2.ms.iniclient.enums.TestTypeEnum;
import it.finanze.sanita.fse2.ms.iniclient.exceptions.base.BadRequestException;
import it.finanze.sanita.fse2.ms.iniclient.exceptions.base.BusinessException;
import it.finanze.sanita.fse2.ms.iniclient.exceptions.base.InputValidationException;
Expand Down Expand Up @@ -61,6 +62,9 @@ public IssuerResponseDTO createIssuer(IssuerCreateRequestDTO issuerDTO) {
entity.setEtichettaRegione(issuerDTO.getEtichettaRegione());
entity.setPazienteCf(issuerDTO.getPazienteCf());
entity.setReadyToScan(issuerDTO.isReadyToScan());
List<TestTypeEnum> mandatoryTests = issuerDTO.getMandatoryTests();
if(mandatoryTests!=null && !mandatoryTests.isEmpty())
entity.setMandatoryTests(mandatoryTests);

IssuerETY asl = null;
if (!StringUtility.isNullOrEmpty(issuerDTO.getNomeDocumentRepository())) {
Expand Down Expand Up @@ -116,6 +120,9 @@ public IssuerResponseDTO updateIssuer(IssuerETY issuerETY, IssuerCreateRequestDT
entity.setPazienteCf(issuerDTO.getPazienteCf());
entity.setReadyToScan(issuerDTO.isReadyToScan());
entity.setEmailSent(issuerETY.isEmailSent());
List<TestTypeEnum> mandatoryTests = issuerDTO.getMandatoryTests();
if(mandatoryTests!=null && !mandatoryTests.isEmpty())
entity.setMandatoryTests(mandatoryTests);

if (issuerDTO.getNomeDocumentRepository() != null && entity.getMiddleware())
throw new BadRequestException("Sono già presenti documenti con asl. Impossibile caricare il middleware");
Expand Down

0 comments on commit 34d89a8

Please sign in to comment.