Skip to content

Commit

Permalink
[SELC-6133] feat: added attachments into response object for api v1/o…
Browse files Browse the repository at this point in the history
…nboarding/{onboardingId}/withUserInfo
  • Loading branch information
pierpaolodidato89 authored Dec 6, 2024
1 parent c5b4dcb commit a84f330
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 20 deletions.
6 changes: 6 additions & 0 deletions apps/onboarding-ms/src/main/docs/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -2373,6 +2373,12 @@
},
"reasonForReject" : {
"type" : "string"
},
"attachments" : {
"type" : "array",
"items" : {
"type" : "string"
}
}
}
},
Expand Down
4 changes: 4 additions & 0 deletions apps/onboarding-ms/src/main/docs/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1720,6 +1720,10 @@ components:
type: string
reasonForReject:
type: string
attachments:
type: array
items:
type: string
OnboardingGetResponse:
type: object
properties:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ public class OnboardingGet {
private String status;
private String userRequestUid;
private String reasonForReject;
private List<String> attachments;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
package it.pagopa.selfcare.onboarding.service;

import static it.pagopa.selfcare.onboarding.common.ProductId.PROD_INTEROP;
import static it.pagopa.selfcare.onboarding.common.ProductId.PROD_PAGOPA;
import static it.pagopa.selfcare.onboarding.constants.CustomError.*;
import static it.pagopa.selfcare.onboarding.util.ErrorMessage.*;
import static it.pagopa.selfcare.onboarding.util.Utils.CONTRACT_FILENAME_FUNC;
import static it.pagopa.selfcare.product.utils.ProductUtils.validRoles;

import eu.europa.esig.dss.enumerations.DigestAlgorithm;
import eu.europa.esig.dss.model.DSSDocument;
import eu.europa.esig.dss.model.FileDocument;
Expand Down Expand Up @@ -47,6 +54,15 @@
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import jakarta.ws.rs.WebApplicationException;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.time.LocalDateTime;
import java.time.OffsetDateTime;
import java.util.*;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.bson.Document;
Expand All @@ -70,23 +86,6 @@
import org.openapi.quarkus.user_registry_json.api.UserApi;
import org.openapi.quarkus.user_registry_json.model.*;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.time.LocalDateTime;
import java.time.OffsetDateTime;
import java.util.*;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Collectors;

import static it.pagopa.selfcare.onboarding.common.ProductId.PROD_INTEROP;
import static it.pagopa.selfcare.onboarding.common.ProductId.PROD_PAGOPA;
import static it.pagopa.selfcare.onboarding.constants.CustomError.*;
import static it.pagopa.selfcare.onboarding.util.ErrorMessage.*;
import static it.pagopa.selfcare.onboarding.util.Utils.CONTRACT_FILENAME_FUNC;
import static it.pagopa.selfcare.product.utils.ProductUtils.validRoles;

@ApplicationScoped
public class OnboardingServiceDefault implements OnboardingService {

Expand Down Expand Up @@ -164,6 +163,8 @@ public class OnboardingServiceDefault implements OnboardingService {
@Inject
SignatureService signatureService;
@Inject
TokenService tokenService;
@Inject
AzureBlobClient azureBlobClient;
@Inject
UserMapper userMapper;
Expand Down Expand Up @@ -1586,7 +1587,10 @@ public Uni<OnboardingGet> onboardingGetWithUserInfo(String onboardingId) {
OnboardingGet onboardingGet = onboardingMapper.toGetResponse(onboarding);
onboardingGet.setUsers(userResponses);
return onboardingGet;
}));
}))
.flatMap(onboardingGet -> tokenService.getAttachments(onboardingId)
.onItem().invoke(onboardingGet::setAttachments)
.replaceWith(onboardingGet));
}

private Uni<List<UserResponse>> toUserResponseWithUserInfo(List<User> users) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ public interface TokenService {
Uni<RestResponse<File>> retrieveContractNotSigned(String onboardingId);

Uni<RestResponse<File>> retrieveAttachment(String onboardingId, String attachmentName);

Uni<List<String>> getAttachments(String onboardingId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,9 @@ public class TokenServiceDefault implements TokenService {
private final AzureBlobClient azureBlobClient;
private final OnboardingMsConfig onboardingMsConfig;


public TokenServiceDefault(AzureBlobClient azureBlobClient, OnboardingMsConfig onboardingMsConfig) {
this.azureBlobClient = azureBlobClient;
this.onboardingMsConfig = onboardingMsConfig;

}

@Override
Expand Down Expand Up @@ -60,6 +58,14 @@ public Uni<RestResponse<File>> retrieveAttachment(String onboardingId, String at
}));
}

@Override
public Uni<List<String>> getAttachments(String onboardingId) {
return Token.find("onboardingId = ?1 and type = ?2", onboardingId, ATTACHMENT.name())
.stream().onItem().transform(Token.class::cast)
.map(Token::getName)
.collect().asList();
}

private String getAttachmentByOnboarding(String onboardingId, String filename) {
return String.format("%s%s%s%s",onboardingMsConfig.getContractPath(), onboardingId, "/attachments", "/" + filename);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ class OnboardingServiceDefaultTest {
@InjectMock
SignatureService signatureService;

@InjectMock
TokenService tokenService;

@InjectMock
@RestClient
OnboardingApi onboardingApi;
Expand Down Expand Up @@ -1808,6 +1811,9 @@ void onboardingGetWithUserInfo() {
when(userRegistryApi.findByIdUsingGET(anyString(), anyString()))
.thenReturn(Uni.createFrom().item(managerResource));

when(tokenService.getAttachments(any()))
.thenReturn(Uni.createFrom().item(List.of("filename")));

UniAssertSubscriber<OnboardingGet> subscriber = onboardingService
.onboardingGetWithUserInfo(onboarding.getId())
.subscribe()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import io.quarkus.test.common.QuarkusTestResource;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.mongodb.MongoTestResource;
import io.smallrye.mutiny.Multi;
import io.smallrye.mutiny.Uni;
import io.smallrye.mutiny.helpers.test.UniAssertSubscriber;
import it.pagopa.selfcare.azurestorage.AzureBlobClient;
Expand Down Expand Up @@ -90,4 +91,26 @@ void retrieveAttachment() {
Assertions.assertNotNull(actual);
Assertions.assertEquals(RestResponse.Status.OK.getStatusCode(), actual.getStatus());
}

@Test
void getTokenAttachments() {
final String filename = "filename";
Token token = new Token();
token.setContractFilename(filename);
token.setName(filename);
ReactivePanacheQuery queryPage = mock(ReactivePanacheQuery.class);
when(queryPage.stream()).thenReturn(Multi.createFrom().item(token));

PanacheMock.mock(Token.class);
when(Token.find("onboardingId = ?1 and type = ?2", onboardingId, ATTACHMENT.name()))
.thenReturn(queryPage);

UniAssertSubscriber<List<String>> subscriber = tokenService.getAttachments(onboardingId)
.subscribe().withSubscriber(UniAssertSubscriber.create());

List<String> actual = subscriber.awaitItem().getItem();
Assertions.assertNotNull(actual);
Assertions.assertFalse(actual.isEmpty());
Assertions.assertEquals(filename, actual.get(0));
}
}

0 comments on commit a84f330

Please sign in to comment.