Skip to content

Commit

Permalink
Branch created for supplementary notification (#188)
Browse files Browse the repository at this point in the history
  • Loading branch information
Anjana1010 authored Jul 19, 2024
1 parent 98c9a72 commit 9ae3daf
Show file tree
Hide file tree
Showing 9 changed files with 534 additions and 24 deletions.
3 changes: 3 additions & 0 deletions OFM.Infrastructure.WebAPI/Extensions/SetupInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ public static class Emails
public const Int16 CreateApplicationNotificationsId = 230;
public const string CreateApplicationNotificationsName = "Create Email for Application Ineligilble";

public const Int16 AllowanceApprovalDenialNotificationId= 240;
public const string AllowanceApprovalDenialNotificationName = "Create email and pdf for supplementary";


}

Expand Down
28 changes: 28 additions & 0 deletions OFM.Infrastructure.WebAPI/Models/Fundings/Fundings.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using ECC.Core.DataContext;
using System.Text.Json.Serialization;

namespace OFM.Infrastructure.WebAPI.Models.Fundings;

Expand Down Expand Up @@ -148,6 +149,33 @@ public class SupplementaryApplication : ofm_allowance
public new decimal? ofm_retroactive_amount { get; set; }
public new SupplementarySchedule? ofm_supplementary_schedule { get; set; }
public string _ofm_application_value { get; set; }

public Guid ofm_allowanceid { get; set; }
public string ofm_allowance_number { get; set; }
public DateTime createdon { get; set; }
public int statuscode { get; set; }
public int ofm_renewal_term { get; set; }
[property: JsonPropertyName("con.ofm_first_name")]

public string ofm_first_name { get; set; }

[property: JsonPropertyName("con.ofm_last_name")]

public string ofm_last_name { get; set; }

[property: JsonPropertyName("app.ofm_contact")]
public Guid _ofm_contact_value { get; set; }

[property: JsonPropertyName("app.ofm_summary_submittedby")]
public Guid _ofm_summary_submittedby_value { get; set; }

[property: JsonPropertyName("app.statuscode")]
public int appstatuscode { get; set; }
[property: JsonPropertyName("app.ofm_funding_number_base")]
public string ofm_funding_number_base { get; set; }
[property: JsonPropertyName("funding.statuscode")]
public int fundingStatusCode { get; set; }

}

public class BusinessClosure
Expand Down
5 changes: 4 additions & 1 deletion OFM.Infrastructure.WebAPI/Models/SettingsModels.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@ public record CommunicationTypes
public class EmailTemplate
{
public int TemplateNumber { get; set; }



public string Description { get; set; }

}

public record ProcessSettings
Expand Down
3 changes: 2 additions & 1 deletion OFM.Infrastructure.WebAPI/OFM.Infrastructure.WebAPI.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
Expand Down Expand Up @@ -58,6 +58,7 @@
<PackageReference Include="Microsoft.Extensions.Http.Polly" Version="8.0.2" />
<PackageReference Include="Microsoft.Identity.Client" Version="4.59.0" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.6" />
<PackageReference Include="Select.HtmlToPdf.NetCore" Version="24.1.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
</ItemGroup>

Expand Down
2 changes: 1 addition & 1 deletion OFM.Infrastructure.WebAPI/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
services.AddScoped<ID365ProcessProvider, P610CreateQuestionProvider>();
services.AddScoped<ID365ProcessProvider, P615CreateMonthlyReportProvider>();
services.AddScoped<ID365ProcessProvider, P700ProviderCertificateProvider>();

services.AddScoped<ID365ProcessProvider, P240AllowanceApprovalDenialNotificationProvider>();
services.AddScoped<D365Email>();
services.AddScoped<ID365BackgroundProcessHandler, D365BackgroundProcessHandler>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ public async Task<HttpResponseMessage> SendDocumentRequestAsync(AZAppUser spn, s
{
request = new(new D365EntityReference(entityNameSet, id), columnName: "ofm_input_document_memo", data, fileName);
}
else if (entityNameSet.Equals("ofm_allowances"))
{
request = new(new D365EntityReference(entityNameSet, id), columnName: "ofm_approval_pdf", data, fileName);
}
else
{
request = new(new D365EntityReference(entityNameSet, id), columnName: "ofm_file", data, fileName);
Expand Down
331 changes: 311 additions & 20 deletions OFM.Infrastructure.WebAPI/Services/Processes/Emails/IEmailRepository.cs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
using Microsoft.Extensions.Options;
using OFM.Infrastructure.WebAPI.Extensions;
using OFM.Infrastructure.WebAPI.Models;
using OFM.Infrastructure.WebAPI.Models.Fundings;
using OFM.Infrastructure.WebAPI.Services.AppUsers;
using OFM.Infrastructure.WebAPI.Services.D365WebApi;
using OFM.Infrastructure.WebAPI.Services.Processes.Fundings;
using System.Net;
using System.Text.Json;
using System.Text.Json.Nodes;

namespace OFM.Infrastructure.WebAPI.Services.Processes.Emails;

public class P240AllowanceApprovalDenialNotificationProvider : ID365ProcessProvider
{
const string EntityNameSet = "emails";
private readonly NotificationSettings _notificationSettings;
private readonly ID365AppUserService _appUserService;
private readonly ID365WebApiService _d365webapiservice;
private readonly IFundingRepository _fundingRepository;
private readonly IEmailRepository _emailRepository;
private readonly ILogger _logger;
private readonly TimeProvider _timeProvider;
private ProcessData? _data;
private string[] _communicationTypesForEmailSentToUserMailBox = [];
private ProcessParameter? _processParams;
private string _requestUri = string.Empty;
private string? _fundingAgreementCommunicationType;
private string? _informationCommunicationType;
private Guid? _allowanceId;
private bool emailCreated = false;

public P240AllowanceApprovalDenialNotificationProvider(IOptionsSnapshot<NotificationSettings> notificationSettings, ID365AppUserService appUserService, ID365WebApiService d365WebApiService, ILoggerFactory loggerFactory, TimeProvider timeProvider, IFundingRepository fundingRepository, IEmailRepository emailRepository)
{
_notificationSettings = notificationSettings.Value;
_appUserService = appUserService;
_d365webapiservice = d365WebApiService;
_fundingRepository = fundingRepository;
_emailRepository = emailRepository;
_logger = loggerFactory.CreateLogger(LogCategory.Process);
_timeProvider = timeProvider;
}

public Int16 ProcessId => Setup.Process.Emails.AllowanceApprovalDenialNotificationId;
public string ProcessName => Setup.Process.Emails.AllowanceApprovalDenialNotificationName;

#region fetchxml queries
public string RequestUri
{
get
{
var fetchXml = $"""
<fetch>
<entity name="ofm_allowance">
<attribute name="ofm_allowance_number" />
<attribute name="ofm_allowance_type" />
<attribute name="ofm_allowanceid" />
<attribute name="ofm_monthly_amount" />
<attribute name="statuscode" />
<attribute name="ofm_start_date" />
<attribute name="ofm_transport_vehicle_vin" />
<attribute name="ofm_retroactive_date" />
<attribute name="ofm_retroactive_amount" />
<filter>
<condition attribute="ofm_allowanceid" operator="eq" value="{_allowanceId}" />
</filter>
<link-entity name="ofm_application" from="ofm_applicationid" to="ofm_application" alias= "app">
<attribute name="ofm_contact" />
<attribute name="statuscode" />
<attribute name="ofm_summary_submittedby" />
<attribute name="ofm_funding_number_base" />
<link-entity name="contact" from="contactid" to="ofm_contact" alias= "con">
<attribute name="ofm_last_name" />
<attribute name="ofm_first_name" />
</link-entity>
</link-entity>
</entity>
</fetch>
""";

var requestUri = $"""
ofm_allowances?fetchXml={WebUtility.UrlEncode(fetchXml)}
""";

return requestUri;
}
}
#endregion

public async Task<ProcessData> GetDataAsync()
{
_logger.LogDebug(CustomLogEvent.Process, "GetContactDataAsync");

var response = await _d365webapiservice.SendRetrieveRequestAsync(_appUserService.AZSystemAppUser, RequestUri);

if (!response.IsSuccessStatusCode)
{
var responseBody = await response.Content.ReadAsStringAsync();
_logger.LogError(CustomLogEvent.Process, "Failed to query Contact records with the server error {responseBody}", responseBody.CleanLog());

return await Task.FromResult(new ProcessData(string.Empty));
}

var jsonObject = await response.Content.ReadFromJsonAsync<JsonObject>();

JsonNode d365Result = string.Empty;
if (jsonObject?.TryGetPropertyValue("value", out var currentValue) == true)
{
if (currentValue?.AsArray().Count == 0)
{
_logger.LogInformation(CustomLogEvent.Process, "No Contact records found with query {requestUri}", RequestUri.CleanLog());
}
d365Result = currentValue!;
}

_logger.LogDebug(CustomLogEvent.Process, "Query Result {queryResult}", d365Result.ToString().CleanLog());

return await Task.FromResult(new ProcessData(d365Result));
}

public async Task<JsonObject> RunProcessAsync(ID365AppUserService appUserService, ID365WebApiService d365WebApiService, ProcessParameter processParams)
{
_processParams = processParams;
_allowanceId = _processParams.SupplementaryApplication.allowanceId;

IEnumerable<D365CommunicationType> _communicationType = await _emailRepository!.LoadCommunicationTypeAsync();
_informationCommunicationType = _communicationType.Where(c => c.ofm_communication_type_number == _notificationSettings.CommunicationTypes.Information)
.Select(s => s.ofm_communication_typeid).FirstOrDefault();
var localData = await GetDataAsync();
var deserializedData = JsonSerializer.Deserialize<List<SupplementaryApplication>>(localData.Data.ToString());
if (deserializedData == null || deserializedData.Count == 0)
{
_logger.LogInformation("No records returned from FetchXml", deserializedData.Count);
return ProcessResult.Completed(ProcessId).SimpleProcessResult;
}
try
{
await _emailRepository.CreateAllowanceEmail(deserializedData.First(), _processParams.Notification.SenderId, _informationCommunicationType, ProcessId, d365WebApiService);
}
catch (Exception ex)
{
_logger.LogError(CustomLogEvent.Process, "Failed to generate email notification for supplementary {responseBody}", ex.InnerException.Message);

}
return ProcessResult.Completed(ProcessId).SimpleProcessResult;


}


}
30 changes: 29 additions & 1 deletion tools/config/update-configmap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,35 @@ D365_CONFIGURATION=$(jq << JSON
{
"TemplateNumber": 250,
"Description": "Application Ineligible"
}
},
{
"TemplateNumber": 240,
"Description": "SupportNeedsProgramAllowanceApproved"
},
{
"TemplateNumber": 255,
"Description": "IndigenousAllowanceApproved"
},
{
"TemplateNumber": 260,
"Description": "TransportationAllowanceApprovedwithRetroActive"
},
{
"TemplateNumber": 290,
"Description": "TransportationAllowanceApprovedwithoutRetroActive"
},
{
"TemplateNumber": 275,
"Description": "SupportNeedsProgramAllowanceDenied"
},
{
"TemplateNumber": 280,
"Description": "IndigenousAllowanceDenied"
},
{
"TemplateNumber": 285,
"Description": "TransportationAllowanceDenied"
}
],
"CommunicationTypes": {
"Information": 1,
Expand Down

0 comments on commit 9ae3daf

Please sign in to comment.