Skip to content

Commit

Permalink
fix compile-errors after rebase and review findings
Browse files Browse the repository at this point in the history
  • Loading branch information
ntruchsess committed Sep 16, 2024
1 parent 08461dd commit 721525d
Show file tree
Hide file tree
Showing 31 changed files with 209 additions and 150 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Options;
using Org.Eclipse.TractusX.Portal.Backend.Administration.Service.ErrorHandling;
using Org.Eclipse.TractusX.Portal.Backend.Administration.Service.Extensions;
using Org.Eclipse.TractusX.Portal.Backend.Administration.Service.Models;
using Org.Eclipse.TractusX.Portal.Backend.Clearinghouse.Library.BusinessLogic;
using Org.Eclipse.TractusX.Portal.Backend.Clearinghouse.Library.Models;
Expand Down Expand Up @@ -130,7 +131,7 @@ private async Task<CompanyWithAddressData> GetCompanyWithAddressAsyncInternal(Gu
var applications = portalRepositories.GetInstance<IApplicationRepository>()
.GetCompanyApplicationsFilteredQuery(
companyName?.Length >= 3 ? companyName : null,
GetCompanyApplicationStatusIds(companyApplicationStatusFilter));
companyApplicationStatusFilter.GetCompanyApplicationStatusIds());

return Pagination.CreateResponseAsync(
page,
Expand Down Expand Up @@ -170,7 +171,7 @@ private async Task<CompanyWithAddressData> GetCompanyWithAddressAsyncInternal(Gu
var applicationsQuery = portalRepositories.GetInstance<IApplicationRepository>()
.GetExternalCompanyApplicationsFilteredQuery(_identityData.CompanyId,
companyName?.Length >= 3 ? companyName : null, externalId,
GetCompanyApplicationStatusIds(companyApplicationStatusFilter));
companyApplicationStatusFilter.GetCompanyApplicationStatusIds());

var orderedQuery = dateCreatedOrderFilter == null || dateCreatedOrderFilter.Value == DateCreatedOrderFilter.DESC
? applicationsQuery.AsSplitQuery().OrderByDescending(application => application.DateCreated)
Expand Down Expand Up @@ -606,25 +607,6 @@ private void PostRegistrationCancelEmailAsync(ICollection<EmailData> emailData,
}
}

private static IEnumerable<CompanyApplicationStatusId> GetCompanyApplicationStatusIds(CompanyApplicationStatusFilter? companyApplicationStatusFilter)
{
switch (companyApplicationStatusFilter)
{
case CompanyApplicationStatusFilter.Closed:
{
return [CompanyApplicationStatusId.CONFIRMED, CompanyApplicationStatusId.DECLINED];
}
case CompanyApplicationStatusFilter.InReview:
{
return [CompanyApplicationStatusId.SUBMITTED];
}
default:
{
return [CompanyApplicationStatusId.SUBMITTED, CompanyApplicationStatusId.CONFIRMED, CompanyApplicationStatusId.DECLINED];
}
}
}

/// <inheritdoc />
public async Task<(string fileName, byte[] content, string contentType)> GetDocumentAsync(Guid documentId)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,16 @@ public static class CompanyApplicationStatusFilterExtensions
public static IEnumerable<CompanyApplicationStatusId> GetCompanyApplicationStatusIds(this CompanyApplicationStatusFilter? companyApplicationStatusFilter) =>
companyApplicationStatusFilter switch
{
CompanyApplicationStatusFilter.Closed =>
[
CompanyApplicationStatusId.CONFIRMED, CompanyApplicationStatusId.DECLINED
CompanyApplicationStatusFilter.Closed => [
CompanyApplicationStatusId.CONFIRMED,
CompanyApplicationStatusId.DECLINED
],
CompanyApplicationStatusFilter.InReview => [
CompanyApplicationStatusId.SUBMITTED
],
CompanyApplicationStatusFilter.InReview => [CompanyApplicationStatusId.SUBMITTED],
_ =>
[
CompanyApplicationStatusId.SUBMITTED, CompanyApplicationStatusId.CONFIRMED,
_ => [
CompanyApplicationStatusId.SUBMITTED,
CompanyApplicationStatusId.CONFIRMED,
CompanyApplicationStatusId.DECLINED
]
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
using Microsoft.Extensions.Options;
using Org.Eclipse.TractusX.Portal.Backend.Clearinghouse.Library.Models;
using Org.Eclipse.TractusX.Portal.Backend.Custodian.Library.BusinessLogic;
using Org.Eclipse.TractusX.Portal.Backend.Framework.Async;
using Org.Eclipse.TractusX.Portal.Backend.Framework.DateTimeProvider;
using Org.Eclipse.TractusX.Portal.Backend.Framework.ErrorHandling;
using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.DBAccess;
Expand Down Expand Up @@ -139,35 +140,36 @@ public async Task ProcessEndClearinghouse(Guid applicationId, ClearinghouseRespo
: [ProcessStepTypeId.START_SELF_DESCRIPTION_LP]);
}

public async Task CheckEndClearinghouseProcesses(CancellationToken stoppingToken)
public async Task CheckEndClearinghouseProcesses(CancellationToken cancellationToken)
{
var applicationIds = await portalRepositories.GetInstance<IApplicationChecklistRepository>()
.GetApplicationsForClearinghouseRetrigger(dateTimeProvider.OffsetNow.AddDays(-_settings.RetriggerEndClearinghouseIntervalInDays))
.ToListAsync(stoppingToken)
.ToListAsync(cancellationToken)
.ConfigureAwait(false);

var hasChanges = false;
foreach (var context in applicationIds.Select(applicationId => checklistService.VerifyChecklistEntryAndProcessSteps(
applicationId,
ApplicationChecklistEntryTypeId.CLEARING_HOUSE,
[ApplicationChecklistEntryStatusId.IN_PROGRESS],
ProcessStepTypeId.AWAIT_CLEARING_HOUSE_RESPONSE)))
if (applicationIds.Count == 0)
return;

await foreach (var context in applicationIds
.Select(applicationId =>
checklistService.VerifyChecklistEntryAndProcessSteps(
applicationId,
ApplicationChecklistEntryTypeId.CLEARING_HOUSE,
[ApplicationChecklistEntryStatusId.IN_PROGRESS],
ProcessStepTypeId.AWAIT_CLEARING_HOUSE_RESPONSE))
.TasksToAsyncEnumerable().WithCancellation(cancellationToken))
{
checklistService.FinalizeChecklistEntryAndProcessSteps(
await context.ConfigureAwait(ConfigureAwaitOptions.None),
context,
null,
item =>
{
item.ApplicationChecklistEntryStatusId = ApplicationChecklistEntryStatusId.TO_DO;
item.Comment = "Reset to retrigger clearinghouse";
},
[ProcessStepTypeId.START_OVERRIDE_CLEARING_HOUSE]);
hasChanges = true;
}

if (hasChanges)
{
await portalRepositories.SaveAsync().ConfigureAwait(ConfigureAwaitOptions.None);
}
await portalRepositories.SaveAsync().ConfigureAwait(ConfigureAwaitOptions.None);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/********************************************************************************
* Copyright (c) 2022 Microsoft and 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 @@ -27,5 +26,5 @@ public interface IClearinghouseBusinessLogic
{
Task<IApplicationChecklistService.WorkerChecklistProcessStepExecutionResult> HandleClearinghouse(IApplicationChecklistService.WorkerChecklistProcessStepData context, CancellationToken cancellationToken);
Task ProcessEndClearinghouse(Guid applicationId, ClearinghouseResponseData data, CancellationToken cancellationToken);
Task CheckEndClearinghouseProcesses(CancellationToken stoppingToken);
Task CheckEndClearinghouseProcesses(CancellationToken cancellationToken);
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
<ProjectReference Include="..\..\portalbackend\PortalBackend.DBAccess\PortalBackend.DBAccess.csproj" />
<ProjectReference Include="..\Custodian.Library\Custodian.Library.csproj" />
<ProjectReference Include="..\..\processes\ApplicationChecklist.Library\ApplicationChecklist.Library.csproj" />
<ProjectReference Include="..\..\framework\Framework.Async\Framework.Async.csproj" />
</ItemGroup>

</Project>
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.7.0</VersionPrefix>
<VersionPrefix>2.8.0</VersionPrefix>
<VersionSuffix></VersionSuffix>
</PropertyGroup>
</Project>
34 changes: 34 additions & 0 deletions src/framework/Framework.Async/ToAsyncEnumerableExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/********************************************************************************
* Copyright (c) 2024 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/

using System.Runtime.CompilerServices;

namespace Org.Eclipse.TractusX.Portal.Backend.Framework.Async;

public static class ToAsyncEnumerableExtensions
{
public static async IAsyncEnumerable<T> TasksToAsyncEnumerable<T>(this IEnumerable<Task<T>> tasks, [EnumeratorCancellation] CancellationToken cancellationToken = default)
{
foreach (var task in tasks)
{
cancellationToken.ThrowIfCancellationRequested();
yield return await task.ConfigureAwait(ConfigureAwaitOptions.None);
}
}
}
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.7.0</VersionPrefix>
<VersionPrefix>2.8.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.7.0</VersionPrefix>
<VersionPrefix>2.8.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.7.0</VersionPrefix>
<VersionPrefix>2.8.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.7.0</VersionPrefix>
<VersionPrefix>2.8.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.7.0</VersionPrefix>
<VersionPrefix>2.8.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.7.0</VersionPrefix>
<VersionPrefix>2.8.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.7.0</VersionPrefix>
<VersionPrefix>2.8.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.7.0</VersionPrefix>
<VersionPrefix>2.8.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.7.0</VersionPrefix>
<VersionPrefix>2.8.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>2.7.0</VersionPrefix>
<VersionPrefix>2.8.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>2.7.0</VersionPrefix>
<VersionPrefix>2.8.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>2.7.0</VersionPrefix>
<VersionPrefix>2.8.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>2.7.0</VersionPrefix>
<VersionPrefix>2.8.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>2.7.0</VersionPrefix>
<VersionPrefix>2.8.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>2.7.0</VersionPrefix>
<VersionPrefix>2.8.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>2.7.0</VersionPrefix>
<VersionPrefix>2.8.0</VersionPrefix>
<VersionSuffix></VersionSuffix>
</PropertyGroup>
</Project>
20 changes: 15 additions & 5 deletions src/maintenance/Maintenance.App/Services/BatchDeleteService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@ public async Task CleanupDocuments(CancellationToken cancellationToken)
{
logger.LogInformation("Getting documents and assignments older {Days} days", _settings.DeleteIntervalInDays);
var documentRepository = portalRepositories.GetInstance<IDocumentRepository>();

var documentData = await documentRepository
.GetDocumentDataForCleanup(dateTimeProvider.OffsetNow.AddDays(-_settings.DeleteIntervalInDays))
.ConfigureAwait(ConfigureAwaitOptions.None);
.ToListAsync(cancellationToken)
.ConfigureAwait(false);
if (documentData.Count == 0)
{
logger.LogInformation("No documents to cleanup");
Expand All @@ -53,11 +55,19 @@ public async Task CleanupDocuments(CancellationToken cancellationToken)

logger.LogInformation("Cleaning up {DocumentCount} Documents and {OfferIdCount} OfferAssignedDocuments", documentData.Count, documentData.SelectMany(x => x.OfferIds).Count());

var agreementsToDeleteDocumentId = documentData.SelectMany(data => data.AgreementIds.Select(agreementId => new Agreement(agreementId, default, null!, default, default, default) { DocumentId = data.DocumentId })).ToList();
portalRepositories.AttachRange(agreementsToDeleteDocumentId);
agreementsToDeleteDocumentId.ForEach(agreement => agreement.DocumentId = null);
documentRepository.RemoveOfferAssignedDocuments(documentData.SelectMany(data => data.OfferIds.Select(offerId => new OfferAssignedDocument(offerId, data.DocumentId))));
portalRepositories.GetInstance<IAgreementRepository>().AttachAndModifyAgreements(
documentData.SelectMany(data => data.AgreementIds.Select<Guid, (Guid, Action<Agreement>?, Action<Agreement>)>(agreementId => (
agreementId,
agreement => agreement.DocumentId = data.DocumentId,
agreement => agreement.DocumentId = null))));

portalRepositories.GetInstance<IOfferRepository>().RemoveOfferAssignedDocuments(
documentData.SelectMany(data => data.OfferIds.Select(offerId => (
offerId,
data.DocumentId))));

documentRepository.RemoveDocuments(documentData.Select(x => x.DocumentId));

await portalRepositories.SaveAsync().ConfigureAwait(ConfigureAwaitOptions.None);
logger.LogInformation("Documents older than {Days} days and depending consents successfully cleaned up", _settings.DeleteIntervalInDays);
}
Expand Down
Loading

0 comments on commit 721525d

Please sign in to comment.