diff --git a/src/administration/Administration.Service/BusinessLogic/IStaticDataBusinessLogic.cs b/src/administration/Administration.Service/BusinessLogic/IStaticDataBusinessLogic.cs
index 10e39b9968..48b19ae007 100644
--- a/src/administration/Administration.Service/BusinessLogic/IStaticDataBusinessLogic.cs
+++ b/src/administration/Administration.Service/BusinessLogic/IStaticDataBusinessLogic.cs
@@ -50,4 +50,10 @@ public interface IStaticDataBusinessLogic
///
/// A list of bpns
IAsyncEnumerable GetOperatorBpns();
+
+ ///
+ /// Get all company certificates
+ ///
+ /// A list of company certificates
+ IAsyncEnumerable GetCertificateTypes();
}
diff --git a/src/administration/Administration.Service/BusinessLogic/StaticDataBusinessLogic.cs b/src/administration/Administration.Service/BusinessLogic/StaticDataBusinessLogic.cs
index 47991e2548..a2b105629f 100644
--- a/src/administration/Administration.Service/BusinessLogic/StaticDataBusinessLogic.cs
+++ b/src/administration/Administration.Service/BusinessLogic/StaticDataBusinessLogic.cs
@@ -55,4 +55,8 @@ public IAsyncEnumerable GetAllLicenseType() =>
///
public IAsyncEnumerable GetOperatorBpns() =>
_portalRepositories.GetInstance().GetOperatorBpns();
+
+ ///
+ public IAsyncEnumerable GetCertificateTypes() =>
+ _portalRepositories.GetInstance().GetCertificateTypes();
}
diff --git a/src/administration/Administration.Service/Controllers/StaticDataController.cs b/src/administration/Administration.Service/Controllers/StaticDataController.cs
index 90917a22c9..d19afab1c6 100644
--- a/src/administration/Administration.Service/Controllers/StaticDataController.cs
+++ b/src/administration/Administration.Service/Controllers/StaticDataController.cs
@@ -104,4 +104,19 @@ public IAsyncEnumerable GetLicenseTypes() =>
[ProducesResponseType(typeof(IAsyncEnumerable), StatusCodes.Status200OK)]
public IAsyncEnumerable GetOperatorBpns() =>
_logic.GetOperatorBpns();
+
+ ///
+ /// Retrieve all certificate types
+ ///
+ /// AsyncEnumerable of certificate types
+ ///
+ /// Example: GET: /api/administration/staticdata/certificateTypes
+ ///
+ /// Returns a list of all of the Language i.e german and english
+ [HttpGet]
+ [Authorize(Roles = "view_certificates")]
+ [Route("certificateTypes")]
+ [ProducesResponseType(typeof(IEnumerable), StatusCodes.Status200OK)]
+ public IAsyncEnumerable GetCertificateTypes() =>
+ _logic.GetCertificateTypes();
}
diff --git a/src/portalbackend/PortalBackend.DBAccess/Models/CompanyCertificateTypeData.cs b/src/portalbackend/PortalBackend.DBAccess/Models/CompanyCertificateTypeData.cs
new file mode 100644
index 0000000000..1f194a12d6
--- /dev/null
+++ b/src/portalbackend/PortalBackend.DBAccess/Models/CompanyCertificateTypeData.cs
@@ -0,0 +1,41 @@
+/********************************************************************************
+ * 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 Org.Eclipse.TractusX.Portal.Backend.PortalBackend.PortalEntities.Enums;
+using System.Text.Json.Serialization;
+
+namespace Org.Eclipse.TractusX.Portal.Backend.PortalBackend.DBAccess.Models;
+
+///
+/// Model for CompanyCertificateTypeData
+/// ]
+/// CompanyCertificate Type Id
+/// description
+///
+public record CompanyCertificateTypeData(
+ [property: JsonPropertyName("certificateType")] CompanyCertificateTypeId CompanyCertificateTypeId,
+ IEnumerable Description);
+
+///
+/// Model for CertificateTypeDescription
+///
+/// language
+/// long Description
+///
+public record CertificateTypeDescription(string LanguageShortName, string Description);
diff --git a/src/portalbackend/PortalBackend.DBAccess/Repositories/IStaticDataRepository.cs b/src/portalbackend/PortalBackend.DBAccess/Repositories/IStaticDataRepository.cs
index 1225ce12c0..229242f4e2 100644
--- a/src/portalbackend/PortalBackend.DBAccess/Repositories/IStaticDataRepository.cs
+++ b/src/portalbackend/PortalBackend.DBAccess/Repositories/IStaticDataRepository.cs
@@ -45,6 +45,12 @@ public interface IStaticDataRepository
/// AsyncEnumerable of the result Counties with long names
IAsyncEnumerable GetAllCountries();
+ ///
+ /// Get all Certificate Types
+ ///
+ /// AsyncEnumerable of the result Company Certificates with Long Description
+ IAsyncEnumerable GetCertificateTypes();
+
///
/// Retrieve Unique Identifier Data for Country Alpha2Code
///
diff --git a/src/portalbackend/PortalBackend.DBAccess/Repositories/StaticDataRepository.cs b/src/portalbackend/PortalBackend.DBAccess/Repositories/StaticDataRepository.cs
index d446b8689b..47b0a8bf4e 100644
--- a/src/portalbackend/PortalBackend.DBAccess/Repositories/StaticDataRepository.cs
+++ b/src/portalbackend/PortalBackend.DBAccess/Repositories/StaticDataRepository.cs
@@ -101,4 +101,16 @@ public IAsyncEnumerable GetLicenseTypeData() =>
_dbContext.LicenseTypes.AsNoTracking()
.Select(licenseType => new LicenseTypeData((int)licenseType.Id, licenseType.Label))
.AsAsyncEnumerable();
+
+ ///
+ public IAsyncEnumerable GetCertificateTypes() =>
+ _dbContext.CompanyCertificateTypes.AsNoTracking()
+ .Where(type => type.CompanyCertificateTypeAssignedStatus!.CompanyCertificateTypeStatusId == CompanyCertificateTypeStatusId.ACTIVE)
+ .Select(type => new CompanyCertificateTypeData
+ (
+ type.Id,
+ type.CompanyCertificateTypeDescriptions
+ .Select(x => new CertificateTypeDescription(x.LanguageShortName, x.Description))
+ ))
+ .AsAsyncEnumerable();
}
diff --git a/src/portalbackend/PortalBackend.PortalEntities/Entities/CompanyCertificateStatus.cs b/src/portalbackend/PortalBackend.PortalEntities/Entities/CompanyCertificateStatus.cs
index 2c29495500..a078cb5bf3 100644
--- a/src/portalbackend/PortalBackend.PortalEntities/Entities/CompanyCertificateStatus.cs
+++ b/src/portalbackend/PortalBackend.PortalEntities/Entities/CompanyCertificateStatus.cs
@@ -27,6 +27,7 @@ public class CompanyCertificateStatus
private CompanyCertificateStatus()
{
Label = null!;
+ CompanyCertificates = new HashSet();
}
public CompanyCertificateStatus(CompanyCertificateStatusId certificateStatusId) : this()
@@ -39,4 +40,8 @@ public CompanyCertificateStatus(CompanyCertificateStatusId certificateStatusId)
[MaxLength(255)]
public string Label { get; private set; }
+
+ // Navigation Properties
+
+ public virtual ICollection CompanyCertificates { get; private set; }
}
diff --git a/src/portalbackend/PortalBackend.PortalEntities/Entities/CompanyCertificateType.cs b/src/portalbackend/PortalBackend.PortalEntities/Entities/CompanyCertificateType.cs
index 74afb573cf..33678a1cfd 100644
--- a/src/portalbackend/PortalBackend.PortalEntities/Entities/CompanyCertificateType.cs
+++ b/src/portalbackend/PortalBackend.PortalEntities/Entities/CompanyCertificateType.cs
@@ -28,6 +28,7 @@ private CompanyCertificateType()
{
Label = null!;
CompanyCertificates = new HashSet();
+ CompanyCertificateTypeDescriptions = new HashSet();
}
public CompanyCertificateType(CompanyCertificateTypeId companyCertificateTypeId) : this()
@@ -45,4 +46,5 @@ public CompanyCertificateType(CompanyCertificateTypeId companyCertificateTypeId)
public virtual CompanyCertificateTypeAssignedStatus? CompanyCertificateTypeAssignedStatus { get; set; }
public virtual ICollection CompanyCertificates { get; private set; }
+ public virtual ICollection CompanyCertificateTypeDescriptions { get; private set; }
}
diff --git a/src/portalbackend/PortalBackend.PortalEntities/Entities/CompanyCertificateTypeStatus.cs b/src/portalbackend/PortalBackend.PortalEntities/Entities/CompanyCertificateTypeStatus.cs
index 89d958dbac..fab6127418 100644
--- a/src/portalbackend/PortalBackend.PortalEntities/Entities/CompanyCertificateTypeStatus.cs
+++ b/src/portalbackend/PortalBackend.PortalEntities/Entities/CompanyCertificateTypeStatus.cs
@@ -27,6 +27,7 @@ public class CompanyCertificateTypeStatus
private CompanyCertificateTypeStatus()
{
Label = null!;
+ CompanyCertificateTypeAssignedStatuses = new HashSet();
}
public CompanyCertificateTypeStatus(CompanyCertificateTypeStatusId companyCertificateTypeStatusId)
diff --git a/tests/administration/Administration.Service.Tests/BusinessLogic/InvitationBusinessLogicTests.cs b/tests/administration/Administration.Service.Tests/BusinessLogic/InvitationBusinessLogicTests.cs
index 4347aa6caf..a3edc90b15 100644
--- a/tests/administration/Administration.Service.Tests/BusinessLogic/InvitationBusinessLogicTests.cs
+++ b/tests/administration/Administration.Service.Tests/BusinessLogic/InvitationBusinessLogicTests.cs
@@ -72,7 +72,7 @@ public InvitationBusinessLogicTests()
_mailingService = A.Fake();
_options = A.Fake>();
- _companyName = _fixture.Create();
+ _companyName = "testCompany";
_idpName = _fixture.Create();
_companyId = _fixture.Create();
_identityProviderId = _fixture.Create();
diff --git a/tests/administration/Administration.Service.Tests/BusinessLogic/StaticDataBusinessLogicTest.cs b/tests/administration/Administration.Service.Tests/BusinessLogic/StaticDataBusinessLogicTest.cs
index da04a65411..bb73469459 100644
--- a/tests/administration/Administration.Service.Tests/BusinessLogic/StaticDataBusinessLogicTest.cs
+++ b/tests/administration/Administration.Service.Tests/BusinessLogic/StaticDataBusinessLogicTest.cs
@@ -118,6 +118,26 @@ public async Task GetAllLanguages_ReturnsExpectedResult()
result.Should().HaveCount(3).And.ContainInOrder(data);
}
+ [Fact]
+ public async Task GetCertificateTypes_ReturnsExpectedResult()
+ {
+ // Arrange
+ var data = _fixture.CreateMany(12).ToImmutableArray();
+
+ A.CallTo(() => _staticDataRepository.GetCertificateTypes())
+ .Returns(data.ToAsyncEnumerable());
+
+ var sut = new StaticDataBusinessLogic(_portalRepositories);
+
+ // Act
+ var result = await sut.GetCertificateTypes().ToListAsync().ConfigureAwait(false);
+
+ // Assert
+ A.CallTo(() => _staticDataRepository.GetCertificateTypes())
+ .MustHaveHappenedOnceExactly();
+ result.Should().HaveCount(12).And.ContainInOrder(data);
+ }
+
[Fact]
public async Task GetOperatorBpns_ReturnsExpectedResult()
{
diff --git a/tests/administration/Administration.Service.Tests/Controllers/StaticDataControllerTest.cs b/tests/administration/Administration.Service.Tests/Controllers/StaticDataControllerTest.cs
index 86a0f6be3a..9f2620a0ff 100644
--- a/tests/administration/Administration.Service.Tests/Controllers/StaticDataControllerTest.cs
+++ b/tests/administration/Administration.Service.Tests/Controllers/StaticDataControllerTest.cs
@@ -98,4 +98,20 @@ public async Task GetOperatorBpns_ReturnsExpectedResult()
A.CallTo(() => _logic.GetOperatorBpns()).MustHaveHappenedOnceExactly();
result.Should().HaveCount(5).And.AllBeOfType();
}
+
+ [Fact]
+ public async Task GetCertificateTypes_ReturnsExpectedResult()
+ {
+ //Arrange
+ var data = _fixture.CreateMany(5).ToAsyncEnumerable();
+ A.CallTo(() => _logic.GetCertificateTypes())
+ .Returns(data);
+
+ //Act
+ var result = await _controller.GetCertificateTypes().ToListAsync().ConfigureAwait(false);
+
+ // Assert
+ A.CallTo(() => _logic.GetCertificateTypes()).MustHaveHappenedOnceExactly();
+ result.Should().HaveCount(5).And.AllBeOfType();
+ }
}
diff --git a/tests/portalbackend/PortalBackend.DBAccess.Tests/StaticDataRepositoryTest.cs b/tests/portalbackend/PortalBackend.DBAccess.Tests/StaticDataRepositoryTest.cs
index aadd13c601..57bbbb926e 100644
--- a/tests/portalbackend/PortalBackend.DBAccess.Tests/StaticDataRepositoryTest.cs
+++ b/tests/portalbackend/PortalBackend.DBAccess.Tests/StaticDataRepositoryTest.cs
@@ -21,6 +21,7 @@
using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.DBAccess.Models;
using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.DBAccess.Repositories;
using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.DBAccess.Tests.Setup;
+using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.PortalEntities;
using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.PortalEntities.Enums;
using Xunit.Extensions.AssemblyFixture;
@@ -156,6 +157,50 @@ public async Task GetAllLanguages_ReturnsExpected()
#endregion
+ #region GetCertificateTypes
+
+ [Fact]
+ public async Task GetCertificateTypes_ReturnsExpectedResult()
+ {
+ // Arrange
+ var sut = await CreateSut().ConfigureAwait(false);
+
+ // Act
+ var results = await sut.GetCertificateTypes().ToListAsync().ConfigureAwait(false);
+
+ // Assert
+ results.Should().HaveCount(12);
+ }
+
+ [Fact]
+ public async Task GetCertificateTypes_WithInactiveCertificateType_ReturnsExpectedResult()
+ {
+ // Arrange
+ var (context, sut) = await CreateSutWithContext().ConfigureAwait(false);
+ var active = new CompanyCertificateTypeAssignedStatus(CompanyCertificateTypeId.ISO_15504_SPICE, CompanyCertificateTypeStatusId.ACTIVE);
+ var inactive = new CompanyCertificateTypeAssignedStatus(CompanyCertificateTypeId.ISO_15504_SPICE, CompanyCertificateTypeStatusId.INACTVIE);
+ context.Remove(active);
+ context.Add(inactive);
+ await context.SaveChangesAsync().ConfigureAwait(false);
+
+ try
+ {
+ // Act
+ var results = await sut.GetCertificateTypes().ToListAsync().ConfigureAwait(false);
+
+ // Assert
+ results.Should().HaveCount(11);
+ }
+ finally
+ {
+ context.Remove(inactive);
+ context.Add(active);
+ await context.SaveChangesAsync().ConfigureAwait(false);
+ }
+ }
+
+ #endregion
+
#region setup
private async Task CreateSut()
@@ -165,5 +210,12 @@ private async Task CreateSut()
return sut;
}
+ private async Task<(PortalDbContext, StaticDataRepository)> CreateSutWithContext()
+ {
+ var context = await _dbTestDbFixture.GetPortalDbContext().ConfigureAwait(false);
+ var sut = new StaticDataRepository(context);
+ return (context, sut);
+ }
+
#endregion
}