Skip to content

Commit

Permalink
[SELC-3996] feat: Introduce New v2 onboarding/company Endpoint (#240)
Browse files Browse the repository at this point in the history
* client onboarding-ms onboarding company

* service

* endpoint v2 /company/onboarding

* open api
  • Loading branch information
manuraf authored Jan 29, 2024
1 parent b63a7af commit e95fbd1
Show file tree
Hide file tree
Showing 11 changed files with 249 additions and 5 deletions.
87 changes: 86 additions & 1 deletion app/src/main/resources/swagger/api-docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -1321,12 +1321,97 @@
} ]
}
},
"/v2/institutions/onboarding" : {
"/v2/institutions/company/onboarding" : {
"post" : {
"tags" : [ "institutions" ],
"summary" : "onboarding",
"description" : "The service allows the onboarding of Users to a subunit of an Institution",
"operationId" : "onboardingUsingPOST_3",
"requestBody" : {
"content" : {
"application/json" : {
"schema" : {
"$ref" : "#/components/schemas/CompanyOnboardingDto"
}
}
}
},
"responses" : {
"201" : {
"description" : "Created"
},
"400" : {
"description" : "Bad Request",
"content" : {
"application/problem+json" : {
"schema" : {
"$ref" : "#/components/schemas/Problem"
}
}
}
},
"401" : {
"description" : "Unauthorized",
"content" : {
"application/problem+json" : {
"schema" : {
"$ref" : "#/components/schemas/Problem"
}
}
}
},
"403" : {
"description" : "Forbidden",
"content" : {
"application/problem+json" : {
"schema" : {
"$ref" : "#/components/schemas/Problem"
}
}
}
},
"404" : {
"description" : "Not Found",
"content" : {
"application/problem+json" : {
"schema" : {
"$ref" : "#/components/schemas/Problem"
}
}
}
},
"409" : {
"description" : "Conflict",
"content" : {
"application/problem+json" : {
"schema" : {
"$ref" : "#/components/schemas/Problem"
}
}
}
},
"500" : {
"description" : "Internal Server Error",
"content" : {
"application/problem+json" : {
"schema" : {
"$ref" : "#/components/schemas/Problem"
}
}
}
}
},
"security" : [ {
"bearerAuth" : [ "global" ]
} ]
}
},
"/v2/institutions/onboarding" : {
"post" : {
"tags" : [ "institutions" ],
"summary" : "onboarding",
"description" : "The service allows the onboarding of Users to a subunit of an Institution",
"operationId" : "onboardingUsingPOST_4",
"requestBody" : {
"content" : {
"application/json" : {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
public interface OnboardingMsConnector {
void onboarding(OnboardingData onboardingData);

void onboardingCompany(OnboardingData onboardingData);

void onboardingTokenComplete(String onboardingId, MultipartFile contract);

void onboardingPending(String onboardingId);
Expand Down
68 changes: 68 additions & 0 deletions connector/rest/docs/openapi/api-selfcare-onboarding-docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,41 @@
} ]
}
},
"/v1/onboarding/pg/completion" : {
"post" : {
"tags" : [ "Onboarding Controller" ],
"requestBody" : {
"content" : {
"application/json" : {
"schema" : {
"$ref" : "#/components/schemas/OnboardingPgRequest"
}
}
}
},
"responses" : {
"200" : {
"description" : "OK",
"content" : {
"application/json" : {
"schema" : {
"$ref" : "#/components/schemas/OnboardingResponse"
}
}
}
},
"401" : {
"description" : "Not Authorized"
},
"403" : {
"description" : "Not Allowed"
}
},
"security" : [ {
"SecurityScheme" : [ ]
} ]
}
},
"/v1/onboarding/psp" : {
"post" : {
"tags" : [ "Onboarding Controller" ],
Expand Down Expand Up @@ -1001,6 +1036,39 @@
}
}
},
"OnboardingPgRequest" : {
"required" : [ "productId", "users", "taxCode", "origin", "digitalAddress" ],
"type" : "object",
"properties" : {
"productId" : {
"minLength" : 1,
"type" : "string"
},
"users" : {
"minItems" : 1,
"type" : "array",
"items" : {
"$ref" : "#/components/schemas/UserRequest"
}
},
"taxCode" : {
"type" : "string"
},
"businessName" : {
"type" : "string"
},
"origin" : {
"$ref" : "#/components/schemas/Origin"
},
"digitalAddress" : {
"pattern" : "\\S",
"type" : "string"
},
"userRequestUid" : {
"type" : "string"
}
}
},
"OnboardingPspRequest" : {
"required" : [ "productId", "users", "institution" ],
"type" : "object",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ public void onboarding(OnboardingData onboardingData) {
}
}


@Override
public void onboardingCompany(OnboardingData onboardingData) {
msOnboardingApiClient._v1OnboardingPgCompletionPost(onboardingMapper.toOnboardingPgRequest(onboardingData));
}

@Override
public void onboardingTokenComplete(String onboardingId, MultipartFile contract) {
msOnboardingApiClient._v1OnboardingOnboardingIdCompletePut(onboardingId, contract);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ public interface OnboardingMapper {
@Mapping(target = "additionalInformations", source = "institutionUpdate.additionalInformations")
OnboardingDefaultRequest toOnboardingDefaultRequest(OnboardingData onboardingData);

@Mapping(target = "taxCode", source = "institutionUpdate.taxCode")
@Mapping(target = "digitalAddress", source = "institutionUpdate.digitalAddress")
OnboardingPgRequest toOnboardingPgRequest(OnboardingData onboardingData);

GeographicTaxonomyDto toGeographicTaxonomyDto(GeographicTaxonomy geographicTaxonomy);

@Named("toInstitutionBase")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
import it.pagopa.selfcare.onboarding.connector.rest.client.MsOnboardingApiClient;
import it.pagopa.selfcare.onboarding.connector.rest.mapper.OnboardingMapper;
import it.pagopa.selfcare.onboarding.connector.rest.mapper.OnboardingMapperImpl;
import it.pagopa.selfcare.onboarding.generated.openapi.v1.dto.OnboardingDefaultRequest;
import it.pagopa.selfcare.onboarding.generated.openapi.v1.dto.OnboardingGet;
import it.pagopa.selfcare.onboarding.generated.openapi.v1.dto.OnboardingPaRequest;
import it.pagopa.selfcare.onboarding.generated.openapi.v1.dto.OnboardingPspRequest;
import it.pagopa.selfcare.onboarding.generated.openapi.v1.dto.*;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.function.Executable;
Expand Down Expand Up @@ -116,6 +113,27 @@ void onboarding_institutionPsp() {
assertNotNull(actual.getInstitution().getDataProtectionOfficer());
verifyNoMoreInteractions(msOnboardingApiClient);
}
@Test
void onboardingCompany() {
// given
OnboardingData onboardingData = new OnboardingData();
onboardingData.setTaxCode("taxCode");
onboardingData.setInstitutionType(InstitutionType.PG);
InstitutionUpdate institutionUpdate = new InstitutionUpdate();
institutionUpdate.setTaxCode("taxCode");
onboardingData.setUsers(List.of(mockInstance(new User())));
onboardingData.setInstitutionUpdate(institutionUpdate);
// when
onboardingMsConnector.onboardingCompany(onboardingData);
// then
ArgumentCaptor<OnboardingPgRequest> onboardingRequestCaptor = ArgumentCaptor.forClass(OnboardingPgRequest.class);
verify(msOnboardingApiClient, times(1))
._v1OnboardingPgCompletionPost(onboardingRequestCaptor.capture());
OnboardingPgRequest actual = onboardingRequestCaptor.getValue();
assertEquals(actual.getTaxCode(), institutionUpdate.getTaxCode());
assertEquals(actual.getDigitalAddress(), institutionUpdate.getDigitalAddress());
verifyNoMoreInteractions(msOnboardingApiClient);
}

@Test
void onboardingComplete() throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public interface InstitutionService {

void onboardingProductV2(OnboardingData onboardingData);

void onboardingCompanyV2(OnboardingData onboardingData);

void onboardingProduct(OnboardingData onboardingData);

void onboarding(OnboardingData onboardingData);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,13 @@ public void onboardingProductV2(OnboardingData onboardingData) {
onboardingMsConnector.onboarding(onboardingData);
log.trace("onboarding end");
}
@Override
public void onboardingCompanyV2(OnboardingData onboardingData) {
log.trace("onboardingProductAsync start");
log.debug("onboardingProductAsync onboardingData = {}", onboardingData);
onboardingMsConnector.onboardingCompany(onboardingData);
log.trace("onboarding end");
}

@Override
public void onboardingProduct(OnboardingData onboardingData) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,20 @@ void onboardingProductAsync() {
.onboarding(any());
}


@Test
void onboardingCompanyV2() {
// given
OnboardingData onboardingData = mockInstance(new OnboardingData(), "setInstitutionType", "setUsers");
onboardingData.setInstitutionType(InstitutionType.PG);
onboardingData.setUsers(List.of(dummyManager, dummyDelegate));
// when
institutionService.onboardingCompanyV2(onboardingData);
// then
verify(onboardingMsConnector, times(1))
.onboardingCompany(any());
}

@Test
void shouldOnboardingProductInstitutionNotPa() {
// given
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import it.pagopa.selfcare.commons.web.model.Problem;
import it.pagopa.selfcare.onboarding.core.InstitutionService;
import it.pagopa.selfcare.onboarding.web.model.CompanyOnboardingDto;
import it.pagopa.selfcare.onboarding.web.model.OnboardingProductDto;
import it.pagopa.selfcare.onboarding.web.model.mapper.OnboardingResourceMapper;
import lombok.extern.slf4j.Slf4j;
Expand Down Expand Up @@ -54,4 +55,22 @@ public void onboarding(@RequestBody @Valid OnboardingProductDto request) {
log.trace(ONBOARDING_END);
}



@ApiResponse(responseCode = "403",
description = "Forbidden",
content = {
@Content(mediaType = APPLICATION_PROBLEM_JSON_VALUE,
schema = @Schema(implementation = Problem.class))
})
@PostMapping(value = "/company/onboarding")
@ResponseStatus(HttpStatus.CREATED)
@ApiOperation(value = "", notes = "${swagger.onboarding.institutions.api.onboarding.subunit}")
public void onboarding(@RequestBody @Valid CompanyOnboardingDto request) {
log.trace(ONBOARDING_START);
log.debug("onboarding request = {}", request);
institutionService.onboardingCompanyV2(onboardingResourceMapper.toEntity(request));
log.trace(ONBOARDING_END);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,23 @@ void onboardingProductAsync(@Value("classpath:stubs/onboardingProductsDtoWithout
.onboardingProductV2(any(OnboardingData.class));
verifyNoMoreInteractions(institutionServiceMock);
}


@Test
void onboardingCompany(@Value("classpath:stubs/onboardingCompanyDto.json") Resource onboardingDto) throws Exception {

// when
mvc.perform(MockMvcRequestBuilders
.post(BASE_URL + "/company/onboarding")
.content(onboardingDto.getInputStream().readAllBytes())
.contentType(APPLICATION_JSON_VALUE)
.accept(APPLICATION_JSON_VALUE))
.andExpect(status().isCreated())
.andExpect(content().string(emptyString()));
// then

verify(institutionServiceMock, times(1))
.onboardingCompanyV2(any(OnboardingData.class));
verifyNoMoreInteractions(institutionServiceMock);
}
}

0 comments on commit e95fbd1

Please sign in to comment.