Skip to content

Commit

Permalink
[PAGOPA-2382] refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
cap-ang committed Nov 18, 2024
1 parent 6ce742e commit 347e4cc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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")
Expand All @@ -35,15 +37,15 @@ 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))),
@ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content(schema = @Schema())),
@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<UploadReport> recoverStatus(
@Parameter(description = "The broker code", required = true)
@NotBlank @PathVariable(name = "broker") String broker,
Expand All @@ -53,7 +55,8 @@ public HttpResponse<UploadReport> 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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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);
}
Expand Down

0 comments on commit 347e4cc

Please sign in to comment.