-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[PPANTT-191] feat: Create mdb gps service #1
Conversation
…ndency with jakarta and format code
… mapper. Bump spring doc dependency version
…plication properties
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remaining comments which cannot be posted as a review comment to avoid GitHub Rate Limit
google-java-format
[google-java-format] reported by reviewdog 🐶
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/controller/HomeController.java
Lines 20 to 58 in 5b8f7d2
@Value("${server.servlet.context-path}") | |
String basePath; | |
@Value("${info.application.name}") | |
private String name; | |
@Value("${info.application.version}") | |
private String version; | |
@Value("${info.properties.environment}") | |
private String environment; | |
/** | |
* @return redirect to Swagger page documentation | |
*/ | |
@Hidden | |
@GetMapping("") | |
public RedirectView home() { | |
if (!basePath.endsWith("/")) { | |
basePath += "/"; | |
} | |
return new RedirectView(basePath + "swagger-ui.html"); | |
} | |
/** | |
* Return app name, version and environment | |
* | |
* @return the app info | |
*/ | |
@Operation( | |
summary = "health check", | |
description = "Return OK if application is started", | |
security = {@SecurityRequirement(name = "ApiKey")}, | |
tags = {"Home"}) | |
@GetMapping(value = "/info") | |
@ResponseStatus(HttpStatus.OK) | |
public ResponseEntity<AppInfo> healthCheck() { | |
AppInfo info = AppInfo.builder().name(name).version(version).environment(environment).build(); | |
return ResponseEntity.status(HttpStatus.OK).body(info); |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/controller/HomeController.java
Line 60 in 5b8f7d2
} |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/controller/MbdGpsController.java
Line 26 in 5b8f7d2
@RequestMapping(consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/controller/MbdGpsController.java
Line 30 in 5b8f7d2
private final ModelMapper modelMapper; |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/controller/MbdGpsController.java
Lines 32 to 35 in 5b8f7d2
@Autowired | |
public MbdGpsController(ModelMapper modelMapper) { | |
this.modelMapper = modelMapper; | |
} |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/controller/MbdGpsController.java
Lines 37 to 63 in 5b8f7d2
/** | |
* Map MBD service specific data into payment option model | |
* | |
* @param mbdPaymentOptionRequest MBD data | |
* @return the mapped model | |
*/ | |
@PostMapping("/mbd/paymentOption") | |
@ResponseStatus(HttpStatus.CREATED) | |
@ApiResponses(value = { | |
@ApiResponse(responseCode = "200", description = "OK", | |
content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, | |
schema = @Schema(implementation = MbdPaymentOptionResponse.class))), | |
@ApiResponse(responseCode = "400", description = "Bad Request", | |
content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, schema = @Schema(implementation = ProblemJson.class))), | |
@ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content(schema = @Schema())), | |
@ApiResponse(responseCode = "404", description = "Not found", content = @Content(schema = @Schema(implementation = ProblemJson.class))), | |
@ApiResponse(responseCode = "429", description = "Too many requests", content = @Content(schema = @Schema())), | |
@ApiResponse(responseCode = "500", description = "Service unavailable", | |
content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, schema = @Schema(implementation = ProblemJson.class))) | |
}) | |
@Operation(summary = "Create MBD payment option", security = {@SecurityRequirement(name = "ApiKey")}) | |
public @Valid MbdPaymentOptionResponse createMdbPaymentOption( | |
@RequestBody @NotNull @Valid MbdPaymentOptionRequest mbdPaymentOptionRequest | |
) { | |
return this.modelMapper.map(mbdPaymentOptionRequest, MbdPaymentOptionResponse.class); | |
} | |
} |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/exception/AppError.java
Lines 8 to 12 in 5b8f7d2
INTERNAL_SERVER_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, "Internal Server Error", "Something was wrong"), | |
BAD_REQUEST(HttpStatus.INTERNAL_SERVER_ERROR, "Bad Request", "%s"), | |
UNAUTHORIZED(HttpStatus.UNAUTHORIZED, "Unauthorized", "Error during authentication"), | |
FORBIDDEN(HttpStatus.FORBIDDEN, "Forbidden", "This method is forbidden"), | |
RESPONSE_NOT_READABLE(HttpStatus.BAD_GATEWAY, "Response Not Readable", "The response body is not readable"), |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/exception/AppError.java
Line 14 in 5b8f7d2
UNKNOWN(null, null, null); |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/exception/AppError.java
Lines 16 to 18 in 5b8f7d2
public final HttpStatus httpStatus; | |
public final String title; | |
public final String details; |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/exception/AppError.java
Lines 20 to 24 in 5b8f7d2
AppError(HttpStatus httpStatus, String title, String details) { | |
this.httpStatus = httpStatus; | |
this.title = title; | |
this.details = details; | |
} |
[google-java-format] reported by reviewdog 🐶
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/exception/AppException.java
Line 4 in 5b8f7d2
import lombok.EqualsAndHashCode; |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/exception/AppException.java
Lines 9 to 10 in 5b8f7d2
import java.util.Formatter; | |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/exception/AppException.java
Line 13 in 5b8f7d2
* <p> See {@link ErrorHandler} |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/exception/AppException.java
Lines 20 to 28 in 5b8f7d2
/** | |
* title returned to the response when this exception occurred | |
*/ | |
String title; | |
/** | |
* http status returned to the response when this exception occurred | |
*/ | |
HttpStatus httpStatus; |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/exception/AppException.java
Lines 30 to 43 in 5b8f7d2
/** | |
* @param httpStatus HTTP status returned to the response | |
* @param title title returned to the response when this exception occurred | |
* @param message the detail message returend to the response | |
* @param cause The cause of this {@link AppException} | |
*/ | |
public AppException( | |
@NotNull HttpStatus httpStatus, @NotNull String title, | |
@NotNull String message, Throwable cause | |
) { | |
super(message, cause); | |
this.title = title; | |
this.httpStatus = httpStatus; | |
} |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/exception/AppException.java
Lines 45 to 54 in 5b8f7d2
/** | |
* @param httpStatus HTTP status returned to the response | |
* @param title title returned to the response when this exception occurred | |
* @param message the detail message returend to the response | |
*/ | |
public AppException(@NotNull HttpStatus httpStatus, @NotNull String title, @NotNull String message) { | |
super(message); | |
this.title = title; | |
this.httpStatus = httpStatus; | |
} |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/exception/AppException.java
Line 56 in 5b8f7d2
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/exception/AppException.java
Lines 57 to 67 in 5b8f7d2
/** | |
* @param appError Response template returned to the response | |
* @param args {@link Formatter} replaces the placeholders in "details" string of | |
* {@link AppError} with the arguments. If there are more arguments than format | |
* specifiers, the extra arguments are ignored. | |
*/ | |
public AppException(@NotNull AppError appError, Object... args) { | |
super(formatDetails(appError, args)); | |
this.httpStatus = appError.httpStatus; | |
this.title = appError.title; | |
} |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/exception/AppException.java
Lines 69 to 80 in 5b8f7d2
/** | |
* @param appError Response template returned to the response | |
* @param cause The cause of this {@link AppException} | |
* @param args Arguments for the details of {@link AppError} replaced by the | |
* {@link Formatter}. If there are more arguments than format specifiers, the | |
* extra arguments are ignored. | |
*/ | |
public AppException(@NotNull AppError appError, Throwable cause, Object... args) { | |
super(formatDetails(appError, args), cause); | |
this.httpStatus = appError.httpStatus; | |
this.title = appError.title; | |
} |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/exception/AppException.java
Lines 82 to 84 in 5b8f7d2
private static String formatDetails(AppError appError, Object[] args) { | |
return String.format(appError.details, args); | |
} |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/exception/AppException.java
Lines 86 to 89 in 5b8f7d2
@Override | |
public String toString() { | |
return "AppException(" + httpStatus + ", " + title + ")" + super.toString(); | |
} |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/exception/ErrorHandler.java
Line 5 in 5b8f7d2
import lombok.extern.slf4j.Slf4j; |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/exception/ErrorHandler.java
Lines 21 to 26 in 5b8f7d2
import java.util.ArrayList; | |
import java.util.List; | |
/** | |
* All Exceptions are handled by this class | |
*/ |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/exception/ErrorHandler.java
Lines 31 to 54 in 5b8f7d2
/** | |
* Handle if the input request is not a valid JSON | |
* | |
* @param ex {@link HttpMessageNotReadableException} exception raised | |
* @param headers of the response | |
* @param status of the response | |
* @param request from frontend | |
* @return a {@link ProblemJson} as response with the cause and with a 400 as HTTP status | |
*/ | |
@Override | |
public ResponseEntity<Object> handleHttpMessageNotReadable( | |
HttpMessageNotReadableException ex, | |
HttpHeaders headers, | |
HttpStatusCode status, | |
WebRequest request | |
) { | |
log.warn("Input not readable: ", ex); | |
var errorResponse = ProblemJson.builder() | |
.status(HttpStatus.BAD_REQUEST.value()) | |
.title(AppError.BAD_REQUEST.getTitle()) | |
.detail("Invalid input format") | |
.build(); | |
return new ResponseEntity<>(errorResponse, HttpStatus.BAD_REQUEST); | |
} |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/exception/ErrorHandler.java
Lines 56 to 79 in 5b8f7d2
/** | |
* Handle if missing some request parameters in the request | |
* | |
* @param ex {@link MissingServletRequestParameterException} exception raised | |
* @param headers of the response | |
* @param status of the response | |
* @param request from frontend | |
* @return a {@link ProblemJson} as response with the cause and with a 400 as HTTP status | |
*/ | |
@Override | |
public ResponseEntity<Object> handleMissingServletRequestParameter( | |
MissingServletRequestParameterException ex, | |
HttpHeaders headers, | |
HttpStatusCode status, | |
WebRequest request | |
) { | |
log.warn("Missing request parameter: ", ex); | |
var errorResponse = ProblemJson.builder() | |
.status(HttpStatus.BAD_REQUEST.value()) | |
.title(AppError.BAD_REQUEST.getTitle()) | |
.detail(ex.getMessage()) | |
.build(); | |
return new ResponseEntity<>(errorResponse, HttpStatus.BAD_REQUEST); | |
} |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/exception/ErrorHandler.java
Line 81 in 5b8f7d2
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/exception/ErrorHandler.java
Lines 82 to 105 in 5b8f7d2
/** | |
* Customize the response for TypeMismatchException. | |
* | |
* @param ex the exception | |
* @param headers the headers to be written to the response | |
* @param status the selected response status | |
* @param request the current request | |
* @return a {@code ResponseEntity} instance | |
*/ | |
@Override | |
protected ResponseEntity<Object> handleTypeMismatch( | |
TypeMismatchException ex, | |
HttpHeaders headers, | |
HttpStatusCode status, | |
WebRequest request | |
) { | |
log.warn("Type mismatch: ", ex); | |
var errorResponse = ProblemJson.builder() | |
.status(HttpStatus.BAD_REQUEST.value()) | |
.title(AppError.BAD_REQUEST.getTitle()) | |
.detail(String.format("Invalid value %s for property %s", ex.getValue(), | |
((MethodArgumentTypeMismatchException) ex).getName())) | |
.build(); | |
return new ResponseEntity<>(errorResponse, HttpStatus.BAD_REQUEST); |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/exception/ErrorHandler.java
Line 107 in 5b8f7d2
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/exception/ErrorHandler.java
Lines 108 to 136 in 5b8f7d2
/** | |
* Handle if validation constraints are unsatisfied | |
* | |
* @param ex {@link MethodArgumentNotValidException} exception raised | |
* @param headers of the response | |
* @param status of the response | |
* @param request from frontend | |
* @return a {@link ProblemJson} as response with the cause and with a 400 as HTTP status | |
*/ | |
@Override | |
protected ResponseEntity<Object> handleMethodArgumentNotValid( | |
MethodArgumentNotValidException ex, | |
HttpHeaders headers, | |
HttpStatusCode status, | |
WebRequest request | |
) { | |
List<String> details = new ArrayList<>(); | |
for (FieldError error : ex.getBindingResult().getFieldErrors()) { | |
details.add(error.getField() + ": " + error.getDefaultMessage()); | |
} | |
var detailsMessage = String.join(", ", details); | |
log.warn("Input not valid: " + detailsMessage); | |
var errorResponse = ProblemJson.builder() | |
.status(HttpStatus.BAD_REQUEST.value()) | |
.title(AppError.BAD_REQUEST.getTitle()) | |
.detail(detailsMessage) | |
.build(); | |
return new ResponseEntity<>(errorResponse, HttpStatus.BAD_REQUEST); | |
} |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/exception/ErrorHandler.java
Lines 138 to 149 in 5b8f7d2
@ExceptionHandler({ConstraintViolationException.class}) | |
public ResponseEntity<ProblemJson> handleConstraintViolationException( | |
final ConstraintViolationException ex, | |
final WebRequest request | |
) { | |
log.warn("Validation Error raised:", ex); | |
var errorResponse = ProblemJson.builder() | |
.status(HttpStatus.BAD_REQUEST.value()) | |
.title(AppError.BAD_REQUEST.getTitle()) | |
.detail(ex.getMessage()) | |
.build(); | |
return new ResponseEntity<>(errorResponse, HttpStatus.BAD_REQUEST); |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/exception/ErrorHandler.java
Line 151 in 5b8f7d2
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/exception/ErrorHandler.java
Lines 152 to 196 in 5b8f7d2
/** | |
* Handle if a {@link AppException} is raised | |
* | |
* @param ex {@link AppException} exception raised | |
* @param request from frontend | |
* @return a {@link ProblemJson} as response with the cause and with an appropriated HTTP status | |
*/ | |
@ExceptionHandler({AppException.class}) | |
public ResponseEntity<ProblemJson> handleAppException( | |
final AppException ex, | |
final WebRequest request | |
) { | |
if (ex.getCause() != null) { | |
log.warn("App Exception raised: {}\nCause of the App Exception: ", ex.getMessage(), ex.getCause()); | |
} else { | |
log.warn("App Exception raised: ", ex); | |
} | |
var errorResponse = ProblemJson.builder() | |
.status(ex.getHttpStatus().value()) | |
.title(ex.getTitle()) | |
.detail(ex.getMessage()) | |
.build(); | |
return new ResponseEntity<>(errorResponse, ex.getHttpStatus()); | |
} | |
/** | |
* Handle if a {@link Exception} is raised | |
* | |
* @param ex {@link Exception} exception raised | |
* @param request from frontend | |
* @return a {@link ProblemJson} as response with the cause and with 500 as HTTP status | |
*/ | |
@ExceptionHandler({Exception.class}) | |
public ResponseEntity<ProblemJson> handleGenericException( | |
final Exception ex, | |
final WebRequest request | |
) { | |
log.error("Generic Exception raised:", ex); | |
var errorResponse = ProblemJson.builder() | |
.status(HttpStatus.INTERNAL_SERVER_ERROR.value()) | |
.title(AppError.INTERNAL_SERVER_ERROR.getTitle()) | |
.detail(ex.getMessage()) | |
.build(); | |
return new ResponseEntity<>(errorResponse, HttpStatus.INTERNAL_SERVER_ERROR); | |
} |
[google-java-format] reported by reviewdog 🐶
Lines 3 to 4 in 5b8f7d2
import it.gov.pagopa.mbd.gps.service.model.MbdPaymentOptionRequestProperties; | |
import it.gov.pagopa.mbd.gps.service.model.PaymentOption; |
[google-java-format] reported by reviewdog 🐶
Line 6 in 5b8f7d2
import it.gov.pagopa.mbd.gps.service.model.MbdPaymentOptionResponse; |
[google-java-format] reported by reviewdog 🐶
Line 7 in 5b8f7d2
import it.gov.pagopa.mbd.gps.service.model.Stamp; |
[google-java-format] reported by reviewdog 🐶
Line 9 in 5b8f7d2
import org.modelmapper.Converter; |
[google-java-format] reported by reviewdog 🐶
Lines 14 to 17 in 5b8f7d2
import java.time.LocalDateTime; | |
import java.time.temporal.ChronoUnit; | |
import java.util.Collections; | |
[google-java-format] reported by reviewdog 🐶
Line 19 in 5b8f7d2
* Converter class that specify how to convert a {@link MbdPaymentOptionRequest} instance to a {@link MbdPaymentOptionResponse} instance |
[google-java-format] reported by reviewdog 🐶
Line 22 in 5b8f7d2
public class ConvertMbdPaymentOptionRequestToMbdPaymentOptionResponse implements Converter<MbdPaymentOptionRequest, MbdPaymentOptionResponse> { |
[google-java-format] reported by reviewdog 🐶
Lines 24 to 26 in 5b8f7d2
private static final boolean IS_PARTIAL_PAYMENT = false; | |
private static final String ID_TRANSFER = "1"; | |
private static final String STAMP_TYPE = "st"; |
[google-java-format] reported by reviewdog 🐶
Lines 28 to 29 in 5b8f7d2
@Value("${mbd.payment-option.description}") | |
private String description; |
[google-java-format] reported by reviewdog 🐶
Lines 31 to 32 in 5b8f7d2
@Value("${mbd.transfer.remittance-information}") | |
private String remittanceInformation; |
[google-java-format] reported by reviewdog 🐶
Lines 34 to 35 in 5b8f7d2
@Value("${mbd.payment-option.due-date-delta}") | |
private int dueDateDelta; |
[google-java-format] reported by reviewdog 🐶
Lines 37 to 38 in 5b8f7d2
@Value("${mbd.payment-option.due-date-delta-time-unit}") | |
private ChronoUnit dueDateDeltaTimeUnit; |
[google-java-format] reported by reviewdog 🐶
Lines 40 to 41 in 5b8f7d2
@Value("${mbd.payment-option.retention-date-delta}") | |
private int retentionDateDelta; |
[google-java-format] reported by reviewdog 🐶
Lines 43 to 44 in 5b8f7d2
@Value("${mbd.payment-option.retention-date-delta-time-unit}") | |
private ChronoUnit retentionDateDeltaTimeUnit; |
[google-java-format] reported by reviewdog 🐶
Lines 46 to 48 in 5b8f7d2
@Override | |
public MbdPaymentOptionResponse convert(MappingContext<MbdPaymentOptionRequest, MbdPaymentOptionResponse> context) { | |
MbdPaymentOptionRequestProperties model = context.getSource().getProperties(); |
[google-java-format] reported by reviewdog 🐶
Lines 50 to 60 in 5b8f7d2
Transfer transfer = Transfer.builder() | |
.amount(model.getAmount()) | |
.idTransfer(ID_TRANSFER) | |
.organizationFiscalCode(model.getFiscalCode()) | |
.remittanceInformation(remittanceInformation) | |
.stamp(Stamp.builder() | |
.hashDocument(model.getDocumentHash()) | |
.provincialResidence(model.getProvincialResidence()) | |
.stampType(STAMP_TYPE) | |
.build()) | |
.build(); |
[google-java-format] reported by reviewdog 🐶
Lines 62 to 71 in 5b8f7d2
PaymentOption paymentOption = PaymentOption.builder() | |
.firstName(model.getFirstName()) | |
.lastName(model.getLastName()) | |
.amount(model.getAmount()) | |
.description(description) | |
.dueDate(LocalDateTime.now().plus(dueDateDelta, dueDateDeltaTimeUnit)) | |
.retentionDate(LocalDateTime.now().plus(retentionDateDelta, retentionDateDeltaTimeUnit)) | |
.isPartialPayment(IS_PARTIAL_PAYMENT) | |
.transfer(Collections.singletonList(transfer)) | |
.build(); |
[google-java-format] reported by reviewdog 🐶
Lines 73 to 77 in 5b8f7d2
return MbdPaymentOptionResponse.builder() | |
.paymentOption(Collections.singletonList(paymentOption)) | |
.build(); | |
} | |
} |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/model/AppCorsConfiguration.java
Lines 21 to 22 in 5b8f7d2
private String[] origins; | |
private String[] methods; |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/model/AppInfo.java
Lines 19 to 21 in 5b8f7d2
private String name; | |
private String version; | |
private String environment; |
[google-java-format] reported by reviewdog 🐶
Lines 10 to 12 in 5b8f7d2
/** | |
* Model class that holds MBD GPS request | |
*/ |
[google-java-format] reported by reviewdog 🐶
Lines 19 to 22 in 5b8f7d2
@Valid | |
@Schema(description = "MBD payment option's properties", requiredMode = Schema.RequiredMode.REQUIRED) | |
private MbdPaymentOptionRequestProperties properties; | |
} |
[google-java-format] reported by reviewdog 🐶
Lines 12 to 14 in 5b8f7d2
/** | |
* Model class that holds MBD service specific data | |
*/ |
[google-java-format] reported by reviewdog 🐶
Lines 21 to 23 in 5b8f7d2
@NotNull(message = "amount is required") | |
@Schema(description = "MBD amount", requiredMode = Schema.RequiredMode.REQUIRED) | |
private Long amount; |
[google-java-format] reported by reviewdog 🐶
Lines 25 to 27 in 5b8f7d2
@NotBlank | |
@Schema(description = "Debtor's name", requiredMode = Schema.RequiredMode.REQUIRED) | |
private String firstName; |
[google-java-format] reported by reviewdog 🐶
Lines 29 to 31 in 5b8f7d2
@NotBlank | |
@Schema(description = "Debtor's last name", requiredMode = Schema.RequiredMode.REQUIRED) | |
private String lastName; |
[google-java-format] reported by reviewdog 🐶
Lines 33 to 35 in 5b8f7d2
@NotBlank | |
@Schema(description = "Debtor's fiscal code", requiredMode = Schema.RequiredMode.REQUIRED) | |
private String fiscalCode; |
[google-java-format] reported by reviewdog 🐶
Lines 37 to 39 in 5b8f7d2
@NotBlank | |
@Schema(description = "Debtor's residence province", requiredMode = Schema.RequiredMode.REQUIRED) | |
private String provincialResidence; |
[google-java-format] reported by reviewdog 🐶
Lines 41 to 45 in 5b8f7d2
@NotBlank | |
@Size(min = 44, max = 44) | |
@Schema(description = "MBD document's hash", requiredMode = Schema.RequiredMode.REQUIRED) | |
private String documentHash; | |
} |
[google-java-format] reported by reviewdog 🐶
Line 5 in 5b8f7d2
import lombok.AllArgsConstructor; |
[google-java-format] reported by reviewdog 🐶
Lines 10 to 14 in 5b8f7d2
import java.util.List; | |
/** | |
* Model class that holds MBD GPS response | |
*/ |
[google-java-format] reported by reviewdog 🐶
Lines 21 to 24 in 5b8f7d2
@Valid | |
@Schema(description = "MBD payment option", requiredMode = Schema.RequiredMode.REQUIRED) | |
private List<@Valid PaymentOption> paymentOption; | |
} |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/model/PaymentOption.java
Line 8 in 5b8f7d2
import lombok.AllArgsConstructor; |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/model/PaymentOption.java
Lines 13 to 18 in 5b8f7d2
import java.time.LocalDateTime; | |
import java.util.List; | |
/** | |
* Model class that holds MBD payment option data | |
*/ |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/model/PaymentOption.java
Lines 25 to 56 in 5b8f7d2
@NotBlank | |
@Schema(description = "Debtor's name", requiredMode = Schema.RequiredMode.REQUIRED) | |
private String firstName; | |
@NotBlank | |
@Schema(description = "Debtor's last name", requiredMode = Schema.RequiredMode.REQUIRED) | |
private String lastName; | |
@NotNull(message = "amount is required") | |
@Schema(description = "Payment option's amount", requiredMode = Schema.RequiredMode.REQUIRED) | |
private Long amount; | |
@NotBlank(message = "payment option description is required") | |
@Size(max = 140) // compliant to paForNode.xsd | |
@Schema(description = "Payment option's description", requiredMode = Schema.RequiredMode.REQUIRED) | |
private String description; | |
@NotNull(message = "is partial payment is required") | |
@Schema(description = "Payment option's is partial payment flag", requiredMode = Schema.RequiredMode.REQUIRED) | |
private Boolean isPartialPayment; | |
@NotNull(message = "due date is required") | |
@Schema(description = "Payment option's due date", requiredMode = Schema.RequiredMode.REQUIRED) | |
private LocalDateTime dueDate; | |
@Schema(description = "Payment option's retention date", requiredMode = Schema.RequiredMode.REQUIRED) | |
private LocalDateTime retentionDate; | |
@Valid | |
@Schema(description = "Payment option's transfer list", requiredMode = Schema.RequiredMode.REQUIRED) | |
private List<@Valid Transfer> transfer; | |
} |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/model/ProblemJson.java
Line 17 in 5b8f7d2
* <p> See {@link ErrorHandler} |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/model/ProblemJson.java
Lines 27 to 29 in 5b8f7d2
@JsonProperty("title") | |
@Schema(description = "A short, summary of the problem type. Written in english and readable for engineers (usually not suited for non technical stakeholders and not localized); example: Service Unavailable") | |
private String title; |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/model/ProblemJson.java
Lines 31 to 35 in 5b8f7d2
@JsonProperty("status") | |
@Schema(example = "200", description = "The HTTP status code generated by the origin server for this occurrence of the problem.") | |
@Min(100) | |
@Max(600) | |
private Integer status; |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/model/ProblemJson.java
Lines 37 to 39 in 5b8f7d2
@JsonProperty("detail") | |
@Schema(example = "There was an error processing the request", description = "A human readable explanation specific to this occurrence of the problem.") | |
private String detail; |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/model/Stamp.java
Lines 12 to 14 in 5b8f7d2
/** | |
* Model class that holds MBD stamp data | |
*/ |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/model/Stamp.java
Lines 21 to 27 in 5b8f7d2
@NotBlank | |
@Size(max = 72) | |
@Schema(description = "Document hash type is stBase64Binary72 as described in https://github.com/pagopa/pagopa-api.", requiredMode = Schema.RequiredMode.REQUIRED) | |
// Stamp generally get as input a base64sha256, that is the SHA256 hash of a given string encoded with Base64. | |
// It is not equivalent to base64encode(sha256(“test”)), if sha256() returns a hexadecimal representation. | |
// The result should normally be 44 characters, to be compliant with as-is it was extended to 72 | |
private String hashDocument; |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/model/Stamp.java
Lines 29 to 32 in 5b8f7d2
@NotBlank | |
@Size(min = 2, max = 2) | |
@Schema(description = "The type of the stamp", minLength = 2, maxLength = 2, requiredMode = Schema.RequiredMode.REQUIRED) | |
private String stampType; |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/model/Stamp.java
Lines 34 to 38 in 5b8f7d2
@NotBlank | |
@Pattern(regexp = "[A-Z]{2}") | |
@Schema(description = "The province of residence", example = "RM", pattern = "[A-Z]{2,2}", requiredMode = Schema.RequiredMode.REQUIRED) | |
private String provincialResidence; | |
} |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/model/Transfer.java
Lines 13 to 15 in 5b8f7d2
/** | |
* Model class that holds MBD transfer data | |
*/ |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/model/Transfer.java
Lines 22 to 24 in 5b8f7d2
@NotBlank(message = "id transfer is required") | |
@Schema(description = "Transfer's id", allowableValues = {"1", "2", "3", "4", "5"}, requiredMode = Schema.RequiredMode.REQUIRED) | |
private String idTransfer; |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/model/Transfer.java
Lines 26 to 28 in 5b8f7d2
@NotNull(message = "amount is required") | |
@Schema(description = "Transfer's amount", requiredMode = Schema.RequiredMode.REQUIRED) | |
private Long amount; |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/model/Transfer.java
Lines 30 to 31 in 5b8f7d2
@Schema(description = "Fiscal code related to the organization targeted by this transfer.", example = "00000000000") | |
private String organizationFiscalCode; |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/model/Transfer.java
Lines 33 to 37 in 5b8f7d2
@NotBlank(message = "remittance information is required") | |
@Size(max = 140, message = "remittance information must be compliant to EACT FORMATTING RULES, up to 140 chars") | |
@Schema(description = "Transfer's remittance information", requiredMode = Schema.RequiredMode.REQUIRED) | |
// https://docs.pagopa.it/saci/specifiche-attuative-dei-codici-identificativi-di-versamento-riversamento-e-rendicontazione/operazione-di-trasferimento-fondi | |
private String remittanceInformation; // causale |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/model/Transfer.java
Lines 39 to 42 in 5b8f7d2
@Valid | |
@Schema(description = "Transfer's stamp", requiredMode = Schema.RequiredMode.REQUIRED) | |
private Stamp stamp; | |
} |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/util/Constants.java
Line 8 in 5b8f7d2
public static final String HEADER_REQUEST_ID = "X-Request-Id"; |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/test/java/it/gov/pagopa/mbd/gps/service/ApplicationTest.java
Line 3 in 5b8f7d2
import org.junit.jupiter.api.Test; |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/test/java/it/gov/pagopa/mbd/gps/service/ApplicationTest.java
Lines 6 to 7 in 5b8f7d2
import static org.junit.jupiter.api.Assertions.assertTrue; | |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/test/java/it/gov/pagopa/mbd/gps/service/ApplicationTest.java
Lines 11 to 15 in 5b8f7d2
@Test | |
void contextLoads() { | |
// check only if the context is loaded | |
assertTrue(true); | |
} |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/test/java/it/gov/pagopa/mbd/gps/service/OpenApiGenerationTest.java
Line 3 in 5b8f7d2
import com.fasterxml.jackson.databind.ObjectMapper; |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/test/java/it/gov/pagopa/mbd/gps/service/OpenApiGenerationTest.java
Line 4 in 5b8f7d2
import org.junit.jupiter.api.Test; |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/test/java/it/gov/pagopa/mbd/gps/service/OpenApiGenerationTest.java
Lines 13 to 19 in 5b8f7d2
import java.nio.file.Files; | |
import java.nio.file.Path; | |
import java.nio.file.Paths; | |
import static org.junit.jupiter.api.Assertions.assertFalse; | |
import static org.junit.jupiter.api.Assertions.assertNotNull; | |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/test/java/it/gov/pagopa/mbd/gps/service/OpenApiGenerationTest.java
Lines 24 to 25 in 5b8f7d2
@Autowired | |
ObjectMapper objectMapper; |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/test/java/it/gov/pagopa/mbd/gps/service/OpenApiGenerationTest.java
Lines 27 to 28 in 5b8f7d2
@Autowired | |
private MockMvc mvc; |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/test/java/it/gov/pagopa/mbd/gps/service/OpenApiGenerationTest.java
Lines 30 to 49 in 5b8f7d2
@Test | |
void swaggerSpringPlugin() throws Exception { | |
mvc.perform(MockMvcRequestBuilders.get("/v3/api-docs").accept(MediaType.APPLICATION_JSON)) | |
.andExpect(MockMvcResultMatchers.status().is2xxSuccessful()) | |
.andDo( | |
result -> { | |
assertNotNull(result); | |
assertNotNull(result.getResponse()); | |
final String content = result.getResponse().getContentAsString(); | |
assertFalse(content.isBlank()); | |
assertFalse(content.contains("${"), "Generated swagger contains placeholders"); | |
Object swagger = | |
objectMapper.readValue(result.getResponse().getContentAsString(), Object.class); | |
String formatted = | |
objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(swagger); | |
Path basePath = Paths.get("openapi/"); | |
Files.createDirectories(basePath); | |
Files.write(basePath.resolve("openapi.json"), formatted.getBytes()); | |
}); | |
} |
[google-java-format] reported by reviewdog 🐶
Line 3 in 5b8f7d2
import org.junit.jupiter.api.Test; |
[google-java-format] reported by reviewdog 🐶
Lines 9 to 11 in 5b8f7d2
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; | |
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | |
[google-java-format] reported by reviewdog 🐶
Lines 16 to 17 in 5b8f7d2
@Autowired | |
private MockMvc mvc; |
[google-java-format] reported by reviewdog 🐶
Lines 19 to 23 in 5b8f7d2
@Test | |
void healthCheckTestSuccess() throws Exception { | |
mvc.perform(get("/info")).andExpect(status().isOk()); | |
} | |
} |
[google-java-format] reported by reviewdog 🐶
Line 3 in 5b8f7d2
import com.fasterxml.jackson.databind.ObjectMapper; |
[google-java-format] reported by reviewdog 🐶
Lines 4 to 5 in 5b8f7d2
import it.gov.pagopa.mbd.gps.service.model.MbdPaymentOptionRequestProperties; | |
import it.gov.pagopa.mbd.gps.service.model.PaymentOption; |
[google-java-format] reported by reviewdog 🐶
Line 7 in 5b8f7d2
import it.gov.pagopa.mbd.gps.service.model.MbdPaymentOptionResponse; |
[google-java-format] reported by reviewdog 🐶
Line 8 in 5b8f7d2
import it.gov.pagopa.mbd.gps.service.model.Transfer; |
[google-java-format] reported by reviewdog 🐶
Lines 17 to 23 in 5b8f7d2
import static org.junit.jupiter.api.Assertions.assertEquals; | |
import static org.junit.jupiter.api.Assertions.assertFalse; | |
import static org.junit.jupiter.api.Assertions.assertNotNull; | |
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; | |
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; | |
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | |
[google-java-format] reported by reviewdog 🐶
Lines 28 to 173 in 5b8f7d2
@Autowired | |
private MockMvc mvc; | |
@Autowired | |
private ObjectMapper objectMapper; | |
@Test | |
void createMdbPaymentOptionTestSuccess() throws Exception { | |
MbdPaymentOptionRequest request = buildMdbPaymentOptionRequest(); | |
MvcResult result = mvc.perform(post("/mbd/paymentOption") | |
.content(objectMapper.writeValueAsString(request)) | |
.contentType(MediaType.APPLICATION_JSON)) | |
.andExpect(status().isCreated()) | |
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE)) | |
.andReturn(); | |
String json = result.getResponse().getContentAsString(); | |
assertNotNull(json); | |
MbdPaymentOptionResponse response = objectMapper.readValue(json, MbdPaymentOptionResponse.class); | |
assertNotNull(response); | |
assertNotNull(response.getPaymentOption()); | |
assertEquals(1, response.getPaymentOption().size()); | |
PaymentOption paymentOption = response.getPaymentOption().get(0); | |
assertEquals(request.getProperties().getFirstName(), paymentOption.getFirstName()); | |
assertEquals(request.getProperties().getLastName(), paymentOption.getLastName()); | |
assertEquals(request.getProperties().getAmount(), paymentOption.getAmount()); | |
assertNotNull(paymentOption.getDescription()); | |
assertNotNull(paymentOption.getDueDate()); | |
assertNotNull(paymentOption.getRetentionDate()); | |
assertFalse(paymentOption.getIsPartialPayment()); | |
assertNotNull(paymentOption.getTransfer()); | |
assertEquals(1, paymentOption.getTransfer().size()); | |
Transfer transfer = paymentOption.getTransfer().get(0); | |
assertEquals(request.getProperties().getAmount(), transfer.getAmount()); | |
assertEquals(request.getProperties().getFiscalCode(), transfer.getOrganizationFiscalCode()); | |
assertEquals("1", transfer.getIdTransfer()); | |
assertNotNull(transfer.getRemittanceInformation()); | |
assertNotNull(transfer.getStamp()); | |
assertEquals(request.getProperties().getProvincialResidence(), transfer.getStamp().getProvincialResidence()); | |
assertEquals(request.getProperties().getDocumentHash(), transfer.getStamp().getHashDocument()); | |
assertEquals("st", transfer.getStamp().getStampType()); | |
} | |
@Test | |
void createMdbPaymentOptionTestFailAmountMissing() throws Exception { | |
MbdPaymentOptionRequest request = buildMdbPaymentOptionRequest(); | |
request.getProperties().setAmount(null); | |
mvc.perform(post("/mbd/paymentOption") | |
.content(objectMapper.writeValueAsString(request)) | |
.contentType(MediaType.APPLICATION_JSON)) | |
.andExpect(status().is4xxClientError()); | |
} | |
@Test | |
void createMdbPaymentOptionTestFailFirstNameMissing() throws Exception { | |
MbdPaymentOptionRequest request = buildMdbPaymentOptionRequest(); | |
request.getProperties().setFirstName(null); | |
mvc.perform(post("/mbd/paymentOption") | |
.content(objectMapper.writeValueAsString(request)) | |
.contentType(MediaType.APPLICATION_JSON)) | |
.andExpect(status().is4xxClientError()); | |
} | |
@Test | |
void createMdbPaymentOptionTestFailLastNameMissing() throws Exception { | |
MbdPaymentOptionRequest request = buildMdbPaymentOptionRequest(); | |
request.getProperties().setLastName(null); | |
mvc.perform(post("/mbd/paymentOption") | |
.content(objectMapper.writeValueAsString(request)) | |
.contentType(MediaType.APPLICATION_JSON)) | |
.andExpect(status().is4xxClientError()); | |
} | |
@Test | |
void createMdbPaymentOptionTestFailFiscalCodeMissing() throws Exception { | |
MbdPaymentOptionRequest request = buildMdbPaymentOptionRequest(); | |
request.getProperties().setFiscalCode(null); | |
mvc.perform(post("/mbd/paymentOption") | |
.content(objectMapper.writeValueAsString(request)) | |
.contentType(MediaType.APPLICATION_JSON)) | |
.andExpect(status().is4xxClientError()); | |
} | |
@Test | |
void createMdbPaymentOptionTestFailProvincialResidenceMissing() throws Exception { | |
MbdPaymentOptionRequest request = buildMdbPaymentOptionRequest(); | |
request.getProperties().setProvincialResidence(null); | |
mvc.perform(post("/mbd/paymentOption") | |
.content(objectMapper.writeValueAsString(request)) | |
.contentType(MediaType.APPLICATION_JSON)) | |
.andExpect(status().is4xxClientError()); | |
} | |
@Test | |
void createMdbPaymentOptionTestFailDocumentHashMissing() throws Exception { | |
MbdPaymentOptionRequest request = buildMdbPaymentOptionRequest(); | |
request.getProperties().setDocumentHash(null); | |
mvc.perform(post("/mbd/paymentOption") | |
.content(objectMapper.writeValueAsString(request)) | |
.contentType(MediaType.APPLICATION_JSON)) | |
.andExpect(status().is4xxClientError()); | |
} | |
@Test | |
void createMdbPaymentOptionTestFailDocumentHashWrongSize() throws Exception { | |
MbdPaymentOptionRequest request = buildMdbPaymentOptionRequest(); | |
request.getProperties().setDocumentHash("asdfsdf"); | |
mvc.perform(post("/mbd/paymentOption") | |
.content(objectMapper.writeValueAsString(request)) | |
.contentType(MediaType.APPLICATION_JSON)) | |
.andExpect(status().is4xxClientError()); | |
} | |
private MbdPaymentOptionRequest buildMdbPaymentOptionRequest() { | |
return MbdPaymentOptionRequest.builder() | |
.properties(MbdPaymentOptionRequestProperties.builder() | |
.amount(16L) | |
.firstName("Mario") | |
.lastName("Rossi") | |
.fiscalCode("0000000000000000") | |
.provincialResidence("AS") | |
.documentHash("1trA5qyjSZNwiwtGG46dyjRpL16TFgGCFvnfFzQrFHbB") | |
.build()) | |
.build(); | |
} | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remaining comments which cannot be posted as a review comment to avoid GitHub Rate Limit
google-java-format
[google-java-format] reported by reviewdog 🐶
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/controller/HomeController.java
Lines 20 to 58 in 5b8f7d2
@Value("${server.servlet.context-path}") | |
String basePath; | |
@Value("${info.application.name}") | |
private String name; | |
@Value("${info.application.version}") | |
private String version; | |
@Value("${info.properties.environment}") | |
private String environment; | |
/** | |
* @return redirect to Swagger page documentation | |
*/ | |
@Hidden | |
@GetMapping("") | |
public RedirectView home() { | |
if (!basePath.endsWith("/")) { | |
basePath += "/"; | |
} | |
return new RedirectView(basePath + "swagger-ui.html"); | |
} | |
/** | |
* Return app name, version and environment | |
* | |
* @return the app info | |
*/ | |
@Operation( | |
summary = "health check", | |
description = "Return OK if application is started", | |
security = {@SecurityRequirement(name = "ApiKey")}, | |
tags = {"Home"}) | |
@GetMapping(value = "/info") | |
@ResponseStatus(HttpStatus.OK) | |
public ResponseEntity<AppInfo> healthCheck() { | |
AppInfo info = AppInfo.builder().name(name).version(version).environment(environment).build(); | |
return ResponseEntity.status(HttpStatus.OK).body(info); |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/controller/HomeController.java
Line 60 in 5b8f7d2
} |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/controller/MbdGpsController.java
Line 26 in 5b8f7d2
@RequestMapping(consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/controller/MbdGpsController.java
Line 30 in 5b8f7d2
private final ModelMapper modelMapper; |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/controller/MbdGpsController.java
Lines 32 to 35 in 5b8f7d2
@Autowired | |
public MbdGpsController(ModelMapper modelMapper) { | |
this.modelMapper = modelMapper; | |
} |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/controller/MbdGpsController.java
Lines 37 to 63 in 5b8f7d2
/** | |
* Map MBD service specific data into payment option model | |
* | |
* @param mbdPaymentOptionRequest MBD data | |
* @return the mapped model | |
*/ | |
@PostMapping("/mbd/paymentOption") | |
@ResponseStatus(HttpStatus.CREATED) | |
@ApiResponses(value = { | |
@ApiResponse(responseCode = "200", description = "OK", | |
content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, | |
schema = @Schema(implementation = MbdPaymentOptionResponse.class))), | |
@ApiResponse(responseCode = "400", description = "Bad Request", | |
content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, schema = @Schema(implementation = ProblemJson.class))), | |
@ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content(schema = @Schema())), | |
@ApiResponse(responseCode = "404", description = "Not found", content = @Content(schema = @Schema(implementation = ProblemJson.class))), | |
@ApiResponse(responseCode = "429", description = "Too many requests", content = @Content(schema = @Schema())), | |
@ApiResponse(responseCode = "500", description = "Service unavailable", | |
content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, schema = @Schema(implementation = ProblemJson.class))) | |
}) | |
@Operation(summary = "Create MBD payment option", security = {@SecurityRequirement(name = "ApiKey")}) | |
public @Valid MbdPaymentOptionResponse createMdbPaymentOption( | |
@RequestBody @NotNull @Valid MbdPaymentOptionRequest mbdPaymentOptionRequest | |
) { | |
return this.modelMapper.map(mbdPaymentOptionRequest, MbdPaymentOptionResponse.class); | |
} | |
} |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/exception/AppError.java
Lines 8 to 12 in 5b8f7d2
INTERNAL_SERVER_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, "Internal Server Error", "Something was wrong"), | |
BAD_REQUEST(HttpStatus.INTERNAL_SERVER_ERROR, "Bad Request", "%s"), | |
UNAUTHORIZED(HttpStatus.UNAUTHORIZED, "Unauthorized", "Error during authentication"), | |
FORBIDDEN(HttpStatus.FORBIDDEN, "Forbidden", "This method is forbidden"), | |
RESPONSE_NOT_READABLE(HttpStatus.BAD_GATEWAY, "Response Not Readable", "The response body is not readable"), |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/exception/AppError.java
Line 14 in 5b8f7d2
UNKNOWN(null, null, null); |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/exception/AppError.java
Lines 16 to 18 in 5b8f7d2
public final HttpStatus httpStatus; | |
public final String title; | |
public final String details; |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/exception/AppError.java
Lines 20 to 24 in 5b8f7d2
AppError(HttpStatus httpStatus, String title, String details) { | |
this.httpStatus = httpStatus; | |
this.title = title; | |
this.details = details; | |
} |
[google-java-format] reported by reviewdog 🐶
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/exception/AppException.java
Line 4 in 5b8f7d2
import lombok.EqualsAndHashCode; |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/exception/AppException.java
Lines 9 to 10 in 5b8f7d2
import java.util.Formatter; | |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/exception/AppException.java
Line 13 in 5b8f7d2
* <p> See {@link ErrorHandler} |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/exception/AppException.java
Lines 20 to 28 in 5b8f7d2
/** | |
* title returned to the response when this exception occurred | |
*/ | |
String title; | |
/** | |
* http status returned to the response when this exception occurred | |
*/ | |
HttpStatus httpStatus; |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/exception/AppException.java
Lines 30 to 43 in 5b8f7d2
/** | |
* @param httpStatus HTTP status returned to the response | |
* @param title title returned to the response when this exception occurred | |
* @param message the detail message returend to the response | |
* @param cause The cause of this {@link AppException} | |
*/ | |
public AppException( | |
@NotNull HttpStatus httpStatus, @NotNull String title, | |
@NotNull String message, Throwable cause | |
) { | |
super(message, cause); | |
this.title = title; | |
this.httpStatus = httpStatus; | |
} |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/exception/AppException.java
Lines 45 to 54 in 5b8f7d2
/** | |
* @param httpStatus HTTP status returned to the response | |
* @param title title returned to the response when this exception occurred | |
* @param message the detail message returend to the response | |
*/ | |
public AppException(@NotNull HttpStatus httpStatus, @NotNull String title, @NotNull String message) { | |
super(message); | |
this.title = title; | |
this.httpStatus = httpStatus; | |
} |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/exception/AppException.java
Line 56 in 5b8f7d2
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/exception/AppException.java
Lines 57 to 67 in 5b8f7d2
/** | |
* @param appError Response template returned to the response | |
* @param args {@link Formatter} replaces the placeholders in "details" string of | |
* {@link AppError} with the arguments. If there are more arguments than format | |
* specifiers, the extra arguments are ignored. | |
*/ | |
public AppException(@NotNull AppError appError, Object... args) { | |
super(formatDetails(appError, args)); | |
this.httpStatus = appError.httpStatus; | |
this.title = appError.title; | |
} |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/exception/AppException.java
Lines 69 to 80 in 5b8f7d2
/** | |
* @param appError Response template returned to the response | |
* @param cause The cause of this {@link AppException} | |
* @param args Arguments for the details of {@link AppError} replaced by the | |
* {@link Formatter}. If there are more arguments than format specifiers, the | |
* extra arguments are ignored. | |
*/ | |
public AppException(@NotNull AppError appError, Throwable cause, Object... args) { | |
super(formatDetails(appError, args), cause); | |
this.httpStatus = appError.httpStatus; | |
this.title = appError.title; | |
} |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/exception/AppException.java
Lines 82 to 84 in 5b8f7d2
private static String formatDetails(AppError appError, Object[] args) { | |
return String.format(appError.details, args); | |
} |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/exception/AppException.java
Lines 86 to 89 in 5b8f7d2
@Override | |
public String toString() { | |
return "AppException(" + httpStatus + ", " + title + ")" + super.toString(); | |
} |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/exception/ErrorHandler.java
Line 5 in 5b8f7d2
import lombok.extern.slf4j.Slf4j; |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/exception/ErrorHandler.java
Lines 21 to 26 in 5b8f7d2
import java.util.ArrayList; | |
import java.util.List; | |
/** | |
* All Exceptions are handled by this class | |
*/ |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/exception/ErrorHandler.java
Lines 31 to 54 in 5b8f7d2
/** | |
* Handle if the input request is not a valid JSON | |
* | |
* @param ex {@link HttpMessageNotReadableException} exception raised | |
* @param headers of the response | |
* @param status of the response | |
* @param request from frontend | |
* @return a {@link ProblemJson} as response with the cause and with a 400 as HTTP status | |
*/ | |
@Override | |
public ResponseEntity<Object> handleHttpMessageNotReadable( | |
HttpMessageNotReadableException ex, | |
HttpHeaders headers, | |
HttpStatusCode status, | |
WebRequest request | |
) { | |
log.warn("Input not readable: ", ex); | |
var errorResponse = ProblemJson.builder() | |
.status(HttpStatus.BAD_REQUEST.value()) | |
.title(AppError.BAD_REQUEST.getTitle()) | |
.detail("Invalid input format") | |
.build(); | |
return new ResponseEntity<>(errorResponse, HttpStatus.BAD_REQUEST); | |
} |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/exception/ErrorHandler.java
Lines 56 to 79 in 5b8f7d2
/** | |
* Handle if missing some request parameters in the request | |
* | |
* @param ex {@link MissingServletRequestParameterException} exception raised | |
* @param headers of the response | |
* @param status of the response | |
* @param request from frontend | |
* @return a {@link ProblemJson} as response with the cause and with a 400 as HTTP status | |
*/ | |
@Override | |
public ResponseEntity<Object> handleMissingServletRequestParameter( | |
MissingServletRequestParameterException ex, | |
HttpHeaders headers, | |
HttpStatusCode status, | |
WebRequest request | |
) { | |
log.warn("Missing request parameter: ", ex); | |
var errorResponse = ProblemJson.builder() | |
.status(HttpStatus.BAD_REQUEST.value()) | |
.title(AppError.BAD_REQUEST.getTitle()) | |
.detail(ex.getMessage()) | |
.build(); | |
return new ResponseEntity<>(errorResponse, HttpStatus.BAD_REQUEST); | |
} |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/exception/ErrorHandler.java
Line 81 in 5b8f7d2
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/exception/ErrorHandler.java
Lines 82 to 105 in 5b8f7d2
/** | |
* Customize the response for TypeMismatchException. | |
* | |
* @param ex the exception | |
* @param headers the headers to be written to the response | |
* @param status the selected response status | |
* @param request the current request | |
* @return a {@code ResponseEntity} instance | |
*/ | |
@Override | |
protected ResponseEntity<Object> handleTypeMismatch( | |
TypeMismatchException ex, | |
HttpHeaders headers, | |
HttpStatusCode status, | |
WebRequest request | |
) { | |
log.warn("Type mismatch: ", ex); | |
var errorResponse = ProblemJson.builder() | |
.status(HttpStatus.BAD_REQUEST.value()) | |
.title(AppError.BAD_REQUEST.getTitle()) | |
.detail(String.format("Invalid value %s for property %s", ex.getValue(), | |
((MethodArgumentTypeMismatchException) ex).getName())) | |
.build(); | |
return new ResponseEntity<>(errorResponse, HttpStatus.BAD_REQUEST); |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/exception/ErrorHandler.java
Line 107 in 5b8f7d2
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/exception/ErrorHandler.java
Lines 108 to 136 in 5b8f7d2
/** | |
* Handle if validation constraints are unsatisfied | |
* | |
* @param ex {@link MethodArgumentNotValidException} exception raised | |
* @param headers of the response | |
* @param status of the response | |
* @param request from frontend | |
* @return a {@link ProblemJson} as response with the cause and with a 400 as HTTP status | |
*/ | |
@Override | |
protected ResponseEntity<Object> handleMethodArgumentNotValid( | |
MethodArgumentNotValidException ex, | |
HttpHeaders headers, | |
HttpStatusCode status, | |
WebRequest request | |
) { | |
List<String> details = new ArrayList<>(); | |
for (FieldError error : ex.getBindingResult().getFieldErrors()) { | |
details.add(error.getField() + ": " + error.getDefaultMessage()); | |
} | |
var detailsMessage = String.join(", ", details); | |
log.warn("Input not valid: " + detailsMessage); | |
var errorResponse = ProblemJson.builder() | |
.status(HttpStatus.BAD_REQUEST.value()) | |
.title(AppError.BAD_REQUEST.getTitle()) | |
.detail(detailsMessage) | |
.build(); | |
return new ResponseEntity<>(errorResponse, HttpStatus.BAD_REQUEST); | |
} |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/exception/ErrorHandler.java
Lines 138 to 149 in 5b8f7d2
@ExceptionHandler({ConstraintViolationException.class}) | |
public ResponseEntity<ProblemJson> handleConstraintViolationException( | |
final ConstraintViolationException ex, | |
final WebRequest request | |
) { | |
log.warn("Validation Error raised:", ex); | |
var errorResponse = ProblemJson.builder() | |
.status(HttpStatus.BAD_REQUEST.value()) | |
.title(AppError.BAD_REQUEST.getTitle()) | |
.detail(ex.getMessage()) | |
.build(); | |
return new ResponseEntity<>(errorResponse, HttpStatus.BAD_REQUEST); |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/exception/ErrorHandler.java
Line 151 in 5b8f7d2
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/exception/ErrorHandler.java
Lines 152 to 196 in 5b8f7d2
/** | |
* Handle if a {@link AppException} is raised | |
* | |
* @param ex {@link AppException} exception raised | |
* @param request from frontend | |
* @return a {@link ProblemJson} as response with the cause and with an appropriated HTTP status | |
*/ | |
@ExceptionHandler({AppException.class}) | |
public ResponseEntity<ProblemJson> handleAppException( | |
final AppException ex, | |
final WebRequest request | |
) { | |
if (ex.getCause() != null) { | |
log.warn("App Exception raised: {}\nCause of the App Exception: ", ex.getMessage(), ex.getCause()); | |
} else { | |
log.warn("App Exception raised: ", ex); | |
} | |
var errorResponse = ProblemJson.builder() | |
.status(ex.getHttpStatus().value()) | |
.title(ex.getTitle()) | |
.detail(ex.getMessage()) | |
.build(); | |
return new ResponseEntity<>(errorResponse, ex.getHttpStatus()); | |
} | |
/** | |
* Handle if a {@link Exception} is raised | |
* | |
* @param ex {@link Exception} exception raised | |
* @param request from frontend | |
* @return a {@link ProblemJson} as response with the cause and with 500 as HTTP status | |
*/ | |
@ExceptionHandler({Exception.class}) | |
public ResponseEntity<ProblemJson> handleGenericException( | |
final Exception ex, | |
final WebRequest request | |
) { | |
log.error("Generic Exception raised:", ex); | |
var errorResponse = ProblemJson.builder() | |
.status(HttpStatus.INTERNAL_SERVER_ERROR.value()) | |
.title(AppError.INTERNAL_SERVER_ERROR.getTitle()) | |
.detail(ex.getMessage()) | |
.build(); | |
return new ResponseEntity<>(errorResponse, HttpStatus.INTERNAL_SERVER_ERROR); | |
} |
[google-java-format] reported by reviewdog 🐶
Lines 3 to 4 in 5b8f7d2
import it.gov.pagopa.mbd.gps.service.model.MbdPaymentOptionRequestProperties; | |
import it.gov.pagopa.mbd.gps.service.model.PaymentOption; |
[google-java-format] reported by reviewdog 🐶
Line 6 in 5b8f7d2
import it.gov.pagopa.mbd.gps.service.model.MbdPaymentOptionResponse; |
[google-java-format] reported by reviewdog 🐶
Line 7 in 5b8f7d2
import it.gov.pagopa.mbd.gps.service.model.Stamp; |
[google-java-format] reported by reviewdog 🐶
Line 9 in 5b8f7d2
import org.modelmapper.Converter; |
[google-java-format] reported by reviewdog 🐶
Lines 14 to 17 in 5b8f7d2
import java.time.LocalDateTime; | |
import java.time.temporal.ChronoUnit; | |
import java.util.Collections; | |
[google-java-format] reported by reviewdog 🐶
Line 19 in 5b8f7d2
* Converter class that specify how to convert a {@link MbdPaymentOptionRequest} instance to a {@link MbdPaymentOptionResponse} instance |
[google-java-format] reported by reviewdog 🐶
Line 22 in 5b8f7d2
public class ConvertMbdPaymentOptionRequestToMbdPaymentOptionResponse implements Converter<MbdPaymentOptionRequest, MbdPaymentOptionResponse> { |
[google-java-format] reported by reviewdog 🐶
Lines 24 to 26 in 5b8f7d2
private static final boolean IS_PARTIAL_PAYMENT = false; | |
private static final String ID_TRANSFER = "1"; | |
private static final String STAMP_TYPE = "st"; |
[google-java-format] reported by reviewdog 🐶
Lines 28 to 29 in 5b8f7d2
@Value("${mbd.payment-option.description}") | |
private String description; |
[google-java-format] reported by reviewdog 🐶
Lines 31 to 32 in 5b8f7d2
@Value("${mbd.transfer.remittance-information}") | |
private String remittanceInformation; |
[google-java-format] reported by reviewdog 🐶
Lines 34 to 35 in 5b8f7d2
@Value("${mbd.payment-option.due-date-delta}") | |
private int dueDateDelta; |
[google-java-format] reported by reviewdog 🐶
Lines 37 to 38 in 5b8f7d2
@Value("${mbd.payment-option.due-date-delta-time-unit}") | |
private ChronoUnit dueDateDeltaTimeUnit; |
[google-java-format] reported by reviewdog 🐶
Lines 40 to 41 in 5b8f7d2
@Value("${mbd.payment-option.retention-date-delta}") | |
private int retentionDateDelta; |
[google-java-format] reported by reviewdog 🐶
Lines 43 to 44 in 5b8f7d2
@Value("${mbd.payment-option.retention-date-delta-time-unit}") | |
private ChronoUnit retentionDateDeltaTimeUnit; |
[google-java-format] reported by reviewdog 🐶
Lines 46 to 48 in 5b8f7d2
@Override | |
public MbdPaymentOptionResponse convert(MappingContext<MbdPaymentOptionRequest, MbdPaymentOptionResponse> context) { | |
MbdPaymentOptionRequestProperties model = context.getSource().getProperties(); |
[google-java-format] reported by reviewdog 🐶
Lines 50 to 60 in 5b8f7d2
Transfer transfer = Transfer.builder() | |
.amount(model.getAmount()) | |
.idTransfer(ID_TRANSFER) | |
.organizationFiscalCode(model.getFiscalCode()) | |
.remittanceInformation(remittanceInformation) | |
.stamp(Stamp.builder() | |
.hashDocument(model.getDocumentHash()) | |
.provincialResidence(model.getProvincialResidence()) | |
.stampType(STAMP_TYPE) | |
.build()) | |
.build(); |
[google-java-format] reported by reviewdog 🐶
Lines 62 to 71 in 5b8f7d2
PaymentOption paymentOption = PaymentOption.builder() | |
.firstName(model.getFirstName()) | |
.lastName(model.getLastName()) | |
.amount(model.getAmount()) | |
.description(description) | |
.dueDate(LocalDateTime.now().plus(dueDateDelta, dueDateDeltaTimeUnit)) | |
.retentionDate(LocalDateTime.now().plus(retentionDateDelta, retentionDateDeltaTimeUnit)) | |
.isPartialPayment(IS_PARTIAL_PAYMENT) | |
.transfer(Collections.singletonList(transfer)) | |
.build(); |
[google-java-format] reported by reviewdog 🐶
Lines 73 to 77 in 5b8f7d2
return MbdPaymentOptionResponse.builder() | |
.paymentOption(Collections.singletonList(paymentOption)) | |
.build(); | |
} | |
} |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/model/AppCorsConfiguration.java
Lines 21 to 22 in 5b8f7d2
private String[] origins; | |
private String[] methods; |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/model/AppInfo.java
Lines 19 to 21 in 5b8f7d2
private String name; | |
private String version; | |
private String environment; |
[google-java-format] reported by reviewdog 🐶
Lines 10 to 12 in 5b8f7d2
/** | |
* Model class that holds MBD GPS request | |
*/ |
[google-java-format] reported by reviewdog 🐶
Lines 19 to 22 in 5b8f7d2
@Valid | |
@Schema(description = "MBD payment option's properties", requiredMode = Schema.RequiredMode.REQUIRED) | |
private MbdPaymentOptionRequestProperties properties; | |
} |
[google-java-format] reported by reviewdog 🐶
Lines 12 to 14 in 5b8f7d2
/** | |
* Model class that holds MBD service specific data | |
*/ |
[google-java-format] reported by reviewdog 🐶
Lines 21 to 23 in 5b8f7d2
@NotNull(message = "amount is required") | |
@Schema(description = "MBD amount", requiredMode = Schema.RequiredMode.REQUIRED) | |
private Long amount; |
[google-java-format] reported by reviewdog 🐶
Lines 25 to 27 in 5b8f7d2
@NotBlank | |
@Schema(description = "Debtor's name", requiredMode = Schema.RequiredMode.REQUIRED) | |
private String firstName; |
[google-java-format] reported by reviewdog 🐶
Lines 29 to 31 in 5b8f7d2
@NotBlank | |
@Schema(description = "Debtor's last name", requiredMode = Schema.RequiredMode.REQUIRED) | |
private String lastName; |
[google-java-format] reported by reviewdog 🐶
Lines 33 to 35 in 5b8f7d2
@NotBlank | |
@Schema(description = "Debtor's fiscal code", requiredMode = Schema.RequiredMode.REQUIRED) | |
private String fiscalCode; |
[google-java-format] reported by reviewdog 🐶
Lines 37 to 39 in 5b8f7d2
@NotBlank | |
@Schema(description = "Debtor's residence province", requiredMode = Schema.RequiredMode.REQUIRED) | |
private String provincialResidence; |
[google-java-format] reported by reviewdog 🐶
Lines 41 to 45 in 5b8f7d2
@NotBlank | |
@Size(min = 44, max = 44) | |
@Schema(description = "MBD document's hash", requiredMode = Schema.RequiredMode.REQUIRED) | |
private String documentHash; | |
} |
[google-java-format] reported by reviewdog 🐶
Line 5 in 5b8f7d2
import lombok.AllArgsConstructor; |
[google-java-format] reported by reviewdog 🐶
Lines 10 to 14 in 5b8f7d2
import java.util.List; | |
/** | |
* Model class that holds MBD GPS response | |
*/ |
[google-java-format] reported by reviewdog 🐶
Lines 21 to 24 in 5b8f7d2
@Valid | |
@Schema(description = "MBD payment option", requiredMode = Schema.RequiredMode.REQUIRED) | |
private List<@Valid PaymentOption> paymentOption; | |
} |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/model/PaymentOption.java
Line 8 in 5b8f7d2
import lombok.AllArgsConstructor; |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/model/PaymentOption.java
Lines 13 to 18 in 5b8f7d2
import java.time.LocalDateTime; | |
import java.util.List; | |
/** | |
* Model class that holds MBD payment option data | |
*/ |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/model/PaymentOption.java
Lines 25 to 56 in 5b8f7d2
@NotBlank | |
@Schema(description = "Debtor's name", requiredMode = Schema.RequiredMode.REQUIRED) | |
private String firstName; | |
@NotBlank | |
@Schema(description = "Debtor's last name", requiredMode = Schema.RequiredMode.REQUIRED) | |
private String lastName; | |
@NotNull(message = "amount is required") | |
@Schema(description = "Payment option's amount", requiredMode = Schema.RequiredMode.REQUIRED) | |
private Long amount; | |
@NotBlank(message = "payment option description is required") | |
@Size(max = 140) // compliant to paForNode.xsd | |
@Schema(description = "Payment option's description", requiredMode = Schema.RequiredMode.REQUIRED) | |
private String description; | |
@NotNull(message = "is partial payment is required") | |
@Schema(description = "Payment option's is partial payment flag", requiredMode = Schema.RequiredMode.REQUIRED) | |
private Boolean isPartialPayment; | |
@NotNull(message = "due date is required") | |
@Schema(description = "Payment option's due date", requiredMode = Schema.RequiredMode.REQUIRED) | |
private LocalDateTime dueDate; | |
@Schema(description = "Payment option's retention date", requiredMode = Schema.RequiredMode.REQUIRED) | |
private LocalDateTime retentionDate; | |
@Valid | |
@Schema(description = "Payment option's transfer list", requiredMode = Schema.RequiredMode.REQUIRED) | |
private List<@Valid Transfer> transfer; | |
} |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/model/ProblemJson.java
Line 17 in 5b8f7d2
* <p> See {@link ErrorHandler} |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/model/ProblemJson.java
Lines 27 to 29 in 5b8f7d2
@JsonProperty("title") | |
@Schema(description = "A short, summary of the problem type. Written in english and readable for engineers (usually not suited for non technical stakeholders and not localized); example: Service Unavailable") | |
private String title; |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/model/ProblemJson.java
Lines 31 to 35 in 5b8f7d2
@JsonProperty("status") | |
@Schema(example = "200", description = "The HTTP status code generated by the origin server for this occurrence of the problem.") | |
@Min(100) | |
@Max(600) | |
private Integer status; |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/model/ProblemJson.java
Lines 37 to 39 in 5b8f7d2
@JsonProperty("detail") | |
@Schema(example = "There was an error processing the request", description = "A human readable explanation specific to this occurrence of the problem.") | |
private String detail; |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/model/Stamp.java
Lines 12 to 14 in 5b8f7d2
/** | |
* Model class that holds MBD stamp data | |
*/ |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/model/Stamp.java
Lines 21 to 27 in 5b8f7d2
@NotBlank | |
@Size(max = 72) | |
@Schema(description = "Document hash type is stBase64Binary72 as described in https://github.com/pagopa/pagopa-api.", requiredMode = Schema.RequiredMode.REQUIRED) | |
// Stamp generally get as input a base64sha256, that is the SHA256 hash of a given string encoded with Base64. | |
// It is not equivalent to base64encode(sha256(“test”)), if sha256() returns a hexadecimal representation. | |
// The result should normally be 44 characters, to be compliant with as-is it was extended to 72 | |
private String hashDocument; |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/model/Stamp.java
Lines 29 to 32 in 5b8f7d2
@NotBlank | |
@Size(min = 2, max = 2) | |
@Schema(description = "The type of the stamp", minLength = 2, maxLength = 2, requiredMode = Schema.RequiredMode.REQUIRED) | |
private String stampType; |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/model/Stamp.java
Lines 34 to 38 in 5b8f7d2
@NotBlank | |
@Pattern(regexp = "[A-Z]{2}") | |
@Schema(description = "The province of residence", example = "RM", pattern = "[A-Z]{2,2}", requiredMode = Schema.RequiredMode.REQUIRED) | |
private String provincialResidence; | |
} |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/model/Transfer.java
Lines 13 to 15 in 5b8f7d2
/** | |
* Model class that holds MBD transfer data | |
*/ |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/model/Transfer.java
Lines 22 to 24 in 5b8f7d2
@NotBlank(message = "id transfer is required") | |
@Schema(description = "Transfer's id", allowableValues = {"1", "2", "3", "4", "5"}, requiredMode = Schema.RequiredMode.REQUIRED) | |
private String idTransfer; |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/model/Transfer.java
Lines 26 to 28 in 5b8f7d2
@NotNull(message = "amount is required") | |
@Schema(description = "Transfer's amount", requiredMode = Schema.RequiredMode.REQUIRED) | |
private Long amount; |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/model/Transfer.java
Lines 30 to 31 in 5b8f7d2
@Schema(description = "Fiscal code related to the organization targeted by this transfer.", example = "00000000000") | |
private String organizationFiscalCode; |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/model/Transfer.java
Lines 33 to 37 in 5b8f7d2
@NotBlank(message = "remittance information is required") | |
@Size(max = 140, message = "remittance information must be compliant to EACT FORMATTING RULES, up to 140 chars") | |
@Schema(description = "Transfer's remittance information", requiredMode = Schema.RequiredMode.REQUIRED) | |
// https://docs.pagopa.it/saci/specifiche-attuative-dei-codici-identificativi-di-versamento-riversamento-e-rendicontazione/operazione-di-trasferimento-fondi | |
private String remittanceInformation; // causale |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/model/Transfer.java
Lines 39 to 42 in 5b8f7d2
@Valid | |
@Schema(description = "Transfer's stamp", requiredMode = Schema.RequiredMode.REQUIRED) | |
private Stamp stamp; | |
} |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/util/Constants.java
Line 8 in 5b8f7d2
public static final String HEADER_REQUEST_ID = "X-Request-Id"; |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/test/java/it/gov/pagopa/mbd/gps/service/ApplicationTest.java
Line 3 in 5b8f7d2
import org.junit.jupiter.api.Test; |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/test/java/it/gov/pagopa/mbd/gps/service/ApplicationTest.java
Lines 6 to 7 in 5b8f7d2
import static org.junit.jupiter.api.Assertions.assertTrue; | |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/test/java/it/gov/pagopa/mbd/gps/service/ApplicationTest.java
Lines 11 to 15 in 5b8f7d2
@Test | |
void contextLoads() { | |
// check only if the context is loaded | |
assertTrue(true); | |
} |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/test/java/it/gov/pagopa/mbd/gps/service/OpenApiGenerationTest.java
Line 3 in 5b8f7d2
import com.fasterxml.jackson.databind.ObjectMapper; |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/test/java/it/gov/pagopa/mbd/gps/service/OpenApiGenerationTest.java
Line 4 in 5b8f7d2
import org.junit.jupiter.api.Test; |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/test/java/it/gov/pagopa/mbd/gps/service/OpenApiGenerationTest.java
Lines 13 to 19 in 5b8f7d2
import java.nio.file.Files; | |
import java.nio.file.Path; | |
import java.nio.file.Paths; | |
import static org.junit.jupiter.api.Assertions.assertFalse; | |
import static org.junit.jupiter.api.Assertions.assertNotNull; | |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/test/java/it/gov/pagopa/mbd/gps/service/OpenApiGenerationTest.java
Lines 24 to 25 in 5b8f7d2
@Autowired | |
ObjectMapper objectMapper; |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/test/java/it/gov/pagopa/mbd/gps/service/OpenApiGenerationTest.java
Lines 27 to 28 in 5b8f7d2
@Autowired | |
private MockMvc mvc; |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/test/java/it/gov/pagopa/mbd/gps/service/OpenApiGenerationTest.java
Lines 30 to 49 in 5b8f7d2
@Test | |
void swaggerSpringPlugin() throws Exception { | |
mvc.perform(MockMvcRequestBuilders.get("/v3/api-docs").accept(MediaType.APPLICATION_JSON)) | |
.andExpect(MockMvcResultMatchers.status().is2xxSuccessful()) | |
.andDo( | |
result -> { | |
assertNotNull(result); | |
assertNotNull(result.getResponse()); | |
final String content = result.getResponse().getContentAsString(); | |
assertFalse(content.isBlank()); | |
assertFalse(content.contains("${"), "Generated swagger contains placeholders"); | |
Object swagger = | |
objectMapper.readValue(result.getResponse().getContentAsString(), Object.class); | |
String formatted = | |
objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(swagger); | |
Path basePath = Paths.get("openapi/"); | |
Files.createDirectories(basePath); | |
Files.write(basePath.resolve("openapi.json"), formatted.getBytes()); | |
}); | |
} |
[google-java-format] reported by reviewdog 🐶
Line 3 in 5b8f7d2
import org.junit.jupiter.api.Test; |
[google-java-format] reported by reviewdog 🐶
Lines 9 to 11 in 5b8f7d2
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; | |
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | |
[google-java-format] reported by reviewdog 🐶
Lines 16 to 17 in 5b8f7d2
@Autowired | |
private MockMvc mvc; |
[google-java-format] reported by reviewdog 🐶
Lines 19 to 23 in 5b8f7d2
@Test | |
void healthCheckTestSuccess() throws Exception { | |
mvc.perform(get("/info")).andExpect(status().isOk()); | |
} | |
} |
[google-java-format] reported by reviewdog 🐶
Line 3 in 5b8f7d2
import com.fasterxml.jackson.databind.ObjectMapper; |
[google-java-format] reported by reviewdog 🐶
Lines 4 to 5 in 5b8f7d2
import it.gov.pagopa.mbd.gps.service.model.MbdPaymentOptionRequestProperties; | |
import it.gov.pagopa.mbd.gps.service.model.PaymentOption; |
[google-java-format] reported by reviewdog 🐶
Line 7 in 5b8f7d2
import it.gov.pagopa.mbd.gps.service.model.MbdPaymentOptionResponse; |
[google-java-format] reported by reviewdog 🐶
Line 8 in 5b8f7d2
import it.gov.pagopa.mbd.gps.service.model.Transfer; |
[google-java-format] reported by reviewdog 🐶
Lines 17 to 23 in 5b8f7d2
import static org.junit.jupiter.api.Assertions.assertEquals; | |
import static org.junit.jupiter.api.Assertions.assertFalse; | |
import static org.junit.jupiter.api.Assertions.assertNotNull; | |
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; | |
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; | |
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | |
[google-java-format] reported by reviewdog 🐶
Lines 28 to 173 in 5b8f7d2
@Autowired | |
private MockMvc mvc; | |
@Autowired | |
private ObjectMapper objectMapper; | |
@Test | |
void createMdbPaymentOptionTestSuccess() throws Exception { | |
MbdPaymentOptionRequest request = buildMdbPaymentOptionRequest(); | |
MvcResult result = mvc.perform(post("/mbd/paymentOption") | |
.content(objectMapper.writeValueAsString(request)) | |
.contentType(MediaType.APPLICATION_JSON)) | |
.andExpect(status().isCreated()) | |
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE)) | |
.andReturn(); | |
String json = result.getResponse().getContentAsString(); | |
assertNotNull(json); | |
MbdPaymentOptionResponse response = objectMapper.readValue(json, MbdPaymentOptionResponse.class); | |
assertNotNull(response); | |
assertNotNull(response.getPaymentOption()); | |
assertEquals(1, response.getPaymentOption().size()); | |
PaymentOption paymentOption = response.getPaymentOption().get(0); | |
assertEquals(request.getProperties().getFirstName(), paymentOption.getFirstName()); | |
assertEquals(request.getProperties().getLastName(), paymentOption.getLastName()); | |
assertEquals(request.getProperties().getAmount(), paymentOption.getAmount()); | |
assertNotNull(paymentOption.getDescription()); | |
assertNotNull(paymentOption.getDueDate()); | |
assertNotNull(paymentOption.getRetentionDate()); | |
assertFalse(paymentOption.getIsPartialPayment()); | |
assertNotNull(paymentOption.getTransfer()); | |
assertEquals(1, paymentOption.getTransfer().size()); | |
Transfer transfer = paymentOption.getTransfer().get(0); | |
assertEquals(request.getProperties().getAmount(), transfer.getAmount()); | |
assertEquals(request.getProperties().getFiscalCode(), transfer.getOrganizationFiscalCode()); | |
assertEquals("1", transfer.getIdTransfer()); | |
assertNotNull(transfer.getRemittanceInformation()); | |
assertNotNull(transfer.getStamp()); | |
assertEquals(request.getProperties().getProvincialResidence(), transfer.getStamp().getProvincialResidence()); | |
assertEquals(request.getProperties().getDocumentHash(), transfer.getStamp().getHashDocument()); | |
assertEquals("st", transfer.getStamp().getStampType()); | |
} | |
@Test | |
void createMdbPaymentOptionTestFailAmountMissing() throws Exception { | |
MbdPaymentOptionRequest request = buildMdbPaymentOptionRequest(); | |
request.getProperties().setAmount(null); | |
mvc.perform(post("/mbd/paymentOption") | |
.content(objectMapper.writeValueAsString(request)) | |
.contentType(MediaType.APPLICATION_JSON)) | |
.andExpect(status().is4xxClientError()); | |
} | |
@Test | |
void createMdbPaymentOptionTestFailFirstNameMissing() throws Exception { | |
MbdPaymentOptionRequest request = buildMdbPaymentOptionRequest(); | |
request.getProperties().setFirstName(null); | |
mvc.perform(post("/mbd/paymentOption") | |
.content(objectMapper.writeValueAsString(request)) | |
.contentType(MediaType.APPLICATION_JSON)) | |
.andExpect(status().is4xxClientError()); | |
} | |
@Test | |
void createMdbPaymentOptionTestFailLastNameMissing() throws Exception { | |
MbdPaymentOptionRequest request = buildMdbPaymentOptionRequest(); | |
request.getProperties().setLastName(null); | |
mvc.perform(post("/mbd/paymentOption") | |
.content(objectMapper.writeValueAsString(request)) | |
.contentType(MediaType.APPLICATION_JSON)) | |
.andExpect(status().is4xxClientError()); | |
} | |
@Test | |
void createMdbPaymentOptionTestFailFiscalCodeMissing() throws Exception { | |
MbdPaymentOptionRequest request = buildMdbPaymentOptionRequest(); | |
request.getProperties().setFiscalCode(null); | |
mvc.perform(post("/mbd/paymentOption") | |
.content(objectMapper.writeValueAsString(request)) | |
.contentType(MediaType.APPLICATION_JSON)) | |
.andExpect(status().is4xxClientError()); | |
} | |
@Test | |
void createMdbPaymentOptionTestFailProvincialResidenceMissing() throws Exception { | |
MbdPaymentOptionRequest request = buildMdbPaymentOptionRequest(); | |
request.getProperties().setProvincialResidence(null); | |
mvc.perform(post("/mbd/paymentOption") | |
.content(objectMapper.writeValueAsString(request)) | |
.contentType(MediaType.APPLICATION_JSON)) | |
.andExpect(status().is4xxClientError()); | |
} | |
@Test | |
void createMdbPaymentOptionTestFailDocumentHashMissing() throws Exception { | |
MbdPaymentOptionRequest request = buildMdbPaymentOptionRequest(); | |
request.getProperties().setDocumentHash(null); | |
mvc.perform(post("/mbd/paymentOption") | |
.content(objectMapper.writeValueAsString(request)) | |
.contentType(MediaType.APPLICATION_JSON)) | |
.andExpect(status().is4xxClientError()); | |
} | |
@Test | |
void createMdbPaymentOptionTestFailDocumentHashWrongSize() throws Exception { | |
MbdPaymentOptionRequest request = buildMdbPaymentOptionRequest(); | |
request.getProperties().setDocumentHash("asdfsdf"); | |
mvc.perform(post("/mbd/paymentOption") | |
.content(objectMapper.writeValueAsString(request)) | |
.contentType(MediaType.APPLICATION_JSON)) | |
.andExpect(status().is4xxClientError()); | |
} | |
private MbdPaymentOptionRequest buildMdbPaymentOptionRequest() { | |
return MbdPaymentOptionRequest.builder() | |
.properties(MbdPaymentOptionRequestProperties.builder() | |
.amount(16L) | |
.firstName("Mario") | |
.lastName("Rossi") | |
.fiscalCode("0000000000000000") | |
.provincialResidence("AS") | |
.documentHash("1trA5qyjSZNwiwtGG46dyjRpL16TFgGCFvnfFzQrFHbB") | |
.build()) | |
.build(); | |
} | |
} |
This pull request sets up GitHub code scanning for this repository. Once the scans have completed and the checks have passed, the analysis results for this pull request branch will appear on this overview. Once you merge this pull request, the 'Security' tab will show more code scanning analysis results (for example, for the default branch). Depending on your configuration and choice of analysis tool, future pull requests will be annotated with code scanning analysis results. For more information about GitHub code scanning, check out the documentation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remaining comments which cannot be posted as a review comment to avoid GitHub Rate Limit
google-java-format
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/exception/ErrorHandler.java
Lines 108 to 136 in 5b8f7d2
/** | |
* Handle if validation constraints are unsatisfied | |
* | |
* @param ex {@link MethodArgumentNotValidException} exception raised | |
* @param headers of the response | |
* @param status of the response | |
* @param request from frontend | |
* @return a {@link ProblemJson} as response with the cause and with a 400 as HTTP status | |
*/ | |
@Override | |
protected ResponseEntity<Object> handleMethodArgumentNotValid( | |
MethodArgumentNotValidException ex, | |
HttpHeaders headers, | |
HttpStatusCode status, | |
WebRequest request | |
) { | |
List<String> details = new ArrayList<>(); | |
for (FieldError error : ex.getBindingResult().getFieldErrors()) { | |
details.add(error.getField() + ": " + error.getDefaultMessage()); | |
} | |
var detailsMessage = String.join(", ", details); | |
log.warn("Input not valid: " + detailsMessage); | |
var errorResponse = ProblemJson.builder() | |
.status(HttpStatus.BAD_REQUEST.value()) | |
.title(AppError.BAD_REQUEST.getTitle()) | |
.detail(detailsMessage) | |
.build(); | |
return new ResponseEntity<>(errorResponse, HttpStatus.BAD_REQUEST); | |
} |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/exception/ErrorHandler.java
Lines 138 to 149 in 5b8f7d2
@ExceptionHandler({ConstraintViolationException.class}) | |
public ResponseEntity<ProblemJson> handleConstraintViolationException( | |
final ConstraintViolationException ex, | |
final WebRequest request | |
) { | |
log.warn("Validation Error raised:", ex); | |
var errorResponse = ProblemJson.builder() | |
.status(HttpStatus.BAD_REQUEST.value()) | |
.title(AppError.BAD_REQUEST.getTitle()) | |
.detail(ex.getMessage()) | |
.build(); | |
return new ResponseEntity<>(errorResponse, HttpStatus.BAD_REQUEST); |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/exception/ErrorHandler.java
Line 151 in 5b8f7d2
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/exception/ErrorHandler.java
Lines 152 to 196 in 5b8f7d2
/** | |
* Handle if a {@link AppException} is raised | |
* | |
* @param ex {@link AppException} exception raised | |
* @param request from frontend | |
* @return a {@link ProblemJson} as response with the cause and with an appropriated HTTP status | |
*/ | |
@ExceptionHandler({AppException.class}) | |
public ResponseEntity<ProblemJson> handleAppException( | |
final AppException ex, | |
final WebRequest request | |
) { | |
if (ex.getCause() != null) { | |
log.warn("App Exception raised: {}\nCause of the App Exception: ", ex.getMessage(), ex.getCause()); | |
} else { | |
log.warn("App Exception raised: ", ex); | |
} | |
var errorResponse = ProblemJson.builder() | |
.status(ex.getHttpStatus().value()) | |
.title(ex.getTitle()) | |
.detail(ex.getMessage()) | |
.build(); | |
return new ResponseEntity<>(errorResponse, ex.getHttpStatus()); | |
} | |
/** | |
* Handle if a {@link Exception} is raised | |
* | |
* @param ex {@link Exception} exception raised | |
* @param request from frontend | |
* @return a {@link ProblemJson} as response with the cause and with 500 as HTTP status | |
*/ | |
@ExceptionHandler({Exception.class}) | |
public ResponseEntity<ProblemJson> handleGenericException( | |
final Exception ex, | |
final WebRequest request | |
) { | |
log.error("Generic Exception raised:", ex); | |
var errorResponse = ProblemJson.builder() | |
.status(HttpStatus.INTERNAL_SERVER_ERROR.value()) | |
.title(AppError.INTERNAL_SERVER_ERROR.getTitle()) | |
.detail(ex.getMessage()) | |
.build(); | |
return new ResponseEntity<>(errorResponse, HttpStatus.INTERNAL_SERVER_ERROR); | |
} |
[google-java-format] reported by reviewdog 🐶
Lines 3 to 4 in 5b8f7d2
import it.gov.pagopa.mbd.gps.service.model.MbdPaymentOptionRequestProperties; | |
import it.gov.pagopa.mbd.gps.service.model.PaymentOption; |
[google-java-format] reported by reviewdog 🐶
Line 6 in 5b8f7d2
import it.gov.pagopa.mbd.gps.service.model.MbdPaymentOptionResponse; |
[google-java-format] reported by reviewdog 🐶
Line 7 in 5b8f7d2
import it.gov.pagopa.mbd.gps.service.model.Stamp; |
[google-java-format] reported by reviewdog 🐶
Line 9 in 5b8f7d2
import org.modelmapper.Converter; |
[google-java-format] reported by reviewdog 🐶
Lines 14 to 17 in 5b8f7d2
import java.time.LocalDateTime; | |
import java.time.temporal.ChronoUnit; | |
import java.util.Collections; | |
[google-java-format] reported by reviewdog 🐶
Line 19 in 5b8f7d2
* Converter class that specify how to convert a {@link MbdPaymentOptionRequest} instance to a {@link MbdPaymentOptionResponse} instance |
[google-java-format] reported by reviewdog 🐶
Line 22 in 5b8f7d2
public class ConvertMbdPaymentOptionRequestToMbdPaymentOptionResponse implements Converter<MbdPaymentOptionRequest, MbdPaymentOptionResponse> { |
[google-java-format] reported by reviewdog 🐶
Lines 24 to 26 in 5b8f7d2
private static final boolean IS_PARTIAL_PAYMENT = false; | |
private static final String ID_TRANSFER = "1"; | |
private static final String STAMP_TYPE = "st"; |
[google-java-format] reported by reviewdog 🐶
Lines 28 to 29 in 5b8f7d2
@Value("${mbd.payment-option.description}") | |
private String description; |
[google-java-format] reported by reviewdog 🐶
Lines 31 to 32 in 5b8f7d2
@Value("${mbd.transfer.remittance-information}") | |
private String remittanceInformation; |
[google-java-format] reported by reviewdog 🐶
Lines 34 to 35 in 5b8f7d2
@Value("${mbd.payment-option.due-date-delta}") | |
private int dueDateDelta; |
[google-java-format] reported by reviewdog 🐶
Lines 37 to 38 in 5b8f7d2
@Value("${mbd.payment-option.due-date-delta-time-unit}") | |
private ChronoUnit dueDateDeltaTimeUnit; |
[google-java-format] reported by reviewdog 🐶
Lines 40 to 41 in 5b8f7d2
@Value("${mbd.payment-option.retention-date-delta}") | |
private int retentionDateDelta; |
[google-java-format] reported by reviewdog 🐶
Lines 43 to 44 in 5b8f7d2
@Value("${mbd.payment-option.retention-date-delta-time-unit}") | |
private ChronoUnit retentionDateDeltaTimeUnit; |
[google-java-format] reported by reviewdog 🐶
Lines 46 to 48 in 5b8f7d2
@Override | |
public MbdPaymentOptionResponse convert(MappingContext<MbdPaymentOptionRequest, MbdPaymentOptionResponse> context) { | |
MbdPaymentOptionRequestProperties model = context.getSource().getProperties(); |
[google-java-format] reported by reviewdog 🐶
Lines 50 to 60 in 5b8f7d2
Transfer transfer = Transfer.builder() | |
.amount(model.getAmount()) | |
.idTransfer(ID_TRANSFER) | |
.organizationFiscalCode(model.getFiscalCode()) | |
.remittanceInformation(remittanceInformation) | |
.stamp(Stamp.builder() | |
.hashDocument(model.getDocumentHash()) | |
.provincialResidence(model.getProvincialResidence()) | |
.stampType(STAMP_TYPE) | |
.build()) | |
.build(); |
[google-java-format] reported by reviewdog 🐶
Lines 62 to 71 in 5b8f7d2
PaymentOption paymentOption = PaymentOption.builder() | |
.firstName(model.getFirstName()) | |
.lastName(model.getLastName()) | |
.amount(model.getAmount()) | |
.description(description) | |
.dueDate(LocalDateTime.now().plus(dueDateDelta, dueDateDeltaTimeUnit)) | |
.retentionDate(LocalDateTime.now().plus(retentionDateDelta, retentionDateDeltaTimeUnit)) | |
.isPartialPayment(IS_PARTIAL_PAYMENT) | |
.transfer(Collections.singletonList(transfer)) | |
.build(); |
[google-java-format] reported by reviewdog 🐶
Lines 73 to 77 in 5b8f7d2
return MbdPaymentOptionResponse.builder() | |
.paymentOption(Collections.singletonList(paymentOption)) | |
.build(); | |
} | |
} |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/model/AppCorsConfiguration.java
Lines 21 to 22 in 5b8f7d2
private String[] origins; | |
private String[] methods; |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/model/AppInfo.java
Lines 19 to 21 in 5b8f7d2
private String name; | |
private String version; | |
private String environment; |
[google-java-format] reported by reviewdog 🐶
Lines 10 to 12 in 5b8f7d2
/** | |
* Model class that holds MBD GPS request | |
*/ |
[google-java-format] reported by reviewdog 🐶
Lines 19 to 22 in 5b8f7d2
@Valid | |
@Schema(description = "MBD payment option's properties", requiredMode = Schema.RequiredMode.REQUIRED) | |
private MbdPaymentOptionRequestProperties properties; | |
} |
[google-java-format] reported by reviewdog 🐶
Lines 12 to 14 in 5b8f7d2
/** | |
* Model class that holds MBD service specific data | |
*/ |
[google-java-format] reported by reviewdog 🐶
Lines 21 to 23 in 5b8f7d2
@NotNull(message = "amount is required") | |
@Schema(description = "MBD amount", requiredMode = Schema.RequiredMode.REQUIRED) | |
private Long amount; |
[google-java-format] reported by reviewdog 🐶
Lines 25 to 27 in 5b8f7d2
@NotBlank | |
@Schema(description = "Debtor's name", requiredMode = Schema.RequiredMode.REQUIRED) | |
private String firstName; |
[google-java-format] reported by reviewdog 🐶
Lines 29 to 31 in 5b8f7d2
@NotBlank | |
@Schema(description = "Debtor's last name", requiredMode = Schema.RequiredMode.REQUIRED) | |
private String lastName; |
[google-java-format] reported by reviewdog 🐶
Lines 33 to 35 in 5b8f7d2
@NotBlank | |
@Schema(description = "Debtor's fiscal code", requiredMode = Schema.RequiredMode.REQUIRED) | |
private String fiscalCode; |
[google-java-format] reported by reviewdog 🐶
Lines 37 to 39 in 5b8f7d2
@NotBlank | |
@Schema(description = "Debtor's residence province", requiredMode = Schema.RequiredMode.REQUIRED) | |
private String provincialResidence; |
[google-java-format] reported by reviewdog 🐶
Lines 41 to 45 in 5b8f7d2
@NotBlank | |
@Size(min = 44, max = 44) | |
@Schema(description = "MBD document's hash", requiredMode = Schema.RequiredMode.REQUIRED) | |
private String documentHash; | |
} |
[google-java-format] reported by reviewdog 🐶
Line 5 in 5b8f7d2
import lombok.AllArgsConstructor; |
[google-java-format] reported by reviewdog 🐶
Lines 10 to 14 in 5b8f7d2
import java.util.List; | |
/** | |
* Model class that holds MBD GPS response | |
*/ |
[google-java-format] reported by reviewdog 🐶
Lines 21 to 24 in 5b8f7d2
@Valid | |
@Schema(description = "MBD payment option", requiredMode = Schema.RequiredMode.REQUIRED) | |
private List<@Valid PaymentOption> paymentOption; | |
} |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/model/PaymentOption.java
Line 8 in 5b8f7d2
import lombok.AllArgsConstructor; |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/model/PaymentOption.java
Lines 13 to 18 in 5b8f7d2
import java.time.LocalDateTime; | |
import java.util.List; | |
/** | |
* Model class that holds MBD payment option data | |
*/ |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/model/PaymentOption.java
Lines 25 to 56 in 5b8f7d2
@NotBlank | |
@Schema(description = "Debtor's name", requiredMode = Schema.RequiredMode.REQUIRED) | |
private String firstName; | |
@NotBlank | |
@Schema(description = "Debtor's last name", requiredMode = Schema.RequiredMode.REQUIRED) | |
private String lastName; | |
@NotNull(message = "amount is required") | |
@Schema(description = "Payment option's amount", requiredMode = Schema.RequiredMode.REQUIRED) | |
private Long amount; | |
@NotBlank(message = "payment option description is required") | |
@Size(max = 140) // compliant to paForNode.xsd | |
@Schema(description = "Payment option's description", requiredMode = Schema.RequiredMode.REQUIRED) | |
private String description; | |
@NotNull(message = "is partial payment is required") | |
@Schema(description = "Payment option's is partial payment flag", requiredMode = Schema.RequiredMode.REQUIRED) | |
private Boolean isPartialPayment; | |
@NotNull(message = "due date is required") | |
@Schema(description = "Payment option's due date", requiredMode = Schema.RequiredMode.REQUIRED) | |
private LocalDateTime dueDate; | |
@Schema(description = "Payment option's retention date", requiredMode = Schema.RequiredMode.REQUIRED) | |
private LocalDateTime retentionDate; | |
@Valid | |
@Schema(description = "Payment option's transfer list", requiredMode = Schema.RequiredMode.REQUIRED) | |
private List<@Valid Transfer> transfer; | |
} |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/model/ProblemJson.java
Line 17 in 5b8f7d2
* <p> See {@link ErrorHandler} |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/model/ProblemJson.java
Lines 27 to 29 in 5b8f7d2
@JsonProperty("title") | |
@Schema(description = "A short, summary of the problem type. Written in english and readable for engineers (usually not suited for non technical stakeholders and not localized); example: Service Unavailable") | |
private String title; |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/model/ProblemJson.java
Lines 31 to 35 in 5b8f7d2
@JsonProperty("status") | |
@Schema(example = "200", description = "The HTTP status code generated by the origin server for this occurrence of the problem.") | |
@Min(100) | |
@Max(600) | |
private Integer status; |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/model/ProblemJson.java
Lines 37 to 39 in 5b8f7d2
@JsonProperty("detail") | |
@Schema(example = "There was an error processing the request", description = "A human readable explanation specific to this occurrence of the problem.") | |
private String detail; |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/model/Stamp.java
Lines 12 to 14 in 5b8f7d2
/** | |
* Model class that holds MBD stamp data | |
*/ |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/model/Stamp.java
Lines 21 to 27 in 5b8f7d2
@NotBlank | |
@Size(max = 72) | |
@Schema(description = "Document hash type is stBase64Binary72 as described in https://github.com/pagopa/pagopa-api.", requiredMode = Schema.RequiredMode.REQUIRED) | |
// Stamp generally get as input a base64sha256, that is the SHA256 hash of a given string encoded with Base64. | |
// It is not equivalent to base64encode(sha256(“test”)), if sha256() returns a hexadecimal representation. | |
// The result should normally be 44 characters, to be compliant with as-is it was extended to 72 | |
private String hashDocument; |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/model/Stamp.java
Lines 29 to 32 in 5b8f7d2
@NotBlank | |
@Size(min = 2, max = 2) | |
@Schema(description = "The type of the stamp", minLength = 2, maxLength = 2, requiredMode = Schema.RequiredMode.REQUIRED) | |
private String stampType; |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/model/Stamp.java
Lines 34 to 38 in 5b8f7d2
@NotBlank | |
@Pattern(regexp = "[A-Z]{2}") | |
@Schema(description = "The province of residence", example = "RM", pattern = "[A-Z]{2,2}", requiredMode = Schema.RequiredMode.REQUIRED) | |
private String provincialResidence; | |
} |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/model/Transfer.java
Lines 13 to 15 in 5b8f7d2
/** | |
* Model class that holds MBD transfer data | |
*/ |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/model/Transfer.java
Lines 22 to 24 in 5b8f7d2
@NotBlank(message = "id transfer is required") | |
@Schema(description = "Transfer's id", allowableValues = {"1", "2", "3", "4", "5"}, requiredMode = Schema.RequiredMode.REQUIRED) | |
private String idTransfer; |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/model/Transfer.java
Lines 26 to 28 in 5b8f7d2
@NotNull(message = "amount is required") | |
@Schema(description = "Transfer's amount", requiredMode = Schema.RequiredMode.REQUIRED) | |
private Long amount; |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/model/Transfer.java
Lines 30 to 31 in 5b8f7d2
@Schema(description = "Fiscal code related to the organization targeted by this transfer.", example = "00000000000") | |
private String organizationFiscalCode; |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/model/Transfer.java
Lines 33 to 37 in 5b8f7d2
@NotBlank(message = "remittance information is required") | |
@Size(max = 140, message = "remittance information must be compliant to EACT FORMATTING RULES, up to 140 chars") | |
@Schema(description = "Transfer's remittance information", requiredMode = Schema.RequiredMode.REQUIRED) | |
// https://docs.pagopa.it/saci/specifiche-attuative-dei-codici-identificativi-di-versamento-riversamento-e-rendicontazione/operazione-di-trasferimento-fondi | |
private String remittanceInformation; // causale |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/model/Transfer.java
Lines 39 to 42 in 5b8f7d2
@Valid | |
@Schema(description = "Transfer's stamp", requiredMode = Schema.RequiredMode.REQUIRED) | |
private Stamp stamp; | |
} |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/util/Constants.java
Line 8 in 5b8f7d2
public static final String HEADER_REQUEST_ID = "X-Request-Id"; |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/test/java/it/gov/pagopa/mbd/gps/service/ApplicationTest.java
Line 3 in 5b8f7d2
import org.junit.jupiter.api.Test; |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/test/java/it/gov/pagopa/mbd/gps/service/ApplicationTest.java
Lines 6 to 7 in 5b8f7d2
import static org.junit.jupiter.api.Assertions.assertTrue; | |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/test/java/it/gov/pagopa/mbd/gps/service/ApplicationTest.java
Lines 11 to 15 in 5b8f7d2
@Test | |
void contextLoads() { | |
// check only if the context is loaded | |
assertTrue(true); | |
} |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/test/java/it/gov/pagopa/mbd/gps/service/OpenApiGenerationTest.java
Line 3 in 5b8f7d2
import com.fasterxml.jackson.databind.ObjectMapper; |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/test/java/it/gov/pagopa/mbd/gps/service/OpenApiGenerationTest.java
Line 4 in 5b8f7d2
import org.junit.jupiter.api.Test; |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/test/java/it/gov/pagopa/mbd/gps/service/OpenApiGenerationTest.java
Lines 13 to 19 in 5b8f7d2
import java.nio.file.Files; | |
import java.nio.file.Path; | |
import java.nio.file.Paths; | |
import static org.junit.jupiter.api.Assertions.assertFalse; | |
import static org.junit.jupiter.api.Assertions.assertNotNull; | |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/test/java/it/gov/pagopa/mbd/gps/service/OpenApiGenerationTest.java
Lines 24 to 25 in 5b8f7d2
@Autowired | |
ObjectMapper objectMapper; |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/test/java/it/gov/pagopa/mbd/gps/service/OpenApiGenerationTest.java
Lines 27 to 28 in 5b8f7d2
@Autowired | |
private MockMvc mvc; |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/test/java/it/gov/pagopa/mbd/gps/service/OpenApiGenerationTest.java
Lines 30 to 49 in 5b8f7d2
@Test | |
void swaggerSpringPlugin() throws Exception { | |
mvc.perform(MockMvcRequestBuilders.get("/v3/api-docs").accept(MediaType.APPLICATION_JSON)) | |
.andExpect(MockMvcResultMatchers.status().is2xxSuccessful()) | |
.andDo( | |
result -> { | |
assertNotNull(result); | |
assertNotNull(result.getResponse()); | |
final String content = result.getResponse().getContentAsString(); | |
assertFalse(content.isBlank()); | |
assertFalse(content.contains("${"), "Generated swagger contains placeholders"); | |
Object swagger = | |
objectMapper.readValue(result.getResponse().getContentAsString(), Object.class); | |
String formatted = | |
objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(swagger); | |
Path basePath = Paths.get("openapi/"); | |
Files.createDirectories(basePath); | |
Files.write(basePath.resolve("openapi.json"), formatted.getBytes()); | |
}); | |
} |
[google-java-format] reported by reviewdog 🐶
Line 3 in 5b8f7d2
import org.junit.jupiter.api.Test; |
[google-java-format] reported by reviewdog 🐶
Lines 9 to 11 in 5b8f7d2
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; | |
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | |
[google-java-format] reported by reviewdog 🐶
Lines 16 to 17 in 5b8f7d2
@Autowired | |
private MockMvc mvc; |
[google-java-format] reported by reviewdog 🐶
Lines 19 to 23 in 5b8f7d2
@Test | |
void healthCheckTestSuccess() throws Exception { | |
mvc.perform(get("/info")).andExpect(status().isOk()); | |
} | |
} |
[google-java-format] reported by reviewdog 🐶
Line 3 in 5b8f7d2
import com.fasterxml.jackson.databind.ObjectMapper; |
[google-java-format] reported by reviewdog 🐶
Lines 4 to 5 in 5b8f7d2
import it.gov.pagopa.mbd.gps.service.model.MbdPaymentOptionRequestProperties; | |
import it.gov.pagopa.mbd.gps.service.model.PaymentOption; |
[google-java-format] reported by reviewdog 🐶
Line 7 in 5b8f7d2
import it.gov.pagopa.mbd.gps.service.model.MbdPaymentOptionResponse; |
[google-java-format] reported by reviewdog 🐶
Line 8 in 5b8f7d2
import it.gov.pagopa.mbd.gps.service.model.Transfer; |
[google-java-format] reported by reviewdog 🐶
Lines 17 to 23 in 5b8f7d2
import static org.junit.jupiter.api.Assertions.assertEquals; | |
import static org.junit.jupiter.api.Assertions.assertFalse; | |
import static org.junit.jupiter.api.Assertions.assertNotNull; | |
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; | |
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; | |
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | |
[google-java-format] reported by reviewdog 🐶
Lines 28 to 173 in 5b8f7d2
@Autowired | |
private MockMvc mvc; | |
@Autowired | |
private ObjectMapper objectMapper; | |
@Test | |
void createMdbPaymentOptionTestSuccess() throws Exception { | |
MbdPaymentOptionRequest request = buildMdbPaymentOptionRequest(); | |
MvcResult result = mvc.perform(post("/mbd/paymentOption") | |
.content(objectMapper.writeValueAsString(request)) | |
.contentType(MediaType.APPLICATION_JSON)) | |
.andExpect(status().isCreated()) | |
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE)) | |
.andReturn(); | |
String json = result.getResponse().getContentAsString(); | |
assertNotNull(json); | |
MbdPaymentOptionResponse response = objectMapper.readValue(json, MbdPaymentOptionResponse.class); | |
assertNotNull(response); | |
assertNotNull(response.getPaymentOption()); | |
assertEquals(1, response.getPaymentOption().size()); | |
PaymentOption paymentOption = response.getPaymentOption().get(0); | |
assertEquals(request.getProperties().getFirstName(), paymentOption.getFirstName()); | |
assertEquals(request.getProperties().getLastName(), paymentOption.getLastName()); | |
assertEquals(request.getProperties().getAmount(), paymentOption.getAmount()); | |
assertNotNull(paymentOption.getDescription()); | |
assertNotNull(paymentOption.getDueDate()); | |
assertNotNull(paymentOption.getRetentionDate()); | |
assertFalse(paymentOption.getIsPartialPayment()); | |
assertNotNull(paymentOption.getTransfer()); | |
assertEquals(1, paymentOption.getTransfer().size()); | |
Transfer transfer = paymentOption.getTransfer().get(0); | |
assertEquals(request.getProperties().getAmount(), transfer.getAmount()); | |
assertEquals(request.getProperties().getFiscalCode(), transfer.getOrganizationFiscalCode()); | |
assertEquals("1", transfer.getIdTransfer()); | |
assertNotNull(transfer.getRemittanceInformation()); | |
assertNotNull(transfer.getStamp()); | |
assertEquals(request.getProperties().getProvincialResidence(), transfer.getStamp().getProvincialResidence()); | |
assertEquals(request.getProperties().getDocumentHash(), transfer.getStamp().getHashDocument()); | |
assertEquals("st", transfer.getStamp().getStampType()); | |
} | |
@Test | |
void createMdbPaymentOptionTestFailAmountMissing() throws Exception { | |
MbdPaymentOptionRequest request = buildMdbPaymentOptionRequest(); | |
request.getProperties().setAmount(null); | |
mvc.perform(post("/mbd/paymentOption") | |
.content(objectMapper.writeValueAsString(request)) | |
.contentType(MediaType.APPLICATION_JSON)) | |
.andExpect(status().is4xxClientError()); | |
} | |
@Test | |
void createMdbPaymentOptionTestFailFirstNameMissing() throws Exception { | |
MbdPaymentOptionRequest request = buildMdbPaymentOptionRequest(); | |
request.getProperties().setFirstName(null); | |
mvc.perform(post("/mbd/paymentOption") | |
.content(objectMapper.writeValueAsString(request)) | |
.contentType(MediaType.APPLICATION_JSON)) | |
.andExpect(status().is4xxClientError()); | |
} | |
@Test | |
void createMdbPaymentOptionTestFailLastNameMissing() throws Exception { | |
MbdPaymentOptionRequest request = buildMdbPaymentOptionRequest(); | |
request.getProperties().setLastName(null); | |
mvc.perform(post("/mbd/paymentOption") | |
.content(objectMapper.writeValueAsString(request)) | |
.contentType(MediaType.APPLICATION_JSON)) | |
.andExpect(status().is4xxClientError()); | |
} | |
@Test | |
void createMdbPaymentOptionTestFailFiscalCodeMissing() throws Exception { | |
MbdPaymentOptionRequest request = buildMdbPaymentOptionRequest(); | |
request.getProperties().setFiscalCode(null); | |
mvc.perform(post("/mbd/paymentOption") | |
.content(objectMapper.writeValueAsString(request)) | |
.contentType(MediaType.APPLICATION_JSON)) | |
.andExpect(status().is4xxClientError()); | |
} | |
@Test | |
void createMdbPaymentOptionTestFailProvincialResidenceMissing() throws Exception { | |
MbdPaymentOptionRequest request = buildMdbPaymentOptionRequest(); | |
request.getProperties().setProvincialResidence(null); | |
mvc.perform(post("/mbd/paymentOption") | |
.content(objectMapper.writeValueAsString(request)) | |
.contentType(MediaType.APPLICATION_JSON)) | |
.andExpect(status().is4xxClientError()); | |
} | |
@Test | |
void createMdbPaymentOptionTestFailDocumentHashMissing() throws Exception { | |
MbdPaymentOptionRequest request = buildMdbPaymentOptionRequest(); | |
request.getProperties().setDocumentHash(null); | |
mvc.perform(post("/mbd/paymentOption") | |
.content(objectMapper.writeValueAsString(request)) | |
.contentType(MediaType.APPLICATION_JSON)) | |
.andExpect(status().is4xxClientError()); | |
} | |
@Test | |
void createMdbPaymentOptionTestFailDocumentHashWrongSize() throws Exception { | |
MbdPaymentOptionRequest request = buildMdbPaymentOptionRequest(); | |
request.getProperties().setDocumentHash("asdfsdf"); | |
mvc.perform(post("/mbd/paymentOption") | |
.content(objectMapper.writeValueAsString(request)) | |
.contentType(MediaType.APPLICATION_JSON)) | |
.andExpect(status().is4xxClientError()); | |
} | |
private MbdPaymentOptionRequest buildMdbPaymentOptionRequest() { | |
return MbdPaymentOptionRequest.builder() | |
.properties(MbdPaymentOptionRequestProperties.builder() | |
.amount(16L) | |
.firstName("Mario") | |
.lastName("Rossi") | |
.fiscalCode("0000000000000000") | |
.provincialResidence("AS") | |
.documentHash("1trA5qyjSZNwiwtGG46dyjRpL16TFgGCFvnfFzQrFHbB") | |
.build()) | |
.build(); | |
} | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remaining comments which cannot be posted as a review comment to avoid GitHub Rate Limit
google-java-format
[google-java-format] reported by reviewdog 🐶
Lines 29 to 31 in 998e8e7
@NotBlank | |
@Schema(description = "Debtor's last name", requiredMode = Schema.RequiredMode.REQUIRED) | |
private String lastName; |
[google-java-format] reported by reviewdog 🐶
Lines 33 to 35 in 998e8e7
@NotBlank | |
@Schema(description = "Debtor's fiscal code", requiredMode = Schema.RequiredMode.REQUIRED) | |
private String fiscalCode; |
[google-java-format] reported by reviewdog 🐶
Lines 37 to 39 in 998e8e7
@NotBlank | |
@Schema(description = "Debtor's residence province", requiredMode = Schema.RequiredMode.REQUIRED) | |
private String provincialResidence; |
[google-java-format] reported by reviewdog 🐶
Lines 41 to 45 in 998e8e7
@NotBlank | |
@Size(min = 44, max = 44) | |
@Schema(description = "MBD document's hash", requiredMode = Schema.RequiredMode.REQUIRED) | |
private String documentHash; | |
} |
[google-java-format] reported by reviewdog 🐶
Line 5 in 998e8e7
import lombok.AllArgsConstructor; |
[google-java-format] reported by reviewdog 🐶
Lines 10 to 14 in 998e8e7
import java.util.List; | |
/** | |
* Model class that holds MBD GPS response | |
*/ |
[google-java-format] reported by reviewdog 🐶
Lines 21 to 24 in 998e8e7
@Valid | |
@Schema(description = "MBD payment option", requiredMode = Schema.RequiredMode.REQUIRED) | |
private List<@Valid PaymentOption> paymentOption; | |
} |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/model/PaymentOption.java
Line 8 in 998e8e7
import lombok.AllArgsConstructor; |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/model/PaymentOption.java
Lines 13 to 18 in 998e8e7
import java.time.LocalDateTime; | |
import java.util.List; | |
/** | |
* Model class that holds MBD payment option data | |
*/ |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/model/PaymentOption.java
Lines 25 to 56 in 998e8e7
@NotBlank | |
@Schema(description = "Debtor's name", requiredMode = Schema.RequiredMode.REQUIRED) | |
private String firstName; | |
@NotBlank | |
@Schema(description = "Debtor's last name", requiredMode = Schema.RequiredMode.REQUIRED) | |
private String lastName; | |
@NotNull(message = "amount is required") | |
@Schema(description = "Payment option's amount", requiredMode = Schema.RequiredMode.REQUIRED) | |
private Long amount; | |
@NotBlank(message = "payment option description is required") | |
@Size(max = 140) // compliant to paForNode.xsd | |
@Schema(description = "Payment option's description", requiredMode = Schema.RequiredMode.REQUIRED) | |
private String description; | |
@NotNull(message = "is partial payment is required") | |
@Schema(description = "Payment option's is partial payment flag", requiredMode = Schema.RequiredMode.REQUIRED) | |
private Boolean isPartialPayment; | |
@NotNull(message = "due date is required") | |
@Schema(description = "Payment option's due date", requiredMode = Schema.RequiredMode.REQUIRED) | |
private LocalDateTime dueDate; | |
@Schema(description = "Payment option's retention date", requiredMode = Schema.RequiredMode.REQUIRED) | |
private LocalDateTime retentionDate; | |
@Valid | |
@Schema(description = "Payment option's transfer list", requiredMode = Schema.RequiredMode.REQUIRED) | |
private List<@Valid Transfer> transfer; | |
} |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/model/ProblemJson.java
Line 17 in 998e8e7
* <p> See {@link ErrorHandler} |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/model/ProblemJson.java
Lines 27 to 29 in 998e8e7
@JsonProperty("title") | |
@Schema(description = "A short, summary of the problem type. Written in english and readable for engineers (usually not suited for non technical stakeholders and not localized); example: Service Unavailable") | |
private String title; |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/model/ProblemJson.java
Lines 31 to 35 in 998e8e7
@JsonProperty("status") | |
@Schema(example = "200", description = "The HTTP status code generated by the origin server for this occurrence of the problem.") | |
@Min(100) | |
@Max(600) | |
private Integer status; |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/model/ProblemJson.java
Lines 37 to 39 in 998e8e7
@JsonProperty("detail") | |
@Schema(example = "There was an error processing the request", description = "A human readable explanation specific to this occurrence of the problem.") | |
private String detail; |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/model/Stamp.java
Lines 12 to 14 in 998e8e7
/** | |
* Model class that holds MBD stamp data | |
*/ |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/model/Stamp.java
Lines 21 to 27 in 998e8e7
@NotBlank | |
@Size(max = 72) | |
@Schema(description = "Document hash type is stBase64Binary72 as described in https://github.com/pagopa/pagopa-api.", requiredMode = Schema.RequiredMode.REQUIRED) | |
// Stamp generally get as input a base64sha256, that is the SHA256 hash of a given string encoded with Base64. | |
// It is not equivalent to base64encode(sha256(“test”)), if sha256() returns a hexadecimal representation. | |
// The result should normally be 44 characters, to be compliant with as-is it was extended to 72 | |
private String hashDocument; |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/model/Stamp.java
Lines 29 to 32 in 998e8e7
@NotBlank | |
@Size(min = 2, max = 2) | |
@Schema(description = "The type of the stamp", minLength = 2, maxLength = 2, requiredMode = Schema.RequiredMode.REQUIRED) | |
private String stampType; |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/model/Stamp.java
Lines 34 to 38 in 998e8e7
@NotBlank | |
@Pattern(regexp = "[A-Z]{2}") | |
@Schema(description = "The province of residence", example = "RM", pattern = "[A-Z]{2,2}", requiredMode = Schema.RequiredMode.REQUIRED) | |
private String provincialResidence; | |
} |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/model/Transfer.java
Lines 13 to 15 in 998e8e7
/** | |
* Model class that holds MBD transfer data | |
*/ |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/model/Transfer.java
Lines 22 to 24 in 998e8e7
@NotBlank(message = "id transfer is required") | |
@Schema(description = "Transfer's id", allowableValues = {"1", "2", "3", "4", "5"}, requiredMode = Schema.RequiredMode.REQUIRED) | |
private String idTransfer; |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/model/Transfer.java
Lines 26 to 28 in 998e8e7
@NotNull(message = "amount is required") | |
@Schema(description = "Transfer's amount", requiredMode = Schema.RequiredMode.REQUIRED) | |
private Long amount; |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/model/Transfer.java
Lines 30 to 31 in 998e8e7
@Schema(description = "Fiscal code related to the organization targeted by this transfer.", example = "00000000000") | |
private String organizationFiscalCode; |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/model/Transfer.java
Lines 33 to 37 in 998e8e7
@NotBlank(message = "remittance information is required") | |
@Size(max = 140, message = "remittance information must be compliant to EACT FORMATTING RULES, up to 140 chars") | |
@Schema(description = "Transfer's remittance information", requiredMode = Schema.RequiredMode.REQUIRED) | |
// https://docs.pagopa.it/saci/specifiche-attuative-dei-codici-identificativi-di-versamento-riversamento-e-rendicontazione/operazione-di-trasferimento-fondi | |
private String remittanceInformation; // causale |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/model/Transfer.java
Lines 39 to 42 in 998e8e7
@Valid | |
@Schema(description = "Transfer's stamp", requiredMode = Schema.RequiredMode.REQUIRED) | |
private Stamp stamp; | |
} |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/main/java/it/gov/pagopa/mbd/gps/service/util/Constants.java
Line 8 in 998e8e7
public static final String HEADER_REQUEST_ID = "X-Request-Id"; |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/test/java/it/gov/pagopa/mbd/gps/service/ApplicationTest.java
Line 3 in 998e8e7
import org.junit.jupiter.api.Test; |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/test/java/it/gov/pagopa/mbd/gps/service/ApplicationTest.java
Lines 6 to 7 in 998e8e7
import static org.junit.jupiter.api.Assertions.assertTrue; | |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/test/java/it/gov/pagopa/mbd/gps/service/ApplicationTest.java
Lines 11 to 15 in 998e8e7
@Test | |
void contextLoads() { | |
// check only if the context is loaded | |
assertTrue(true); | |
} |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/test/java/it/gov/pagopa/mbd/gps/service/OpenApiGenerationTest.java
Line 3 in 998e8e7
import com.fasterxml.jackson.databind.ObjectMapper; |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/test/java/it/gov/pagopa/mbd/gps/service/OpenApiGenerationTest.java
Line 4 in 998e8e7
import org.junit.jupiter.api.Test; |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/test/java/it/gov/pagopa/mbd/gps/service/OpenApiGenerationTest.java
Lines 13 to 19 in 998e8e7
import java.nio.file.Files; | |
import java.nio.file.Path; | |
import java.nio.file.Paths; | |
import static org.junit.jupiter.api.Assertions.assertFalse; | |
import static org.junit.jupiter.api.Assertions.assertNotNull; | |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/test/java/it/gov/pagopa/mbd/gps/service/OpenApiGenerationTest.java
Lines 24 to 25 in 998e8e7
@Autowired | |
ObjectMapper objectMapper; |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/test/java/it/gov/pagopa/mbd/gps/service/OpenApiGenerationTest.java
Lines 27 to 28 in 998e8e7
@Autowired | |
private MockMvc mvc; |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/test/java/it/gov/pagopa/mbd/gps/service/OpenApiGenerationTest.java
Lines 30 to 49 in 998e8e7
@Test | |
void swaggerSpringPlugin() throws Exception { | |
mvc.perform(MockMvcRequestBuilders.get("/v3/api-docs").accept(MediaType.APPLICATION_JSON)) | |
.andExpect(MockMvcResultMatchers.status().is2xxSuccessful()) | |
.andDo( | |
result -> { | |
assertNotNull(result); | |
assertNotNull(result.getResponse()); | |
final String content = result.getResponse().getContentAsString(); | |
assertFalse(content.isBlank()); | |
assertFalse(content.contains("${"), "Generated swagger contains placeholders"); | |
Object swagger = | |
objectMapper.readValue(result.getResponse().getContentAsString(), Object.class); | |
String formatted = | |
objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(swagger); | |
Path basePath = Paths.get("openapi/"); | |
Files.createDirectories(basePath); | |
Files.write(basePath.resolve("openapi.json"), formatted.getBytes()); | |
}); | |
} |
[google-java-format] reported by reviewdog 🐶
Line 3 in 998e8e7
import org.junit.jupiter.api.Test; |
[google-java-format] reported by reviewdog 🐶
Lines 9 to 11 in 998e8e7
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; | |
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | |
[google-java-format] reported by reviewdog 🐶
Lines 16 to 17 in 998e8e7
@Autowired | |
private MockMvc mvc; |
[google-java-format] reported by reviewdog 🐶
Lines 19 to 23 in 998e8e7
@Test | |
void healthCheckTestSuccess() throws Exception { | |
mvc.perform(get("/info")).andExpect(status().isOk()); | |
} | |
} |
[google-java-format] reported by reviewdog 🐶
Line 3 in 998e8e7
import com.fasterxml.jackson.databind.ObjectMapper; |
[google-java-format] reported by reviewdog 🐶
Lines 4 to 5 in 998e8e7
import it.gov.pagopa.mbd.gps.service.model.MbdPaymentOptionRequestProperties; | |
import it.gov.pagopa.mbd.gps.service.model.PaymentOption; |
[google-java-format] reported by reviewdog 🐶
Line 7 in 998e8e7
import it.gov.pagopa.mbd.gps.service.model.MbdPaymentOptionResponse; |
[google-java-format] reported by reviewdog 🐶
Line 8 in 998e8e7
import it.gov.pagopa.mbd.gps.service.model.Transfer; |
[google-java-format] reported by reviewdog 🐶
Lines 17 to 23 in 998e8e7
import static org.junit.jupiter.api.Assertions.assertEquals; | |
import static org.junit.jupiter.api.Assertions.assertFalse; | |
import static org.junit.jupiter.api.Assertions.assertNotNull; | |
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; | |
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; | |
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | |
[google-java-format] reported by reviewdog 🐶
Lines 28 to 173 in 998e8e7
@Autowired | |
private MockMvc mvc; | |
@Autowired | |
private ObjectMapper objectMapper; | |
@Test | |
void createMdbPaymentOptionTestSuccess() throws Exception { | |
MbdPaymentOptionRequest request = buildMdbPaymentOptionRequest(); | |
MvcResult result = mvc.perform(post("/mbd/paymentOption") | |
.content(objectMapper.writeValueAsString(request)) | |
.contentType(MediaType.APPLICATION_JSON)) | |
.andExpect(status().isCreated()) | |
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE)) | |
.andReturn(); | |
String json = result.getResponse().getContentAsString(); | |
assertNotNull(json); | |
MbdPaymentOptionResponse response = objectMapper.readValue(json, MbdPaymentOptionResponse.class); | |
assertNotNull(response); | |
assertNotNull(response.getPaymentOption()); | |
assertEquals(1, response.getPaymentOption().size()); | |
PaymentOption paymentOption = response.getPaymentOption().get(0); | |
assertEquals(request.getProperties().getFirstName(), paymentOption.getFirstName()); | |
assertEquals(request.getProperties().getLastName(), paymentOption.getLastName()); | |
assertEquals(request.getProperties().getAmount(), paymentOption.getAmount()); | |
assertNotNull(paymentOption.getDescription()); | |
assertNotNull(paymentOption.getDueDate()); | |
assertNotNull(paymentOption.getRetentionDate()); | |
assertFalse(paymentOption.getIsPartialPayment()); | |
assertNotNull(paymentOption.getTransfer()); | |
assertEquals(1, paymentOption.getTransfer().size()); | |
Transfer transfer = paymentOption.getTransfer().get(0); | |
assertEquals(request.getProperties().getAmount(), transfer.getAmount()); | |
assertEquals(request.getProperties().getFiscalCode(), transfer.getOrganizationFiscalCode()); | |
assertEquals("1", transfer.getIdTransfer()); | |
assertNotNull(transfer.getRemittanceInformation()); | |
assertNotNull(transfer.getStamp()); | |
assertEquals(request.getProperties().getProvincialResidence(), transfer.getStamp().getProvincialResidence()); | |
assertEquals(request.getProperties().getDocumentHash(), transfer.getStamp().getHashDocument()); | |
assertEquals("st", transfer.getStamp().getStampType()); | |
} | |
@Test | |
void createMdbPaymentOptionTestFailAmountMissing() throws Exception { | |
MbdPaymentOptionRequest request = buildMdbPaymentOptionRequest(); | |
request.getProperties().setAmount(null); | |
mvc.perform(post("/mbd/paymentOption") | |
.content(objectMapper.writeValueAsString(request)) | |
.contentType(MediaType.APPLICATION_JSON)) | |
.andExpect(status().is4xxClientError()); | |
} | |
@Test | |
void createMdbPaymentOptionTestFailFirstNameMissing() throws Exception { | |
MbdPaymentOptionRequest request = buildMdbPaymentOptionRequest(); | |
request.getProperties().setFirstName(null); | |
mvc.perform(post("/mbd/paymentOption") | |
.content(objectMapper.writeValueAsString(request)) | |
.contentType(MediaType.APPLICATION_JSON)) | |
.andExpect(status().is4xxClientError()); | |
} | |
@Test | |
void createMdbPaymentOptionTestFailLastNameMissing() throws Exception { | |
MbdPaymentOptionRequest request = buildMdbPaymentOptionRequest(); | |
request.getProperties().setLastName(null); | |
mvc.perform(post("/mbd/paymentOption") | |
.content(objectMapper.writeValueAsString(request)) | |
.contentType(MediaType.APPLICATION_JSON)) | |
.andExpect(status().is4xxClientError()); | |
} | |
@Test | |
void createMdbPaymentOptionTestFailFiscalCodeMissing() throws Exception { | |
MbdPaymentOptionRequest request = buildMdbPaymentOptionRequest(); | |
request.getProperties().setFiscalCode(null); | |
mvc.perform(post("/mbd/paymentOption") | |
.content(objectMapper.writeValueAsString(request)) | |
.contentType(MediaType.APPLICATION_JSON)) | |
.andExpect(status().is4xxClientError()); | |
} | |
@Test | |
void createMdbPaymentOptionTestFailProvincialResidenceMissing() throws Exception { | |
MbdPaymentOptionRequest request = buildMdbPaymentOptionRequest(); | |
request.getProperties().setProvincialResidence(null); | |
mvc.perform(post("/mbd/paymentOption") | |
.content(objectMapper.writeValueAsString(request)) | |
.contentType(MediaType.APPLICATION_JSON)) | |
.andExpect(status().is4xxClientError()); | |
} | |
@Test | |
void createMdbPaymentOptionTestFailDocumentHashMissing() throws Exception { | |
MbdPaymentOptionRequest request = buildMdbPaymentOptionRequest(); | |
request.getProperties().setDocumentHash(null); | |
mvc.perform(post("/mbd/paymentOption") | |
.content(objectMapper.writeValueAsString(request)) | |
.contentType(MediaType.APPLICATION_JSON)) | |
.andExpect(status().is4xxClientError()); | |
} | |
@Test | |
void createMdbPaymentOptionTestFailDocumentHashWrongSize() throws Exception { | |
MbdPaymentOptionRequest request = buildMdbPaymentOptionRequest(); | |
request.getProperties().setDocumentHash("asdfsdf"); | |
mvc.perform(post("/mbd/paymentOption") | |
.content(objectMapper.writeValueAsString(request)) | |
.contentType(MediaType.APPLICATION_JSON)) | |
.andExpect(status().is4xxClientError()); | |
} | |
private MbdPaymentOptionRequest buildMdbPaymentOptionRequest() { | |
return MbdPaymentOptionRequest.builder() | |
.properties(MbdPaymentOptionRequestProperties.builder() | |
.amount(16L) | |
.firstName("Mario") | |
.lastName("Rossi") | |
.fiscalCode("0000000000000000") | |
.provincialResidence("AS") | |
.documentHash("1trA5qyjSZNwiwtGG46dyjRpL16TFgGCFvnfFzQrFHbB") | |
.build()) | |
.build(); | |
} | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remaining comments which cannot be posted as a review comment to avoid GitHub Rate Limit
google-java-format
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/test/java/it/gov/pagopa/mbd/gps/service/OpenApiGenerationTest.java
Lines 13 to 19 in 83cc121
import java.nio.file.Files; | |
import java.nio.file.Path; | |
import java.nio.file.Paths; | |
import static org.junit.jupiter.api.Assertions.assertFalse; | |
import static org.junit.jupiter.api.Assertions.assertNotNull; | |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/test/java/it/gov/pagopa/mbd/gps/service/OpenApiGenerationTest.java
Lines 24 to 25 in 83cc121
@Autowired | |
ObjectMapper objectMapper; |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/test/java/it/gov/pagopa/mbd/gps/service/OpenApiGenerationTest.java
Lines 27 to 28 in 83cc121
@Autowired | |
private MockMvc mvc; |
[google-java-format] reported by reviewdog 🐶
pagopa-gps-mbd-service/src/test/java/it/gov/pagopa/mbd/gps/service/OpenApiGenerationTest.java
Lines 30 to 49 in 83cc121
@Test | |
void swaggerSpringPlugin() throws Exception { | |
mvc.perform(MockMvcRequestBuilders.get("/v3/api-docs").accept(MediaType.APPLICATION_JSON)) | |
.andExpect(MockMvcResultMatchers.status().is2xxSuccessful()) | |
.andDo( | |
result -> { | |
assertNotNull(result); | |
assertNotNull(result.getResponse()); | |
final String content = result.getResponse().getContentAsString(); | |
assertFalse(content.isBlank()); | |
assertFalse(content.contains("${"), "Generated swagger contains placeholders"); | |
Object swagger = | |
objectMapper.readValue(result.getResponse().getContentAsString(), Object.class); | |
String formatted = | |
objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(swagger); | |
Path basePath = Paths.get("openapi/"); | |
Files.createDirectories(basePath); | |
Files.write(basePath.resolve("openapi.json"), formatted.getBytes()); | |
}); | |
} |
[google-java-format] reported by reviewdog 🐶
Line 3 in 83cc121
import org.junit.jupiter.api.Test; |
[google-java-format] reported by reviewdog 🐶
Lines 9 to 11 in 83cc121
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; | |
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | |
[google-java-format] reported by reviewdog 🐶
Lines 16 to 17 in 83cc121
@Autowired | |
private MockMvc mvc; |
[google-java-format] reported by reviewdog 🐶
Lines 19 to 23 in 83cc121
@Test | |
void healthCheckTestSuccess() throws Exception { | |
mvc.perform(get("/info")).andExpect(status().isOk()); | |
} | |
} |
[google-java-format] reported by reviewdog 🐶
Line 3 in 83cc121
import com.fasterxml.jackson.databind.ObjectMapper; |
[google-java-format] reported by reviewdog 🐶
Lines 4 to 5 in 83cc121
import it.gov.pagopa.mbd.gps.service.model.MbdPaymentOptionRequestProperties; | |
import it.gov.pagopa.mbd.gps.service.model.PaymentOption; |
[google-java-format] reported by reviewdog 🐶
Line 7 in 83cc121
import it.gov.pagopa.mbd.gps.service.model.MbdPaymentOptionResponse; |
[google-java-format] reported by reviewdog 🐶
Line 8 in 83cc121
import it.gov.pagopa.mbd.gps.service.model.Transfer; |
[google-java-format] reported by reviewdog 🐶
Lines 17 to 23 in 83cc121
import static org.junit.jupiter.api.Assertions.assertEquals; | |
import static org.junit.jupiter.api.Assertions.assertFalse; | |
import static org.junit.jupiter.api.Assertions.assertNotNull; | |
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; | |
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; | |
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | |
[google-java-format] reported by reviewdog 🐶
Lines 28 to 173 in 83cc121
@Autowired | |
private MockMvc mvc; | |
@Autowired | |
private ObjectMapper objectMapper; | |
@Test | |
void createMdbPaymentOptionTestSuccess() throws Exception { | |
MbdPaymentOptionRequest request = buildMdbPaymentOptionRequest(); | |
MvcResult result = mvc.perform(post("/mbd/paymentOption") | |
.content(objectMapper.writeValueAsString(request)) | |
.contentType(MediaType.APPLICATION_JSON)) | |
.andExpect(status().isCreated()) | |
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE)) | |
.andReturn(); | |
String json = result.getResponse().getContentAsString(); | |
assertNotNull(json); | |
MbdPaymentOptionResponse response = objectMapper.readValue(json, MbdPaymentOptionResponse.class); | |
assertNotNull(response); | |
assertNotNull(response.getPaymentOption()); | |
assertEquals(1, response.getPaymentOption().size()); | |
PaymentOption paymentOption = response.getPaymentOption().get(0); | |
assertEquals(request.getProperties().getFirstName(), paymentOption.getFirstName()); | |
assertEquals(request.getProperties().getLastName(), paymentOption.getLastName()); | |
assertEquals(request.getProperties().getAmount(), paymentOption.getAmount()); | |
assertNotNull(paymentOption.getDescription()); | |
assertNotNull(paymentOption.getDueDate()); | |
assertNotNull(paymentOption.getRetentionDate()); | |
assertFalse(paymentOption.getIsPartialPayment()); | |
assertNotNull(paymentOption.getTransfer()); | |
assertEquals(1, paymentOption.getTransfer().size()); | |
Transfer transfer = paymentOption.getTransfer().get(0); | |
assertEquals(request.getProperties().getAmount(), transfer.getAmount()); | |
assertEquals(request.getProperties().getFiscalCode(), transfer.getOrganizationFiscalCode()); | |
assertEquals("1", transfer.getIdTransfer()); | |
assertNotNull(transfer.getRemittanceInformation()); | |
assertNotNull(transfer.getStamp()); | |
assertEquals(request.getProperties().getProvincialResidence(), transfer.getStamp().getProvincialResidence()); | |
assertEquals(request.getProperties().getDocumentHash(), transfer.getStamp().getHashDocument()); | |
assertEquals("st", transfer.getStamp().getStampType()); | |
} | |
@Test | |
void createMdbPaymentOptionTestFailAmountMissing() throws Exception { | |
MbdPaymentOptionRequest request = buildMdbPaymentOptionRequest(); | |
request.getProperties().setAmount(null); | |
mvc.perform(post("/mbd/paymentOption") | |
.content(objectMapper.writeValueAsString(request)) | |
.contentType(MediaType.APPLICATION_JSON)) | |
.andExpect(status().is4xxClientError()); | |
} | |
@Test | |
void createMdbPaymentOptionTestFailFirstNameMissing() throws Exception { | |
MbdPaymentOptionRequest request = buildMdbPaymentOptionRequest(); | |
request.getProperties().setFirstName(null); | |
mvc.perform(post("/mbd/paymentOption") | |
.content(objectMapper.writeValueAsString(request)) | |
.contentType(MediaType.APPLICATION_JSON)) | |
.andExpect(status().is4xxClientError()); | |
} | |
@Test | |
void createMdbPaymentOptionTestFailLastNameMissing() throws Exception { | |
MbdPaymentOptionRequest request = buildMdbPaymentOptionRequest(); | |
request.getProperties().setLastName(null); | |
mvc.perform(post("/mbd/paymentOption") | |
.content(objectMapper.writeValueAsString(request)) | |
.contentType(MediaType.APPLICATION_JSON)) | |
.andExpect(status().is4xxClientError()); | |
} | |
@Test | |
void createMdbPaymentOptionTestFailFiscalCodeMissing() throws Exception { | |
MbdPaymentOptionRequest request = buildMdbPaymentOptionRequest(); | |
request.getProperties().setFiscalCode(null); | |
mvc.perform(post("/mbd/paymentOption") | |
.content(objectMapper.writeValueAsString(request)) | |
.contentType(MediaType.APPLICATION_JSON)) | |
.andExpect(status().is4xxClientError()); | |
} | |
@Test | |
void createMdbPaymentOptionTestFailProvincialResidenceMissing() throws Exception { | |
MbdPaymentOptionRequest request = buildMdbPaymentOptionRequest(); | |
request.getProperties().setProvincialResidence(null); | |
mvc.perform(post("/mbd/paymentOption") | |
.content(objectMapper.writeValueAsString(request)) | |
.contentType(MediaType.APPLICATION_JSON)) | |
.andExpect(status().is4xxClientError()); | |
} | |
@Test | |
void createMdbPaymentOptionTestFailDocumentHashMissing() throws Exception { | |
MbdPaymentOptionRequest request = buildMdbPaymentOptionRequest(); | |
request.getProperties().setDocumentHash(null); | |
mvc.perform(post("/mbd/paymentOption") | |
.content(objectMapper.writeValueAsString(request)) | |
.contentType(MediaType.APPLICATION_JSON)) | |
.andExpect(status().is4xxClientError()); | |
} | |
@Test | |
void createMdbPaymentOptionTestFailDocumentHashWrongSize() throws Exception { | |
MbdPaymentOptionRequest request = buildMdbPaymentOptionRequest(); | |
request.getProperties().setDocumentHash("asdfsdf"); | |
mvc.perform(post("/mbd/paymentOption") | |
.content(objectMapper.writeValueAsString(request)) | |
.contentType(MediaType.APPLICATION_JSON)) | |
.andExpect(status().is4xxClientError()); | |
} | |
private MbdPaymentOptionRequest buildMdbPaymentOptionRequest() { | |
return MbdPaymentOptionRequest.builder() | |
.properties(MbdPaymentOptionRequestProperties.builder() | |
.amount(16L) | |
.firstName("Mario") | |
.lastName("Rossi") | |
.fiscalCode("0000000000000000") | |
.provincialResidence("AS") | |
.documentHash("1trA5qyjSZNwiwtGG46dyjRpL16TFgGCFvnfFzQrFHbB") | |
.build()) | |
.build(); | |
} | |
} |
…java Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
…figuration.java Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
This PR exceeds the recommended size of 400 lines. Please make sure you are NOT addressing multiple issues with one PR. Note this PR might be rejected due to its size. |
Quality Gate passedIssues Measures |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great work @gioelemella
List of Changes
Motivation and Context
How Has This Been Tested?
Screenshots (if appropriate):
Types of changes
Checklist: