Skip to content

Commit

Permalink
[PAGOPA-2282] refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
cap-ang committed Oct 25, 2024
1 parent 2ca8902 commit 556daf0
Showing 1 changed file with 52 additions and 29 deletions.
81 changes: 52 additions & 29 deletions src/main/java/it/gov/pagopa/fdr/service/psps/PspsService.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;
import org.jboss.logging.Logger;
import org.jboss.logging.MDC;
Expand Down Expand Up @@ -330,50 +331,72 @@ public void publishByFdr(String action, String pspId, String fdr, boolean intern
fdrPublishEntity.persistEntity();

log.info("Starting saveOnStorage storage on BlobStorage of FDR payment entities");
historyService.asyncSaveOnStorage(fdrPublishEntity, fdrPaymentPublishEntities);
log.info("End of saveOnStorage storage on BlobStorage of FDR payment entities");

log.info("Starting delete FdrInsertEntity");
fdrEntity.delete();
log.infof(
"Delete FdrPaymentInsertEntity by fdr[%s], pspId[%s]", fdrEntity.getRevision(), fdr, pspId);
FdrPaymentInsertEntity.deleteByFdrAndPspId(fdr, pspId);
log.info("End delete deleteByFdrAndPspId");
CompletableFuture<Boolean> executeSaveOnStorage = CompletableFuture.supplyAsync(() -> {
historyService.saveOnStorage(fdrPublishEntity, fdrPaymentPublishEntities);
log.info("Async saveOnStorage successful executed");
return true;
});
executeSaveOnStorage
.thenAccept(value -> {
log.info("End of saveOnStorage storage on BlobStorage of FDR payment entities");

log.info("Starting delete FdrInsertEntity");
fdrEntity.delete();
log.infof(
"Delete FdrPaymentInsertEntity by fdr[%s], pspId[%s]", fdrEntity.getRevision(), fdr, pspId);

Check failure

Code scanning / CodeQL

Log Injection High

This log entry depends on a
user-provided value
.
This log entry depends on a
user-provided value
.

Check failure

Code scanning / CodeQL

Log Injection High

This log entry depends on a
user-provided value
.
This log entry depends on a
user-provided value
.
FdrPaymentInsertEntity.deleteByFdrAndPspId(fdr, pspId);
log.info("End delete deleteByFdrAndPspId");
log.info("Starting conversion to queue");
this.addToConversionQueue(internalPublish, fdrEntity);
log.info("End of conversion to queue");
log.info("Starting write to re");
this.rePublish(fdr, pspId, fdrPublishEntity);
log.info("End of write to re");
})
.exceptionally(e -> {
log.error("Exception during async saveOnStorage: ", e);
return null;
});
}

private void addToConversionQueue(boolean internalPublish, FdrInsertEntity fdrEntity) {
// add to conversion queue
if (internalPublish) {
log.info("NOT Add FdrInsertEntity in queue fdr message");
} else {
log.info("Starting add FdrInsertEntity in queue fdr message");
conversionQueue.addQueueFlowMessage(
FdrMessage.builder()
.fdr(fdrEntity.getFdr())
.pspId(fdrEntity.getSender().getPspId())
.organizationId(fdrEntity.getReceiver().getOrganizationId())
.retry(0L)
.revision(fdrEntity.getRevision())
.build());
FdrMessage.builder()
.fdr(fdrEntity.getFdr())
.pspId(fdrEntity.getSender().getPspId())
.organizationId(fdrEntity.getReceiver().getOrganizationId())
.retry(0L)
.revision(fdrEntity.getRevision())
.build());
log.info("End add FdrInsertEntity in queue fdr message");
}
}

private void rePublish(String fdr, String pspId, FdrPublishEntity fdrPublishEntity) {
String sessionId = (String) MDC.get(TRX_ID);
MDC.put(EVENT_CATEGORY, EventTypeEnum.INTERNAL.name());
reService.sendEvent(
ReInternal.builder()
.serviceIdentifier(AppVersionEnum.FDR003)
.created(Instant.now())
.sessionId(sessionId)
.eventType(EventTypeEnum.INTERNAL)
.fdrPhysicalDelete(false)
.fdrStatus(FdrStatusEnum.PUBLISHED)
.fdr(fdr)
.pspId(pspId)
.organizationId(fdrPublishEntity.getReceiver().getOrganizationId())
.revision(fdrPublishEntity.getRevision())
.fdrAction(FdrActionEnum.PUBLISH)
.build());
ReInternal.builder()
.serviceIdentifier(AppVersionEnum.FDR003)
.created(Instant.now())
.sessionId(sessionId)
.eventType(EventTypeEnum.INTERNAL)
.fdrPhysicalDelete(false)
.fdrStatus(FdrStatusEnum.PUBLISHED)
.fdr(fdr)
.pspId(pspId)
.organizationId(fdrPublishEntity.getReceiver().getOrganizationId())
.revision(fdrPublishEntity.getRevision())
.fdrAction(FdrActionEnum.PUBLISH)
.build());
}


@WithSpan(kind = SERVER)
public void deleteByFdr(String action, String pspId, String fdr) {
log.infof(AppMessageUtil.logExecute(action));
Expand Down

0 comments on commit 556daf0

Please sign in to comment.