Skip to content

Commit

Permalink
Merge pull request #31 from Worth-NL/feature/OpenKlant_2.0_Init
Browse files Browse the repository at this point in the history
Feature/open klant 2.0 init
  • Loading branch information
Thomas-M-Krystyan authored May 14, 2024
2 parents 3b1ca01 + cc2a890 commit adeca80
Show file tree
Hide file tree
Showing 13 changed files with 152 additions and 26 deletions.
23 changes: 22 additions & 1 deletion Documentation/OMC - Documentation.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# OMC Documentation

v.1.7.2
v.1.7.3

© 2024, Worth Systems.

Expand Down Expand Up @@ -48,6 +48,27 @@ In `launchSettings.json` file, remember to always have these lines incuded in th

![Invalid base URL - Error](images/swagger_ui_launch_settings.png)

## 1.2. Docker

- After cloning **OMC** Git repository:
> [email protected]:Worth-NL/NotifyNL-OMC.git
- Go to the root catalog:
> .../NotifyNL-OMC
- And run the following **docker** command:
> docker build -f EventsHandler/Api/EventsHandler/Dockerfile --force-rm -t `omc` .
>
> NOTE: `omc` is just name of your **docker image** and it can be anything you want
The command from above is addressing the issue with building **docker image** from the `Dockerfile` location:
`ERROR: failed to solve: failed to compute cache key: failed to calculate checksum of ref`

![Docker - Failed to compute cache key](images/docker_error_failed_to_compute_cache_key.png)

- From this moment follow the **HELM Chart** documentation to set up _environment variables_
in order to run an already created **docker container**.

---
# 2. Architecture

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ protected virtual NotifyData GetEmailNotifyData(Case @case, CitizenData citizen)
#endregion

#region Abstract

/// <summary>
/// Gets the SMS template ID for this strategy.
/// </summary>
Expand All @@ -142,7 +141,7 @@ protected virtual NotifyData GetEmailNotifyData(Case @case, CitizenData citizen)
/// Gets the e-mail template ID for this strategy.
/// </summary>
/// <returns>
/// The template ID from "Notify NL" Web service in format "00000000-0000-0000-0000-00000000".
/// The template ID from "Notify NL" Web service in format "00000000-0000-0000-0000-00000000" (UUID).
/// </returns>
protected abstract string GetEmailTemplateId();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,8 @@ public ScenariosResolver(IServiceProvider serviceProvider, IDataQueryService<Not
/// <inheritdoc cref="IScenariosResolver.DetermineScenarioAsync(NotificationEvent)"/>
async Task<INotifyScenario> IScenariosResolver.DetermineScenarioAsync(NotificationEvent notification)
{
// Scenarios for Cases
if (notification.Action == Actions.Create &&
notification.Channel == Channels.Cases &&
notification.Resource == Resources.Status)
// Supported scenarios for business cases
if (CanProcess(notification))
{
CaseStatuses caseStatuses = await this._dataQuery.From(notification).GetCaseStatusesAsync();

Expand All @@ -54,8 +52,21 @@ async Task<INotifyScenario> IScenariosResolver.DetermineScenarioAsync(Notificati
return strategy;
}

// There is no matching scenario to be applied
// There is no matching scenario to be applied. There is no clear instruction what to do with received Notification
return this._serviceProvider.GetRequiredService<NotImplementedScenario>();
}

/// <summary>
/// OMC is meant to process <see cref="NotificationEvent"/>s with certain characteristics (determining the workflow).
/// </summary>
private static bool CanProcess(NotificationEvent notification)
{
return notification is
{
Action: Actions.Create,
Channel: Channels.Cases,
Resource: Resources.Status
};
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

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

namespace EventsHandler.Behaviors.Mapping.Models.POCOs.OpenZaak
{
Expand Down Expand Up @@ -45,7 +46,7 @@ internal readonly CaseStatus LastStatus()
{
// NOTE: The statuses are ordered in reversed order (first item is the newest one)
return this.Count > 0 ? this.Results[0] // The very latest status
: new CaseStatus();
: throw new HttpRequestException(Resources.HttpRequest_ERROR_NoLastStatus);
}
}
}
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.72";
internal const string Version = "1.73";
}
#endregion

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Asp.Versioning;
using EventsHandler.Behaviors.Responding.Messages.Models.Base;
using EventsHandler.Constants;
using EventsHandler.Properties;
using Microsoft.AspNetCore.Mvc;

namespace EventsHandler.Controllers.Base
Expand Down Expand Up @@ -60,18 +61,18 @@ protected ObjectResult LogApiResponse(Exception exception, ObjectResult objectRe
#region Sentry logging
private static readonly Dictionary<LogLevel, SentryLevel> s_logMapping = new()
{
{ LogLevel.Trace, SentryLevel.Debug },
{ LogLevel.Debug, SentryLevel.Debug },
{ LogLevel.Information, SentryLevel.Info },
{ LogLevel.Trace, SentryLevel.Debug },
{ LogLevel.Debug, SentryLevel.Debug },
{ LogLevel.Information, SentryLevel.Info },
{ LogLevel.Warning, SentryLevel.Warning },
{ LogLevel.Error, SentryLevel.Error },
{ LogLevel.Critical, SentryLevel.Fatal }
{ LogLevel.Error, SentryLevel.Error },
{ LogLevel.Critical, SentryLevel.Fatal }
};

/// <inheritdoc cref="SentrySdk.CaptureMessage(string, SentryLevel)"/>
private static void LogMessage(LogLevel logLevel, string logMessage)
{
_ = SentrySdk.CaptureMessage($"OMC | {logLevel:G} | {logMessage}", s_logMapping[logLevel]);
_ = SentrySdk.CaptureMessage($"{Resources.Application_Name} | {logLevel:G} | {logMessage}", s_logMapping[logLevel]);
}

/// <inheritdoc cref="SentrySdk.CaptureException(Exception)"/>
Expand All @@ -97,7 +98,7 @@ private static string DetermineResultMessage(ObjectResult objectResult)
BaseApiStandardResponseBody baseResponse => baseResponse.ToString(),

// Unknown object result
_ => $"Not standardized API response | {objectResult.StatusCode} | {nameof(objectResult.Value)}"
_ => $"{Resources.Processing_ERROR_UnspecifiedResponse} | {objectResult.StatusCode} | {nameof(objectResult.Value)}"
};
}
#endregion
Expand Down
58 changes: 56 additions & 2 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.

25 changes: 23 additions & 2 deletions EventsHandler/Api/EventsHandler/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -253,23 +253,25 @@
</data>
<data name="Processing_ERROR_Scenario_NotImplemented" xml:space="preserve">
<value>It was not possible to determine what to do with the received notification.</value>
<comment>HTTP Status Code = 206</comment>
</data>
<data name="Processing_ERROR_Telemetry_CompletionNotSent" xml:space="preserve">
<value>The notification was sent but the completion status could not be delivered to the external telemetry API endpoint.</value>
</data>
<data name="Processing_SUCCESS_Scenario_NotificationSent" xml:space="preserve">
<value>The notification has been successfully processed and sent to Notify NL.</value>
<comment>HTTP Status Code = 202 or 206</comment>
</data>
<data name="Swagger_Authentication_Description" xml:space="preserve">
<value>Insert received JWT token here</value>
<comment>Swagger UI</comment>
</data>
<data name="Swagger_Description" xml:space="preserve">
<value>Application handling the workflow between multiple Notify NL components.</value>
<value>API handling the data and communication workflow between multiple third-party components in order to send notifications through Notify NL.</value>
<comment>Swagger UI</comment>
</data>
<data name="Swagger_Title" xml:space="preserve">
<value>Notify NL - Events Handler</value>
<value>OMC (Output Management Component)</value>
<comment>Swagger UI</comment>
</data>
<data name="Swagger_Version" xml:space="preserve">
Expand Down Expand Up @@ -313,6 +315,7 @@
</data>
<data name="Register_NotifyNL_SUCCESS_NotificationSent" xml:space="preserve">
<value>The notification was passed to NotifyNL API.</value>
<comment>HTTP Status Code = 202 or 206</comment>
</data>
<data name="Feedback_NotifyNL_ERROR_UnexpectedFailure" xml:space="preserve">
<value>An unexpected error occurred during processing the notification with ID</value>
Expand All @@ -326,4 +329,22 @@
<value>Version of the API was requested</value>
<comment>API Endpoint: Events/Version</comment>
</data>
<data name="Application_Name" xml:space="preserve">
<value>OMC</value>
</data>
<data name="Deserialization_ERROR_CannotDeserialize_Message" xml:space="preserve">
<value>The given value cannot be deserialized into dedicated target object</value>
</data>
<data name="Deserialization_ERROR_CannotDeserialize_Target" xml:space="preserve">
<value>Target</value>
</data>
<data name="Deserialization_ERROR_CannotDeserialize_Value" xml:space="preserve">
<value>Value</value>
</data>
<data name="HttpRequest_ERROR_NoLastStatus" xml:space="preserve">
<value>HTTP Request: The case does not contain any statuses</value>
</data>
<data name="Processing_ERROR_UnspecifiedResponse" xml:space="preserve">
<value>Not standardized (unexpected) API response</value>
</data>
</root>
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// © 2023, Worth Systems.

using EventsHandler.Behaviors.Mapping.Models.Interfaces;
using EventsHandler.Behaviors.Mapping.Models.POCOs.NotificatieApi;
using EventsHandler.Behaviors.Mapping.Models.POCOs.OpenKlant;
using EventsHandler.Behaviors.Mapping.Models.POCOs.OpenZaak;
Expand Down Expand Up @@ -73,8 +74,7 @@ async Task<TModel> IQueryContext.ProcessGetAsync<TModel>(HttpClientTypes httpsCl

(bool isSuccess, string jsonResult) = await this._httpSupplier.GetAsync(httpsClientType, organizationId, uri);

return isSuccess ? this._serializer.Deserialize<TModel>(jsonResult)
: throw new HttpRequestException($"{fallbackErrorMessage} | URI: {uri} | JSON response: {jsonResult}");
return GetApiResult<TModel>(isSuccess, jsonResult, uri, fallbackErrorMessage);
}

/// <inheritdoc cref="IQueryContext.ProcessPostAsync{TModel}(HttpClientTypes, Uri, HttpContent, string)"/>
Expand All @@ -86,6 +86,12 @@ async Task<TModel> IQueryContext.ProcessPostAsync<TModel>(HttpClientTypes httpsC

(bool isSuccess, string jsonResult) = await this._httpSupplier.PostAsync(httpsClientType, organizationId, uri, body);

return GetApiResult<TModel>(isSuccess, jsonResult, uri, fallbackErrorMessage);
}

private TModel GetApiResult<TModel>(bool isSuccess, string jsonResult, Uri uri, string fallbackErrorMessage)
where TModel : struct, IJsonSerializable
{
return isSuccess ? this._serializer.Deserialize<TModel>(jsonResult)
: throw new HttpRequestException($"{fallbackErrorMessage} | URI: {uri} | JSON response: {jsonResult}");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,28 @@

using EventsHandler.Services.Serialization.Interfaces;
using System.Text.Json;
using EventsHandler.Properties;

namespace EventsHandler.Services.Serialization
{
/// <inheritdoc cref="ISerializationService"/>
internal sealed class SpecificSerializer : ISerializationService
{
/// <inheritdoc cref="ISerializationService.Deserialize{TModel}(object)"/>
/// <exception cref="JsonException">The value cannot be deserialized.</exception>
TModel ISerializationService.Deserialize<TModel>(object json)
{
return JsonSerializer.Deserialize<TModel>($"{json}");
try
{
return JsonSerializer.Deserialize<TModel>($"{json}");
}
catch
{
throw new JsonException(message:
$"{Resources.Deserialization_ERROR_CannotDeserialize_Message} | " +
$"{Resources.Deserialization_ERROR_CannotDeserialize_Target}: {typeof(TModel).Name} | " +
$"{Resources.Deserialization_ERROR_CannotDeserialize_Value}: {json}");
}
}

/// <inheritdoc cref="ISerializationService.Serialize{TModel}(TModel)"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"IsAsymmetric": false
},
"Features": {
"UseNewOpenKlant": true
"UseNewOpenKlant": false
},
"AllowedHosts": "*"
}
2 changes: 1 addition & 1 deletion EventsHandler/Api/EventsHandler/appsettings.Test.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"IsAsymmetric": false
},
"Features": {
"UseNewOpenKlant": true
"UseNewOpenKlant": false
},
"AllowedHosts": "*"
}

0 comments on commit adeca80

Please sign in to comment.