Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/merge in system text json branch #377

Open
wants to merge 8 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions CDP4Authentication/CDP4Authentication.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFramework>net9.0</TargetFramework>
<Company>Starion Group S.A.</Company>
<Title>CDP4Authentication-CE</Title>
<Version>9.0.0</Version>
<Version>10.0.0</Version>
<Description>CDP4-COMET Library to support the implementation of authentication</Description>
<Copyright>Copyright © Starion Group S.A.</Copyright>
<Authors>Sam Gerené, Alex Vorobiev, Alexander van Delft</Authors>
Expand All @@ -13,9 +13,5 @@
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<LangVersion>latest</LangVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>

</Project>
14 changes: 11 additions & 3 deletions CDP4Authentication/Contracts/AuthenticatorPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
using System;
using System.Collections.Generic;
using System.IO;

using Newtonsoft.Json;
using System.Text.Json;
using System.Text.Json.Serialization;

/// <summary>
/// Generic abstract Authentication plugin definition.
Expand All @@ -43,13 +43,21 @@
where TProperties : IAuthenticatorProperties
where TConnector : AuthenticatorConnector<TProperties>
{
/// <summary>
/// Gets the <see cref="JsonSerializerOptions"/> to be used on serialization
/// </summary>
protected JsonSerializerOptions JsonSerializerOptions { get; }

/// <summary>
/// Initializes a new instance of the <see cref="AuthenticatorPlugin{TProperties, TConnector}"/> class.
/// </summary>
protected AuthenticatorPlugin()
{
this.LoadConfig();
this.InitializeConnectors();
this.JsonSerializerOptions = new JsonSerializerOptions(JsonSerializerOptions.Default);
lxatstariongroup marked this conversation as resolved.
Show resolved Hide resolved
this.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter(null, false));

Check warning on line 59 in CDP4Authentication/Contracts/AuthenticatorPlugin.cs

View workflow job for this annotation

GitHub Actions / Build

Remove this default value assigned to parameter 'namingPolicy'. (https://rules.sonarsource.com/csharp/RSPEC-3254)

Check warning on line 59 in CDP4Authentication/Contracts/AuthenticatorPlugin.cs

View workflow job for this annotation

GitHub Actions / Build

Remove this default value assigned to parameter 'namingPolicy'. (https://rules.sonarsource.com/csharp/RSPEC-3254)

Check warning on line 59 in CDP4Authentication/Contracts/AuthenticatorPlugin.cs

View workflow job for this annotation

GitHub Actions / Build

Remove this default value assigned to parameter 'namingPolicy'. (https://rules.sonarsource.com/csharp/RSPEC-3254)
this.JsonSerializerOptions.PropertyNamingPolicy = JsonNamingPolicy.CamelCase;
}

/// <summary>
Expand Down Expand Up @@ -117,7 +125,7 @@
/// </returns>
protected virtual AuthenticatorConfig<TProperties> DeserializeConfigFile(string json, string configLocation)
{
var appConfig = JsonConvert.DeserializeObject<AuthenticatorConfig<TProperties>>(json);
var appConfig = JsonSerializer.Deserialize<AuthenticatorConfig<TProperties>>(json, this.JsonSerializerOptions);

if (appConfig == null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFramework>net9.0</TargetFramework>
<Company>Starion Group S.A.</Company>
<Title>CDP4DatabaseAuthentication-CE</Title>
<Version>9.0.0</Version>
<Version>10.0.0</Version>
<Description>CDP4-COMET Database authentication</Description>
<Copyright>Copyright © Starion Group S.A.</Copyright>
<Authors>Sam Gerené, Alex Vorobiev, Alexander van Delft</Authors>
Expand Down
10 changes: 2 additions & 8 deletions CDP4Orm/CDP4Orm.csproj
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<Company>Starion Group S.A.</Company>
<Title>CDP4Orm-CE</Title>
<Version>9.0.0</Version>
<Version>10.0.0</Version>
<Description>CDP4-COMET Data-Model Object Relational Mapping</Description>
<Copyright>Copyright © Starion Group S.A.</Copyright>
<Authors>Sam Gerené, Alex Vorobiev, Alexander van Delft</Authors>
<Configurations>Debug;Release</Configurations>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<LangVersion>latest</LangVersion>
</PropertyGroup>

<ItemGroup>
<Compile Remove="MigrationScript\WithoutViews\**" />
<Compile Remove="MigrationScript\WithViews\**" />
Expand All @@ -21,7 +19,6 @@
<None Remove="MigrationScript\WithoutViews\**" />
<None Remove="MigrationScript\WithViews\**" />
</ItemGroup>

<ItemGroup>
<None Remove="AutoGenStructure\01_SiteDirectory_setup.sql" />
<None Remove="AutoGenStructure\02_SiteDirectory_structure.sql" />
Expand Down Expand Up @@ -50,7 +47,6 @@
<None Remove="MigrationScript\SiteDirectory_20200612_6_1_0_0_reset_statement_timeout.sql" />
<None Remove="MigrationScript\SiteDirectory_20210108_6_3_0_0_Model_Updates.sql" />
</ItemGroup>

<ItemGroup>
<EmbeddedResource Include="AutoGenStructure\01_SiteDirectory_setup.sql" />
<EmbeddedResource Include="AutoGenStructure\02_SiteDirectory_structure.sql" />
Expand Down Expand Up @@ -78,9 +74,8 @@
<EmbeddedResource Include="MigrationScript\SiteDirectory_20181016_1_0_11_1_UsernameConstraint.sql" />
<EmbeddedResource Include="MigrationScript\SiteDirectory_20210108_6_3_0_0_Model_Updates.sql" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="CDP4JsonSerializer-CE" Version="27.4.2" />
<PackageReference Include="CDP4JsonSerializer-CE" Version="28.0.0-rc31" />
<PackageReference Include="Npgsql" Version="9.0.2" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="9.0.1" />
</ItemGroup>
Expand All @@ -92,5 +87,4 @@
<ItemGroup>
<ProjectReference Include="..\CDP4Authentication\CDP4Authentication.csproj" />
</ItemGroup>

</Project>
9 changes: 4 additions & 5 deletions CDP4Orm/Dao/BaseDao.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,12 @@ namespace CDP4Orm.Dao
{
using System;
using System.Collections.Generic;
using System.Text.Json;

using CDP4Common.DTO;

using CDP4JsonSerializer;

using Newtonsoft.Json.Linq;

using Npgsql;

/// <summary>
Expand All @@ -54,7 +53,7 @@ public abstract class BaseDao
/// The <see cref="NpgsqlTransaction"/> for which <see cref="currentTransactionDatetime"/> was retrieved
/// </summary>
private NpgsqlTransaction currentTransactionDataTimeTransaction;

/// <summary>
/// Execute additional logic before each update function call.
/// </summary>
Expand Down Expand Up @@ -306,6 +305,7 @@ private DateTime GetTransactionDateTime(NpgsqlTransaction transaction)
using var command = new NpgsqlCommand("SELECT * FROM \"SiteDirectory\".\"get_transaction_time\"();",
transaction.Connection,
transaction);

this.currentTransactionDatetime = (DateTime)command.ExecuteScalar();
}

Expand All @@ -319,8 +319,7 @@ private DateTime GetTransactionDateTime(NpgsqlTransaction transaction)
/// <returns>A <see cref="Thing"/></returns>
protected Thing MapJsonbToDto(NpgsqlDataReader reader)
{
var jsonObject = JObject.Parse(reader.GetValue(0).ToString());

var jsonObject = JsonSerializer.Deserialize<JsonElement>(reader.GetValue(0).ToString());
Thing thing;

try
Expand Down
15 changes: 11 additions & 4 deletions CDP4Orm/Dao/Cache/CacheDao.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ namespace CDP4Orm.Dao.Cache

using Microsoft.Extensions.Logging;

using Newtonsoft.Json;

using Npgsql;

using NpgsqlTypes;
Expand Down Expand Up @@ -98,7 +96,7 @@ public void Write(NpgsqlTransaction transaction, string partition, Thing thing)

command.Parameters.Add("iid", NpgsqlDbType.Uuid).Value = thing.Iid;
command.Parameters.Add("revisionnumber", NpgsqlDbType.Integer).Value = thing.RevisionNumber;
command.Parameters.Add("jsonb", NpgsqlDbType.Jsonb).Value = thing.ToJsonObject().ToString(Formatting.None);
command.Parameters.Add("jsonb", NpgsqlDbType.Jsonb).Value = thing.ToJsonString();

// log the sql command
command.ExecuteNonQuery();
Expand Down Expand Up @@ -129,7 +127,16 @@ public void BulkWrite(NpgsqlTransaction transaction, string partition, IReadOnly
{
var iidParam = new NpgsqlParameter($"iid_{index}", NpgsqlDbType.Uuid) { Value = thing.Iid };
var revisionParam = new NpgsqlParameter($"revision_{index}", NpgsqlDbType.Integer) { Value = thing.RevisionNumber };
var jsonbParam = new NpgsqlParameter($"jsonb_{index}", NpgsqlDbType.Jsonb) { Value = thing.ToJsonObject().ToString(Formatting.None) };
var jsonbParam = new NpgsqlParameter($"jsonb_{index}", NpgsqlDbType.Jsonb);

var serializedJson = thing.ToJsonString();

if (string.IsNullOrWhiteSpace(serializedJson))
{
serializedJson = "{}";
}

jsonbParam.Value = serializedJson;

parameters.Add(iidParam);
parameters.Add(revisionParam);
Expand Down
10 changes: 4 additions & 6 deletions CDP4Orm/Dao/Revision/RevisionDao.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,14 @@ namespace CDP4Orm.Dao.Revision
using System.Data;
using System.Linq;
using System.Text;
using System.Text.Json;

using CDP4Common.CommonData;

using CDP4JsonSerializer;

using Microsoft.Extensions.Logging;

using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

using Npgsql;

using NpgsqlTypes;
Expand Down Expand Up @@ -192,7 +190,7 @@ public void WriteRevision(NpgsqlTransaction transaction, string partition, Thing
command.Parameters.Add("iid", NpgsqlDbType.Uuid).Value = thing.Iid;
command.Parameters.Add("revisionnumber", NpgsqlDbType.Integer).Value = thing.RevisionNumber;
command.Parameters.Add("actor", NpgsqlDbType.Uuid).Value = actor;
command.Parameters.Add("jsonb", NpgsqlDbType.Jsonb).Value = thing.ToJsonObject().ToString(Formatting.None);
command.Parameters.Add("jsonb", NpgsqlDbType.Jsonb).Value = thing.ToJsonString();

command.ExecuteNonQuery();
}
Expand Down Expand Up @@ -226,7 +224,7 @@ public void BulkWriteRevision(NpgsqlTransaction transaction, string partition, I
var iidParam = new NpgsqlParameter($"iid_{index}", NpgsqlDbType.Uuid) { Value = thing.Iid };
var revisionParam = new NpgsqlParameter($"revisionnumber_{index}", NpgsqlDbType.Integer) { Value = thing.RevisionNumber };
var actorParam = new NpgsqlParameter($"actor_{index}", NpgsqlDbType.Uuid) { Value = actor };
var jsonbParam = new NpgsqlParameter($"jsonb_{index}", NpgsqlDbType.Jsonb) { Value = thing.ToJsonObject().ToString(Formatting.None) };
var jsonbParam = new NpgsqlParameter($"jsonb_{index}", NpgsqlDbType.Jsonb) { Value = thing.ToJsonString() };

parameters.Add(iidParam);
parameters.Add(revisionParam);
Expand Down Expand Up @@ -663,7 +661,7 @@ private static string GetThingRevisionTableName(ClassKind classKind)
/// <returns>A <see cref="Thing"/></returns>
private Thing MapToDto(NpgsqlDataReader reader)
{
var jsonObject = JObject.Parse(reader.GetValue(0).ToString());
var jsonObject = JsonSerializer.Deserialize<JsonElement>(reader.GetValue(0).ToString());

Thing thing;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFramework>net9.0</TargetFramework>
<Company>Starion Group S.A.</Company>
<Title>CDP4WspDatabaseAuthentication-CE</Title>
<Version>9.0.0</Version>
<Version>10.0.0</Version>
<Description>CDP4-COMET WSP Database authentication</Description>
<Copyright>Copyright © Starion Group S.A.</Copyright>
<Authors>Sam Gerené, Alex Vorobiev, Alexander van Delft</Authors>
Expand Down
3 changes: 2 additions & 1 deletion COMET-WebServices.sln
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,14 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
docker-compose-nginx.yml = docker-compose-nginx.yml
docker-compose.yml = docker-compose.yml
Dockerfile = Dockerfile
DockerfilePreRelease = DockerfilePreRelease
Nuget.Config = Nuget.Config
README.md = README.md
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CDP4Authentication.Tests", "CDP4Authentication.Tests\CDP4Authentication.Tests.csproj", "{551D1D98-92D6-4391-ADB8-448BC9219330}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VersionFileCreator", "VersionFileCreator\VersionFileCreator.csproj", "{E941F9C0-139A-4DB7-9C98-32A320378DDB}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "VersionFileCreator", "VersionFileCreator\VersionFileCreator.csproj", "{E941F9C0-139A-4DB7-9C98-32A320378DDB}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
Loading
Loading