Skip to content

Commit

Permalink
Merge pull request #36 from Worth-NL/feature/Tasks
Browse files Browse the repository at this point in the history
Feature/tasks
  • Loading branch information
Thomas-M-Krystyan authored Jul 16, 2024
2 parents 03047c2 + 7d11ae0 commit 3453e99
Show file tree
Hide file tree
Showing 75 changed files with 2,153 additions and 507 deletions.
86 changes: 58 additions & 28 deletions Documentation/OMC - Documentation.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using EventsHandler.Controllers;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc.Filters;
using System.Diagnostics.CodeAnalysis;

namespace EventsHandler.Attributes.Authorization
{
Expand All @@ -12,6 +13,7 @@ namespace EventsHandler.Attributes.Authorization
/// <seealso cref="AuthorizeAttribute"/>
/// <seealso cref="IAuthorizationFilter"/>
[AttributeUsage(AttributeTargets.Method)]
[ExcludeFromCodeCoverage]
internal sealed class ApiAuthorization : AuthorizeAttribute, IAuthorizationFilter
{
public void OnAuthorization(AuthorizationFilterContext context)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using EventsHandler.Behaviors.Mapping.Models.POCOs.NotificatieApi;
using EventsHandler.Behaviors.Mapping.Models.POCOs.OpenKlant;
using EventsHandler.Configuration;
using EventsHandler.Services.DataQuerying.Adapter.Interfaces;
using EventsHandler.Services.DataQuerying.Interfaces;
using Resources = EventsHandler.Properties.Resources;

Expand All @@ -23,10 +24,13 @@ namespace EventsHandler.Behaviors.Communication.Strategy.Base
internal abstract class BaseScenario : INotifyScenario
{
/// <inheritdoc cref="WebApiConfiguration"/>
protected WebApiConfiguration Configuration { get; private set; }
protected WebApiConfiguration Configuration { get; }

/// <inheritdoc cref="IDataQueryService{TModel}"/>
protected IDataQueryService<NotificationEvent> DataQuery { get; }

/// <inheritdoc cref="IQueryContext"/>
protected IQueryContext? QueryContext { get; set; }

/// <inheritdoc cref="CommonPartyData"/>
protected CommonPartyData? CachedCommonPartyData { get; set; }
Expand All @@ -44,31 +48,29 @@ protected BaseScenario(WebApiConfiguration configuration, IDataQueryService<Noti
/// <inheritdoc cref="INotifyScenario.GetAllNotifyDataAsync(NotificationEvent)"/>
async Task<NotifyData[]> INotifyScenario.GetAllNotifyDataAsync(NotificationEvent notification)
=> await this.GetAllNotifyDataAsync(notification);

/// <inheritdoc cref="INotifyScenario.DropCache()"/>
void INotifyScenario.DropCache()
=> this.DropCache();
#endregion

#region Virtual (GetAllNotifyDataAsync)
/// <inheritdoc cref="INotifyScenario.GetAllNotifyDataAsync(NotificationEvent)"/>
internal virtual async Task<NotifyData[]> GetAllNotifyDataAsync(NotificationEvent notification)
{
if (this.CachedCommonPartyData == null) // NOTE: Needs to be set by a respective strategy
// Validation: This model needs to be set by a respective strategy
if (this.CachedCommonPartyData == null ||
this.CachedCommonPartyData.Value.IsDefault())
{
throw new InvalidOperationException(Resources.HttpRequest_ERROR_NoPartyData);
}

// Determine which types of notifications should be published
return this.CachedCommonPartyData.Value.DistributionChannel switch
NotifyData[] notifyData = this.CachedCommonPartyData.Value.DistributionChannel switch
{
DistributionChannels.Email => new[] { await GetEmailNotifyDataAsync(notification, this.CachedCommonPartyData.Value) },
DistributionChannels.Email => new[] { await GetEmailNotifyDataAsync(this.CachedCommonPartyData.Value) },

DistributionChannels.Sms => new[] { await GetSmsNotifyDataAsync(notification, this.CachedCommonPartyData.Value) },
DistributionChannels.Sms => new[] { await GetSmsNotifyDataAsync(this.CachedCommonPartyData.Value) },

// NOTE: Older version of "OpenKlant" was supporting option for many types of notifications
DistributionChannels.Both => new[] { await GetEmailNotifyDataAsync(notification, this.CachedCommonPartyData.Value),
await GetSmsNotifyDataAsync(notification, this.CachedCommonPartyData.Value) },
DistributionChannels.Both => new[] { await GetEmailNotifyDataAsync(this.CachedCommonPartyData.Value),
await GetSmsNotifyDataAsync(this.CachedCommonPartyData.Value) },

DistributionChannels.None => Array.Empty<NotifyData>(),

Expand All @@ -77,26 +79,29 @@ await GetSmsNotifyDataAsync(notification, this.CachedCommonPartyData.Value) },
=> throw new InvalidOperationException(Resources.Processing_ERROR_Notification_DeliveryMethodUnknown),
_ => throw new InvalidOperationException(Resources.Processing_ERROR_Notification_DeliveryMethodUnknown)
};

DropCache();

return notifyData;
}
#endregion

#region Virtual (Email logic)
/// <summary>
/// Gets the e-mail notify data to be used with "Notify NL" API Client.
/// </summary>
/// <param name="notification">The initial notification from "OpenNotificaties" Web API service.</param>
/// <param name="partyData">The data associated to a specific party (e.g., citizen, organization).</param>
/// <returns>
/// The e-mail data for "Notify NL" Web API service.
/// </returns>
protected virtual async Task<NotifyData> GetEmailNotifyDataAsync(NotificationEvent notification, CommonPartyData partyData)
protected virtual async Task<NotifyData> GetEmailNotifyDataAsync(CommonPartyData partyData)
{
return new NotifyData
(
notificationMethod: NotifyMethods.Email,
contactDetails: partyData.EmailAddress,
templateId: GetEmailTemplateId(),
personalization: await GetEmailPersonalizationAsync(notification, partyData)
personalization: await GetEmailPersonalizationAsync(partyData)
);
}
#endregion
Expand All @@ -105,32 +110,36 @@ protected virtual async Task<NotifyData> GetEmailNotifyDataAsync(NotificationEve
/// <summary>
/// Gets the SMS notify data to be used with "Notify NL" API Client.
/// </summary>
/// <param name="notification">The initial notification from "OpenNotificaties" Web API service.</param>
/// <param name="partyData">The data associated to a specific party (e.g., citizen, organization).</param>
/// <returns>
/// The SMS data for "Notify NL" Web API service.
/// </returns>
protected virtual async Task<NotifyData> GetSmsNotifyDataAsync(NotificationEvent notification, CommonPartyData partyData)
protected virtual async Task<NotifyData> GetSmsNotifyDataAsync(CommonPartyData partyData)
{
return new NotifyData
(
notificationMethod: NotifyMethods.Sms,
contactDetails: partyData.TelephoneNumber,
templateId: GetSmsTemplateId(),
personalization: await GetSmsPersonalizationAsync(notification, partyData)
personalization: await GetSmsPersonalizationAsync(partyData)
);
}
#endregion

#region Virtual (DropCache)
/// <summary>
/// <inheritdoc cref="INotifyScenario.DropCache()"/>
/// Drops (clears) the scenario internal cache.
/// <para>
/// Clears:
/// </para>
/// <list type="bullet">
/// <item><see cref="QueryContext"/></item>
/// <item><see cref="CachedCommonPartyData"/></item>
/// </list>
/// </summary>
protected virtual void DropCache()
{
this.QueryContext = null;
this.CachedCommonPartyData = null;
}
#endregion
Expand All @@ -147,13 +156,11 @@ protected virtual void DropCache()
/// <summary>
/// Gets the e-mail "personalization" for this strategy.
/// </summary>
/// <param name="notification">The initial notification from "OpenNotificaties" Web API service.</param>
/// <param name="partyData">The data associated to a specific party (e.g., citizen, organization).</param>
/// <returns>
/// The dictionary of &lt;placeholder, value&gt; used for personalization of "Notify NL" Web API service notification.
/// </returns>
protected abstract Task<Dictionary<string, object>> GetEmailPersonalizationAsync(
NotificationEvent notification, CommonPartyData partyData);
protected abstract Task<Dictionary<string, object>> GetEmailPersonalizationAsync(CommonPartyData partyData);
#endregion

#region Abstract (SMS logic)
Expand All @@ -168,13 +175,11 @@ protected abstract Task<Dictionary<string, object>> GetEmailPersonalizationAsync
/// <summary>
/// Gets the SMS "personalization" for this strategy.
/// </summary>
/// <param name="notification">The initial notification from "OpenNotificaties" Web API service.</param>
/// <param name="partyData">The data associated to a specific party (e.g., citizen, organization).</param>
/// <returns>
/// The dictionary of &lt;placeholder, value&gt; used for personalization of "Notify NL" Web API service notification.
/// </returns>
protected abstract Task<Dictionary<string, object>> GetSmsPersonalizationAsync(
NotificationEvent notification, CommonPartyData partyData);
protected abstract Task<Dictionary<string, object>> GetSmsPersonalizationAsync(CommonPartyData partyData);
#endregion
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,7 @@ protected BaseCaseScenario(WebApiConfiguration configuration, IDataQueryService<
{
}

#region Polymorphic (GetAllNotifyDataAsync)
/// <inheritdoc cref="BaseScenario.GetAllNotifyDataAsync(NotificationEvent)"/>
internal sealed override async Task<NotifyData[]> GetAllNotifyDataAsync(NotificationEvent notification)
{
this.CachedCommonPartyData ??= await this.DataQuery.From(notification).GetPartyDataAsync();

return await base.GetAllNotifyDataAsync(notification);
}
#endregion

#region PassAlreadyQueriedResult()
#region Parent
/// <summary>
/// Passes the already queried result.
/// </summary>
Expand All @@ -50,6 +40,17 @@ internal void PassAlreadyQueriedResult(CaseStatusType caseStatusType)
}
#endregion

#region Polymorphic (GetAllNotifyDataAsync)
/// <inheritdoc cref="BaseScenario.GetAllNotifyDataAsync(NotificationEvent)"/>
internal sealed override async Task<NotifyData[]> GetAllNotifyDataAsync(NotificationEvent notification)
{
this.QueryContext ??= this.DataQuery.From(notification);
this.CachedCommonPartyData ??= await this.QueryContext.GetPartyDataAsync();

return await base.GetAllNotifyDataAsync(notification);
}
#endregion

#region Polymorphic (DropCache)
/// <summary>
/// <inheritdoc cref="BaseScenario.DropCache()"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using EventsHandler.Behaviors.Mapping.Models.POCOs.OpenKlant;
using EventsHandler.Behaviors.Mapping.Models.POCOs.OpenZaak;
using EventsHandler.Configuration;
using EventsHandler.Services.DataQuerying.Adapter.Interfaces;
using EventsHandler.Services.DataQuerying.Interfaces;

namespace EventsHandler.Behaviors.Communication.Strategy.Implementations.Cases
Expand Down Expand Up @@ -36,21 +35,19 @@ public CaseCaseFinishedScenario(WebApiConfiguration configuration, IDataQuerySer
protected override string GetEmailTemplateId()
=> this.Configuration.User.TemplateIds.Email.ZaakClose();

/// <inheritdoc cref="BaseScenario.GetEmailPersonalizationAsync(NotificationEvent, CommonPartyData)"/>
protected override async Task<Dictionary<string, object>> GetEmailPersonalizationAsync(
NotificationEvent notification, CommonPartyData partyData)
/// <inheritdoc cref="BaseScenario.GetEmailPersonalizationAsync(CommonPartyData)"/>
protected override async Task<Dictionary<string, object>> GetEmailPersonalizationAsync(CommonPartyData partyData)
{
IQueryContext queryContext = this.DataQuery.From(notification);
this.CachedCase ??= await queryContext.GetCaseAsync();
this.CachedCaseStatuses ??= await queryContext.GetCaseStatusesAsync();
this.CachedLastCaseStatusType ??= await queryContext.GetLastCaseStatusTypeAsync(this.CachedCaseStatuses);
this.CachedCase ??= await this.QueryContext!.GetCaseAsync();
this.CachedCaseStatuses ??= await this.QueryContext!.GetCaseStatusesAsync();
this.CachedLastCaseStatusType ??= await this.QueryContext!.GetLastCaseStatusTypeAsync(this.CachedCaseStatuses);

return new Dictionary<string, object>
{
{ "zaak.omschrijving", this.CachedCase.Value.Name },
{ "zaak.identificatie", this.CachedCase.Value.Identification },
{ "klant.voorvoegselAchternaam", partyData.SurnamePrefix },
{ "klant.voornaam", partyData.Name },
{ "klant.voorvoegselAchternaam", partyData.SurnamePrefix },
{ "klant.achternaam", partyData.Surname },
{ "status.omschrijving", this.CachedLastCaseStatusType.Value.Description }
};
Expand All @@ -62,24 +59,10 @@ protected override async Task<Dictionary<string, object>> GetEmailPersonalizatio
protected override string GetSmsTemplateId()
=> this.Configuration.User.TemplateIds.Sms.ZaakClose();

/// <inheritdoc cref="BaseScenario.GetSmsPersonalizationAsync(NotificationEvent, CommonPartyData)"/>
protected override async Task<Dictionary<string, object>> GetSmsPersonalizationAsync(
NotificationEvent notification, CommonPartyData partyData)
/// <inheritdoc cref="BaseScenario.GetSmsPersonalizationAsync(CommonPartyData)"/>
protected override async Task<Dictionary<string, object>> GetSmsPersonalizationAsync(CommonPartyData partyData)
{
IQueryContext queryContext = this.DataQuery.From(notification);
this.CachedCase ??= await queryContext.GetCaseAsync();
this.CachedCaseStatuses ??= await queryContext.GetCaseStatusesAsync();
this.CachedLastCaseStatusType ??= await queryContext.GetLastCaseStatusTypeAsync(this.CachedCaseStatuses);

return new Dictionary<string, object>
{
{ "zaak.omschrijving", this.CachedCase.Value.Name },
{ "zaak.identificatie", this.CachedCase.Value.Identification },
{ "klant.voornaam", partyData.Name },
{ "klant.voorvoegselAchternaam", partyData.SurnamePrefix },
{ "klant.achternaam", partyData.Surname },
{ "status.omschrijving", this.CachedLastCaseStatusType.Value.Description }
};
return await GetEmailPersonalizationAsync(partyData); // NOTE: Both implementations are identical
}
#endregion

Expand All @@ -95,7 +78,6 @@ protected override void DropCache()
base.DropCache();

this.CachedCaseStatuses = null;
this.CachedLastCaseStatusType = null;
}
#endregion
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using EventsHandler.Behaviors.Mapping.Models.POCOs.OpenKlant;
using EventsHandler.Behaviors.Mapping.Models.POCOs.OpenZaak;
using EventsHandler.Configuration;
using EventsHandler.Services.DataQuerying.Adapter.Interfaces;
using EventsHandler.Services.DataQuerying.Interfaces;

namespace EventsHandler.Behaviors.Communication.Strategy.Implementations.Cases
Expand Down Expand Up @@ -36,21 +35,19 @@ public CaseCaseStatusUpdatedScenario(WebApiConfiguration configuration, IDataQue
protected override string GetEmailTemplateId()
=> this.Configuration.User.TemplateIds.Email.ZaakUpdate();

/// <inheritdoc cref="BaseScenario.GetEmailPersonalizationAsync(NotificationEvent, CommonPartyData)"/>
protected override async Task<Dictionary<string, object>> GetEmailPersonalizationAsync(
NotificationEvent notification, CommonPartyData partyData)
/// <inheritdoc cref="BaseScenario.GetEmailPersonalizationAsync(CommonPartyData)"/>
protected override async Task<Dictionary<string, object>> GetEmailPersonalizationAsync(CommonPartyData partyData)
{
IQueryContext queryContext = this.DataQuery.From(notification);
this.CachedCase ??= await queryContext.GetCaseAsync();
this.CachedCaseStatuses ??= await queryContext.GetCaseStatusesAsync();
this.CachedLastCaseStatusType ??= await queryContext.GetLastCaseStatusTypeAsync(this.CachedCaseStatuses);
this.CachedCase ??= await this.QueryContext!.GetCaseAsync();
this.CachedCaseStatuses ??= await this.QueryContext!.GetCaseStatusesAsync();
this.CachedLastCaseStatusType ??= await this.QueryContext!.GetLastCaseStatusTypeAsync(this.CachedCaseStatuses);

return new Dictionary<string, object>
{
{ "zaak.omschrijving", this.CachedCase.Value.Name },
{ "zaak.identificatie", this.CachedCase.Value.Identification },
{ "klant.voorvoegselAchternaam", partyData.SurnamePrefix },
{ "klant.voornaam", partyData.Name },
{ "klant.voorvoegselAchternaam", partyData.SurnamePrefix },
{ "klant.achternaam", partyData.Surname },
{ "status.omschrijving", this.CachedLastCaseStatusType.Value.Description }
};
Expand All @@ -62,24 +59,10 @@ protected override async Task<Dictionary<string, object>> GetEmailPersonalizatio
protected override string GetSmsTemplateId()
=> this.Configuration.User.TemplateIds.Sms.ZaakUpdate();

/// <inheritdoc cref="BaseScenario.GetSmsPersonalizationAsync(NotificationEvent, CommonPartyData)"/>
protected override async Task<Dictionary<string, object>> GetSmsPersonalizationAsync(
NotificationEvent notification, CommonPartyData partyData)
/// <inheritdoc cref="BaseScenario.GetSmsPersonalizationAsync(CommonPartyData)"/>
protected override async Task<Dictionary<string, object>> GetSmsPersonalizationAsync(CommonPartyData partyData)
{
IQueryContext queryContext = this.DataQuery.From(notification);
this.CachedCase ??= await queryContext.GetCaseAsync();
this.CachedCaseStatuses ??= await queryContext.GetCaseStatusesAsync();
this.CachedLastCaseStatusType ??= await queryContext.GetLastCaseStatusTypeAsync(this.CachedCaseStatuses);

return new Dictionary<string, object>
{
{ "zaak.omschrijving", this.CachedCase.Value.Name },
{ "zaak.identificatie", this.CachedCase.Value.Identification },
{ "klant.voornaam", partyData.Name },
{ "klant.voorvoegselAchternaam", partyData.SurnamePrefix },
{ "klant.achternaam", partyData.Surname },
{ "status.omschrijving", this.CachedLastCaseStatusType.Value.Description }
};
return await GetEmailPersonalizationAsync(partyData); // NOTE: Both implementations are identical
}
#endregion

Expand All @@ -95,7 +78,6 @@ protected override void DropCache()
base.DropCache();

this.CachedCaseStatuses = null;
this.CachedLastCaseStatusType = null;
}
#endregion
}
Expand Down
Loading

0 comments on commit 3453e99

Please sign in to comment.