Skip to content

Commit 3600523

Browse files
fix: updated retrieveSignedFile
1 parent ae70f43 commit 3600523

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

apps/onboarding-ms/src/main/java/it/pagopa/selfcare/onboarding/service/impl/TokenServiceDefault.java

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,15 +146,28 @@ public Uni<RestResponse<File>> retrieveSignedFile(String onboardingId) {
146146
.onItem().transformToUni(token -> Uni.createFrom().item(() -> azureBlobClient.retrieveFile(token.getContractSigned()))
147147
.runSubscriptionOn(Executors.newSingleThreadExecutor())
148148
.onItem().transform(contract -> {
149+
File fileToSend = contract; // Di base mandiamo il contratto originale
150+
149151
if (token.getContractSigned().endsWith(".pdf")) {
150152
isPdfValid(contract);
151153
} else {
152154
isP7mValid(contract, signatureService);
153-
File original = signatureService.extractFile(contract);
154-
isPdfValid(original);
155+
// Sovrascriviamo fileToSend con il PDF estratto per permettere la visualizzazione
156+
fileToSend = signatureService.extractFile(contract);
157+
isPdfValid(fileToSend);
155158
}
156-
RestResponse.ResponseBuilder<File> response = RestResponse.ResponseBuilder.ok(contract, MediaType.APPLICATION_OCTET_STREAM);
157-
response.header(HTTP_HEADER_CONTENT_DISPOSITION, HTTP_HEADER_VALUE_ATTACHMENT_FILENAME + getCurrentContractName(token, true));
159+
160+
// Nota: Usa fileToSend invece di contract
161+
RestResponse.ResponseBuilder<File> response = RestResponse.ResponseBuilder.ok(fileToSend, MediaType.APPLICATION_OCTET_STREAM);
162+
163+
// Opzionale: Se vuoi essere gentile col browser, cambia l'estensione nel nome file da .p7m a .pdf
164+
// così quando l'utente salva, lo salva come PDF leggibile.
165+
String filename = getCurrentContractName(token, true);
166+
if(filename.endsWith(".p7m")) {
167+
filename = filename.replace(".p7m", "");
168+
}
169+
response.header(HTTP_HEADER_CONTENT_DISPOSITION, HTTP_HEADER_VALUE_ATTACHMENT_FILENAME + filename);
170+
158171
return response.build();
159172
}).onFailure().recoverWithUni(() -> Uni.createFrom().item(RestResponse.ResponseBuilder.<File>notFound().build())));
160173
}

0 commit comments

Comments
 (0)