diff --git a/src/database/PolicyHub.DbAccess/Repositories/PolicyRepository.cs b/src/database/PolicyHub.DbAccess/Repositories/PolicyRepository.cs index 96ceaa2..6957b04 100644 --- a/src/database/PolicyHub.DbAccess/Repositories/PolicyRepository.cs +++ b/src/database/PolicyHub.DbAccess/Repositories/PolicyRepository.cs @@ -35,8 +35,9 @@ public IAsyncEnumerable GetAttributeKeys() => public IAsyncEnumerable GetPolicyTypes(PolicyTypeId? type, UseCaseId? useCase) => dbContext.Policies .Where(p => - (type == null || p.Types.Any(x => x.Id == type)) && - (useCase == null || p.UseCases.Any(x => x.Id == useCase))) + p.IsActive && + (type == null || p.Types.Any(x => x.Id == type && x.IsActive)) && + (useCase == null || p.UseCases.Any(x => x.Id == useCase && x.IsActive))) .Select(p => new PolicyTypeResponse( p.TechnicalKey, p.Types.Where(t => t.IsActive).Select(t => t.Id), @@ -50,13 +51,21 @@ public IAsyncEnumerable GetPolicyTypes(PolicyTypeId? type, U public Task<(bool Exists, string LeftOperand, (AttributeKeyId? Key, IEnumerable Values) Attributes, string? RightOperandValue)> GetPolicyContentAsync(UseCaseId? useCase, PolicyTypeId type, string credential) => dbContext.Policies .Where(p => + p.IsActive && p.Types.Any(t => t.IsActive && t.Id == type) && - (useCase == null || p.UseCases.Any(x => x.Id == useCase)) && + (useCase == null || p.UseCases.Any(x => x.Id == useCase && x.IsActive)) && p.TechnicalKey == credential) .Select(p => new ValueTuple>, string?>( true, p.LeftOperandValue ?? p.TechnicalKey, - new ValueTuple>(p.AttributeKeyId, p.AttributeKey!.PolicyAttributes.Where(pa => pa.IsActive && pa.PolicyId == p.Id).Select(a => a.AttributeValue)), + new ValueTuple>( + p.AttributeKeyId, + p.AttributeKey!.PolicyAttributes.Where(pa => + pa.IsActive && + pa.PolicyId == p.Id && + pa.IsActive && + (useCase == null || pa.PolicyAttributeAssignedUseCases.Any(x => x.UseCaseId == useCase && x.IsActive)) + ).Select(a => a.AttributeValue)), p.PolicyKind!.Configuration!.RightOperandValue )) .FirstOrDefaultAsync(); @@ -64,6 +73,7 @@ public IAsyncEnumerable GetPolicyTypes(PolicyTypeId? type, U public IAsyncEnumerable<(string TechnicalKey, string LeftOperand, (AttributeKeyId? Key, IEnumerable Values) Attributes, string? RightOperandValue)> GetPolicyForOperandContent(PolicyTypeId type, IEnumerable technicalKeys) => dbContext.Policies .Where(p => + p.IsActive && p.Types.Any(t => t.IsActive && t.Id == type) && technicalKeys.Contains(p.TechnicalKey)) .Select(p => new ValueTuple>, string?>( diff --git a/src/database/PolicyHub.Entities/Entities/IActiveEntity.cs b/src/database/PolicyHub.Entities/Entities/IActiveEntity.cs new file mode 100644 index 0000000..f95f029 --- /dev/null +++ b/src/database/PolicyHub.Entities/Entities/IActiveEntity.cs @@ -0,0 +1,6 @@ +namespace Org.Eclipse.TractusX.PolicyHub.Entities.Entities; + +public interface IActiveEntity +{ + bool IsActive { get; set; } +} diff --git a/src/database/PolicyHub.Entities/Entities/Policy.cs b/src/database/PolicyHub.Entities/Entities/Policy.cs index 98f410d..356a325 100644 --- a/src/database/PolicyHub.Entities/Entities/Policy.cs +++ b/src/database/PolicyHub.Entities/Entities/Policy.cs @@ -21,7 +21,7 @@ namespace Org.Eclipse.TractusX.PolicyHub.Entities.Entities; -public class Policy +public class Policy : IActiveEntity { private Policy() { diff --git a/src/database/PolicyHub.Entities/Entities/PolicyAttribute.cs b/src/database/PolicyHub.Entities/Entities/PolicyAttribute.cs index 2cfbffb..07830c7 100644 --- a/src/database/PolicyHub.Entities/Entities/PolicyAttribute.cs +++ b/src/database/PolicyHub.Entities/Entities/PolicyAttribute.cs @@ -21,30 +21,35 @@ namespace Org.Eclipse.TractusX.PolicyHub.Entities.Entities; -public class PolicyAttribute +public class PolicyAttribute : IActiveEntity { private PolicyAttribute() { AttributeValue = null!; + PolicyAttributeAssignedUseCases = new HashSet(); } - public PolicyAttribute(Guid policyId, AttributeKeyId key, string attributeValue) + public PolicyAttribute(Guid id, Guid policyId, AttributeKeyId key, string attributeValue) : this() { + Id = id; PolicyId = policyId; Key = key; AttributeValue = attributeValue; } - public Guid PolicyId { get; private set; } + public Guid Id { get; set; } + public Guid PolicyId { get; set; } - public AttributeKeyId Key { get; private set; } + public AttributeKeyId Key { get; set; } - public string AttributeValue { get; private set; } + public string AttributeValue { get; set; } public bool IsActive { get; set; } public virtual Policy? Policy { get; private set; } public virtual AttributeKey? AttributeKey { get; private set; } + + public virtual ICollection PolicyAttributeAssignedUseCases { get; private set; } } diff --git a/src/database/PolicyHub.Entities/Entities/PolicyAttributeAssignedUseCases.cs b/src/database/PolicyHub.Entities/Entities/PolicyAttributeAssignedUseCases.cs new file mode 100644 index 0000000..d32d1f2 --- /dev/null +++ b/src/database/PolicyHub.Entities/Entities/PolicyAttributeAssignedUseCases.cs @@ -0,0 +1,47 @@ +/******************************************************************************** + * 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.PolicyHub.Entities.Enums; + +namespace Org.Eclipse.TractusX.PolicyHub.Entities.Entities; + +public class PolicyAttributeAssignedUseCases +{ + private PolicyAttributeAssignedUseCases() + { + PolicyAttribute = null!; + UseCase = null!; + } + + public PolicyAttributeAssignedUseCases(Guid attributeId, UseCaseId useCaseId) + : this() + { + AttributeId = attributeId; + UseCaseId = useCaseId; + } + + public Guid AttributeId { get; set; } + + public UseCaseId UseCaseId { get; set; } + + public bool IsActive { get; set; } + + public virtual PolicyAttribute? PolicyAttribute { get; private set; } + public virtual UseCase? UseCase { get; private set; } +} diff --git a/src/database/PolicyHub.Entities/Entities/PolicyType.cs b/src/database/PolicyHub.Entities/Entities/PolicyType.cs index c33f9eb..171011d 100644 --- a/src/database/PolicyHub.Entities/Entities/PolicyType.cs +++ b/src/database/PolicyHub.Entities/Entities/PolicyType.cs @@ -21,7 +21,7 @@ namespace Org.Eclipse.TractusX.PolicyHub.Entities.Entities; -public class PolicyType +public class PolicyType : IActiveEntity { private PolicyType() { diff --git a/src/database/PolicyHub.Entities/Entities/UseCase.cs b/src/database/PolicyHub.Entities/Entities/UseCase.cs index 5849811..166a5a4 100644 --- a/src/database/PolicyHub.Entities/Entities/UseCase.cs +++ b/src/database/PolicyHub.Entities/Entities/UseCase.cs @@ -21,15 +21,17 @@ namespace Org.Eclipse.TractusX.PolicyHub.Entities.Entities; -public class UseCase +public class UseCase : IActiveEntity { private UseCase() { Label = null!; Policies = new HashSet(); + PolicyAttributeAssignedUseCases = new HashSet(); } - public UseCase(UseCaseId useCaseId, bool isActive) : this() + public UseCase(UseCaseId useCaseId, bool isActive) + : this() { Id = useCaseId; Label = useCaseId.ToString(); @@ -43,4 +45,6 @@ public UseCase(UseCaseId useCaseId, bool isActive) : this() // Navigation properties public virtual ICollection Policies { get; private set; } + + public virtual ICollection PolicyAttributeAssignedUseCases { get; private set; } } diff --git a/src/database/PolicyHub.Entities/PolicyHubContext.cs b/src/database/PolicyHub.Entities/PolicyHubContext.cs index d8ea154..540fe1a 100644 --- a/src/database/PolicyHub.Entities/PolicyHubContext.cs +++ b/src/database/PolicyHub.Entities/PolicyHubContext.cs @@ -111,10 +111,10 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) modelBuilder.Entity(entity => { - entity.Property(x => x.IsActive).HasDefaultValue(true); - entity - .HasKey(x => new { x.PolicyId, x.Key, x.AttributeValue }); + .HasKey(x => new { x.Id }); + + entity.Property(x => x.IsActive).HasDefaultValue(true); entity .HasOne(pa => pa.AttributeKey) @@ -127,6 +127,24 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) .HasForeignKey(x => x.PolicyId); }); + modelBuilder.Entity(entity => + { + entity.Property(x => x.IsActive).HasDefaultValue(true); + + entity + .HasKey(x => new { x.AttributeId, x.UseCaseId }); + + entity + .HasOne(pa => pa.PolicyAttribute) + .WithMany(p => p.PolicyAttributeAssignedUseCases) + .HasForeignKey(x => x.AttributeId); + + entity + .HasOne(pa => pa.UseCase) + .WithMany(p => p.PolicyAttributeAssignedUseCases) + .HasForeignKey(x => x.UseCaseId); + }); + modelBuilder.Entity(entity => { entity.Property(x => x.IsActive).HasDefaultValue(true); diff --git a/src/database/PolicyHub.Migrations/Migrations/20240425103233_25-policy-seeding.Designer.cs b/src/database/PolicyHub.Migrations/Migrations/20240425103233_25-policy-seeding.Designer.cs new file mode 100644 index 0000000..9236f95 --- /dev/null +++ b/src/database/PolicyHub.Migrations/Migrations/20240425103233_25-policy-seeding.Designer.cs @@ -0,0 +1,543 @@ +/******************************************************************************** + * Copyright (c) 2023 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; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; +using Org.Eclipse.TractusX.PolicyHub.Entities; + +#nullable disable + +namespace Org.Eclipse.TractusX.PolicyHub.Migrations.Migrations +{ + [DbContext(typeof(PolicyHubContext))] + [Migration("20240425103233_25-policy-seeding")] + partial class _25policyseeding + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasDefaultSchema("policy-hub") + .UseCollation("en_US.utf8") + .HasAnnotation("ProductVersion", "8.0.3") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("Org.Eclipse.TractusX.PolicyHub.Entities.Entities.AttributeKey", b => + { + b.Property("Id") + .HasColumnType("integer") + .HasColumnName("id"); + + b.Property("Label") + .IsRequired() + .HasColumnType("text") + .HasColumnName("label"); + + b.HasKey("Id") + .HasName("pk_attribute_keys"); + + b.ToTable("attribute_keys", "policy-hub"); + + b.HasData( + new + { + Id = 1, + Label = "Regex" + }, + new + { + Id = 2, + Label = "Static" + }, + new + { + Id = 3, + Label = "DynamicValue" + }, + new + { + Id = 4, + Label = "Brands" + }, + new + { + Id = 5, + Label = "Version" + }); + }); + + modelBuilder.Entity("Org.Eclipse.TractusX.PolicyHub.Entities.Entities.Policy", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid") + .HasColumnName("id"); + + b.Property("AttributeKeyId") + .HasColumnType("integer") + .HasColumnName("attribute_key_id"); + + b.Property("Description") + .IsRequired() + .HasColumnType("text") + .HasColumnName("description"); + + b.Property("IsActive") + .ValueGeneratedOnAdd() + .HasColumnType("boolean") + .HasDefaultValue(true) + .HasColumnName("is_active"); + + b.Property("KindId") + .HasColumnType("integer") + .HasColumnName("kind_id"); + + b.Property("LeftOperandValue") + .HasColumnType("text") + .HasColumnName("left_operand_value"); + + b.Property("TechnicalKey") + .IsRequired() + .HasColumnType("text") + .HasColumnName("technical_key"); + + b.HasKey("Id") + .HasName("pk_policies"); + + b.HasIndex("AttributeKeyId") + .HasDatabaseName("ix_policies_attribute_key_id"); + + b.HasIndex("KindId") + .HasDatabaseName("ix_policies_kind_id"); + + b.ToTable("policies", "policy-hub"); + }); + + modelBuilder.Entity("Org.Eclipse.TractusX.PolicyHub.Entities.Entities.PolicyAssignedTypes", b => + { + b.Property("PolicyId") + .HasColumnType("uuid") + .HasColumnName("policy_id"); + + b.Property("PolicyTypeId") + .HasColumnType("integer") + .HasColumnName("policy_type_id"); + + b.HasKey("PolicyId", "PolicyTypeId") + .HasName("pk_policy_assigned_types"); + + b.HasIndex("PolicyTypeId") + .HasDatabaseName("ix_policy_assigned_types_policy_type_id"); + + b.ToTable("policy_assigned_types", "policy-hub"); + }); + + modelBuilder.Entity("Org.Eclipse.TractusX.PolicyHub.Entities.Entities.PolicyAssignedUseCases", b => + { + b.Property("PolicyId") + .HasColumnType("uuid") + .HasColumnName("policy_id"); + + b.Property("UseCaseId") + .HasColumnType("integer") + .HasColumnName("use_case_id"); + + b.HasKey("PolicyId", "UseCaseId") + .HasName("pk_policy_assigned_use_cases"); + + b.HasIndex("UseCaseId") + .HasDatabaseName("ix_policy_assigned_use_cases_use_case_id"); + + b.ToTable("policy_assigned_use_cases", "policy-hub"); + }); + + modelBuilder.Entity("Org.Eclipse.TractusX.PolicyHub.Entities.Entities.PolicyAttribute", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid") + .HasColumnName("id"); + + b.Property("AttributeValue") + .IsRequired() + .HasColumnType("text") + .HasColumnName("attribute_value"); + + b.Property("IsActive") + .ValueGeneratedOnAdd() + .HasColumnType("boolean") + .HasDefaultValue(true) + .HasColumnName("is_active"); + + b.Property("Key") + .HasColumnType("integer") + .HasColumnName("key"); + + b.Property("PolicyId") + .HasColumnType("uuid") + .HasColumnName("policy_id"); + + b.HasKey("Id") + .HasName("pk_policy_attributes"); + + b.HasIndex("Key") + .HasDatabaseName("ix_policy_attributes_key"); + + b.HasIndex("PolicyId") + .HasDatabaseName("ix_policy_attributes_policy_id"); + + b.ToTable("policy_attributes", "policy-hub"); + }); + + modelBuilder.Entity("Org.Eclipse.TractusX.PolicyHub.Entities.Entities.PolicyAttributeAssignedUseCases", b => + { + b.Property("AttributeId") + .HasColumnType("uuid") + .HasColumnName("attribute_id"); + + b.Property("UseCaseId") + .HasColumnType("integer") + .HasColumnName("use_case_id"); + + b.Property("IsActive") + .ValueGeneratedOnAdd() + .HasColumnType("boolean") + .HasDefaultValue(true) + .HasColumnName("is_active"); + + b.HasKey("AttributeId", "UseCaseId") + .HasName("pk_policy_attribute_assigned_use_cases"); + + b.HasIndex("UseCaseId") + .HasDatabaseName("ix_policy_attribute_assigned_use_cases_use_case_id"); + + b.ToTable("policy_attribute_assigned_use_cases", "policy-hub"); + }); + + modelBuilder.Entity("Org.Eclipse.TractusX.PolicyHub.Entities.Entities.PolicyKind", b => + { + b.Property("Id") + .HasColumnType("integer") + .HasColumnName("id"); + + b.Property("Label") + .IsRequired() + .HasColumnType("text") + .HasColumnName("label"); + + b.Property("TechnicalEnforced") + .HasColumnType("boolean") + .HasColumnName("technical_enforced"); + + b.HasKey("Id") + .HasName("pk_policy_kinds"); + + b.ToTable("policy_kinds", "policy-hub"); + + b.HasData( + new + { + Id = 1, + Label = "BusinessPartnerNumber", + TechnicalEnforced = true + }, + new + { + Id = 2, + Label = "Membership", + TechnicalEnforced = true + }, + new + { + Id = 3, + Label = "Framework", + TechnicalEnforced = true + }, + new + { + Id = 4, + Label = "Purpose", + TechnicalEnforced = false + }, + new + { + Id = 5, + Label = "Dismantler", + TechnicalEnforced = true + }); + }); + + modelBuilder.Entity("Org.Eclipse.TractusX.PolicyHub.Entities.Entities.PolicyKindConfiguration", b => + { + b.Property("PolicyKindId") + .HasColumnType("integer") + .HasColumnName("policy_kind_id"); + + b.Property("RightOperandValue") + .IsRequired() + .HasColumnType("text") + .HasColumnName("right_operand_value"); + + b.HasKey("PolicyKindId") + .HasName("pk_policy_kind_configurations"); + + b.ToTable("policy_kind_configurations", "policy-hub"); + }); + + modelBuilder.Entity("Org.Eclipse.TractusX.PolicyHub.Entities.Entities.PolicyType", b => + { + b.Property("Id") + .HasColumnType("integer") + .HasColumnName("id"); + + b.Property("IsActive") + .ValueGeneratedOnAdd() + .HasColumnType("boolean") + .HasDefaultValue(true) + .HasColumnName("is_active"); + + b.Property("Label") + .IsRequired() + .HasColumnType("text") + .HasColumnName("label"); + + b.HasKey("Id") + .HasName("pk_policy_types"); + + b.ToTable("policy_types", "policy-hub"); + + b.HasData( + new + { + Id = 1, + IsActive = true, + Label = "Access" + }, + new + { + Id = 2, + IsActive = true, + Label = "Usage" + }); + }); + + modelBuilder.Entity("Org.Eclipse.TractusX.PolicyHub.Entities.Entities.UseCase", b => + { + b.Property("Id") + .HasColumnType("integer") + .HasColumnName("id"); + + b.Property("IsActive") + .ValueGeneratedOnAdd() + .HasColumnType("boolean") + .HasDefaultValue(true) + .HasColumnName("is_active"); + + b.Property("Label") + .IsRequired() + .HasColumnType("text") + .HasColumnName("label"); + + b.HasKey("Id") + .HasName("pk_use_cases"); + + b.ToTable("use_cases", "policy-hub"); + + b.HasData( + new + { + Id = 1, + IsActive = true, + Label = "Traceability" + }, + new + { + Id = 2, + IsActive = true, + Label = "Quality" + }, + new + { + Id = 3, + IsActive = true, + Label = "PCF" + }, + new + { + Id = 4, + IsActive = true, + Label = "Behavioraltwin" + }, + new + { + Id = 5, + IsActive = true, + Label = "Sustainability" + }); + }); + + modelBuilder.Entity("Org.Eclipse.TractusX.PolicyHub.Entities.Entities.Policy", b => + { + b.HasOne("Org.Eclipse.TractusX.PolicyHub.Entities.Entities.AttributeKey", "AttributeKey") + .WithMany("Policies") + .HasForeignKey("AttributeKeyId") + .HasConstraintName("fk_policies_attribute_keys_attribute_key_id"); + + b.HasOne("Org.Eclipse.TractusX.PolicyHub.Entities.Entities.PolicyKind", "PolicyKind") + .WithMany("Policies") + .HasForeignKey("KindId") + .IsRequired() + .HasConstraintName("fk_policies_policy_kinds_kind_id"); + + b.Navigation("AttributeKey"); + + b.Navigation("PolicyKind"); + }); + + modelBuilder.Entity("Org.Eclipse.TractusX.PolicyHub.Entities.Entities.PolicyAssignedTypes", b => + { + b.HasOne("Org.Eclipse.TractusX.PolicyHub.Entities.Entities.Policy", "Policy") + .WithMany() + .HasForeignKey("PolicyId") + .IsRequired() + .HasConstraintName("fk_policy_assigned_types_policies_policy_id"); + + b.HasOne("Org.Eclipse.TractusX.PolicyHub.Entities.Entities.PolicyType", "PolicyType") + .WithMany() + .HasForeignKey("PolicyTypeId") + .IsRequired() + .HasConstraintName("fk_policy_assigned_types_policy_types_policy_type_id"); + + b.Navigation("Policy"); + + b.Navigation("PolicyType"); + }); + + modelBuilder.Entity("Org.Eclipse.TractusX.PolicyHub.Entities.Entities.PolicyAssignedUseCases", b => + { + b.HasOne("Org.Eclipse.TractusX.PolicyHub.Entities.Entities.Policy", "Policy") + .WithMany() + .HasForeignKey("PolicyId") + .IsRequired() + .HasConstraintName("fk_policy_assigned_use_cases_policies_policy_id"); + + b.HasOne("Org.Eclipse.TractusX.PolicyHub.Entities.Entities.UseCase", "UseCase") + .WithMany() + .HasForeignKey("UseCaseId") + .IsRequired() + .HasConstraintName("fk_policy_assigned_use_cases_use_cases_use_case_id"); + + b.Navigation("Policy"); + + b.Navigation("UseCase"); + }); + + modelBuilder.Entity("Org.Eclipse.TractusX.PolicyHub.Entities.Entities.PolicyAttribute", b => + { + b.HasOne("Org.Eclipse.TractusX.PolicyHub.Entities.Entities.AttributeKey", "AttributeKey") + .WithMany("PolicyAttributes") + .HasForeignKey("Key") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired() + .HasConstraintName("fk_policy_attributes_attribute_keys_key"); + + b.HasOne("Org.Eclipse.TractusX.PolicyHub.Entities.Entities.Policy", "Policy") + .WithMany("Attributes") + .HasForeignKey("PolicyId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired() + .HasConstraintName("fk_policy_attributes_policies_policy_id"); + + b.Navigation("AttributeKey"); + + b.Navigation("Policy"); + }); + + modelBuilder.Entity("Org.Eclipse.TractusX.PolicyHub.Entities.Entities.PolicyAttributeAssignedUseCases", b => + { + b.HasOne("Org.Eclipse.TractusX.PolicyHub.Entities.Entities.PolicyAttribute", "PolicyAttribute") + .WithMany("PolicyAttributeAssignedUseCases") + .HasForeignKey("AttributeId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired() + .HasConstraintName("fk_policy_attribute_assigned_use_cases_policy_attributes_attri"); + + b.HasOne("Org.Eclipse.TractusX.PolicyHub.Entities.Entities.UseCase", "UseCase") + .WithMany("PolicyAttributeAssignedUseCases") + .HasForeignKey("UseCaseId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired() + .HasConstraintName("fk_policy_attribute_assigned_use_cases_use_cases_use_case_id"); + + b.Navigation("PolicyAttribute"); + + b.Navigation("UseCase"); + }); + + modelBuilder.Entity("Org.Eclipse.TractusX.PolicyHub.Entities.Entities.PolicyKindConfiguration", b => + { + b.HasOne("Org.Eclipse.TractusX.PolicyHub.Entities.Entities.PolicyKind", "PolicyKind") + .WithOne("Configuration") + .HasForeignKey("Org.Eclipse.TractusX.PolicyHub.Entities.Entities.PolicyKindConfiguration", "PolicyKindId") + .IsRequired() + .HasConstraintName("fk_policy_kind_configurations_policy_kinds_policy_kind_id"); + + b.Navigation("PolicyKind"); + }); + + modelBuilder.Entity("Org.Eclipse.TractusX.PolicyHub.Entities.Entities.AttributeKey", b => + { + b.Navigation("Policies"); + + b.Navigation("PolicyAttributes"); + }); + + modelBuilder.Entity("Org.Eclipse.TractusX.PolicyHub.Entities.Entities.Policy", b => + { + b.Navigation("Attributes"); + }); + + modelBuilder.Entity("Org.Eclipse.TractusX.PolicyHub.Entities.Entities.PolicyAttribute", b => + { + b.Navigation("PolicyAttributeAssignedUseCases"); + }); + + modelBuilder.Entity("Org.Eclipse.TractusX.PolicyHub.Entities.Entities.PolicyKind", b => + { + b.Navigation("Configuration"); + + b.Navigation("Policies"); + }); + + modelBuilder.Entity("Org.Eclipse.TractusX.PolicyHub.Entities.Entities.UseCase", b => + { + b.Navigation("PolicyAttributeAssignedUseCases"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/database/PolicyHub.Migrations/Migrations/20240425103233_25-policy-seeding.cs b/src/database/PolicyHub.Migrations/Migrations/20240425103233_25-policy-seeding.cs new file mode 100644 index 0000000..f3a14fe --- /dev/null +++ b/src/database/PolicyHub.Migrations/Migrations/20240425103233_25-policy-seeding.cs @@ -0,0 +1,180 @@ +/******************************************************************************** + * Copyright (c) 2023 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 Microsoft.EntityFrameworkCore.Migrations; +using System; + +#nullable disable + +namespace Org.Eclipse.TractusX.PolicyHub.Migrations.Migrations +{ + /// + public partial class _25policyseeding : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "fk_policies_policy_kinds_policy_kind_id", + schema: "policy-hub", + table: "policies"); + + migrationBuilder.DropForeignKey( + name: "fk_policy_attributes_attribute_keys_attribute_key_id", + schema: "policy-hub", + table: "policy_attributes"); + + migrationBuilder.DropPrimaryKey( + name: "pk_policy_attributes", + schema: "policy-hub", + table: "policy_attributes"); + + migrationBuilder.AddColumn( + name: "id", + schema: "policy-hub", + table: "policy_attributes", + type: "uuid", + nullable: false, + defaultValueSql: "gen_random_uuid()"); + + migrationBuilder.AddPrimaryKey( + name: "pk_policy_attributes", + schema: "policy-hub", + table: "policy_attributes", + column: "id"); + + migrationBuilder.CreateTable( + name: "policy_attribute_assigned_use_cases", + schema: "policy-hub", + columns: table => new + { + attribute_id = table.Column(type: "uuid", nullable: false), + use_case_id = table.Column(type: "integer", nullable: false), + is_active = table.Column(type: "boolean", nullable: false, defaultValue: true) + }, + constraints: table => + { + table.PrimaryKey("pk_policy_attribute_assigned_use_cases", x => new { x.attribute_id, x.use_case_id }); + table.ForeignKey( + name: "fk_policy_attribute_assigned_use_cases_policy_attributes_attri", + column: x => x.attribute_id, + principalSchema: "policy-hub", + principalTable: "policy_attributes", + principalColumn: "id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "fk_policy_attribute_assigned_use_cases_use_cases_use_case_id", + column: x => x.use_case_id, + principalSchema: "policy-hub", + principalTable: "use_cases", + principalColumn: "id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "ix_policy_attributes_policy_id", + schema: "policy-hub", + table: "policy_attributes", + column: "policy_id"); + + migrationBuilder.CreateIndex( + name: "ix_policy_attribute_assigned_use_cases_use_case_id", + schema: "policy-hub", + table: "policy_attribute_assigned_use_cases", + column: "use_case_id"); + + migrationBuilder.AddForeignKey( + name: "fk_policies_policy_kinds_kind_id", + schema: "policy-hub", + table: "policies", + column: "kind_id", + principalSchema: "policy-hub", + principalTable: "policy_kinds", + principalColumn: "id"); + + migrationBuilder.AddForeignKey( + name: "fk_policy_attributes_attribute_keys_key", + schema: "policy-hub", + table: "policy_attributes", + column: "key", + principalSchema: "policy-hub", + principalTable: "attribute_keys", + principalColumn: "id", + onDelete: ReferentialAction.Cascade); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "fk_policies_policy_kinds_kind_id", + schema: "policy-hub", + table: "policies"); + + migrationBuilder.DropForeignKey( + name: "fk_policy_attributes_attribute_keys_key", + schema: "policy-hub", + table: "policy_attributes"); + + migrationBuilder.DropTable( + name: "policy_attribute_assigned_use_cases", + schema: "policy-hub"); + + migrationBuilder.DropPrimaryKey( + name: "pk_policy_attributes", + schema: "policy-hub", + table: "policy_attributes"); + + migrationBuilder.DropIndex( + name: "ix_policy_attributes_policy_id", + schema: "policy-hub", + table: "policy_attributes"); + + migrationBuilder.DropColumn( + name: "id", + schema: "policy-hub", + table: "policy_attributes"); + + migrationBuilder.AddPrimaryKey( + name: "pk_policy_attributes", + schema: "policy-hub", + table: "policy_attributes", + columns: new[] { "policy_id", "key", "attribute_value" }); + + migrationBuilder.AddForeignKey( + name: "fk_policies_policy_kinds_policy_kind_id", + schema: "policy-hub", + table: "policies", + column: "kind_id", + principalSchema: "policy-hub", + principalTable: "policy_kinds", + principalColumn: "id"); + + migrationBuilder.AddForeignKey( + name: "fk_policy_attributes_attribute_keys_attribute_key_id", + schema: "policy-hub", + table: "policy_attributes", + column: "key", + principalSchema: "policy-hub", + principalTable: "attribute_keys", + principalColumn: "id", + onDelete: ReferentialAction.Cascade); + } + } +} diff --git a/src/database/PolicyHub.Migrations/Migrations/PolicyHubContextModelSnapshot.cs b/src/database/PolicyHub.Migrations/Migrations/PolicyHubContextModelSnapshot.cs index ec552b8..5ea70e7 100644 --- a/src/database/PolicyHub.Migrations/Migrations/PolicyHubContextModelSnapshot.cs +++ b/src/database/PolicyHub.Migrations/Migrations/PolicyHubContextModelSnapshot.cs @@ -1,4 +1,4 @@ -/******************************************************************************** +/******************************************************************************** * Copyright (c) 2023 Contributors to the Eclipse Foundation * * See the NOTICE file(s) distributed with this work for additional @@ -34,7 +34,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) modelBuilder .HasDefaultSchema("policy-hub") .UseCollation("en_US.utf8") - .HasAnnotation("ProductVersion", "7.0.12") + .HasAnnotation("ProductVersion", "8.0.3") .HasAnnotation("Relational:MaxIdentifierLength", 63); NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); @@ -170,15 +170,13 @@ protected override void BuildModel(ModelBuilder modelBuilder) modelBuilder.Entity("Org.Eclipse.TractusX.PolicyHub.Entities.Entities.PolicyAttribute", b => { - b.Property("PolicyId") + b.Property("Id") + .ValueGeneratedOnAdd() .HasColumnType("uuid") - .HasColumnName("policy_id"); - - b.Property("Key") - .HasColumnType("integer") - .HasColumnName("key"); + .HasColumnName("id"); b.Property("AttributeValue") + .IsRequired() .HasColumnType("text") .HasColumnName("attribute_value"); @@ -188,15 +186,51 @@ protected override void BuildModel(ModelBuilder modelBuilder) .HasDefaultValue(true) .HasColumnName("is_active"); - b.HasKey("PolicyId", "Key", "AttributeValue") + b.Property("Key") + .HasColumnType("integer") + .HasColumnName("key"); + + b.Property("PolicyId") + .HasColumnType("uuid") + .HasColumnName("policy_id"); + + b.HasKey("Id") .HasName("pk_policy_attributes"); b.HasIndex("Key") .HasDatabaseName("ix_policy_attributes_key"); + b.HasIndex("PolicyId") + .HasDatabaseName("ix_policy_attributes_policy_id"); + b.ToTable("policy_attributes", "policy-hub"); }); + modelBuilder.Entity("Org.Eclipse.TractusX.PolicyHub.Entities.Entities.PolicyAttributeAssignedUseCases", b => + { + b.Property("AttributeId") + .HasColumnType("uuid") + .HasColumnName("attribute_id"); + + b.Property("UseCaseId") + .HasColumnType("integer") + .HasColumnName("use_case_id"); + + b.Property("IsActive") + .ValueGeneratedOnAdd() + .HasColumnType("boolean") + .HasDefaultValue(true) + .HasColumnName("is_active"); + + b.HasKey("AttributeId", "UseCaseId") + .HasName("pk_policy_attribute_assigned_use_cases"); + + b.HasIndex("UseCaseId") + .HasDatabaseName("ix_policy_attribute_assigned_use_cases_use_case_id"); + + b.ToTable("policy_attribute_assigned_use_cases", "policy-hub"); + }); + modelBuilder.Entity("Org.Eclipse.TractusX.PolicyHub.Entities.Entities.PolicyKind", b => { b.Property("Id") @@ -370,7 +404,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) .WithMany("Policies") .HasForeignKey("KindId") .IsRequired() - .HasConstraintName("fk_policies_policy_kinds_policy_kind_id"); + .HasConstraintName("fk_policies_policy_kinds_kind_id"); b.Navigation("AttributeKey"); @@ -422,7 +456,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) .HasForeignKey("Key") .OnDelete(DeleteBehavior.Cascade) .IsRequired() - .HasConstraintName("fk_policy_attributes_attribute_keys_attribute_key_id"); + .HasConstraintName("fk_policy_attributes_attribute_keys_key"); b.HasOne("Org.Eclipse.TractusX.PolicyHub.Entities.Entities.Policy", "Policy") .WithMany("Attributes") @@ -436,6 +470,27 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.Navigation("Policy"); }); + modelBuilder.Entity("Org.Eclipse.TractusX.PolicyHub.Entities.Entities.PolicyAttributeAssignedUseCases", b => + { + b.HasOne("Org.Eclipse.TractusX.PolicyHub.Entities.Entities.PolicyAttribute", "PolicyAttribute") + .WithMany("PolicyAttributeAssignedUseCases") + .HasForeignKey("AttributeId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired() + .HasConstraintName("fk_policy_attribute_assigned_use_cases_policy_attributes_attri"); + + b.HasOne("Org.Eclipse.TractusX.PolicyHub.Entities.Entities.UseCase", "UseCase") + .WithMany("PolicyAttributeAssignedUseCases") + .HasForeignKey("UseCaseId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired() + .HasConstraintName("fk_policy_attribute_assigned_use_cases_use_cases_use_case_id"); + + b.Navigation("PolicyAttribute"); + + b.Navigation("UseCase"); + }); + modelBuilder.Entity("Org.Eclipse.TractusX.PolicyHub.Entities.Entities.PolicyKindConfiguration", b => { b.HasOne("Org.Eclipse.TractusX.PolicyHub.Entities.Entities.PolicyKind", "PolicyKind") @@ -459,12 +514,22 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.Navigation("Attributes"); }); + modelBuilder.Entity("Org.Eclipse.TractusX.PolicyHub.Entities.Entities.PolicyAttribute", b => + { + b.Navigation("PolicyAttributeAssignedUseCases"); + }); + modelBuilder.Entity("Org.Eclipse.TractusX.PolicyHub.Entities.Entities.PolicyKind", b => { b.Navigation("Configuration"); b.Navigation("Policies"); }); + + modelBuilder.Entity("Org.Eclipse.TractusX.PolicyHub.Entities.Entities.UseCase", b => + { + b.Navigation("PolicyAttributeAssignedUseCases"); + }); #pragma warning restore 612, 618 } } diff --git a/src/database/PolicyHub.Migrations/Seeder/BatchDeleteSeeder.cs b/src/database/PolicyHub.Migrations/Seeder/BatchDeleteSeeder.cs new file mode 100644 index 0000000..acc9ff2 --- /dev/null +++ b/src/database/PolicyHub.Migrations/Seeder/BatchDeleteSeeder.cs @@ -0,0 +1,97 @@ +/******************************************************************************** + * Copyright (c) 2023 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 Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Options; +using Org.Eclipse.TractusX.PolicyHub.Entities; +using Org.Eclipse.TractusX.PolicyHub.Entities.Entities; +using Org.Eclipse.TractusX.Portal.Backend.Framework.Seeding; + +namespace Org.Eclipse.TractusX.PolicyHub.Migrations.Seeder; + +/// +/// Seeder to seed the all configured entities +/// +public class BatchDeleteSeeder : ICustomSeeder +{ + private readonly PolicyHubContext _context; + private readonly ILogger _logger; + private readonly SeederSettings _settings; + + /// + /// Constructor + /// + /// The database context + /// The logger + /// The options + public BatchDeleteSeeder(PolicyHubContext context, ILogger logger, IOptions options) + { + _context = context; + _logger = logger; + _settings = options.Value; + } + + /// + public int Order => 3; + + /// + public async Task ExecuteAsync(CancellationToken cancellationToken) + { + if (!_settings.DataPaths.Any()) + { + _logger.LogInformation("There a no data paths configured, therefore the {SeederName} will be skipped", nameof(BatchInsertSeeder)); + return; + } + + await SeedTable("policies", x => x.Id, cancellationToken).ConfigureAwait(false); + await SeedTable("policy_attributes", x => x.Id, cancellationToken).ConfigureAwait(false); + await SeedTable("policy_kind_configurations", x => x.PolicyKindId, cancellationToken).ConfigureAwait(false); + await SeedTable("policy_assigned_types", x => new { x.PolicyId, x.PolicyTypeId }, cancellationToken).ConfigureAwait(false); + await SeedTable("policy_assigned_use_cases", x => new { x.PolicyId, x.UseCaseId }, cancellationToken).ConfigureAwait(false); + await SeedTable("policy_attribute_assigned_use_cases", x => new { x.AttributeId, x.UseCaseId }, cancellationToken).ConfigureAwait(false); + + await _context.SaveChangesAsync(cancellationToken).ConfigureAwait(false); + } + + private async Task SeedTable(string fileName, Func keySelector, CancellationToken cancellationToken) where T : class + { + _logger.LogDebug("Start seeding {Filename}", fileName); + var additionalEnvironments = _settings.TestDataEnvironments ?? Enumerable.Empty(); + var data = await SeederHelper.GetSeedData(_logger, fileName, _settings.DataPaths, cancellationToken, additionalEnvironments.ToArray()).ConfigureAwait(false); + _logger.LogDebug("Found {ElementCount} data", data.Count); + var isActiveEntity = typeof(T).IsAssignableTo(typeof(IActiveEntity)); + + // Identify entities in the database that are not present in the JSON data + var existingEntities = await _context.Set().ToListAsync(cancellationToken).ConfigureAwait(false); + var entitiesToRemove = existingEntities.Where(dbEntity => data.All(jsonEntity => !keySelector(dbEntity).Equals(keySelector(jsonEntity)))).ToList(); + if (isActiveEntity) + { + foreach (var entity in entitiesToRemove) + { + _context.Set().Attach(entity); + (entity as IActiveEntity)!.IsActive = false; + } + } + else + { + _context.Set().RemoveRange(entitiesToRemove); + } + } +} diff --git a/src/database/PolicyHub.Migrations/Seeder/BatchInsertSeeder.cs b/src/database/PolicyHub.Migrations/Seeder/BatchInsertSeeder.cs index cfed58d..a8b714d 100644 --- a/src/database/PolicyHub.Migrations/Seeder/BatchInsertSeeder.cs +++ b/src/database/PolicyHub.Migrations/Seeder/BatchInsertSeeder.cs @@ -60,10 +60,11 @@ public async Task ExecuteAsync(CancellationToken cancellationToken) } await SeedTable("policies", x => x.Id, cancellationToken).ConfigureAwait(false); - await SeedTable("policy_attributes", x => new { x.PolicyId, x.Key, x.AttributeValue }, cancellationToken).ConfigureAwait(false); + await SeedTable("policy_attributes", x => x.Id, cancellationToken).ConfigureAwait(false); await SeedTable("policy_kind_configurations", x => x.PolicyKindId, cancellationToken).ConfigureAwait(false); await SeedTable("policy_assigned_types", x => new { x.PolicyId, x.PolicyTypeId }, cancellationToken).ConfigureAwait(false); await SeedTable("policy_assigned_use_cases", x => new { x.PolicyId, x.UseCaseId }, cancellationToken).ConfigureAwait(false); + await SeedTable("policy_attribute_assigned_use_cases", x => new { x.AttributeId, x.UseCaseId }, cancellationToken).ConfigureAwait(false); await _context.SaveChangesAsync(cancellationToken).ConfigureAwait(false); } diff --git a/src/database/PolicyHub.Migrations/Seeder/BatchUpdateSeeder.cs b/src/database/PolicyHub.Migrations/Seeder/BatchUpdateSeeder.cs index ff172d4..c8a74b6 100644 --- a/src/database/PolicyHub.Migrations/Seeder/BatchUpdateSeeder.cs +++ b/src/database/PolicyHub.Migrations/Seeder/BatchUpdateSeeder.cs @@ -44,19 +44,24 @@ public async Task ExecuteAsync(CancellationToken cancellationToken) await SeedTable( "policies", x => new { x.Id }, - x => x.dbEntity.IsActive != x.dataEntity.IsActive, + x => x.dbEntity.IsActive != x.dataEntity.IsActive || x.dbEntity.TechnicalKey != x.dataEntity.TechnicalKey || x.dbEntity.LeftOperandValue != x.dataEntity.LeftOperandValue, (dbEntity, entity) => { dbEntity.IsActive = entity.IsActive; + dbEntity.TechnicalKey = entity.TechnicalKey; + dbEntity.LeftOperandValue = entity.LeftOperandValue; }, cancellationToken).ConfigureAwait(false); await SeedTable( "policy_attributes", - x => new { x.PolicyId, x.Key, x.AttributeValue }, - x => x.dbEntity.IsActive != x.dataEntity.IsActive, + x => new { x.Id }, + x => x.dbEntity.IsActive != x.dataEntity.IsActive || x.dbEntity.AttributeValue != x.dataEntity.AttributeValue || x.dbEntity.Key != x.dataEntity.Key || x.dbEntity.PolicyId != x.dataEntity.PolicyId, (dbEntry, entry) => { dbEntry.IsActive = entry.IsActive; + dbEntry.AttributeValue = entry.AttributeValue; + dbEntry.Key = entry.Key; + dbEntry.PolicyId = entry.PolicyId; }, cancellationToken).ConfigureAwait(false); await _context.SaveChangesAsync(cancellationToken).ConfigureAwait(false); diff --git a/src/database/PolicyHub.Migrations/Seeder/Data/policies.json b/src/database/PolicyHub.Migrations/Seeder/Data/policies.json index 465c983..cf6adc2 100644 --- a/src/database/PolicyHub.Migrations/Seeder/Data/policies.json +++ b/src/database/PolicyHub.Migrations/Seeder/Data/policies.json @@ -16,52 +16,36 @@ "attribute_key_id": 2 }, { - "id": "01a0fba3-9b6e-435a-b045-e0e890c300b3", - "kind_id": 3, - "technical_key": "FrameworkAgreement.traceability", - "description": "With the Framework Credential, only those participants which have signed the respective framework agreement (general or via a specific version) are allowed to view or negotiate the respective data offer. Generic: \"rightOperand\": \"active\"; specific \"rightOperand\": \"active:{version}\"", + "id": "01a0fba3-9b6e-435a-b045-e0e890c300c1", + "kind_id": 5, + "technical_key": "Dismantler.allowedBrands", + "left_operand_value": null, + "description": "Company role defining a dismantler. Companies holding the credential are dismantler certified companies.", "is_active": true, - "attribute_key_id": 5 + "attribute_key_id": 4 }, { - "id": "01a0fba3-9b6e-435a-b045-e0e890c300b4", - "kind_id": 3, - "technical_key": "FrameworkAgreement.quality", - "description": "With the Framework Credential, only those participants which have signed the respective framework agreement (general or via a specific version) are allowed to view or negotiate the respective data offer. Generic: \"rightOperand\": \"active\"; specific \"rightOperand\": \"active:{version}\"", + "id": "01a0fba3-9b6e-435a-b045-e0e890c300c2", + "kind_id": 4, + "technical_key": "UsagePurpose", + "description": "", "is_active": true, - "attribute_key_id": 5 + "attribute_key_id": 3 }, { - "id": "01a0fba3-9b6e-435a-b045-e0e890c300b5", + "id": "01a0fba3-9b6e-435a-b045-e0e890c300c9", "kind_id": 3, - "technical_key": "FrameworkAgreement.pcf", + "technical_key": "FrameworkAgreement", "description": "With the Framework Credential, only those participants which have signed the respective framework agreement (general or via a specific version) are allowed to view or negotiate the respective data offer. Generic: \"rightOperand\": \"active\"; specific \"rightOperand\": \"active:{version}\"", "is_active": true, "attribute_key_id": 5 }, { - "id": "01a0fba3-9b6e-435a-b045-e0e890c300b6", - "kind_id": 3, - "technical_key": "FrameworkAgreement.behavioraltwin", - "description": "With the Framework Credential, only those participants which have signed the respective framework agreement (general or via a specific version) are allowed to view or negotiate the respective data offer. Generic: \"rightOperand\": \"active\"; specific \"rightOperand\": \"active:{version}\"", - "is_active": true, - "attribute_key_id": 5 - }, - { - "id": "01a0fba3-9b6e-435a-b045-e0e890c300c1", + "id": "01a0fba3-9b6e-435a-b045-e0e890c300d1", "kind_id": 5, - "technical_key": "companyRole.dismantler", - "left_operand_value": "Dismantler.activityType", - "description": "Company role defining a dismantler. Companies holding the credential are dismantler certified companies.", + "technical_key": "Dismantler", + "description": "Companies holding the credential are dismantler certified companies.", "is_active": true, "attribute_key_id": 4 - }, - { - "id": "01a0fba3-9b6e-435a-b045-e0e890c300c2", - "kind_id": 4, - "technical_key": "purpose", - "description": "", - "is_active": true, - "attribute_key_id": 2 } ] 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 45bbce7..05b6fbc 100644 --- a/src/database/PolicyHub.Migrations/Seeder/Data/policy_assigned_types.json +++ b/src/database/PolicyHub.Migrations/Seeder/Data/policy_assigned_types.json @@ -2,12 +2,11 @@ { "policy_id": "01a0fba3-9b6e-435a-b045-e0e890c300b1", "policy_type_id": 1, "is_active": true }, { "policy_id": "01a0fba3-9b6e-435a-b045-e0e890c300b1", "policy_type_id": 2, "is_active": true }, { "policy_id": "01a0fba3-9b6e-435a-b045-e0e890c300b2", "policy_type_id": 1, "is_active": true }, - { "policy_id": "01a0fba3-9b6e-435a-b045-e0e890c300b2", "policy_type_id": 2, "is_active": true }, - { "policy_id": "01a0fba3-9b6e-435a-b045-e0e890c300b3", "policy_type_id": 2, "is_active": true }, - { "policy_id": "01a0fba3-9b6e-435a-b045-e0e890c300b4", "policy_type_id": 2, "is_active": true }, - { "policy_id": "01a0fba3-9b6e-435a-b045-e0e890c300b5", "policy_type_id": 2, "is_active": true }, - { "policy_id": "01a0fba3-9b6e-435a-b045-e0e890c300b6", "policy_type_id": 2, "is_active": true }, + { "policy_id": "01a0fba3-9b6e-435a-b045-e0e890c300b2", "policy_type_id": 2, "is_active": true }, { "policy_id": "01a0fba3-9b6e-435a-b045-e0e890c300c1", "policy_type_id": 1, "is_active": true }, { "policy_id": "01a0fba3-9b6e-435a-b045-e0e890c300c1", "policy_type_id": 2, "is_active": true }, - { "policy_id": "01a0fba3-9b6e-435a-b045-e0e890c300c2", "policy_type_id": 2, "is_active": true } + { "policy_id": "01a0fba3-9b6e-435a-b045-e0e890c300c2", "policy_type_id": 2, "is_active": true }, + { "policy_id": "01a0fba3-9b6e-435a-b045-e0e890c300c9", "policy_type_id": 2, "is_active": true }, + { "policy_id": "01a0fba3-9b6e-435a-b045-e0e890c300d1", "policy_type_id": 1, "is_active": true }, + { "policy_id": "01a0fba3-9b6e-435a-b045-e0e890c300d1", "policy_type_id": 2, "is_active": true } ] 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 629fb18..ccfb878 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 @@ -8,15 +8,21 @@ { "policy_id": "01a0fba3-9b6e-435a-b045-e0e890c300b2", "use_case_id": 2, "is_active": true }, { "policy_id": "01a0fba3-9b6e-435a-b045-e0e890c300b2", "use_case_id": 3, "is_active": true }, { "policy_id": "01a0fba3-9b6e-435a-b045-e0e890c300b2", "use_case_id": 4, "is_active": true }, - { "policy_id": "01a0fba3-9b6e-435a-b045-e0e890c300b2", "use_case_id": 5, "is_active": true }, - { "policy_id": "01a0fba3-9b6e-435a-b045-e0e890c300b3", "use_case_id": 1, "is_active": true }, - { "policy_id": "01a0fba3-9b6e-435a-b045-e0e890c300b4", "use_case_id": 2, "is_active": true }, - { "policy_id": "01a0fba3-9b6e-435a-b045-e0e890c300b5", "use_case_id": 3, "is_active": true }, - { "policy_id": "01a0fba3-9b6e-435a-b045-e0e890c300b6", "use_case_id": 4, "is_active": true }, + { "policy_id": "01a0fba3-9b6e-435a-b045-e0e890c300b2", "use_case_id": 5, "is_active": true }, { "policy_id": "01a0fba3-9b6e-435a-b045-e0e890c300c1", "use_case_id": 1, "is_active": true }, { "policy_id": "01a0fba3-9b6e-435a-b045-e0e890c300c1", "use_case_id": 2, "is_active": true }, { "policy_id": "01a0fba3-9b6e-435a-b045-e0e890c300c1", "use_case_id": 3, "is_active": true }, { "policy_id": "01a0fba3-9b6e-435a-b045-e0e890c300c1", "use_case_id": 4, "is_active": true }, { "policy_id": "01a0fba3-9b6e-435a-b045-e0e890c300c1", "use_case_id": 5, "is_active": true }, - { "policy_id": "01a0fba3-9b6e-435a-b045-e0e890c300c2", "use_case_id": 1, "is_active": true } + { "policy_id": "01a0fba3-9b6e-435a-b045-e0e890c300c2", "use_case_id": 1, "is_active": true }, + { "policy_id": "01a0fba3-9b6e-435a-b045-e0e890c300c9", "use_case_id": 1, "is_active": true }, + { "policy_id": "01a0fba3-9b6e-435a-b045-e0e890c300c9", "use_case_id": 2, "is_active": true }, + { "policy_id": "01a0fba3-9b6e-435a-b045-e0e890c300c9", "use_case_id": 3, "is_active": true }, + { "policy_id": "01a0fba3-9b6e-435a-b045-e0e890c300c9", "use_case_id": 4, "is_active": true }, + { "policy_id": "01a0fba3-9b6e-435a-b045-e0e890c300c9", "use_case_id": 5, "is_active": true }, + { "policy_id": "01a0fba3-9b6e-435a-b045-e0e890c300d1", "use_case_id": 1, "is_active": true }, + { "policy_id": "01a0fba3-9b6e-435a-b045-e0e890c300d1", "use_case_id": 2, "is_active": true }, + { "policy_id": "01a0fba3-9b6e-435a-b045-e0e890c300d1", "use_case_id": 3, "is_active": true }, + { "policy_id": "01a0fba3-9b6e-435a-b045-e0e890c300d1", "use_case_id": 4, "is_active": true }, + { "policy_id": "01a0fba3-9b6e-435a-b045-e0e890c300d1", "use_case_id": 5, "is_active": true } ] diff --git a/src/database/PolicyHub.Migrations/Seeder/Data/policy_attribute_assigned_use_cases.json b/src/database/PolicyHub.Migrations/Seeder/Data/policy_attribute_assigned_use_cases.json new file mode 100644 index 0000000..b969a73 --- /dev/null +++ b/src/database/PolicyHub.Migrations/Seeder/Data/policy_attribute_assigned_use_cases.json @@ -0,0 +1,62 @@ +[ + { "attribute_id": "01a0fba3-9b6e-435a-b045-e0e890c300d1", "use_case_id": 1, "is_active": true }, + { "attribute_id": "01a0fba3-9b6e-435a-b045-e0e890c300d1", "use_case_id": 2, "is_active": true }, + { "attribute_id": "01a0fba3-9b6e-435a-b045-e0e890c300d1", "use_case_id": 3, "is_active": true }, + { "attribute_id": "01a0fba3-9b6e-435a-b045-e0e890c300d1", "use_case_id": 4, "is_active": true }, + { "attribute_id": "01a0fba3-9b6e-435a-b045-e0e890c300d1", "use_case_id": 5, "is_active": true }, + { "attribute_id": "01a0fba3-9b6e-435a-b045-e0e890c300d2", "use_case_id": 1, "is_active": true }, + { "attribute_id": "01a0fba3-9b6e-435a-b045-e0e890c300d2", "use_case_id": 2, "is_active": true }, + { "attribute_id": "01a0fba3-9b6e-435a-b045-e0e890c300d2", "use_case_id": 3, "is_active": true }, + { "attribute_id": "01a0fba3-9b6e-435a-b045-e0e890c300d2", "use_case_id": 4, "is_active": true }, + { "attribute_id": "01a0fba3-9b6e-435a-b045-e0e890c300d2", "use_case_id": 5, "is_active": true }, + { "attribute_id": "01a0fba3-9b6e-435a-b045-e0e890c300d6", "use_case_id": 1, "is_active": true }, + { "attribute_id": "01a0fba3-9b6e-435a-b045-e0e890c300d6", "use_case_id": 2, "is_active": true }, + { "attribute_id": "01a0fba3-9b6e-435a-b045-e0e890c300d6", "use_case_id": 3, "is_active": true }, + { "attribute_id": "01a0fba3-9b6e-435a-b045-e0e890c300d6", "use_case_id": 4, "is_active": true }, + { "attribute_id": "01a0fba3-9b6e-435a-b045-e0e890c300d6", "use_case_id": 5, "is_active": true }, + { "attribute_id": "01a0fba3-9b6e-435a-b045-e0e890c300d7", "use_case_id": 1, "is_active": true }, + { "attribute_id": "01a0fba3-9b6e-435a-b045-e0e890c300d7", "use_case_id": 2, "is_active": true }, + { "attribute_id": "01a0fba3-9b6e-435a-b045-e0e890c300d7", "use_case_id": 3, "is_active": true }, + { "attribute_id": "01a0fba3-9b6e-435a-b045-e0e890c300d7", "use_case_id": 4, "is_active": true }, + { "attribute_id": "01a0fba3-9b6e-435a-b045-e0e890c300d7", "use_case_id": 5, "is_active": true }, + { "attribute_id": "01a0fba3-9b6e-435a-b045-e0e890c300d8", "use_case_id": 1, "is_active": true }, + { "attribute_id": "01a0fba3-9b6e-435a-b045-e0e890c300d8", "use_case_id": 2, "is_active": true }, + { "attribute_id": "01a0fba3-9b6e-435a-b045-e0e890c300d8", "use_case_id": 3, "is_active": true }, + { "attribute_id": "01a0fba3-9b6e-435a-b045-e0e890c300d8", "use_case_id": 4, "is_active": true }, + { "attribute_id": "01a0fba3-9b6e-435a-b045-e0e890c300d8", "use_case_id": 5, "is_active": true }, + { "attribute_id": "01a0fba3-9b6e-435a-b045-e0e890c300d9", "use_case_id": 1, "is_active": true }, + { "attribute_id": "01a0fba3-9b6e-435a-b045-e0e890c300e1", "use_case_id": 1, "is_active": true }, + { "attribute_id": "01a0fba3-9b6e-435a-b045-e0e890c300e2", "use_case_id": 1, "is_active": true }, + { "attribute_id": "01a0fba3-9b6e-435a-b045-e0e890c300e3", "use_case_id": 2, "is_active": true }, + { "attribute_id": "01a0fba3-9b6e-435a-b045-e0e890c300e3", "use_case_id": 3, "is_active": true }, + { "attribute_id": "01a0fba3-9b6e-435a-b045-e0e890c300e3", "use_case_id": 4, "is_active": true }, + { "attribute_id": "01a0fba3-9b6e-435a-b045-e0e890c300e3", "use_case_id": 5, "is_active": true }, + { "attribute_id": "01a0fba3-9b6e-435a-b045-e0e890c300e4", "use_case_id": 2, "is_active": true }, + { "attribute_id": "01a0fba3-9b6e-435a-b045-e0e890c300e4", "use_case_id": 3, "is_active": true }, + { "attribute_id": "01a0fba3-9b6e-435a-b045-e0e890c300e4", "use_case_id": 4, "is_active": true }, + { "attribute_id": "01a0fba3-9b6e-435a-b045-e0e890c300e4", "use_case_id": 5, "is_active": true }, + { "attribute_id": "01a0fba3-9b6e-435a-b045-e0e890c300e6", "use_case_id": 2, "is_active": true }, + { "attribute_id": "01a0fba3-9b6e-435a-b045-e0e890c300e6", "use_case_id": 3, "is_active": true }, + { "attribute_id": "01a0fba3-9b6e-435a-b045-e0e890c300e6", "use_case_id": 4, "is_active": true }, + { "attribute_id": "01a0fba3-9b6e-435a-b045-e0e890c300e6", "use_case_id": 5, "is_active": true }, + { "attribute_id": "01a0fba3-9b6e-435a-b045-e0e890c300e7", "use_case_id": 2, "is_active": true }, + { "attribute_id": "01a0fba3-9b6e-435a-b045-e0e890c300e7", "use_case_id": 3, "is_active": true }, + { "attribute_id": "01a0fba3-9b6e-435a-b045-e0e890c300e7", "use_case_id": 4, "is_active": true }, + { "attribute_id": "01a0fba3-9b6e-435a-b045-e0e890c300e7", "use_case_id": 5, "is_active": true }, + { "attribute_id": "01a0fba3-9b6e-435a-b045-e0e890c300e8", "use_case_id": 2, "is_active": true }, + { "attribute_id": "01a0fba3-9b6e-435a-b045-e0e890c300e8", "use_case_id": 3, "is_active": true }, + { "attribute_id": "01a0fba3-9b6e-435a-b045-e0e890c300e8", "use_case_id": 4, "is_active": true }, + { "attribute_id": "01a0fba3-9b6e-435a-b045-e0e890c300e8", "use_case_id": 5, "is_active": true }, + { "attribute_id": "01a0fba3-9b6e-435a-b045-e0e890c300e9", "use_case_id": 2, "is_active": true }, + { "attribute_id": "01a0fba3-9b6e-435a-b045-e0e890c300e9", "use_case_id": 3, "is_active": true }, + { "attribute_id": "01a0fba3-9b6e-435a-b045-e0e890c300e9", "use_case_id": 4, "is_active": true }, + { "attribute_id": "01a0fba3-9b6e-435a-b045-e0e890c300e9", "use_case_id": 5, "is_active": true }, + { "attribute_id": "01a0fba3-9b6e-435a-b045-e0e890c300f1", "use_case_id": 2, "is_active": true }, + { "attribute_id": "01a0fba3-9b6e-435a-b045-e0e890c300f1", "use_case_id": 3, "is_active": true }, + { "attribute_id": "01a0fba3-9b6e-435a-b045-e0e890c300f1", "use_case_id": 4, "is_active": true }, + { "attribute_id": "01a0fba3-9b6e-435a-b045-e0e890c300f2", "use_case_id": 1, "is_active": true }, + { "attribute_id": "01a0fba3-9b6e-435a-b045-e0e890c300f2", "use_case_id": 2, "is_active": true }, + { "attribute_id": "01a0fba3-9b6e-435a-b045-e0e890c300f2", "use_case_id": 3, "is_active": true }, + { "attribute_id": "01a0fba3-9b6e-435a-b045-e0e890c300f2", "use_case_id": 4, "is_active": true }, + { "attribute_id": "01a0fba3-9b6e-435a-b045-e0e890c300f2", "use_case_id": 5, "is_active": true } +] \ No newline at end of file diff --git a/src/database/PolicyHub.Migrations/Seeder/Data/policy_attributes.json b/src/database/PolicyHub.Migrations/Seeder/Data/policy_attributes.json index c8b08d4..e0d787c 100644 --- a/src/database/PolicyHub.Migrations/Seeder/Data/policy_attributes.json +++ b/src/database/PolicyHub.Migrations/Seeder/Data/policy_attributes.json @@ -1,86 +1,135 @@ [ { + "id": "01a0fba3-9b6e-435a-b045-e0e890c300d1", "policy_id": "01a0fba3-9b6e-435a-b045-e0e890c300b1", "key": 1, "attribute_value": "^BPNL[\\w|\\d]{12}$", "is_active": true }, { + "id": "01a0fba3-9b6e-435a-b045-e0e890c300d2", "policy_id": "01a0fba3-9b6e-435a-b045-e0e890c300b2", "key": 2, "attribute_value": "active", "is_active": true }, { - "policy_id": "01a0fba3-9b6e-435a-b045-e0e890c300b3", - "key": 5, - "attribute_value": "1.0", + "id": "01a0fba3-9b6e-435a-b045-e0e890c300d3", + "policy_id": "01a0fba3-9b6e-435a-b045-e0e890c300c2", + "key": 2, + "attribute_value": "purpose.trace.v1.TraceBattery", "is_active": true }, { - "policy_id": "01a0fba3-9b6e-435a-b045-e0e890c300b3", + "id": "01a0fba3-9b6e-435a-b045-e0e890c300d4", + "policy_id": "01a0fba3-9b6e-435a-b045-e0e890c300c2", + "key": 2, + "attribute_value": "purpose.trace.v1.aspects", + "is_active": true + }, + { + "id": "01a0fba3-9b6e-435a-b045-e0e890c300d5", + "policy_id": "01a0fba3-9b6e-435a-b045-e0e890c300c2", + "key": 2, + "attribute_value": "purpose.trace.v1.qualityanalysis", + "is_active": true + }, + { + "id": "01a0fba3-9b6e-435a-b045-e0e890c300d6", + "policy_id": "01a0fba3-9b6e-435a-b045-e0e890c300c1", + "key": 4, + "attribute_value": "BMW", + "is_active": true + }, + { + "id": "01a0fba3-9b6e-435a-b045-e0e890c300d7", + "policy_id": "01a0fba3-9b6e-435a-b045-e0e890c300c1", + "key": 4, + "attribute_value": "Audi", + "is_active": true + }, + { + "id": "01a0fba3-9b6e-435a-b045-e0e890c300d8", + "policy_id": "01a0fba3-9b6e-435a-b045-e0e890c300c1", + "key": 4, + "attribute_value": "VW", + "is_active": true + }, + { + "id": "01a0fba3-9b6e-435a-b045-e0e890c300d9", + "policy_id": "01a0fba3-9b6e-435a-b045-e0e890c300c9", "key": 5, - "attribute_value": "1.1", + "attribute_value": "Traceability:1.0", "is_active": true }, { - "policy_id": "01a0fba3-9b6e-435a-b045-e0e890c300b3", + "id": "01a0fba3-9b6e-435a-b045-e0e890c300e1", + "policy_id": "01a0fba3-9b6e-435a-b045-e0e890c300c9", "key": 5, - "attribute_value": "1.2", + "attribute_value": "Traceability:1.1", "is_active": true }, { - "policy_id": "01a0fba3-9b6e-435a-b045-e0e890c300b4", + "id": "01a0fba3-9b6e-435a-b045-e0e890c300e2", + "policy_id": "01a0fba3-9b6e-435a-b045-e0e890c300c9", "key": 5, - "attribute_value": "1.0", + "attribute_value": "Traceability:1.2", "is_active": true }, { - "policy_id": "01a0fba3-9b6e-435a-b045-e0e890c300b5", + "id": "01a0fba3-9b6e-435a-b045-e0e890c300e3", + "policy_id": "01a0fba3-9b6e-435a-b045-e0e890c300c9", "key": 5, - "attribute_value": "1.0", + "attribute_value": "Quality:1.0", "is_active": true }, { - "policy_id": "01a0fba3-9b6e-435a-b045-e0e890c300b6", + "id": "01a0fba3-9b6e-435a-b045-e0e890c300e4", + "policy_id": "01a0fba3-9b6e-435a-b045-e0e890c300c9", "key": 5, - "attribute_value": "1.0", + "attribute_value": "PCF:1.0", "is_active": true }, { - "policy_id": "01a0fba3-9b6e-435a-b045-e0e890c300c2", - "key": 2, - "attribute_value": "purpose.trace.v1.TraceBattery", + "id": "01a0fba3-9b6e-435a-b045-e0e890c300e6", + "policy_id": "01a0fba3-9b6e-435a-b045-e0e890c300c9", + "key": 5, + "attribute_value": "Behavioraltwin:1.0", "is_active": true }, { - "policy_id": "01a0fba3-9b6e-435a-b045-e0e890c300c2", - "key": 2, - "attribute_value": "purpose.trace.v1.aspects", + "id": "01a0fba3-9b6e-435a-b045-e0e890c300e7", + "policy_id": "01a0fba3-9b6e-435a-b045-e0e890c300c9", + "key": 5, + "attribute_value": "Circulareconomy:1.0", "is_active": true }, { - "policy_id": "01a0fba3-9b6e-435a-b045-e0e890c300c2", - "key": 2, - "attribute_value": "purpose.trace.v1.qualityanalysis", + "id": "01a0fba3-9b6e-435a-b045-e0e890c300e8", + "policy_id": "01a0fba3-9b6e-435a-b045-e0e890c300c9", + "key": 5, + "attribute_value": "Demandcapacity:1.0", "is_active": true }, { - "policy_id": "01a0fba3-9b6e-435a-b045-e0e890c300c1", - "key": 4, - "attribute_value": "BMW", + "id": "01a0fba3-9b6e-435a-b045-e0e890c300e9", + "policy_id": "01a0fba3-9b6e-435a-b045-e0e890c300c9", + "key": 5, + "attribute_value": "Puris:1.0", "is_active": true }, { - "policy_id": "01a0fba3-9b6e-435a-b045-e0e890c300c1", - "key": 4, - "attribute_value": "Audi", + "id": "01a0fba3-9b6e-435a-b045-e0e890c300f1", + "policy_id": "01a0fba3-9b6e-435a-b045-e0e890c300c9", + "key": 5, + "attribute_value": "Businesspartner:1.0", "is_active": true }, { - "policy_id": "01a0fba3-9b6e-435a-b045-e0e890c300c1", + "id": "01a0fba3-9b6e-435a-b045-e0e890c300f2", + "policy_id": "01a0fba3-9b6e-435a-b045-e0e890c300d1", "key": 4, - "attribute_value": "VW", + "attribute_value": "active", "is_active": true } -] +] \ No newline at end of file diff --git a/src/database/PolicyHub.Migrations/Seeder/Data/policy_kind_configurations.json b/src/database/PolicyHub.Migrations/Seeder/Data/policy_kind_configurations.json index f47fb46..0d4f101 100644 --- a/src/database/PolicyHub.Migrations/Seeder/Data/policy_kind_configurations.json +++ b/src/database/PolicyHub.Migrations/Seeder/Data/policy_kind_configurations.json @@ -1,3 +1,2 @@ [ - { "policy_kind_id": 3, "right_operand_value": "active:{0}" } ] diff --git a/src/hub/PolicyHub.Service/BusinessLogic/PolicyHubBusinessLogic.cs b/src/hub/PolicyHub.Service/BusinessLogic/PolicyHubBusinessLogic.cs index bda650b..548b428 100644 --- a/src/hub/PolicyHub.Service/BusinessLogic/PolicyHubBusinessLogic.cs +++ b/src/hub/PolicyHub.Service/BusinessLogic/PolicyHubBusinessLogic.cs @@ -20,6 +20,7 @@ using Org.Eclipse.TractusX.PolicyHub.DbAccess; using Org.Eclipse.TractusX.PolicyHub.DbAccess.Models; using Org.Eclipse.TractusX.PolicyHub.DbAccess.Repositories; +using Org.Eclipse.TractusX.PolicyHub.Entities.Entities; using Org.Eclipse.TractusX.PolicyHub.Entities.Enums; using Org.Eclipse.TractusX.PolicyHub.Service.Extensions; using Org.Eclipse.TractusX.PolicyHub.Service.Models; @@ -52,19 +53,26 @@ public async Task GetPolicyContentWithFiltersAsync(UseCaseId? us } var (rightOperand, additionalAttribute) = attributes.Key != null ? - GetRightOperand(operatorId, attributes, rightOperands, value, leftOperand) : + GetRightOperand(operatorId, attributes, rightOperands, value, leftOperand, useCase) : (rightOperandValue!, null); - return new PolicyResponse(CreateFileContent(type, operatorId, leftOperand, rightOperand), additionalAttribute == null ? null : Enumerable.Repeat(additionalAttribute, 1)); + return new PolicyResponse(CreateFileContent(type, operatorId, "cx-policy:" + leftOperand, rightOperand), additionalAttribute == null ? null : Enumerable.Repeat(additionalAttribute, 1)); } - private static (object rightOperand, AdditionalAttributes? additionalAttribute) GetRightOperand(OperatorId operatorId, (AttributeKeyId? Key, IEnumerable Values) attributes, IEnumerable rightOperands, string? value, string leftOperand) => + private static (object rightOperand, AdditionalAttributes? additionalAttribute) GetRightOperand(OperatorId operatorId, (AttributeKeyId? Key, IEnumerable Values) attributes, IEnumerable rightOperands, string? value, string leftOperand, UseCaseId? useCase) => attributes.Key switch { AttributeKeyId.DynamicValue => (value ?? "{dynamicValue}", null), AttributeKeyId.Regex => (GetRegexValue(attributes, value), null), _ => operatorId == OperatorId.Equals - ? rightOperands.Count() > 1 ? ($"@{leftOperand}-{attributes.Key}", new AdditionalAttributes($"@{leftOperand}-{attributes.Key}", rightOperands)) : (rightOperands.Single(), null) + ? rightOperands.Count() > 1 ? + ($"@{leftOperand}{(useCase != null ? + useCase.ToString().Insert(0, ".") : + string.Empty)}-{attributes.Key}", + new AdditionalAttributes($"@{leftOperand}{(useCase != null ? + useCase.ToString().Insert(0, ".") : + string.Empty)}-{attributes.Key}", rightOperands)) : + (rightOperands.Single(), null) : (rightOperands, null) }; @@ -163,7 +171,7 @@ public async Task GetPolicyContentAsync(PolicyContentRequest req } var (rightOperand, additionalAttribute) = policy.Attributes.Key != null ? - GetRightOperand(constraint.Operator, policy.Attributes, rightOperands, constraint.Value, policy.LeftOperand) : + GetRightOperand(constraint.Operator, policy.Attributes, rightOperands, constraint.Value, policy.LeftOperand, null) : (policy.RightOperandValue!, null); if (additionalAttribute != null) { @@ -173,7 +181,7 @@ public async Task GetPolicyContentAsync(PolicyContentRequest req constraints.Add(new Constraint(null, null, - policy.LeftOperand, + "cx-policy:" + policy.LeftOperand, constraint.Operator.OperatorToJsonString(), rightOperand )); diff --git a/tests/database/PolicyHub.DbAccess.Tests/PolicyRepositoryTests.cs b/tests/database/PolicyHub.DbAccess.Tests/PolicyRepositoryTests.cs index 373577d..389b85e 100644 --- a/tests/database/PolicyHub.DbAccess.Tests/PolicyRepositoryTests.cs +++ b/tests/database/PolicyHub.DbAccess.Tests/PolicyRepositoryTests.cs @@ -72,15 +72,13 @@ public async Task GetPolicyTypes_ReturnsExpectedResult() var result = await sut.GetPolicyTypes(null, null).ToListAsync(); // Assert - result.Should().NotBeEmpty().And.HaveCount(8).And.Satisfy( + result.Should().NotBeEmpty().And.HaveCount(6).And.Satisfy( x => x.TechnicalKey == "BusinessPartnerNumber", x => x.TechnicalKey == "Membership", - x => x.TechnicalKey == "FrameworkAgreement.traceability", - x => x.TechnicalKey == "FrameworkAgreement.quality", - x => x.TechnicalKey == "FrameworkAgreement.pcf", - x => x.TechnicalKey == "FrameworkAgreement.behavioraltwin", - x => x.TechnicalKey == "companyRole.dismantler", - x => x.TechnicalKey == "purpose" + x => x.TechnicalKey == "FrameworkAgreement", + x => x.TechnicalKey == "Dismantler.allowedBrands", + x => x.TechnicalKey == "UsagePurpose", + x => x.TechnicalKey == "Dismantler" ); } @@ -94,10 +92,11 @@ public async Task GetPolicyTypes_WithTypeFilter_ReturnsExpectedResult() var result = await sut.GetPolicyTypes(PolicyTypeId.Access, null).ToListAsync(); // Assert - result.Should().NotBeEmpty().And.HaveCount(3).And.Satisfy( + result.Should().NotBeEmpty().And.HaveCount(4).And.Satisfy( x => x.TechnicalKey == "BusinessPartnerNumber" && x.Attribute.Count() == 1 && x.Type.Count() == 2 && x.UseCase.Count() == 5, x => x.TechnicalKey == "Membership" && x.Attribute.Count() == 1 && x.Type.Count() == 2 && x.UseCase.Count() == 5, - x => x.TechnicalKey == "companyRole.dismantler" && x.Attribute.Count() == 3 && x.Type.Count() == 2 && x.UseCase.Count() == 5 + x => x.TechnicalKey == "Dismantler.allowedBrands" && x.Attribute.Count() == 3 && x.Type.Count() == 2 && x.UseCase.Count() == 5, + x => x.TechnicalKey == "Dismantler" && x.Attribute.Count() == 1 && x.Type.Count() == 2 && x.UseCase.Count() == 5 ); } @@ -108,13 +107,15 @@ public async Task GetPolicyTypes_WithUseCase_ReturnsExpectedResult() var sut = await CreateSut(); // Act - var result = await sut.GetPolicyTypes(null, UseCaseId.Sustainability).ToListAsync(); + var result = await sut.GetPolicyTypes(null, UseCaseId.Quality).ToListAsync(); // Assert - result.Should().NotBeEmpty().And.HaveCount(3).And.Satisfy( + result.Should().NotBeEmpty().And.HaveCount(5).And.Satisfy( x => x.TechnicalKey == "BusinessPartnerNumber" && x.Attribute.Count() == 1 && x.Type.Count() == 2 && x.UseCase.Count() == 5, x => x.TechnicalKey == "Membership" && x.Attribute.Count() == 1 && x.Type.Count() == 2 && x.UseCase.Count() == 5, - x => x.TechnicalKey == "companyRole.dismantler" && x.Attribute.Count() == 3 && x.Type.Count() == 2 && x.UseCase.Count() == 5 + x => x.TechnicalKey == "Dismantler.allowedBrands" && x.Attribute.Count() == 3 && x.Type.Count() == 2 && x.UseCase.Count() == 5, + x => x.TechnicalKey == "FrameworkAgreement" && x.Attribute.Count() == 10 && x.Type.Count() == 1 && x.UseCase.Count() == 5, + x => x.TechnicalKey == "Dismantler" && x.Attribute.Count() == 1 && x.Type.Count() == 2 && x.UseCase.Count() == 5 ); } @@ -147,15 +148,25 @@ public async Task GetPolicyContentAsync_WithRightOperand_ReturnsExpectedResult() var sut = await CreateSut(); // Act - var result = await sut.GetPolicyContentAsync(null, PolicyTypeId.Usage, "FrameworkAgreement.behavioraltwin"); + var result = await sut.GetPolicyContentAsync(null, PolicyTypeId.Usage, "FrameworkAgreement"); // Assert result.Exists.Should().BeTrue(); result.Attributes.Key.Should().Be(AttributeKeyId.Version); - result.Attributes.Values.Should().ContainSingle() - .And.Satisfy(x => x == "1.0"); - result.LeftOperand.Should().Be("FrameworkAgreement.behavioraltwin"); - result.RightOperandValue.Should().Be("active:{0}"); + result.Attributes.Values.Should().Satisfy( + x => x == "Traceability:1.0", + x => x == "Traceability:1.1", + x => x == "Traceability:1.2", + x => x == "Quality:1.0", + x => x == "PCF:1.0", + x => x == "Behavioraltwin:1.0", + x => x == "Circulareconomy:1.0", + x => x == "Demandcapacity:1.0", + x => x == "Puris:1.0", + x => x == "Businesspartner:1.0" + ); + result.LeftOperand.Should().Be("FrameworkAgreement"); + result.RightOperandValue.Should().BeNull(); } #endregion diff --git a/tests/hub/PolicyHub.Service.Tests/BusinessLogic/PolicyHubBusinessLogicTests.cs b/tests/hub/PolicyHub.Service.Tests/BusinessLogic/PolicyHubBusinessLogicTests.cs index f265624..1626f6d 100644 --- a/tests/hub/PolicyHub.Service.Tests/BusinessLogic/PolicyHubBusinessLogicTests.cs +++ b/tests/hub/PolicyHub.Service.Tests/BusinessLogic/PolicyHubBusinessLogicTests.cs @@ -181,8 +181,8 @@ public async Task GetPolicyContentWithFiltersAsync_WithMultipleValues_ReturnsExp x => x == "value2", x => x == "value3" ); - result.Content.Permission.Constraint.RightOperandValue.Should().Be("@multipleAdditionalValues-Static"); - result.Content.Permission.Constraint.LeftOperand.Should().Be("multipleAdditionalValues"); + result.Content.Permission.Constraint.RightOperandValue.Should().Be("@multipleAdditionalValues.Traceability-Static"); + result.Content.Permission.Constraint.LeftOperand.Should().Be("cx-policy:multipleAdditionalValues"); result.Content.Permission.Constraint.Operator.Should().Be("eq"); result.Content.Permission.Constraint.AndOperands.Should().BeNull(); result.Content.Permission.Constraint.OrOperands.Should().BeNull(); @@ -422,10 +422,10 @@ public async Task GetPolicyContentAsync_WithValid_ReturnsExpected() result.Content.Permission.Constraint.AndOperands.Should().BeNull(); result.Content.Permission.Constraint.OrOperands.Should().HaveCount(4) .And.Satisfy( - x => x.LeftOperand == "active" && x.Operator == "in" && ((x.RightOperandValue as IEnumerable)!).Count() == 2, - x => x.LeftOperand == "active" && x.Operator == "eq" && x.RightOperandValue as string == "BPNL00000001TEST", - x => x.LeftOperand == "active" && x.Operator == "eq" && x.RightOperandValue as string == "{dynamicValue}", - x => x.LeftOperand == "active" && x.Operator == "eq" && x.RightOperandValue as string == "test"); + x => x.LeftOperand == "cx-policy:active" && x.Operator == "in" && ((x.RightOperandValue as IEnumerable)!).Count() == 2, + x => x.LeftOperand == "cx-policy:active" && x.Operator == "eq" && x.RightOperandValue as string == "BPNL00000001TEST", + x => x.LeftOperand == "cx-policy:active" && x.Operator == "eq" && x.RightOperandValue as string == "{dynamicValue}", + x => x.LeftOperand == "cx-policy:active" && x.Operator == "eq" && x.RightOperandValue as string == "test"); } [Fact] @@ -461,8 +461,8 @@ public async Task GetPolicyContentAsync_WithMultipleValues_ReturnsExpected() result.Content.Permission.Constraint.OrOperands.Should().BeNull(); result.Content.Permission.Constraint.AndOperands.Should().HaveCount(2) .And.Satisfy( - x => x.LeftOperand == "multipleAdditionalValues" && x.Operator == "eq" && x.RightOperandValue as string == "@multipleAdditionalValues-Static", - x => x.LeftOperand == "test" && x.Operator == "in" && (x.RightOperandValue as IEnumerable)!.Count() == 2); + x => x.LeftOperand == "cx-policy:multipleAdditionalValues" && x.Operator == "eq" && x.RightOperandValue as string == "@multipleAdditionalValues-Static", + x => x.LeftOperand == "cx-policy:test" && x.Operator == "in" && (x.RightOperandValue as IEnumerable)!.Count() == 2); result.AdditionalAttributes.Should().ContainSingle() .And.Satisfy(x => x.Key == "@multipleAdditionalValues-Static"); result.AdditionalAttributes!.Single().PossibleValues.Should().HaveCount(3) diff --git a/tests/hub/PolicyHub.Service.Tests/Controllers/PolicyHubControllerTests.cs b/tests/hub/PolicyHub.Service.Tests/Controllers/PolicyHubControllerTests.cs index ccb5aab..805abcd 100644 --- a/tests/hub/PolicyHub.Service.Tests/Controllers/PolicyHubControllerTests.cs +++ b/tests/hub/PolicyHub.Service.Tests/Controllers/PolicyHubControllerTests.cs @@ -78,15 +78,13 @@ public async Task GetPolicyTypes_WithoutFilter_ReturnsExpected() // Assert policies.Should().NotBeNull() - .And.HaveCount(8).And.Satisfy( + .And.HaveCount(6).And.Satisfy( x => x.TechnicalKey == "BusinessPartnerNumber", x => x.TechnicalKey == "Membership", - x => x.TechnicalKey == "FrameworkAgreement.traceability", - x => x.TechnicalKey == "FrameworkAgreement.quality", - x => x.TechnicalKey == "FrameworkAgreement.pcf", - x => x.TechnicalKey == "FrameworkAgreement.behavioraltwin", - x => x.TechnicalKey == "companyRole.dismantler", - x => x.TechnicalKey == "purpose" + x => x.TechnicalKey == "FrameworkAgreement", + x => x.TechnicalKey == "Dismantler.allowedBrands", + x => x.TechnicalKey == "UsagePurpose", + x => x.TechnicalKey == "Dismantler" ); } @@ -98,10 +96,11 @@ public async Task GetPolicyTypes_WithTypeFilter_ReturnsExpected() // Assert policies.Should().NotBeNull() - .And.HaveCount(3).And.Satisfy( + .And.HaveCount(4).And.Satisfy( x => x.TechnicalKey == "BusinessPartnerNumber", x => x.TechnicalKey == "Membership", - x => x.TechnicalKey == "companyRole.dismantler" + x => x.TechnicalKey == "Dismantler.allowedBrands", + x => x.TechnicalKey == "Dismantler" ); } @@ -113,12 +112,13 @@ public async Task GetPolicyTypes_WithUseCaseFilter_ReturnsExpected() // Assert policies.Should().NotBeNull() - .And.HaveCount(5).And.Satisfy( + .And.HaveCount(6).And.Satisfy( x => x.TechnicalKey == "BusinessPartnerNumber", x => x.TechnicalKey == "Membership", - x => x.TechnicalKey == "FrameworkAgreement.traceability", - x => x.TechnicalKey == "companyRole.dismantler", - x => x.TechnicalKey == "purpose" + x => x.TechnicalKey == "FrameworkAgreement", + x => x.TechnicalKey == "Dismantler.allowedBrands", + x => x.TechnicalKey == "UsagePurpose", + x => x.TechnicalKey == "Dismantler" ); } @@ -165,35 +165,35 @@ public async Task GetPolicyContent_BpnWithValue_ReturnsExpected() response.StatusCode.Should().Be(HttpStatusCode.OK); (await response.Content.ReadAsStringAsync()) .Should() - .Be("{\"content\":{\"@context\":[\"https://www.w3.org/ns/odrl.jsonld\",{\"cx\":\"https://w3id.org/catenax/v0.0.1/ns/\"}],\"@type\":\"Offer\",\"@id\":\"....\",\"permission\":{\"action\":\"use\",\"constraint\":{\"leftOperand\":\"BusinessPartnerNumber\",\"operator\":\"eq\",\"rightOperand\":\"BPNL00000003CRHK\"}}}}"); + .Be("{\"content\":{\"@context\":[\"https://www.w3.org/ns/odrl.jsonld\",{\"cx\":\"https://w3id.org/catenax/v0.0.1/ns/\"}],\"@type\":\"Offer\",\"@id\":\"....\",\"permission\":{\"action\":\"use\",\"constraint\":{\"leftOperand\":\"cx-policy:BusinessPartnerNumber\",\"operator\":\"eq\",\"rightOperand\":\"BPNL00000003CRHK\"}}}}"); } [Fact] public async Task GetPolicyContent_UsageFrameworkEquals_ReturnsExpected() { // Act - var response = await _client.GetAsync($"{BaseUrl}/policy-content?type={PolicyTypeId.Usage}&policyName=FrameworkAgreement.traceability&operatorType={OperatorId.Equals}"); + var response = await _client.GetAsync($"{BaseUrl}/policy-content?useCase=Traceability&type={PolicyTypeId.Usage}&policyName=FrameworkAgreement&operatorType={OperatorId.Equals}"); // Assert response.Should().NotBeNull(); response.StatusCode.Should().Be(HttpStatusCode.OK); (await response.Content.ReadAsStringAsync()) .Should() - .Be("{\"content\":{\"@context\":[\"https://www.w3.org/ns/odrl.jsonld\",{\"cx\":\"https://w3id.org/catenax/v0.0.1/ns/\"}],\"@type\":\"Offer\",\"@id\":\"....\",\"permission\":{\"action\":\"use\",\"constraint\":{\"leftOperand\":\"FrameworkAgreement.traceability\",\"operator\":\"eq\",\"rightOperand\":\"@FrameworkAgreement.traceability-Version\"}}},\"attributes\":[{\"key\":\"@FrameworkAgreement.traceability-Version\",\"possibleValues\":[\"active:1.0\",\"active:1.1\",\"active:1.2\"]}]}"); + .Be("{\"content\":{\"@context\":[\"https://www.w3.org/ns/odrl.jsonld\",{\"cx\":\"https://w3id.org/catenax/v0.0.1/ns/\"}],\"@type\":\"Offer\",\"@id\":\"....\",\"permission\":{\"action\":\"use\",\"constraint\":{\"leftOperand\":\"cx-policy:FrameworkAgreement\",\"operator\":\"eq\",\"rightOperand\":\"@FrameworkAgreement.Traceability-Version\"}}},\"attributes\":[{\"key\":\"@FrameworkAgreement.Traceability-Version\",\"possibleValues\":[\"Traceability:1.0\",\"Traceability:1.1\",\"Traceability:1.2\"]}]}"); } [Fact] public async Task GetPolicyContent_UsageDismantlerIn_ReturnsExpected() { // Act - var response = await _client.GetAsync($"{BaseUrl}/policy-content?type={PolicyTypeId.Usage}&policyName=companyRole.dismantler&operatorType={OperatorId.In}"); + var response = await _client.GetAsync($"{BaseUrl}/policy-content?type={PolicyTypeId.Usage}&policyName=Dismantler.allowedBrands&operatorType={OperatorId.In}"); // Assert response.Should().NotBeNull(); response.StatusCode.Should().Be(HttpStatusCode.OK); (await response.Content.ReadAsStringAsync()) .Should() - .Be("{\"content\":{\"@context\":[\"https://www.w3.org/ns/odrl.jsonld\",{\"cx\":\"https://w3id.org/catenax/v0.0.1/ns/\"}],\"@type\":\"Offer\",\"@id\":\"....\",\"permission\":{\"action\":\"use\",\"constraint\":{\"leftOperand\":\"Dismantler.activityType\",\"operator\":\"in\",\"rightOperand\":[\"Audi\",\"BMW\",\"VW\"]}}}}"); + .Be("{\"content\":{\"@context\":[\"https://www.w3.org/ns/odrl.jsonld\",{\"cx\":\"https://w3id.org/catenax/v0.0.1/ns/\"}],\"@type\":\"Offer\",\"@id\":\"....\",\"permission\":{\"action\":\"use\",\"constraint\":{\"leftOperand\":\"cx-policy:Dismantler.allowedBrands\",\"operator\":\"in\",\"rightOperand\":[\"BMW\",\"Audi\",\"VW\"]}}}}"); } [Fact] @@ -207,7 +207,7 @@ public async Task GetPolicyContent_TraceabilityUsagePurposeEquals_ReturnsExpecte response.StatusCode.Should().Be(HttpStatusCode.OK); (await response.Content.ReadAsStringAsync()) .Should() - .Be("{\"content\":{\"@context\":[\"https://www.w3.org/ns/odrl.jsonld\",{\"cx\":\"https://w3id.org/catenax/v0.0.1/ns/\"}],\"@type\":\"Offer\",\"@id\":\"....\",\"permission\":{\"action\":\"use\",\"constraint\":{\"leftOperand\":\"Membership\",\"operator\":\"eq\",\"rightOperand\":\"active\"}}}}"); + .Be("{\"content\":{\"@context\":[\"https://www.w3.org/ns/odrl.jsonld\",{\"cx\":\"https://w3id.org/catenax/v0.0.1/ns/\"}],\"@type\":\"Offer\",\"@id\":\"....\",\"permission\":{\"action\":\"use\",\"constraint\":{\"leftOperand\":\"cx-policy:Membership\",\"operator\":\"eq\",\"rightOperand\":\"active\"}}}}"); } #endregion @@ -223,8 +223,8 @@ public async Task GetPolicyContentWithFiltersAsync_TwoEqualsConstraintsAndOperan ConstraintOperandId.And, new[] { - new Constraints("FrameworkAgreement.traceability", OperatorId.Equals, "1.0"), - new Constraints("companyRole.dismantler", OperatorId.In, "Audi") + new Constraints("FrameworkAgreement", OperatorId.Equals, "Traceability:1.0"), + new Constraints("Dismantler.allowedBrands", OperatorId.In, "Audi") }); // Act @@ -235,7 +235,7 @@ public async Task GetPolicyContentWithFiltersAsync_TwoEqualsConstraintsAndOperan response.StatusCode.Should().Be(HttpStatusCode.OK); (await response.Content.ReadAsStringAsync()) .Should() - .Be("{\"content\":{\"@context\":[\"https://www.w3.org/ns/odrl.jsonld\",{\"cx\":\"https://w3id.org/catenax/v0.0.1/ns/\"}],\"@type\":\"Offer\",\"@id\":\"....\",\"permission\":{\"action\":\"use\",\"constraint\":{\"odrl:and\":[{\"leftOperand\":\"FrameworkAgreement.traceability\",\"operator\":\"eq\",\"rightOperand\":\"@FrameworkAgreement.traceability-Version\"},{\"leftOperand\":\"Dismantler.activityType\",\"operator\":\"in\",\"rightOperand\":[\"Audi\",\"BMW\",\"VW\"]}]}}},\"attributes\":[{\"key\":\"@FrameworkAgreement.traceability-Version\",\"possibleValues\":[\"active:1.0\",\"active:1.1\",\"active:1.2\"]}]}"); + .Be("{\"content\":{\"@context\":[\"https://www.w3.org/ns/odrl.jsonld\",{\"cx\":\"https://w3id.org/catenax/v0.0.1/ns/\"}],\"@type\":\"Offer\",\"@id\":\"....\",\"permission\":{\"action\":\"use\",\"constraint\":{\"odrl:and\":[{\"leftOperand\":\"cx-policy:Dismantler.allowedBrands\",\"operator\":\"in\",\"rightOperand\":[\"BMW\",\"Audi\",\"VW\"]},{\"leftOperand\":\"cx-policy:FrameworkAgreement\",\"operator\":\"eq\",\"rightOperand\":\"@FrameworkAgreement-Version\"}]}}},\"attributes\":[{\"key\":\"@FrameworkAgreement-Version\",\"possibleValues\":[\"Traceability:1.0\",\"Traceability:1.1\",\"Traceability:1.2\",\"Quality:1.0\",\"PCF:1.0\",\"Behavioraltwin:1.0\",\"Circulareconomy:1.0\",\"Demandcapacity:1.0\",\"Puris:1.0\",\"Businesspartner:1.0\"]}]}"); } [Fact] @@ -268,8 +268,8 @@ public async Task GetPolicyContentWithFiltersAsync_MultipleConstraintsEqualsAndO ConstraintOperandId.And, new[] { - new Constraints("FrameworkAgreement.traceability", OperatorId.Equals, "1.0"), - new Constraints("companyRole.dismantler", OperatorId.In, "Audi"), + new Constraints("FrameworkAgreement", OperatorId.Equals, "Traceability:1.0"), + new Constraints("Dismantler.allowedBrands", OperatorId.In, "Audi"), new Constraints("BusinessPartnerNumber", OperatorId.Equals, "BPNL00000003CRHK") }); @@ -281,81 +281,9 @@ public async Task GetPolicyContentWithFiltersAsync_MultipleConstraintsEqualsAndO response.StatusCode.Should().Be(HttpStatusCode.OK); (await response.Content.ReadAsStringAsync()) .Should() - .Be("{\"content\":{\"@context\":[\"https://www.w3.org/ns/odrl.jsonld\",{\"cx\":\"https://w3id.org/catenax/v0.0.1/ns/\"}],\"@type\":\"Offer\",\"@id\":\"....\",\"permission\":{\"action\":\"use\",\"constraint\":{\"odrl:and\":[{\"leftOperand\":\"BusinessPartnerNumber\",\"operator\":\"eq\",\"rightOperand\":\"BPNL00000003CRHK\"},{\"leftOperand\":\"FrameworkAgreement.traceability\",\"operator\":\"eq\",\"rightOperand\":\"@FrameworkAgreement.traceability-Version\"},{\"leftOperand\":\"Dismantler.activityType\",\"operator\":\"in\",\"rightOperand\":[\"Audi\",\"BMW\",\"VW\"]}]}}},\"attributes\":[{\"key\":\"@FrameworkAgreement.traceability-Version\",\"possibleValues\":[\"active:1.0\",\"active:1.1\",\"active:1.2\"]}]}"); + .Be("{\"content\":{\"@context\":[\"https://www.w3.org/ns/odrl.jsonld\",{\"cx\":\"https://w3id.org/catenax/v0.0.1/ns/\"}],\"@type\":\"Offer\",\"@id\":\"....\",\"permission\":{\"action\":\"use\",\"constraint\":{\"odrl:and\":[{\"leftOperand\":\"cx-policy:BusinessPartnerNumber\",\"operator\":\"eq\",\"rightOperand\":\"BPNL00000003CRHK\"},{\"leftOperand\":\"cx-policy:Dismantler.allowedBrands\",\"operator\":\"in\",\"rightOperand\":[\"BMW\",\"Audi\",\"VW\"]},{\"leftOperand\":\"cx-policy:FrameworkAgreement\",\"operator\":\"eq\",\"rightOperand\":\"@FrameworkAgreement-Version\"}]}}},\"attributes\":[{\"key\":\"@FrameworkAgreement-Version\",\"possibleValues\":[\"Traceability:1.0\",\"Traceability:1.1\",\"Traceability:1.2\",\"Quality:1.0\",\"PCF:1.0\",\"Behavioraltwin:1.0\",\"Circulareconomy:1.0\",\"Demandcapacity:1.0\",\"Puris:1.0\",\"Businesspartner:1.0\"]}]}"); } - // [Fact] - // public async Task GetPolicyContentWithFiltersAsync_MultipleConstraintsEqualsOrOperand_ReturnsExpected() - // { - // // Arrange - // var data = new PolicyContentRequest( - // PolicyTypeId.Usage, - // ConstraintOperandId.Or, - // new[] - // { - // new Constraints("FrameworkAgreement.traceability", OperatorId.Equals, null), - // new Constraints("companyRole.dismantler", OperatorId.In, null), - // }); - // [Fact] - // public async Task GetPolicyContentWithFiltersAsync_MultipleConstraintsEqualsOrOperand_ReturnsExpected() - // { - // // Arrange - // var data = new PolicyContentRequest( - // PolicyTypeId.Usage, - // ConstraintOperandId.Or, - // new[] - // { - // new Constraints("FrameworkAgreement.traceability", OperatorId.Equals, null), - // new Constraints("companyRole.dismantler", OperatorId.In, null), - // }); - - // // Act - // var response = await _client.PostAsJsonAsync($"{BaseUrl}/policy-content", data, JsonOptions); - - // // Assert - // response.Should().NotBeNull(); - // response.StatusCode.Should().Be(HttpStatusCode.OK); - // (await response.Content.ReadAsStringAsync()) - // .Should() - // .Be("{\"content\":{\"@context\":[\"https://www.w3.org/ns/odrl.jsonld\",{\"cx\":\"https://w3id.org/catenax/v0.0.1/ns/\"}],\"@type\":\"Offer\",\"@id\":\"....\",\"permission\":{\"action\":\"use\",\"constraint\":{\"odrl:or\":[{\"leftOperand\":\"FrameworkAgreement.traceability\",\"operator\":\"eq\",\"rightOperand\":\"@FrameworkAgreement.traceability-Version\"},{\"leftOperand\":\"Dismantler.activityType\",\"operator\":\"in\",\"rightOperand\":[\"Audi\",\"BMW\",\"VW\"]}]}}},\"attributes\":[{\"key\":\"@FrameworkAgreement.traceability-Version\",\"possibleValues\":[\"active:1.0\",\"active:1.1\",\"active:1.2\"]}]}"); - // } - - // [Fact] - // public async Task GetPolicyContentWithFiltersAsync_WithSameConstraintKeys_ReturnsError() - // { - // // Arrange - // var data = new PolicyContentRequest( - // PolicyTypeId.Usage, - // ConstraintOperandId.Or, - // new[] - // { - // new Constraints("FrameworkAgreement.traceability", OperatorId.Equals, null), - // new Constraints("FrameworkAgreement.traceability", OperatorId.Equals, null), - // }); - // [Fact] - // public async Task GetPolicyContentWithFiltersAsync_WithSameConstraintKeys_ReturnsError() - // { - // // Arrange - // var data = new PolicyContentRequest( - // PolicyTypeId.Usage, - // ConstraintOperandId.Or, - // new[] - // { - // new Constraints("FrameworkAgreement.traceability", OperatorId.Equals, null), - // new Constraints("FrameworkAgreement.traceability", OperatorId.Equals, null), - // }); - - // // Act - // var response = await _client.PostAsJsonAsync($"{BaseUrl}/policy-content", data, JsonOptions); - - // // Assert - // response.Should().NotBeNull(); - // response.StatusCode.Should().Be(HttpStatusCode.BadRequest); - // var error = await response.Content.ReadFromJsonAsync(JsonOptions); - // error!.Errors.Should().ContainSingle().And.Satisfy( - // x => x.Value.Single() == "Keys FrameworkAgreement.traceability have been defined multiple times"); - // } - #endregion #region Swagger