Skip to content

Commit

Permalink
feat(processes): use process package (#145)
Browse files Browse the repository at this point in the history
Refs: #3
Reviewed-By: Evelyn Gurschler <[email protected]>
  • Loading branch information
Phil91 authored Feb 5, 2025
1 parent c68d4f2 commit 17eb127
Show file tree
Hide file tree
Showing 62 changed files with 985 additions and 3,997 deletions.
1 change: 0 additions & 1 deletion docker/Dockerfile-dim-migrations
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ ARG TARGETARCH
WORKDIR /
COPY LICENSE /
COPY /src/database /src/database
COPY /src/processes/Processes.Worker.Library /src/processes/Processes.Worker.Library
WORKDIR /src/database/Dim.Migrations
RUN dotnet publish "Dim.Migrations.csproj" -c Release -o /migrations/publish

Expand Down
28 changes: 0 additions & 28 deletions src/Dim.sln
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "clients", "clients", "{B84A
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dim.Clients", "clients\Dim.Clients\Dim.Clients.csproj", "{8356C7AF-6F88-4A62-B3E9-5656634A6FEA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Processes.Library", "processes\Processes.Library\Processes.Library.csproj", "{BFDDFCF5-8F35-4348-A568-57D8E34DF289}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Processes.Worker", "processes\Processes.Worker\Processes.Worker.csproj", "{E5F65B6F-BD8F-4FAF-80A2-69C9DA20DCC2}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Processes.Worker.Library", "processes\Processes.Worker.Library\Processes.Worker.Library.csproj", "{4F40B8F2-12D4-403B-B666-8F0540354455}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "database", "database", "{4A305F87-23B4-4929-B138-4B7D2710526F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dim.DbAccess", "database\Dim.DbAccess\Dim.DbAccess.csproj", "{6984539B-7B5A-481E-A955-3AE537D43166}"
Expand All @@ -30,10 +26,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dim.Web", "web\Dim.Web\Dim.
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{CB1B7D43-9AFC-47EF-8915-A547F7F553AB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Processes.Library.Tests", "..\tests\processes\Processes.Library.Tests\Processes.Library.Tests.csproj", "{AA29EECC-CD77-4452-B48E-CC038E4FBB69}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Processes.Worker.Library.Tests", "..\tests\processes\Processes.Worker.Library.Tests\Processes.Worker.Library.Tests.csproj", "{9888C703-CC13-47EB-89F0-B8A34D64BD07}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tests.Shared", "..\tests\shared\Tests.Shared\Tests.Shared.csproj", "{0D288AF0-1CE5-4B2B-9F80-532040F24BCF}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DimProcess.Executor.Tests", "..\tests\processes\DimProcess.Executor.Tests\DimProcess.Executor.Tests.csproj", "{A44447B0-794D-451A-A571-E3B761174B48}"
Expand All @@ -56,18 +48,10 @@ Global
{8356C7AF-6F88-4A62-B3E9-5656634A6FEA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8356C7AF-6F88-4A62-B3E9-5656634A6FEA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8356C7AF-6F88-4A62-B3E9-5656634A6FEA}.Release|Any CPU.Build.0 = Release|Any CPU
{BFDDFCF5-8F35-4348-A568-57D8E34DF289}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BFDDFCF5-8F35-4348-A568-57D8E34DF289}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BFDDFCF5-8F35-4348-A568-57D8E34DF289}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BFDDFCF5-8F35-4348-A568-57D8E34DF289}.Release|Any CPU.Build.0 = Release|Any CPU
{E5F65B6F-BD8F-4FAF-80A2-69C9DA20DCC2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E5F65B6F-BD8F-4FAF-80A2-69C9DA20DCC2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E5F65B6F-BD8F-4FAF-80A2-69C9DA20DCC2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E5F65B6F-BD8F-4FAF-80A2-69C9DA20DCC2}.Release|Any CPU.Build.0 = Release|Any CPU
{4F40B8F2-12D4-403B-B666-8F0540354455}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4F40B8F2-12D4-403B-B666-8F0540354455}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4F40B8F2-12D4-403B-B666-8F0540354455}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4F40B8F2-12D4-403B-B666-8F0540354455}.Release|Any CPU.Build.0 = Release|Any CPU
{6984539B-7B5A-481E-A955-3AE537D43166}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6984539B-7B5A-481E-A955-3AE537D43166}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6984539B-7B5A-481E-A955-3AE537D43166}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand All @@ -92,14 +76,6 @@ Global
{1B50DC13-DB8A-41CF-9D40-A8740B068AC2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1B50DC13-DB8A-41CF-9D40-A8740B068AC2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1B50DC13-DB8A-41CF-9D40-A8740B068AC2}.Release|Any CPU.Build.0 = Release|Any CPU
{AA29EECC-CD77-4452-B48E-CC038E4FBB69}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AA29EECC-CD77-4452-B48E-CC038E4FBB69}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AA29EECC-CD77-4452-B48E-CC038E4FBB69}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AA29EECC-CD77-4452-B48E-CC038E4FBB69}.Release|Any CPU.Build.0 = Release|Any CPU
{9888C703-CC13-47EB-89F0-B8A34D64BD07}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9888C703-CC13-47EB-89F0-B8A34D64BD07}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9888C703-CC13-47EB-89F0-B8A34D64BD07}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9888C703-CC13-47EB-89F0-B8A34D64BD07}.Release|Any CPU.Build.0 = Release|Any CPU
{0D288AF0-1CE5-4B2B-9F80-532040F24BCF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0D288AF0-1CE5-4B2B-9F80-532040F24BCF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0D288AF0-1CE5-4B2B-9F80-532040F24BCF}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down Expand Up @@ -127,17 +103,13 @@ Global
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{8356C7AF-6F88-4A62-B3E9-5656634A6FEA} = {B84A3CAB-AC86-4B2D-A490-79E1002350FF}
{BFDDFCF5-8F35-4348-A568-57D8E34DF289} = {30AA679F-7CF6-4FBE-9A13-BEF98BCFE3D2}
{E5F65B6F-BD8F-4FAF-80A2-69C9DA20DCC2} = {30AA679F-7CF6-4FBE-9A13-BEF98BCFE3D2}
{4F40B8F2-12D4-403B-B666-8F0540354455} = {30AA679F-7CF6-4FBE-9A13-BEF98BCFE3D2}
{6984539B-7B5A-481E-A955-3AE537D43166} = {4A305F87-23B4-4929-B138-4B7D2710526F}
{0A85DB84-41A0-4EE0-815B-D922329A8BCA} = {4A305F87-23B4-4929-B138-4B7D2710526F}
{41AA384E-E433-440E-A02E-83F03AC98A63} = {30AA679F-7CF6-4FBE-9A13-BEF98BCFE3D2}
{F14C5E02-DC54-4A27-B2DE-513A644E6473} = {30AA679F-7CF6-4FBE-9A13-BEF98BCFE3D2}
{1621A06B-9AF2-421C-BB48-08028560E108} = {4A305F87-23B4-4929-B138-4B7D2710526F}
{1B50DC13-DB8A-41CF-9D40-A8740B068AC2} = {D20B95EF-D7D9-45BA-B5A4-C8D3B64AC745}
{AA29EECC-CD77-4452-B48E-CC038E4FBB69} = {CB1B7D43-9AFC-47EF-8915-A547F7F553AB}
{9888C703-CC13-47EB-89F0-B8A34D64BD07} = {CB1B7D43-9AFC-47EF-8915-A547F7F553AB}
{0D288AF0-1CE5-4B2B-9F80-532040F24BCF} = {CB1B7D43-9AFC-47EF-8915-A547F7F553AB}
{A44447B0-794D-451A-A571-E3B761174B48} = {CB1B7D43-9AFC-47EF-8915-A547F7F553AB}
{85D316A0-17BE-4983-AB06-5C72365ABD9B} = {CB1B7D43-9AFC-47EF-8915-A547F7F553AB}
Expand Down
6 changes: 3 additions & 3 deletions src/clients/Dim.Clients/Dim.Clients.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@
<PackageReference Include="Microsoft.Extensions.Options" Version="8.0.2" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Options.DataAnnotations" Version="8.0.0" />
<PackageReference Include="Org.Eclipse.TractusX.Portal.Backend.Framework.DependencyInjection" Version="2.13.0" />
<PackageReference Include="Org.Eclipse.TractusX.Portal.Backend.Framework.ErrorHandling" Version="2.13.0" />
<PackageReference Include="Org.Eclipse.TractusX.Portal.Backend.Framework.HttpClientExtensions" Version="2.13.0" />
<PackageReference Include="Org.Eclipse.TractusX.Portal.Backend.Framework.DependencyInjection" Version="2.14.0" />
<PackageReference Include="Org.Eclipse.TractusX.Portal.Backend.Framework.ErrorHandling" Version="2.14.0" />
<PackageReference Include="Org.Eclipse.TractusX.Portal.Backend.Framework.HttpClientExtensions" Version="2.14.0" />
</ItemGroup>

</Project>
4 changes: 2 additions & 2 deletions src/database/Dim.DbAccess/Dim.DbAccess.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks.EntityFrameworkCore" Version="8.0.11" />
<PackageReference Include="Org.Eclipse.TractusX.Portal.Backend.Framework.DependencyInjection" Version="2.13.0" />
<PackageReference Include="Org.Eclipse.TractusX.Portal.Backend.Framework.ErrorHandling" Version="2.13.0" />
<PackageReference Include="Org.Eclipse.TractusX.Portal.Backend.Framework.DependencyInjection" Version="2.14.0" />
<PackageReference Include="Org.Eclipse.TractusX.Portal.Backend.Framework.ErrorHandling" Version="2.14.0" />
</ItemGroup>

<ItemGroup>
Expand Down
40 changes: 40 additions & 0 deletions src/database/Dim.DbAccess/DimProcessDbContextAccess.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/********************************************************************************
* Copyright (c) 2025 BMW Group AG
* Copyright 2025 SAP SE or an SAP affiliate company and ssi-dim-middle-layer contributors.
*
* 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 Dim.Entities;
using Dim.Entities.Entities;
using Dim.Entities.Enums;
using Microsoft.EntityFrameworkCore;
using Org.Eclipse.TractusX.Portal.Backend.Framework.Processes.Library.Concrete.Entities;
using Org.Eclipse.TractusX.Portal.Backend.Framework.Processes.Library.DBAccess;
using Org.Eclipse.TractusX.Portal.Backend.Framework.Processes.Library.Enums;

namespace Dim.DbAccess;

public class DimProcessDbContextAccess(DimDbContext dbContext) :
IProcessRepositoryContextAccess<Process, ProcessType<Process, ProcessTypeId>, ProcessStep<Process, ProcessTypeId, ProcessStepTypeId>, ProcessStepType<Process, ProcessTypeId, ProcessStepTypeId>, ProcessTypeId, ProcessStepTypeId>
{
public DbSet<Process> Processes => dbContext.Processes;
public DbSet<ProcessStep<Process, ProcessTypeId, ProcessStepTypeId>> ProcessSteps => dbContext.ProcessSteps;
public DbSet<ProcessStepStatus<Process, ProcessTypeId, ProcessStepTypeId>> ProcessStepStatuses => dbContext.ProcessStepStatuses;

public Process CreateProcess(Guid id, ProcessTypeId processTypeId, Guid version) => new(id, processTypeId, version);
public ProcessStep<Process, ProcessTypeId, ProcessStepTypeId> CreateProcessStep(Guid id, ProcessStepTypeId processStepTypeId, ProcessStepStatusId processStepStatusId, Guid processId, DateTimeOffset now) => new(id, processStepTypeId, processStepStatusId, processId, now);
}
60 changes: 16 additions & 44 deletions src/database/Dim.DbAccess/DimRepositories.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,53 +20,25 @@

using Dim.DbAccess.Repositories;
using Dim.Entities;
using Microsoft.EntityFrameworkCore;
using Org.Eclipse.TractusX.Portal.Backend.Framework.ErrorHandling;
using Dim.Entities.Entities;
using Dim.Entities.Enums;
using Org.Eclipse.TractusX.Portal.Backend.Framework.DBAccess;
using Org.Eclipse.TractusX.Portal.Backend.Framework.Processes.Library.Concrete.Entities;
using Org.Eclipse.TractusX.Portal.Backend.Framework.Processes.Library.DBAccess;
using System.Collections.Immutable;

namespace Dim.DbAccess;

public class DimRepositories(DimDbContext dbContext)
: IDimRepositories
public class DimRepositories(DimDbContext dbContext) :
AbstractRepositories<DimDbContext>(dbContext),
IDimRepositories
{
private static readonly IReadOnlyDictionary<Type, Func<DimDbContext, object>> Types = new Dictionary<Type, Func<DimDbContext, object>> {
{ typeof(IProcessStepRepository), context => new ProcessStepRepository(context) },
{ typeof(ITenantRepository), context => new TenantRepository(context) },
{ typeof(ITechnicalUserRepository), context => new TechnicalUserRepository(context) }
}.ToImmutableDictionary();

public RepositoryType GetInstance<RepositoryType>()
{
object? repository = default;

if (Types.TryGetValue(typeof(RepositoryType), out var createFunc))
{
repository = createFunc(dbContext);
}

return (RepositoryType)(repository ?? throw new ArgumentException($"unexpected type {typeof(RepositoryType).Name}", nameof(RepositoryType)));
}

/// <inheritdoc />
public TEntity Attach<TEntity>(TEntity entity, Action<TEntity>? setOptionalParameters = null) where TEntity : class
{
var attachedEntity = dbContext.Attach(entity).Entity;
setOptionalParameters?.Invoke(attachedEntity);

return attachedEntity;
}

public Task<int> SaveAsync()
{
try
{
return dbContext.SaveChangesAsync();
}
catch (DbUpdateConcurrencyException e)
{
throw new ConflictException("while processing a concurrent update was saved to the database (reason could also be data to be deleted is no longer existing)", e);
}
}

public void Clear() => dbContext.ChangeTracker.Clear();
protected override IReadOnlyDictionary<Type, Func<DimDbContext, object>> RepositoryTypes => Types;

private static readonly IReadOnlyDictionary<Type, Func<DimDbContext, object>> Types = ImmutableDictionary.CreateRange(
[
CreateTypeEntry<ITenantRepository>(context => new TenantRepository(context)),
CreateTypeEntry<ITechnicalUserRepository>(context => new TechnicalUserRepository(context)),
CreateTypeEntry<IProcessStepRepository<ProcessTypeId, ProcessStepTypeId>>(context => new ProcessStepRepository<Process, ProcessType<Process, ProcessTypeId>, ProcessStep<Process, ProcessTypeId, ProcessStepTypeId>, ProcessStepType<Process, ProcessTypeId, ProcessStepTypeId>, ProcessTypeId, ProcessStepTypeId>(new DimProcessDbContextAccess(context))),
]);
}
10 changes: 3 additions & 7 deletions src/database/Dim.DbAccess/IDimRepositories.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,8 @@
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/

using Org.Eclipse.TractusX.Portal.Backend.Framework.DBAccess;

namespace Dim.DbAccess;

public interface IDimRepositories
{
RepositoryType GetInstance<RepositoryType>();
TEntity Attach<TEntity>(TEntity entity, Action<TEntity>? setOptionalParameters = null) where TEntity : class;
Task<int> SaveAsync();
void Clear();
}
public interface IDimRepositories : IRepositories;
1 change: 1 addition & 0 deletions src/database/Dim.DbAccess/Models/ProcessData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
********************************************************************************/

using Dim.Entities.Enums;
using Org.Eclipse.TractusX.Portal.Backend.Framework.Processes.Library.Enums;

namespace Dim.DbAccess.Models;

Expand Down
28 changes: 0 additions & 28 deletions src/database/Dim.DbAccess/Models/VerifyProcessData.cs

This file was deleted.

40 changes: 0 additions & 40 deletions src/database/Dim.DbAccess/Repositories/IProcessStepRepository.cs

This file was deleted.

Loading

0 comments on commit 17eb127

Please sign in to comment.