Skip to content

Commit

Permalink
Merge pull request #59 from Worth-NL/feature/Settings_Move-OMC-Workfl…
Browse files Browse the repository at this point in the history
…ows_ToEnvVar

Feature/settings move omc workflows to env var
  • Loading branch information
Thomas-M-Krystyan authored Sep 6, 2024
2 parents afd6402 + e4874a5 commit a2ade41
Show file tree
Hide file tree
Showing 20 changed files with 155 additions and 154 deletions.
74 changes: 31 additions & 43 deletions Documentation/OMC - Documentation.md

Large diffs are not rendered by default.

Binary file not shown.
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.810";
internal const string Version = "1.811";
}
#endregion

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public IActionResult Version()

return Ok($"{Resources.Application_Name}: v{DefaultValues.ApiController.Version} " +
$"({Environment.GetEnvironmentVariable(DefaultValues.EnvironmentVariables.AspNetCoreEnvironment)}) | " +
$"Workflow: v{this._configuration.AppSettings.Features.OmcWorkflowVersion()} " +
$"Workflow: v{this._configuration.OMC.Features.Workflow_Version()} " +
$"{this._register.GetVersions()}");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,30 @@ internal static class ConfigurationExtensions
/// </summary>
/// <param name="configuration">The application configuration.</param>
internal static bool IsEncryptionAsymmetric(this IConfiguration configuration)
=> configuration.GetValue<bool>(key: $"{nameof(WebApiConfiguration.AppSettings.Encryption)}:" +
$"{nameof(WebApiConfiguration.AppSettings.Encryption.IsAsymmetric)}");
{
const string key = $"{nameof(WebApiConfiguration.AppSettings.Encryption)}:" +
$"{nameof(WebApiConfiguration.AppSettings.Encryption.IsAsymmetric)}";

return configuration.GetValue<bool>(key);
}

private static string? s_omcWorkflowVersionKey;
private static byte? s_omcWorkflowVersionValue;

/// <summary>
/// Gets the version of Open services ("OpenNotificaties", "OpenZaak", "OpenKlant") which should be used in business logic.
/// </summary>
/// <param name="configuration">The application configuration.</param>
internal static byte OmcWorkflowVersion(this IConfiguration configuration)
=> configuration.GetValue<byte>(key: $"{nameof(WebApiConfiguration.AppSettings.Features)}:" +
$"{nameof(WebApiConfiguration.AppSettings.Features.OmcWorkflowVersion)}");
internal static byte OmcWorkflowVersion()
{
s_omcWorkflowVersionKey ??= ($"{nameof(WebApiConfiguration.OMC)}_" +
$"{nameof(WebApiConfiguration.OMC.Features)}_" +
$"{nameof(WebApiConfiguration.OMC.Features.Workflow_Version)}")
.ToUpper();

return s_omcWorkflowVersionValue ??=
byte.Parse(
Environment.GetEnvironmentVariable(s_omcWorkflowVersionKey) ?? "0");
}
#endregion

#region Validation
Expand Down
39 changes: 19 additions & 20 deletions EventsHandler/Api/EventsHandler/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
using Swashbuckle.AspNetCore.Filters;
using System.Diagnostics.CodeAnalysis;
using System.Reflection;
using ConfigurationExtensions = EventsHandler.Extensions.ConfigurationExtensions;
using OpenKlant = EventsHandler.Services.DataQuerying.Composition.Strategy.OpenKlant;
using OpenZaak = EventsHandler.Services.DataQuerying.Composition.Strategy.OpenZaak;
using Register = EventsHandler.Services.Register;
Expand Down Expand Up @@ -318,60 +319,58 @@ private static void RegisterOpenServices(this WebApplicationBuilder builder)
// Common query methods
builder.Services.AddSingleton<IQueryBase, QueryBase>();

byte omcWorkflowVersion = builder.Configuration.OmcWorkflowVersion();

// Strategies
builder.Services.AddSingleton(typeof(OpenZaak.Interfaces.IQueryZaak), DetermineOpenZaakVersion(omcWorkflowVersion));
builder.Services.AddSingleton(typeof(OpenKlant.Interfaces.IQueryKlant), DetermineOpenKlantVersion(omcWorkflowVersion));
builder.Services.AddSingleton(typeof(IQueryObjecten), DetermineObjectenVersion(omcWorkflowVersion));
builder.Services.AddSingleton(typeof(IQueryObjectTypen), DetermineObjectTypenVersion(omcWorkflowVersion));
builder.Services.AddSingleton(typeof(OpenZaak.Interfaces.IQueryZaak), DetermineOpenZaakVersion());
builder.Services.AddSingleton(typeof(OpenKlant.Interfaces.IQueryKlant), DetermineOpenKlantVersion());
builder.Services.AddSingleton(typeof(IQueryObjecten), DetermineObjectenVersion());
builder.Services.AddSingleton(typeof(IQueryObjectTypen), DetermineObjectTypenVersion());

// Feedback and telemetry
builder.Services.AddSingleton(typeof(ITelemetryService), DetermineTelemetryVersion(omcWorkflowVersion));
builder.Services.AddSingleton(typeof(ITelemetryService), DetermineTelemetryVersion());

return;

static Type DetermineOpenZaakVersion(byte omcWorkflowVersion)
static Type DetermineOpenZaakVersion()
{
return omcWorkflowVersion switch
return ConfigurationExtensions.OmcWorkflowVersion() switch
{
1 => typeof(OpenZaak.v1.QueryZaak),
2 => typeof(OpenZaak.v2.QueryZaak),
_ => throw new NotImplementedException(Resources.Configuration_ERROR_VersionOpenZaakUnknown)
};
}

static Type DetermineOpenKlantVersion(byte omcWorkflowVersion)
static Type DetermineOpenKlantVersion()
{
return omcWorkflowVersion switch
return ConfigurationExtensions.OmcWorkflowVersion() switch
{
1 => typeof(OpenKlant.v1.QueryKlant),
2 => typeof(OpenKlant.v2.QueryKlant),
_ => throw new NotImplementedException(Resources.Configuration_ERROR_VersionOpenKlantUnknown)
};
}

static Type DetermineObjectenVersion(byte omcWorkflowVersion)
static Type DetermineObjectenVersion()
{
return omcWorkflowVersion switch
return ConfigurationExtensions.OmcWorkflowVersion() switch
{
1 or 2 => typeof(QueryObjecten),
_ => throw new NotImplementedException(Resources.Configuration_ERROR_VersionObjectenUnknown)
};
}

static Type DetermineObjectTypenVersion(byte omcWorkflowVersion)
static Type DetermineObjectTypenVersion()
{
return omcWorkflowVersion switch
return ConfigurationExtensions.OmcWorkflowVersion() switch
{
1 or 2 => typeof(QueryObjectTypen),
_ => throw new NotImplementedException(Resources.Configuration_ERROR_VersionObjectTypenUnknown)
};
}

static Type DetermineTelemetryVersion(byte omcWorkflowVersion)
static Type DetermineTelemetryVersion()
{
return omcWorkflowVersion switch
return ConfigurationExtensions.OmcWorkflowVersion() switch
{
1 => typeof(Register.v1.ContactRegistration),
2 => typeof(Register.v2.ContactRegistration),
Expand All @@ -392,13 +391,13 @@ private static void RegisterResponders(this WebApplicationBuilder builder)
builder.Services.AddSingleton<IRespondingService<NotificationEvent>, Responder.OmcResponder>();

// Explicit interfaces (generic) used by other controllers => check "IRespondingService<TResult, TDetails>"
builder.Services.AddSingleton(typeof(Responder.NotifyResponder), DetermineResponderVersion(builder));
builder.Services.AddSingleton(typeof(Responder.NotifyResponder), DetermineResponderVersion());

return;

static Type DetermineResponderVersion(WebApplicationBuilder builder)
static Type DetermineResponderVersion()
{
return builder.Configuration.OmcWorkflowVersion() switch
return ConfigurationExtensions.OmcWorkflowVersion() switch
{
1 => typeof(Responder.v1.NotifyCallbackResponder),
2 => typeof(Responder.v2.NotifyCallbackResponder),
Expand Down
12 changes: 6 additions & 6 deletions EventsHandler/Api/EventsHandler/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions EventsHandler/Api/EventsHandler/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -358,13 +358,13 @@
<value>This type of HttpClient is not supported yet:</value>
</data>
<data name="Configuration_ERROR_VersionOpenKlantUnknown" xml:space="preserve">
<value>The version of OpenKlant service to be used by OMC is unknown or not supported ('Features:OmcWorkflowVersion').</value>
<value>The version of OpenKlant service to be used by OMC is unknown or not supported. Check used version of OMC workflow.</value>
</data>
<data name="Configuration_ERROR_VersionOpenZaakUnknown" xml:space="preserve">
<value>The version of OpenZaak service to be used by OMC is unknown or not supported ('Features:OmcWorkflowVersion').</value>
<value>The version of OpenZaak service to be used by OMC is unknown or not supported. Check used version of OMC workflow.</value>
</data>
<data name="Configuration_ERROR_VersionTelemetryUnknown" xml:space="preserve">
<value>The version of Telemetry service to be used by OMC is unknown or not supported ('Features:OmcWorkflowVersion').</value>
<value>The version of Telemetry service to be used by OMC is unknown or not supported. Check used version of OMC workflow.</value>
</data>
<data name="Events_NotifyClientInitialized" xml:space="preserve">
<value>The Notify HttpClient was initialized for organization ID: {0}.</value>
Expand All @@ -382,7 +382,7 @@
<value>HTTP Request: It was not possible to determine any matching digital addresses (e-mail or phone number) in any of the contact details for any of the parties (citizens, organizations) retrieved from OpenKlant Web API service.</value>
</data>
<data name="Configuration_ERROR_VersionNotifyResponderUnknown" xml:space="preserve">
<value>The version of NotifyResponder service to be used by OMC is unknown or not supported ('Features:OmcWorkflowVersion').</value>
<value>The version of NotifyResponder service to be used by OMC is unknown or not supported. Check used version of OMC workflow.</value>
</data>
<data name="Deserialization_ERROR_NotDeserialized_Notification_Properties_Reason1" xml:space="preserve">
<value>SENDER: In the received notification some [Required] properties are either null, empty, or with default values.</value>
Expand All @@ -394,10 +394,10 @@
<value>The notification can not be sent because the case type with identification {0} is not included in the {1}.</value>
</data>
<data name="Configuration_ERROR_VersionObjectenUnknown" xml:space="preserve">
<value>The version of Objecten service to be used by OMC is unknown or not supported ('Features:OmcWorkflowVersion').</value>
<value>The version of Objecten service to be used by OMC is unknown or not supported. Check used version of OMC workflow.</value>
</data>
<data name="Configuration_ERROR_VersionObjectTypenUnknown" xml:space="preserve">
<value>The version of ObjectTypen service to be used by OMC is unknown or not supported ('Features:OmcWorkflowVersion').</value>
<value>The version of ObjectTypen service to be used by OMC is unknown or not supported. Check used version of OMC workflow.</value>
</data>
<data name="HttpRequest_ERROR_NoTask" xml:space="preserve">
<value>HTTP Request: The task (object) could not be retrieved from Objecten Web API service.</value>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@

"OMC_API_BASEURL_NOTIFYNL": "https://api.acc.notifynl.nl",

"OMC_FEATURES_WORKFLOW_VERSION": "1",

// NOTE: This will be still used for OpenZaak and OpenKlant 1.0 or only for OpenZaak 1.0 if OpenKlant 2.0 is used
"USER_AUTHORIZATION_JWT_SECRET": "worthsys123",
"USER_AUTHORIZATION_JWT_ISSUER": "goc",
Expand Down Expand Up @@ -98,6 +100,8 @@

"OMC_API_BASEURL_NOTIFYNL": "https://api.acc.notifynl.nl",

"OMC_FEATURES_WORKFLOW_VERSION": "2",

// NOTE: This will be still used for OpenZaak and OpenKlant 1.0 or only for OpenZaak 1.0 if OpenKlant 2.0 is used
"USER_AUTHORIZATION_JWT_SECRET": "worthsys123",
"USER_AUTHORIZATION_JWT_ISSUER": "goc",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// © 2023, Worth Systems.

using EventsHandler.Constants;
using EventsHandler.Extensions;
using EventsHandler.Mapping.Models.POCOs.NotificatieApi;
using EventsHandler.Mapping.Models.POCOs.OpenKlant;
Expand Down Expand Up @@ -57,12 +56,17 @@ private static async Task<ContactMoment> SendFeedbackToOpenKlantAsync(

string jsonBody =
$"{{" +
$" \"bronorganisatie\": {notification.GetOrganizationId()}, " + // ENG: Source organization
$" \"registratiedatum\": {caseStatus.Created}, " + // ENG: Date of registration (of the case)
$" \"kanaal\": \"{notificationMethod}\", " + // ENG: Channel (of communication / notification)
$" \"tekst\": \"{logMessage}\", " + // ENG: Text (to be logged)
$" \"initiatief\": \"gemeente\", " + // ENG: Initiator (of the case)
$" \"medewerker\": \"{DefaultValues.Models.EmptyUri}\"" + // ENG: Worker / collaborator / contributor
$" \"bronorganisatie\": {notification.GetOrganizationId()}, " + // ENG: Source organization
$" \"registratiedatum\": \"{caseStatus.Created:yyyy-MM-ddThh:mm:ss}\", " + // ENG: Date of registration (of the case)
$" \"kanaal\": \"{notificationMethod}\", " + // ENG: Channel (of communication / notification)
$" \"tekst\": \"{logMessage}\", " + // ENG: Text (to be logged)
$" \"initiatief\": \"gemeente\", " + // ENG: Initiator (of the case)
$" \"medewerkerIdentificatie\": {{" + // ENG: Worker / collaborator / contributor
$" \"identificatie\": \"omc\", " +
$" \"achternaam\": \"omc\", " +
$" \"voorletters\": \"omc\", " +
$" \"voorvoegselAchternaam\": \"omc\"" +
$" }}" +
$"}}";

return await queryContext.SendFeedbackToOpenKlantAsync(jsonBody);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ ObjectResult IRespondingService.Get_Exception_ActionResult(string errorMessage)
return ObjectResultExtensions.AsResult_400(message ?? errorMessage);
}

/// <inheritdoc cref="IRespondingService.Get_Exception_ActionResult(Microsoft.AspNetCore.Mvc.Filters.ResultExecutingContext,System.Collections.Generic.IDictionary{string,string[]})"/>
/// <inheritdoc cref="IRespondingService.Get_Exception_ActionResult(ResultExecutingContext, IDictionary{string,string[]})"/>
ResultExecutingContext IRespondingService.Get_Exception_ActionResult(ResultExecutingContext context, IDictionary<string, string[]> errorDetails)
{
if (((IRespondingService)this).ContainsErrorMessage(errorDetails, out string errorMessage))
Expand Down
Loading

0 comments on commit a2ade41

Please sign in to comment.