Skip to content

Commit

Permalink
feat(retrigger): add retrigger steps for technical users
Browse files Browse the repository at this point in the history
Refs: #56
  • Loading branch information
Phil91 committed Aug 6, 2024
1 parent 3331ff5 commit 1e8a2e7
Show file tree
Hide file tree
Showing 10 changed files with 157 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,5 @@ public interface IProcessStepRepository
Task<ProcessData?> GetWalletProcessForTenant(string bpn, string companyName);
Task<ProcessData?> GetTechnicalUserProcess(string technicalUserName);
Task<(bool ProcessExists, VerifyProcessData ProcessData)> IsValidProcess(Guid processId, ProcessTypeId processTypeId, IEnumerable<ProcessStepTypeId> processSetpTypeIds);

}
7 changes: 6 additions & 1 deletion src/database/Dim.Entities/Enums/ProcessStepTypeId.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,13 @@ public enum ProcessStepTypeId
CREATE_TECHNICAL_USER = 100,
GET_TECHNICAL_USER_DATA = 101,
SEND_TECHNICAL_USER_CREATION_CALLBACK = 102,
RETRIGGER_CREATE_TECHNICAL_USER = 103,
RETRIGGER_GET_TECHNICAL_USER_DATA = 104,
RETRIGGER_SEND_TECHNICAL_USER_CREATION_CALLBACK = 105,

// Delete Technical User
DELETE_TECHNICAL_USER = 200,
SEND_TECHNICAL_USER_DELETION_CALLBACK = 201
SEND_TECHNICAL_USER_DELETION_CALLBACK = 201,
RETRIGGER_DELETE_TECHNICAL_USER = 202,
RETRIGGER_SEND_TECHNICAL_USER_DELETION_CALLBACK = 203
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public static ProcessStepTypeId GetWalletRetriggerStep(this ProcessStepTypeId pr
ProcessStepTypeId.CREATE_STATUS_LIST => ProcessStepTypeId.RETRIGGER_CREATE_STATUS_LIST,
_ => throw new ArgumentOutOfRangeException(nameof(processStepTypeId), processStepTypeId, null)
};

public static ProcessStepTypeId GetWalletStepForRetrigger(this ProcessStepTypeId processStepTypeId) =>
processStepTypeId switch
{
Expand All @@ -71,4 +71,26 @@ public static ProcessStepTypeId GetWalletStepForRetrigger(this ProcessStepTypeId
ProcessStepTypeId.RETRIGGER_CREATE_STATUS_LIST => ProcessStepTypeId.CREATE_STATUS_LIST,
_ => throw new ArgumentOutOfRangeException(nameof(processStepTypeId), processStepTypeId, null)
};

public static ProcessStepTypeId GetTechnicalRetriggerStep(this ProcessStepTypeId processStepTypeId) =>
processStepTypeId switch
{
ProcessStepTypeId.CREATE_TECHNICAL_USER => ProcessStepTypeId.RETRIGGER_CREATE_TECHNICAL_USER,
ProcessStepTypeId.GET_TECHNICAL_USER_DATA => ProcessStepTypeId.RETRIGGER_GET_TECHNICAL_USER_DATA,
ProcessStepTypeId.SEND_TECHNICAL_USER_CREATION_CALLBACK => ProcessStepTypeId.RETRIGGER_SEND_TECHNICAL_USER_CREATION_CALLBACK,
ProcessStepTypeId.DELETE_TECHNICAL_USER => ProcessStepTypeId.RETRIGGER_DELETE_TECHNICAL_USER,
ProcessStepTypeId.SEND_TECHNICAL_USER_DELETION_CALLBACK => ProcessStepTypeId.RETRIGGER_SEND_TECHNICAL_USER_DELETION_CALLBACK,
_ => throw new ArgumentOutOfRangeException(nameof(processStepTypeId), processStepTypeId, null)
};

public static ProcessStepTypeId GetTechnicalStepForRetrigger(this ProcessStepTypeId processStepTypeId) =>
processStepTypeId switch
{
ProcessStepTypeId.RETRIGGER_CREATE_TECHNICAL_USER => ProcessStepTypeId.CREATE_TECHNICAL_USER,
ProcessStepTypeId.RETRIGGER_GET_TECHNICAL_USER_DATA => ProcessStepTypeId.GET_TECHNICAL_USER_DATA,
ProcessStepTypeId.RETRIGGER_SEND_TECHNICAL_USER_CREATION_CALLBACK => ProcessStepTypeId.SEND_TECHNICAL_USER_CREATION_CALLBACK,
ProcessStepTypeId.RETRIGGER_DELETE_TECHNICAL_USER => ProcessStepTypeId.DELETE_TECHNICAL_USER,
ProcessStepTypeId.RETRIGGER_SEND_TECHNICAL_USER_DELETION_CALLBACK => ProcessStepTypeId.SEND_TECHNICAL_USER_DELETION_CALLBACK,
_ => throw new ArgumentOutOfRangeException(nameof(processStepTypeId), processStepTypeId, null)
};
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,12 @@ protected override void Up(MigrationBuilder migrationBuilder)
{ 33, "RETRIGGER_CREATE_COMPANY_IDENTITY" },
{ 34, "RETRIGGER_ASSIGN_COMPANY_APPLICATION" },
{ 35, "RETRIGGER_CREATE_STATUS_LIST" },
{ 36, "RETRIGGER_SEND_CALLBACK" }
{ 36, "RETRIGGER_SEND_CALLBACK" },
{ 103, "RETRIGGER_CREATE_TECHNICAL_USER" },
{ 104, "RETRIGGER_GET_TECHNICAL_USER_DATA" },
{ 105, "RETRIGGER_SEND_TECHNICAL_USER_CREATION_CALLBACK" },
{ 202, "RETRIGGER_DELETE_TECHNICAL_USER" },
{ 203, "RETRIGGER_SEND_TECHNICAL_USER_DELETION_CALLBACK" }
});

migrationBuilder.CreateIndex(
Expand Down Expand Up @@ -204,6 +209,36 @@ protected override void Down(MigrationBuilder migrationBuilder)
keyColumn: "id",
keyValue: 36);

migrationBuilder.DeleteData(
schema: "dim",
table: "process_step_types",
keyColumn: "id",
keyValue: 103);

migrationBuilder.DeleteData(
schema: "dim",
table: "process_step_types",
keyColumn: "id",
keyValue: 104);

migrationBuilder.DeleteData(
schema: "dim",
table: "process_step_types",
keyColumn: "id",
keyValue: 105);

migrationBuilder.DeleteData(
schema: "dim",
table: "process_step_types",
keyColumn: "id",
keyValue: 202);

migrationBuilder.DeleteData(
schema: "dim",
table: "process_step_types",
keyColumn: "id",
keyValue: 203);

migrationBuilder.CreateIndex(
name: "ix_tenants_process_id",
schema: "dim",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,21 @@ protected override void BuildModel(ModelBuilder modelBuilder)
Label = "SEND_TECHNICAL_USER_CREATION_CALLBACK"
},
new
{
Id = 103,
Label = "RETRIGGER_CREATE_TECHNICAL_USER"
},
new
{
Id = 104,
Label = "RETRIGGER_GET_TECHNICAL_USER_DATA"
},
new
{
Id = 105,
Label = "RETRIGGER_SEND_TECHNICAL_USER_CREATION_CALLBACK"
},
new
{
Id = 200,
Label = "DELETE_TECHNICAL_USER"
Expand All @@ -382,6 +397,16 @@ protected override void BuildModel(ModelBuilder modelBuilder)
{
Id = 201,
Label = "SEND_TECHNICAL_USER_DELETION_CALLBACK"
},
new
{
Id = 202,
Label = "RETRIGGER_DELETE_TECHNICAL_USER"
},
new
{
Id = 203,
Label = "RETRIGGER_SEND_TECHNICAL_USER_DELETION_CALLBACK"
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
using Dim.DbAccess;
using Dim.DbAccess.Repositories;
using Dim.Entities.Enums;
using Dim.Entities.Extensions;
using DimProcess.Library;
using Org.Eclipse.TractusX.Portal.Backend.Framework.ErrorHandling;
using Processes.Worker.Library;
Expand Down Expand Up @@ -92,19 +93,19 @@ public class TechnicalUserProcessTypeExecutor(
}
catch (Exception ex) when (ex is not SystemException)
{
(stepStatusId, processMessage, nextStepTypeIds) = ProcessError(ex);
(stepStatusId, processMessage, nextStepTypeIds) = ProcessError(ex, processStepTypeId);
modified = true;
}

return new IProcessTypeExecutor.StepExecutionResult(modified, stepStatusId, nextStepTypeIds, null, processMessage);
}

private static (ProcessStepStatusId StatusId, string? ProcessMessage, IEnumerable<ProcessStepTypeId>? nextSteps) ProcessError(Exception ex)
private static (ProcessStepStatusId StatusId, string? ProcessMessage, IEnumerable<ProcessStepTypeId>? nextSteps) ProcessError(Exception ex, ProcessStepTypeId processStepTypeId)
{
return ex switch
{
ServiceException { IsRecoverable: true } => (ProcessStepStatusId.TODO, ex.Message, null),
_ => (ProcessStepStatusId.FAILED, ex.Message, null)
_ => (ProcessStepStatusId.FAILED, ex.Message, Enumerable.Repeat(processStepTypeId.GetTechnicalRetriggerStep(), 1))
};
}
}
19 changes: 18 additions & 1 deletion src/web/Dim.Web/BusinessLogic/DimBusinessLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public async Task<ProcessData> GetTechnicalUserProcess(string technicalUserName)
return processData;
}

public async Task RetriggerProcessStep(Guid processId, ProcessStepTypeId processStepTypeId)
public async Task RetriggerWalletProcessStep(Guid processId, ProcessStepTypeId processStepTypeId)
{
var stepToTrigger = processStepTypeId.GetWalletStepForRetrigger();

Expand All @@ -195,4 +195,21 @@ public async Task RetriggerProcessStep(Guid processId, ProcessStepTypeId process
context.FinalizeProcessStep();
await dimRepositories.SaveAsync().ConfigureAwait(ConfigureAwaitOptions.None);
}

public async Task RetriggerTechnicalUserProcessStep(Guid processId, ProcessStepTypeId processStepTypeId)
{
var stepToTrigger = processStepTypeId.GetTechnicalStepForRetrigger();

var (validProcessId, processData) = await dimRepositories.GetInstance<IProcessStepRepository>().IsValidProcess(processId, ProcessTypeId.TECHNICAL_USER, Enumerable.Repeat(processStepTypeId, 1)).ConfigureAwait(false);
if (!validProcessId)
{
throw new NotFoundException($"process {processId} does not exist");
}

var context = processData.CreateManualProcessData(stepToTrigger, dimRepositories, () => $"processId {processId}");

context.ScheduleProcessSteps(Enumerable.Repeat(stepToTrigger, 1));
context.FinalizeProcessStep();
await dimRepositories.SaveAsync().ConfigureAwait(ConfigureAwaitOptions.None);
}
}
2 changes: 1 addition & 1 deletion src/web/Dim.Web/BusinessLogic/IDimBusinessLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ public interface IDimBusinessLogic : ITransient
Task DeleteTechnicalUser(string bpn, TechnicalUserData technicalUserData);
Task<ProcessData> GetSetupProcess(string bpn, string companyName);
Task<ProcessData> GetTechnicalUserProcess(string technicalUserName);
Task RetriggerProcessStep(Guid processId, ProcessStepTypeId processStepTypeId);
Task RetriggerWalletProcessStep(Guid processId, ProcessStepTypeId processStepTypeId);
}
21 changes: 17 additions & 4 deletions src/web/Dim.Web/Controllers/DimController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,27 @@ public static RouteGroupBuilder MapDimApi(this RouteGroupBuilder group)
.RequireAuthorization(r => r.RequireRole("get_process"))
.Produces(StatusCodes.Status200OK, contentType: Constants.JsonContentType);

dim.MapGet("process/{processId}/retrigger", (
dim.MapGet("process/wallet/{processId}/retrigger", (
[FromRoute] Guid processId,
[FromQuery] ProcessStepTypeId processStepTypeId,
[FromServices] IDimBusinessLogic dimBusinessLogic)
=> dimBusinessLogic.RetriggerProcessStep(processId, processStepTypeId)
=> dimBusinessLogic.RetriggerWalletProcessStep(processId, processStepTypeId)
)
.WithSwaggerDescription("Retriggers the given process step",
"Example: Post: api/dim/process/{processId}/retrigger?processStepTypeId={processStepTypeId}",
.WithSwaggerDescription("Retriggers the given process step of the wallet creation process",
"Example: Post: api/dim/process/wallet/{processId}/retrigger?processStepTypeId={processStepTypeId}",
"Id of the process",
"The process step that should be retriggered")
.RequireAuthorization(r => r.RequireRole("retrigger_process"))
.Produces(StatusCodes.Status200OK, contentType: Constants.JsonContentType);

dim.MapGet("process/technicalUser/{processId}/retrigger", (
[FromRoute] Guid processId,
[FromQuery] ProcessStepTypeId processStepTypeId,
[FromServices] IDimBusinessLogic dimBusinessLogic)
=> dimBusinessLogic.RetriggerWalletProcessStep(processId, processStepTypeId)
)
.WithSwaggerDescription("Retriggers the given process step of a technical user process",
"Example: Post: api/dim/process/technicalUser/{processId}/retrigger?processStepTypeId={processStepTypeId}",
"Id of the process",
"The process step that should be retriggered")
.RequireAuthorization(r => r.RequireRole("retrigger_process"))
Expand Down

0 comments on commit 1e8a2e7

Please sign in to comment.