Skip to content

Commit

Permalink
feat: add mtam functionality to digdir source (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
SondreJDigdir authored Jan 30, 2025
1 parent 87b6cb1 commit 473b78c
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 37 deletions.
6 changes: 5 additions & 1 deletion src/Dan.Plugin.Tilda/Config/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ public string GetClassBaseUri(string className)
return Environment.GetEnvironmentVariable(className + ".uri");
}

public string GetClassBaseCode(string className)
{
return Environment.GetEnvironmentVariable(className + ".code");
}

public string RedisConnectionString { get; set; }

public bool IsTest { get; set; }
Expand All @@ -24,7 +29,6 @@ public string GetClassBaseUri(string className)
public string KvKofuviCertificateName { get; set; }

public string DataAltinnNoBaseUrl { get; set; }
public string AltinnEventsBaseUrl { get; set; }

public static string CosmosDbConnection => Environment.GetEnvironmentVariable("CosmosDbConnection");
public string CosmosDbDatabase { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion src/Dan.Plugin.Tilda/Functions/Timers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class Timers(
[Function("MtamTimer")]
public async Task MessageToOtherAuditorsTimer(
// [HttpTrigger(AuthorizationLevel.Function, "get", "post")] HttpRequestData req, // easier to test locally using http trigger
[TimerTrigger("0 */5 * * * *")] TimerInfo timerInfo,
[TimerTrigger("%MtamTriggerCron%")] TimerInfo timerInfo,
FunctionContext context)
{
var mtamSources = tildaSourceProvider.GetAllSources<ITildaAlertMessage>().ToList();
Expand Down
13 changes: 10 additions & 3 deletions src/Dan.Plugin.Tilda/Models/TildaDataSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public virtual string GetUriAll(string baseUri, string dataset, string requestor

public virtual async Task<List<AlertSourceMessage>> GetAlertMessagesAsync(string from)
{
var targetUrl = $"{BaseUri}/{MtamDatasetName}?fromDate={from}";
var targetUrl = GetAlertUri(from);
string responseString;
try
{
Expand Down Expand Up @@ -184,7 +184,7 @@ public virtual async Task<List<AlertSourceMessage>> GetAlertMessagesAsync(string
public virtual async Task<AlertSourceMessage> GetAlertMessageAsync(EvidenceHarvesterRequest req,
string identifier)
{
var targetUrl = $"{BaseUri}/{MtamDatasetName}/{identifier}?requestor={req.Requestor}";
var targetUrl = GetSingleAlertUri(identifier, req.Requestor);
string responseString;
try
{
Expand Down Expand Up @@ -252,7 +252,7 @@ public virtual async Task<AlertSourceMessage> GetAlertMessageAsync(EvidenceHarve

public async Task SendAlertMessageAsync(CloudEvent cloudEvent)
{
var targetUrl = $"{BaseUri}/{MtamDatasetName}";
var targetUrl = PostAlertUri();
var resiliencePipeline = _pipelineProvider.GetPipeline("alert-pipeline");
CloudEventFormatter formatter = new JsonEventFormatter();
var cloudEventContent = cloudEvent.ToHttpContent(ContentMode.Structured, formatter);
Expand All @@ -266,5 +266,12 @@ await resiliencePipeline.ExecuteAsync(async token =>
}
});
}

protected virtual string GetAlertUri(string from) => $"{BaseUri}/{MtamDatasetName}?fromDate={from}";

protected virtual string GetSingleAlertUri(string id, string requestor) =>
$"{BaseUri}/{MtamDatasetName}/{id}?requestor={requestor}";

protected virtual string PostAlertUri() => $"{BaseUri}/{MtamDatasetName}";
}
}
16 changes: 10 additions & 6 deletions src/Dan.Plugin.Tilda/TildaSources/Digitaliseringsdirektoratet.cs
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using Dan.Common.Models;
using Dan.Plugin.Tilda.Config;
using Dan.Plugin.Tilda.Models;
using Dan.Plugin.Tilda.Utils;
using Dan.Plugin.Tilda.Interfaces;
using Dan.Plugin.Tilda.Models.AlertMessages;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Nadobe.Common.Models;
using Polly.Registry;

namespace Dan.Plugin.Tilda.TildaSources
{


public class Digitaliseringsdirektoratet : TildaDataSource, ITildaPdfReport//, ITildaAuditReports, ITildaNPDIDAuditReports, ITildaAuditCoordination, ITildaTrendReports, ITildaTrendReportsAll, ITildaAuditCoordinationAll, ITildaAuditReportsAll, ITildaAlertMessage
public class Digitaliseringsdirektoratet : TildaDataSource, ITildaAlertMessage, ITildaPdfReport//, ITildaAuditReports, ITildaNPDIDAuditReports, ITildaAuditCoordination, ITildaTrendReports, ITildaTrendReportsAll, ITildaAuditCoordinationAll, ITildaAuditReportsAll, ITildaAlertMessage
{

private const string orgNo = "991825827";
Expand All @@ -30,13 +26,15 @@ public class Digitaliseringsdirektoratet : TildaDataSource, ITildaPdfReport//, I

public override bool TestOnly => true;

private readonly string _code;

public Digitaliseringsdirektoratet(IOptions<Settings> settings,
IHttpClientFactory httpClientFactory,
ILoggerFactory loggerFactory,
ResiliencePipelineProvider<string> pipelineProvider) :
base(settings, httpClientFactory, loggerFactory, pipelineProvider)
{

_code = _settings.GetClassBaseCode(GetType().Name);
}

public Digitaliseringsdirektoratet() : base()
Expand Down Expand Up @@ -206,6 +204,12 @@ public override async Task<NPDIDAuditReportList> GetNPDIDAuditReportsAsync(Evide

return resultList;
}

protected override string GetAlertUri(string from) => $"{BaseUri}/{MtamDatasetName}?fromDate={from}&code={_code}";
protected override string GetSingleAlertUri(string id, string requestor) =>
$"{BaseUri}/{MtamDatasetName}/{id}?requestor={requestor}&code={_code}";

protected override string PostAlertUri() => $"{BaseUri}/{MtamDatasetName}?code={_code}";
}

}
26 changes: 0 additions & 26 deletions src/Dan.Plugin.Tilda/TildaSources/LocalTestSource.cs

This file was deleted.

0 comments on commit 473b78c

Please sign in to comment.