Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(sd): add process steps for sd creation #1189

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions docs/api/administration-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,37 @@ paths:
description: Internal Server Error
'401':
description: The User is unauthorized
/api/administration/companydata/retrigger-self-description-response:
post:
tags:
- CompanyData
summary: 'Retriggers the process to create the missing self description documents (Authorization required - Roles: approve_new_partner)'
parameters:
- name: processId
in: path
required: true
schema:
type: string
format: uuid
responses:
'204':
description: Empty response on success.
'400':
description: Bad Request
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'404':
description: No Process found for the processId
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'500':
description: Internal Server Error
'401':
description: The User is unauthorized
/api/administration/Connectors:
get:
tags:
Expand Down Expand Up @@ -1178,6 +1209,37 @@ paths:
description: Internal Server Error
'401':
description: The User is unauthorized
/api/administration/Connectors/retrigger-self-description-response:
post:
tags:
- Connectors
summary: 'Retriggers the process to create the missing self description response documents (Authorization required - Roles: approve_new_partner)'
parameters:
- name: processId
in: path
required: true
schema:
type: string
format: uuid
responses:
'204':
description: Empty response on success.
'400':
description: Bad Request
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'404':
description: No Process found for the processId
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'500':
description: Internal Server Error
'401':
description: The User is unauthorized
'/api/administration/Documents/{documentId}':
get:
tags:
Expand Down Expand Up @@ -7596,6 +7658,10 @@ components:
- SELF_DESCRIPTION_COMPANY_CREATION
- RETRIGGER_SELF_DESCRIPTION_CONNECTOR_CREATION
- RETRIGGER_SELF_DESCRIPTION_COMPANY_CREATION
- AWAIT_SELF_DESCRIPTION_CONNECTOR_RESPONSE
- AWAIT_SELF_DESCRIPTION_COMPANY_RESPONSE
- RETRIGGER_AWAIT_SELF_DESCRIPTION_CONNECTOR_RESPONSE
- RETRIGGER_AWAIT_SELF_DESCRIPTION_COMPANY_RESPONSE
type: string
ProviderDetailData:
type: object
Expand Down
4 changes: 4 additions & 0 deletions docs/api/apps-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3631,6 +3631,10 @@ components:
- SELF_DESCRIPTION_COMPANY_CREATION
- RETRIGGER_SELF_DESCRIPTION_CONNECTOR_CREATION
- RETRIGGER_SELF_DESCRIPTION_COMPANY_CREATION
- AWAIT_SELF_DESCRIPTION_CONNECTOR_RESPONSE
- AWAIT_SELF_DESCRIPTION_COMPANY_RESPONSE
- RETRIGGER_AWAIT_SELF_DESCRIPTION_CONNECTOR_RESPONSE
- RETRIGGER_AWAIT_SELF_DESCRIPTION_COMPANY_RESPONSE
type: string
SubscriberSubscriptionDetailData:
type: object
Expand Down
4 changes: 4 additions & 0 deletions docs/api/services-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2210,6 +2210,10 @@ components:
- SELF_DESCRIPTION_COMPANY_CREATION
- RETRIGGER_SELF_DESCRIPTION_CONNECTOR_CREATION
- RETRIGGER_SELF_DESCRIPTION_COMPANY_CREATION
- AWAIT_SELF_DESCRIPTION_CONNECTOR_RESPONSE
- AWAIT_SELF_DESCRIPTION_COMPANY_RESPONSE
- RETRIGGER_AWAIT_SELF_DESCRIPTION_CONNECTOR_RESPONSE
- RETRIGGER_AWAIT_SELF_DESCRIPTION_COMPANY_RESPONSE
type: string
ProviderSubscriptionDetailData:
type: object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -472,4 +472,21 @@ public async Task RetriggerSelfDescriptionCreation(Guid processId)
context.FinalizeProcessStep();
await portalRepositories.SaveAsync().ConfigureAwait(ConfigureAwaitOptions.None);
}

public async Task RetriggerSelfDescriptionResponseCreation(Guid processId)
{
const ProcessStepTypeId NextStep = ProcessStepTypeId.SELF_DESCRIPTION_COMPANY_CREATION;
const ProcessStepTypeId StepToTrigger = ProcessStepTypeId.RETRIGGER_AWAIT_SELF_DESCRIPTION_COMPANY_RESPONSE;
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 @@ -499,4 +499,21 @@ public async Task RetriggerSelfDescriptionCreation(Guid processId)
context.FinalizeProcessStep();
await portalRepositories.SaveAsync().ConfigureAwait(ConfigureAwaitOptions.None);
}

public async Task RetriggerSelfDescriptionResponseCreation(Guid processId)
{
const ProcessStepTypeId NextStep = ProcessStepTypeId.SELF_DESCRIPTION_CONNECTOR_CREATION;
const ProcessStepTypeId StepToTrigger = ProcessStepTypeId.RETRIGGER_AWAIT_SELF_DESCRIPTION_CONNECTOR_RESPONSE;
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 @@ -53,5 +53,6 @@ public interface ICompanyDataBusinessLogic
Task<DimUrlsResponse> GetDimServiceUrls();
Task<Pagination.Response<CompanyMissingSdDocumentData>> GetCompaniesWithMissingSdDocument(int page, int size);
Task RetriggerSelfDescriptionCreation(Guid processId);
Task RetriggerSelfDescriptionResponseCreation(Guid processId);
Task TriggerSelfDescriptionCreation();
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,5 @@ public interface IConnectorsBusinessLogic
Task<Pagination.Response<ConnectorMissingSdDocumentData>> GetConnectorsWithMissingSdDocument(int page, int size);
Task TriggerSelfDescriptionCreation();
Task RetriggerSelfDescriptionCreation(Guid processId);
Task RetriggerSelfDescriptionResponseCreation(Guid processId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -385,4 +385,24 @@ public async Task<NoContentResult> RetriggerSelfDescriptionProcess([FromRoute] G
await logic.RetriggerSelfDescriptionCreation(processId).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-response/{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-response")]
[ProducesResponseType(StatusCodes.Status204NoContent)]
[ProducesResponseType(typeof(ErrorResponse), StatusCodes.Status400BadRequest)]
[ProducesResponseType(typeof(ErrorResponse), StatusCodes.Status404NotFound)]
public async Task<NoContentResult> RetriggerSelfDescriptionResponseProcess([FromRoute] Guid processId)
{
await logic.RetriggerSelfDescriptionResponseCreation(processId).ConfigureAwait(false);
return NoContent();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -307,4 +307,24 @@ public async Task<NoContentResult> RetriggerSelfDescriptionProcess([FromRoute] G
await logic.RetriggerSelfDescriptionCreation(processId).ConfigureAwait(false);
return NoContent();
}

/// <summary>
/// Retriggers the process to create the missing self description response documents
/// </summary>
/// <returns>NoContent</returns>
/// Example: POST: /api/administration/connectors/retrigger-self-description-response/{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-response")]
[ProducesResponseType(StatusCodes.Status204NoContent)]
[ProducesResponseType(typeof(ErrorResponse), StatusCodes.Status400BadRequest)]
[ProducesResponseType(typeof(ErrorResponse), StatusCodes.Status404NotFound)]
public async Task<NoContentResult> RetriggerSelfDescriptionResponseProcess([FromRoute] Guid processId)
{
await logic.RetriggerSelfDescriptionResponseCreation(processId).ConfigureAwait(false);
return NoContent();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@
using Microsoft.Extensions.Options;
using Org.Eclipse.TractusX.Portal.Backend.Framework.ErrorHandling;
using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.DBAccess;
using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.DBAccess.Models;
using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.DBAccess.Repositories;
using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.PortalEntities.Enums;
using Org.Eclipse.TractusX.Portal.Backend.Processes.ApplicationChecklist.Library;
using Org.Eclipse.TractusX.Portal.Backend.Processes.Library;
using Org.Eclipse.TractusX.Portal.Backend.SdFactory.Library.Models;
using System.Security.Cryptography;
using System.Text.Json;
Expand Down Expand Up @@ -139,10 +141,12 @@ public async Task ProcessFinishSelfDescriptionLpForApplication(SelfDescriptionRe
/// <inheritdoc />
public async Task ProcessFinishSelfDescriptionLpForConnector(SelfDescriptionResponseData data, CancellationToken cancellationToken)
{
if (ValidateConfirmationData(data))
var connectorsRepository = portalRepositories.GetInstance<IConnectorsRepository>();
var result = ValidateConfirmationData(data);
if (result)
{
var documentId = await ProcessAndCreateDocument(SdFactoryResponseModelTitle.Connector, data, cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None);
portalRepositories.GetInstance<IConnectorsRepository>().AttachAndModifyConnector(data.ExternalId, null, con =>
connectorsRepository.AttachAndModifyConnector(data.ExternalId, null, con =>
{
con.SelfDescriptionDocumentId = documentId;
con.StatusId = ConnectorStatusId.ACTIVE;
Expand All @@ -151,21 +155,47 @@ public async Task ProcessFinishSelfDescriptionLpForConnector(SelfDescriptionResp
}
else
{
portalRepositories.GetInstance<IConnectorsRepository>().AttachAndModifyConnector(data.ExternalId, null, con =>
connectorsRepository.AttachAndModifyConnector(data.ExternalId, null, con =>
{
con.SelfDescriptionMessage = data.Message!;
con.DateLastChanged = DateTimeOffset.UtcNow;
});
}

var processData = await connectorsRepository.GetProcessDataForConnectorId(data.ExternalId);
if (processData == null)
{
HandleSdCreationProcess(processData!, data, ProcessStepTypeId.AWAIT_SELF_DESCRIPTION_CONNECTOR_RESPONSE, ProcessStepTypeId.RETRIGGER_AWAIT_SELF_DESCRIPTION_CONNECTOR_RESPONSE);
}
}

private void HandleSdCreationProcess(VerifyProcessData processData, SelfDescriptionResponseData data, ProcessStepTypeId processStepTypeId, ProcessStepTypeId retriggerProcessStepTypeId)
{
var context = processData.CreateManualProcessData(processStepTypeId, portalRepositories, () => $"externalId {data.ExternalId}");
if (data.Status == SelfDescriptionStatus.Confirm)
{
context.FinalizeProcessStep();
}
else
{
context.ScheduleProcessSteps(new[] { retriggerProcessStepTypeId });
context.FailProcessStep(data.Message!);
}
}

public async Task ProcessFinishSelfDescriptionLpForCompany(SelfDescriptionResponseData data, CancellationToken cancellationToken)
{
var companyRepository = portalRepositories.GetInstance<ICompanyRepository>();
if (data.Status == SelfDescriptionStatus.Confirm)
{
var documentId = await ProcessAndCreateDocument(SdFactoryResponseModelTitle.LegalPerson, data, cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None);
portalRepositories.GetInstance<ICompanyRepository>().AttachAndModifyCompany(data.ExternalId, null,
c => { c.SelfDescriptionDocumentId = documentId; });
companyRepository.AttachAndModifyCompany(data.ExternalId, null, c => { c.SelfDescriptionDocumentId = documentId; });
}

var processData = await companyRepository.GetProcessDataForCompanyIdId(data.ExternalId);
if (processData == null)
{
HandleSdCreationProcess(processData!, data, ProcessStepTypeId.AWAIT_SELF_DESCRIPTION_COMPANY_RESPONSE, ProcessStepTypeId.RETRIGGER_AWAIT_SELF_DESCRIPTION_COMPANY_RESPONSE);
}
}

Expand All @@ -175,7 +205,7 @@ private static bool ValidateConfirmationData(SelfDescriptionResponseData data)
switch (confirm)
{
case false when string.IsNullOrEmpty(data.Message):
throw new ConflictException("Please provide a messsage");
throw new ConflictException("Please provide a message");
case true when data.Content == null:
throw new ConflictException("Please provide a selfDescriptionDocument");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
<ProjectReference Include="..\..\framework\Framework.Token\Framework.Token.csproj" />
<ProjectReference Include="..\..\portalbackend\PortalBackend.DBAccess\PortalBackend.DBAccess.csproj" />
<ProjectReference Include="..\..\processes\ApplicationChecklist.Library\ApplicationChecklist.Library.csproj" />
<ProjectReference Include="..\..\processes\Processes.Library\Processes.Library.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -458,4 +458,12 @@ public Task<bool> IsExistingCompany(Guid companyId) =>
.Where(x => x.BusinessPartnerNumber == bpn)
.Select(x => new ValueTuple<bool, Guid, IEnumerable<Guid>>(true, x.Id, x.CompanyApplications.Where(a => a.ApplicationStatusId == CompanyApplicationStatusId.SUBMITTED).Select(a => a.Id)))
.SingleOrDefaultAsync();

public Task<VerifyProcessData?> GetProcessDataForCompanyIdId(Guid companyId) =>
context.Companies
.Where(c => c.Id == companyId && c.SdCreationProcessId != null && c.SdCreationProcess!.ProcessTypeId == ProcessTypeId.SELF_DESCRIPTION_CREATION)
.Select(c => new VerifyProcessData(
c.SdCreationProcess,
c.SdCreationProcess!.ProcessSteps.Where(step => step.ProcessStepStatusId == ProcessStepStatusId.TODO)))
.SingleOrDefaultAsync();
}
Original file line number Diff line number Diff line change
Expand Up @@ -239,4 +239,12 @@ public Task<bool> CheckConnectorExists(string name, string connectorUrl) =>
dbContext.Connectors.AnyAsync(x =>
x.Name == name &&
x.ConnectorUrl == connectorUrl);

public Task<VerifyProcessData?> GetProcessDataForConnectorId(Guid connectorId) =>
dbContext.Connectors
.Where(c => c.Id == connectorId && c.SdCreationProcessId != null && c.SdCreationProcess!.ProcessTypeId == ProcessTypeId.SELF_DESCRIPTION_CREATION)
.Select(c => new VerifyProcessData(
c.SdCreationProcess,
c.SdCreationProcess!.ProcessSteps.Where(step => step.ProcessStepStatusId == ProcessStepStatusId.TODO)))
.SingleOrDefaultAsync();
}
Original file line number Diff line number Diff line change
Expand Up @@ -183,4 +183,5 @@ public interface ICompanyRepository
Task<(Guid Id, IEnumerable<(UniqueIdentifierId Id, string Value)> UniqueIdentifiers, string? BusinessPartnerNumber, string CountryCode)> GetCompanyByProcessId(Guid processId);
Task<bool> IsExistingCompany(Guid companyId);
Task<(bool Exists, Guid CompanyId, IEnumerable<Guid> SubmittedCompanyApplicationId)> GetCompanyIdByBpn(string bpn);
Task<VerifyProcessData?> GetProcessDataForCompanyIdId(Guid companyId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,5 @@ public interface IConnectorsRepository
IAsyncEnumerable<Guid> GetConnectorIdsWithMissingSelfDescription();
Task<(Guid Id, string? BusinessPartnerNumber, Guid SelfDescriptionDocumentId)> GetConnectorForProcessId(Guid processId);
Task<bool> CheckConnectorExists(string name, string connectorUrl);
Task<VerifyProcessData?> GetProcessDataForConnectorId(Guid connectorId);
}
Loading
Loading