Skip to content

Commit

Permalink
Merge pull request #2224 from bcgov/1.10.8
Browse files Browse the repository at this point in the history
1.10.8
  • Loading branch information
bcgov-brwang authored May 18, 2023
2 parents 4a2acef + f649fbf commit c591e69
Show file tree
Hide file tree
Showing 41 changed files with 1,795 additions and 479 deletions.
11 changes: 11 additions & 0 deletions .pipeline/lib/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,17 @@ module.exports = (settings) => {
)
);

objects.push(
...oc.processDeploymentTemplate(
`${templatesLocalBaseUrl}/configmaps/api-appsettings.yaml`,
{
param: {
ENV: phases[phase].phase,
},
}
)
);

objects.push(
...oc.processDeploymentTemplate(
`${templatesLocalBaseUrl}/api-deploy-config.yaml`,
Expand Down
5 changes: 4 additions & 1 deletion Server/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -279,4 +279,7 @@ __pycache__/
*.sonarqube

*.DotSettings
*.DotSettings.user
*.DotSettings.user

# Override .s2i/bin
!.s2i/bin
9 changes: 9 additions & 0 deletions Server/.s2i/bin/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash
set -e

echo "---> Overwriting appsettings.json ..."
cp /opt/app-root/configmap/appsettings.json /opt/app-root/app/appsettings.json

# Execute the default S2I script
echo "---> Executing default s2i run script ..."
source ${STI_SCRIPTS_PATH}/run
27 changes: 24 additions & 3 deletions Server/HetsApi/Controllers/DistrictEquipmentTypeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
using HetsData.Hangfire;
using AutoMapper;
using HetsData.Dtos;
using Microsoft.Extensions.Logging;
using System;

namespace HetsApi.Controllers
{
Expand All @@ -26,12 +28,14 @@ public class DistrictEquipmentTypeController : ControllerBase
private readonly DbAppContext _context;
private readonly IConfiguration _configuration;
private readonly IMapper _mapper;
private readonly ILogger<DistrictEquipmentTypeController> _logger;

public DistrictEquipmentTypeController(DbAppContext context, IConfiguration configuration, IMapper mapper)
public DistrictEquipmentTypeController(DbAppContext context, IConfiguration configuration, IMapper mapper, ILogger<DistrictEquipmentTypeController> logger)
{
_context = context;
_configuration = configuration;
_mapper = mapper;
_logger = logger;
}

/// <summary>
Expand Down Expand Up @@ -271,7 +275,12 @@ public virtual ActionResult<DistrictEquipmentTypeDto> DistrictEquipmentTypesIdPo

foreach (HetLocalArea localArea in localAreas)
{
EquipmentHelper.RecalculateSeniority(localArea.LocalAreaId, equipment.DistrictEquipmentTypeId, _context, seniorityScoringRules);
EquipmentHelper.RecalculateSeniority(
localArea.LocalAreaId, equipment.DistrictEquipmentTypeId, _context, seniorityScoringRules,
(errMessage, ex) => {
_logger.LogError(errMessage);
_logger.LogError(ex.ToString());
});
}
}
}
Expand Down Expand Up @@ -316,8 +325,20 @@ public virtual IActionResult MergeDistrictEquipmentTypesPost()
IConfigurationSection scoringRules = _configuration.GetSection("SeniorityScoringRules");
string seniorityScoringRules = GetConfigJson(scoringRules);

Action<string> logInfoAction = (msg) => {
_logger.LogInformation(msg);
};

Action<string, Exception> logErrorAction = (errMessage, ex) => {
_logger.LogError(errMessage);
_logger.LogError(ex.ToString());
};

// queue the job
BackgroundJob.Enqueue<DistrictEquipmentTypesMerger>(x => x.MergeDistrictEquipmentTypes(seniorityScoringRules));
BackgroundJob.Enqueue<DistrictEquipmentTypesMerger>(x => x.MergeDistrictEquipmentTypes(
seniorityScoringRules,
logInfoAction,
logErrorAction));

// return ok
return new ObjectResult(new HetsResponse("Merge job added to hangfire"));
Expand Down
57 changes: 48 additions & 9 deletions Server/HetsApi/Controllers/EquipmentController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -311,12 +311,24 @@ public virtual ActionResult<EquipmentDto> EquipmentIdPut([FromRoute]int id, [Fro
if (rebuildSeniority)
{
// update new area
EquipmentHelper.RecalculateSeniority(item.LocalAreaId, item.DistrictEquipmentTypeId, _context, _configuration, equipment);
EquipmentHelper.RecalculateSeniority(
item.LocalAreaId, item.DistrictEquipmentTypeId, _context, _configuration,
(errMessage, ex) => {
_logger.LogError(errMessage);
_logger.LogError(ex.ToString());
},
equipment);

// update old area
if (rebuildOldSeniority)
{
EquipmentHelper.RecalculateSeniority((int)originalLocalAreaId, (int)originalDistrictEquipmentTypeId, _context, _configuration, equipment);
EquipmentHelper.RecalculateSeniority(
(int)originalLocalAreaId, (int)originalDistrictEquipmentTypeId, _context, _configuration,
(errMessage, ex) => {
_logger.LogError(errMessage);
_logger.LogError(ex.ToString());
},
equipment);
}
}

Expand Down Expand Up @@ -454,7 +466,13 @@ public virtual ActionResult<EquipmentDto> EquipmentIdStatusPut([FromRoute]int id
// recalculation seniority (if required)
if (recalculateSeniority)
{
EquipmentHelper.RecalculateSeniority(localAreaId, districtEquipmentTypeId, _context, _configuration, equipment);
EquipmentHelper.RecalculateSeniority(
localAreaId, districtEquipmentTypeId, _context, _configuration,
(errMessage, ex) => {
_logger.LogError(errMessage);
_logger.LogError(ex.ToString());
},
equipment);
}

// save the changes
Expand Down Expand Up @@ -528,7 +546,10 @@ public virtual ActionResult<EquipmentDto> EquipmentPost([FromBody]EquipmentDto i
// recalculation seniority (if required)
int? localAreaId = equipment.LocalAreaId;
int? districtEquipmentTypeId = equipment.DistrictEquipmentTypeId;
EquipmentHelper.RecalculateSeniority(localAreaId, districtEquipmentTypeId, _context, _configuration);
EquipmentHelper.RecalculateSeniority(localAreaId, districtEquipmentTypeId, _context, _configuration, (errMessage, ex) => {
_logger.LogError(errMessage);
_logger.LogError(ex.ToString());
});

// save the result of the seniority recalculation
_context.SaveChanges();
Expand All @@ -551,8 +572,17 @@ public virtual IActionResult RecalculateSeniorityListPost()
IConfigurationSection scoringRules = _configuration.GetSection("SeniorityScoringRules");
string seniorityScoringRules = GetConfigJson(scoringRules);

Action<string> logInfoAction = (msg) => {
_logger.LogInformation(msg);
};

Action<string, Exception> logErrorAction = (errMessage, ex) => {
_logger.LogError(errMessage);
_logger.LogError(ex.ToString());
};

// queue the job
BackgroundJob.Enqueue<SeniorityCalculator>(x => x.RecalculateSeniorityList(seniorityScoringRules));
BackgroundJob.Enqueue<SeniorityCalculator>(x => x.RecalculateSeniorityList(seniorityScoringRules, logInfoAction, logErrorAction));

// return ok
return new ObjectResult(new HetsResponse("Recalculate job added to hangfire"));
Expand Down Expand Up @@ -729,7 +759,10 @@ public virtual ActionResult<EquipmentLiteDto> EquipmentSearchGet([FromQuery]stri
}

// convert Equipment Model to the "EquipmentLite" Model
SeniorityScoringRules scoringRules = new SeniorityScoringRules(_configuration);
SeniorityScoringRules scoringRules = new SeniorityScoringRules(_configuration, (errMessage, ex) => {
_logger.LogError(errMessage);
_logger.LogError(ex.ToString());
});
List<EquipmentLiteDto> result = new List<EquipmentLiteDto>();

var dataList = data.ToList();
Expand Down Expand Up @@ -1382,7 +1415,10 @@ public virtual IActionResult EquipmentSeniorityListDocGet([FromQuery]string loca
// convert Equipment Model to Pdf View Model
// **********************************************************************
SeniorityListReportViewModel seniorityList = new SeniorityListReportViewModel();
SeniorityScoringRules scoringRules = new SeniorityScoringRules(_configuration);
SeniorityScoringRules scoringRules = new SeniorityScoringRules(_configuration, (errMessage, ex) => {
_logger.LogError(errMessage);
_logger.LogError(ex.ToString());
});
SeniorityListRecord listRecord = new SeniorityListRecord();

// manage the rotation list data
Expand Down Expand Up @@ -1467,7 +1503,10 @@ public virtual IActionResult EquipmentSeniorityListDocGet([FromQuery]string loca

// convert to open xml document
string documentName = $"SeniorityList-{DateTime.Now:yyyy-MM-dd}{(counterCopy ? "-(CounterCopy)" : "")}.docx";
byte[] document = SeniorityList.GetSeniorityList(seniorityList, documentName, counterCopy);
byte[] document = SeniorityList.GetSeniorityList(seniorityList, documentName, counterCopy, (errMessage, ex) => {
_logger.LogError(errMessage);
_logger.LogError(ex.ToString());
});

// return document
FileContentResult result = new FileContentResult(document, "application/vnd.openxmlformats-officedocument.wordprocessingml.document")
Expand Down Expand Up @@ -1505,7 +1544,7 @@ private int GetLastCalledEquipmentId(int localAreaId, int districtEquipmentTypeI
}
catch (Exception e)
{
Console.WriteLine(e);
_logger.LogError($"GetLastCalledEquipmentId exception: {e.ToString()}");
throw;
}
}
Expand Down
49 changes: 39 additions & 10 deletions Server/HetsApi/Controllers/OwnerController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,10 @@ public virtual ActionResult<OwnerDto> OwnersIdPut([FromRoute]int id, [FromBody]O
if (statusId == null) return new BadRequestObjectResult(new HetsResponse("HETS-23", ErrorViewModel.GetDescription("HETS-23", _configuration)));

// get processing rules
SeniorityScoringRules scoringRules = new SeniorityScoringRules(_configuration);
SeniorityScoringRules scoringRules = new SeniorityScoringRules(_configuration, (errMessage, ex) => {
_logger.LogError(errMessage);
_logger.LogError(ex.ToString());
});

// get active equipment
IQueryable<HetEquipment> equipmentListB = _context.HetEquipments
Expand All @@ -302,12 +305,22 @@ public virtual ActionResult<OwnerDto> OwnersIdPut([FromRoute]int id, [FromBody]O
: scoringRules.GetTotalBlocks();

// update block assignments
SeniorityListHelper.AssignBlocks(localAreaId, districtEquipmentTypeId, blockSize, totalBlocks, _context);
SeniorityListHelper.AssignBlocks(
localAreaId, districtEquipmentTypeId, blockSize, totalBlocks, _context,
(errMessage, ex) => {
_logger.LogError(errMessage);
_logger.LogError(ex.ToString());
});

// update old area block assignments
if (oldLocalArea != null)
{
SeniorityListHelper.AssignBlocks((int)oldLocalArea, districtEquipmentTypeId, blockSize, totalBlocks, _context);
SeniorityListHelper.AssignBlocks(
(int)oldLocalArea, districtEquipmentTypeId, blockSize, totalBlocks, _context,
(errMessage, ex) => {
_logger.LogError(errMessage);
_logger.LogError(ex.ToString());
});
}
}
}
Expand Down Expand Up @@ -412,7 +425,10 @@ public virtual ActionResult<OwnerDto> OwnersIdStatusPut([FromRoute]int id, [From
}

// recalculate the seniority
EquipmentHelper.RecalculateSeniority(localAreaId, districtEquipmentTypeId, _context, _configuration);
EquipmentHelper.RecalculateSeniority(localAreaId, districtEquipmentTypeId, _context, _configuration, (errMessage, ex) => {
_logger.LogError(errMessage);
_logger.LogError(ex.ToString());
});

// HETS-1119 - Add change of status comments to Notes
string equipmentStatusNote = $"(Status changed to: {equipment.Status}) {equipment.StatusComment}";
Expand Down Expand Up @@ -638,7 +654,10 @@ OwnerVerificationReportModel reportModel

// convert to open xml document
string documentName = $"OwnerVerification-{DateTime.Now:yyyy-MM-dd}.docx";
byte[] document = OwnerVerification.GetOwnerVerification(reportModel, documentName);
byte[] document = OwnerVerification.GetOwnerVerification(reportModel, documentName, (errMessage, ex) => {
_logger.LogError(errMessage);
_logger.LogError(ex.ToString());
});

// return document
FileContentResult result = new FileContentResult(document, "application/vnd.openxmlformats-officedocument.wordprocessingml.document")
Expand Down Expand Up @@ -775,7 +794,10 @@ public virtual IActionResult OwnersIdMailingLabelsPdfPost([FromBody]ReportParame
{
_logger.LogInformation("Owner Mailing Labels Pdf - HETS Pdf Service Response: OK");

var pdfResponseBytes = GetPdf(response);
var pdfResponseBytes = GetPdf(response, (errMessage, ex) => {
_logger.LogError(errMessage);
_logger.LogError(ex.ToString());
});

// convert to string and log
string pdfResponse = Encoding.Default.GetString(pdfResponseBytes);
Expand Down Expand Up @@ -812,7 +834,7 @@ public virtual IActionResult OwnersIdMailingLabelsPdfPost([FromBody]ReportParame
return new NotFoundObjectResult(new HetsResponse("HETS-01", ErrorViewModel.GetDescription("HETS-01", _configuration)));
}

private static byte[] GetPdf(HttpResponseMessage response)
private static byte[] GetPdf(HttpResponseMessage response, Action<string, Exception> logErrorAction)
{
try
{
Expand All @@ -823,7 +845,8 @@ private static byte[] GetPdf(HttpResponseMessage response)
}
catch (Exception e)
{
Console.WriteLine(e);

logErrorAction("GetPdf exception: ", e);
throw;
}
}
Expand Down Expand Up @@ -864,7 +887,10 @@ public virtual IActionResult OwnersIdMailingLabelsDocPost([FromBody]ReportParame
}

var fileName = $"MailingLabels-{DateTime.Now:yyyy-MM-dd-H-mm}.docx";
var file = MailingLabel.GetMailingLabel(owners);
var file = MailingLabel.GetMailingLabel(owners, (errMessage, ex) => {
_logger.LogError(errMessage);
_logger.LogError(ex.ToString());
});

FileContentResult result = new FileContentResult(file, "application/vnd.openxmlformats-officedocument.wordprocessingml.document")
{
Expand Down Expand Up @@ -1209,7 +1235,10 @@ public virtual ActionResult<List<EquipmentDto>> OwnersIdEquipmentTransferPost([F
districtEquipmentTypes.Add(districtEquipmentTypeId);

// recalculate seniority
EquipmentHelper.RecalculateSeniority(localAreaId, districtEquipmentTypeId, _context, _configuration);
EquipmentHelper.RecalculateSeniority(localAreaId, districtEquipmentTypeId, _context, _configuration, (errMessage, ex) => {
_logger.LogError(errMessage);
_logger.LogError(ex.ToString());
});
}
}

Expand Down
5 changes: 4 additions & 1 deletion Server/HetsApi/Controllers/RentalAgreementController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,10 @@ public virtual IActionResult RentalAgreementsIdDocGet([FromRoute] int id)

// convert to open xml document
string documentName = $"{fileName}.docx";
byte[] document = RentalAgreement.GetRentalAgreement(reportModel, documentName);
byte[] document = RentalAgreement.GetRentalAgreement(reportModel, documentName, (errMessage, ex) => {
_logger.LogError(errMessage);
_logger.LogError(ex.ToString());
});

// return document
FileContentResult result = new FileContentResult(document, "application/vnd.openxmlformats-officedocument.wordprocessingml.document")
Expand Down
Loading

0 comments on commit c591e69

Please sign in to comment.