From 1ccff502deff6925a9a90a26966de41597311496 Mon Sep 17 00:00:00 2001 From: Kanwalmeet Singh Date: Fri, 10 Feb 2023 13:57:14 +0100 Subject: [PATCH] updates for COLID 2.11 release --- .../COLID.Scheduler.Common.csproj | 2 ++ .../Constants/Metadata.cs | 31 ++++++++++++------- src/COLID.Scheduler.Web/appsettings.json | 4 ++- tests/UnitTests/Builder/ContactBuilder.cs | 12 +++++-- tests/UnitTests/TestData.cs | 22 +++++++++---- 5 files changed, 51 insertions(+), 20 deletions(-) diff --git a/src/COLID.Scheduler.Common/COLID.Scheduler.Common.csproj b/src/COLID.Scheduler.Common/COLID.Scheduler.Common.csproj index 895e0c4..3055ac0 100644 --- a/src/COLID.Scheduler.Common/COLID.Scheduler.Common.csproj +++ b/src/COLID.Scheduler.Common/COLID.Scheduler.Common.csproj @@ -5,6 +5,8 @@ + + diff --git a/src/COLID.Scheduler.Common/Constants/Metadata.cs b/src/COLID.Scheduler.Common/Constants/Metadata.cs index 4a919bd..1e811d2 100644 --- a/src/COLID.Scheduler.Common/Constants/Metadata.cs +++ b/src/COLID.Scheduler.Common/Constants/Metadata.cs @@ -1,28 +1,37 @@ -using System; -using System.Collections.Generic; -using System.Text; +using System.IO; +using Microsoft.Extensions.Configuration; namespace COLID.Scheduler.Common.Constants { public static class Metadata { - public const string Author = "https://pid.bayer.com/kos/19050/author"; + private static readonly string _basePath = Path.GetFullPath("appsettings.json"); + private static readonly string _filePath = _basePath.Substring(0, _basePath.Length - 16); + private static IConfigurationRoot _configuration = new ConfigurationBuilder() + .SetBasePath(_filePath) + .AddJsonFile("appsettings.json") + .Build(); + public static readonly string _serviceUrl = _configuration.GetValue("ServiceUrl"); - public const string LastChangeUser = "https://pid.bayer.com/kos/19050/lastChangeUser"; + public static readonly string Author = _serviceUrl + "kos/19050/author"; - public const string DataSteward = "https://pid.bayer.com/kos/19050/hasDataSteward"; + public static readonly string LastChangeUser = _serviceUrl + "kos/19050/lastChangeUser"; - public const string ContactPerson = "https://pid.bayer.com/kos/19050/hasContactPerson"; + public static readonly string DataSteward = _serviceUrl + "kos/19050/hasDataSteward"; - public const string ChangeRequester = "https://pid.bayer.com/kos/19050/546454"; + public static readonly string ContactPerson = _serviceUrl + "kos/19050/hasContactPerson"; - public const string ConsumerGroup = "https://pid.bayer.com/kos/19050#hasConsumerGroup"; + public static readonly string ChangeRequester = _serviceUrl + "kos/19050/546454"; - public const string InformationClassification = "https://pid.bayer.com/kos/19050/hasInformationClassification"; + public static readonly string ConsumerGroup = _serviceUrl + "kos/19050#hasConsumerGroup"; + + public static readonly string InformationClassification = _serviceUrl + "kos/19050/hasInformationClassification"; public const string W3Type = "http://www/w3/org/1999/02/22-rdf-syntax-ns#type"; - public const string LifecyleStatus = "https://pid.bayer.com/kos/19050/hasLifecycleStatus"; + public static readonly string LifecyleStatus = _serviceUrl + "kos/19050/hasLifecycleStatus"; + + public static readonly string ConsumerGroupContact = _serviceUrl + "kos/19050/hasConsumerGroupContactPerson"; } } diff --git a/src/COLID.Scheduler.Web/appsettings.json b/src/COLID.Scheduler.Web/appsettings.json index 712d46a..2e4db40 100644 --- a/src/COLID.Scheduler.Web/appsettings.json +++ b/src/COLID.Scheduler.Web/appsettings.json @@ -11,5 +11,7 @@ "CorrelationId": "Warning" } }, - "AllowedHosts": "*" + "AllowedHosts": "*", + "ServiceUrl": "https://pid.bayer.com/", + "HttpServiceUrl": "http://pid.bayer.com/" } \ No newline at end of file diff --git a/tests/UnitTests/Builder/ContactBuilder.cs b/tests/UnitTests/Builder/ContactBuilder.cs index 7785886..b21a5d5 100644 --- a/tests/UnitTests/Builder/ContactBuilder.cs +++ b/tests/UnitTests/Builder/ContactBuilder.cs @@ -1,14 +1,22 @@ using System; using System.Collections.Generic; +using System.IO; using System.Text; using COLID.Scheduler.Common.DataModels; +using Microsoft.Extensions.Configuration; namespace UnitTests.Builder { public class ContactBuilder { private ContactDto _contact = new ContactDto(); - + private static readonly string _basePath = Path.GetFullPath("appsettings.json"); + private static readonly string _filePath = _basePath.Substring(0, _basePath.Length - 16); + private static IConfigurationRoot _configuration = new ConfigurationBuilder() + .SetBasePath(_filePath) + .AddJsonFile("appsettings.json") + .Build(); + public static readonly string _serviceUrl = _configuration.GetValue("ServiceUrl"); public ContactBuilder() { } @@ -21,7 +29,7 @@ public ContactDto Build() public ContactBuilder GenerateSampleData() { WithEmailAddress("marcus.davies@bayer.com"); - WithTypeUri(new Uri("https://pid.bayer.com/kos/19050/hasContactPerson")); + WithTypeUri(new Uri(_serviceUrl + "kos/19050/hasContactPerson")); WithTypeLabel("Contact Person"); IsTechnical(false); return this; diff --git a/tests/UnitTests/TestData.cs b/tests/UnitTests/TestData.cs index eab5ea9..dc6b786 100644 --- a/tests/UnitTests/TestData.cs +++ b/tests/UnitTests/TestData.cs @@ -1,13 +1,23 @@ using System; using System.Collections.Generic; +using System.IO; using System.Text; using COLID.Scheduler.Common.DataModels; +using Microsoft.Extensions.Configuration; using UnitTests.Builder; +using COLID.Scheduler.Common.Constants; namespace UnitTests { public static class TestData { + private static readonly string _basePath = Path.GetFullPath("appsettings.json"); + private static readonly string _filePath = _basePath.Substring(0, _basePath.Length - 16); + private static IConfigurationRoot _configuration = new ConfigurationBuilder() + .SetBasePath(_filePath) + .AddJsonFile("appsettings.json") + .Build(); + public static readonly string _serviceUrl = _configuration.GetValue("ServiceUrl"); public static AdUserDto GenerateAdUser(bool enabled = true) { var id = Guid.NewGuid().ToString(); @@ -18,7 +28,7 @@ public static AdUserDto GenerateAdUser(bool enabled = true) public static ColidEntryContactsDto GenerateColidEntryContacts(string colidEntryLabel, IEnumerable contacts) { return new ColidEntryContactBuilder() - .WithPidUri($"https://pid.bayer.com/{Guid.NewGuid()}") + .WithPidUri($"{_serviceUrl}{Guid.NewGuid()}") .WithLabel(colidEntryLabel) .WithContacts(contacts) .WithConsumerGroupContact(GenerateContactConsumerGroupAdmin()) @@ -45,7 +55,7 @@ public static ContactDto GenerateContactConsumerGroupAdmin() { return new ContactBuilder() .WithEmailAddress("consumer.group.admin@bayer.com") - .WithTypeUri("https://pid.bayer.com/kos/19050/hasConsumerGroupContactPerson") + .WithTypeUri(Metadata.ConsumerGroupContact) .WithTypeLabel("Contact Person") .Build(); } @@ -54,7 +64,7 @@ public static ContactDto GenerateContactContactPerson(string email) { return new ContactBuilder() .WithEmailAddress(email) - .WithTypeUri("https://pid.bayer.com/kos/19050/hasContactPerson") + .WithTypeUri(Metadata.ContactPerson) .WithTypeLabel("Contact Person") .IsTechnical(false) .Build(); @@ -64,7 +74,7 @@ public static ContactDto GenerateContactLastChangeUser(string email) { return new ContactBuilder() .WithEmailAddress(email) - .WithTypeUri("https://pid.bayer.com/kos/19050/lastChangeUser") + .WithTypeUri(Metadata.LastChangeUser) .WithTypeLabel("Last Change User") .IsTechnical(true) .Build(); @@ -74,7 +84,7 @@ public static ContactDto GenerateContactAuthor(string email) { return new ContactBuilder() .WithEmailAddress(email) - .WithTypeUri("https://pid.bayer.com/kos/19050/author") + .WithTypeUri(Metadata.Author) .WithTypeLabel("Author") .IsTechnical(true) .Build(); @@ -84,7 +94,7 @@ public static ContactDto GenerateContactDataSteward(string email) { return new ContactBuilder() .WithEmailAddress(email) - .WithTypeUri("https://pid.bayer.com/kos/19050/hasDataSteward") + .WithTypeUri(Metadata.DataSteward) .WithTypeLabel("Data Steward") .IsTechnical(false) .Build();