From 7ee1e76d9c74c2dd1511ae900c50e0f1da10c0c2 Mon Sep 17 00:00:00 2001 From: Phil Schneider Date: Thu, 23 Nov 2023 17:08:55 +0100 Subject: [PATCH] feat(seeding): add purpose policies Refs: CPLP-3362 --- .../Models/PolicyTypeResponse.cs | 1 - .../Repositories/PolicyRepository.cs | 1 - .../Seeder/Data/policies.json | 16 ++++++++++++---- .../Seeder/Data/policy_assigned_types.json | 3 ++- .../Seeder/Data/policy_assigned_use_cases.json | 7 ++----- src/hub/PolicyHub.Service/Program.cs | 9 +++++++++ 6 files changed, 25 insertions(+), 12 deletions(-) diff --git a/src/database/PolicyHub.DbAccess/Models/PolicyTypeResponse.cs b/src/database/PolicyHub.DbAccess/Models/PolicyTypeResponse.cs index 181092d..5a691c6 100644 --- a/src/database/PolicyHub.DbAccess/Models/PolicyTypeResponse.cs +++ b/src/database/PolicyHub.DbAccess/Models/PolicyTypeResponse.cs @@ -23,7 +23,6 @@ namespace Org.Eclipse.TractusX.PolicyHub.DbAccess.Models; public record PolicyTypeResponse ( - PolicyKindId Name, string TechnicalKey, IEnumerable Type, string Description, diff --git a/src/database/PolicyHub.DbAccess/Repositories/PolicyRepository.cs b/src/database/PolicyHub.DbAccess/Repositories/PolicyRepository.cs index f4131f4..e641638 100644 --- a/src/database/PolicyHub.DbAccess/Repositories/PolicyRepository.cs +++ b/src/database/PolicyHub.DbAccess/Repositories/PolicyRepository.cs @@ -44,7 +44,6 @@ public IAsyncEnumerable GetPolicyTypes(PolicyTypeId? type, U (type == null || p.Types.Any(x => x.Id == type)) && (useCase == null || p.UseCases.Any(x => x.Id == useCase))) .Select(p => new PolicyTypeResponse( - p.KindId, p.TechnicalKey, p.Types.Where(t => t.IsActive).Select(t => t.Id), p.Description, diff --git a/src/database/PolicyHub.Migrations/Seeder/Data/policies.json b/src/database/PolicyHub.Migrations/Seeder/Data/policies.json index 663c9cd..0a04146 100644 --- a/src/database/PolicyHub.Migrations/Seeder/Data/policies.json +++ b/src/database/PolicyHub.Migrations/Seeder/Data/policies.json @@ -50,16 +50,16 @@ { "id": "01a0fba3-9b6e-435a-b045-e0e890c300b7", "kind_id": 4, - "technical_key": "purpose", - "description": "tbd", + "technical_key": "purpose.trace.v1.TraceBattery", + "description": "Facilitating compliance with mandatory regulatory requirements for tracking and reporting battery cells, modules & high-voltage batteries.", "is_active": true, "attribute_key_id": 2 }, { "id": "01a0fba3-9b6e-435a-b045-e0e890c300b8", "kind_id": 4, - "technical_key": "purpose", - "description": "tbd", + "technical_key": "purpose.trace.v1.aspects", + "description": "Establishing a digital representation of the automotive supply chain to enable a component specific data exchange.", "is_active": true, "attribute_key_id": 3 }, @@ -71,5 +71,13 @@ "description": "tbd", "is_active": true, "attribute_key_id": 4 + }, + { + "id": "01a0fba3-9b6e-435a-b045-e0e890c300c1", + "kind_id": 4, + "technical_key": "purpose.trace.v1.qualityanalysis", + "description": " The data can be used for quality analysis to identify and select affected components and to send quality notifications to affected customers or suppliers.", + "is_active": true, + "attribute_key_id": 3 } ] \ No newline at end of file diff --git a/src/database/PolicyHub.Migrations/Seeder/Data/policy_assigned_types.json b/src/database/PolicyHub.Migrations/Seeder/Data/policy_assigned_types.json index 7021c66..8e43e45 100644 --- a/src/database/PolicyHub.Migrations/Seeder/Data/policy_assigned_types.json +++ b/src/database/PolicyHub.Migrations/Seeder/Data/policy_assigned_types.json @@ -10,5 +10,6 @@ { "policy_id": "01a0fba3-9b6e-435a-b045-e0e890c300b7", "policy_type_id": 2, "is_active": true }, { "policy_id": "01a0fba3-9b6e-435a-b045-e0e890c300b8", "policy_type_id": 2, "is_active": true }, { "policy_id": "01a0fba3-9b6e-435a-b045-e0e890c300b9", "policy_type_id": 1, "is_active": true }, - { "policy_id": "01a0fba3-9b6e-435a-b045-e0e890c300b9", "policy_type_id": 2, "is_active": true } + { "policy_id": "01a0fba3-9b6e-435a-b045-e0e890c300b9", "policy_type_id": 2, "is_active": true }, + { "policy_id": "01a0fba3-9b6e-435a-b045-e0e890c300c1", "policy_type_id": 2, "is_active": true } ] \ No newline at end of file diff --git a/src/database/PolicyHub.Migrations/Seeder/Data/policy_assigned_use_cases.json b/src/database/PolicyHub.Migrations/Seeder/Data/policy_assigned_use_cases.json index e202b49..1346268 100644 --- a/src/database/PolicyHub.Migrations/Seeder/Data/policy_assigned_use_cases.json +++ b/src/database/PolicyHub.Migrations/Seeder/Data/policy_assigned_use_cases.json @@ -15,13 +15,10 @@ { "policy_id": "01a0fba3-9b6e-435a-b045-e0e890c300b6", "use_case_id": 4, "is_active": true }, { "policy_id": "01a0fba3-9b6e-435a-b045-e0e890c300b7", "use_case_id": 1, "is_active": true }, { "policy_id": "01a0fba3-9b6e-435a-b045-e0e890c300b8", "use_case_id": 1, "is_active": true }, - { "policy_id": "01a0fba3-9b6e-435a-b045-e0e890c300b8", "use_case_id": 2, "is_active": true }, - { "policy_id": "01a0fba3-9b6e-435a-b045-e0e890c300b8", "use_case_id": 3, "is_active": true }, - { "policy_id": "01a0fba3-9b6e-435a-b045-e0e890c300b8", "use_case_id": 4, "is_active": true }, - { "policy_id": "01a0fba3-9b6e-435a-b045-e0e890c300b8", "use_case_id": 5, "is_active": true }, { "policy_id": "01a0fba3-9b6e-435a-b045-e0e890c300b9", "use_case_id": 1, "is_active": true }, { "policy_id": "01a0fba3-9b6e-435a-b045-e0e890c300b9", "use_case_id": 2, "is_active": true }, { "policy_id": "01a0fba3-9b6e-435a-b045-e0e890c300b9", "use_case_id": 3, "is_active": true }, { "policy_id": "01a0fba3-9b6e-435a-b045-e0e890c300b9", "use_case_id": 4, "is_active": true }, - { "policy_id": "01a0fba3-9b6e-435a-b045-e0e890c300b9", "use_case_id": 5, "is_active": true } + { "policy_id": "01a0fba3-9b6e-435a-b045-e0e890c300b9", "use_case_id": 5, "is_active": true }, + { "policy_id": "01a0fba3-9b6e-435a-b045-e0e890c300c1", "use_case_id": 1, "is_active": true } ] \ No newline at end of file diff --git a/src/hub/PolicyHub.Service/Program.cs b/src/hub/PolicyHub.Service/Program.cs index 781185a..313c360 100644 --- a/src/hub/PolicyHub.Service/Program.cs +++ b/src/hub/PolicyHub.Service/Program.cs @@ -21,6 +21,7 @@ using Org.Eclipse.TractusX.PolicyHub.Service.Authentication; using Org.Eclipse.TractusX.PolicyHub.Service.Controllers; using Org.Eclipse.TractusX.Portal.Backend.Framework.Web; +using System.Text.Json.Serialization; const string Version = "v2"; @@ -30,6 +31,14 @@ { builder.Services.AddEndpointsApiExplorer(); builder.Services.AddHubRepositories(builder.Configuration); + builder.Services.ConfigureHttpJsonOptions(options => + { + options.SerializerOptions.Converters.Add(new JsonStringEnumConverter()); + }); + builder.Services.Configure(options => + { + options.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter()); + }); }, (app, _) => {