Skip to content

Commit

Permalink
chore: Recovery by partition (#142)
Browse files Browse the repository at this point in the history
  • Loading branch information
aomegax authored Oct 10, 2024
1 parent 9abe3d1 commit a18c3e5
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import it.gov.pagopa.wispconverter.controller.model.RecoveryReceiptByPartitionRequest;
import it.gov.pagopa.wispconverter.controller.model.RecoveryReceiptReportResponse;
import it.gov.pagopa.wispconverter.controller.model.RecoveryReceiptRequest;
import it.gov.pagopa.wispconverter.controller.model.RecoveryReceiptResponse;
Expand Down Expand Up @@ -92,7 +93,7 @@ public ResponseEntity<RecoveryReceiptResponse> recoverReceiptKOForCreditorInstit

@Operation(summary = "Execute reconciliation for passed receipts.", description = "Execute reconciliation of all receipts in the request, searching by passed identifier", security = {@SecurityRequirement(name = "ApiKey")}, tags = {"Recovery"})
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Reconciliation completed")
@ApiResponse(responseCode = "200", description = "Reconciliation scheduled")
})
@PostMapping(value = "/receipts")
public ResponseEntity<RecoveryReceiptReportResponse> recoverReceiptToBeReSent(@RequestBody RecoveryReceiptRequest request) {
Expand All @@ -108,4 +109,23 @@ public ResponseEntity<RecoveryReceiptReportResponse> recoverReceiptToBeReSent(@R
throw ex;
}
}

@Operation(summary = "Execute reconciliation for passed receipts by partition.", description = "Execute reconciliation of all receipts contained in the partitions of the request", security = {@SecurityRequirement(name = "ApiKey")}, tags = {"Recovery"})
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Reconciliation scheduled")
})
@PostMapping(value = "/partitions")
public ResponseEntity<RecoveryReceiptReportResponse> recoverReceiptToBeReSentByPartition(@RequestBody RecoveryReceiptByPartitionRequest request) {
try {
log.info("Invoking API operation recoverReceiptToBeReSentByPartition - args: {}", request);

Check failure

Code scanning / CodeQL

Log Injection High

This log entry depends on a
user-provided value
.
return ResponseEntity.ok(recoveryService.recoverReceiptToBeReSentByPartition(request));
} catch (Exception ex) {
String operationId = MDC.get(Constants.MDC_OPERATION_ID);
log.error(String.format("GenericException: operation-id=[%s]", operationId != null ? operationId : "n/a"), ex);
AppException appException = new AppException(ex, AppErrorCodeMessageEnum.ERROR, ex.getMessage());
ErrorResponse errorResponse = errorUtil.forAppException(appException);
log.error("Failed API operation recoverReceiptToBeReSentByPartition - error: {}", errorResponse);
throw ex;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package it.gov.pagopa.wispconverter.controller.model;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

import java.util.List;

@Data
@Builder(toBuilder = true)
@NoArgsConstructor
@AllArgsConstructor
@ToString
@JsonIgnoreProperties(ignoreUnknown = true)
public class RecoveryReceiptByPartitionRequest {

private List<String> partitionKeys;
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
import java.util.List;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;

@Service
@Slf4j
Expand Down Expand Up @@ -243,6 +245,21 @@ private void generateRE(String primitive, String operationStatus, InternalStepSt
reService.addRe(reEvent);
}

public RecoveryReceiptReportResponse recoverReceiptToBeReSentByPartition(RecoveryReceiptByPartitionRequest request) {

List<String> receiptsIds = request.getPartitionKeys().stream()
.map(PartitionKey::new)
.flatMap(partitionKey -> StreamSupport.stream(rtRetryRepository.findAll(partitionKey).spliterator(), false))
.map(RTRequestEntity::getId)
.toList();

RecoveryReceiptRequest req = RecoveryReceiptRequest.builder()
.receiptIds(receiptsIds)
.build();

return recoverReceiptToBeReSent(req);
}

public RecoveryReceiptReportResponse recoverReceiptToBeReSent(RecoveryReceiptRequest request) {

RecoveryReceiptReportResponse response = RecoveryReceiptReportResponse.builder()
Expand Down

0 comments on commit a18c3e5

Please sign in to comment.