Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion source/backend/api/Areas/Documents/SearchController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using Pims.Core.Extensions;
using Pims.Core.Json;
using Pims.Core.Security;
using Pims.Dal.Entities;
using Swashbuckle.AspNetCore.Annotations;

namespace Pims.Api.Areas.Documents
Expand All @@ -29,12 +30,14 @@ namespace Pims.Api.Areas.Documents
public class SearchController : ControllerBase
{
private readonly IDocumentService _documentService;
private readonly IPropertyService _propertyService;
private readonly IMapper _mapper;
private readonly ILogger _logger;

public SearchController(IDocumentService documentService, IMapper mapper, ILogger<SearchController> logger)
public SearchController(IDocumentService documentService, IPropertyService propertyService, IMapper mapper, ILogger<SearchController> logger)
{
_documentService = documentService;
_propertyService = propertyService;
_mapper = mapper;
_logger = logger;
}
Expand Down Expand Up @@ -70,7 +73,36 @@ public IActionResult GetDocuments([FromQuery] DocumentSearchFilterModel filter)
_logger.LogInformation("Dispatching to service: {Service}", _documentService.GetType());
var documents = _documentService.GetPage(filter);

// Transform all properties to lat/long for returned documents that have properties, this is required for the front end to properly display the property locations.
foreach (var document in documents.Items)
{
var propertyDocuments = document.PimsPropertyDocuments ?? new List<PimsPropertyDocument>();
document.PimsPropertyDocuments = TransformAllPropertiesToLatLong(propertyDocuments);
}

return new JsonResult(_mapper.Map<PageModel<DocumentSearchResultModel>>(documents));
}

/// <summary>
/// Returns the spatial location and boundary polygons in lat/long (4326) for a list of document properties.
/// The spatial values will be modified in-place.
/// </summary>
/// <param name="propertyDocuments">The document properties to re-project.</param>
/// <returns>The document properties with transformed spatial locations.</returns>
private ICollection<PimsPropertyDocument> TransformAllPropertiesToLatLong(ICollection<PimsPropertyDocument> propertyDocuments)
{
if (propertyDocuments == null)
{
return propertyDocuments;
}

foreach (var propertyDocument in propertyDocuments)
{
propertyDocument.Property = _propertyService.TransformPropertyToLatLong(propertyDocument.Property);
}

return propertyDocuments;
}

}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
Expand All @@ -13,6 +14,7 @@
using Pims.Core.Api.Policies;
using Pims.Core.Extensions;
using Pims.Core.Security;
using Pims.Dal.Entities;
using Pims.Dal.Entities.Models;
using Swashbuckle.AspNetCore.Annotations;

Expand All @@ -30,11 +32,13 @@ namespace Pims.Api.Areas.Reports.Controllers
public class ManagementActivityController : ControllerBase
{
private readonly IManagementActivityService _managementActivityService;
private readonly IPropertyService _propertyService;
private readonly ILogger _logger;

public ManagementActivityController(IManagementActivityService managementActivityService, ILogger<ManagementActivityController> logger)
public ManagementActivityController(IManagementActivityService managementActivityService, IPropertyService propertyService, ILogger<ManagementActivityController> logger)
{
_managementActivityService = managementActivityService;
_propertyService = propertyService;
_logger = logger;
}

Expand Down Expand Up @@ -78,6 +82,13 @@ public IActionResult ExportManagementActivitiesOverview([FromBody] ManagementAct
return NoContent();
}

// Transform all properties to lat/long for returned activities that have properties, this is required for the front end to properly display the property locations.
foreach (var activity in allManagementActivities)
{
var activityProperties = activity.PimsManagementActivityProperties ?? new List<PimsManagementActivityProperty>();
activity.PimsManagementActivityProperties = TransformAllPropertiesToLatLong(activityProperties);
}

var reportActivities = allManagementActivities.Select(a => new ManagementActivityOverviewReportModel(a));

return ReportHelper.GenerateExcel(reportActivities, "Management Activities Overview");
Expand Down Expand Up @@ -123,9 +134,38 @@ public IActionResult ExportManagementActivityInvoices([FromBody] ManagementActiv
return NoContent();
}

// Transform all properties to lat/long for returned invoices that have properties, this is required for the front end to properly display the property locations.
foreach (var invoice in allInvoices)
{
var activityProperties = invoice.ManagementActivity.PimsManagementActivityProperties ?? new List<PimsManagementActivityProperty>();
invoice.ManagementActivity.PimsManagementActivityProperties = TransformAllPropertiesToLatLong(activityProperties);
}

var reportInvoices = allInvoices.Select(i => new ManagementActivityInvoicesReportModel(i));

return ReportHelper.GenerateExcel(reportInvoices, "Management Activity Invoices");
}

/// <summary>
/// Returns the spatial location and boundary polygons in lat/long (4326) for a list of activity properties.
/// The spatial values will be modified in-place.
/// </summary>
/// <param name="activityProperties">The activity properties to re-project.</param>
/// <returns>The activity properties with transformed spatial locations.</returns>
private ICollection<PimsManagementActivityProperty> TransformAllPropertiesToLatLong(ICollection<PimsManagementActivityProperty> activityProperties)
{
if (activityProperties == null)
{
return activityProperties;
}

foreach (var activityProperty in activityProperties)
{
activityProperty.Property = _propertyService.TransformPropertyToLatLong(activityProperty.Property);
}

return activityProperties;
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Pims.Api.Helpers.Extensions;
using Pims.Api.Helpers.Reporting;
using Pims.Api.Models.Base;
using Pims.Api.Services;
using Pims.Core.Api.Exceptions;
using Pims.Core.Api.Policies;
using Pims.Core.Security;
Expand All @@ -29,6 +30,8 @@ public class PropertyController : ControllerBase
{
#region Variables
private readonly IPropertyRepository _propertyRepository;
private readonly IPropertyService _propertyService;

private readonly IMapper _mapper;
#endregion

Expand All @@ -38,10 +41,12 @@ public class PropertyController : ControllerBase
/// Creates a new instance of a ReportController class, initializes it with the specified arguments.
/// </summary>
/// <param name="propertyRepository"></param>
/// <param name="propertyService"></param>
/// <param name="mapper"></param>
public PropertyController(IPropertyRepository propertyRepository, IMapper mapper)
public PropertyController(IPropertyRepository propertyRepository, IPropertyService propertyService, IMapper mapper)
{
_propertyRepository = propertyRepository;
_propertyService = propertyService;
_mapper = mapper;
}
#endregion
Expand Down Expand Up @@ -98,6 +103,13 @@ public IActionResult ExportProperties([FromBody] Property.Models.Search.Property

filter.Quantity = all ? _propertyRepository.Count() : filter.Quantity;
var page = _propertyRepository.GetPage((PropertyFilter)filter);

// Transform all properties to lat/long for returned invoices that have properties, this is required for the front end to properly display the property locations.
foreach (var propertyVw in page.Items)
{
_propertyService.TransformPropertyVwToLatLong(propertyVw);
}

var report = _mapper.Map<PageModel<Models.Property.PropertyModel>>(page);

return acceptHeader.ToString() switch
Expand Down
4 changes: 2 additions & 2 deletions source/backend/api/Areas/Reports/Mapping/Lease/LeaseMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ private static void MapLease((Entity.PimsLeasePeriod period, Entity.PimsLease le
dest.AgreementCommencementDate = src.lease.OrigStartDate?.FilterSqlMinDate().ToNullableDateOnly();
dest.AgreementExpiryDate = src.lease.OrigExpiryDate?.FilterSqlMinDate().ToNullableDateOnly();
dest.LeaseAmount = src.period?.PaymentAmount;
dest.Pid = src.property?.Property?.Pid;
dest.Pin = src.property?.Property?.Pin;
dest.Pid = src.property?.Property?.PidFormatted ?? string.Empty;
dest.Pin = src.property?.Property?.Pin.ToString() ?? string.Empty;
dest.TenantName = src.stakeholder?.GetStakeholderName();
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Mapster;
using Pims.Core.Helpers;
using Entity = Pims.Dal.Entities;
using Model = Pims.Api.Areas.Reports.Models.Property;

Expand All @@ -16,7 +17,7 @@ public void Register(TypeAdapterConfig config)
.Map(dest => dest.Latitude, src => src.Location.Coordinate.Y)
.Map(dest => dest.Longitude, src => src.Location.Coordinate.X)

.Map(dest => dest.PID, src => src.ParcelIdentity)
.Map(dest => dest.PID, src => src.PidFormatted)
.Map(dest => dest.PIN, src => src.Pin)
.Map(dest => dest.LandArea, src => src.LandArea)
.Map(dest => dest.LandLegalDescription, src => src.LandLegalDescription);
Expand All @@ -29,7 +30,7 @@ public void Register(TypeAdapterConfig config)
.Map(dest => dest.Latitude, src => src.Location.Coordinate.Y)
.Map(dest => dest.Longitude, src => src.Location.Coordinate.X)

.Map(dest => dest.PID, src => src.PidPadded)
.Map(dest => dest.PID, src => src.PidPadded != null ? PidTranslator.ConvertPIDToDash(src.PidPadded) : string.Empty)
.Map(dest => dest.PIN, src => src.Pin)
.Map(dest => dest.LandArea, src => src.LandArea)
.Map(dest => dest.LandLegalDescription, src => src.LandLegalDescription);
Expand Down
4 changes: 2 additions & 2 deletions source/backend/api/Areas/Reports/Models/Lease/LeaseModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ public class LeaseModel

[DisplayName("PID")]
[CsvHelper.Configuration.Attributes.Name("PID")]
public int? Pid { get; set; }
public string Pid { get; set; }

[DisplayName("PIN")]
[CsvHelper.Configuration.Attributes.Name("PIN")]
public int? Pin { get; set; }
public string Pin { get; set; }

[DisplayName("Lease Amount")]
[CsvHelper.Configuration.Attributes.Name("Lease Amount")]
Expand Down
47 changes: 11 additions & 36 deletions source/backend/api/Models/Report/LeasePaymentReportModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System.ComponentModel;
using System.Linq;
using Pims.Api.Services;
using Pims.Core.Helpers;
using Pims.Dal.Entities;
using Pims.Dal.Helpers.Extensions;

Expand Down Expand Up @@ -190,8 +189,8 @@ public static LeasePaymentReportModel MapFrom(PimsLeasePayment src)
dest.LFileNumber = src.LeasePeriod.Lease?.LFileNo ?? string.Empty;
dest.HistoricalFiles = GetHistoricalFileNumbers(src.LeasePeriod.Lease);
dest.LeaseStatus = src.LeasePeriod.Lease?.LeaseStatusTypeCodeNavigation?.Description ?? string.Empty;
dest.PropertyList = string.Join(",", leaseProperties.Select(lp => GetFallbackPropertyIdentifier(lp)));
dest.TenantList = string.Join(",", leaseTenants.Select(t => GetStakeholderName(t)));
dest.PropertyList = GetPropertiesAsString(leaseProperties);
dest.TenantList = string.Join("|", leaseTenants.Select(t => GetStakeholderName(t)));
dest.PayableOrReceivable = src.LeasePeriod.Lease.LeasePayRvblTypeCodeNavigation?.Description ?? string.Empty;
dest.Program = GetLeaseProgramName(src.LeasePeriod.Lease);
dest.PeriodStart = src.LeasePeriod.PeriodStartDate.ToString("MMMM dd, yyyy");
Expand Down Expand Up @@ -219,6 +218,15 @@ private static string GetLastPaymentDate(PimsLease lease)
return lastPayment != null ? lastPayment.PaymentReceivedDate.ToString("MMMM dd, yyyy") : string.Empty;
}

private static string GetPropertiesAsString(ICollection<PimsPropertyLease> leaseProperties)
{
return string.Join("|", leaseProperties
.Where(lp => lp?.Property != null)
.Select(lp => lp.Property.GetPropertyName())
.Where(s => !string.IsNullOrWhiteSpace(s))
.Distinct());
}

private static string GetStakeholderName(PimsLeaseStakeholder stakeholder)
{
if (stakeholder is null)
Expand Down Expand Up @@ -258,39 +266,6 @@ private static string GetLeaseProgramName(PimsLease lease)
}
}

private static string GetFallbackPropertyIdentifier(PimsPropertyLease propertyLease)
{
PimsProperty property = propertyLease?.Property;
if (property?.Pid != null)
{
return PidTranslator.ConvertPIDToDash(property.Pid.ToString());
}

if (property?.Pin != null)
{
return property.Pin.ToString();
}

if (property?.Address != null && !string.IsNullOrEmpty(property.Address.StreetAddress1))
{
string[] addressStrings = new string[2] { property.Address.StreetAddress1, property.Address.MunicipalityName };
return $"({string.Join(" ", addressStrings.Where(s => s != null))})";
}

if (!string.IsNullOrEmpty(propertyLease?.Name))
{
return $"({propertyLease.Name})";
}

if (property?.Location != null)
{
return $"({property.Location.Coordinate.X}, {property.Location.Coordinate.Y})";
}

// Fallback if no identifier is available.
return "No Property Identifier";
}

private static string GetHistoricalFileNumbers(PimsLease lease)
{
var properties = lease.PimsPropertyLeases.Select(pl => pl.Property).Where(p => p != null);
Expand Down
2 changes: 1 addition & 1 deletion source/backend/api/Services/AcquisitionFileService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public List<AcquisitionFileExportModel> GetAcquisitionFileExport(AcquisitionFilt
MinistryProject = fileProperty.file.Project is not null ? $"{fileProperty.file.Project.Code} {fileProperty.file.Project.Description}" : string.Empty,
CivicAddress = (fileProperty.fp?.Property is not null && fileProperty.fp.Property.Address is not null) ? fileProperty.fp.Property.Address.FormatFullAddressString() : string.Empty,
GeneralLocation = (fileProperty.fp?.Property is not null) ? fileProperty.fp.Property.GeneralLocation : string.Empty,
Pid = fileProperty.fp is not null && fileProperty.fp.Property.Pid.HasValue ? fileProperty.fp.Property.Pid.ToString() : string.Empty,
Pid = fileProperty.fp is not null && fileProperty.fp.Property.PidFormatted != null ? fileProperty.fp.Property.PidFormatted : string.Empty,
Pin = fileProperty.fp is not null && fileProperty.fp.Property.Pin.HasValue ? fileProperty.fp.Property.Pin.ToString() : string.Empty,
AcquisitionFileStatusTypeCode = fileProperty.file.AcquisitionFileStatusTypeCodeNavigation is not null ? fileProperty.file.AcquisitionFileStatusTypeCodeNavigation.Description : string.Empty,
FileFunding = fileProperty.file.AcquisitionFundingTypeCodeNavigation is not null ? fileProperty.file.AcquisitionFundingTypeCodeNavigation.Description : string.Empty,
Expand Down
2 changes: 1 addition & 1 deletion source/backend/api/Services/DispositionFileService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ public List<DispositionFileExportModel> GetDispositionFileExport(DispositionFilt
MotiRegion = file.RegionCodeNavigation?.Description ?? string.Empty,
TeamMembers = string.Join("|", file.PimsDispositionFileTeams.Select(x => (x.PersonId.HasValue ? x.Person.GetFullName(true) + $" ({x.DspFlTeamProfileTypeCodeNavigation?.Description})" : x.Organization.Name + $" (Role: {x.DspFlTeamProfileTypeCodeNavigation?.Description}, Primary: {x.PrimaryContact?.GetFullName(true) ?? "N/A"})")) ?? Array.Empty<string>()),
CivicAddress = string.Join("|", file.PimsDispositionFileProperties.Select(x => x.Property?.Address?.FormatFullAddressString()).Where(x => x != null)),
Pid = string.Join("|", file.PimsDispositionFileProperties.Select(x => x.Property?.Pid).Where(x => x != null)),
Pid = string.Join("|", file.PimsDispositionFileProperties.Select(x => x.Property?.PidFormatted).Where(x => x != null)),
Pin = string.Join("|", file.PimsDispositionFileProperties.Select(x => x.Property?.Pin).Where(x => x != null)),
GeneralLocation = string.Join("|", file.PimsDispositionFileProperties.Select(x => x.Property?.GeneralLocation).Where(x => x != null)),
DispositionStatusTypeCode = file.DispositionStatusTypeCodeNavigation?.Description ?? string.Empty,
Expand Down
3 changes: 1 addition & 2 deletions source/backend/api/Services/DocumentService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,7 @@ public DocumentService(
IAvService avService,
IMapper mapper,
IOptionsMonitor<AuthClientOptions> options,
IOptionsMonitor<MayanConfig> mayanOptions,
IDocumentQueueRepository queueRepository)
IOptionsMonitor<MayanConfig> mayanOptions)
: base(user, logger)
{
this.documentRepository = documentRepository;
Expand Down
8 changes: 8 additions & 0 deletions source/backend/api/Services/IPropertyService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,14 @@ void UpdateFilePropertyBoundary<T>(T incomingFileProperty, T filePropertyToUpdat
/// <returns>The property with transformed spatial locations.</returns>
PimsProperty TransformPropertyToLatLong(PimsProperty property);

/// <summary>
/// Returns the spatial location and boundary polygons in lat/long (4326) for a given PimsPropertyVw instance.
/// The spatial values will be modified in-place.
/// </summary>
/// <param name="propertyVw">The property to re-project.</param>
/// <returns>The property with transformed spatial locations.</returns>
PimsPropertyVw TransformPropertyVwToLatLong(PimsPropertyVw propertyVw);

/// <summary>
/// Returns the spatial location and boundary polygons in lat/long (4326) for a list of file properties.
/// The spatial values will be modified in-place.
Expand Down
10 changes: 9 additions & 1 deletion source/backend/api/Services/LeaseService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,14 @@ public IEnumerable<PimsLease> GetAllByIds(IEnumerable<long> leaseIds)
long? contractorPersonId = pimsUser.IsContractor ? pimsUser.PersonId : null;

var leases = _leaseRepository.GetAllByIds(leaseIds, pimsUser.PimsRegionUsers.Select(u => u.RegionCode).ToHashSet(), contractorPersonId).ToList();

// Ensure we return property information with lat/long coordinates for any properties associated to the returned leases.
foreach (var lease in leases)
{
var propertyLeases = lease.PimsPropertyLeases ?? new List<PimsPropertyLease>();
lease.PimsPropertyLeases = _propertyService.TransformAllPropertiesToLatLong(propertyLeases.ToList());
}

return leases;
}

Expand Down Expand Up @@ -540,7 +548,7 @@ private static void ValidateRenewalDates(PimsLease lease, PimsLease currentLease

if (renewal.IsExercised == true)
{
if(!renewal.CommencementDt.HasValue)
if (!renewal.CommencementDt.HasValue)
{
throw new BusinessRuleViolationException("Exercised renewals must have a commencement date");
}
Expand Down
Loading
Loading