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

Merged
merged 8 commits into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from 7 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 @@ -7646,6 +7708,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 @@ -3700,6 +3700,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 @@ -2271,6 +2271,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 @@ -458,17 +458,21 @@ public async Task TriggerSelfDescriptionCreation()
await portalRepositories.SaveAsync().ConfigureAwait(ConfigureAwaitOptions.None);
}

public async Task RetriggerSelfDescriptionCreation(Guid processId)
public Task RetriggerSelfDescriptionCreation(Guid processId) => RetriggerSelfDescriptionCompanyCreation(processId, ProcessStepTypeId.RETRIGGER_SELF_DESCRIPTION_COMPANY_CREATION);

public Task RetriggerSelfDescriptionResponseCreation(Guid processId) => RetriggerSelfDescriptionCompanyCreation(processId, ProcessStepTypeId.RETRIGGER_AWAIT_SELF_DESCRIPTION_COMPANY_RESPONSE);

private async Task RetriggerSelfDescriptionCompanyCreation(Guid processId, ProcessStepTypeId stepToTrigger)
{
const ProcessStepTypeId NextStep = ProcessStepTypeId.SELF_DESCRIPTION_COMPANY_CREATION;
const ProcessStepTypeId StepToTrigger = ProcessStepTypeId.RETRIGGER_SELF_DESCRIPTION_COMPANY_CREATION;
var (validProcessId, processData) = await portalRepositories.GetInstance<IPortalProcessStepRepository>().IsValidProcess(processId, ProcessTypeId.SELF_DESCRIPTION_CREATION, Enumerable.Repeat(StepToTrigger, 1)).ConfigureAwait(ConfigureAwaitOptions.None);

var (validProcessId, processData) = await portalRepositories.GetInstance<IPortalProcessStepRepository>().IsValidProcess(processId, ProcessTypeId.SELF_DESCRIPTION_CREATION, Enumerable.Repeat(stepToTrigger, 1)).ConfigureAwait(ConfigureAwaitOptions.None);
if (!validProcessId)
{
throw NotFoundException.Create(AdministrationCompanyDataErrors.COMPANY_DATA_NOT_PROCESSID_NOT_EXIST, new ErrorParameter[] { new(nameof(processId), processId.ToString()) });
}

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

context.ScheduleProcessSteps(Enumerable.Repeat(NextStep, 1));
context.FinalizeProcessStep();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -491,17 +491,20 @@ public async Task TriggerSelfDescriptionCreation()
await portalRepositories.SaveAsync().ConfigureAwait(ConfigureAwaitOptions.None);
}

public async Task RetriggerSelfDescriptionCreation(Guid processId)
public Task RetriggerSelfDescriptionCreation(Guid processId) => RetriggerSelfDescriptionConnectorCreation(processId, ProcessStepTypeId.RETRIGGER_SELF_DESCRIPTION_CONNECTOR_CREATION);

public Task RetriggerSelfDescriptionResponseCreation(Guid processId) => RetriggerSelfDescriptionConnectorCreation(processId, ProcessStepTypeId.RETRIGGER_AWAIT_SELF_DESCRIPTION_CONNECTOR_RESPONSE);

private async Task RetriggerSelfDescriptionConnectorCreation(Guid processId, ProcessStepTypeId stepToTrigger)
{
const ProcessStepTypeId NextStep = ProcessStepTypeId.SELF_DESCRIPTION_CONNECTOR_CREATION;
const ProcessStepTypeId StepToTrigger = ProcessStepTypeId.RETRIGGER_SELF_DESCRIPTION_CONNECTOR_CREATION;
var (validProcessId, processData) = await portalRepositories.GetInstance<IPortalProcessStepRepository>().IsValidProcess(processId, ProcessTypeId.SELF_DESCRIPTION_CREATION, Enumerable.Repeat(StepToTrigger, 1)).ConfigureAwait(ConfigureAwaitOptions.None);
var (validProcessId, processData) = await portalRepositories.GetInstance<IPortalProcessStepRepository>().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}");
var context = processData.CreateManualProcessData(stepToTrigger, portalRepositories, () => $"processId {processId}");

context.ScheduleProcessSteps(Enumerable.Repeat(NextStep, 1));
context.FinalizeProcessStep();
Expand Down
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,6 +20,8 @@
using Microsoft.Extensions.Options;
using Org.Eclipse.TractusX.Portal.Backend.Framework.ErrorHandling;
using Org.Eclipse.TractusX.Portal.Backend.Framework.Processes.Library.Enums;
using Org.Eclipse.TractusX.Portal.Backend.Framework.Processes.Library.Extensions;
using Org.Eclipse.TractusX.Portal.Backend.Framework.Processes.Library.Models;
using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.DBAccess;
using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.DBAccess.Repositories;
using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.PortalEntities.Enums;
Expand Down Expand Up @@ -140,10 +142,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 @@ -152,21 +156,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).ConfigureAwait(ConfigureAwaitOptions.None);
if (processData != null)
{
HandleSdCreationProcess(processData, data, ProcessStepTypeId.AWAIT_SELF_DESCRIPTION_CONNECTOR_RESPONSE, ProcessStepTypeId.RETRIGGER_AWAIT_SELF_DESCRIPTION_CONNECTOR_RESPONSE);
}
}

private void HandleSdCreationProcess(VerifyProcessData<ProcessTypeId, ProcessStepTypeId> 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([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).ConfigureAwait(ConfigureAwaitOptions.None);
if (processData != null)
{
HandleSdCreationProcess(processData, data, ProcessStepTypeId.AWAIT_SELF_DESCRIPTION_COMPANY_RESPONSE, ProcessStepTypeId.RETRIGGER_AWAIT_SELF_DESCRIPTION_COMPANY_RESPONSE);
}
}

Expand All @@ -176,7 +206,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
2 changes: 1 addition & 1 deletion src/framework/Framework.Async/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

<Project>
<PropertyGroup>
<VersionPrefix>2.15.0</VersionPrefix>
<VersionPrefix>2.16.0</VersionPrefix>
<VersionSuffix></VersionSuffix>
</PropertyGroup>
</Project>
2 changes: 1 addition & 1 deletion src/framework/Framework.Cors/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

<Project>
<PropertyGroup>
<VersionPrefix>2.15.0</VersionPrefix>
<VersionPrefix>2.16.0</VersionPrefix>
<VersionSuffix></VersionSuffix>
</PropertyGroup>
</Project>
2 changes: 1 addition & 1 deletion src/framework/Framework.DBAccess/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

<Project>
<PropertyGroup>
<VersionPrefix>2.15.0</VersionPrefix>
<VersionPrefix>2.16.0</VersionPrefix>
<VersionSuffix></VersionSuffix>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

<Project>
<PropertyGroup>
<VersionPrefix>2.15.0</VersionPrefix>
<VersionPrefix>2.16.0</VersionPrefix>
<VersionSuffix></VersionSuffix>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

<Project>
<PropertyGroup>
<VersionPrefix>2.15.0</VersionPrefix>
<VersionPrefix>2.16.0</VersionPrefix>
<VersionSuffix></VersionSuffix>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

<Project>
<PropertyGroup>
<VersionPrefix>2.15.0</VersionPrefix>
<VersionPrefix>2.16.0</VersionPrefix>
<VersionSuffix></VersionSuffix>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

<Project>
<PropertyGroup>
<VersionPrefix>2.15.0</VersionPrefix>
<VersionPrefix>2.16.0</VersionPrefix>
<VersionSuffix></VersionSuffix>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

<Project>
<PropertyGroup>
<VersionPrefix>2.15.0</VersionPrefix>
<VersionPrefix>2.16.0</VersionPrefix>
<VersionSuffix></VersionSuffix>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

<Project>
<PropertyGroup>
<VersionPrefix>2.15.0</VersionPrefix>
<VersionPrefix>2.16.0</VersionPrefix>
<VersionSuffix></VersionSuffix>
</PropertyGroup>
</Project>
2 changes: 1 addition & 1 deletion src/framework/Framework.IO/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

<Project>
<PropertyGroup>
<VersionPrefix>2.15.0</VersionPrefix>
<VersionPrefix>2.16.0</VersionPrefix>
<VersionSuffix></VersionSuffix>
</PropertyGroup>
</Project>
Loading
Loading