diff --git a/src/main/java/it/gov/pagopa/gpd/upload/controller/SupportController.java b/src/main/java/it/gov/pagopa/gpd/upload/controller/SupportController.java index 6ad9fcf..e71288d 100644 --- a/src/main/java/it/gov/pagopa/gpd/upload/controller/SupportController.java +++ b/src/main/java/it/gov/pagopa/gpd/upload/controller/SupportController.java @@ -4,8 +4,8 @@ import io.micronaut.http.HttpStatus; import io.micronaut.http.MediaType; import io.micronaut.http.annotation.Controller; +import io.micronaut.http.annotation.Get; import io.micronaut.http.annotation.PathVariable; -import io.micronaut.http.annotation.Post; import io.micronaut.scheduling.TaskExecutors; import io.micronaut.scheduling.annotation.ExecuteOn; import io.swagger.v3.oas.annotations.Operation; @@ -23,7 +23,9 @@ import it.gov.pagopa.gpd.upload.service.StatusService; import jakarta.inject.Inject; import jakarta.validation.constraints.NotBlank; +import lombok.extern.slf4j.Slf4j; +@Slf4j @Tag(name = "Support API") @ExecuteOn(TaskExecutors.IO) @Controller("support") @@ -35,7 +37,7 @@ public class SupportController { @Inject StatusService statusService; - @Operation(summary = "Support API to recover status", description = "Returns the debt positions upload status.", tags = {"support"}) + @Operation(summary = "Support API to recover status on CREATE operation", description = "Returns the debt positions upload report recovered.", tags = {"support"}) @ApiResponses(value = { @ApiResponse(responseCode = "200", description = "OK", content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = @Schema(implementation = AppInfo.class))), @ApiResponse(responseCode = "400", description = "Bad Request", content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = @Schema(implementation = ProblemJson.class))), @@ -43,7 +45,7 @@ public class SupportController { @ApiResponse(responseCode = "403", description = "Forbidden", content = @Content(schema = @Schema())), @ApiResponse(responseCode = "429", description = "Too many requests.", content = @Content(mediaType = MediaType.TEXT_JSON)), @ApiResponse(responseCode = "500", description = "Service unavailable", content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = @Schema(implementation = ProblemJson.class)))}) - @Post(value = "brokers/{broker}/organizations/{organization}/{upload}/status") + @Get(value = "brokers/{broker}/organizations/{organization}/{upload}/status/created/refresh") public HttpResponse recoverStatus( @Parameter(description = "The broker code", required = true) @NotBlank @PathVariable(name = "broker") String broker, @@ -53,7 +55,8 @@ public HttpResponse recoverStatus( @NotBlank @PathVariable(name = "upload") String upload ) { Status status = recoveryService.recover(broker, organization, upload); - UploadReport report = statusService.mapReport(status); + log.info("[Support-API] Status {} recovered", status.getId()); + UploadReport report = statusService.getReport(organization, upload); return HttpResponse.status(HttpStatus.OK) .contentType(MediaType.APPLICATION_JSON) diff --git a/src/main/java/it/gov/pagopa/gpd/upload/service/RecoveryService.java b/src/main/java/it/gov/pagopa/gpd/upload/service/RecoveryService.java index 209e831..439f1f2 100644 --- a/src/main/java/it/gov/pagopa/gpd/upload/service/RecoveryService.java +++ b/src/main/java/it/gov/pagopa/gpd/upload/service/RecoveryService.java @@ -6,10 +6,13 @@ import it.gov.pagopa.gpd.upload.entity.Status; import it.gov.pagopa.gpd.upload.exception.AppException; import it.gov.pagopa.gpd.upload.model.UploadInput; +import it.gov.pagopa.gpd.upload.model.UploadOperation; import it.gov.pagopa.gpd.upload.model.pd.PaymentPositionModel; import jakarta.inject.Inject; import jakarta.inject.Singleton; import lombok.extern.slf4j.Slf4j; + +import java.time.LocalDateTime; import java.util.ArrayList; import java.util.HashSet; import java.util.List; @@ -33,6 +36,10 @@ public Status recover(String brokerId, String organizationFiscalCode, String upl Status current = statusService.getStatus(organizationFiscalCode, uploadId); UploadInput uploadInput = blobService.getUploadInput(brokerId, organizationFiscalCode, uploadId); + if(!uploadInput.getUploadOperation().equals(UploadOperation.CREATE)) + throw new AppException(HttpStatus.NOT_FOUND, + "Upload operation not processable", String.format("Not exists create operation with upload-id %s", uploadId)); + // check if upload is pending if(current.upload.getCurrent() >= current.upload.getTotal()) return current; @@ -54,6 +61,7 @@ public Status recover(String brokerId, String organizationFiscalCode, String upl .statusCode(HttpStatus.CREATED.getCode()) .statusMessage(statusService.getDetail(HttpStatus.CREATED)) .build()); + current.upload.setEnd(LocalDateTime.now()); return statusService.upsert(current); }