Skip to content

Commit

Permalink
Merge pull request #69 from Worth-NL/fix/Serialization_CommonTaskData…
Browse files Browse the repository at this point in the history
…_NijmegenCase

Fix/serialization common task data nijmegen case
  • Loading branch information
Thomas-M-Krystyan authored Sep 19, 2024
2 parents 4a0467d + 99e4157 commit e4ced85
Show file tree
Hide file tree
Showing 12 changed files with 199 additions and 79 deletions.
2 changes: 1 addition & 1 deletion Documentation/OMC - Documentation.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# **OMC** Documentation

v.1.8.16
v.1.8.17

© 2024, Worth Systems.

Expand Down
2 changes: 1 addition & 1 deletion EventsHandler/Api/EventsHandler/Constants/DefaultValues.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ internal static class ApiController
{
internal const string Route = "[controller]";

internal const string Version = "1.816";
internal const string Version = "1.817";
}
#endregion

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ namespace EventsHandler.Mapping.Models.POCOs.Objecten.Task
internal readonly struct CommonTaskData : IJsonSerializable
{
/// <summary>
/// The reference to related object in <see cref="System.Uri"/> format:
/// The reference to related object in <see cref="Uri"/> format:
/// <code>
/// http(s)://Domain/ApiEndpoint/[UUID]
/// </code>
/// </summary>
[JsonRequired]
[JsonInclude]
[JsonPropertyOrder(0)]
internal Uri CaseUri { get; init; } // NOTE: Some task data might not have it (recreating of URI is necessary)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ internal static CommonTaskData ConvertToUnified(this vNijmegen.TaskObject taskNi
{
return new CommonTaskData
{
CaseUri = RecreateCaseUri(taskNijmegen.Record.Data.Coupling.Id), // NOTE: GUID is given, URI needs to be recreated
CaseId = taskNijmegen.Record.Data.Coupling.Id,
CaseUri = RecreateCaseUri(taskNijmegen.Record.Data.TaskForm.Coupling.Id), // NOTE: GUID is given, URI needs to be recreated
CaseId = taskNijmegen.Record.Data.TaskForm.Coupling.Id,
Title = taskNijmegen.Record.Data.Title,
Status = taskNijmegen.Record.Data.Status,
ExpirationDate = taskNijmegen.Record.Data.ExpirationDate,
Identification = taskNijmegen.Record.Data.Identification
ExpirationDate = taskNijmegen.Record.Data.TaskForm.ExpirationDate,
Identification = taskNijmegen.Record.Data.TaskForm.Identification
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,31 @@
namespace EventsHandler.Mapping.Models.POCOs.Objecten.Task.vNijmegen
{
/// <summary>
/// The coupling related to the <see cref="TaskObject"/> retrieved from "Objecten" Web API service.
/// The coupling related to the <see cref="TaskForm"/> retrieved from "Objecten" Web API service.
/// </summary>
/// <remarks>
/// Version used by Nijmegen.
/// </remarks>
/// <seealso cref="IJsonSerializable"/>
public struct Coupling : IJsonSerializable
{
/// <summary>
/// The type of the <see cref="Coupling"/>.
/// The ID of the <see cref="Coupling"/> object (e.g., case).
/// </summary>
[JsonRequired]
[JsonInclude]
[JsonPropertyName("registratie")]
[JsonPropertyName("uuid")]
[JsonPropertyOrder(0)]
public Registrations Type { get; internal set; }
public Guid Id { get; internal set; } = Guid.Empty;

/// <summary>
/// The ID of the <see cref="Coupling"/> object (e.g., case).
/// The type of the <see cref="Coupling"/>.
/// </summary>
[JsonRequired]
[JsonInclude]
[JsonPropertyName("uuid")]
[JsonPropertyName("registratie")]
[JsonPropertyOrder(1)]
public Guid Id { get; internal set; } = Guid.Empty;
public Registrations Type { get; internal set; }

/// <summary>
/// Initializes a new instance of the <see cref="Coupling"/> struct.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,26 +30,12 @@ public struct Data : IJsonSerializable
[JsonPropertyOrder(1)]
public TaskStatuses Status { get; internal set; }

/// <inheritdoc cref="CommonTaskData.ExpirationDate"/>
/// <inheritdoc cref="vNijmegen.TaskForm"/>
[JsonRequired]
[JsonInclude]
[JsonPropertyName("verloopdatum")]
[JsonPropertyName("formtaak")]
[JsonPropertyOrder(2)]
public DateTime ExpirationDate { get; internal set; }

/// <inheritdoc cref="CommonTaskData.Identification"/>
[JsonRequired]
[JsonInclude]
[JsonPropertyName("identificatie")]
[JsonPropertyOrder(3)]
public Identification Identification { get; internal set; }

/// <inheritdoc cref="CommonTaskData.Identification"/>
[JsonRequired]
[JsonInclude]
[JsonPropertyName("koppeling")]
[JsonPropertyOrder(4)]
public Coupling Coupling { get; internal set; }
public TaskForm TaskForm { get; internal set; }

/// <summary>
/// Initializes a new instance of the <see cref="Data"/> struct.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// // © 2024, Worth Systems.

using EventsHandler.Mapping.Models.Interfaces;
using System.Text.Json.Serialization;

namespace EventsHandler.Mapping.Models.POCOs.Objecten.Task.vNijmegen
{
/// <summary>
/// The task form related to the <see cref="Data"/> retrieved from "Objecten" Web API service.
/// </summary>
/// <remarks>
/// Version used by Nijmegen.
/// </remarks>
/// <seealso cref="IJsonSerializable"/>
public struct TaskForm : IJsonSerializable
{
/// <inheritdoc cref="vNijmegen.Coupling"/>
[JsonRequired]
[JsonInclude]
[JsonPropertyName("koppeling")]
[JsonPropertyOrder(0)]
public Coupling Coupling { get; internal set; }

/// <inheritdoc cref="CommonTaskData.ExpirationDate"/>
[JsonRequired]
[JsonInclude]
[JsonPropertyName("verloopdatum")]
[JsonPropertyOrder(1)]
public DateTime ExpirationDate { get; internal set; }

/// <inheritdoc cref="CommonTaskData.Identification"/>
[JsonRequired]
[JsonInclude]
[JsonPropertyName("identificatie")]
[JsonPropertyOrder(2)]
public Identification Identification { get; internal set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@ public override DateTime Read(ref Utf8JsonReader reader, Type typeToConvert, Jso
{
return reader.TokenType == JsonTokenType.Null
? DateTime.MinValue
: reader.GetDateTime();
: DateTime.TryParse(reader.GetString(), out DateTime dateTime)
? dateTime
: DateTime.MinValue;
}

/// <inheritdoc cref="JsonConverter{TValue}.Write(Utf8JsonWriter, TValue, JsonSerializerOptions)"/>
public override void Write(Utf8JsonWriter writer, DateTime value, JsonSerializerOptions options)
{
writer.WriteStringValue(value.ToString("O"));
writer.WriteStringValue($"{value:O}");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,21 @@ TModel ISerializationService.Deserialize<TModel>(object json)
{
return JsonSerializer.Deserialize<TModel>($"{json}", s_serializerOptions);
}
#pragma warning disable CS0168 // The variable is used but only in DEBUG mode
catch (JsonException exception)
#pragma warning restore CS0168
{
#if DEBUG
TestContext.WriteLine(exception.Message);
#endif

string requiredProperties = GetRequiredMembers<TModel>();

throw new JsonException(message:
$"{Resources.Deserialization_ERROR_CannotDeserialize_Message} | " +
$"{Resources.Deserialization_ERROR_CannotDeserialize_Target}: {typeof(TModel).Name} | " +
$"{Resources.Deserialization_ERROR_CannotDeserialize_Value}: {json} | " +
$"{Resources.Deserialization_ERROR_CannotDeserialize_Required}: {GetRequiredMembers<TModel>()}");
$"{Resources.Deserialization_ERROR_CannotDeserialize_Required}: {(requiredProperties.IsEmpty() ? "_" : requiredProperties)}");
}
}

Expand All @@ -67,7 +71,7 @@ private static string GetRequiredMembers<TModel>()
typeof(TModel),
// Generate, cache, and get cached value
typeof(TModel)
.GetProperties(BindingFlags.Instance | BindingFlags.Public)
.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)
.Where(property => property.GetCustomAttribute<JsonRequiredAttribute>() != null)
.Select(property => property.GetCustomAttribute<JsonPropertyNameAttribute>()?.Name ?? property.Name)
.Join());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using EventsHandler.Mapping.Enums.NotificatieApi;
using EventsHandler.Mapping.Enums.NotifyNL;
using EventsHandler.Mapping.Enums.Objecten;
using EventsHandler.Mapping.Enums.Objecten.vNijmegen;
using EventsHandler.Mapping.Enums.OpenKlant;
using EventsHandler.Mapping.Enums.OpenZaak;
using System.Text.Json;
Expand Down Expand Up @@ -41,6 +42,8 @@ public sealed class EnumsTests
// Objecten: TaskStatuses
[TestCase(typeof(TaskStatuses), TaskStatuses.Open, "open")]
[TestCase(typeof(TaskStatuses), TaskStatuses.Closed, "gesloten")]
// Objecten/Nijmegen : Registrations
[TestCase(typeof(Registrations), Registrations.Case, "zaak")]
// NotifyNL: Notification types
[TestCase(typeof(NotificationTypes), NotificationTypes.Email, "email")]
[TestCase(typeof(NotificationTypes), NotificationTypes.Sms, "sms")]
Expand Down Expand Up @@ -99,6 +102,8 @@ public void JsonSerializer_CustomEnumSerialization_FromEnglishEnum_ToDutchJson(T
// Objecten: TaskStatuses
[TestCase("open", typeof(TaskStatuses), TaskStatuses.Open)]
[TestCase("gesloten", typeof(TaskStatuses), TaskStatuses.Closed)]
// Objecten/Nijmegen : Registrations
[TestCase("zaak", typeof(Registrations), Registrations.Case)]
// NotifyNL: Notification types
[TestCase("email", typeof(NotificationTypes), NotificationTypes.Email)]
[TestCase("sms", typeof(NotificationTypes), NotificationTypes.Sms)]
Expand Down Expand Up @@ -135,6 +140,7 @@ public void JsonSerializer_CustomEnumSerialization_FromDutchJson_ToEnglishEnum(s
// Objecten
[TestCase(":", typeof(IdTypes), IdTypes.Unknown)]
[TestCase(";", typeof(TaskStatuses), TaskStatuses.Unknown)]
[TestCase(".", typeof(Registrations), Registrations.Unknown)]
// NotifyNL
[TestCase("-", typeof(NotificationTypes), NotificationTypes.Unknown)]
[TestCase(" ", typeof(DeliveryStatuses), DeliveryStatuses.Unknown)]
Expand Down
Loading

0 comments on commit e4ced85

Please sign in to comment.