Skip to content

Commit

Permalink
[SELC-6174] feat: rework onboarding completion logic (#642)
Browse files Browse the repository at this point in the history
  • Loading branch information
gianmarcoplutino authored Dec 10, 2024
1 parent 55c4b03 commit 157f7c3
Show file tree
Hide file tree
Showing 8 changed files with 109 additions and 262 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,18 @@
import java.util.Optional;

import static it.pagopa.selfcare.onboarding.entity.OnboardingWorkflowType.INSTITUTION;
import static it.pagopa.selfcare.onboarding.functions.utils.ActivityName.*;
import static it.pagopa.selfcare.onboarding.utils.Utils.getOnboardingWorkflowString;

public record WorkflowExecutorConfirmation(ObjectMapper objectMapper, TaskOptions optionsRetry) implements WorkflowExecutor {
public record WorkflowExecutorConfirmation(ObjectMapper objectMapper,
TaskOptions optionsRetry) implements WorkflowExecutor {

@Override
public Optional<OnboardingStatus> executeRequestState(TaskOrchestrationContext ctx, OnboardingWorkflow onboardingWorkflow) {
return Optional.empty();
String onboardingWorkflowString = getOnboardingWorkflowString(objectMapper, onboardingWorkflow);
ctx.callActivity(BUILD_CONTRACT_ACTIVITY_NAME, onboardingWorkflowString, optionsRetry, String.class).await();
ctx.callActivity(SAVE_TOKEN_WITH_CONTRACT_ACTIVITY_NAME, onboardingWorkflowString, optionsRetry, String.class).await();
return Optional.of(OnboardingStatus.PENDING);
}

@Override
Expand Down
57 changes: 6 additions & 51 deletions apps/onboarding-ms/src/main/docs/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -502,24 +502,9 @@
"operationId" : "onboardingCompletion",
"requestBody" : {
"content" : {
"multipart/form-data" : {
"application/json" : {
"schema" : {
"required" : [ "contract" ],
"type" : "object",
"properties" : {
"onboardingRequest" : {
"$ref" : "#/components/schemas/OnboardingDefaultRequest"
},
"contract" : {
"format" : "binary",
"type" : "string"
}
}
},
"encoding" : {
"onboardingRequest" : {
"contentType" : "application/json"
}
"$ref" : "#/components/schemas/OnboardingDefaultRequest"
}
}
}
Expand Down Expand Up @@ -695,24 +680,9 @@
"operationId" : "onboardingPaCompletion",
"requestBody" : {
"content" : {
"multipart/form-data" : {
"application/json" : {
"schema" : {
"required" : [ "contract" ],
"type" : "object",
"properties" : {
"onboardingRequest" : {
"$ref" : "#/components/schemas/OnboardingPaRequest"
},
"contract" : {
"format" : "binary",
"type" : "string"
}
}
},
"encoding" : {
"onboardingRequest" : {
"contentType" : "application/json"
}
"$ref" : "#/components/schemas/OnboardingPaRequest"
}
}
}
Expand Down Expand Up @@ -862,24 +832,9 @@
"operationId" : "onboardingPspCompletion",
"requestBody" : {
"content" : {
"multipart/form-data" : {
"application/json" : {
"schema" : {
"required" : [ "contract" ],
"type" : "object",
"properties" : {
"onboardingRequest" : {
"$ref" : "#/components/schemas/OnboardingPspRequest"
},
"contract" : {
"format" : "binary",
"type" : "string"
}
}
},
"encoding" : {
"onboardingRequest" : {
"contentType" : "application/json"
}
"$ref" : "#/components/schemas/OnboardingPspRequest"
}
}
}
Expand Down
45 changes: 6 additions & 39 deletions apps/onboarding-ms/src/main/docs/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -367,20 +367,9 @@ paths:
operationId: onboardingCompletion
requestBody:
content:
multipart/form-data:
application/json:
schema:
required:
- contract
type: object
properties:
onboardingRequest:
$ref: "#/components/schemas/OnboardingDefaultRequest"
contract:
format: binary
type: string
encoding:
onboardingRequest:
contentType: application/json
$ref: "#/components/schemas/OnboardingDefaultRequest"
responses:
"200":
description: OK
Expand Down Expand Up @@ -511,20 +500,9 @@ paths:
operationId: onboardingPaCompletion
requestBody:
content:
multipart/form-data:
application/json:
schema:
required:
- contract
type: object
properties:
onboardingRequest:
$ref: "#/components/schemas/OnboardingPaRequest"
contract:
format: binary
type: string
encoding:
onboardingRequest:
contentType: application/json
$ref: "#/components/schemas/OnboardingPaRequest"
responses:
"200":
description: OK
Expand Down Expand Up @@ -631,20 +609,9 @@ paths:
operationId: onboardingPspCompletion
requestBody:
content:
multipart/form-data:
application/json:
schema:
required:
- contract
type: object
properties:
onboardingRequest:
$ref: "#/components/schemas/OnboardingPspRequest"
contract:
format: binary
type: string
encoding:
onboardingRequest:
contentType: application/json
$ref: "#/components/schemas/OnboardingPspRequest"
responses:
"200":
description: OK
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import org.eclipse.microprofile.openapi.annotations.Operation;
import org.eclipse.microprofile.openapi.annotations.extensions.Extension;
import org.eclipse.microprofile.openapi.annotations.tags.Tag;
import org.jboss.resteasy.reactive.PartType;
import org.jboss.resteasy.reactive.RestForm;
import org.jboss.resteasy.reactive.server.core.ResteasyReactiveRequestContext;

Expand Down Expand Up @@ -172,21 +171,12 @@ public Uni<OnboardingResponse> onboardingPsp(@Valid OnboardingPspRequest onboard
@POST
@Tag(name = "Onboarding Controller")
@Tag(name = "internal-v1")
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Uni<OnboardingResponse> onboardingCompletion(
@NotNull @RestForm("contract") File file,
@NotNull @FormParam("onboardingRequest") @PartType(MediaType.APPLICATION_JSON) OnboardingDefaultRequest onboardingRequest,
@Context ResteasyReactiveRequestContext ctx,
@Context SecurityContext securityContext) {

return readUserIdFromToken(securityContext)
.onItem()
.transformToUni(
userId -> onboardingService.onboardingCompletion(
fillUserId(onboardingMapper.toEntity(onboardingRequest), userId),
onboardingRequest.getUsers(),
retrieveContractFromFormData(ctx.getFormData(), file)));
public Uni<OnboardingResponse> onboardingCompletion(@Valid OnboardingDefaultRequest onboardingRequest, @Context SecurityContext ctx) {
return readUserIdFromToken(ctx)
.onItem().transformToUni(userId -> onboardingService
.onboardingCompletion(fillUserId(onboardingMapper.toEntity(onboardingRequest), userId), onboardingRequest.getUsers()));
}

@Operation(
Expand All @@ -197,21 +187,12 @@ public Uni<OnboardingResponse> onboardingCompletion(
@Path("/pa/completion")
@Tag(name = "Onboarding Controller")
@Tag(name = "internal-v1")
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Uni<OnboardingResponse> onboardingPaCompletion(
@NotNull @RestForm("contract") File file,
@NotNull @FormParam("onboardingRequest") @PartType(MediaType.APPLICATION_JSON) OnboardingPaRequest onboardingRequest,
@Context ResteasyReactiveRequestContext ctx,
@Context SecurityContext securityContext) {

return readUserIdFromToken(securityContext)
.onItem()
.transformToUni(
userId -> onboardingService.onboardingCompletion(
fillUserId(onboardingMapper.toEntity(onboardingRequest), userId),
onboardingRequest.getUsers(),
retrieveContractFromFormData(ctx.getFormData(), file)));
public Uni<OnboardingResponse> onboardingPaCompletion(@Valid OnboardingPaRequest onboardingRequest, @Context SecurityContext ctx) {
return readUserIdFromToken(ctx)
.onItem().transformToUni(userId -> onboardingService
.onboardingCompletion(fillUserId(onboardingMapper.toEntity(onboardingRequest), userId), onboardingRequest.getUsers()));
}

@Operation(
Expand Down Expand Up @@ -250,21 +231,12 @@ public Uni<OnboardingResponse> onboardingPspImport(@Valid OnboardingImportPspReq
@Path("/psp/completion")
@Tag(name = "Onboarding Controller")
@Tag(name = "internal-v1")
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Uni<OnboardingResponse> onboardingPspCompletion(
@NotNull @RestForm("contract") File file,
@NotNull @FormParam("onboardingRequest") @PartType(MediaType.APPLICATION_JSON) OnboardingPspRequest onboardingRequest,
@Context ResteasyReactiveRequestContext ctx,
@Context SecurityContext securityContext) {

return readUserIdFromToken(securityContext)
.onItem()
.transformToUni(
userId -> onboardingService.onboardingCompletion(
fillUserId(onboardingMapper.toEntity(onboardingRequest), userId),
onboardingRequest.getUsers(),
retrieveContractFromFormData(ctx.getFormData(), file)));
public Uni<OnboardingResponse> onboardingPspCompletion(@Valid OnboardingPspRequest onboardingRequest, @Context SecurityContext ctx) {
return readUserIdFromToken(ctx)
.onItem().transformToUni(userId -> onboardingService
.onboardingCompletion(fillUserId(onboardingMapper.toEntity(onboardingRequest), userId), onboardingRequest.getUsers()));
}

@Operation(
Expand All @@ -280,7 +252,7 @@ public Uni<OnboardingResponse> onboardingPspCompletion(
public Uni<OnboardingResponse> onboardingPgCompletion(@Valid OnboardingPgRequest onboardingRequest, @Context SecurityContext ctx) {
return readUserIdFromToken(ctx)
.onItem().transformToUni(userId -> onboardingService
.onboardingCompletion(fillUserId(onboardingMapper.toEntity(onboardingRequest), userId), onboardingRequest.getUsers(), null));
.onboardingCompletion(fillUserId(onboardingMapper.toEntity(onboardingRequest), userId), onboardingRequest.getUsers()));
}

@Operation(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Uni<OnboardingResponse> onboardingImport(
boolean forceImport);

Uni<OnboardingResponse> onboardingCompletion(
Onboarding onboarding, List<UserRequest> userRequests, FormItem formItem);
Onboarding onboarding, List<UserRequest> userRequests);

Uni<OnboardingResponse> onboardingAggregationCompletion(
Onboarding onboarding,
Expand Down
Loading

0 comments on commit 157f7c3

Please sign in to comment.