Skip to content

Commit

Permalink
fix(sd-trigger): adjust retrigger process for sd creation
Browse files Browse the repository at this point in the history
Refs: #813
  • Loading branch information
Phil91 committed Aug 29, 2024
1 parent 20e0b7e commit 63949f9
Show file tree
Hide file tree
Showing 39 changed files with 10,569 additions and 394 deletions.
8 changes: 7 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,11 @@
"${commentprefix#} ${cx_header_with_#}",
"${commentend#}"
]
}
},
"cSpell.enableFiletypes": [
"dockercompose",
"dotenv",
"editorconfig"
],
"dotnet-test-explorer.testProjectPath": "tests/**/*csproj"
}
56 changes: 28 additions & 28 deletions src/Portal.Backend.sln
Original file line number Diff line number Diff line change
Expand Up @@ -282,9 +282,9 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IdentityProviderProvisionin
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UserProvisioning.Executor.Tests", "..\tests\processes\UserProvisioning.Executor.Tests\UserProvisioning.Executor.Tests.csproj", "{0CBCC851-99A1-4005-9BBA-E6A20A0AEDAA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SelfDescriptionCreation.Executor", "processes\SelfDescriptionCreation.Executor\SelfDescriptionCreation.Executor.csproj", "{08535520-F6E6-4DAF-AB36-12C48437368A}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SelfDescriptionCreation.Executor", "processes\SelfDescriptionCreation.Executor\SelfDescriptionCreation.Executor.csproj", "{D8EBE555-F103-4D05-9697-5381E4DE1DFE}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SelfDescriptionCreation.Executor.Tests", "..\tests\processes\SelfDescriptionCreation.Executor.Tests\SelfDescriptionCreation.Executor.Tests.csproj", "{E87898BA-59A4-4F02-9594-50756BBF4E22}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SelfDescriptionCreation.Executor.Tests", "..\tests\processes\SelfDescriptionCreation.Executor.Tests\SelfDescriptionCreation.Executor.Tests.csproj", "{AA14B842-6A65-40BB-818A-D450F66F4101}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -1798,30 +1798,30 @@ Global
{0CBCC851-99A1-4005-9BBA-E6A20A0AEDAA}.Release|x64.Build.0 = Release|Any CPU
{0CBCC851-99A1-4005-9BBA-E6A20A0AEDAA}.Release|x86.ActiveCfg = Release|Any CPU
{0CBCC851-99A1-4005-9BBA-E6A20A0AEDAA}.Release|x86.Build.0 = Release|Any CPU
{08535520-F6E6-4DAF-AB36-12C48437368A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{08535520-F6E6-4DAF-AB36-12C48437368A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{08535520-F6E6-4DAF-AB36-12C48437368A}.Debug|x64.ActiveCfg = Debug|Any CPU
{08535520-F6E6-4DAF-AB36-12C48437368A}.Debug|x64.Build.0 = Debug|Any CPU
{08535520-F6E6-4DAF-AB36-12C48437368A}.Debug|x86.ActiveCfg = Debug|Any CPU
{08535520-F6E6-4DAF-AB36-12C48437368A}.Debug|x86.Build.0 = Debug|Any CPU
{08535520-F6E6-4DAF-AB36-12C48437368A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{08535520-F6E6-4DAF-AB36-12C48437368A}.Release|Any CPU.Build.0 = Release|Any CPU
{08535520-F6E6-4DAF-AB36-12C48437368A}.Release|x64.ActiveCfg = Release|Any CPU
{08535520-F6E6-4DAF-AB36-12C48437368A}.Release|x64.Build.0 = Release|Any CPU
{08535520-F6E6-4DAF-AB36-12C48437368A}.Release|x86.ActiveCfg = Release|Any CPU
{08535520-F6E6-4DAF-AB36-12C48437368A}.Release|x86.Build.0 = Release|Any CPU
{E87898BA-59A4-4F02-9594-50756BBF4E22}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E87898BA-59A4-4F02-9594-50756BBF4E22}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E87898BA-59A4-4F02-9594-50756BBF4E22}.Debug|x64.ActiveCfg = Debug|Any CPU
{E87898BA-59A4-4F02-9594-50756BBF4E22}.Debug|x64.Build.0 = Debug|Any CPU
{E87898BA-59A4-4F02-9594-50756BBF4E22}.Debug|x86.ActiveCfg = Debug|Any CPU
{E87898BA-59A4-4F02-9594-50756BBF4E22}.Debug|x86.Build.0 = Debug|Any CPU
{E87898BA-59A4-4F02-9594-50756BBF4E22}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E87898BA-59A4-4F02-9594-50756BBF4E22}.Release|Any CPU.Build.0 = Release|Any CPU
{E87898BA-59A4-4F02-9594-50756BBF4E22}.Release|x64.ActiveCfg = Release|Any CPU
{E87898BA-59A4-4F02-9594-50756BBF4E22}.Release|x64.Build.0 = Release|Any CPU
{E87898BA-59A4-4F02-9594-50756BBF4E22}.Release|x86.ActiveCfg = Release|Any CPU
{E87898BA-59A4-4F02-9594-50756BBF4E22}.Release|x86.Build.0 = Release|Any CPU
{D8EBE555-F103-4D05-9697-5381E4DE1DFE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D8EBE555-F103-4D05-9697-5381E4DE1DFE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D8EBE555-F103-4D05-9697-5381E4DE1DFE}.Debug|x64.ActiveCfg = Debug|Any CPU
{D8EBE555-F103-4D05-9697-5381E4DE1DFE}.Debug|x64.Build.0 = Debug|Any CPU
{D8EBE555-F103-4D05-9697-5381E4DE1DFE}.Debug|x86.ActiveCfg = Debug|Any CPU
{D8EBE555-F103-4D05-9697-5381E4DE1DFE}.Debug|x86.Build.0 = Debug|Any CPU
{D8EBE555-F103-4D05-9697-5381E4DE1DFE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D8EBE555-F103-4D05-9697-5381E4DE1DFE}.Release|Any CPU.Build.0 = Release|Any CPU
{D8EBE555-F103-4D05-9697-5381E4DE1DFE}.Release|x64.ActiveCfg = Release|Any CPU
{D8EBE555-F103-4D05-9697-5381E4DE1DFE}.Release|x64.Build.0 = Release|Any CPU
{D8EBE555-F103-4D05-9697-5381E4DE1DFE}.Release|x86.ActiveCfg = Release|Any CPU
{D8EBE555-F103-4D05-9697-5381E4DE1DFE}.Release|x86.Build.0 = Release|Any CPU
{AA14B842-6A65-40BB-818A-D450F66F4101}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AA14B842-6A65-40BB-818A-D450F66F4101}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AA14B842-6A65-40BB-818A-D450F66F4101}.Debug|x64.ActiveCfg = Debug|Any CPU
{AA14B842-6A65-40BB-818A-D450F66F4101}.Debug|x64.Build.0 = Debug|Any CPU
{AA14B842-6A65-40BB-818A-D450F66F4101}.Debug|x86.ActiveCfg = Debug|Any CPU
{AA14B842-6A65-40BB-818A-D450F66F4101}.Debug|x86.Build.0 = Debug|Any CPU
{AA14B842-6A65-40BB-818A-D450F66F4101}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AA14B842-6A65-40BB-818A-D450F66F4101}.Release|Any CPU.Build.0 = Release|Any CPU
{AA14B842-6A65-40BB-818A-D450F66F4101}.Release|x64.ActiveCfg = Release|Any CPU
{AA14B842-6A65-40BB-818A-D450F66F4101}.Release|x64.Build.0 = Release|Any CPU
{AA14B842-6A65-40BB-818A-D450F66F4101}.Release|x86.ActiveCfg = Release|Any CPU
{AA14B842-6A65-40BB-818A-D450F66F4101}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -1956,7 +1956,7 @@ Global
{143433B2-2792-4C5F-A3C2-E5C91D68E30D} = {323C198D-A8C6-4EB0-8B79-72624275E35F}
{9636BEC8-6929-4852-8DC8-8B41609630A3} = {282CEF03-292F-4A49-83C6-997567D0FF5F}
{E5494227-BDFE-41F2-A12F-54292D76C29F} = {282CEF03-292F-4A49-83C6-997567D0FF5F}
{08535520-F6E6-4DAF-AB36-12C48437368A} = {282CEF03-292F-4A49-83C6-997567D0FF5F}
{E87898BA-59A4-4F02-9594-50756BBF4E22} = {323C198D-A8C6-4EB0-8B79-72624275E35F}
{D8EBE555-F103-4D05-9697-5381E4DE1DFE} = {282CEF03-292F-4A49-83C6-997567D0FF5F}
{AA14B842-6A65-40BB-818A-D450F66F4101} = {323C198D-A8C6-4EB0-8B79-72624275E35F}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@
using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.DBAccess.Repositories;
using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.PortalEntities.Enums;
using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.PortalEntities.Identities;
using Org.Eclipse.TractusX.Portal.Backend.Processes.Library;
using Org.Eclipse.TractusX.Portal.Backend.Processes.Mailing.Library;
using System.Collections.Immutable;
using System.Globalization;
using System.Text.Json;
using System.Text.RegularExpressions;

namespace Org.Eclipse.TractusX.Portal.Backend.Administration.Service.BusinessLogic;
Expand Down Expand Up @@ -359,13 +364,6 @@ public async Task<DimUrlsResponse> GetDimServiceUrls()
);
}

public Task<Pagination.Response<CompanyMissingSdDocumentData>> GetCompaniesWithMissingSdDocument(int page, int size) =>
Pagination.CreateResponseAsync(
page,
size,
_settings.MaxPageSize,
portalRepositories.GetInstance<ICompanyRepository>().GetCompaniesWithMissingSdDocument());

/// <inheritdoc />
public async Task<int> DeleteCompanyCertificateAsync(Guid documentId)
{
Expand Down Expand Up @@ -432,6 +430,7 @@ public async Task<int> DeleteCompanyCertificateAsync(Guid documentId)
{
throw new NotFoundException($"Company certificate document {documentId} does not exist");
}

if (!documentDetails.IsStatusLocked)
{
throw new ForbiddenException($"Document {documentId} status is not locked");
Expand All @@ -440,17 +439,42 @@ public async Task<int> DeleteCompanyCertificateAsync(Guid documentId)
return (documentDetails.FileName, documentDetails.Content, documentDetails.MediaTypeId.MapToMediaType());
}

public Task<Pagination.Response<CompanyMissingSdDocumentData>> GetCompaniesWithMissingSdDocument(int page, int size) =>
Pagination.CreateResponseAsync(
page,
size,
_settings.MaxPageSize,
portalRepositories.GetInstance<ICompanyRepository>().GetCompaniesWithMissingSdDocument());

public async Task TriggerSelfDescriptionCreation()
{
var hasMissingSdDocumentCompanies = await portalRepositories.GetInstance<ICompanyRepository>().HasAnyCompaniesWithMissingSelfDescription().ConfigureAwait(ConfigureAwaitOptions.None);
if (hasMissingSdDocumentCompanies)
var companiesWithMissingSd = portalRepositories.GetInstance<ICompanyRepository>().GetCompanyIdsWithMissingSelfDescription();
var processStepRepository = portalRepositories.GetInstance<IProcessStepRepository>();
var companyRepository = portalRepositories.GetInstance<ICompanyRepository>();
await foreach (var companyId in companiesWithMissingSd)
{
var processStepRepository = portalRepositories.GetInstance<IProcessStepRepository>();
var processId = processStepRepository.CreateProcess(ProcessTypeId.SELF_DESCRIPTION_CREATION).Id;

processStepRepository.CreateProcessStep(ProcessStepTypeId.SELF_DESCRIPTION_COMPANY_CREATION, ProcessStepStatusId.TODO, processId);
companyRepository.AttachAndModifyCompany(companyId, c => c.SdCreationProcessId = null, c => c.SdCreationProcessId = processId);
}

await portalRepositories.SaveAsync().ConfigureAwait(ConfigureAwaitOptions.None);
}

await portalRepositories.SaveAsync().ConfigureAwait(ConfigureAwaitOptions.None);
public async Task RetriggerSelfDescriptionCreation(Guid processId)
{
const ProcessStepTypeId NextStep = ProcessStepTypeId.SELF_DESCRIPTION_COMPANY_CREATION;
const ProcessStepTypeId StepToTrigger = ProcessStepTypeId.RETRIGGER_SELF_DESCRIPTION_COMPANY_CREATION;
var (validProcessId, processData) = await portalRepositories.GetInstance<IProcessStepRepository>().IsValidProcess(processId, ProcessTypeId.SELF_DESCRIPTION_CREATION, Enumerable.Repeat(StepToTrigger, 1)).ConfigureAwait(ConfigureAwaitOptions.None);
if (!validProcessId)
{
throw new NotFoundException($"process {processId} does not exist");
}

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

context.ScheduleProcessSteps(Enumerable.Repeat(NextStep, 1));
context.FinalizeProcessStep();
await portalRepositories.SaveAsync().ConfigureAwait(ConfigureAwaitOptions.None);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.DBAccess.Repositories;
using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.PortalEntities.Enums;
using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.PortalEntities.Identities;
using Org.Eclipse.TractusX.Portal.Backend.Processes.Library;
using Org.Eclipse.TractusX.Portal.Backend.SdFactory.Library.BusinessLogic;
using Org.Eclipse.TractusX.Portal.Backend.SdFactory.Library.Models;
using System.Text.RegularExpressions;
Expand Down Expand Up @@ -346,7 +347,7 @@ public IAsyncEnumerable<ConnectorEndPointData> GetCompanyConnectorEndPointAsync(
/// <inheritdoc />
public async Task ProcessClearinghouseSelfDescription(SelfDescriptionResponseData data, CancellationToken cancellationToken)
{
logger.LogInformation("Process SelfDescription called with the following data {Data}", data.ToString().Replace(Environment.NewLine, string.Empty));
logger.LogInformation("Process SelfDescription called with the following data {@Data}", data.ToString().Replace(Environment.NewLine, string.Empty));

var result = await portalRepositories.GetInstance<IConnectorsRepository>()
.GetConnectorDataById(data.ExternalId)
Expand Down Expand Up @@ -433,14 +434,33 @@ public IAsyncEnumerable<OfferSubscriptionConnectorData> GetConnectorOfferSubscri

public async Task TriggerSelfDescriptionCreation()
{
var hasMissingSdDocumentConnectors = await portalRepositories.GetInstance<IConnectorsRepository>().HasAnyConnectorsWithMissingSelfDescription().ConfigureAwait(ConfigureAwaitOptions.None);
if (hasMissingSdDocumentConnectors)
var connectorRepository = portalRepositories.GetInstance<IConnectorsRepository>();
var processStepRepository = portalRepositories.GetInstance<IProcessStepRepository>();
var connectorIds = connectorRepository.GetConnectorIdsWithMissingSelfDescription();
await foreach (var connectorId in connectorIds)
{
var processStepRepository = portalRepositories.GetInstance<IProcessStepRepository>();
var processId = processStepRepository.CreateProcess(ProcessTypeId.SELF_DESCRIPTION_CREATION).Id;
processStepRepository.CreateProcessStep(ProcessStepTypeId.SELF_DESCRIPTION_CONNECTOR_CREATION, ProcessStepStatusId.TODO, processId);
connectorRepository.AttachAndModifyConnector(connectorId, c => c.SdCreationProcessId = null, c => c.SdCreationProcessId = processId);
}

await portalRepositories.SaveAsync().ConfigureAwait(ConfigureAwaitOptions.None);
await portalRepositories.SaveAsync().ConfigureAwait(ConfigureAwaitOptions.None);
}

public async Task RetriggerSelfDescriptionCreation(Guid processId)
{
const ProcessStepTypeId NextStep = ProcessStepTypeId.SELF_DESCRIPTION_CONNECTOR_CREATION;
const ProcessStepTypeId StepToTrigger = ProcessStepTypeId.RETRIGGER_SELF_DESCRIPTION_CONNECTOR_CREATION;
var (validProcessId, processData) = await portalRepositories.GetInstance<IProcessStepRepository>().IsValidProcess(processId, ProcessTypeId.SELF_DESCRIPTION_CREATION, Enumerable.Repeat(StepToTrigger, 1)).ConfigureAwait(ConfigureAwaitOptions.None);
if (!validProcessId)
{
throw new NotFoundException($"process {processId} does not exist");
}

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

context.ScheduleProcessSteps(Enumerable.Repeat(NextStep, 1));
context.FinalizeProcessStep();
await portalRepositories.SaveAsync().ConfigureAwait(ConfigureAwaitOptions.None);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/********************************************************************************
* Copyright (c) 2022 BMW Group AG
* Copyright (c) 2022 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
Expand Down Expand Up @@ -53,5 +52,6 @@ public interface ICompanyDataBusinessLogic
Task<Pagination.Response<CompanyCertificateData>> GetAllCompanyCertificatesAsync(int page, int size, CertificateSorting? sorting, CompanyCertificateStatusId? certificateStatus, CompanyCertificateTypeId? certificateType);
Task<DimUrlsResponse> GetDimServiceUrls();
Task<Pagination.Response<CompanyMissingSdDocumentData>> GetCompaniesWithMissingSdDocument(int page, int size);
Task RetriggerSelfDescriptionCreation(Guid processId);
Task TriggerSelfDescriptionCreation();
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/********************************************************************************
* Copyright (c) 2022 BMW Group AG
* Copyright (c) 2022 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
Expand Down Expand Up @@ -102,6 +101,6 @@ public interface IConnectorsBusinessLogic
IAsyncEnumerable<OfferSubscriptionConnectorData> GetConnectorOfferSubscriptionData(bool? connectorIdSet);

Task<Pagination.Response<ConnectorMissingSdDocumentData>> GetConnectorsWithMissingSdDocument(int page, int size);

Task TriggerSelfDescriptionCreation();
Task RetriggerSelfDescriptionCreation(Guid processId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -365,4 +365,24 @@ public async Task<NoContentResult> TriggerSelfDescriptionProcess()
await logic.TriggerSelfDescriptionCreation().ConfigureAwait(false);
return NoContent();
}

/// <summary>
/// Retriggers the process to create the missing self description documents
/// </summary>
/// <returns>NoContent</returns>
/// Example: POST: /api/administration/companyData/trigger-self-description/{processId}
/// <response code="204">Empty response on success.</response>
/// <response code="404">No Process found for the processId</response>
[HttpPost]
[Authorize(Roles = "approve_new_partner")]
[Authorize(Policy = PolicyTypes.CompanyUser)]
[Route("retrigger-self-description")]
[ProducesResponseType(StatusCodes.Status204NoContent)]
[ProducesResponseType(typeof(ErrorResponse), StatusCodes.Status400BadRequest)]
[ProducesResponseType(typeof(ErrorResponse), StatusCodes.Status404NotFound)]
public async Task<NoContentResult> RetriggerSelfDescriptionProcess([FromRoute] Guid processId)
{
await logic.RetriggerSelfDescriptionCreation(processId).ConfigureAwait(false);
return NoContent();
}
}
Loading

0 comments on commit 63949f9

Please sign in to comment.