Skip to content

Commit

Permalink
Merge back from hotfix send user fd notification (#559)
Browse files Browse the repository at this point in the history
Co-authored-by: empassaro <emanuele.passaro@emeal.nttdata.com>
  • Loading branch information
andrea-putzu and empassaro authored Oct 21, 2024
1 parent e9c0e50 commit d4c3668
Show file tree
Hide file tree
Showing 17 changed files with 732 additions and 99 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
package it.pagopa.selfcare.onboarding.dto;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import it.pagopa.selfcare.onboarding.utils.CustomOffsetDateTimeSerializer;

import java.nio.file.Paths;
import java.time.OffsetDateTime;
import java.util.Objects;

@JsonInclude(JsonInclude.Include.NON_NULL)
public class NotificationUserToSend {

private String id;
private String institutionId;
private String product;

private String onboardingTokenId;

private String createdAt;
@JsonSerialize(using = CustomOffsetDateTimeSerializer.class)
private OffsetDateTime closedAt;

private String updatedAt;

private NotificationUserType type;
private UserToNotify user;


public String getInstitutionId() {
return institutionId;
}

public void setInstitutionId(String institutionId) {
this.institutionId = institutionId;
}


public NotificationUserType getType() {
return type;
}

public void setType(NotificationUserType type) {
this.type = type;
}


public String getOnboardingTokenId() {
return onboardingTokenId;
}

public void setOnboardingTokenId(String onboardingTokenId) {
this.onboardingTokenId = onboardingTokenId;
}

public OffsetDateTime getClosedAt() {
return closedAt;
}

public void setClosedAt(OffsetDateTime closedAt) {
this.closedAt = closedAt;
}


public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}

public String getProduct() {
return product;
}

public void setProduct(String product) {
this.product = product;
}


public String getCreatedAt() {
return createdAt;
}

public void setCreatedAt(String createdAt) {
this.createdAt = createdAt;
}

public String getUpdatedAt() {
return updatedAt;
}

public void setUpdatedAt(String updatedAt) {
this.updatedAt = updatedAt;
}

public UserToNotify getUser() {
return user;
}

public void setUser(UserToNotify user) {
this.user = user;
}

@Override
public String toString() {
return "NotificationToSend{" +
"id='" + id + '\'' +
", institutionId='" + institutionId + '\'' +
", product='" + product + '\'' +
", onboardingTokenId='" + onboardingTokenId + '\'' +
", createdAt=" + createdAt +
", closedAt=" + closedAt +
", updatedAt=" + updatedAt +
", userId=" + user.getUserId() +
'}';
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package it.pagopa.selfcare.onboarding.dto;

public enum NotificationUserType {
ADD_INSTITUTE(QueueUserEvent.ADD_INSTITUTE),
UPDATE_INSTITUTION(QueueUserEvent.UPDATE_INSTITUTION),
ACTIVE_USER(QueueUserEvent.ACTIVE_USER),
SUSPEND_USER(QueueUserEvent.SUSPEND_USER),
DELETE_USER(QueueUserEvent.DELETE_USER);


private final QueueUserEvent queueUserEvent;

NotificationUserType(QueueUserEvent queueUserEvent) {
this.queueUserEvent = queueUserEvent;
}

public static NotificationUserType getNotificationTypeFromQueueEvent(QueueUserEvent queueEvent) {
for (NotificationUserType notificationType : NotificationUserType.values()) {
if (notificationType.queueUserEvent == queueEvent) {
return notificationType;
}
}
return null; // Return null if no matching NotificationType is found
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package it.pagopa.selfcare.onboarding.dto;

public enum QueueUserEvent {
ADD_INSTITUTE,
UPDATE_INSTITUTION,
ACTIVE_USER,
SUSPEND_USER,
DELETE_USER
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package it.pagopa.selfcare.onboarding.dto;

import com.fasterxml.jackson.annotation.JsonInclude;
import it.pagopa.selfcare.onboarding.common.PartyRole;

import java.util.List;

@JsonInclude(JsonInclude.Include.NON_NULL)
public class UserToNotify {

private String userId;
private String role;
private List<String> roles;

public String getUserId() {
return userId;
}

public void setUserId(String userId) {
this.userId = userId;
}

public String getRole() {
return role;
}

public void setRole(String role) {
this.role = role;
}

public List<String> getRoles() {
return roles;
}

public void setRoles(List<String> roles) {
this.roles = roles;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public HttpResponseMessage startOrchestration(
try {

/* if timeout is null, caller wants response asynchronously */
if(Objects.isNull(timeoutString)) {
if (Objects.isNull(timeoutString)) {
return durableContext.createCheckStatusResponse(request, instanceId);
}

Expand All @@ -94,11 +94,11 @@ public HttpResponseMessage startOrchestration(
true);

boolean isFailed = Optional.ofNullable(metadata)
.map(orchestration -> OrchestrationRuntimeStatus.FAILED.equals(orchestration.getRuntimeStatus()) )
.map(orchestration -> OrchestrationRuntimeStatus.FAILED.equals(orchestration.getRuntimeStatus()))
.orElse(true);

return isFailed
? request.createResponseBuilder(HttpStatus.INTERNAL_SERVER_ERROR)
? request.createResponseBuilder(HttpStatus.INTERNAL_SERVER_ERROR)
.build()
: request.createResponseBuilder(HttpStatus.OK)
.build();
Expand All @@ -107,6 +107,7 @@ public HttpResponseMessage startOrchestration(
return durableContext.createCheckStatusResponse(request, instanceId);
}
}

@FunctionName(ONBOARDINGS_AGGREGATE_ORCHESTRATOR)
public void onboardingsAggregateOrchestrator(
@DurableOrchestrationTrigger(name = "taskOrchestrationContext") TaskOrchestrationContext ctx,
Expand All @@ -115,7 +116,7 @@ public void onboardingsAggregateOrchestrator(
try {
String onboardingAggregate = ctx.getInput(String.class);
boolean existsDelegation = Boolean.parseBoolean(ctx.callActivity(EXISTS_DELEGATION_ACTIVITY, onboardingAggregate, optionsRetry, String.class).await());
if(!existsDelegation) {
if (!existsDelegation) {
onboardingId = ctx.callActivity(CREATE_AGGREGATE_ONBOARDING_REQUEST_ACTIVITY, onboardingAggregate, optionsRetry, String.class).await();
ctx.callSubOrchestrator("Onboardings", onboardingId, String.class).await();
}
Expand Down Expand Up @@ -148,15 +149,19 @@ public void onboardingsOrchestrator(
.orElseThrow(() -> new ResourceNotFoundException(String.format("Onboarding with id %s not found!", onboardingId)));

switch (onboarding.getWorkflowType()) {
case CONTRACT_REGISTRATION -> workflowExecutor = new WorkflowExecutorContractRegistration(objectMapper, optionsRetry);
case CONTRACT_REGISTRATION_AGGREGATOR -> workflowExecutor = new WorkflowExecutorContractRegistrationAggregator(objectMapper, optionsRetry, onboardingMapper);
case FOR_APPROVE -> workflowExecutor = new WorkflowExecutorForApprove(objectMapper, optionsRetry);
case CONTRACT_REGISTRATION ->
workflowExecutor = new WorkflowExecutorContractRegistration(objectMapper, optionsRetry);
case CONTRACT_REGISTRATION_AGGREGATOR ->
workflowExecutor = new WorkflowExecutorContractRegistrationAggregator(objectMapper, optionsRetry, onboardingMapper);
case FOR_APPROVE -> workflowExecutor = new WorkflowExecutorForApprove(objectMapper, optionsRetry);
case FOR_APPROVE_PT -> workflowExecutor = new WorkflowExecutorForApprovePt(objectMapper, optionsRetry);
case CONFIRMATION -> workflowExecutor = new WorkflowExecutorConfirmation(objectMapper, optionsRetry);
case CONFIRMATION_AGGREGATE -> workflowExecutor = new WorkflowExecutorConfirmAggregate(objectMapper, optionsRetry);
case CONFIRMATION_AGGREGATE ->
workflowExecutor = new WorkflowExecutorConfirmAggregate(objectMapper, optionsRetry);
case IMPORT -> workflowExecutor = new WorkflowExecutorImport(objectMapper, optionsRetry);
case USERS -> workflowExecutor = new WorkflowExecutorForUsers(objectMapper, optionsRetry);
case INCREMENT_REGISTRATION_AGGREGATOR -> workflowExecutor = new WorkflowExecutorIncrementRegistrationAggregator(objectMapper, optionsRetry, onboardingMapper);
case INCREMENT_REGISTRATION_AGGREGATOR ->
workflowExecutor = new WorkflowExecutorIncrementRegistrationAggregator(objectMapper, optionsRetry, onboardingMapper);
case USERS_PG -> workflowExecutor = new WorkflowExecutorForUsersPg(objectMapper, optionsRetry);
default -> throw new IllegalArgumentException("Workflow options not found!");
}
Expand Down
Loading

0 comments on commit d4c3668

Please sign in to comment.