Skip to content

Commit

Permalink
Merge pull request #4141 from bcgov/test
Browse files Browse the repository at this point in the history
v5.3 release
  • Loading branch information
devinleighsmith authored Jun 27, 2024
2 parents 120fe48 + 9660455 commit 51f2bfc
Show file tree
Hide file tree
Showing 1,049 changed files with 186,734 additions and 18,869 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/api-dotnetcore.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ jobs:
- name: Codecov
uses: codecov/[email protected]
env:
env:
CODECOV_TOKEN: ${{ secrets.CODECOV }}
with:
# User defined upload name. Visible in Codecov UI
Expand All @@ -122,7 +122,7 @@ jobs:

- name: SonarScanner for .NET 8 with pull request decoration support
id: scan
uses: highbyte/sonarscan-dotnet@v2.1.2
uses: highbyte/sonarscan-dotnet@v2.3.2
if: ${{ github.event_name == 'push' }}
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
Expand Down
File renamed without changes.
47 changes: 47 additions & 0 deletions source/backend/api/Areas/Documents/DocumentController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Pims.Api.Models.Requests.Http;
using Pims.Api.Policies;
using Pims.Api.Services;
using Pims.Core.Exceptions;
using Pims.Core.Json;
using Pims.Dal.Security;
using Swashbuckle.AspNetCore.Annotations;
Expand Down Expand Up @@ -233,6 +234,52 @@ public async Task<IActionResult> GetDocumentMetadata(long mayanDocumentId)
return new JsonResult(result);
}

/// <summary>
/// Downloads the list of pages for the file within the desired document.
/// </summary>
[HttpGet("storage/{mayanDocumentId}/file/{documentFileId}/pages")]
[HasPermission(Permissions.DocumentView)]
[ProducesResponseType(typeof(ExternalResponse<QueryResponse<FilePageModel>>), 200)]
[SwaggerOperation(Tags = new[] { "storage-documents" })]
[TypeFilter(typeof(NullJsonResultFilter))]
public async Task<IActionResult> GetDocumentFilePageList(long mayanDocumentId, long documentFileId)
{
var result = await _documentService.GetDocumentFilePageListAsync(mayanDocumentId, documentFileId);
if(result.HttpStatusCode != System.Net.HttpStatusCode.OK)
{
throw new HttpClientRequestException(result.Message, result.HttpStatusCode);
}

return new JsonResult(result.Payload.Results);
}

/// <summary>
/// Downloads the desired page for the file within the target document.
/// </summary>
[HttpGet("storage/{mayanDocumentId}/file/{documentFileId}/pages/{documentFilePageId}")]
[HasPermission(Permissions.DocumentView)]
[ProducesResponseType(typeof(FileStreamResult), 200)]
[SwaggerOperation(Tags = new[] { "storage-documents" })]
[TypeFilter(typeof(NullJsonResultFilter))]
public async Task<FileStreamResult> DownloadFilePageImage(long mayanDocumentId, long documentFileId, long documentFilePageId)
{
var response = await _documentService.DownloadFilePageImageAsync(mayanDocumentId, documentFileId, documentFilePageId);

if (response.StatusCode == System.Net.HttpStatusCode.NotFound)
{
throw new KeyNotFoundException();
}
else if (!response.IsSuccessStatusCode)
{
throw new HttpClientRequestException(response);
}

return new FileStreamResult(response.Content.ReadAsStream(), "application/octet-stream")
{
FileDownloadName = $"Page {documentFilePageId}",
};
}

#endregion
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
using System;
using System.Collections.Generic;
using MapsterMapper;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Pims.Api.Models.Concepts.Property;
using Pims.Api.Policies;
using Pims.Api.Services;
using Pims.Core.Extensions;
using Pims.Core.Json;
using Pims.Dal.Security;
using Swashbuckle.AspNetCore.Annotations;

namespace Pims.Api.Areas.HistoricalNumber.Controllers
{
/// <summary>
/// HistoricalNumberController class, provides endpoints for interacting with property historical numbers.
/// </summary>
[Authorize]
[ApiController]
[ApiVersion("1.0")]
[Area("properties")]
[Route("v{version:apiVersion}/[area]")]
[Route("[area]")]
public class HistoricalNumberController : ControllerBase
{
#region Variables
private readonly IPropertyService _propertyService;
private readonly IMapper _mapper;
private readonly ILogger _logger;
#endregion

#region Constructors

/// <summary>
/// Creates a new instance of a HistoricalNumberController class, initializes it with the specified arguments.
/// </summary>
/// <param name="propertyService"></param>
/// <param name="mapper"></param>
///
public HistoricalNumberController(IPropertyService propertyService, IMapper mapper, ILogger<HistoricalNumberController> logger)
{
_propertyService = propertyService;
_mapper = mapper;
_logger = logger;
}

/// <summary>
/// Gets a list of the historic numbers for a given property id.
/// </summary>
[HttpGet("{propertyId}/historicalNumbers")]
[HasPermission(Permissions.PropertyView)]
[Produces("application/json")]
[ProducesResponseType(typeof(IEnumerable<HistoricalFileNumberModel>), 200)]
[SwaggerOperation(Tags = new[] { "property" })]
[TypeFilter(typeof(NullJsonResultFilter))]
public IActionResult GetHistoricalNumbersForPropertyId(long propertyId)
{
_logger.LogInformation(
"Request received by Controller: {Controller}, Action: {ControllerAction}, User: {User}, DateTime: {DateTime}",
nameof(HistoricalNumberController),
nameof(GetHistoricalNumbersForPropertyId),
User.GetUsername(),
DateTime.Now);

var historicalNumbers = _propertyService.GetHistoricalNumbersForPropertyId(propertyId);
return new JsonResult(_mapper.Map<List<HistoricalFileNumberModel>>(historicalNumbers));
}

/// <summary>
/// Updates the list of historic numbers for a given property id.
/// </summary>
[HttpPut("{propertyId}/historicalNumbers")]
[HasPermission(Permissions.PropertyEdit)]
[Produces("application/json")]
[ProducesResponseType(typeof(IEnumerable<HistoricalFileNumberModel>), 200)]
[SwaggerOperation(Tags = new[] { "property" })]
[TypeFilter(typeof(NullJsonResultFilter))]
public IActionResult UpdateHistoricalNumbers(long propertyId, IEnumerable<HistoricalFileNumberModel> historicalNumbers)
{
_logger.LogInformation(
"Request received by Controller: {Controller}, Action: {ControllerAction}, User: {User}, DateTime: {DateTime}",
nameof(HistoricalNumberController),
nameof(UpdateHistoricalNumbers),
User.GetUsername(),
DateTime.Now);

var historicalEntities = _mapper.Map<IEnumerable<Dal.Entities.PimsHistoricalFileNumber>>(historicalNumbers);
var updatedEntities = _propertyService.UpdateHistoricalFileNumbers(propertyId, historicalEntities);

return new JsonResult(_mapper.Map<IEnumerable<HistoricalFileNumberModel>>(updatedEntities));
}
#endregion
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public IActionResult UpdateInsurance(int leaseId, IEnumerable<InsuranceModel> in
/// </summary>
/// <returns></returns>
[HttpGet]
[HasPermission(Permissions.LeaseEdit)]
[HasPermission(Permissions.LeaseView)]
[Produces("application/json")]
[ProducesResponseType(typeof(IEnumerable<InsuranceModel>), 200)]
[SwaggerOperation(Tags = new[] { "insurance" })]
Expand Down
50 changes: 50 additions & 0 deletions source/backend/api/Areas/Leases/Controllers/LeaseController.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using MapsterMapper;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Pims.Api.Helpers.Exceptions;
using Pims.Api.Models.Concepts.AcquisitionFile;
using Pims.Api.Models.Concepts.File;
using Pims.Api.Models.Concepts.Lease;
using Pims.Api.Policies;
using Pims.Api.Services;
Expand Down Expand Up @@ -142,6 +146,52 @@ public IActionResult UpdateLease(LeaseModel leaseModel, [FromQuery] string[] use

return new JsonResult(_mapper.Map<LeaseModel>(updatedLease));
}

/// <summary>
/// Get the lease checklist items.
/// </summary>
/// <returns>The checklist items.</returns>
[HttpGet("{id:long}/checklist")]
[HasPermission(Permissions.LeaseView)]
[Produces("application/json")]
[ProducesResponseType(typeof(IEnumerable<FileChecklistItemModel>), 200)]
[SwaggerOperation(Tags = new[] { "lease" })]
[TypeFilter(typeof(NullJsonResultFilter))]
public IActionResult GetLeaseChecklistItems([FromRoute] long id)
{
var checklist = _leaseService.GetChecklistItems(id);

return new JsonResult(_mapper.Map<IEnumerable<FileChecklistItemModel>>(checklist));
}

/// <summary>
/// Update the lease checklist.
/// </summary>
/// <returns>Updated lease.</returns>
[HttpPut("{id:long}/checklist")]
[HasPermission(Permissions.LeaseEdit)]
[Produces("application/json")]
[ProducesResponseType(typeof(LeaseModel), 200)]
[SwaggerOperation(Tags = new[] { "lease" })]
[TypeFilter(typeof(NullJsonResultFilter))]
public IActionResult UpdateLeaseChecklist([FromRoute]long id, [FromBody] IList<FileChecklistItemModel> checklistItems)
{
if(checklistItems.Any(x => x.FileId != id))
{
throw new BadRequestException("All checklist items file id must match the Lease's id");
}

if (checklistItems.Count == 0)
{
throw new BadRequestException("Checklist items must be greater than zero");
}

var checklistItemEntities = _mapper.Map<IList<Dal.Entities.PimsLeaseChecklistItem>>(checklistItems);
var updatedLease = _leaseService.UpdateChecklistItems(id, checklistItemEntities);

return new JsonResult(_mapper.Map<LeaseModel>(updatedLease));
}

#endregion
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public IActionResult GetLeases()
User.GetUsername(),
DateTime.Now);

var uri = new Uri(this.Request.GetDisplayUrl());
var uri = new Uri(Request.GetDisplayUrl());
var query = Microsoft.AspNetCore.WebUtilities.QueryHelpers.ParseQuery(uri.Query);
return GetLeases(new LeaseFilterModel(query));
}
Expand Down
32 changes: 20 additions & 12 deletions source/backend/api/Areas/Property/Models/PropertyFilterModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ public class PropertyFilterModel : PageFilter
/// </summary>
public string PlanNumber { get; set; }

/// <summary>
/// get/set - Search by historical LIS or PS file numbers.
/// </summary>
public string Historical { get; set; }

/// <summary>
/// get/set - The property ownership status.
/// </summary>
Expand All @@ -54,11 +59,11 @@ public PropertyFilterModel(Dictionary<string, Microsoft.Extensions.Primitives.St
// We want case-insensitive query parameter properties.
var filter = new Dictionary<string, Microsoft.Extensions.Primitives.StringValues>(query, StringComparer.OrdinalIgnoreCase);

this.Sort = filter.GetStringArrayValue(nameof(this.Sort));
var tempSort = this.Sort.ToList();
Sort = filter.GetStringArrayValue(nameof(Sort));
var tempSort = Sort.ToList();

// Convert sort to db format
for (int i = 0; i < this.Sort.Length; i++)
for (int i = 0; i < Sort.Length; i++)
{
if (tempSort[i].StartsWith("Location"))
{
Expand All @@ -72,20 +77,21 @@ public PropertyFilterModel(Dictionary<string, Microsoft.Extensions.Primitives.St
{
// The order will affect the display in the frontend. For now in alphabetical order.
// i.e. [Core Inventory, Disposed, Other Interest, Property of Interest]
var direction = this.Sort[i].Split(' ')[1];
tempSort[i] = this.Sort[i].Replace("Ownership", "IsOwned");
var direction = Sort[i].Split(' ')[1];
tempSort[i] = Sort[i].Replace("Ownership", "IsOwned");
tempSort.Add($"IsDisposed {direction}");
tempSort.Add($"IsOtherInterest {direction}");
tempSort.Add($"HasActiveAcquisitionFile {direction}");
tempSort.Add($"HasActiveResearchFile {direction}");
}
}
this.Sort = tempSort.ToArray();
Sort = tempSort.ToArray();

this.PinOrPid = filter.GetStringValue(nameof(this.PinOrPid));
this.Address = filter.GetStringValue(nameof(this.Address));
this.PlanNumber = filter.GetStringValue(nameof(this.PlanNumber));
this.Ownership = filter.GetStringArrayValue(nameof(this.Ownership));
PinOrPid = filter.GetStringValue(nameof(PinOrPid));
Address = filter.GetStringValue(nameof(Address));
PlanNumber = filter.GetStringValue(nameof(PlanNumber));
Historical = filter.GetStringValue(nameof(Historical));
Ownership = filter.GetStringArrayValue(nameof(Ownership));
}
#endregion

Expand All @@ -106,6 +112,7 @@ public static explicit operator PropertyFilter(PropertyFilterModel model)
PinOrPid = model.PinOrPid,
Address = model.Address,
PlanNumber = model.PlanNumber,
Historical = model.Historical,
Ownership = model.Ownership,
};

Expand All @@ -119,8 +126,9 @@ public static explicit operator PropertyFilter(PropertyFilterModel model)
public override bool IsValid()
{
return base.IsValid()
|| !string.IsNullOrWhiteSpace(this.PinOrPid)
|| !string.IsNullOrWhiteSpace(this.Address);
|| !string.IsNullOrWhiteSpace(PinOrPid)
|| !string.IsNullOrWhiteSpace(Historical)
|| !string.IsNullOrWhiteSpace(Address);
}
#endregion
}
Expand Down
6 changes: 6 additions & 0 deletions source/backend/api/Controllers/LookupController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ public IActionResult GetAll()
var dispositionChecklistItemStatusTypes = _mapper.Map<Model.LookupModel[]>(_lookupRepository.GetAllDispositionChecklistItemStatusTypes());
var dispositionChecklistItemTypes = _mapper.Map<Model.LookupModel[]>(_lookupRepository.GetAllDispositionChecklistItemTypes());
var dispositionChecklistSectionTypes = _mapper.Map<Model.LookupModel[]>(_lookupRepository.GetAllDispositionChecklistSectionTypes());
var historicalNumberTypes = _mapper.Map<Model.LookupModel[]>(_lookupRepository.GetAllHistoricalNumberTypes());
var leaseChecklistStatusTypes = _mapper.Map<Model.LookupModel[]>(_lookupRepository.GetAllLeaseChecklistItemStatusTypes());
var leaseChecklistSectionTypes = _mapper.Map<Model.LookupModel[]>(_lookupRepository.GetAllLeaseChecklistSectionTypes());

var codes = new List<object>();
codes.AddRange(areaUnitTypes);
Expand Down Expand Up @@ -220,6 +223,9 @@ public IActionResult GetAll()
codes.AddRange(dispositionChecklistItemStatusTypes);
codes.AddRange(dispositionChecklistItemTypes);
codes.AddRange(dispositionChecklistSectionTypes);
codes.AddRange(historicalNumberTypes);
codes.AddRange(leaseChecklistStatusTypes);
codes.AddRange(leaseChecklistSectionTypes);

var response = new JsonResult(codes);

Expand Down
36 changes: 36 additions & 0 deletions source/backend/api/Helpers/Healthchecks/PimsCdogsHealthCheck.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Diagnostics.HealthChecks;
using Pims.Api.Repositories.Cdogs;

namespace Pims.Api.Helpers.Healthchecks
{
public class PimsCdogsHealthcheck : IHealthCheck
{
private readonly IDocumentGenerationRepository _generationRepository;

public PimsCdogsHealthcheck(IDocumentGenerationRepository generationRepository)
{
_generationRepository = generationRepository;
}

public async Task<HealthCheckResult> CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToken = default)
{
try
{

var fileTypes = await _generationRepository.TryGetFileTypesAsync();
if (fileTypes.HttpStatusCode != System.Net.HttpStatusCode.OK || fileTypes.Payload == null || fileTypes.Payload.Dictionary.Count == 0)
{
return new HealthCheckResult(HealthStatus.Degraded, $"received invalid file types response from CDOGS");
}
}
catch (Exception e)
{
return new HealthCheckResult(context.Registration.FailureStatus, $"Cdogs error response: {e.Message} {e.StackTrace}");
}
return HealthCheckResult.Healthy();
}
}
}
Loading

0 comments on commit 51f2bfc

Please sign in to comment.