Skip to content

Commit ce4aa6a

Browse files
authored
feat(sd): add process steps for sd creation (#1189)
* feat(sd): add process steps for sd creation + retrigger * update framework minor version * add and adjust unit tests Refs: #1182 --------- Co-authored-by: Norbert Truchsess <[email protected]>
1 parent a676ac4 commit ce4aa6a

File tree

48 files changed

+10934
-57
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+10934
-57
lines changed

docs/api/administration-service.yaml

+66
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,37 @@ paths:
662662
description: Internal Server Error
663663
'401':
664664
description: The User is unauthorized
665+
/api/administration/companydata/retrigger-self-description-response:
666+
post:
667+
tags:
668+
- CompanyData
669+
summary: 'Retriggers the process to create the missing self description documents (Authorization required - Roles: approve_new_partner)'
670+
parameters:
671+
- name: processId
672+
in: path
673+
required: true
674+
schema:
675+
type: string
676+
format: uuid
677+
responses:
678+
'204':
679+
description: Empty response on success.
680+
'400':
681+
description: Bad Request
682+
content:
683+
application/json:
684+
schema:
685+
$ref: '#/components/schemas/ErrorResponse'
686+
'404':
687+
description: No Process found for the processId
688+
content:
689+
application/json:
690+
schema:
691+
$ref: '#/components/schemas/ErrorResponse'
692+
'500':
693+
description: Internal Server Error
694+
'401':
695+
description: The User is unauthorized
665696
/api/administration/Connectors:
666697
get:
667698
tags:
@@ -1178,6 +1209,37 @@ paths:
11781209
description: Internal Server Error
11791210
'401':
11801211
description: The User is unauthorized
1212+
/api/administration/Connectors/retrigger-self-description-response:
1213+
post:
1214+
tags:
1215+
- Connectors
1216+
summary: 'Retriggers the process to create the missing self description response documents (Authorization required - Roles: approve_new_partner)'
1217+
parameters:
1218+
- name: processId
1219+
in: path
1220+
required: true
1221+
schema:
1222+
type: string
1223+
format: uuid
1224+
responses:
1225+
'204':
1226+
description: Empty response on success.
1227+
'400':
1228+
description: Bad Request
1229+
content:
1230+
application/json:
1231+
schema:
1232+
$ref: '#/components/schemas/ErrorResponse'
1233+
'404':
1234+
description: No Process found for the processId
1235+
content:
1236+
application/json:
1237+
schema:
1238+
$ref: '#/components/schemas/ErrorResponse'
1239+
'500':
1240+
description: Internal Server Error
1241+
'401':
1242+
description: The User is unauthorized
11811243
'/api/administration/Documents/{documentId}':
11821244
get:
11831245
tags:
@@ -7646,6 +7708,10 @@ components:
76467708
- SELF_DESCRIPTION_COMPANY_CREATION
76477709
- RETRIGGER_SELF_DESCRIPTION_CONNECTOR_CREATION
76487710
- RETRIGGER_SELF_DESCRIPTION_COMPANY_CREATION
7711+
- AWAIT_SELF_DESCRIPTION_CONNECTOR_RESPONSE
7712+
- AWAIT_SELF_DESCRIPTION_COMPANY_RESPONSE
7713+
- RETRIGGER_AWAIT_SELF_DESCRIPTION_CONNECTOR_RESPONSE
7714+
- RETRIGGER_AWAIT_SELF_DESCRIPTION_COMPANY_RESPONSE
76497715
type: string
76507716
ProviderDetailData:
76517717
type: object

docs/api/apps-service.yaml

+4
Original file line numberDiff line numberDiff line change
@@ -3700,6 +3700,10 @@ components:
37003700
- SELF_DESCRIPTION_COMPANY_CREATION
37013701
- RETRIGGER_SELF_DESCRIPTION_CONNECTOR_CREATION
37023702
- RETRIGGER_SELF_DESCRIPTION_COMPANY_CREATION
3703+
- AWAIT_SELF_DESCRIPTION_CONNECTOR_RESPONSE
3704+
- AWAIT_SELF_DESCRIPTION_COMPANY_RESPONSE
3705+
- RETRIGGER_AWAIT_SELF_DESCRIPTION_CONNECTOR_RESPONSE
3706+
- RETRIGGER_AWAIT_SELF_DESCRIPTION_COMPANY_RESPONSE
37033707
type: string
37043708
SubscriberSubscriptionDetailData:
37053709
type: object

docs/api/services-service.yaml

+4
Original file line numberDiff line numberDiff line change
@@ -2271,6 +2271,10 @@ components:
22712271
- SELF_DESCRIPTION_COMPANY_CREATION
22722272
- RETRIGGER_SELF_DESCRIPTION_CONNECTOR_CREATION
22732273
- RETRIGGER_SELF_DESCRIPTION_COMPANY_CREATION
2274+
- AWAIT_SELF_DESCRIPTION_CONNECTOR_RESPONSE
2275+
- AWAIT_SELF_DESCRIPTION_COMPANY_RESPONSE
2276+
- RETRIGGER_AWAIT_SELF_DESCRIPTION_CONNECTOR_RESPONSE
2277+
- RETRIGGER_AWAIT_SELF_DESCRIPTION_COMPANY_RESPONSE
22742278
type: string
22752279
ProviderSubscriptionDetailData:
22762280
type: object

src/administration/Administration.Service/BusinessLogic/CompanyDataBusinessLogic.cs

+8-4
Original file line numberDiff line numberDiff line change
@@ -458,17 +458,21 @@ public async Task TriggerSelfDescriptionCreation()
458458
await portalRepositories.SaveAsync().ConfigureAwait(ConfigureAwaitOptions.None);
459459
}
460460

461-
public async Task RetriggerSelfDescriptionCreation(Guid processId)
461+
public Task RetriggerSelfDescriptionCreation(Guid processId) => RetriggerSelfDescriptionCompanyCreation(processId, ProcessStepTypeId.RETRIGGER_SELF_DESCRIPTION_COMPANY_CREATION);
462+
463+
public Task RetriggerSelfDescriptionResponseCreation(Guid processId) => RetriggerSelfDescriptionCompanyCreation(processId, ProcessStepTypeId.RETRIGGER_AWAIT_SELF_DESCRIPTION_COMPANY_RESPONSE);
464+
465+
private async Task RetriggerSelfDescriptionCompanyCreation(Guid processId, ProcessStepTypeId stepToTrigger)
462466
{
463467
const ProcessStepTypeId NextStep = ProcessStepTypeId.SELF_DESCRIPTION_COMPANY_CREATION;
464-
const ProcessStepTypeId StepToTrigger = ProcessStepTypeId.RETRIGGER_SELF_DESCRIPTION_COMPANY_CREATION;
465-
var (validProcessId, processData) = await portalRepositories.GetInstance<IPortalProcessStepRepository>().IsValidProcess(processId, ProcessTypeId.SELF_DESCRIPTION_CREATION, Enumerable.Repeat(StepToTrigger, 1)).ConfigureAwait(ConfigureAwaitOptions.None);
468+
469+
var (validProcessId, processData) = await portalRepositories.GetInstance<IPortalProcessStepRepository>().IsValidProcess(processId, ProcessTypeId.SELF_DESCRIPTION_CREATION, Enumerable.Repeat(stepToTrigger, 1)).ConfigureAwait(ConfigureAwaitOptions.None);
466470
if (!validProcessId)
467471
{
468472
throw NotFoundException.Create(AdministrationCompanyDataErrors.COMPANY_DATA_NOT_PROCESSID_NOT_EXIST, new ErrorParameter[] { new(nameof(processId), processId.ToString()) });
469473
}
470474

471-
var context = processData.CreateManualProcessData(StepToTrigger, portalRepositories, () => $"processId {processId}");
475+
var context = processData.CreateManualProcessData(stepToTrigger, portalRepositories, () => $"processId {processId}");
472476

473477
context.ScheduleProcessSteps(Enumerable.Repeat(NextStep, 1));
474478
context.FinalizeProcessStep();

src/administration/Administration.Service/BusinessLogic/ConnectorsBusinessLogic.cs

+7-4
Original file line numberDiff line numberDiff line change
@@ -491,17 +491,20 @@ public async Task TriggerSelfDescriptionCreation()
491491
await portalRepositories.SaveAsync().ConfigureAwait(ConfigureAwaitOptions.None);
492492
}
493493

494-
public async Task RetriggerSelfDescriptionCreation(Guid processId)
494+
public Task RetriggerSelfDescriptionCreation(Guid processId) => RetriggerSelfDescriptionConnectorCreation(processId, ProcessStepTypeId.RETRIGGER_SELF_DESCRIPTION_CONNECTOR_CREATION);
495+
496+
public Task RetriggerSelfDescriptionResponseCreation(Guid processId) => RetriggerSelfDescriptionConnectorCreation(processId, ProcessStepTypeId.RETRIGGER_AWAIT_SELF_DESCRIPTION_CONNECTOR_RESPONSE);
497+
498+
private async Task RetriggerSelfDescriptionConnectorCreation(Guid processId, ProcessStepTypeId stepToTrigger)
495499
{
496500
const ProcessStepTypeId NextStep = ProcessStepTypeId.SELF_DESCRIPTION_CONNECTOR_CREATION;
497-
const ProcessStepTypeId StepToTrigger = ProcessStepTypeId.RETRIGGER_SELF_DESCRIPTION_CONNECTOR_CREATION;
498-
var (validProcessId, processData) = await portalRepositories.GetInstance<IPortalProcessStepRepository>().IsValidProcess(processId, ProcessTypeId.SELF_DESCRIPTION_CREATION, Enumerable.Repeat(StepToTrigger, 1)).ConfigureAwait(ConfigureAwaitOptions.None);
501+
var (validProcessId, processData) = await portalRepositories.GetInstance<IPortalProcessStepRepository>().IsValidProcess(processId, ProcessTypeId.SELF_DESCRIPTION_CREATION, Enumerable.Repeat(stepToTrigger, 1)).ConfigureAwait(ConfigureAwaitOptions.None);
499502
if (!validProcessId)
500503
{
501504
throw new NotFoundException($"process {processId} does not exist");
502505
}
503506

504-
var context = processData.CreateManualProcessData(StepToTrigger, portalRepositories, () => $"processId {processId}");
507+
var context = processData.CreateManualProcessData(stepToTrigger, portalRepositories, () => $"processId {processId}");
505508

506509
context.ScheduleProcessSteps(Enumerable.Repeat(NextStep, 1));
507510
context.FinalizeProcessStep();

src/administration/Administration.Service/BusinessLogic/ICompanyDataBusinessLogic.cs

+1
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,6 @@ public interface ICompanyDataBusinessLogic
5353
Task<DimUrlsResponse> GetDimServiceUrls();
5454
Task<Pagination.Response<CompanyMissingSdDocumentData>> GetCompaniesWithMissingSdDocument(int page, int size);
5555
Task RetriggerSelfDescriptionCreation(Guid processId);
56+
Task RetriggerSelfDescriptionResponseCreation(Guid processId);
5657
Task TriggerSelfDescriptionCreation();
5758
}

src/administration/Administration.Service/BusinessLogic/IConnectorsBusinessLogic.cs

+1
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,5 @@ public interface IConnectorsBusinessLogic
105105
Task<Pagination.Response<ConnectorMissingSdDocumentData>> GetConnectorsWithMissingSdDocument(int page, int size);
106106
Task TriggerSelfDescriptionCreation();
107107
Task RetriggerSelfDescriptionCreation(Guid processId);
108+
Task RetriggerSelfDescriptionResponseCreation(Guid processId);
108109
}

src/administration/Administration.Service/Controllers/CompanyDataController.cs

+20
Original file line numberDiff line numberDiff line change
@@ -385,4 +385,24 @@ public async Task<NoContentResult> RetriggerSelfDescriptionProcess([FromRoute] G
385385
await logic.RetriggerSelfDescriptionCreation(processId).ConfigureAwait(false);
386386
return NoContent();
387387
}
388+
389+
/// <summary>
390+
/// Retriggers the process to create the missing self description documents
391+
/// </summary>
392+
/// <returns>NoContent</returns>
393+
/// Example: POST: /api/administration/companyData/trigger-self-description-response/{processId}
394+
/// <response code="204">Empty response on success.</response>
395+
/// <response code="404">No Process found for the processId</response>
396+
[HttpPost]
397+
[Authorize(Roles = "approve_new_partner")]
398+
[Authorize(Policy = PolicyTypes.CompanyUser)]
399+
[Route("retrigger-self-description-response")]
400+
[ProducesResponseType(StatusCodes.Status204NoContent)]
401+
[ProducesResponseType(typeof(ErrorResponse), StatusCodes.Status400BadRequest)]
402+
[ProducesResponseType(typeof(ErrorResponse), StatusCodes.Status404NotFound)]
403+
public async Task<NoContentResult> RetriggerSelfDescriptionResponseProcess([FromRoute] Guid processId)
404+
{
405+
await logic.RetriggerSelfDescriptionResponseCreation(processId).ConfigureAwait(false);
406+
return NoContent();
407+
}
388408
}

src/administration/Administration.Service/Controllers/ConnectorsController.cs

+20
Original file line numberDiff line numberDiff line change
@@ -307,4 +307,24 @@ public async Task<NoContentResult> RetriggerSelfDescriptionProcess([FromRoute] G
307307
await logic.RetriggerSelfDescriptionCreation(processId).ConfigureAwait(false);
308308
return NoContent();
309309
}
310+
311+
/// <summary>
312+
/// Retriggers the process to create the missing self description response documents
313+
/// </summary>
314+
/// <returns>NoContent</returns>
315+
/// Example: POST: /api/administration/connectors/retrigger-self-description-response/{processId}
316+
/// <response code="204">Empty response on success.</response>
317+
/// <response code="404">No Process found for the processId</response>
318+
[HttpPost]
319+
[Authorize(Roles = "approve_new_partner")]
320+
[Authorize(Policy = PolicyTypes.CompanyUser)]
321+
[Route("retrigger-self-description-response")]
322+
[ProducesResponseType(StatusCodes.Status204NoContent)]
323+
[ProducesResponseType(typeof(ErrorResponse), StatusCodes.Status400BadRequest)]
324+
[ProducesResponseType(typeof(ErrorResponse), StatusCodes.Status404NotFound)]
325+
public async Task<NoContentResult> RetriggerSelfDescriptionResponseProcess([FromRoute] Guid processId)
326+
{
327+
await logic.RetriggerSelfDescriptionResponseCreation(processId).ConfigureAwait(false);
328+
return NoContent();
329+
}
310330
}

src/externalsystems/SdFactory.Library/BusinessLogic/SdFactoryBusinessLogic.cs

+36-6
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
using Microsoft.Extensions.Options;
2121
using Org.Eclipse.TractusX.Portal.Backend.Framework.ErrorHandling;
2222
using Org.Eclipse.TractusX.Portal.Backend.Framework.Processes.Library.Enums;
23+
using Org.Eclipse.TractusX.Portal.Backend.Framework.Processes.Library.Extensions;
24+
using Org.Eclipse.TractusX.Portal.Backend.Framework.Processes.Library.Models;
2325
using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.DBAccess;
2426
using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.DBAccess.Repositories;
2527
using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.PortalEntities.Enums;
@@ -140,10 +142,12 @@ public async Task ProcessFinishSelfDescriptionLpForApplication(SelfDescriptionRe
140142
/// <inheritdoc />
141143
public async Task ProcessFinishSelfDescriptionLpForConnector(SelfDescriptionResponseData data, CancellationToken cancellationToken)
142144
{
143-
if (ValidateConfirmationData(data))
145+
var connectorsRepository = portalRepositories.GetInstance<IConnectorsRepository>();
146+
var result = ValidateConfirmationData(data);
147+
if (result)
144148
{
145149
var documentId = await ProcessAndCreateDocument(SdFactoryResponseModelTitle.Connector, data, cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None);
146-
portalRepositories.GetInstance<IConnectorsRepository>().AttachAndModifyConnector(data.ExternalId, null, con =>
150+
connectorsRepository.AttachAndModifyConnector(data.ExternalId, null, con =>
147151
{
148152
con.SelfDescriptionDocumentId = documentId;
149153
con.StatusId = ConnectorStatusId.ACTIVE;
@@ -152,21 +156,47 @@ public async Task ProcessFinishSelfDescriptionLpForConnector(SelfDescriptionResp
152156
}
153157
else
154158
{
155-
portalRepositories.GetInstance<IConnectorsRepository>().AttachAndModifyConnector(data.ExternalId, null, con =>
159+
connectorsRepository.AttachAndModifyConnector(data.ExternalId, null, con =>
156160
{
157161
con.SelfDescriptionMessage = data.Message!;
158162
con.DateLastChanged = DateTimeOffset.UtcNow;
159163
});
160164
}
165+
166+
var processData = await connectorsRepository.GetProcessDataForConnectorId(data.ExternalId).ConfigureAwait(ConfigureAwaitOptions.None);
167+
if (processData != null)
168+
{
169+
HandleSdCreationProcess(processData, data, ProcessStepTypeId.AWAIT_SELF_DESCRIPTION_CONNECTOR_RESPONSE, ProcessStepTypeId.RETRIGGER_AWAIT_SELF_DESCRIPTION_CONNECTOR_RESPONSE);
170+
}
171+
}
172+
173+
private void HandleSdCreationProcess(VerifyProcessData<ProcessTypeId, ProcessStepTypeId> processData, SelfDescriptionResponseData data, ProcessStepTypeId processStepTypeId, ProcessStepTypeId retriggerProcessStepTypeId)
174+
{
175+
var context = processData.CreateManualProcessData(processStepTypeId, portalRepositories, () => $"externalId {data.ExternalId}");
176+
if (data.Status == SelfDescriptionStatus.Confirm)
177+
{
178+
context.FinalizeProcessStep();
179+
}
180+
else
181+
{
182+
context.ScheduleProcessSteps([retriggerProcessStepTypeId]);
183+
context.FailProcessStep(data.Message);
184+
}
161185
}
162186

163187
public async Task ProcessFinishSelfDescriptionLpForCompany(SelfDescriptionResponseData data, CancellationToken cancellationToken)
164188
{
189+
var companyRepository = portalRepositories.GetInstance<ICompanyRepository>();
165190
if (data.Status == SelfDescriptionStatus.Confirm)
166191
{
167192
var documentId = await ProcessAndCreateDocument(SdFactoryResponseModelTitle.LegalPerson, data, cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None);
168-
portalRepositories.GetInstance<ICompanyRepository>().AttachAndModifyCompany(data.ExternalId, null,
169-
c => { c.SelfDescriptionDocumentId = documentId; });
193+
companyRepository.AttachAndModifyCompany(data.ExternalId, null, c => { c.SelfDescriptionDocumentId = documentId; });
194+
}
195+
196+
var processData = await companyRepository.GetProcessDataForCompanyIdId(data.ExternalId).ConfigureAwait(ConfigureAwaitOptions.None);
197+
if (processData != null)
198+
{
199+
HandleSdCreationProcess(processData, data, ProcessStepTypeId.AWAIT_SELF_DESCRIPTION_COMPANY_RESPONSE, ProcessStepTypeId.RETRIGGER_AWAIT_SELF_DESCRIPTION_COMPANY_RESPONSE);
170200
}
171201
}
172202

@@ -176,7 +206,7 @@ private static bool ValidateConfirmationData(SelfDescriptionResponseData data)
176206
switch (confirm)
177207
{
178208
case false when string.IsNullOrEmpty(data.Message):
179-
throw new ConflictException("Please provide a messsage");
209+
throw new ConflictException("Please provide a message");
180210
case true when data.Content == null:
181211
throw new ConflictException("Please provide a selfDescriptionDocument");
182212
}

src/framework/Framework.Async/Directory.Build.props

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
<Project>
2121
<PropertyGroup>
22-
<VersionPrefix>2.15.0</VersionPrefix>
22+
<VersionPrefix>2.16.0</VersionPrefix>
2323
<VersionSuffix></VersionSuffix>
2424
</PropertyGroup>
2525
</Project>

src/framework/Framework.Cors/Directory.Build.props

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
<Project>
2121
<PropertyGroup>
22-
<VersionPrefix>2.15.0</VersionPrefix>
22+
<VersionPrefix>2.16.0</VersionPrefix>
2323
<VersionSuffix></VersionSuffix>
2424
</PropertyGroup>
2525
</Project>

src/framework/Framework.DBAccess/Directory.Build.props

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
<Project>
2121
<PropertyGroup>
22-
<VersionPrefix>2.15.0</VersionPrefix>
22+
<VersionPrefix>2.16.0</VersionPrefix>
2323
<VersionSuffix></VersionSuffix>
2424
</PropertyGroup>
2525
</Project>

src/framework/Framework.DateTimeProvider/Directory.Build.props

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
<Project>
2121
<PropertyGroup>
22-
<VersionPrefix>2.15.0</VersionPrefix>
22+
<VersionPrefix>2.16.0</VersionPrefix>
2323
<VersionSuffix></VersionSuffix>
2424
</PropertyGroup>
2525
</Project>

src/framework/Framework.DependencyInjection/Directory.Build.props

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
<Project>
2121
<PropertyGroup>
22-
<VersionPrefix>2.15.0</VersionPrefix>
22+
<VersionPrefix>2.16.0</VersionPrefix>
2323
<VersionSuffix></VersionSuffix>
2424
</PropertyGroup>
2525
</Project>

src/framework/Framework.ErrorHandling.Controller/Directory.Build.props

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
<Project>
2121
<PropertyGroup>
22-
<VersionPrefix>2.15.0</VersionPrefix>
22+
<VersionPrefix>2.16.0</VersionPrefix>
2323
<VersionSuffix></VersionSuffix>
2424
</PropertyGroup>
2525
</Project>

src/framework/Framework.ErrorHandling.Web/Directory.Build.props

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
<Project>
2121
<PropertyGroup>
22-
<VersionPrefix>2.15.0</VersionPrefix>
22+
<VersionPrefix>2.16.0</VersionPrefix>
2323
<VersionSuffix></VersionSuffix>
2424
</PropertyGroup>
2525
</Project>

src/framework/Framework.ErrorHandling/Directory.Build.props

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
<Project>
2121
<PropertyGroup>
22-
<VersionPrefix>2.15.0</VersionPrefix>
22+
<VersionPrefix>2.16.0</VersionPrefix>
2323
<VersionSuffix></VersionSuffix>
2424
</PropertyGroup>
2525
</Project>

src/framework/Framework.HttpClientExtensions/Directory.Build.props

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
<Project>
2121
<PropertyGroup>
22-
<VersionPrefix>2.15.0</VersionPrefix>
22+
<VersionPrefix>2.16.0</VersionPrefix>
2323
<VersionSuffix></VersionSuffix>
2424
</PropertyGroup>
2525
</Project>

src/framework/Framework.IO/Directory.Build.props

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
<Project>
2121
<PropertyGroup>
22-
<VersionPrefix>2.15.0</VersionPrefix>
22+
<VersionPrefix>2.16.0</VersionPrefix>
2323
<VersionSuffix></VersionSuffix>
2424
</PropertyGroup>
2525
</Project>

0 commit comments

Comments
 (0)