From b056c44acf2d717695efeade3bc5af5f73933063 Mon Sep 17 00:00:00 2001 From: Phil Schneider Date: Fri, 2 Aug 2024 09:14:55 +0200 Subject: [PATCH] feat(retrigger): add retrigger steps to process worker Refs: #56 --- src/clients/Dim.Clients/Api/Cf/CfClient.cs | 64 +- src/clients/Dim.Clients/Api/Dim/DimClient.cs | 36 +- .../Api/Directories/DirectoryClient.cs | 16 +- .../Api/Entitlements/EntitlementClient.cs | 11 +- .../Api/Provisioning/ProvisioningClient.cs | 11 +- .../Dim.Clients/Api/Services/ServiceClient.cs | 23 +- .../Api/SubAccounts/SubAccountClient.cs | 29 +- .../Api/Subscriptions/SubscriptionClient.cs | 12 +- .../Token/BasicAuthTokenService.cs | 25 +- .../Dim.DbAccess/Models/ProcessData.cs | 33 + .../Repositories/IProcessStepRepository.cs | 5 + .../Repositories/ProcessStepRepository.cs | 44 +- src/database/Dim.Entities/DimDbContext.cs | 8 +- src/database/Dim.Entities/Entities/Process.cs | 6 +- .../Dim.Entities/Enums/ProcessStepTypeId.cs | 18 + .../Extensions/ProcessStepTypeIdExtensions.cs | 74 ++ ...801133205_56-AddRetriggerSteps.Designer.cs | 667 ++++++++++++++++++ .../20240801133205_56-AddRetriggerSteps.cs | 220 ++++++ .../Migrations/DimDbContextModelSnapshot.cs | 106 ++- src/database/Dim.Migrations/Program.cs | 2 +- .../DimProcessCollectionExtensions.cs | 2 +- .../DimProcessTypeExecutor.cs | 47 +- .../TechnicalUserProcessTypeExecutor.cs | 14 +- .../Callback/CallbackService.cs | 12 +- .../DimProcess.Library/DimProcessHandler.cs | 94 +-- .../TechnicalUserProcessHandler.cs | 24 +- .../IProcessExecutor.cs | 2 +- .../IProcessTypeExecutor.cs | 2 +- .../ProcessExecutionService.cs | 6 +- .../ProcessExecutionServiceExtensions.cs | 2 +- .../ProcessExecutionServiceSettings.cs | 2 +- .../ProcessExecutor.cs | 27 +- src/processes/Processes.Worker/Program.cs | 4 +- .../Dim.Web/BusinessLogic/DimBusinessLogic.cs | 66 +- .../BusinessLogic/IDimBusinessLogic.cs | 5 + src/web/Dim.Web/Controllers/DimController.cs | 38 + src/web/Dim.Web/Dim.Web.csproj | 1 + .../DimProcessHandlerTests.cs | 46 +- .../ProcessExecutionServiceTests.cs | 1 - .../ProcessExecutorTests.cs | 1 - 40 files changed, 1497 insertions(+), 309 deletions(-) create mode 100644 src/database/Dim.DbAccess/Models/ProcessData.cs create mode 100644 src/database/Dim.Entities/Extensions/ProcessStepTypeIdExtensions.cs create mode 100644 src/database/Dim.Migrations/Migrations/20240801133205_56-AddRetriggerSteps.Designer.cs create mode 100644 src/database/Dim.Migrations/Migrations/20240801133205_56-AddRetriggerSteps.cs diff --git a/src/clients/Dim.Clients/Api/Cf/CfClient.cs b/src/clients/Dim.Clients/Api/Cf/CfClient.cs index 1df819e..4a16340 100644 --- a/src/clients/Dim.Clients/Api/Cf/CfClient.cs +++ b/src/clients/Dim.Clients/Api/Cf/CfClient.cs @@ -30,33 +30,27 @@ namespace Dim.Clients.Api.Cf; -public class CfClient : ICfClient +public class CfClient(IBasicAuthTokenService basicAuthTokenService, IOptions settings) + : ICfClient { - private readonly CfSettings _settings; - private readonly IBasicAuthTokenService _basicAuthTokenService; - - public CfClient(IBasicAuthTokenService basicAuthTokenService, IOptions settings) - { - _basicAuthTokenService = basicAuthTokenService; - _settings = settings.Value; - } + private readonly CfSettings _settings = settings.Value; public async Task CreateCloudFoundrySpace(string tenantName, CancellationToken cancellationToken) { - var client = await _basicAuthTokenService.GetBasicAuthorizedLegacyClient(_settings, cancellationToken).ConfigureAwait(false); - var cfEnvironmentId = await GetEnvironmentId(tenantName, cancellationToken, client).ConfigureAwait(false); + var client = await basicAuthTokenService.GetBasicAuthorizedLegacyClient(_settings, cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None); + var cfEnvironmentId = await GetEnvironmentId(tenantName, cancellationToken, client).ConfigureAwait(ConfigureAwaitOptions.None); var data = new CreateSpaceRequest( $"{tenantName}-space", new SpaceRelationship(new SpaceOrganization(new SpaceRelationshipData(cfEnvironmentId))) ); var result = await client.PostAsJsonAsync("/v3/spaces", data, JsonSerializerExtensions.Options, cancellationToken) - .CatchingIntoServiceExceptionFor("create-cfe", HttpAsyncResponseMessageExtension.RecoverOptions.ALLWAYS).ConfigureAwait(false); + .CatchingIntoServiceExceptionFor("create-cfe", HttpAsyncResponseMessageExtension.RecoverOptions.INFRASTRUCTURE).ConfigureAwait(false); try { var response = await result.Content .ReadFromJsonAsync(JsonSerializerExtensions.Options, cancellationToken) - .ConfigureAwait(false); + .ConfigureAwait(ConfigureAwaitOptions.None); if (response == null) { @@ -77,7 +71,7 @@ private static async Task GetEnvironmentId(string tenantName, Cancellation .CatchingIntoServiceExceptionFor("get-organizations", HttpAsyncResponseMessageExtension.RecoverOptions.INFRASTRUCTURE); var environments = await environmentsResponse.Content .ReadFromJsonAsync(JsonSerializerExtensions.Options, cancellationToken) - .ConfigureAwait(false); + .ConfigureAwait(ConfigureAwaitOptions.None); var tenantEnvironment = environments?.Resources.Where(x => x.Name == tenantName); if (tenantEnvironment == null || tenantEnvironment.Count() > 1) @@ -90,7 +84,7 @@ private static async Task GetEnvironmentId(string tenantName, Cancellation public async Task AddSpaceRoleToUser(string type, string user, Guid spaceId, CancellationToken cancellationToken) { - var client = await _basicAuthTokenService.GetBasicAuthorizedLegacyClient(_settings, cancellationToken).ConfigureAwait(false); + var client = await basicAuthTokenService.GetBasicAuthorizedLegacyClient(_settings, cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None); var data = new AddSpaceRoleToUserRequest( type, new SpaceRoleRelationship( @@ -105,14 +99,14 @@ await client.PostAsJsonAsync("/v3/roles", data, JsonSerializerExtensions.Options public async Task GetServicePlan(string servicePlanName, string servicePlanType, CancellationToken cancellationToken) { - var client = await _basicAuthTokenService.GetBasicAuthorizedLegacyClient(_settings, cancellationToken).ConfigureAwait(false); + var client = await basicAuthTokenService.GetBasicAuthorizedLegacyClient(_settings, cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None); var result = await client.GetAsync("/v3/service_plans", cancellationToken) - .CatchingIntoServiceExceptionFor("get-service-plan", HttpAsyncResponseMessageExtension.RecoverOptions.ALLWAYS).ConfigureAwait(false); + .CatchingIntoServiceExceptionFor("get-service-plan", HttpAsyncResponseMessageExtension.RecoverOptions.INFRASTRUCTURE).ConfigureAwait(false); try { var response = await result.Content .ReadFromJsonAsync(JsonSerializerExtensions.Options, cancellationToken) - .ConfigureAwait(false); + .ConfigureAwait(ConfigureAwaitOptions.None); if (response == null) { @@ -137,14 +131,14 @@ public async Task GetServicePlan(string servicePlanName, string servicePla public async Task GetSpace(string tenantName, CancellationToken cancellationToken) { var spaceName = $"{tenantName}-space"; - var client = await _basicAuthTokenService.GetBasicAuthorizedLegacyClient(_settings, cancellationToken).ConfigureAwait(false); + var client = await basicAuthTokenService.GetBasicAuthorizedLegacyClient(_settings, cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None); var result = await client.GetAsync($"/v3/spaces?names={HttpUtility.UrlEncode(spaceName)}", cancellationToken) - .CatchingIntoServiceExceptionFor("get-space", HttpAsyncResponseMessageExtension.RecoverOptions.ALLWAYS).ConfigureAwait(false); + .CatchingIntoServiceExceptionFor("get-space", HttpAsyncResponseMessageExtension.RecoverOptions.INFRASTRUCTURE).ConfigureAwait(false); try { var response = await result.Content .ReadFromJsonAsync(JsonSerializerExtensions.Options, cancellationToken) - .ConfigureAwait(false); + .ConfigureAwait(ConfigureAwaitOptions.None); if (response == null) { @@ -167,7 +161,7 @@ public async Task GetSpace(string tenantName, CancellationToken cancellati public async Task CreateDimServiceInstance(string tenantName, Guid spaceId, Guid servicePlanId, CancellationToken cancellationToken) { - var client = await _basicAuthTokenService.GetBasicAuthorizedLegacyClient(_settings, cancellationToken).ConfigureAwait(false); + var client = await basicAuthTokenService.GetBasicAuthorizedLegacyClient(_settings, cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None); var data = new CreateDimServiceInstance( "managed", $"{tenantName}-dim-instance", @@ -177,20 +171,20 @@ public async Task CreateDimServiceInstance(string tenantName, Guid spaceId, Guid ); await client.PostAsJsonAsync("/v3/service_instances", data, JsonSerializerExtensions.Options, cancellationToken) - .CatchingIntoServiceExceptionFor("create-dim-si", HttpAsyncResponseMessageExtension.RecoverOptions.ALLWAYS).ConfigureAwait(false); + .CatchingIntoServiceExceptionFor("create-dim-si", HttpAsyncResponseMessageExtension.RecoverOptions.INFRASTRUCTURE).ConfigureAwait(false); } private async Task GetServiceInstances(string tenantName, Guid? spaceId, CancellationToken cancellationToken) { var name = $"{tenantName}-dim-instance"; - var client = await _basicAuthTokenService.GetBasicAuthorizedLegacyClient(_settings, cancellationToken).ConfigureAwait(false); + var client = await basicAuthTokenService.GetBasicAuthorizedLegacyClient(_settings, cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None); var result = await client.GetAsync($"/v3/service_instances?names={HttpUtility.UrlEncode(name)}", cancellationToken) .CatchingIntoServiceExceptionFor("get-si", HttpAsyncResponseMessageExtension.RecoverOptions.INFRASTRUCTURE).ConfigureAwait(false); try { var response = await result.Content .ReadFromJsonAsync(JsonSerializerExtensions.Options, cancellationToken) - .ConfigureAwait(false); + .ConfigureAwait(ConfigureAwaitOptions.None); if (response == null) { throw new ServiceException("Response must not be null"); @@ -212,8 +206,8 @@ private async Task GetServiceInstances(string tenantName, Guid? spaceId, C public async Task CreateServiceInstanceBindings(string tenantName, string? keyName, Guid spaceId, CancellationToken cancellationToken) { - var serviceInstanceId = await GetServiceInstances(tenantName, spaceId, cancellationToken).ConfigureAwait(false); - var client = await _basicAuthTokenService.GetBasicAuthorizedLegacyClient(_settings, cancellationToken).ConfigureAwait(false); + var serviceInstanceId = await GetServiceInstances(tenantName, spaceId, cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None); + var client = await basicAuthTokenService.GetBasicAuthorizedLegacyClient(_settings, cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None); var data = new CreateServiceCredentialBindingRequest( "key", $"{keyName ?? tenantName}-dim-key01", @@ -221,20 +215,20 @@ public async Task CreateServiceInstanceBindings(string tenantName, string? keyNa new DimServiceInstance(new DimData(serviceInstanceId))) ); await client.PostAsJsonAsync("/v3/service_credential_bindings", data, JsonSerializerOptions.Default, cancellationToken) - .CatchingIntoServiceExceptionFor("create-si-bindings", HttpAsyncResponseMessageExtension.RecoverOptions.ALLWAYS); + .CatchingIntoServiceExceptionFor("create-si-bindings", HttpAsyncResponseMessageExtension.RecoverOptions.INFRASTRUCTURE); } public async Task GetServiceBinding(string tenantName, Guid spaceId, string bindingName, CancellationToken cancellationToken) { - var client = await _basicAuthTokenService.GetBasicAuthorizedLegacyClient(_settings, cancellationToken).ConfigureAwait(false); - var serviceInstanceId = await GetServiceInstances(tenantName, spaceId, cancellationToken).ConfigureAwait(false); + var client = await basicAuthTokenService.GetBasicAuthorizedLegacyClient(_settings, cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None); + var serviceInstanceId = await GetServiceInstances(tenantName, spaceId, cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None); var result = await client.GetAsync($"/v3/service_credential_bindings?names={HttpUtility.UrlEncode(bindingName)}", cancellationToken) .CatchingIntoServiceExceptionFor("get-credential-binding", HttpAsyncResponseMessageExtension.RecoverOptions.INFRASTRUCTURE).ConfigureAwait(false); try { var response = await result.Content .ReadFromJsonAsync(JsonSerializerExtensions.Options, cancellationToken) - .ConfigureAwait(false); + .ConfigureAwait(ConfigureAwaitOptions.None); if (response == null) { throw new ServiceException("Response must not be null"); @@ -256,14 +250,14 @@ public async Task GetServiceBinding(string tenantName, Guid spaceId, strin public async Task GetServiceBindingDetails(Guid id, CancellationToken cancellationToken) { - var client = await _basicAuthTokenService.GetBasicAuthorizedLegacyClient(_settings, cancellationToken).ConfigureAwait(false); + var client = await basicAuthTokenService.GetBasicAuthorizedLegacyClient(_settings, cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None); var result = await client.GetAsync($"/v3/service_credential_bindings/{id}/details", cancellationToken) .CatchingIntoServiceExceptionFor("get-credential-binding-name", HttpAsyncResponseMessageExtension.RecoverOptions.INFRASTRUCTURE).ConfigureAwait(false); try { var response = await result.Content .ReadFromJsonAsync(JsonSerializerExtensions.Options, cancellationToken) - .ConfigureAwait(false); + .ConfigureAwait(ConfigureAwaitOptions.None); if (response == null) { @@ -280,8 +274,8 @@ public async Task GetServiceBindingDetai public async Task DeleteServiceInstanceBindings(Guid serviceBindingId, CancellationToken cancellationToken) { - var client = await _basicAuthTokenService.GetBasicAuthorizedLegacyClient(_settings, cancellationToken).ConfigureAwait(false); + var client = await basicAuthTokenService.GetBasicAuthorizedLegacyClient(_settings, cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None); await client.DeleteAsync($"/v3/service_credential_bindings/{serviceBindingId}", cancellationToken) - .CatchingIntoServiceExceptionFor("delete-si-bindings", HttpAsyncResponseMessageExtension.RecoverOptions.ALLWAYS); + .CatchingIntoServiceExceptionFor("delete-si-bindings", HttpAsyncResponseMessageExtension.RecoverOptions.INFRASTRUCTURE); } } diff --git a/src/clients/Dim.Clients/Api/Dim/DimClient.cs b/src/clients/Dim.Clients/Api/Dim/DimClient.cs index 5ec830e..7b4ce6a 100644 --- a/src/clients/Dim.Clients/Api/Dim/DimClient.cs +++ b/src/clients/Dim.Clients/Api/Dim/DimClient.cs @@ -32,7 +32,7 @@ public class DimClient(IBasicAuthTokenService basicAuthTokenService, IHttpClient { public async Task CreateCompanyIdentity(BasicAuthSettings dimBasicAuth, Guid tenantId, string hostingUrl, string baseUrl, bool isIssuer, CancellationToken cancellationToken) { - var client = await basicAuthTokenService.GetBasicAuthorizedClient(dimBasicAuth, cancellationToken).ConfigureAwait(false); + var client = await basicAuthTokenService.GetBasicAuthorizedClient(dimBasicAuth, cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None); var data = new CreateCompanyIdentityRequest(new Payload( hostingUrl, new Network("web", "production"), @@ -51,14 +51,14 @@ [new Service($"dim:web:{tenantId}", "CredentialService", "https://dis-agent-prod .CatchingIntoServiceExceptionFor("create-company-identity", HttpAsyncResponseMessageExtension.RecoverOptions.INFRASTRUCTURE, async m => { - var message = await m.Content.ReadAsStringAsync().ConfigureAwait(false); + var message = await m.Content.ReadAsStringAsync().ConfigureAwait(ConfigureAwaitOptions.None); return (false, message); }).ConfigureAwait(false); try { var response = await result.Content .ReadFromJsonAsync(JsonSerializerExtensions.Options, cancellationToken) - .ConfigureAwait(false); + .ConfigureAwait(ConfigureAwaitOptions.None); if (response == null) { throw new ServiceException("Response was empty", true); @@ -75,14 +75,14 @@ [new Service($"dim:web:{tenantId}", "CredentialService", "https://dis-agent-prod public async Task GetDidDocument(string url, CancellationToken cancellationToken) { var client = clientFactory.CreateClient("didDocumentDownload"); - using var result = await client.GetStreamAsync(url, cancellationToken).ConfigureAwait(false); - var document = await JsonDocument.ParseAsync(result, cancellationToken: cancellationToken).ConfigureAwait(false); + using var result = await client.GetStreamAsync(url, cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None); + var document = await JsonDocument.ParseAsync(result, cancellationToken: cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None); return document; } public async Task CreateApplication(BasicAuthSettings dimAuth, string dimBaseUrl, string tenantName, CancellationToken cancellationToken) { - var client = await basicAuthTokenService.GetBasicAuthorizedClient(dimAuth, cancellationToken).ConfigureAwait(false); + var client = await basicAuthTokenService.GetBasicAuthorizedClient(dimAuth, cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None); var data = new CreateApplicationRequest(new ApplicationPayload( "catena-x-portal", $"Catena-X Portal MIW for {tenantName}", @@ -91,14 +91,14 @@ public async Task CreateApplication(BasicAuthSettings dimAuth, string di .CatchingIntoServiceExceptionFor("create-application", HttpAsyncResponseMessageExtension.RecoverOptions.INFRASTRUCTURE, async m => { - var message = await m.Content.ReadAsStringAsync().ConfigureAwait(false); + var message = await m.Content.ReadAsStringAsync().ConfigureAwait(ConfigureAwaitOptions.None); return (false, message); }).ConfigureAwait(false); try { var response = await result.Content .ReadFromJsonAsync(JsonSerializerExtensions.Options, cancellationToken) - .ConfigureAwait(false); + .ConfigureAwait(ConfigureAwaitOptions.None); if (response == null) { throw new ServiceException("Response was empty", true); @@ -114,19 +114,19 @@ public async Task CreateApplication(BasicAuthSettings dimAuth, string di public async Task GetApplication(BasicAuthSettings dimAuth, string dimBaseUrl, string applicationId, CancellationToken cancellationToken) { - var client = await basicAuthTokenService.GetBasicAuthorizedClient(dimAuth, cancellationToken).ConfigureAwait(false); + var client = await basicAuthTokenService.GetBasicAuthorizedClient(dimAuth, cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None); var result = await client.GetAsync($"{dimBaseUrl}/api/v2.0.0/applications/{applicationId}", cancellationToken) .CatchingIntoServiceExceptionFor("get-application", HttpAsyncResponseMessageExtension.RecoverOptions.INFRASTRUCTURE, async m => { - var message = await m.Content.ReadAsStringAsync().ConfigureAwait(false); + var message = await m.Content.ReadAsStringAsync().ConfigureAwait(ConfigureAwaitOptions.None); return (false, message); }).ConfigureAwait(false); try { var response = await result.Content .ReadFromJsonAsync(JsonSerializerExtensions.Options, cancellationToken) - .ConfigureAwait(false); + .ConfigureAwait(ConfigureAwaitOptions.None); if (response == null) { throw new ServiceException("Response must not be null"); @@ -142,26 +142,26 @@ public async Task GetApplication(BasicAuthSettings dimAuth, string dimBa public async Task AssignApplicationToCompany(BasicAuthSettings dimAuth, string dimBaseUrl, string applicationKey, Guid companyId, CancellationToken cancellationToken) { - var client = await basicAuthTokenService.GetBasicAuthorizedClient(dimAuth, cancellationToken).ConfigureAwait(false); + var client = await basicAuthTokenService.GetBasicAuthorizedClient(dimAuth, cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None); var data = new CompanyIdentityPatch(new ApplicationUpdates(Enumerable.Repeat(applicationKey, 1))); await client.PatchAsJsonAsync($"{dimBaseUrl}/api/v2.0.0/companyIdentities/{companyId}", data, JsonSerializerExtensions.Options, cancellationToken) .CatchingIntoServiceExceptionFor("assign-application", HttpAsyncResponseMessageExtension.RecoverOptions.INFRASTRUCTURE, async m => { - var message = await m.Content.ReadAsStringAsync().ConfigureAwait(false); + var message = await m.Content.ReadAsStringAsync().ConfigureAwait(ConfigureAwaitOptions.None); return (false, message); }).ConfigureAwait(false); } public async Task GetStatusList(BasicAuthSettings dimAuth, string dimBaseUrl, Guid companyId, CancellationToken cancellationToken) { - var client = await basicAuthTokenService.GetBasicAuthorizedClient(dimAuth, cancellationToken).ConfigureAwait(false); + var client = await basicAuthTokenService.GetBasicAuthorizedClient(dimAuth, cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None); var result = await client.GetAsync($"{dimBaseUrl}/api/v2.0.0/companyIdentities/{companyId}/revocationLists", cancellationToken); try { var response = await result.Content .ReadFromJsonAsync(JsonSerializerExtensions.Options, cancellationToken) - .ConfigureAwait(false); + .ConfigureAwait(ConfigureAwaitOptions.None); if (response == null) { throw new ServiceException("Response must not be null"); @@ -182,20 +182,20 @@ public async Task GetStatusList(BasicAuthSettings dimAuth, string dimBas public async Task CreateStatusList(BasicAuthSettings dimAuth, string dimBaseUrl, Guid companyId, CancellationToken cancellationToken) { - var client = await basicAuthTokenService.GetBasicAuthorizedClient(dimAuth, cancellationToken).ConfigureAwait(false); + var client = await basicAuthTokenService.GetBasicAuthorizedClient(dimAuth, cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None); var data = new CreateStatusListRequest(new CreateStatusListPaypload(new CreateStatusList("StatusList2021", DateTimeOffset.UtcNow.ToString("yyyyMMdd"), "New revocation list", 2097152))); var result = await client.PostAsJsonAsync($"{dimBaseUrl}/api/v2.0.0/companyIdentities/{companyId}/revocationLists", data, JsonSerializerExtensions.Options, cancellationToken) .CatchingIntoServiceExceptionFor("assign-application", HttpAsyncResponseMessageExtension.RecoverOptions.INFRASTRUCTURE, async m => { - var message = await m.Content.ReadAsStringAsync().ConfigureAwait(false); + var message = await m.Content.ReadAsStringAsync().ConfigureAwait(ConfigureAwaitOptions.None); return (false, message); }).ConfigureAwait(false); try { var response = await result.Content .ReadFromJsonAsync(JsonSerializerExtensions.Options, cancellationToken) - .ConfigureAwait(false); + .ConfigureAwait(ConfigureAwaitOptions.None); if (response == null) { throw new ServiceException("Response must not be null"); diff --git a/src/clients/Dim.Clients/Api/Directories/DirectoryClient.cs b/src/clients/Dim.Clients/Api/Directories/DirectoryClient.cs index fd50052..62ca961 100644 --- a/src/clients/Dim.Clients/Api/Directories/DirectoryClient.cs +++ b/src/clients/Dim.Clients/Api/Directories/DirectoryClient.cs @@ -29,20 +29,14 @@ namespace Dim.Clients.Api.Directories; -public class DirectoryClient : IDirectoryClient +public class DirectoryClient(IBasicAuthTokenService basicAuthTokenService, IOptions settings) + : IDirectoryClient { - private readonly DirectorySettings _settings; - private readonly IBasicAuthTokenService _basicAuthTokenService; - - public DirectoryClient(IBasicAuthTokenService basicAuthTokenService, IOptions settings) - { - _basicAuthTokenService = basicAuthTokenService; - _settings = settings.Value; - } + private readonly DirectorySettings _settings = settings.Value; public async Task CreateDirectory(string description, string bpnl, Guid parentId, CancellationToken cancellationToken) { - var client = await _basicAuthTokenService.GetBasicAuthorizedClient(_settings, cancellationToken).ConfigureAwait(false); + var client = await basicAuthTokenService.GetBasicAuthorizedClient(_settings, cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None); var directory = new DirectoryRequest( description, Enumerable.Repeat("phil.schneider@digitalnativesolutions.de", 1), @@ -59,7 +53,7 @@ public async Task CreateDirectory(string description, string bpnl, Guid pa { var response = await result.Content .ReadFromJsonAsync(JsonSerializerExtensions.Options, cancellationToken) - .ConfigureAwait(false); + .ConfigureAwait(ConfigureAwaitOptions.None); if (response == null) { diff --git a/src/clients/Dim.Clients/Api/Entitlements/EntitlementClient.cs b/src/clients/Dim.Clients/Api/Entitlements/EntitlementClient.cs index 8103474..bd0005d 100644 --- a/src/clients/Dim.Clients/Api/Entitlements/EntitlementClient.cs +++ b/src/clients/Dim.Clients/Api/Entitlements/EntitlementClient.cs @@ -25,18 +25,11 @@ namespace Dim.Clients.Api.Entitlements; -public class EntitlementClient : IEntitlementClient +public class EntitlementClient(IBasicAuthTokenService basicAuthTokenService) : IEntitlementClient { - private readonly IBasicAuthTokenService _basicAuthTokenService; - - public EntitlementClient(IBasicAuthTokenService basicAuthTokenService) - { - _basicAuthTokenService = basicAuthTokenService; - } - public async Task AssignEntitlements(BasicAuthSettings basicAuthSettings, Guid subAccountId, CancellationToken cancellationToken) { - var client = await _basicAuthTokenService.GetBasicAuthorizedClient(basicAuthSettings, cancellationToken).ConfigureAwait(false); + var client = await basicAuthTokenService.GetBasicAuthorizedClient(basicAuthSettings, cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None); var data = new CreateSubAccountRequest( new List { diff --git a/src/clients/Dim.Clients/Api/Provisioning/ProvisioningClient.cs b/src/clients/Dim.Clients/Api/Provisioning/ProvisioningClient.cs index a986b87..9afb8e9 100644 --- a/src/clients/Dim.Clients/Api/Provisioning/ProvisioningClient.cs +++ b/src/clients/Dim.Clients/Api/Provisioning/ProvisioningClient.cs @@ -26,15 +26,8 @@ namespace Dim.Clients.Api.Provisioning; -public class ProvisioningClient : IProvisioningClient +public class ProvisioningClient(IBasicAuthTokenService basicAuthTokenService) : IProvisioningClient { - private readonly IBasicAuthTokenService _basicAuthTokenService; - - public ProvisioningClient(IBasicAuthTokenService basicAuthTokenService) - { - _basicAuthTokenService = basicAuthTokenService; - } - public async Task CreateCloudFoundryEnvironment(string authUrl, BindingItem bindingData, string tenantName, string user, CancellationToken cancellationToken) { var authSettings = new BasicAuthSettings @@ -43,7 +36,7 @@ public async Task CreateCloudFoundryEnvironment(string authUrl, BindingItem bind ClientId = bindingData.Credentials.Uaa.ClientId, ClientSecret = bindingData.Credentials.Uaa.ClientSecret }; - var client = await _basicAuthTokenService.GetBasicAuthorizedClient(authSettings, cancellationToken).ConfigureAwait(false); + var client = await basicAuthTokenService.GetBasicAuthorizedClient(authSettings, cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None); var data = new CreateCfeRequest( "cloudfoundry", new Dictionary diff --git a/src/clients/Dim.Clients/Api/Services/ServiceClient.cs b/src/clients/Dim.Clients/Api/Services/ServiceClient.cs index d6da273..b812640 100644 --- a/src/clients/Dim.Clients/Api/Services/ServiceClient.cs +++ b/src/clients/Dim.Clients/Api/Services/ServiceClient.cs @@ -28,15 +28,8 @@ namespace Dim.Clients.Api.Services; -public class ServiceClient : IServiceClient +public class ServiceClient(IBasicAuthTokenService basicAuthTokenService) : IServiceClient { - private readonly IBasicAuthTokenService _basicAuthTokenService; - - public ServiceClient(IBasicAuthTokenService basicAuthTokenService) - { - _basicAuthTokenService = basicAuthTokenService; - } - public async Task CreateServiceInstance(ServiceManagementBindingItem saBinding, CancellationToken cancellationToken) { var serviceAuth = new BasicAuthSettings @@ -45,7 +38,7 @@ public async Task CreateServiceInstance(ServiceMa ClientId = saBinding.ClientId, ClientSecret = saBinding.ClientSecret }; - var client = await _basicAuthTokenService.GetBasicAuthorizedClient(serviceAuth, cancellationToken).ConfigureAwait(false); + var client = await basicAuthTokenService.GetBasicAuthorizedClient(serviceAuth, cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None); var directory = new CreateServiceInstanceRequest( "cis-local-instance", "cis", @@ -57,12 +50,12 @@ public async Task CreateServiceInstance(ServiceMa ); var result = await client.PostAsJsonAsync($"{saBinding.SmUrl}/v1/service_instances?async=false", directory, JsonSerializerExtensions.Options, cancellationToken) - .CatchingIntoServiceExceptionFor("create-service-instance", HttpAsyncResponseMessageExtension.RecoverOptions.ALLWAYS).ConfigureAwait(false); + .CatchingIntoServiceExceptionFor("create-service-instance", HttpAsyncResponseMessageExtension.RecoverOptions.INFRASTRUCTURE).ConfigureAwait(false); try { var response = await result.Content .ReadFromJsonAsync(JsonSerializerExtensions.Options, cancellationToken) - .ConfigureAwait(false); + .ConfigureAwait(ConfigureAwaitOptions.None); if (response == null) { throw new ServiceException("Response was empty", true); @@ -84,7 +77,7 @@ public async Task CreateServiceBinding(ServiceMana ClientId = saBinding.ClientId, ClientSecret = saBinding.ClientSecret }; - var client = await _basicAuthTokenService.GetBasicAuthorizedClient(serviceAuth, cancellationToken).ConfigureAwait(false); + var client = await basicAuthTokenService.GetBasicAuthorizedClient(serviceAuth, cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None); var data = new CreateServiceBindingRequest( "cis-local-binding", serviceInstanceId @@ -96,7 +89,7 @@ public async Task CreateServiceBinding(ServiceMana { var response = await result.Content .ReadFromJsonAsync(JsonSerializerExtensions.Options, cancellationToken) - .ConfigureAwait(false); + .ConfigureAwait(ConfigureAwaitOptions.None); if (response == null) { throw new ServiceException("Response was empty", true); @@ -118,14 +111,14 @@ public async Task GetServiceBinding(ServiceManagementBindingItem sa ClientId = saBinding.ClientId, ClientSecret = saBinding.ClientSecret }; - var client = await _basicAuthTokenService.GetBasicAuthorizedClient(serviceAuth, cancellationToken).ConfigureAwait(false); + var client = await basicAuthTokenService.GetBasicAuthorizedClient(serviceAuth, cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None); var result = await client.GetAsync($"{saBinding.SmUrl}/v1/service_bindings?fieldQuery=name eq '{serviceBindingName}'", cancellationToken) .CatchingIntoServiceExceptionFor("get-service-binding", HttpAsyncResponseMessageExtension.RecoverOptions.INFRASTRUCTURE).ConfigureAwait(false); try { var response = await result.Content .ReadFromJsonAsync(JsonSerializerExtensions.Options, cancellationToken) - .ConfigureAwait(false); + .ConfigureAwait(ConfigureAwaitOptions.None); if (response == null) { throw new ServiceException("Response was empty", true); diff --git a/src/clients/Dim.Clients/Api/SubAccounts/SubAccountClient.cs b/src/clients/Dim.Clients/Api/SubAccounts/SubAccountClient.cs index 3150304..b2fe2fc 100644 --- a/src/clients/Dim.Clients/Api/SubAccounts/SubAccountClient.cs +++ b/src/clients/Dim.Clients/Api/SubAccounts/SubAccountClient.cs @@ -28,20 +28,15 @@ namespace Dim.Clients.Api.SubAccounts; -public class SubAccountClient : ISubAccountClient +public class SubAccountClient(IBasicAuthTokenService basicAuthTokenService) + : ISubAccountClient { private static readonly Regex TenantName = new(@"(?<=[^\w-])|(?<=[^-])[\W_]+|(?<=[^-])$", RegexOptions.Compiled, new TimeSpan(0, 0, 0, 1)); - private readonly IBasicAuthTokenService _basicAuthTokenService; - - public SubAccountClient(IBasicAuthTokenService basicAuthTokenService) - { - _basicAuthTokenService = basicAuthTokenService; - } public async Task CreateSubaccount(BasicAuthSettings basicAuthSettings, string adminMail, string tenantName, Guid directoryId, CancellationToken cancellationToken) { var subdomain = TenantName.Replace(tenantName, "-").ToLower().TrimStart('-').TrimEnd('-'); - var client = await _basicAuthTokenService.GetBasicAuthorizedClient(basicAuthSettings, cancellationToken).ConfigureAwait(false); + var client = await basicAuthTokenService.GetBasicAuthorizedClient(basicAuthSettings, cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None); var directory = new CreateSubAccountRequest( false, $"CX customer sub-account {tenantName}", @@ -60,16 +55,12 @@ public async Task CreateSubaccount(BasicAuthSettings basicAuthSettings, st ); var result = await client.PostAsJsonAsync("/accounts/v1/subaccounts", directory, JsonSerializerExtensions.Options, cancellationToken) - .CatchingIntoServiceExceptionFor("create-subaccount", HttpAsyncResponseMessageExtension.RecoverOptions.INFRASTRUCTURE, async message => - { - var errorMessage = await message.Content.ReadAsStringAsync().ConfigureAwait(false); - return new(false, errorMessage); - }).ConfigureAwait(false); + .CatchingIntoServiceExceptionFor("create-subaccount", HttpAsyncResponseMessageExtension.RecoverOptions.INFRASTRUCTURE).ConfigureAwait(false); try { var response = await result.Content .ReadFromJsonAsync(JsonSerializerExtensions.Options, cancellationToken) - .ConfigureAwait(false); + .ConfigureAwait(ConfigureAwaitOptions.None); if (response == null) { @@ -86,27 +77,27 @@ public async Task CreateSubaccount(BasicAuthSettings basicAuthSettings, st public async Task CreateServiceManagerBindings(BasicAuthSettings basicAuthSettings, Guid subAccountId, CancellationToken cancellationToken) { - var client = await _basicAuthTokenService.GetBasicAuthorizedClient(basicAuthSettings, cancellationToken).ConfigureAwait(false); + var client = await basicAuthTokenService.GetBasicAuthorizedClient(basicAuthSettings, cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None); var data = new { name = "accessServiceManager" }; await client.PostAsJsonAsync($"/accounts/v2/subaccounts/{subAccountId}/serviceManagerBindings", data, JsonSerializerExtensions.Options, cancellationToken) - .CatchingIntoServiceExceptionFor("create-subaccount", HttpAsyncResponseMessageExtension.RecoverOptions.ALLWAYS).ConfigureAwait(false); + .CatchingIntoServiceExceptionFor("create-subaccount", HttpAsyncResponseMessageExtension.RecoverOptions.INFRASTRUCTURE).ConfigureAwait(false); } public async Task GetServiceManagerBindings(BasicAuthSettings basicAuthSettings, Guid subAccountId, CancellationToken cancellationToken) { - var client = await _basicAuthTokenService.GetBasicAuthorizedClient(basicAuthSettings, cancellationToken).ConfigureAwait(false); + var client = await basicAuthTokenService.GetBasicAuthorizedClient(basicAuthSettings, cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None); var result = await client.GetAsync($"/accounts/v2/subaccounts/{subAccountId}/serviceManagerBindings", cancellationToken) - .CatchingIntoServiceExceptionFor("create-subaccount", HttpAsyncResponseMessageExtension.RecoverOptions.ALLWAYS).ConfigureAwait(false); + .CatchingIntoServiceExceptionFor("create-subaccount", HttpAsyncResponseMessageExtension.RecoverOptions.INFRASTRUCTURE).ConfigureAwait(false); try { var response = await result.Content .ReadFromJsonAsync(JsonSerializerExtensions.Options, cancellationToken) - .ConfigureAwait(false); + .ConfigureAwait(ConfigureAwaitOptions.None); if (response == null || response.Items.Count() != 1) { diff --git a/src/clients/Dim.Clients/Api/Subscriptions/SubscriptionClient.cs b/src/clients/Dim.Clients/Api/Subscriptions/SubscriptionClient.cs index 04bb6b8..4ac1bf2 100644 --- a/src/clients/Dim.Clients/Api/Subscriptions/SubscriptionClient.cs +++ b/src/clients/Dim.Clients/Api/Subscriptions/SubscriptionClient.cs @@ -26,15 +26,9 @@ namespace Dim.Clients.Api.Subscriptions; -public class SubscriptionClient : ISubscriptionClient +public class SubscriptionClient(IBasicAuthTokenService basicAuthTokenService) + : ISubscriptionClient { - private readonly IBasicAuthTokenService _basicAuthTokenService; - - public SubscriptionClient(IBasicAuthTokenService basicAuthTokenService) - { - _basicAuthTokenService = basicAuthTokenService; - } - public async Task SubscribeApplication(string authUrl, BindingItem bindingData, string applicationName, string planName, CancellationToken cancellationToken) { var authSettings = new BasicAuthSettings @@ -43,7 +37,7 @@ public async Task SubscribeApplication(string authUrl, BindingItem bindingData, ClientId = bindingData.Credentials.Uaa.ClientId, ClientSecret = bindingData.Credentials.Uaa.ClientSecret }; - var client = await _basicAuthTokenService.GetBasicAuthorizedClient(authSettings, cancellationToken).ConfigureAwait(false); + var client = await basicAuthTokenService.GetBasicAuthorizedClient(authSettings, cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None); var data = new { planName = planName diff --git a/src/clients/Dim.Clients/Token/BasicAuthTokenService.cs b/src/clients/Dim.Clients/Token/BasicAuthTokenService.cs index d817fbb..44a8742 100644 --- a/src/clients/Dim.Clients/Token/BasicAuthTokenService.cs +++ b/src/clients/Dim.Clients/Token/BasicAuthTokenService.cs @@ -25,15 +25,8 @@ namespace Dim.Clients.Token; -public class BasicAuthTokenService : IBasicAuthTokenService +public class BasicAuthTokenService(IHttpClientFactory httpClientFactory) : IBasicAuthTokenService { - private readonly IHttpClientFactory _httpClientFactory; - - public BasicAuthTokenService(IHttpClientFactory httpClientFactory) - { - _httpClientFactory = httpClientFactory; - } - public async Task GetBasicAuthorizedClient(BasicAuthSettings settings, CancellationToken cancellationToken) { var tokenParameters = new GetBasicTokenSettings( @@ -42,9 +35,9 @@ public async Task GetBasicAuthorizedClient(BasicAuthSettings sett settings.ClientSecret, settings.TokenAddress); - var token = await this.GetBasicTokenAsync(tokenParameters, cancellationToken).ConfigureAwait(false); + var token = await this.GetBasicTokenAsync(tokenParameters, cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None); - var httpClient = _httpClientFactory.CreateClient(typeof(T).Name); + var httpClient = httpClientFactory.CreateClient(typeof(T).Name); httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token); return httpClient; } @@ -57,9 +50,9 @@ public async Task GetBasicAuthorizedLegacyClient(BasicAuthSetting settings.ClientSecret, settings.TokenAddress); - var token = await this.GetBasicLegacyToken(tokenParameters, cancellationToken).ConfigureAwait(false); + var token = await this.GetBasicLegacyToken(tokenParameters, cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None); - var httpClient = _httpClientFactory.CreateClient(typeof(T).Name); + var httpClient = httpClientFactory.CreateClient(typeof(T).Name); httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token); return httpClient; } @@ -71,7 +64,7 @@ public async Task GetBasicAuthorizedLegacyClient(BasicAuthSetting { "grant_type", "client_credentials" } }; var content = new FormUrlEncodedContent(formParameters); - var authClient = _httpClientFactory.CreateClient(settings.HttpClientName); + var authClient = httpClientFactory.CreateClient(settings.HttpClientName); var authenticationString = $"{settings.ClientId}:{settings.ClientSecret}"; var base64String = Convert.ToBase64String(System.Text.Encoding.ASCII.GetBytes(authenticationString)); @@ -80,7 +73,7 @@ public async Task GetBasicAuthorizedLegacyClient(BasicAuthSetting var response = await authClient.PostAsync(settings.TokenAddress, content, cancellationToken) .CatchingIntoServiceExceptionFor("token-post", HttpAsyncResponseMessageExtension.RecoverOptions.INFRASTRUCTURE).ConfigureAwait(false); - var responseObject = await response.Content.ReadFromJsonAsync(JsonSerializerExtensions.Options, cancellationToken).ConfigureAwait(false); + var responseObject = await response.Content.ReadFromJsonAsync(JsonSerializerExtensions.Options, cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None); return responseObject?.AccessToken; } @@ -95,14 +88,14 @@ public async Task GetBasicAuthorizedLegacyClient(BasicAuthSetting { "response_type", "token" } }; var content = new FormUrlEncodedContent(formParameters); - var authClient = _httpClientFactory.CreateClient(settings.HttpClientName); + var authClient = httpClientFactory.CreateClient(settings.HttpClientName); var base64String = Convert.ToBase64String("cf:"u8.ToArray()); authClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", base64String); var response = await authClient.PostAsync(settings.TokenAddress, content, cancellationToken) .CatchingIntoServiceExceptionFor("token-post", HttpAsyncResponseMessageExtension.RecoverOptions.INFRASTRUCTURE).ConfigureAwait(false); - var responseObject = await response.Content.ReadFromJsonAsync(JsonSerializerExtensions.Options, cancellationToken).ConfigureAwait(false); + var responseObject = await response.Content.ReadFromJsonAsync(JsonSerializerExtensions.Options, cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None); return responseObject?.AccessToken; } } diff --git a/src/database/Dim.DbAccess/Models/ProcessData.cs b/src/database/Dim.DbAccess/Models/ProcessData.cs new file mode 100644 index 0000000..2656d8e --- /dev/null +++ b/src/database/Dim.DbAccess/Models/ProcessData.cs @@ -0,0 +1,33 @@ +/******************************************************************************** + * Copyright (c) 2024 BMW Group AG + * Copyright 2024 SAP SE or an SAP affiliate company and ssi-dim-middle-layer contributors. + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0. + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + * SPDX-License-Identifier: Apache-2.0 + ********************************************************************************/ + +using Dim.Entities.Enums; + +namespace Dim.DbAccess.Models; + +public record ProcessData( + Guid ProcessId, + IEnumerable ProcessStepData +); + +public record ProcessStepData( + ProcessStepTypeId ProcessStepTypeId, + ProcessStepStatusId ProcessStepStatusId +); diff --git a/src/database/Dim.DbAccess/Repositories/IProcessStepRepository.cs b/src/database/Dim.DbAccess/Repositories/IProcessStepRepository.cs index f9b26df..e6b2f9b 100644 --- a/src/database/Dim.DbAccess/Repositories/IProcessStepRepository.cs +++ b/src/database/Dim.DbAccess/Repositories/IProcessStepRepository.cs @@ -18,6 +18,7 @@ * SPDX-License-Identifier: Apache-2.0 ********************************************************************************/ +using Dim.DbAccess.Models; using Dim.Entities.Entities; using Dim.Entities.Enums; @@ -35,4 +36,8 @@ public interface IProcessStepRepository void AttachAndModifyProcessSteps(IEnumerable<(Guid ProcessStepId, Action? Initialize, Action Modify)> processStepIdsInitializeModifyData); IAsyncEnumerable GetActiveProcesses(IEnumerable processTypeIds, IEnumerable processStepTypeIds, DateTimeOffset lockExpiryDate); IAsyncEnumerable<(Guid ProcessStepId, ProcessStepTypeId ProcessStepTypeId)> GetProcessStepData(Guid processId); + Task GetWalletProcessForTenant(string bpn, string companyName); + Task GetTechnicalUserProcess(string technicalUserName); + Task<(bool ProcessExists, VerifyProcessData ProcessData)> IsValidProcess(Guid processId, ProcessTypeId processTypeId, IEnumerable processSetpTypeIds); + } diff --git a/src/database/Dim.DbAccess/Repositories/ProcessStepRepository.cs b/src/database/Dim.DbAccess/Repositories/ProcessStepRepository.cs index cc66c45..6f8ffb7 100644 --- a/src/database/Dim.DbAccess/Repositories/ProcessStepRepository.cs +++ b/src/database/Dim.DbAccess/Repositories/ProcessStepRepository.cs @@ -18,6 +18,7 @@ * SPDX-License-Identifier: Apache-2.0 ********************************************************************************/ +using Dim.DbAccess.Models; using Dim.Entities; using Dim.Entities.Entities; using Dim.Entities.Enums; @@ -42,10 +43,10 @@ public ProcessStepRepository(DimDbContext dimDbContext) public Process CreateProcess(ProcessTypeId processTypeId) => _context.Add(new Process(Guid.NewGuid(), processTypeId, Guid.NewGuid())).Entity; - public ProcessStep CreateProcessStep(Dim.Entities.Enums.ProcessStepTypeId processStepTypeId, Dim.Entities.Enums.ProcessStepStatusId processStepStatusId, Guid processId) => + public ProcessStep CreateProcessStep(ProcessStepTypeId processStepTypeId, ProcessStepStatusId processStepStatusId, Guid processId) => _context.Add(new ProcessStep(Guid.NewGuid(), processStepTypeId, processStepStatusId, processId, DateTimeOffset.UtcNow)).Entity; - public IEnumerable CreateProcessStepRange(IEnumerable<(Dim.Entities.Enums.ProcessStepTypeId ProcessStepTypeId, Dim.Entities.Enums.ProcessStepStatusId ProcessStepStatusId, Guid ProcessId)> processStepTypeStatus) + public IEnumerable CreateProcessStepRange(IEnumerable<(ProcessStepTypeId ProcessStepTypeId, ProcessStepStatusId ProcessStepStatusId, Guid ProcessId)> processStepTypeStatus) { var processSteps = processStepTypeStatus.Select(x => new ProcessStep(Guid.NewGuid(), x.ProcessStepTypeId, x.ProcessStepStatusId, x.ProcessId, DateTimeOffset.UtcNow)).ToList(); _context.AddRange(processSteps); @@ -98,4 +99,43 @@ public IAsyncEnumerable GetActiveProcesses(IEnumerable p step.Id, step.ProcessStepTypeId)) .AsAsyncEnumerable(); + + public Task GetWalletProcessForTenant(string bpn, string companyName) => + _context.Processes + .Where(x => + x.ProcessTypeId == ProcessTypeId.SETUP_DIM && + x.Tenant!.Bpn == bpn && + x.Tenant.CompanyName == companyName) + .Select(x => new ProcessData( + x.Id, + x.ProcessSteps.Select(ps => new ProcessStepData( + ps.ProcessStepTypeId, + ps.ProcessStepStatusId)))) + .SingleOrDefaultAsync(); + + public Task GetTechnicalUserProcess(string technicalUserName) => + _context.Processes + .Where(x => + x.ProcessTypeId == ProcessTypeId.TECHNICAL_USER && + x.TechnicalUser!.TechnicalUserName == technicalUserName) + .Select(x => new ProcessData( + x.Id, + x.ProcessSteps.Select(ps => new ProcessStepData( + ps.ProcessStepTypeId, + ps.ProcessStepStatusId)))) + .SingleOrDefaultAsync(); + + public Task<(bool ProcessExists, VerifyProcessData ProcessData)> IsValidProcess(Guid processId, ProcessTypeId processTypeId, IEnumerable processStepTypeIds) => _context.Processes + .AsNoTracking() + .Where(x => x.Id == processId && x.ProcessTypeId == processTypeId) + .Select(x => new ValueTuple( + true, + new VerifyProcessData( + x, + x.ProcessSteps + .Where(step => + processStepTypeIds.Contains(step.ProcessStepTypeId) && + step.ProcessStepStatusId == ProcessStepStatusId.TODO)) + )) + .SingleOrDefaultAsync(); } diff --git a/src/database/Dim.Entities/DimDbContext.cs b/src/database/Dim.Entities/DimDbContext.cs index 61df8bb..0d4701e 100644 --- a/src/database/Dim.Entities/DimDbContext.cs +++ b/src/database/Dim.Entities/DimDbContext.cs @@ -89,16 +89,16 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) modelBuilder.Entity(t => { t.HasOne(d => d.Process) - .WithMany(p => p.Tenants) - .HasForeignKey(d => d.ProcessId) + .WithOne(p => p.Tenant) + .HasForeignKey(d => d.ProcessId) .OnDelete(DeleteBehavior.ClientSetNull); }); modelBuilder.Entity(tu => { tu.HasOne(d => d.Process) - .WithMany(p => p.TechnicalUsers) - .HasForeignKey(d => d.ProcessId) + .WithOne(p => p.TechnicalUser) + .HasForeignKey(d => d.ProcessId) .OnDelete(DeleteBehavior.ClientSetNull); tu.HasOne(t => t.Tenant) diff --git a/src/database/Dim.Entities/Entities/Process.cs b/src/database/Dim.Entities/Entities/Process.cs index 048c4f3..7f9e48d 100644 --- a/src/database/Dim.Entities/Entities/Process.cs +++ b/src/database/Dim.Entities/Entities/Process.cs @@ -29,8 +29,6 @@ public class Process : ILockableEntity private Process() { ProcessSteps = new HashSet(); - Tenants = new HashSet(); - TechnicalUsers = new HashSet(); } public Process(Guid id, ProcessTypeId processTypeId, Guid version) : this() @@ -51,7 +49,7 @@ public Process(Guid id, ProcessTypeId processTypeId, Guid version) : this() // Navigation properties public virtual ProcessType? ProcessType { get; set; } + public virtual Tenant? Tenant { get; set; } + public virtual TechnicalUser? TechnicalUser { get; set; } public virtual ICollection ProcessSteps { get; private set; } - public virtual ICollection Tenants { get; private set; } - public virtual ICollection TechnicalUsers { get; private set; } } diff --git a/src/database/Dim.Entities/Enums/ProcessStepTypeId.cs b/src/database/Dim.Entities/Enums/ProcessStepTypeId.cs index c11b7de..44e7b60 100644 --- a/src/database/Dim.Entities/Enums/ProcessStepTypeId.cs +++ b/src/database/Dim.Entities/Enums/ProcessStepTypeId.cs @@ -41,6 +41,24 @@ public enum ProcessStepTypeId ASSIGN_COMPANY_APPLICATION = 16, CREATE_STATUS_LIST = 17, SEND_CALLBACK = 18, + RETRIGGER_CREATE_SUBACCOUNT = 19, + RETRIGGER_CREATE_SERVICEMANAGER_BINDINGS = 20, + RETRIGGER_ASSIGN_ENTITLEMENTS = 21, + RETRIGGER_CREATE_SERVICE_INSTANCE = 22, + RETRIGGER_CREATE_SERVICE_BINDING = 23, + RETRIGGER_SUBSCRIBE_APPLICATION = 24, + RETRIGGER_CREATE_CLOUD_FOUNDRY_ENVIRONMENT = 25, + RETRIGGER_CREATE_CLOUD_FOUNDRY_SPACE = 26, + RETRIGGER_ADD_SPACE_MANAGER_ROLE = 27, + RETRIGGER_ADD_SPACE_DEVELOPER_ROLE = 28, + RETRIGGER_CREATE_DIM_SERVICE_INSTANCE = 29, + RETRIGGER_CREATE_SERVICE_INSTANCE_BINDING = 30, + RETRIGGER_GET_DIM_DETAILS = 31, + RETRIGGER_CREATE_APPLICATION = 32, + RETRIGGER_CREATE_COMPANY_IDENTITY = 33, + RETRIGGER_ASSIGN_COMPANY_APPLICATION = 34, + RETRIGGER_CREATE_STATUS_LIST = 35, + RETRIGGER_SEND_CALLBACK = 36, // Create Technical User CREATE_TECHNICAL_USER = 100, diff --git a/src/database/Dim.Entities/Extensions/ProcessStepTypeIdExtensions.cs b/src/database/Dim.Entities/Extensions/ProcessStepTypeIdExtensions.cs new file mode 100644 index 0000000..194ff7c --- /dev/null +++ b/src/database/Dim.Entities/Extensions/ProcessStepTypeIdExtensions.cs @@ -0,0 +1,74 @@ +/******************************************************************************** + * Copyright (c) 2024 BMW Group AG + * Copyright 2024 SAP SE or an SAP affiliate company and ssi-dim-middle-layer contributors. + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0. + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + * SPDX-License-Identifier: Apache-2.0 + ********************************************************************************/ + +using Dim.Entities.Enums; + +namespace Dim.Entities.Extensions; + +public static class ProcessStepTypeIdExtensions +{ + public static ProcessStepTypeId GetWalletRetriggerStep(this ProcessStepTypeId processStepTypeId) => + processStepTypeId switch + { + ProcessStepTypeId.SEND_CALLBACK => ProcessStepTypeId.RETRIGGER_SEND_CALLBACK, + ProcessStepTypeId.CREATE_SUBACCOUNT => ProcessStepTypeId.RETRIGGER_CREATE_SUBACCOUNT, + ProcessStepTypeId.CREATE_SERVICEMANAGER_BINDINGS => ProcessStepTypeId.RETRIGGER_CREATE_SERVICEMANAGER_BINDINGS, + ProcessStepTypeId.ASSIGN_ENTITLEMENTS => ProcessStepTypeId.RETRIGGER_ASSIGN_ENTITLEMENTS, + ProcessStepTypeId.CREATE_SERVICE_INSTANCE => ProcessStepTypeId.RETRIGGER_CREATE_SERVICE_INSTANCE, + ProcessStepTypeId.CREATE_SERVICE_BINDING => ProcessStepTypeId.RETRIGGER_CREATE_SERVICE_BINDING, + ProcessStepTypeId.SUBSCRIBE_APPLICATION => ProcessStepTypeId.RETRIGGER_SUBSCRIBE_APPLICATION, + ProcessStepTypeId.CREATE_CLOUD_FOUNDRY_ENVIRONMENT => ProcessStepTypeId.RETRIGGER_CREATE_CLOUD_FOUNDRY_ENVIRONMENT, + ProcessStepTypeId.CREATE_CLOUD_FOUNDRY_SPACE => ProcessStepTypeId.RETRIGGER_CREATE_CLOUD_FOUNDRY_SPACE, + ProcessStepTypeId.ADD_SPACE_MANAGER_ROLE => ProcessStepTypeId.RETRIGGER_ADD_SPACE_MANAGER_ROLE, + ProcessStepTypeId.ADD_SPACE_DEVELOPER_ROLE => ProcessStepTypeId.RETRIGGER_ADD_SPACE_DEVELOPER_ROLE, + ProcessStepTypeId.CREATE_DIM_SERVICE_INSTANCE => ProcessStepTypeId.RETRIGGER_CREATE_DIM_SERVICE_INSTANCE, + ProcessStepTypeId.CREATE_SERVICE_INSTANCE_BINDING => ProcessStepTypeId.RETRIGGER_CREATE_SERVICE_INSTANCE_BINDING, + ProcessStepTypeId.GET_DIM_DETAILS => ProcessStepTypeId.RETRIGGER_GET_DIM_DETAILS, + ProcessStepTypeId.CREATE_APPLICATION => ProcessStepTypeId.RETRIGGER_CREATE_APPLICATION, + ProcessStepTypeId.CREATE_COMPANY_IDENTITY => ProcessStepTypeId.RETRIGGER_CREATE_COMPANY_IDENTITY, + ProcessStepTypeId.ASSIGN_COMPANY_APPLICATION => ProcessStepTypeId.RETRIGGER_ASSIGN_COMPANY_APPLICATION, + 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 + { + ProcessStepTypeId.RETRIGGER_SEND_CALLBACK => ProcessStepTypeId.SEND_CALLBACK, + ProcessStepTypeId.RETRIGGER_CREATE_SUBACCOUNT => ProcessStepTypeId.CREATE_SUBACCOUNT, + ProcessStepTypeId.RETRIGGER_CREATE_SERVICEMANAGER_BINDINGS => ProcessStepTypeId.CREATE_SERVICEMANAGER_BINDINGS, + ProcessStepTypeId.RETRIGGER_ASSIGN_ENTITLEMENTS => ProcessStepTypeId.ASSIGN_ENTITLEMENTS, + ProcessStepTypeId.RETRIGGER_CREATE_SERVICE_INSTANCE => ProcessStepTypeId.CREATE_SERVICE_INSTANCE, + ProcessStepTypeId.RETRIGGER_CREATE_SERVICE_BINDING => ProcessStepTypeId.CREATE_SERVICE_BINDING, + ProcessStepTypeId.RETRIGGER_SUBSCRIBE_APPLICATION => ProcessStepTypeId.SUBSCRIBE_APPLICATION, + ProcessStepTypeId.RETRIGGER_CREATE_CLOUD_FOUNDRY_ENVIRONMENT => ProcessStepTypeId.CREATE_CLOUD_FOUNDRY_ENVIRONMENT, + ProcessStepTypeId.RETRIGGER_CREATE_CLOUD_FOUNDRY_SPACE => ProcessStepTypeId.CREATE_CLOUD_FOUNDRY_SPACE, + ProcessStepTypeId.RETRIGGER_ADD_SPACE_MANAGER_ROLE => ProcessStepTypeId.ADD_SPACE_MANAGER_ROLE, + ProcessStepTypeId.RETRIGGER_ADD_SPACE_DEVELOPER_ROLE => ProcessStepTypeId.ADD_SPACE_DEVELOPER_ROLE, + ProcessStepTypeId.RETRIGGER_CREATE_DIM_SERVICE_INSTANCE => ProcessStepTypeId.CREATE_DIM_SERVICE_INSTANCE, + ProcessStepTypeId.RETRIGGER_CREATE_SERVICE_INSTANCE_BINDING => ProcessStepTypeId.CREATE_SERVICE_INSTANCE_BINDING, + ProcessStepTypeId.RETRIGGER_GET_DIM_DETAILS => ProcessStepTypeId.GET_DIM_DETAILS, + ProcessStepTypeId.RETRIGGER_CREATE_APPLICATION => ProcessStepTypeId.CREATE_APPLICATION, + ProcessStepTypeId.RETRIGGER_CREATE_COMPANY_IDENTITY => ProcessStepTypeId.CREATE_COMPANY_IDENTITY, + ProcessStepTypeId.RETRIGGER_ASSIGN_COMPANY_APPLICATION => ProcessStepTypeId.ASSIGN_COMPANY_APPLICATION, + ProcessStepTypeId.RETRIGGER_CREATE_STATUS_LIST => ProcessStepTypeId.CREATE_STATUS_LIST, + _ => throw new ArgumentOutOfRangeException(nameof(processStepTypeId), processStepTypeId, null) + }; +} diff --git a/src/database/Dim.Migrations/Migrations/20240801133205_56-AddRetriggerSteps.Designer.cs b/src/database/Dim.Migrations/Migrations/20240801133205_56-AddRetriggerSteps.Designer.cs new file mode 100644 index 0000000..5f9109c --- /dev/null +++ b/src/database/Dim.Migrations/Migrations/20240801133205_56-AddRetriggerSteps.Designer.cs @@ -0,0 +1,667 @@ +/******************************************************************************** + * Copyright (c) 2024 BMW Group AG + * Copyright 2024 SAP SE or an SAP affiliate company and ssi-dim-middle-layer contributors. + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0. + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + * SPDX-License-Identifier: Apache-2.0 + ********************************************************************************/ + +// +using System; +using Dim.Entities; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace Dim.Migrations.Migrations +{ + [DbContext(typeof(DimDbContext))] + [Migration("20240801133205_56-AddRetriggerSteps")] + partial class _56AddRetriggerSteps + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasDefaultSchema("dim") + .UseCollation("en_US.utf8") + .HasAnnotation("ProductVersion", "8.0.7") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("Dim.Entities.Entities.Process", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid") + .HasColumnName("id"); + + b.Property("LockExpiryDate") + .HasColumnType("timestamp with time zone") + .HasColumnName("lock_expiry_date"); + + b.Property("ProcessTypeId") + .HasColumnType("integer") + .HasColumnName("process_type_id"); + + b.Property("Version") + .IsConcurrencyToken() + .HasColumnType("uuid") + .HasColumnName("version"); + + b.HasKey("Id") + .HasName("pk_processes"); + + b.HasIndex("ProcessTypeId") + .HasDatabaseName("ix_processes_process_type_id"); + + b.ToTable("processes", "dim"); + }); + + modelBuilder.Entity("Dim.Entities.Entities.ProcessStep", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid") + .HasColumnName("id"); + + b.Property("DateCreated") + .HasColumnType("timestamp with time zone") + .HasColumnName("date_created"); + + b.Property("DateLastChanged") + .HasColumnType("timestamp with time zone") + .HasColumnName("date_last_changed"); + + b.Property("Message") + .HasColumnType("text") + .HasColumnName("message"); + + b.Property("ProcessId") + .HasColumnType("uuid") + .HasColumnName("process_id"); + + b.Property("ProcessStepStatusId") + .HasColumnType("integer") + .HasColumnName("process_step_status_id"); + + b.Property("ProcessStepTypeId") + .HasColumnType("integer") + .HasColumnName("process_step_type_id"); + + b.HasKey("Id") + .HasName("pk_process_steps"); + + b.HasIndex("ProcessId") + .HasDatabaseName("ix_process_steps_process_id"); + + b.HasIndex("ProcessStepStatusId") + .HasDatabaseName("ix_process_steps_process_step_status_id"); + + b.HasIndex("ProcessStepTypeId") + .HasDatabaseName("ix_process_steps_process_step_type_id"); + + b.ToTable("process_steps", "dim"); + }); + + modelBuilder.Entity("Dim.Entities.Entities.ProcessStepStatus", b => + { + b.Property("Id") + .HasColumnType("integer") + .HasColumnName("id"); + + b.Property("Label") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("character varying(255)") + .HasColumnName("label"); + + b.HasKey("Id") + .HasName("pk_process_step_statuses"); + + b.ToTable("process_step_statuses", "dim"); + + b.HasData( + new + { + Id = 1, + Label = "TODO" + }, + new + { + Id = 2, + Label = "DONE" + }, + new + { + Id = 3, + Label = "SKIPPED" + }, + new + { + Id = 4, + Label = "FAILED" + }, + new + { + Id = 5, + Label = "DUPLICATE" + }); + }); + + modelBuilder.Entity("Dim.Entities.Entities.ProcessStepType", b => + { + b.Property("Id") + .HasColumnType("integer") + .HasColumnName("id"); + + b.Property("Label") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("character varying(255)") + .HasColumnName("label"); + + b.HasKey("Id") + .HasName("pk_process_step_types"); + + b.ToTable("process_step_types", "dim"); + + b.HasData( + new + { + Id = 1, + Label = "CREATE_SUBACCOUNT" + }, + new + { + Id = 2, + Label = "CREATE_SERVICEMANAGER_BINDINGS" + }, + new + { + Id = 3, + Label = "ASSIGN_ENTITLEMENTS" + }, + new + { + Id = 4, + Label = "CREATE_SERVICE_INSTANCE" + }, + new + { + Id = 5, + Label = "CREATE_SERVICE_BINDING" + }, + new + { + Id = 6, + Label = "SUBSCRIBE_APPLICATION" + }, + new + { + Id = 7, + Label = "CREATE_CLOUD_FOUNDRY_ENVIRONMENT" + }, + new + { + Id = 8, + Label = "CREATE_CLOUD_FOUNDRY_SPACE" + }, + new + { + Id = 9, + Label = "ADD_SPACE_MANAGER_ROLE" + }, + new + { + Id = 10, + Label = "ADD_SPACE_DEVELOPER_ROLE" + }, + new + { + Id = 11, + Label = "CREATE_DIM_SERVICE_INSTANCE" + }, + new + { + Id = 12, + Label = "CREATE_SERVICE_INSTANCE_BINDING" + }, + new + { + Id = 13, + Label = "GET_DIM_DETAILS" + }, + new + { + Id = 14, + Label = "CREATE_APPLICATION" + }, + new + { + Id = 15, + Label = "CREATE_COMPANY_IDENTITY" + }, + new + { + Id = 16, + Label = "ASSIGN_COMPANY_APPLICATION" + }, + new + { + Id = 17, + Label = "CREATE_STATUS_LIST" + }, + new + { + Id = 18, + Label = "SEND_CALLBACK" + }, + new + { + Id = 19, + Label = "RETRIGGER_CREATE_SUBACCOUNT" + }, + new + { + Id = 20, + Label = "RETRIGGER_CREATE_SERVICEMANAGER_BINDINGS" + }, + new + { + Id = 21, + Label = "RETRIGGER_ASSIGN_ENTITLEMENTS" + }, + new + { + Id = 22, + Label = "RETRIGGER_CREATE_SERVICE_INSTANCE" + }, + new + { + Id = 23, + Label = "RETRIGGER_CREATE_SERVICE_BINDING" + }, + new + { + Id = 24, + Label = "RETRIGGER_SUBSCRIBE_APPLICATION" + }, + new + { + Id = 25, + Label = "RETRIGGER_CREATE_CLOUD_FOUNDRY_ENVIRONMENT" + }, + new + { + Id = 26, + Label = "RETRIGGER_CREATE_CLOUD_FOUNDRY_SPACE" + }, + new + { + Id = 27, + Label = "RETRIGGER_ADD_SPACE_MANAGER_ROLE" + }, + new + { + Id = 28, + Label = "RETRIGGER_ADD_SPACE_DEVELOPER_ROLE" + }, + new + { + Id = 29, + Label = "RETRIGGER_CREATE_DIM_SERVICE_INSTANCE" + }, + new + { + Id = 30, + Label = "RETRIGGER_CREATE_SERVICE_INSTANCE_BINDING" + }, + new + { + Id = 31, + Label = "RETRIGGER_GET_DIM_DETAILS" + }, + new + { + Id = 32, + Label = "RETRIGGER_CREATE_APPLICATION" + }, + new + { + Id = 33, + Label = "RETRIGGER_CREATE_COMPANY_IDENTITY" + }, + new + { + Id = 34, + Label = "RETRIGGER_ASSIGN_COMPANY_APPLICATION" + }, + new + { + Id = 35, + Label = "RETRIGGER_CREATE_STATUS_LIST" + }, + new + { + Id = 36, + Label = "RETRIGGER_SEND_CALLBACK" + }, + new + { + Id = 100, + Label = "CREATE_TECHNICAL_USER" + }, + new + { + Id = 101, + Label = "GET_TECHNICAL_USER_DATA" + }, + new + { + Id = 102, + Label = "SEND_TECHNICAL_USER_CREATION_CALLBACK" + }, + new + { + Id = 200, + Label = "DELETE_TECHNICAL_USER" + }, + new + { + Id = 201, + Label = "SEND_TECHNICAL_USER_DELETION_CALLBACK" + }); + }); + + modelBuilder.Entity("Dim.Entities.Entities.ProcessType", b => + { + b.Property("Id") + .HasColumnType("integer") + .HasColumnName("id"); + + b.Property("Label") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("character varying(255)") + .HasColumnName("label"); + + b.HasKey("Id") + .HasName("pk_process_types"); + + b.ToTable("process_types", "dim"); + + b.HasData( + new + { + Id = 1, + Label = "SETUP_DIM" + }, + new + { + Id = 2, + Label = "TECHNICAL_USER" + }); + }); + + modelBuilder.Entity("Dim.Entities.Entities.TechnicalUser", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid") + .HasColumnName("id"); + + b.Property("ClientId") + .HasColumnType("text") + .HasColumnName("client_id"); + + b.Property("ClientSecret") + .HasColumnType("bytea") + .HasColumnName("client_secret"); + + b.Property("EncryptionMode") + .HasColumnType("integer") + .HasColumnName("encryption_mode"); + + b.Property("ExternalId") + .HasColumnType("uuid") + .HasColumnName("external_id"); + + b.Property("InitializationVector") + .HasColumnType("bytea") + .HasColumnName("initialization_vector"); + + b.Property("ProcessId") + .HasColumnType("uuid") + .HasColumnName("process_id"); + + b.Property("TechnicalUserName") + .IsRequired() + .HasColumnType("text") + .HasColumnName("technical_user_name"); + + b.Property("TenantId") + .HasColumnType("uuid") + .HasColumnName("tenant_id"); + + b.Property("TokenAddress") + .HasColumnType("text") + .HasColumnName("token_address"); + + b.HasKey("Id") + .HasName("pk_technical_users"); + + b.HasIndex("ProcessId") + .IsUnique() + .HasDatabaseName("ix_technical_users_process_id"); + + b.HasIndex("TenantId") + .HasDatabaseName("ix_technical_users_tenant_id"); + + b.ToTable("technical_users", "dim"); + }); + + modelBuilder.Entity("Dim.Entities.Entities.Tenant", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid") + .HasColumnName("id"); + + b.Property("ApplicationId") + .HasColumnType("text") + .HasColumnName("application_id"); + + b.Property("ApplicationKey") + .HasColumnType("text") + .HasColumnName("application_key"); + + b.Property("Bpn") + .IsRequired() + .HasColumnType("text") + .HasColumnName("bpn"); + + b.Property("CompanyId") + .HasColumnType("uuid") + .HasColumnName("company_id"); + + b.Property("CompanyName") + .IsRequired() + .HasColumnType("text") + .HasColumnName("company_name"); + + b.Property("Did") + .HasColumnType("text") + .HasColumnName("did"); + + b.Property("DidDocumentLocation") + .IsRequired() + .HasColumnType("text") + .HasColumnName("did_document_location"); + + b.Property("DidDownloadUrl") + .HasColumnType("text") + .HasColumnName("did_download_url"); + + b.Property("DimInstanceId") + .HasColumnType("uuid") + .HasColumnName("dim_instance_id"); + + b.Property("IsIssuer") + .HasColumnType("boolean") + .HasColumnName("is_issuer"); + + b.Property("OperatorId") + .HasColumnType("uuid") + .HasColumnName("operator_id"); + + b.Property("ProcessId") + .HasColumnType("uuid") + .HasColumnName("process_id"); + + b.Property("ServiceBindingName") + .HasColumnType("text") + .HasColumnName("service_binding_name"); + + b.Property("ServiceInstanceId") + .HasColumnType("text") + .HasColumnName("service_instance_id"); + + b.Property("SpaceId") + .HasColumnType("uuid") + .HasColumnName("space_id"); + + b.Property("SubAccountId") + .HasColumnType("uuid") + .HasColumnName("sub_account_id"); + + b.HasKey("Id") + .HasName("pk_tenants"); + + b.HasIndex("ProcessId") + .IsUnique() + .HasDatabaseName("ix_tenants_process_id"); + + b.ToTable("tenants", "dim"); + }); + + modelBuilder.Entity("Dim.Entities.Entities.Process", b => + { + b.HasOne("Dim.Entities.Entities.ProcessType", "ProcessType") + .WithMany("Processes") + .HasForeignKey("ProcessTypeId") + .IsRequired() + .HasConstraintName("fk_processes_process_types_process_type_id"); + + b.Navigation("ProcessType"); + }); + + modelBuilder.Entity("Dim.Entities.Entities.ProcessStep", b => + { + b.HasOne("Dim.Entities.Entities.Process", "Process") + .WithMany("ProcessSteps") + .HasForeignKey("ProcessId") + .IsRequired() + .HasConstraintName("fk_process_steps_processes_process_id"); + + b.HasOne("Dim.Entities.Entities.ProcessStepStatus", "ProcessStepStatus") + .WithMany("ProcessSteps") + .HasForeignKey("ProcessStepStatusId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired() + .HasConstraintName("fk_process_steps_process_step_statuses_process_step_status_id"); + + b.HasOne("Dim.Entities.Entities.ProcessStepType", "ProcessStepType") + .WithMany("ProcessSteps") + .HasForeignKey("ProcessStepTypeId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired() + .HasConstraintName("fk_process_steps_process_step_types_process_step_type_id"); + + b.Navigation("Process"); + + b.Navigation("ProcessStepStatus"); + + b.Navigation("ProcessStepType"); + }); + + modelBuilder.Entity("Dim.Entities.Entities.TechnicalUser", b => + { + b.HasOne("Dim.Entities.Entities.Process", "Process") + .WithOne("TechnicalUser") + .HasForeignKey("Dim.Entities.Entities.TechnicalUser", "ProcessId") + .IsRequired() + .HasConstraintName("fk_technical_users_processes_process_id"); + + b.HasOne("Dim.Entities.Entities.Tenant", "Tenant") + .WithMany("TechnicalUsers") + .HasForeignKey("TenantId") + .IsRequired() + .HasConstraintName("fk_technical_users_tenants_tenant_id"); + + b.Navigation("Process"); + + b.Navigation("Tenant"); + }); + + modelBuilder.Entity("Dim.Entities.Entities.Tenant", b => + { + b.HasOne("Dim.Entities.Entities.Process", "Process") + .WithOne("Tenant") + .HasForeignKey("Dim.Entities.Entities.Tenant", "ProcessId") + .IsRequired() + .HasConstraintName("fk_tenants_processes_process_id"); + + b.Navigation("Process"); + }); + + modelBuilder.Entity("Dim.Entities.Entities.Process", b => + { + b.Navigation("ProcessSteps"); + + b.Navigation("TechnicalUser"); + + b.Navigation("Tenant"); + }); + + modelBuilder.Entity("Dim.Entities.Entities.ProcessStepStatus", b => + { + b.Navigation("ProcessSteps"); + }); + + modelBuilder.Entity("Dim.Entities.Entities.ProcessStepType", b => + { + b.Navigation("ProcessSteps"); + }); + + modelBuilder.Entity("Dim.Entities.Entities.ProcessType", b => + { + b.Navigation("Processes"); + }); + + modelBuilder.Entity("Dim.Entities.Entities.Tenant", b => + { + b.Navigation("TechnicalUsers"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/database/Dim.Migrations/Migrations/20240801133205_56-AddRetriggerSteps.cs b/src/database/Dim.Migrations/Migrations/20240801133205_56-AddRetriggerSteps.cs new file mode 100644 index 0000000..9b5e3dc --- /dev/null +++ b/src/database/Dim.Migrations/Migrations/20240801133205_56-AddRetriggerSteps.cs @@ -0,0 +1,220 @@ +/******************************************************************************** + * Copyright (c) 2024 BMW Group AG + * Copyright 2024 SAP SE or an SAP affiliate company and ssi-dim-middle-layer contributors. + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0. + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + * SPDX-License-Identifier: Apache-2.0 + ********************************************************************************/ + +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +#pragma warning disable CA1814 // Prefer jagged arrays over multidimensional + +namespace Dim.Migrations.Migrations +{ + /// + public partial class _56AddRetriggerSteps : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropIndex( + name: "ix_tenants_process_id", + schema: "dim", + table: "tenants"); + + migrationBuilder.DropIndex( + name: "ix_technical_users_process_id", + schema: "dim", + table: "technical_users"); + + migrationBuilder.InsertData( + schema: "dim", + table: "process_step_types", + columns: new[] { "id", "label" }, + values: new object[,] + { + { 19, "RETRIGGER_CREATE_SUBACCOUNT" }, + { 20, "RETRIGGER_CREATE_SERVICEMANAGER_BINDINGS" }, + { 21, "RETRIGGER_ASSIGN_ENTITLEMENTS" }, + { 22, "RETRIGGER_CREATE_SERVICE_INSTANCE" }, + { 23, "RETRIGGER_CREATE_SERVICE_BINDING" }, + { 24, "RETRIGGER_SUBSCRIBE_APPLICATION" }, + { 25, "RETRIGGER_CREATE_CLOUD_FOUNDRY_ENVIRONMENT" }, + { 26, "RETRIGGER_CREATE_CLOUD_FOUNDRY_SPACE" }, + { 27, "RETRIGGER_ADD_SPACE_MANAGER_ROLE" }, + { 28, "RETRIGGER_ADD_SPACE_DEVELOPER_ROLE" }, + { 29, "RETRIGGER_CREATE_DIM_SERVICE_INSTANCE" }, + { 30, "RETRIGGER_CREATE_SERVICE_INSTANCE_BINDING" }, + { 31, "RETRIGGER_GET_DIM_DETAILS" }, + { 32, "RETRIGGER_CREATE_APPLICATION" }, + { 33, "RETRIGGER_CREATE_COMPANY_IDENTITY" }, + { 34, "RETRIGGER_ASSIGN_COMPANY_APPLICATION" }, + { 35, "RETRIGGER_CREATE_STATUS_LIST" }, + { 36, "RETRIGGER_SEND_CALLBACK" } + }); + + migrationBuilder.CreateIndex( + name: "ix_tenants_process_id", + schema: "dim", + table: "tenants", + column: "process_id", + unique: true); + + migrationBuilder.CreateIndex( + name: "ix_technical_users_process_id", + schema: "dim", + table: "technical_users", + column: "process_id", + unique: true); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropIndex( + name: "ix_tenants_process_id", + schema: "dim", + table: "tenants"); + + migrationBuilder.DropIndex( + name: "ix_technical_users_process_id", + schema: "dim", + table: "technical_users"); + + migrationBuilder.DeleteData( + schema: "dim", + table: "process_step_types", + keyColumn: "id", + keyValue: 19); + + migrationBuilder.DeleteData( + schema: "dim", + table: "process_step_types", + keyColumn: "id", + keyValue: 20); + + migrationBuilder.DeleteData( + schema: "dim", + table: "process_step_types", + keyColumn: "id", + keyValue: 21); + + migrationBuilder.DeleteData( + schema: "dim", + table: "process_step_types", + keyColumn: "id", + keyValue: 22); + + migrationBuilder.DeleteData( + schema: "dim", + table: "process_step_types", + keyColumn: "id", + keyValue: 23); + + migrationBuilder.DeleteData( + schema: "dim", + table: "process_step_types", + keyColumn: "id", + keyValue: 24); + + migrationBuilder.DeleteData( + schema: "dim", + table: "process_step_types", + keyColumn: "id", + keyValue: 25); + + migrationBuilder.DeleteData( + schema: "dim", + table: "process_step_types", + keyColumn: "id", + keyValue: 26); + + migrationBuilder.DeleteData( + schema: "dim", + table: "process_step_types", + keyColumn: "id", + keyValue: 27); + + migrationBuilder.DeleteData( + schema: "dim", + table: "process_step_types", + keyColumn: "id", + keyValue: 28); + + migrationBuilder.DeleteData( + schema: "dim", + table: "process_step_types", + keyColumn: "id", + keyValue: 29); + + migrationBuilder.DeleteData( + schema: "dim", + table: "process_step_types", + keyColumn: "id", + keyValue: 30); + + migrationBuilder.DeleteData( + schema: "dim", + table: "process_step_types", + keyColumn: "id", + keyValue: 31); + + migrationBuilder.DeleteData( + schema: "dim", + table: "process_step_types", + keyColumn: "id", + keyValue: 32); + + migrationBuilder.DeleteData( + schema: "dim", + table: "process_step_types", + keyColumn: "id", + keyValue: 33); + + migrationBuilder.DeleteData( + schema: "dim", + table: "process_step_types", + keyColumn: "id", + keyValue: 34); + + migrationBuilder.DeleteData( + schema: "dim", + table: "process_step_types", + keyColumn: "id", + keyValue: 35); + + migrationBuilder.DeleteData( + schema: "dim", + table: "process_step_types", + keyColumn: "id", + keyValue: 36); + + migrationBuilder.CreateIndex( + name: "ix_tenants_process_id", + schema: "dim", + table: "tenants", + column: "process_id"); + + migrationBuilder.CreateIndex( + name: "ix_technical_users_process_id", + schema: "dim", + table: "technical_users", + column: "process_id"); + } + } +} diff --git a/src/database/Dim.Migrations/Migrations/DimDbContextModelSnapshot.cs b/src/database/Dim.Migrations/Migrations/DimDbContextModelSnapshot.cs index e3b42c2..9fc74a3 100644 --- a/src/database/Dim.Migrations/Migrations/DimDbContextModelSnapshot.cs +++ b/src/database/Dim.Migrations/Migrations/DimDbContextModelSnapshot.cs @@ -35,7 +35,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) modelBuilder .HasDefaultSchema("dim") .UseCollation("en_US.utf8") - .HasAnnotation("ProductVersion", "8.0.5") + .HasAnnotation("ProductVersion", "8.0.7") .HasAnnotation("Relational:MaxIdentifierLength", 63); NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); @@ -269,6 +269,96 @@ protected override void BuildModel(ModelBuilder modelBuilder) Label = "SEND_CALLBACK" }, new + { + Id = 19, + Label = "RETRIGGER_CREATE_SUBACCOUNT" + }, + new + { + Id = 20, + Label = "RETRIGGER_CREATE_SERVICEMANAGER_BINDINGS" + }, + new + { + Id = 21, + Label = "RETRIGGER_ASSIGN_ENTITLEMENTS" + }, + new + { + Id = 22, + Label = "RETRIGGER_CREATE_SERVICE_INSTANCE" + }, + new + { + Id = 23, + Label = "RETRIGGER_CREATE_SERVICE_BINDING" + }, + new + { + Id = 24, + Label = "RETRIGGER_SUBSCRIBE_APPLICATION" + }, + new + { + Id = 25, + Label = "RETRIGGER_CREATE_CLOUD_FOUNDRY_ENVIRONMENT" + }, + new + { + Id = 26, + Label = "RETRIGGER_CREATE_CLOUD_FOUNDRY_SPACE" + }, + new + { + Id = 27, + Label = "RETRIGGER_ADD_SPACE_MANAGER_ROLE" + }, + new + { + Id = 28, + Label = "RETRIGGER_ADD_SPACE_DEVELOPER_ROLE" + }, + new + { + Id = 29, + Label = "RETRIGGER_CREATE_DIM_SERVICE_INSTANCE" + }, + new + { + Id = 30, + Label = "RETRIGGER_CREATE_SERVICE_INSTANCE_BINDING" + }, + new + { + Id = 31, + Label = "RETRIGGER_GET_DIM_DETAILS" + }, + new + { + Id = 32, + Label = "RETRIGGER_CREATE_APPLICATION" + }, + new + { + Id = 33, + Label = "RETRIGGER_CREATE_COMPANY_IDENTITY" + }, + new + { + Id = 34, + Label = "RETRIGGER_ASSIGN_COMPANY_APPLICATION" + }, + new + { + Id = 35, + Label = "RETRIGGER_CREATE_STATUS_LIST" + }, + new + { + Id = 36, + Label = "RETRIGGER_SEND_CALLBACK" + }, + new { Id = 100, Label = "CREATE_TECHNICAL_USER" @@ -373,6 +463,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) .HasName("pk_technical_users"); b.HasIndex("ProcessId") + .IsUnique() .HasDatabaseName("ix_technical_users_process_id"); b.HasIndex("TenantId") @@ -459,6 +550,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) .HasName("pk_tenants"); b.HasIndex("ProcessId") + .IsUnique() .HasDatabaseName("ix_tenants_process_id"); b.ToTable("tenants", "dim"); @@ -507,8 +599,8 @@ protected override void BuildModel(ModelBuilder modelBuilder) modelBuilder.Entity("Dim.Entities.Entities.TechnicalUser", b => { b.HasOne("Dim.Entities.Entities.Process", "Process") - .WithMany("TechnicalUsers") - .HasForeignKey("ProcessId") + .WithOne("TechnicalUser") + .HasForeignKey("Dim.Entities.Entities.TechnicalUser", "ProcessId") .IsRequired() .HasConstraintName("fk_technical_users_processes_process_id"); @@ -526,8 +618,8 @@ protected override void BuildModel(ModelBuilder modelBuilder) modelBuilder.Entity("Dim.Entities.Entities.Tenant", b => { b.HasOne("Dim.Entities.Entities.Process", "Process") - .WithMany("Tenants") - .HasForeignKey("ProcessId") + .WithOne("Tenant") + .HasForeignKey("Dim.Entities.Entities.Tenant", "ProcessId") .IsRequired() .HasConstraintName("fk_tenants_processes_process_id"); @@ -538,9 +630,9 @@ protected override void BuildModel(ModelBuilder modelBuilder) { b.Navigation("ProcessSteps"); - b.Navigation("TechnicalUsers"); + b.Navigation("TechnicalUser"); - b.Navigation("Tenants"); + b.Navigation("Tenant"); }); modelBuilder.Entity("Dim.Entities.Entities.ProcessStepStatus", b => diff --git a/src/database/Dim.Migrations/Program.cs b/src/database/Dim.Migrations/Program.cs index 8b257e6..ad63b90 100644 --- a/src/database/Dim.Migrations/Program.cs +++ b/src/database/Dim.Migrations/Program.cs @@ -49,7 +49,7 @@ } catch (Exception ex) when (!ex.GetType().Name.Equals("StopTheHostException", StringComparison.Ordinal)) { - Log.Fatal("Unhandled exception {Exception}", ex); + Log.Fatal(ex, "Unhandled exception"); throw; } finally diff --git a/src/processes/DimProcess.Executor/DependencyInjection/DimProcessCollectionExtensions.cs b/src/processes/DimProcess.Executor/DependencyInjection/DimProcessCollectionExtensions.cs index 78be5c0..741d88c 100644 --- a/src/processes/DimProcess.Executor/DependencyInjection/DimProcessCollectionExtensions.cs +++ b/src/processes/DimProcess.Executor/DependencyInjection/DimProcessCollectionExtensions.cs @@ -21,7 +21,7 @@ using DimProcess.Library.DependencyInjection; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; -using Org.Eclipse.TractusX.Portal.Backend.Processes.Worker.Library; +using Processes.Worker.Library; namespace DimProcess.Executor.DependencyInjection; diff --git a/src/processes/DimProcess.Executor/DimProcessTypeExecutor.cs b/src/processes/DimProcess.Executor/DimProcessTypeExecutor.cs index db9c5fd..eb4f595 100644 --- a/src/processes/DimProcess.Executor/DimProcessTypeExecutor.cs +++ b/src/processes/DimProcess.Executor/DimProcessTypeExecutor.cs @@ -21,9 +21,10 @@ 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 Org.Eclipse.TractusX.Portal.Backend.Processes.Worker.Library; +using Processes.Worker.Library; using System.Collections.Immutable; namespace DimProcess.Executor; @@ -63,7 +64,7 @@ public class DimProcessTypeExecutor( public async ValueTask InitializeProcess(Guid processId, IEnumerable processStepTypeIds) { - var (exists, tenantId, companyName, bpn) = await dimRepositories.GetInstance().GetTenantDataForProcessId(processId).ConfigureAwait(false); + var (exists, tenantId, companyName, bpn) = await dimRepositories.GetInstance().GetTenantDataForProcessId(processId).ConfigureAwait(ConfigureAwaitOptions.None); if (!exists) { throw new NotFoundException($"process {processId} does not exist or is not associated with an tenant"); @@ -91,59 +92,59 @@ public class DimProcessTypeExecutor( (nextStepTypeIds, stepStatusId, modified, processMessage) = processStepTypeId switch { ProcessStepTypeId.CREATE_SUBACCOUNT => await dimProcessHandler.CreateSubaccount(_tenantId, _tenantName, cancellationToken) - .ConfigureAwait(false), + .ConfigureAwait(ConfigureAwaitOptions.None), ProcessStepTypeId.CREATE_SERVICEMANAGER_BINDINGS => await dimProcessHandler.CreateServiceManagerBindings(_tenantId, cancellationToken) - .ConfigureAwait(false), + .ConfigureAwait(ConfigureAwaitOptions.None), ProcessStepTypeId.ASSIGN_ENTITLEMENTS => await dimProcessHandler.AssignEntitlements(_tenantId, cancellationToken) - .ConfigureAwait(false), + .ConfigureAwait(ConfigureAwaitOptions.None), ProcessStepTypeId.CREATE_SERVICE_INSTANCE => await dimProcessHandler.CreateServiceInstance(_tenantId, cancellationToken) - .ConfigureAwait(false), + .ConfigureAwait(ConfigureAwaitOptions.None), ProcessStepTypeId.CREATE_SERVICE_BINDING => await dimProcessHandler.CreateServiceBindings(_tenantId, cancellationToken) - .ConfigureAwait(false), + .ConfigureAwait(ConfigureAwaitOptions.None), ProcessStepTypeId.SUBSCRIBE_APPLICATION => await dimProcessHandler.SubscribeApplication(_tenantId, cancellationToken) - .ConfigureAwait(false), + .ConfigureAwait(ConfigureAwaitOptions.None), ProcessStepTypeId.CREATE_CLOUD_FOUNDRY_ENVIRONMENT => await dimProcessHandler.CreateCloudFoundryEnvironment(_tenantId, _tenantName, cancellationToken) - .ConfigureAwait(false), + .ConfigureAwait(ConfigureAwaitOptions.None), ProcessStepTypeId.CREATE_CLOUD_FOUNDRY_SPACE => await dimProcessHandler.CreateCloudFoundrySpace(_tenantId, _tenantName, cancellationToken) - .ConfigureAwait(false), + .ConfigureAwait(ConfigureAwaitOptions.None), ProcessStepTypeId.ADD_SPACE_MANAGER_ROLE => await dimProcessHandler.AddSpaceManagerRole(_tenantId, cancellationToken) - .ConfigureAwait(false), + .ConfigureAwait(ConfigureAwaitOptions.None), ProcessStepTypeId.ADD_SPACE_DEVELOPER_ROLE => await dimProcessHandler.AddSpaceDeveloperRole(_tenantId, cancellationToken) - .ConfigureAwait(false), + .ConfigureAwait(ConfigureAwaitOptions.None), ProcessStepTypeId.CREATE_DIM_SERVICE_INSTANCE => await dimProcessHandler.CreateDimServiceInstance(_tenantName, _tenantId, cancellationToken) - .ConfigureAwait(false), + .ConfigureAwait(ConfigureAwaitOptions.None), ProcessStepTypeId.CREATE_SERVICE_INSTANCE_BINDING => await dimProcessHandler.CreateServiceInstanceBindings(_tenantName, _tenantId, cancellationToken) - .ConfigureAwait(false), + .ConfigureAwait(ConfigureAwaitOptions.None), ProcessStepTypeId.GET_DIM_DETAILS => await dimProcessHandler.GetDimDetails(_tenantName, _tenantId, cancellationToken) - .ConfigureAwait(false), + .ConfigureAwait(ConfigureAwaitOptions.None), ProcessStepTypeId.CREATE_APPLICATION => await dimProcessHandler.CreateApplication(_tenantName, _tenantId, cancellationToken) - .ConfigureAwait(false), + .ConfigureAwait(ConfigureAwaitOptions.None), ProcessStepTypeId.CREATE_COMPANY_IDENTITY => await dimProcessHandler.CreateCompanyIdentity(_tenantId, cancellationToken) - .ConfigureAwait(false), + .ConfigureAwait(ConfigureAwaitOptions.None), ProcessStepTypeId.ASSIGN_COMPANY_APPLICATION => await dimProcessHandler.AssignCompanyApplication(_tenantId, cancellationToken) - .ConfigureAwait(false), + .ConfigureAwait(ConfigureAwaitOptions.None), ProcessStepTypeId.CREATE_STATUS_LIST => await dimProcessHandler.CreateStatusList(_tenantId, cancellationToken) - .ConfigureAwait(false), + .ConfigureAwait(ConfigureAwaitOptions.None), ProcessStepTypeId.SEND_CALLBACK => await dimProcessHandler.SendCallback(_tenantId, cancellationToken) - .ConfigureAwait(false), + .ConfigureAwait(ConfigureAwaitOptions.None), _ => (null, ProcessStepStatusId.TODO, false, null) }; } catch (Exception ex) when (ex is not SystemException) { - (stepStatusId, processMessage, nextStepTypeIds) = ProcessError(ex); + (stepStatusId, processMessage, nextStepTypeIds) = ProcessError(processStepTypeId, ex); modified = true; } return new IProcessTypeExecutor.StepExecutionResult(modified, stepStatusId, nextStepTypeIds, null, processMessage); } - private static (ProcessStepStatusId StatusId, string? ProcessMessage, IEnumerable? nextSteps) ProcessError(Exception ex) + private static (ProcessStepStatusId StatusId, string? ProcessMessage, IEnumerable? nextSteps) ProcessError(ProcessStepTypeId processStepTypeId, Exception ex) { return ex switch { ServiceException { IsRecoverable: true } => (ProcessStepStatusId.TODO, ex.Message, null), - _ => (ProcessStepStatusId.FAILED, ex.Message, null) + _ => (ProcessStepStatusId.FAILED, ex.Message, Enumerable.Repeat(processStepTypeId.GetWalletRetriggerStep(), 1)) }; } } diff --git a/src/processes/DimProcess.Executor/TechnicalUserProcessTypeExecutor.cs b/src/processes/DimProcess.Executor/TechnicalUserProcessTypeExecutor.cs index 0919575..c6df4b2 100644 --- a/src/processes/DimProcess.Executor/TechnicalUserProcessTypeExecutor.cs +++ b/src/processes/DimProcess.Executor/TechnicalUserProcessTypeExecutor.cs @@ -23,7 +23,7 @@ using Dim.Entities.Enums; using DimProcess.Library; using Org.Eclipse.TractusX.Portal.Backend.Framework.ErrorHandling; -using Org.Eclipse.TractusX.Portal.Backend.Processes.Worker.Library; +using Processes.Worker.Library; using System.Collections.Immutable; namespace DimProcess.Executor; @@ -50,7 +50,7 @@ public class TechnicalUserProcessTypeExecutor( public async ValueTask InitializeProcess(Guid processId, IEnumerable processStepTypeIds) { - var (exists, technicalUserId, companyName, bpn) = await dimRepositories.GetInstance().GetTenantDataForTechnicalUserProcessId(processId).ConfigureAwait(false); + var (exists, technicalUserId, companyName, bpn) = await dimRepositories.GetInstance().GetTenantDataForTechnicalUserProcessId(processId).ConfigureAwait(ConfigureAwaitOptions.None); if (!exists) { throw new NotFoundException($"process {processId} does not exist or is not associated with an technical user"); @@ -78,15 +78,15 @@ public class TechnicalUserProcessTypeExecutor( (nextStepTypeIds, stepStatusId, modified, processMessage) = processStepTypeId switch { ProcessStepTypeId.CREATE_TECHNICAL_USER => await technicalUserProcessHandler.CreateServiceInstanceBindings(_tenantName, _technicalUserId, cancellationToken) - .ConfigureAwait(false), + .ConfigureAwait(ConfigureAwaitOptions.None), ProcessStepTypeId.GET_TECHNICAL_USER_DATA => await technicalUserProcessHandler.GetTechnicalUserData(_tenantName, _technicalUserId, cancellationToken) - .ConfigureAwait(false), + .ConfigureAwait(ConfigureAwaitOptions.None), ProcessStepTypeId.SEND_TECHNICAL_USER_CREATION_CALLBACK => await technicalUserProcessHandler.SendCreateCallback(_technicalUserId, cancellationToken) - .ConfigureAwait(false), + .ConfigureAwait(ConfigureAwaitOptions.None), ProcessStepTypeId.DELETE_TECHNICAL_USER => await technicalUserProcessHandler.DeleteServiceInstanceBindings(_tenantName, _technicalUserId, cancellationToken) - .ConfigureAwait(false), + .ConfigureAwait(ConfigureAwaitOptions.None), ProcessStepTypeId.SEND_TECHNICAL_USER_DELETION_CALLBACK => await technicalUserProcessHandler.SendDeleteCallback(_technicalUserId, cancellationToken) - .ConfigureAwait(false), + .ConfigureAwait(ConfigureAwaitOptions.None), _ => (null, ProcessStepStatusId.TODO, false, null) }; } diff --git a/src/processes/DimProcess.Library/Callback/CallbackService.cs b/src/processes/DimProcess.Library/Callback/CallbackService.cs index 5fc8565..0f3fdb0 100644 --- a/src/processes/DimProcess.Library/Callback/CallbackService.cs +++ b/src/processes/DimProcess.Library/Callback/CallbackService.cs @@ -36,7 +36,7 @@ public class CallbackService(ITokenService tokenService, IOptions(_settings, cancellationToken) - .ConfigureAwait(false); + .ConfigureAwait(ConfigureAwaitOptions.None); var data = new CallbackDataModel( did, didDocument, @@ -45,24 +45,24 @@ public async Task SendCallback(string bpn, ServiceCredentialBindingDetailRespons dimDetails.Credentials.Uaa.ClientId, dimDetails.Credentials.Uaa.ClientSecret) ); - await httpClient.PostAsJsonAsync($"/api/administration/registration/dim/{bpn}", data, JsonSerializerExtensions.Options, cancellationToken).ConfigureAwait(false); + await httpClient.PostAsJsonAsync($"/api/administration/registration/dim/{bpn}", data, JsonSerializerExtensions.Options, cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None); } public async Task SendTechnicalUserCallback(Guid externalId, string tokenAddress, string clientId, string clientSecret, CancellationToken cancellationToken) { var httpClient = await tokenService.GetAuthorizedClient(_settings, cancellationToken) - .ConfigureAwait(false); + .ConfigureAwait(ConfigureAwaitOptions.None); var data = new AuthenticationDetail( tokenAddress, clientId, clientSecret); - await httpClient.PostAsJsonAsync($"/api/administration/serviceAccount/callback/{externalId}", data, JsonSerializerExtensions.Options, cancellationToken).ConfigureAwait(false); + await httpClient.PostAsJsonAsync($"/api/administration/serviceAccount/callback/{externalId}", data, JsonSerializerExtensions.Options, cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None); } public async Task SendTechnicalUserDeletionCallback(Guid externalId, CancellationToken cancellationToken) { var httpClient = await tokenService.GetAuthorizedClient(_settings, cancellationToken) - .ConfigureAwait(false); - await httpClient.PostAsync($"/api/administration/serviceAccount/callback/{externalId}/delete", null, cancellationToken).ConfigureAwait(false); + .ConfigureAwait(ConfigureAwaitOptions.None); + await httpClient.PostAsync($"/api/administration/serviceAccount/callback/{externalId}/delete", null, cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None); } } diff --git a/src/processes/DimProcess.Library/DimProcessHandler.cs b/src/processes/DimProcess.Library/DimProcessHandler.cs index 22aeb68..fd9db03 100644 --- a/src/processes/DimProcess.Library/DimProcessHandler.cs +++ b/src/processes/DimProcess.Library/DimProcessHandler.cs @@ -62,7 +62,7 @@ public class DimProcessHandler( ClientSecret = _settings.ClientsecretCisCentral }; - var subAccountId = await subAccountClient.CreateSubaccount(subAccountAuth, adminMail, tenantName, parentDirectoryId, cancellationToken).ConfigureAwait(false); + var subAccountId = await subAccountClient.CreateSubaccount(subAccountAuth, adminMail, tenantName, parentDirectoryId, cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None); dimRepositories.GetInstance().AttachAndModifyTenant(tenantId, tenant => { tenant.SubAccountId = null; @@ -88,13 +88,13 @@ public class DimProcessHandler( }; var tenantRepository = dimRepositories.GetInstance(); - var subAccountId = await tenantRepository.GetSubAccountIdByTenantId(tenantId).ConfigureAwait(false); + var subAccountId = await tenantRepository.GetSubAccountIdByTenantId(tenantId).ConfigureAwait(ConfigureAwaitOptions.None); if (subAccountId == null) { throw new ConflictException("SubAccountId must not be null."); } - await subAccountClient.CreateServiceManagerBindings(subAccountAuth, subAccountId.Value, cancellationToken).ConfigureAwait(false); + await subAccountClient.CreateServiceManagerBindings(subAccountAuth, subAccountId.Value, cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None); return new ValueTuple?, ProcessStepStatusId, bool, string?>( Enumerable.Repeat(ProcessStepTypeId.ASSIGN_ENTITLEMENTS, 1), @@ -111,13 +111,13 @@ public class DimProcessHandler( ClientId = _settings.ClientidCisCentral, ClientSecret = _settings.ClientsecretCisCentral }; - var subAccountId = await dimRepositories.GetInstance().GetSubAccountIdByTenantId(tenantId).ConfigureAwait(false); + var subAccountId = await dimRepositories.GetInstance().GetSubAccountIdByTenantId(tenantId).ConfigureAwait(ConfigureAwaitOptions.None); if (subAccountId == null) { throw new ConflictException("SubAccountId must not be null."); } - await entitlementClient.AssignEntitlements(subAccountAuth, subAccountId.Value, cancellationToken).ConfigureAwait(false); + await entitlementClient.AssignEntitlements(subAccountAuth, subAccountId.Value, cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None); return new ValueTuple?, ProcessStepStatusId, bool, string?>( Enumerable.Repeat(ProcessStepTypeId.CREATE_SERVICE_INSTANCE, 1), @@ -134,14 +134,14 @@ public class DimProcessHandler( ClientId = _settings.ClientidCisCentral, ClientSecret = _settings.ClientsecretCisCentral }; - var subAccountId = await dimRepositories.GetInstance().GetSubAccountIdByTenantId(tenantId).ConfigureAwait(false); + var subAccountId = await dimRepositories.GetInstance().GetSubAccountIdByTenantId(tenantId).ConfigureAwait(ConfigureAwaitOptions.None); if (subAccountId == null) { throw new ConflictException("SubAccountId must not be null."); } - var saBinding = await subAccountClient.GetServiceManagerBindings(subAccountAuth, subAccountId.Value, cancellationToken).ConfigureAwait(false); - var serviceInstance = await serviceClient.CreateServiceInstance(saBinding, cancellationToken).ConfigureAwait(false); + var saBinding = await subAccountClient.GetServiceManagerBindings(subAccountAuth, subAccountId.Value, cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None); + var serviceInstance = await serviceClient.CreateServiceInstance(saBinding, cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None); dimRepositories.GetInstance().AttachAndModifyTenant(tenantId, tenant => { @@ -166,7 +166,7 @@ public class DimProcessHandler( ClientId = _settings.ClientidCisCentral, ClientSecret = _settings.ClientsecretCisCentral }; - var (subAccountId, serviceInstanceId) = await dimRepositories.GetInstance().GetSubAccountAndServiceInstanceIdsByTenantId(tenantId).ConfigureAwait(false); + var (subAccountId, serviceInstanceId) = await dimRepositories.GetInstance().GetSubAccountAndServiceInstanceIdsByTenantId(tenantId).ConfigureAwait(ConfigureAwaitOptions.None); if (subAccountId == null) { throw new ConflictException("SubAccountId must not be null."); @@ -177,8 +177,8 @@ public class DimProcessHandler( throw new ConflictException("ServiceInstanceId must not be null."); } - var saBinding = await subAccountClient.GetServiceManagerBindings(subAccountAuth, subAccountId.Value, cancellationToken).ConfigureAwait(false); - var serviceBinding = await serviceClient.CreateServiceBinding(saBinding, serviceInstanceId, cancellationToken).ConfigureAwait(false); + var saBinding = await subAccountClient.GetServiceManagerBindings(subAccountAuth, subAccountId.Value, cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None); + var serviceBinding = await serviceClient.CreateServiceBinding(saBinding, serviceInstanceId, cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None); dimRepositories.GetInstance().AttachAndModifyTenant(tenantId, tenant => { @@ -203,7 +203,7 @@ public class DimProcessHandler( ClientId = _settings.ClientidCisCentral, ClientSecret = _settings.ClientsecretCisCentral }; - var (subAccountId, serviceBindingName) = await dimRepositories.GetInstance().GetSubAccountIdAndServiceBindingNameByTenantId(tenantId).ConfigureAwait(false); + var (subAccountId, serviceBindingName) = await dimRepositories.GetInstance().GetSubAccountIdAndServiceBindingNameByTenantId(tenantId).ConfigureAwait(ConfigureAwaitOptions.None); if (subAccountId == null) { throw new ConflictException("SubAccountId must not be null."); @@ -214,9 +214,9 @@ public class DimProcessHandler( throw new ConflictException("ServiceBindingName must not be null."); } - var saBinding = await subAccountClient.GetServiceManagerBindings(subAccountAuth, subAccountId.Value, cancellationToken).ConfigureAwait(false); - var bindingResponse = await serviceClient.GetServiceBinding(saBinding, serviceBindingName, cancellationToken).ConfigureAwait(false); - await subscriptionClient.SubscribeApplication(saBinding.Url, bindingResponse, "decentralized-identity-management-app", "standard", cancellationToken).ConfigureAwait(false); + var saBinding = await subAccountClient.GetServiceManagerBindings(subAccountAuth, subAccountId.Value, cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None); + var bindingResponse = await serviceClient.GetServiceBinding(saBinding, serviceBindingName, cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None); + await subscriptionClient.SubscribeApplication(saBinding.Url, bindingResponse, "decentralized-identity-management-app", "standard", cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None); return new ValueTuple?, ProcessStepStatusId, bool, string?>( Enumerable.Repeat(ProcessStepTypeId.CREATE_CLOUD_FOUNDRY_ENVIRONMENT, 1), @@ -234,7 +234,7 @@ public class DimProcessHandler( ClientId = _settings.ClientidCisCentral, ClientSecret = _settings.ClientsecretCisCentral }; - var (subAccountId, serviceBindingName) = await dimRepositories.GetInstance().GetSubAccountIdAndServiceBindingNameByTenantId(tenantId).ConfigureAwait(false); + var (subAccountId, serviceBindingName) = await dimRepositories.GetInstance().GetSubAccountIdAndServiceBindingNameByTenantId(tenantId).ConfigureAwait(ConfigureAwaitOptions.None); if (subAccountId == null) { throw new ConflictException("SubAccountId must not be null."); @@ -245,10 +245,10 @@ public class DimProcessHandler( throw new ConflictException("ServiceBindingName must not be null."); } - var saBinding = await subAccountClient.GetServiceManagerBindings(subAccountAuth, subAccountId.Value, cancellationToken).ConfigureAwait(false); - var bindingResponse = await serviceClient.GetServiceBinding(saBinding, serviceBindingName, cancellationToken).ConfigureAwait(false); + var saBinding = await subAccountClient.GetServiceManagerBindings(subAccountAuth, subAccountId.Value, cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None); + var bindingResponse = await serviceClient.GetServiceBinding(saBinding, serviceBindingName, cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None); await provisioningClient.CreateCloudFoundryEnvironment(saBinding.Url, bindingResponse, tenantName, adminMail, cancellationToken) - .ConfigureAwait(false); + .ConfigureAwait(ConfigureAwaitOptions.None); return new ValueTuple?, ProcessStepStatusId, bool, string?>( Enumerable.Repeat(ProcessStepTypeId.CREATE_CLOUD_FOUNDRY_SPACE, 1), @@ -259,7 +259,7 @@ await provisioningClient.CreateCloudFoundryEnvironment(saBinding.Url, bindingRes public async Task<(IEnumerable? nextStepTypeIds, ProcessStepStatusId stepStatusId, bool modified, string? processMessage)> CreateCloudFoundrySpace(Guid tenantId, string tenantName, CancellationToken cancellationToken) { - var spaceId = await cfClient.CreateCloudFoundrySpace(tenantName, cancellationToken).ConfigureAwait(false); + var spaceId = await cfClient.CreateCloudFoundrySpace(tenantName, cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None); dimRepositories.GetInstance().AttachAndModifyTenant(tenantId, tenant => { @@ -279,13 +279,13 @@ await provisioningClient.CreateCloudFoundryEnvironment(saBinding.Url, bindingRes public async Task<(IEnumerable? nextStepTypeIds, ProcessStepStatusId stepStatusId, bool modified, string? processMessage)> AddSpaceManagerRole(Guid tenantId, CancellationToken cancellationToken) { var adminMail = _settings.AdminMail; - var spaceId = await dimRepositories.GetInstance().GetSpaceId(tenantId).ConfigureAwait(false); + var spaceId = await dimRepositories.GetInstance().GetSpaceId(tenantId).ConfigureAwait(ConfigureAwaitOptions.None); if (spaceId == null) { throw new ConflictException("SpaceId must not be null."); } - await cfClient.AddSpaceRoleToUser("space_manager", adminMail, spaceId.Value, cancellationToken).ConfigureAwait(false); + await cfClient.AddSpaceRoleToUser("space_manager", adminMail, spaceId.Value, cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None); return new ValueTuple?, ProcessStepStatusId, bool, string?>( Enumerable.Repeat(ProcessStepTypeId.ADD_SPACE_DEVELOPER_ROLE, 1), @@ -297,13 +297,13 @@ await provisioningClient.CreateCloudFoundryEnvironment(saBinding.Url, bindingRes public async Task<(IEnumerable? nextStepTypeIds, ProcessStepStatusId stepStatusId, bool modified, string? processMessage)> AddSpaceDeveloperRole(Guid tenantId, CancellationToken cancellationToken) { var adminMail = _settings.AdminMail; - var spaceId = await dimRepositories.GetInstance().GetSpaceId(tenantId).ConfigureAwait(false); + var spaceId = await dimRepositories.GetInstance().GetSpaceId(tenantId).ConfigureAwait(ConfigureAwaitOptions.None); if (spaceId == null) { throw new ConflictException("SpaceId must not be null."); } - await cfClient.AddSpaceRoleToUser("space_developer", adminMail, spaceId.Value, cancellationToken).ConfigureAwait(false); + await cfClient.AddSpaceRoleToUser("space_developer", adminMail, spaceId.Value, cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None); return new ValueTuple?, ProcessStepStatusId, bool, string?>( Enumerable.Repeat(ProcessStepTypeId.CREATE_DIM_SERVICE_INSTANCE, 1), @@ -314,9 +314,9 @@ await provisioningClient.CreateCloudFoundryEnvironment(saBinding.Url, bindingRes public async Task<(IEnumerable? nextStepTypeIds, ProcessStepStatusId stepStatusId, bool modified, string? processMessage)> CreateDimServiceInstance(string tenantName, Guid tenantId, CancellationToken cancellationToken) { - var servicePlanId = await cfClient.GetServicePlan("decentralized-identity-management", "standard", cancellationToken).ConfigureAwait(false); - var spaceId = await cfClient.GetSpace(tenantName, cancellationToken).ConfigureAwait(false); - await cfClient.CreateDimServiceInstance(tenantName, spaceId, servicePlanId, cancellationToken).ConfigureAwait(false); + var servicePlanId = await cfClient.GetServicePlan("decentralized-identity-management", "standard", cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None); + var spaceId = await cfClient.GetSpace(tenantName, cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None); + await cfClient.CreateDimServiceInstance(tenantName, spaceId, servicePlanId, cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None); return new ValueTuple?, ProcessStepStatusId, bool, string?>( Enumerable.Repeat(ProcessStepTypeId.CREATE_SERVICE_INSTANCE_BINDING, 1), @@ -327,13 +327,13 @@ await provisioningClient.CreateCloudFoundryEnvironment(saBinding.Url, bindingRes public async Task<(IEnumerable? nextStepTypeIds, ProcessStepStatusId stepStatusId, bool modified, string? processMessage)> CreateServiceInstanceBindings(string tenantName, Guid tenantId, CancellationToken cancellationToken) { - var spaceId = await dimRepositories.GetInstance().GetSpaceId(tenantId).ConfigureAwait(false); + var spaceId = await dimRepositories.GetInstance().GetSpaceId(tenantId).ConfigureAwait(ConfigureAwaitOptions.None); if (spaceId == null) { throw new ConflictException("SpaceId must not be null."); } - await cfClient.CreateServiceInstanceBindings(tenantName, null, spaceId.Value, cancellationToken).ConfigureAwait(false); + await cfClient.CreateServiceInstanceBindings(tenantName, null, spaceId.Value, cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None); return new ValueTuple?, ProcessStepStatusId, bool, string?>( Enumerable.Repeat(ProcessStepTypeId.GET_DIM_DETAILS, 1), @@ -344,13 +344,13 @@ await provisioningClient.CreateCloudFoundryEnvironment(saBinding.Url, bindingRes public async Task<(IEnumerable? nextStepTypeIds, ProcessStepStatusId stepStatusId, bool modified, string? processMessage)> GetDimDetails(string tenantName, Guid tenantId, CancellationToken cancellationToken) { - var spaceId = await dimRepositories.GetInstance().GetSpaceId(tenantId).ConfigureAwait(false); + var spaceId = await dimRepositories.GetInstance().GetSpaceId(tenantId).ConfigureAwait(ConfigureAwaitOptions.None); if (spaceId == null) { throw new ConflictException("SpaceId must not be null."); } - var dimInstanceId = await cfClient.GetServiceBinding(tenantName, spaceId.Value, $"{tenantName}-dim-key01", cancellationToken).ConfigureAwait(false); + var dimInstanceId = await cfClient.GetServiceBinding(tenantName, spaceId.Value, $"{tenantName}-dim-key01", cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None); dimRepositories.GetInstance().AttachAndModifyTenant(tenantId, tenant => { @@ -369,13 +369,13 @@ await provisioningClient.CreateCloudFoundryEnvironment(saBinding.Url, bindingRes public async Task<(IEnumerable? nextStepTypeIds, ProcessStepStatusId stepStatusId, bool modified, string? processMessage)> CreateApplication(string tenantName, Guid tenantId, CancellationToken cancellationToken) { - var (dimInstanceId, _, _) = await dimRepositories.GetInstance().GetDimInstanceIdAndHostingUrl(tenantId).ConfigureAwait(false); + var (dimInstanceId, _, _) = await dimRepositories.GetInstance().GetDimInstanceIdAndHostingUrl(tenantId).ConfigureAwait(ConfigureAwaitOptions.None); if (dimInstanceId == null) { throw new ConflictException("DimInstanceId must not be null."); } - var dimDetails = await cfClient.GetServiceBindingDetails(dimInstanceId.Value, cancellationToken).ConfigureAwait(false); + var dimDetails = await cfClient.GetServiceBindingDetails(dimInstanceId.Value, cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None); var dimAuth = new BasicAuthSettings { @@ -384,7 +384,7 @@ await provisioningClient.CreateCloudFoundryEnvironment(saBinding.Url, bindingRes ClientSecret = dimDetails.Credentials.Uaa.ClientSecret }; var dimBaseUrl = dimDetails.Credentials.Url; - var applicationId = await dimClient.CreateApplication(dimAuth, dimBaseUrl, tenantName, cancellationToken).ConfigureAwait(false); + var applicationId = await dimClient.CreateApplication(dimAuth, dimBaseUrl, tenantName, cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None); dimRepositories.GetInstance().AttachAndModifyTenant(tenantId, tenant => { tenant.ApplicationId = null; @@ -402,13 +402,13 @@ await provisioningClient.CreateCloudFoundryEnvironment(saBinding.Url, bindingRes public async Task<(IEnumerable? nextStepTypeIds, ProcessStepStatusId stepStatusId, bool modified, string? processMessage)> CreateCompanyIdentity(Guid tenantId, CancellationToken cancellationToken) { - var (dimInstanceId, hostingUrl, isIssuer) = await dimRepositories.GetInstance().GetDimInstanceIdAndHostingUrl(tenantId).ConfigureAwait(false); + var (dimInstanceId, hostingUrl, isIssuer) = await dimRepositories.GetInstance().GetDimInstanceIdAndHostingUrl(tenantId).ConfigureAwait(ConfigureAwaitOptions.None); if (dimInstanceId == null) { throw new ConflictException("DimInstanceId must not be null."); } - var dimDetails = await cfClient.GetServiceBindingDetails(dimInstanceId.Value, cancellationToken).ConfigureAwait(false); + var dimDetails = await cfClient.GetServiceBindingDetails(dimInstanceId.Value, cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None); var dimAuth = new BasicAuthSettings { @@ -417,7 +417,7 @@ await provisioningClient.CreateCloudFoundryEnvironment(saBinding.Url, bindingRes ClientSecret = dimDetails.Credentials.Uaa.ClientSecret }; var dimBaseUrl = dimDetails.Credentials.Url; - var result = await dimClient.CreateCompanyIdentity(dimAuth, tenantId, hostingUrl, dimBaseUrl, isIssuer, cancellationToken).ConfigureAwait(false); + var result = await dimClient.CreateCompanyIdentity(dimAuth, tenantId, hostingUrl, dimBaseUrl, isIssuer, cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None); dimRepositories.GetInstance().AttachAndModifyTenant(tenantId, tenant => { @@ -440,7 +440,7 @@ await provisioningClient.CreateCloudFoundryEnvironment(saBinding.Url, bindingRes public async Task<(IEnumerable? nextStepTypeIds, ProcessStepStatusId stepStatusId, bool modified, string? processMessage)> AssignCompanyApplication(Guid tenantId, CancellationToken cancellationToken) { - var (applicationId, companyId, dimInstanceId, isIssuer) = await dimRepositories.GetInstance().GetApplicationAndCompanyId(tenantId).ConfigureAwait(false); + var (applicationId, companyId, dimInstanceId, isIssuer) = await dimRepositories.GetInstance().GetApplicationAndCompanyId(tenantId).ConfigureAwait(ConfigureAwaitOptions.None); if (applicationId == null) { throw new ConflictException("ApplicationId must always be set here"); @@ -456,7 +456,7 @@ await provisioningClient.CreateCloudFoundryEnvironment(saBinding.Url, bindingRes throw new ConflictException("DimInstanceId must not be null."); } - var dimDetails = await cfClient.GetServiceBindingDetails(dimInstanceId.Value, cancellationToken).ConfigureAwait(false); + var dimDetails = await cfClient.GetServiceBindingDetails(dimInstanceId.Value, cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None); var dimAuth = new BasicAuthSettings { TokenAddress = $"{dimDetails.Credentials.Uaa.Url}/oauth/token", @@ -465,7 +465,7 @@ await provisioningClient.CreateCloudFoundryEnvironment(saBinding.Url, bindingRes }; var dimBaseUrl = dimDetails.Credentials.Url; var applicationKey = await dimClient.GetApplication(dimAuth, dimBaseUrl, applicationId, cancellationToken); - await dimClient.AssignApplicationToCompany(dimAuth, dimBaseUrl, applicationKey, companyId.Value, cancellationToken).ConfigureAwait(false); + await dimClient.AssignApplicationToCompany(dimAuth, dimBaseUrl, applicationKey, companyId.Value, cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None); dimRepositories.GetInstance().AttachAndModifyTenant(tenantId, tenant => { @@ -484,7 +484,7 @@ await provisioningClient.CreateCloudFoundryEnvironment(saBinding.Url, bindingRes public async Task<(IEnumerable? nextStepTypeIds, ProcessStepStatusId stepStatusId, bool modified, string? processMessage)> CreateStatusList(Guid tenantId, CancellationToken cancellationToken) { - var (_, companyId, dimInstanceId, _) = await dimRepositories.GetInstance().GetApplicationAndCompanyId(tenantId).ConfigureAwait(false); + var (_, companyId, dimInstanceId, _) = await dimRepositories.GetInstance().GetApplicationAndCompanyId(tenantId).ConfigureAwait(ConfigureAwaitOptions.None); if (companyId == null) { throw new ConflictException("CompanyId must always be set here"); @@ -495,7 +495,7 @@ await provisioningClient.CreateCloudFoundryEnvironment(saBinding.Url, bindingRes throw new ConflictException("DimInstanceId must not be null."); } - var dimDetails = await cfClient.GetServiceBindingDetails(dimInstanceId.Value, cancellationToken).ConfigureAwait(false); + var dimDetails = await cfClient.GetServiceBindingDetails(dimInstanceId.Value, cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None); var dimAuth = new BasicAuthSettings { TokenAddress = $"{dimDetails.Credentials.Uaa.Url}/oauth/token", @@ -503,7 +503,7 @@ await provisioningClient.CreateCloudFoundryEnvironment(saBinding.Url, bindingRes ClientSecret = dimDetails.Credentials.Uaa.ClientSecret }; var dimBaseUrl = dimDetails.Credentials.Url; - await dimClient.CreateStatusList(dimAuth, dimBaseUrl, companyId.Value, cancellationToken).ConfigureAwait(false); + await dimClient.CreateStatusList(dimAuth, dimBaseUrl, companyId.Value, cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None); return new ValueTuple?, ProcessStepStatusId, bool, string?>( Enumerable.Repeat(ProcessStepTypeId.SEND_CALLBACK, 1), @@ -514,7 +514,7 @@ await provisioningClient.CreateCloudFoundryEnvironment(saBinding.Url, bindingRes public async Task<(IEnumerable? nextStepTypeIds, ProcessStepStatusId stepStatusId, bool modified, string? processMessage)> SendCallback(Guid tenantId, CancellationToken cancellationToken) { - var (bpn, downloadUrl, did, dimInstanceId) = await dimRepositories.GetInstance().GetCallbackData(tenantId).ConfigureAwait(false); + var (bpn, downloadUrl, did, dimInstanceId) = await dimRepositories.GetInstance().GetCallbackData(tenantId).ConfigureAwait(ConfigureAwaitOptions.None); if (downloadUrl == null) { throw new ConflictException("DownloadUrl must not be null."); @@ -530,10 +530,10 @@ await provisioningClient.CreateCloudFoundryEnvironment(saBinding.Url, bindingRes throw new ConflictException("DimInstanceId must not be null."); } - var dimDetails = await cfClient.GetServiceBindingDetails(dimInstanceId.Value, cancellationToken).ConfigureAwait(false); - var didDocument = await dimClient.GetDidDocument(downloadUrl, cancellationToken).ConfigureAwait(false); + var dimDetails = await cfClient.GetServiceBindingDetails(dimInstanceId.Value, cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None); + var didDocument = await dimClient.GetDidDocument(downloadUrl, cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None); - await callbackService.SendCallback(bpn, dimDetails, didDocument, did, cancellationToken).ConfigureAwait(false); + await callbackService.SendCallback(bpn, dimDetails, didDocument, did, cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None); return new ValueTuple?, ProcessStepStatusId, bool, string?>( null, diff --git a/src/processes/DimProcess.Library/TechnicalUserProcessHandler.cs b/src/processes/DimProcess.Library/TechnicalUserProcessHandler.cs index 18f414e..df53ad5 100644 --- a/src/processes/DimProcess.Library/TechnicalUserProcessHandler.cs +++ b/src/processes/DimProcess.Library/TechnicalUserProcessHandler.cs @@ -41,13 +41,13 @@ public class TechnicalUserProcessHandler( public async Task<(IEnumerable? nextStepTypeIds, ProcessStepStatusId stepStatusId, bool modified, string? processMessage)> CreateServiceInstanceBindings(string tenantName, Guid technicalUserId, CancellationToken cancellationToken) { - var (spaceId, technicalUserName) = await dimRepositories.GetInstance().GetSpaceIdAndTechnicalUserName(technicalUserId).ConfigureAwait(false); + var (spaceId, technicalUserName) = await dimRepositories.GetInstance().GetSpaceIdAndTechnicalUserName(technicalUserId).ConfigureAwait(ConfigureAwaitOptions.None); if (spaceId == null) { throw new ConflictException("SpaceId must not be null."); } - await cfClient.CreateServiceInstanceBindings(tenantName, technicalUserName, spaceId.Value, cancellationToken).ConfigureAwait(false); + await cfClient.CreateServiceInstanceBindings(tenantName, technicalUserName, spaceId.Value, cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None); return new ValueTuple?, ProcessStepStatusId, bool, string?>( Enumerable.Repeat(ProcessStepTypeId.GET_TECHNICAL_USER_DATA, 1), @@ -58,14 +58,14 @@ public class TechnicalUserProcessHandler( public async Task<(IEnumerable? nextStepTypeIds, ProcessStepStatusId stepStatusId, bool modified, string? processMessage)> GetTechnicalUserData(string tenantName, Guid technicalUserId, CancellationToken cancellationToken) { - var (spaceId, technicalUserName) = await dimRepositories.GetInstance().GetSpaceIdAndTechnicalUserName(technicalUserId).ConfigureAwait(false); + var (spaceId, technicalUserName) = await dimRepositories.GetInstance().GetSpaceIdAndTechnicalUserName(technicalUserId).ConfigureAwait(ConfigureAwaitOptions.None); if (spaceId == null) { throw new ConflictException("SpaceId must not be null."); } - var dimInstanceId = await cfClient.GetServiceBinding(tenantName, spaceId.Value, $"{technicalUserName}-dim-key01", cancellationToken).ConfigureAwait(false); - var dimDetails = await cfClient.GetServiceBindingDetails(dimInstanceId, cancellationToken).ConfigureAwait(false); + var dimInstanceId = await cfClient.GetServiceBinding(tenantName, spaceId.Value, $"{technicalUserName}-dim-key01", cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None); + var dimDetails = await cfClient.GetServiceBindingDetails(dimInstanceId, cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None); var cryptoHelper = _settings.EncryptionConfigs.GetCryptoHelper(_settings.EncryptionConfigIndex); var (secret, initializationVector) = cryptoHelper.Encrypt(dimDetails.Credentials.Uaa.ClientSecret); @@ -95,7 +95,7 @@ public class TechnicalUserProcessHandler( public async Task<(IEnumerable? nextStepTypeIds, ProcessStepStatusId stepStatusId, bool modified, string? processMessage)> SendCreateCallback(Guid technicalUserId, CancellationToken cancellationToken) { - var (externalId, tokenAddress, clientId, clientSecret, initializationVector, _) = await dimRepositories.GetInstance().GetTechnicalUserCallbackData(technicalUserId).ConfigureAwait(false); + var (externalId, tokenAddress, clientId, clientSecret, initializationVector, _) = await dimRepositories.GetInstance().GetTechnicalUserCallbackData(technicalUserId).ConfigureAwait(ConfigureAwaitOptions.None); if (string.IsNullOrWhiteSpace(clientId)) { @@ -115,7 +115,7 @@ public class TechnicalUserProcessHandler( var cryptoHelper = _settings.EncryptionConfigs.GetCryptoHelper(_settings.EncryptionConfigIndex); var secret = cryptoHelper.Decrypt(clientSecret, initializationVector); - await callbackService.SendTechnicalUserCallback(externalId, tokenAddress, clientId, secret, cancellationToken).ConfigureAwait(false); + await callbackService.SendTechnicalUserCallback(externalId, tokenAddress, clientId, secret, cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None); return new ValueTuple?, ProcessStepStatusId, bool, string?>( null, @@ -126,14 +126,14 @@ public class TechnicalUserProcessHandler( public async Task<(IEnumerable? nextStepTypeIds, ProcessStepStatusId stepStatusId, bool modified, string? processMessage)> DeleteServiceInstanceBindings(string tenantName, Guid technicalUserId, CancellationToken cancellationToken) { - var (spaceId, technicalUserName) = await dimRepositories.GetInstance().GetSpaceIdAndTechnicalUserName(technicalUserId).ConfigureAwait(false); + var (spaceId, technicalUserName) = await dimRepositories.GetInstance().GetSpaceIdAndTechnicalUserName(technicalUserId).ConfigureAwait(ConfigureAwaitOptions.None); if (spaceId == null) { throw new ConflictException("SpaceId must not be null."); } - var serviceBindingId = await cfClient.GetServiceBinding(tenantName, spaceId.Value, $"{technicalUserName}-dim-key01", cancellationToken).ConfigureAwait(false); - await cfClient.DeleteServiceInstanceBindings(serviceBindingId, cancellationToken).ConfigureAwait(false); + var serviceBindingId = await cfClient.GetServiceBinding(tenantName, spaceId.Value, $"{technicalUserName}-dim-key01", cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None); + await cfClient.DeleteServiceInstanceBindings(serviceBindingId, cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None); return new ValueTuple?, ProcessStepStatusId, bool, string?>( Enumerable.Repeat(ProcessStepTypeId.SEND_TECHNICAL_USER_DELETION_CALLBACK, 1), @@ -146,9 +146,9 @@ public class TechnicalUserProcessHandler( { var tenantRepository = dimRepositories.GetInstance(); - var externalId = await tenantRepository.GetExternalIdForTechnicalUser(technicalUserId).ConfigureAwait(false); + var externalId = await tenantRepository.GetExternalIdForTechnicalUser(technicalUserId).ConfigureAwait(ConfigureAwaitOptions.None); tenantRepository.RemoveTechnicalUser(technicalUserId); - await callbackService.SendTechnicalUserDeletionCallback(externalId, cancellationToken).ConfigureAwait(false); + await callbackService.SendTechnicalUserDeletionCallback(externalId, cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None); return new ValueTuple?, ProcessStepStatusId, bool, string?>( null, diff --git a/src/processes/Processes.Worker.Library/IProcessExecutor.cs b/src/processes/Processes.Worker.Library/IProcessExecutor.cs index 88a0b87..22bb752 100644 --- a/src/processes/Processes.Worker.Library/IProcessExecutor.cs +++ b/src/processes/Processes.Worker.Library/IProcessExecutor.cs @@ -20,7 +20,7 @@ using Dim.Entities.Enums; -namespace Org.Eclipse.TractusX.Portal.Backend.Processes.Worker.Library; +namespace Processes.Worker.Library; public interface IProcessExecutor { diff --git a/src/processes/Processes.Worker.Library/IProcessTypeExecutor.cs b/src/processes/Processes.Worker.Library/IProcessTypeExecutor.cs index 051803a..213de9f 100644 --- a/src/processes/Processes.Worker.Library/IProcessTypeExecutor.cs +++ b/src/processes/Processes.Worker.Library/IProcessTypeExecutor.cs @@ -21,7 +21,7 @@ using Dim.Entities.Enums; using Org.Eclipse.TractusX.Portal.Backend.Framework.ErrorHandling; -namespace Org.Eclipse.TractusX.Portal.Backend.Processes.Worker.Library; +namespace Processes.Worker.Library; public interface IProcessTypeExecutor { diff --git a/src/processes/Processes.Worker.Library/ProcessExecutionService.cs b/src/processes/Processes.Worker.Library/ProcessExecutionService.cs index d8644c2..076f04e 100644 --- a/src/processes/Processes.Worker.Library/ProcessExecutionService.cs +++ b/src/processes/Processes.Worker.Library/ProcessExecutionService.cs @@ -27,7 +27,7 @@ using Org.Eclipse.TractusX.Portal.Backend.Framework.DBAccess; using Org.Eclipse.TractusX.Portal.Backend.Framework.ErrorHandling; -namespace Org.Eclipse.TractusX.Portal.Backend.Processes.Worker.Library; +namespace Processes.Worker.Library; /// /// Service that reads all open/pending processSteps of a checklist and triggers their execution. @@ -118,14 +118,14 @@ bool UpdateVersion() _ => false }) { - await executorRepositories.SaveAsync().ConfigureAwait(false); + await executorRepositories.SaveAsync().ConfigureAwait(ConfigureAwaitOptions.None); } executorRepositories.Clear(); } if (process.ReleaseLock()) { - await executorRepositories.SaveAsync().ConfigureAwait(false); + await executorRepositories.SaveAsync().ConfigureAwait(ConfigureAwaitOptions.None); executorRepositories.Clear(); } _logger.LogInformation("finished processing process {processId}", process.Id); diff --git a/src/processes/Processes.Worker.Library/ProcessExecutionServiceExtensions.cs b/src/processes/Processes.Worker.Library/ProcessExecutionServiceExtensions.cs index 4642c0c..8fd0c74 100644 --- a/src/processes/Processes.Worker.Library/ProcessExecutionServiceExtensions.cs +++ b/src/processes/Processes.Worker.Library/ProcessExecutionServiceExtensions.cs @@ -22,7 +22,7 @@ using Microsoft.Extensions.DependencyInjection; using Org.Eclipse.TractusX.Portal.Backend.Framework.DateTimeProvider; -namespace Org.Eclipse.TractusX.Portal.Backend.Processes.Worker.Library; +namespace Processes.Worker.Library; public static class ProcessExecutionServiceExtensions { diff --git a/src/processes/Processes.Worker.Library/ProcessExecutionServiceSettings.cs b/src/processes/Processes.Worker.Library/ProcessExecutionServiceSettings.cs index 1508a17..3f31291 100644 --- a/src/processes/Processes.Worker.Library/ProcessExecutionServiceSettings.cs +++ b/src/processes/Processes.Worker.Library/ProcessExecutionServiceSettings.cs @@ -20,7 +20,7 @@ using System.ComponentModel.DataAnnotations; -namespace Org.Eclipse.TractusX.Portal.Backend.Processes.Worker.Library; +namespace Processes.Worker.Library; public class ProcessExecutionServiceSettings { diff --git a/src/processes/Processes.Worker.Library/ProcessExecutor.cs b/src/processes/Processes.Worker.Library/ProcessExecutor.cs index 96905e0..e1073fe 100644 --- a/src/processes/Processes.Worker.Library/ProcessExecutor.cs +++ b/src/processes/Processes.Worker.Library/ProcessExecutor.cs @@ -27,7 +27,7 @@ using System.Collections.Immutable; using System.Runtime.CompilerServices; -namespace Org.Eclipse.TractusX.Portal.Backend.Processes.Worker.Library; +namespace Processes.Worker.Library; public class ProcessExecutor : IProcessExecutor { @@ -78,6 +78,7 @@ public ProcessExecutor(IEnumerable executors, IDimReposito { yield return IProcessExecutor.ProcessExecutionResult.LockRequested; } + ProcessStepStatusId resultStepStatusId; IEnumerable? scheduleStepTypeIds; IEnumerable? skipStepTypeIds; @@ -97,10 +98,12 @@ public ProcessExecutor(IEnumerable executors, IDimReposito modified = false; success = false; } + if (!success) { yield return IProcessExecutor.ProcessExecutionResult.Unmodified; } + modified |= SetProcessStepStatus(stepTypeId, resultStepStatusId, context, processMessage); modified |= SkipProcessStepTypeIds(skipStepTypeIds, context); modified |= ScheduleProcessStepTypeIds(scheduleStepTypeIds, context); @@ -123,6 +126,7 @@ private bool ScheduleProcessStepTypeIds(IEnumerable? schedule { return false; } + foreach (var newStep in _processStepRepository.CreateProcessStepRange(newStepTypeIds.Select(stepTypeId => (stepTypeId, ProcessStepStatusId.TODO, context.ProcessId)))) { context.AllSteps.Add(newStep.ProcessStepTypeId, new[] { newStep.Id }); @@ -131,6 +135,7 @@ private bool ScheduleProcessStepTypeIds(IEnumerable? schedule context.ExecutableStepTypeIds.Add(newStep.ProcessStepTypeId); } } + return true; } @@ -140,6 +145,7 @@ private bool SkipProcessStepTypeIds(IEnumerable? skipStepType { return false; } + var modified = false; foreach (var skipStepTypeId in skipStepTypeIds) { @@ -151,6 +157,7 @@ private bool SkipProcessStepTypeIds(IEnumerable? skipStepType modified |= skippedStep; } + return modified; } @@ -164,17 +171,23 @@ private bool SetProcessStepStatus(ProcessStepTypeId stepTypeId, ProcessStepStatu var isFirst = true; foreach (var stepId in stepIds) { - _processStepRepository.AttachAndModifyProcessStep(stepId, null, step => + _processStepRepository.AttachAndModifyProcessStep(stepId, s => + { + s.Message = "placeholder"; + }, + step => { step.ProcessStepStatusId = isFirst ? stepStatusId : ProcessStepStatusId.DUPLICATE; step.Message = processMessage; }); isFirst = false; } + if (context.Executor.IsExecutableStepTypeId(stepTypeId)) { context.ExecutableStepTypeIds.Remove(stepTypeId); } + return true; } @@ -185,14 +198,9 @@ private sealed record ProcessContext( IProcessTypeExecutor Executor ); - private sealed class ProcessStepTypeSet + private sealed class ProcessStepTypeSet(IEnumerable items) { - private readonly HashSet _items; - - public ProcessStepTypeSet(IEnumerable items) - { - _items = new HashSet(items); - } + private readonly HashSet _items = new(items); public bool TryGetNext(out ProcessStepTypeId item) { @@ -202,6 +210,7 @@ public bool TryGetNext(out ProcessStepTypeId item) item = default; return false; } + item = enumerator.Current; _items.Remove(item); return true; diff --git a/src/processes/Processes.Worker/Program.cs b/src/processes/Processes.Worker/Program.cs index 1d26e66..8420912 100644 --- a/src/processes/Processes.Worker/Program.cs +++ b/src/processes/Processes.Worker/Program.cs @@ -24,7 +24,7 @@ using Microsoft.Extensions.Hosting; using Org.Eclipse.TractusX.Portal.Backend.Framework.Logging; using Org.Eclipse.TractusX.Portal.Backend.Framework.Token; -using Org.Eclipse.TractusX.Portal.Backend.Processes.Worker.Library; +using Processes.Worker.Library; using Serilog; LoggingExtensions.EnsureInitialized(); @@ -56,7 +56,7 @@ Log.Information("Start processing"); var workerInstance = host.Services.GetRequiredService(); - await workerInstance.ExecuteAsync(tokenSource.Token).ConfigureAwait(false); + await workerInstance.ExecuteAsync(tokenSource.Token).ConfigureAwait(ConfigureAwaitOptions.None); Log.Information("Execution finished shutting down"); } catch (Exception ex) when (!ex.GetType().Name.Equals("StopTheHostException", StringComparison.Ordinal)) diff --git a/src/web/Dim.Web/BusinessLogic/DimBusinessLogic.cs b/src/web/Dim.Web/BusinessLogic/DimBusinessLogic.cs index 7496cdc..b5fee4e 100644 --- a/src/web/Dim.Web/BusinessLogic/DimBusinessLogic.cs +++ b/src/web/Dim.Web/BusinessLogic/DimBusinessLogic.cs @@ -22,8 +22,11 @@ using Dim.Clients.Api.Dim; using Dim.Clients.Token; using Dim.DbAccess; +using Dim.DbAccess.Models; using Dim.DbAccess.Repositories; using Dim.Entities.Enums; +using Dim.Entities.Extensions; +using Dim.Processes.Library; using Dim.Web.ErrorHandling; using Dim.Web.Models; using Microsoft.Extensions.Options; @@ -48,12 +51,12 @@ public async Task StartSetupDim(string companyName, string bpn, string didDocume dimRepositories.GetInstance().CreateTenant(companyName, bpn, didDocumentLocation, isIssuer, processId, _settings.OperatorId); - await dimRepositories.SaveAsync().ConfigureAwait(false); + await dimRepositories.SaveAsync().ConfigureAwait(ConfigureAwaitOptions.None); } public async Task GetStatusList(string bpn, CancellationToken cancellationToken) { - var (exists, companyId, instanceId) = await dimRepositories.GetInstance().GetCompanyAndInstanceIdForBpn(bpn).ConfigureAwait(false); + var (exists, companyId, instanceId) = await dimRepositories.GetInstance().GetCompanyAndInstanceIdForBpn(bpn).ConfigureAwait(ConfigureAwaitOptions.None); if (!exists) { throw NotFoundException.Create(DimErrors.NO_COMPANY_FOR_BPN, new ErrorParameter[] { new("bpn", bpn) }); @@ -69,7 +72,7 @@ public async Task GetStatusList(string bpn, CancellationToken cancellati throw ConflictException.Create(DimErrors.NO_INSTANCE_ID_SET); } - var dimDetails = await cfClient.GetServiceBindingDetails(instanceId.Value, cancellationToken).ConfigureAwait(false); + var dimDetails = await cfClient.GetServiceBindingDetails(instanceId.Value, cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None); var dimAuth = new BasicAuthSettings { TokenAddress = $"{dimDetails.Credentials.Uaa.Url}/oauth/token", @@ -77,12 +80,12 @@ public async Task GetStatusList(string bpn, CancellationToken cancellati ClientSecret = dimDetails.Credentials.Uaa.ClientSecret }; var dimBaseUrl = dimDetails.Credentials.Url; - return await dimClient.GetStatusList(dimAuth, dimBaseUrl, companyId.Value, cancellationToken).ConfigureAwait(false); + return await dimClient.GetStatusList(dimAuth, dimBaseUrl, companyId.Value, cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None); } public async Task CreateStatusList(string bpn, CancellationToken cancellationToken) { - var (exists, companyId, instanceId) = await dimRepositories.GetInstance().GetCompanyAndInstanceIdForBpn(bpn).ConfigureAwait(false); + var (exists, companyId, instanceId) = await dimRepositories.GetInstance().GetCompanyAndInstanceIdForBpn(bpn).ConfigureAwait(ConfigureAwaitOptions.None); if (!exists) { throw NotFoundException.Create(DimErrors.NO_COMPANY_FOR_BPN, new ErrorParameter[] { new("bpn", bpn) }); @@ -98,7 +101,7 @@ public async Task CreateStatusList(string bpn, CancellationToken cancell throw ConflictException.Create(DimErrors.NO_INSTANCE_ID_SET); } - var dimDetails = await cfClient.GetServiceBindingDetails(instanceId.Value, cancellationToken).ConfigureAwait(false); + var dimDetails = await cfClient.GetServiceBindingDetails(instanceId.Value, cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None); var dimAuth = new BasicAuthSettings { TokenAddress = $"{dimDetails.Credentials.Uaa.Url}/oauth/token", @@ -106,12 +109,12 @@ public async Task CreateStatusList(string bpn, CancellationToken cancell ClientSecret = dimDetails.Credentials.Uaa.ClientSecret }; var dimBaseUrl = dimDetails.Credentials.Url; - return await dimClient.CreateStatusList(dimAuth, dimBaseUrl, companyId.Value, cancellationToken).ConfigureAwait(false); + return await dimClient.CreateStatusList(dimAuth, dimBaseUrl, companyId.Value, cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None); } public async Task CreateTechnicalUser(string bpn, TechnicalUserData technicalUserData) { - var (exists, tenantId) = await dimRepositories.GetInstance().GetTenantForBpn(bpn).ConfigureAwait(false); + var (exists, tenantId) = await dimRepositories.GetInstance().GetTenantForBpn(bpn).ConfigureAwait(ConfigureAwaitOptions.None); if (!exists) { @@ -124,12 +127,12 @@ public async Task CreateTechnicalUser(string bpn, TechnicalUserData technicalUse dimRepositories.GetInstance().CreateTenantTechnicalUser(tenantId, technicalUserData.Name, technicalUserData.ExternalId, processId); - await dimRepositories.SaveAsync().ConfigureAwait(false); + await dimRepositories.SaveAsync().ConfigureAwait(ConfigureAwaitOptions.None); } public async Task DeleteTechnicalUser(string bpn, TechnicalUserData technicalUserData) { - var (exists, technicalUserId, processId) = await dimRepositories.GetInstance().GetTechnicalUserForBpn(bpn, technicalUserData.Name).ConfigureAwait(false); + var (exists, technicalUserId, processId) = await dimRepositories.GetInstance().GetTechnicalUserForBpn(bpn, technicalUserData.Name).ConfigureAwait(ConfigureAwaitOptions.None); if (!exists) { throw NotFoundException.Create(DimErrors.NO_TECHNICAL_USER_FOUND, new ErrorParameter[] { new("bpn", bpn) }); @@ -144,6 +147,47 @@ public async Task DeleteTechnicalUser(string bpn, TechnicalUserData technicalUse t.ProcessId = processId; }); - await dimRepositories.SaveAsync().ConfigureAwait(false); + await dimRepositories.SaveAsync().ConfigureAwait(ConfigureAwaitOptions.None); + } + + public async Task GetSetupProcess(string bpn, string companyName) + { + var processData = await dimRepositories.GetInstance().GetWalletProcessForTenant(bpn, companyName) + .ConfigureAwait(ConfigureAwaitOptions.None); + if (processData == null) + { + throw new NotFoundException($"No process data found for BPN {bpn} and company name {companyName}"); + } + + return processData; + } + + public async Task GetTechnicalUserProcess(string technicalUserName) + { + var processData = await dimRepositories.GetInstance().GetTechnicalUserProcess(technicalUserName) + .ConfigureAwait(ConfigureAwaitOptions.None); + if (processData == null) + { + throw new NotFoundException($"No process data found for technical user {technicalUserName}"); + } + + return processData; + } + + public async Task RetriggerProcessStep(Guid processId, ProcessStepTypeId processStepTypeId) + { + var stepToTrigger = processStepTypeId.GetWalletStepForRetrigger(); + + var (validProcessId, processData) = await dimRepositories.GetInstance().IsValidProcess(processId, ProcessTypeId.SETUP_DIM, 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); } } diff --git a/src/web/Dim.Web/BusinessLogic/IDimBusinessLogic.cs b/src/web/Dim.Web/BusinessLogic/IDimBusinessLogic.cs index 603bb0e..cc75032 100644 --- a/src/web/Dim.Web/BusinessLogic/IDimBusinessLogic.cs +++ b/src/web/Dim.Web/BusinessLogic/IDimBusinessLogic.cs @@ -18,6 +18,8 @@ * SPDX-License-Identifier: Apache-2.0 ********************************************************************************/ +using Dim.DbAccess.Models; +using Dim.Entities.Enums; using Dim.Web.Models; using Org.Eclipse.TractusX.Portal.Backend.Framework.DependencyInjection; @@ -30,4 +32,7 @@ public interface IDimBusinessLogic : ITransient Task CreateStatusList(string bpn, CancellationToken cancellationToken); Task CreateTechnicalUser(string bpn, TechnicalUserData technicalUserData); Task DeleteTechnicalUser(string bpn, TechnicalUserData technicalUserData); + Task GetSetupProcess(string bpn, string companyName); + Task GetTechnicalUserProcess(string technicalUserName); + Task RetriggerProcessStep(Guid processId, ProcessStepTypeId processStepTypeId); } diff --git a/src/web/Dim.Web/Controllers/DimController.cs b/src/web/Dim.Web/Controllers/DimController.cs index 486ecdb..e98ac32 100644 --- a/src/web/Dim.Web/Controllers/DimController.cs +++ b/src/web/Dim.Web/Controllers/DimController.cs @@ -18,6 +18,7 @@ * SPDX-License-Identifier: Apache-2.0 ********************************************************************************/ +using Dim.Entities.Enums; using Dim.Web.BusinessLogic; using Dim.Web.Extensions; using Dim.Web.Models; @@ -80,6 +81,43 @@ public static RouteGroupBuilder MapDimApi(this RouteGroupBuilder group) .RequireAuthorization(r => r.RequireRole("delete_technical_user")) .Produces(StatusCodes.Status200OK, contentType: Constants.JsonContentType); + dim.MapGet("process/setup", ( + [FromQuery] string bpn, + [FromQuery] string companyName, + [FromServices] IDimBusinessLogic dimBusinessLogic) + => dimBusinessLogic.GetSetupProcess(bpn, companyName) + ) + .WithSwaggerDescription("Gets the wallet creation process id for the given bpn and companyName", + "Example: Post: api/dim/process/setup?bpn={bpn}&companyName={companyName}", + "bpn of the company", + "name of the company") + .RequireAuthorization(r => r.RequireRole("get_process")) + .Produces(StatusCodes.Status200OK, contentType: Constants.JsonContentType); + + dim.MapGet("process/technical-user", ( + [FromQuery] string technicalUserName, + [FromServices] IDimBusinessLogic dimBusinessLogic) + => dimBusinessLogic.GetTechnicalUserProcess(technicalUserName) + ) + .WithSwaggerDescription("Gets the technical user creation process id for the given technicalUserName", + "Example: Post: api/dim/process/technical-user?technicalUserName={technicalUserName}", + "name of the techincal user to get the process for") + .RequireAuthorization(r => r.RequireRole("get_process")) + .Produces(StatusCodes.Status200OK, contentType: Constants.JsonContentType); + + dim.MapGet("process/{processId}/retrigger", ( + [FromRoute] Guid processId, + [FromQuery] ProcessStepTypeId processStepTypeId, + [FromServices] IDimBusinessLogic dimBusinessLogic) + => dimBusinessLogic.RetriggerProcessStep(processId, processStepTypeId) + ) + .WithSwaggerDescription("Retriggers the given process step", + "Example: Post: api/dim/process/{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); + return group; } } diff --git a/src/web/Dim.Web/Dim.Web.csproj b/src/web/Dim.Web/Dim.Web.csproj index 886a45f..4a29c3d 100644 --- a/src/web/Dim.Web/Dim.Web.csproj +++ b/src/web/Dim.Web/Dim.Web.csproj @@ -21,6 +21,7 @@ + diff --git a/tests/processes/DimProcess.Library.Tests/DimProcessHandlerTests.cs b/tests/processes/DimProcess.Library.Tests/DimProcessHandlerTests.cs index f594324..455ce09 100644 --- a/tests/processes/DimProcess.Library.Tests/DimProcessHandlerTests.cs +++ b/tests/processes/DimProcess.Library.Tests/DimProcessHandlerTests.cs @@ -133,7 +133,7 @@ public async Task CreateServiceManagerBindings_WithNotExisting_ReturnsExpected() // Arrange A.CallTo(() => _tenantRepositories.GetSubAccountIdByTenantId(_tenantId)) .Returns((Guid?)null); - async Task Act() => await _sut.CreateServiceManagerBindings(_tenantId, CancellationToken.None).ConfigureAwait(false); + async Task Act() => await _sut.CreateServiceManagerBindings(_tenantId, CancellationToken.None).ConfigureAwait(ConfigureAwaitOptions.None); // Act var ex = await Assert.ThrowsAsync(Act); @@ -173,7 +173,7 @@ public async Task AssignEntitlements_WithNotExisting_ReturnsExpected() // Arrange A.CallTo(() => _tenantRepositories.GetSubAccountIdByTenantId(_tenantId)) .Returns((Guid?)null); - async Task Act() => await _sut.AssignEntitlements(_tenantId, CancellationToken.None).ConfigureAwait(false); + async Task Act() => await _sut.AssignEntitlements(_tenantId, CancellationToken.None).ConfigureAwait(ConfigureAwaitOptions.None); // Act var ex = await Assert.ThrowsAsync(Act); @@ -213,7 +213,7 @@ public async Task CreateServiceInstance_WithNotExisting_ReturnsExpected() // Arrange A.CallTo(() => _tenantRepositories.GetSubAccountIdByTenantId(_tenantId)) .Returns((Guid?)null); - async Task Act() => await _sut.CreateServiceInstance(_tenantId, CancellationToken.None).ConfigureAwait(false); + async Task Act() => await _sut.CreateServiceInstance(_tenantId, CancellationToken.None).ConfigureAwait(ConfigureAwaitOptions.None); // Act var ex = await Assert.ThrowsAsync(Act); @@ -266,7 +266,7 @@ public async Task CreateServiceBindings_WithNotExistingSubAccount_ReturnsExpecte // Arrange A.CallTo(() => _tenantRepositories.GetSubAccountAndServiceInstanceIdsByTenantId(_tenantId)) .Returns((null, null)); - async Task Act() => await _sut.CreateServiceBindings(_tenantId, CancellationToken.None).ConfigureAwait(false); + async Task Act() => await _sut.CreateServiceBindings(_tenantId, CancellationToken.None).ConfigureAwait(ConfigureAwaitOptions.None); // Act var ex = await Assert.ThrowsAsync(Act); @@ -281,7 +281,7 @@ public async Task CreateServiceBindings_WithNotExistingServiceInstance_ReturnsEx // Arrange A.CallTo(() => _tenantRepositories.GetSubAccountAndServiceInstanceIdsByTenantId(_tenantId)) .Returns((Guid.NewGuid(), null)); - async Task Act() => await _sut.CreateServiceBindings(_tenantId, CancellationToken.None).ConfigureAwait(false); + async Task Act() => await _sut.CreateServiceBindings(_tenantId, CancellationToken.None).ConfigureAwait(ConfigureAwaitOptions.None); // Act var ex = await Assert.ThrowsAsync(Act); @@ -337,7 +337,7 @@ public async Task SubscribeApplication_WithNotExistingSubAccount_ReturnsExpected // Arrange A.CallTo(() => _tenantRepositories.GetSubAccountAndServiceInstanceIdsByTenantId(_tenantId)) .Returns((null, null)); - async Task Act() => await _sut.SubscribeApplication(_tenantId, CancellationToken.None).ConfigureAwait(false); + async Task Act() => await _sut.SubscribeApplication(_tenantId, CancellationToken.None).ConfigureAwait(ConfigureAwaitOptions.None); // Act var ex = await Assert.ThrowsAsync(Act); @@ -352,7 +352,7 @@ public async Task SubscribeApplication_WithNotExistingServiceBindingName_Returns // Arrange A.CallTo(() => _tenantRepositories.GetSubAccountAndServiceInstanceIdsByTenantId(_tenantId)) .Returns((Guid.NewGuid(), null)); - async Task Act() => await _sut.SubscribeApplication(_tenantId, CancellationToken.None).ConfigureAwait(false); + async Task Act() => await _sut.SubscribeApplication(_tenantId, CancellationToken.None).ConfigureAwait(ConfigureAwaitOptions.None); // Act var ex = await Assert.ThrowsAsync(Act); @@ -404,7 +404,7 @@ public async Task CreateCloudFoundryEnvironment_WithNotExistingSubAccount_Return // Arrange A.CallTo(() => _tenantRepositories.GetSubAccountIdAndServiceBindingNameByTenantId(_tenantId)) .Returns((null, null)); - async Task Act() => await _sut.CreateCloudFoundryEnvironment(_tenantId, _tenantName, CancellationToken.None).ConfigureAwait(false); + async Task Act() => await _sut.CreateCloudFoundryEnvironment(_tenantId, _tenantName, CancellationToken.None).ConfigureAwait(ConfigureAwaitOptions.None); // Act var ex = await Assert.ThrowsAsync(Act); @@ -419,7 +419,7 @@ public async Task CreateCloudFoundryEnvironment_WithNotExistingServiceInstance_R // Arrange A.CallTo(() => _tenantRepositories.GetSubAccountIdAndServiceBindingNameByTenantId(_tenantId)) .Returns((Guid.NewGuid(), null)); - async Task Act() => await _sut.CreateCloudFoundryEnvironment(_tenantId, _tenantName, CancellationToken.None).ConfigureAwait(false); + async Task Act() => await _sut.CreateCloudFoundryEnvironment(_tenantId, _tenantName, CancellationToken.None).ConfigureAwait(ConfigureAwaitOptions.None); // Act var ex = await Assert.ThrowsAsync(Act); @@ -498,7 +498,7 @@ public async Task AddSpaceManagerRole_WithNotExisting_ReturnsExpected() // Arrange A.CallTo(() => _tenantRepositories.GetSpaceId(_tenantId)) .Returns((Guid?)null); - async Task Act() => await _sut.AddSpaceManagerRole(_tenantId, CancellationToken.None).ConfigureAwait(false); + async Task Act() => await _sut.AddSpaceManagerRole(_tenantId, CancellationToken.None).ConfigureAwait(ConfigureAwaitOptions.None); // Act var ex = await Assert.ThrowsAsync(Act); @@ -538,7 +538,7 @@ public async Task AddSpaceDeveloperRole_WithNotExisting_ReturnsExpected() // Arrange A.CallTo(() => _tenantRepositories.GetSpaceId(_tenantId)) .Returns((Guid?)null); - async Task Act() => await _sut.AddSpaceDeveloperRole(_tenantId, CancellationToken.None).ConfigureAwait(false); + async Task Act() => await _sut.AddSpaceDeveloperRole(_tenantId, CancellationToken.None).ConfigureAwait(ConfigureAwaitOptions.None); // Act var ex = await Assert.ThrowsAsync(Act); @@ -606,7 +606,7 @@ public async Task CreateServiceInstanceBindings_WithNotExisting_ReturnsExpected( // Arrange A.CallTo(() => _tenantRepositories.GetSpaceId(_tenantId)) .Returns((Guid?)null); - async Task Act() => await _sut.CreateServiceInstanceBindings(_tenantName, _tenantId, CancellationToken.None).ConfigureAwait(false); + async Task Act() => await _sut.CreateServiceInstanceBindings(_tenantName, _tenantId, CancellationToken.None).ConfigureAwait(ConfigureAwaitOptions.None); // Act var ex = await Assert.ThrowsAsync(Act); @@ -649,7 +649,7 @@ public async Task GetDimDetails_WithNotExisting_ReturnsExpected() // Arrange A.CallTo(() => _tenantRepositories.GetSpaceId(_tenantId)) .Returns((Guid?)null); - async Task Act() => await _sut.GetDimDetails(_tenantName, _tenantId, CancellationToken.None).ConfigureAwait(false); + async Task Act() => await _sut.GetDimDetails(_tenantName, _tenantId, CancellationToken.None).ConfigureAwait(ConfigureAwaitOptions.None); // Act var ex = await Assert.ThrowsAsync(Act); @@ -697,7 +697,7 @@ public async Task CreateApplication_WithNotExisting_ReturnsExpected() // Arrange A.CallTo(() => _tenantRepositories.GetDimInstanceIdAndHostingUrl(_tenantId)) .Returns(((Guid?)null, string.Empty, false)); - async Task Act() => await _sut.CreateApplication(_tenantName, _tenantId, CancellationToken.None).ConfigureAwait(false); + async Task Act() => await _sut.CreateApplication(_tenantName, _tenantId, CancellationToken.None).ConfigureAwait(ConfigureAwaitOptions.None); // Act var ex = await Assert.ThrowsAsync(Act); @@ -751,7 +751,7 @@ public async Task CreateCompanyIdentity_WithNotExisting_ReturnsExpected() // Arrange A.CallTo(() => _tenantRepositories.GetDimInstanceIdAndHostingUrl(_tenantId)) .Returns(((Guid?)null, string.Empty, false)); - async Task Act() => await _sut.CreateCompanyIdentity(_tenantId, CancellationToken.None).ConfigureAwait(false); + async Task Act() => await _sut.CreateCompanyIdentity(_tenantId, CancellationToken.None).ConfigureAwait(ConfigureAwaitOptions.None); // Act var ex = await Assert.ThrowsAsync(Act); @@ -809,7 +809,7 @@ public async Task AssignCompanyApplication_WithNotExisting_ReturnsExpected() // Arrange A.CallTo(() => _tenantRepositories.GetApplicationAndCompanyId(_tenantId)) .Returns(((string?)null, (Guid?)null, (Guid?)null, false)); - async Task Act() => await _sut.AssignCompanyApplication(_tenantId, CancellationToken.None).ConfigureAwait(false); + async Task Act() => await _sut.AssignCompanyApplication(_tenantId, CancellationToken.None).ConfigureAwait(ConfigureAwaitOptions.None); // Act var ex = await Assert.ThrowsAsync(Act); @@ -824,7 +824,7 @@ public async Task AssignCompanyApplication_WithNoCompanyId_ReturnsExpected() // Arrange A.CallTo(() => _tenantRepositories.GetApplicationAndCompanyId(_tenantId)) .Returns((Guid.NewGuid().ToString(), (Guid?)null, (Guid?)null, false)); - async Task Act() => await _sut.AssignCompanyApplication(_tenantId, CancellationToken.None).ConfigureAwait(false); + async Task Act() => await _sut.AssignCompanyApplication(_tenantId, CancellationToken.None).ConfigureAwait(ConfigureAwaitOptions.None); // Act var ex = await Assert.ThrowsAsync(Act); @@ -839,7 +839,7 @@ public async Task AssignCompanyApplication_WithNoDimInstanceId_ReturnsExpected() // Arrange A.CallTo(() => _tenantRepositories.GetApplicationAndCompanyId(_tenantId)) .Returns((Guid.NewGuid().ToString(), Guid.NewGuid(), null, false)); - async Task Act() => await _sut.AssignCompanyApplication(_tenantId, CancellationToken.None).ConfigureAwait(false); + async Task Act() => await _sut.AssignCompanyApplication(_tenantId, CancellationToken.None).ConfigureAwait(ConfigureAwaitOptions.None); // Act var ex = await Assert.ThrowsAsync(Act); @@ -900,7 +900,7 @@ public async Task CreateStatusList_WithNoCompanyId_ReturnsExpected() // Arrange A.CallTo(() => _tenantRepositories.GetApplicationAndCompanyId(_tenantId)) .Returns((Guid.NewGuid().ToString(), (Guid?)null, (Guid?)null, false)); - async Task Act() => await _sut.CreateStatusList(_tenantId, CancellationToken.None).ConfigureAwait(false); + async Task Act() => await _sut.CreateStatusList(_tenantId, CancellationToken.None).ConfigureAwait(ConfigureAwaitOptions.None); // Act var ex = await Assert.ThrowsAsync(Act); @@ -915,7 +915,7 @@ public async Task CreateStatusList_WithNoDimInstanceId_ReturnsExpected() // Arrange A.CallTo(() => _tenantRepositories.GetApplicationAndCompanyId(_tenantId)) .Returns((Guid.NewGuid().ToString(), Guid.NewGuid(), null, false)); - async Task Act() => await _sut.CreateStatusList(_tenantId, CancellationToken.None).ConfigureAwait(false); + async Task Act() => await _sut.CreateStatusList(_tenantId, CancellationToken.None).ConfigureAwait(ConfigureAwaitOptions.None); // Act var ex = await Assert.ThrowsAsync(Act); @@ -960,7 +960,7 @@ public async Task SendCallback_WithNotExisting_ReturnsExpected() // Arrange A.CallTo(() => _tenantRepositories.GetCallbackData(_tenantId)) .Returns(("bpn123", (string?)null, (string?)null, (Guid?)null)); - async Task Act() => await _sut.SendCallback(_tenantId, CancellationToken.None).ConfigureAwait(false); + async Task Act() => await _sut.SendCallback(_tenantId, CancellationToken.None).ConfigureAwait(ConfigureAwaitOptions.None); // Act var ex = await Assert.ThrowsAsync(Act); @@ -975,7 +975,7 @@ public async Task SendCallback_WithNoCompanyId_ReturnsExpected() // Arrange A.CallTo(() => _tenantRepositories.GetCallbackData(_tenantId)) .Returns(("bpn123", "https://example.org/did", (string?)null, (Guid?)null)); - async Task Act() => await _sut.SendCallback(_tenantId, CancellationToken.None).ConfigureAwait(false); + async Task Act() => await _sut.SendCallback(_tenantId, CancellationToken.None).ConfigureAwait(ConfigureAwaitOptions.None); // Act var ex = await Assert.ThrowsAsync(Act); @@ -990,7 +990,7 @@ public async Task SendCallback_WithNoDimInstanceId_ReturnsExpected() // Arrange A.CallTo(() => _tenantRepositories.GetCallbackData(_tenantId)) .Returns(("bpn123", "https://example.org/did", Guid.NewGuid().ToString(), (Guid?)null)); - async Task Act() => await _sut.SendCallback(_tenantId, CancellationToken.None).ConfigureAwait(false); + async Task Act() => await _sut.SendCallback(_tenantId, CancellationToken.None).ConfigureAwait(ConfigureAwaitOptions.None); // Act var ex = await Assert.ThrowsAsync(Act); diff --git a/tests/processes/Processes.Worker.Library.Tests/ProcessExecutionServiceTests.cs b/tests/processes/Processes.Worker.Library.Tests/ProcessExecutionServiceTests.cs index 62b0bb0..d731e8e 100644 --- a/tests/processes/Processes.Worker.Library.Tests/ProcessExecutionServiceTests.cs +++ b/tests/processes/Processes.Worker.Library.Tests/ProcessExecutionServiceTests.cs @@ -27,7 +27,6 @@ using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using Org.Eclipse.TractusX.Portal.Backend.Framework.DateTimeProvider; -using Org.Eclipse.TractusX.Portal.Backend.Processes.Worker.Library; using System.Collections.Immutable; namespace Processes.Worker.Library.Tests; diff --git a/tests/processes/Processes.Worker.Library.Tests/ProcessExecutorTests.cs b/tests/processes/Processes.Worker.Library.Tests/ProcessExecutorTests.cs index 222fcf9..48ebdd9 100644 --- a/tests/processes/Processes.Worker.Library.Tests/ProcessExecutorTests.cs +++ b/tests/processes/Processes.Worker.Library.Tests/ProcessExecutorTests.cs @@ -24,7 +24,6 @@ using Dim.Entities.Enums; using Microsoft.Extensions.Logging; using Org.Eclipse.TractusX.Portal.Backend.Framework.ErrorHandling; -using Org.Eclipse.TractusX.Portal.Backend.Processes.Worker.Library; using System.Collections.Immutable; using ProcessTypeId = Dim.Entities.Enums.ProcessTypeId;