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(auto-setup): adjust provider callbackurl handling #1227

Open
wants to merge 3 commits 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
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@
********************************************************************************/

using Org.Eclipse.TractusX.Portal.Backend.Administration.Service.ErrorHandling;
using Org.Eclipse.TractusX.Portal.Backend.Framework.Async;
using Org.Eclipse.TractusX.Portal.Backend.Framework.ErrorHandling;
using Org.Eclipse.TractusX.Portal.Backend.Framework.Identity;
using Org.Eclipse.TractusX.Portal.Backend.Framework.IO;
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.Models;
using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.DBAccess.Repositories;
Expand All @@ -30,30 +33,26 @@

namespace Org.Eclipse.TractusX.Portal.Backend.Administration.Service.BusinessLogic;

public class SubscriptionConfigurationBusinessLogic : ISubscriptionConfigurationBusinessLogic
public class SubscriptionConfigurationBusinessLogic(
IOfferSubscriptionProcessService offerSubscriptionProcessService,
IPortalRepositories portalRepositories,
IIdentityService identityService)
: ISubscriptionConfigurationBusinessLogic
{
private readonly IOfferSubscriptionProcessService _offerSubscriptionProcessService;
private readonly IPortalRepositories _portalRepositories;
private readonly IIdentityData _identityData;

public SubscriptionConfigurationBusinessLogic(IOfferSubscriptionProcessService offerSubscriptionProcessService, IPortalRepositories portalRepositories, IIdentityService identityService)
{
_offerSubscriptionProcessService = offerSubscriptionProcessService;
_portalRepositories = portalRepositories;
_identityData = identityService.IdentityData;
}
private readonly IIdentityData _identityData = identityService.IdentityData;

/// <inheritdoc />
public async Task<ProviderDetailReturnData> GetProviderCompanyDetailsAsync()
{
var companyId = _identityData.CompanyId;
var result = await _portalRepositories.GetInstance<ICompanyRepository>()
var result = await portalRepositories.GetInstance<ICompanyRepository>()
.GetProviderCompanyDetailAsync(CompanyRoleId.SERVICE_PROVIDER, companyId)
.ConfigureAwait(ConfigureAwaitOptions.None);
if (result == default)
{
throw ConflictException.Create(AdministrationSubscriptionConfigurationErrors.SUBSCRIPTION_CONFLICT_COMPANY_NOT_FOUND, new ErrorParameter[] { new(nameof(companyId), companyId.ToString()) });
}

if (!result.IsProviderCompany)
{
throw ForbiddenException.Create(AdministrationSubscriptionConfigurationErrors.SUBSCRIPTION_FORBIDDEN_COMPANY_NOT_SERVICE_PROVIDER, new ErrorParameter[] { new(nameof(companyId), companyId.ToString()) });
Expand All @@ -78,7 +77,7 @@ public Task SetProviderCompanyDetailsAsync(ProviderDetailData data)

private async Task SetOfferProviderCompanyDetailsInternalAsync(ProviderDetailData data, Guid companyId)
{
var companyRepository = _portalRepositories.GetInstance<ICompanyRepository>();
var companyRepository = portalRepositories.GetInstance<ICompanyRepository>();
var providerDetailData = await companyRepository
.GetProviderCompanyDetailsExistsForUser(companyId)
.ConfigureAwait(ConfigureAwaitOptions.None);
Expand All @@ -92,9 +91,14 @@ private async Task SetOfferProviderCompanyDetailsInternalAsync(ProviderDetailDat
{
companyRepository.AttachAndModifyProviderCompanyDetails(
providerDetailData.ProviderCompanyDetailId,
details => { details.AutoSetupUrl = providerDetailData.Url; },
details =>
{
details.AutoSetupUrl = providerDetailData.Url;
details.AutoSetupCallbackUrl = providerDetailData.CallbackUrl;
},
details =>
{
details.AutoSetupCallbackUrl = data.CallbackUrl;
details.AutoSetupUrl = data.Url;
details.DateLastChanged = DateTimeOffset.UtcNow;
});
Expand All @@ -106,9 +110,32 @@ private async Task SetOfferProviderCompanyDetailsInternalAsync(ProviderDetailDat
hasChanges = true;
}

if (providerDetailData.CallbackUrl is not null && data.CallbackUrl is null)
{
await HandleOfferSetupProcesses(companyId).ConfigureAwait(ConfigureAwaitOptions.None);
hasChanges = true;
}

if (hasChanges)
{
await _portalRepositories.SaveAsync().ConfigureAwait(ConfigureAwaitOptions.None);
await portalRepositories.SaveAsync().ConfigureAwait(ConfigureAwaitOptions.None);
}
}

private async Task HandleOfferSetupProcesses(Guid companyId)
{
var processData = await portalRepositories.GetInstance<IOfferSubscriptionsRepository>()
.GetOfferSubscriptionRetriggerProcessesForCompanyId(companyId)
.PreSortedGroupBy(x => x.Process, x => x.ProcessStep, (left, right) => left.Id == right.Id)
.Select(group => new VerifyProcessData<ProcessTypeId, ProcessStepTypeId>(group.Key, group))
.ToListAsync()
.ConfigureAwait(false);

foreach (var context in processData.Select(data =>
data.CreateManualProcessData(ProcessStepTypeId.RETRIGGER_PROVIDER, portalRepositories, () => $"processId {data.Process!.Id}")))
{
context.FinalizeProcessStep();
context.ScheduleProcessSteps(Enumerable.Repeat(ProcessStepTypeId.AWAIT_START_AUTOSETUP, 1));
}
}

Expand All @@ -129,11 +156,7 @@ private static async Task HandleCreateProviderCompanyDetails(ProviderDetailData

companyRepository.CreateProviderCompanyDetail(companyId, data.Url!, providerDetails =>
{
if (data.CallbackUrl != null)
{
providerDetails.AutoSetupCallbackUrl = data.CallbackUrl;
}

providerDetails.AutoSetupCallbackUrl = data.CallbackUrl;
providerDetails.DateLastChanged = DateTimeOffset.UtcNow;
});
}
Expand All @@ -158,18 +181,17 @@ public Task RetriggerProviderCallback(Guid offerSubscriptionId) =>
public Task RetriggerCreateDimTechnicalUser(Guid offerSubscriptionId) =>
TriggerProcessStep(offerSubscriptionId, ProcessStepTypeId.RETRIGGER_OFFERSUBSCRIPTION_CREATE_DIM_TECHNICAL_USER, true);

/// <inheritdoc />
private async Task TriggerProcessStep(Guid offerSubscriptionId, ProcessStepTypeId stepToTrigger, bool mustBePending)
{
var nextStep = stepToTrigger.GetOfferSubscriptionStepToRetrigger();
var context = await _offerSubscriptionProcessService.VerifySubscriptionAndProcessSteps(offerSubscriptionId, stepToTrigger, null, mustBePending)
var context = await offerSubscriptionProcessService.VerifySubscriptionAndProcessSteps(offerSubscriptionId, stepToTrigger, null, mustBePending)
.ConfigureAwait(ConfigureAwaitOptions.None);

_offerSubscriptionProcessService.FinalizeProcessSteps(context, Enumerable.Repeat(nextStep, 1));
await _portalRepositories.SaveAsync().ConfigureAwait(ConfigureAwaitOptions.None);
offerSubscriptionProcessService.FinalizeProcessSteps(context, Enumerable.Repeat(nextStep, 1));
await portalRepositories.SaveAsync().ConfigureAwait(ConfigureAwaitOptions.None);
}

/// <inheritdoc />
public IAsyncEnumerable<ProcessStepData> GetProcessStepsForSubscription(Guid offerSubscriptionId) =>
_portalRepositories.GetInstance<IOfferSubscriptionsRepository>().GetProcessStepsForSubscription(offerSubscriptionId);
portalRepositories.GetInstance<IOfferSubscriptionsRepository>().GetProcessStepsForSubscription(offerSubscriptionId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ public async Task ProcessFinishSelfDescriptionLpForCompany(SelfDescriptionRespon
companyRepository.AttachAndModifyCompany(data.ExternalId, null, c => { c.SelfDescriptionDocumentId = documentId; });
}

var processData = await companyRepository.GetProcessDataForCompanyIdId(data.ExternalId).ConfigureAwait(ConfigureAwaitOptions.None);
var processData = await companyRepository.GetSelfDescriptionProcessDataForCompanyId(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 Down
14 changes: 7 additions & 7 deletions src/framework/Framework.Async/AsyncGroupByExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,28 @@ namespace Org.Eclipse.TractusX.Portal.Backend.Framework.Async;

public static class AsyncGroupByExtensions
{
public static async IAsyncEnumerable<IGrouping<TKey, TElement>> PreSortedGroupBy<T, TKey, TElement>(this IAsyncEnumerable<T> Data, Func<T, TKey> KeySelector, Func<T, TElement> ElementSelector) where T : notnull where TKey : notnull
public static async IAsyncEnumerable<IGrouping<TKey, TElement>> PreSortedGroupBy<T, TKey, TElement>(this IAsyncEnumerable<T> data, Func<T, TKey> keySelector, Func<T, TElement> elementSelector, Func<TKey, TKey, bool>? isEqualKey = null) where T : notnull where TKey : notnull
{
await using var enumerator = Data.GetAsyncEnumerator();
await using var enumerator = data.GetAsyncEnumerator();

var hasNext = await enumerator.MoveNextAsync().ConfigureAwait(false);
if (hasNext)
{
var key = KeySelector(enumerator.Current);
var key = keySelector(enumerator.Current);
TKey nextKey = default!;
while (true)
{
var values = new LinkedList<TElement>();
do
{
values.AddLast(ElementSelector(enumerator.Current));
values.AddLast(elementSelector(enumerator.Current));
hasNext = await enumerator.MoveNextAsync().ConfigureAwait(false);
if (hasNext)
{
nextKey = KeySelector(enumerator.Current);
nextKey = keySelector(enumerator.Current);
}
}
while (hasNext && nextKey.Equals(key));
while (hasNext && (isEqualKey == null ? nextKey.Equals(key) : isEqualKey(nextKey, key)));
yield return new Grouping<TKey, TElement>(key, values);
if (!hasNext)
{
Expand All @@ -54,7 +54,7 @@ public static async IAsyncEnumerable<IGrouping<TKey, TElement>> PreSortedGroupBy
yield break;
}

public static IAsyncEnumerable<IGrouping<TKey, T>> PreSortedGroupBy<T, TKey>(this IAsyncEnumerable<T> Data, Func<T, TKey> KeySelector) where T : notnull where TKey : notnull => Data.PreSortedGroupBy(KeySelector, x => x);
public static IAsyncEnumerable<IGrouping<TKey, T>> PreSortedGroupBy<T, TKey>(this IAsyncEnumerable<T> data, Func<T, TKey> keySelector) where T : notnull where TKey : notnull => data.PreSortedGroupBy(keySelector, x => x);

private sealed class Grouping<TKey, TElement> : IGrouping<TKey, TElement>
{
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>3.3.0</VersionPrefix>
<VersionPrefix>3.4.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>3.3.0</VersionPrefix>
<VersionPrefix>3.4.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>3.3.0</VersionPrefix>
<VersionPrefix>3.4.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>3.3.0</VersionPrefix>
<VersionPrefix>3.4.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>3.3.0</VersionPrefix>
<VersionPrefix>3.4.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>3.3.0</VersionPrefix>
<VersionPrefix>3.4.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>3.3.0</VersionPrefix>
<VersionPrefix>3.4.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>3.3.0</VersionPrefix>
<VersionPrefix>3.4.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>3.3.0</VersionPrefix>
<VersionPrefix>3.4.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>3.3.0</VersionPrefix>
<VersionPrefix>3.4.0</VersionPrefix>
<VersionSuffix></VersionSuffix>
</PropertyGroup>
</Project>
2 changes: 1 addition & 1 deletion src/framework/Framework.Identity/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

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

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

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

<Project>
<PropertyGroup>
<VersionPrefix>3.3.0</VersionPrefix>
<VersionPrefix>3.4.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>3.3.0</VersionPrefix>
<VersionPrefix>3.4.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>3.3.0</VersionPrefix>
<VersionPrefix>3.4.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>3.3.0</VersionPrefix>
<VersionPrefix>3.4.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>3.3.0</VersionPrefix>
<VersionPrefix>3.4.0</VersionPrefix>
<VersionSuffix></VersionSuffix>
</PropertyGroup>
</Project>
2 changes: 1 addition & 1 deletion src/framework/Framework.Seeding/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

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

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

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

<Project>
<PropertyGroup>
<VersionPrefix>3.3.0</VersionPrefix>
<VersionPrefix>3.4.0</VersionPrefix>
<VersionSuffix></VersionSuffix>
</PropertyGroup>
</Project>
Loading
Loading