Skip to content

Commit

Permalink
Merge pull request #1397 from bcgov/test
Browse files Browse the repository at this point in the history
Test -> master
  • Loading branch information
devinleighsmith authored May 12, 2022
2 parents 8bde7b3 + 79e5cac commit 62e5c9a
Show file tree
Hide file tree
Showing 533 changed files with 72,734 additions and 7,773 deletions.
9 changes: 9 additions & 0 deletions backend/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,15 @@ dotnet_diagnostic.SA1208.severity = warning
dotnet_diagnostic.SA1623.severity = none
# SA1309 Field should not begin with an underscore
dotnet_diagnostic.SA1309.severity = none
# SA1513 Closing brace should be followed by an empty line
dotnet_diagnostic.SA1505.severity = none
# SA1505 Opening brace should be followed by an empty line
dotnet_diagnostic.SA1513.severity = none
# SA1124 Do not use regions
dotnet_diagnostic.SA1124.severity = none
# SA1507 Code should not contain multiple blank lines in a row
dotnet_diagnostic.SA1507.severity = none


# Entity Framework files
[**{entities/ef/*,PIMSContext}.cs]
Expand Down
17 changes: 14 additions & 3 deletions backend/api/Areas/Admin/Controllers/AccessRequestController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,20 @@ public AccessRequestController(IPimsRepository pimsService, IMapper mapper)
[SwaggerOperation(Tags = new[] { "admin-access-requests" })]
public IActionResult GetPage(int page = 1, int quantity = 10, string searchText = null, string role = null, string organization = null, string status = null, string sort = null)
{
if (page < 1) page = 1;
if (quantity < 1) quantity = 1;
if (quantity > 20) quantity = 20;
if (page < 1)
{
page = 1;
}

if (quantity < 1)
{
quantity = 1;
}

if (quantity > 20)
{
quantity = 20;
}

var filter = new EModel.AccessRequestFilter(page, quantity, searchText, role, organization, status, new[] { sort });

Expand Down
17 changes: 14 additions & 3 deletions backend/api/Areas/Admin/Controllers/ClaimController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,20 @@ public ClaimController(IPimsRepository pimsService, IMapper mapper)
[SwaggerOperation(Tags = new[] { "admin-claim" })]
public IActionResult GetClaims(int page = 1, int quantity = 10, string name = null)
{
if (page < 1) page = 1;
if (quantity < 1) quantity = 1;
if (quantity > 50) quantity = 50;
if (page < 1)
{
page = 1;
}

if (quantity < 1)
{
quantity = 1;
}

if (quantity > 50)
{
quantity = 50;
}

var paged = _pimsService.Claim.Get(page, quantity, name);
var result = _mapper.Map<Api.Models.PageModel<Model.ClaimModel>>(paged);
Expand Down
17 changes: 14 additions & 3 deletions backend/api/Areas/Admin/Controllers/RoleController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,20 @@ public RoleController(IPimsRepository pimsService, IMapper mapper)
[SwaggerOperation(Tags = new[] { "admin-role" })]
public IActionResult GetRoles(int page = 1, int quantity = 10, string name = null)
{
if (page < 1) page = 1;
if (quantity < 1) quantity = 1;
if (quantity > 50) quantity = 50;
if (page < 1)
{
page = 1;
}

if (quantity < 1)
{
quantity = 1;
}

if (quantity > 50)
{
quantity = 50;
}

var paged = _pimsService.Role.Get(page, quantity, name);
var result = _mapper.Map<Api.Models.PageModel<Model.RoleModel>>(paged);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,10 @@ public IActionResult GetOrganizationPredictions()
public IActionResult GetOrganizationPredictions([FromBody] AutocompletionRequestModel filter)
{
filter.ThrowBadRequestIfNull($"The request must include an autocomplete request.");
if (!filter.IsValid()) throw new BadRequestException("Autocomplete request must contain valid values.");
if (!filter.IsValid())
{
throw new BadRequestException("Autocomplete request must contain valid values.");
}

var predictions = _pimsService.Autocomplete.GetOrganizationPredictions(filter);

Expand Down
5 changes: 4 additions & 1 deletion backend/api/Areas/Contacts/Controllers/SearchController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,10 @@ public IActionResult GetContacts()
public IActionResult GetContacts([FromBody] ContactFilterModel filter)
{
filter.ThrowBadRequestIfNull($"The request must include a filter.");
if (!filter.IsValid()) throw new BadRequestException("Contact filter must contain valid values.");
if (!filter.IsValid())
{
throw new BadRequestException("Contact filter must contain valid values.");
}

Paged<Dal.Entities.PimsContactMgrVw> contacts = _pimsService.Contact.GetPage((ContactFilter)filter);
return new JsonResult(_mapper.Map<Api.Models.PageModel<ContactSummaryModel>>(contacts));
Expand Down
5 changes: 4 additions & 1 deletion backend/api/Areas/Leases/Controllers/SearchController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,10 @@ public IActionResult GetLeases()
public IActionResult GetLeases([FromBody] LeaseFilterModel filter)
{
filter.ThrowBadRequestIfNull($"The request must include a filter.");
if (!filter.IsValid()) throw new BadRequestException("Property filter must contain valid values.");
if (!filter.IsValid())
{
throw new BadRequestException("Property filter must contain valid values.");
}

var leases = _pimsService.Lease.GetPage((LeaseFilter)filter);
return new JsonResult(_mapper.Map<Api.Models.PageModel<LeaseModel>>(leases));
Expand Down
8 changes: 3 additions & 5 deletions backend/api/Areas/Leases/Mapping/Lease/PropertyMap.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Mapster;
using Pims.Api.Helpers.Extensions;
using Entity = Pims.Dal.Entities;
using Model = Pims.Api.Areas.Lease.Models.Lease;

Expand All @@ -15,8 +14,7 @@ public void Register(TypeAdapterConfig config)
.Map(dest => dest.PID, src => src.Property.Pid)
.Map(dest => dest.PIN, src => src.Property.Pin)
.Map(dest => dest.Name, src => src.Property.Name)
.Map(dest => dest.AreaUnitId, src => src.Property.PropertyAreaUnitTypeCode)
.Map(dest => dest.AreaUnit, src => src.Property.PropertyAreaUnitTypeCodeNavigation.Description)
.Map(dest => dest.AreaUnitType, src => src.AreaUnitTypeCodeNavigation)
.Map(dest => dest.Address, src => src.Property.Address)
.Map(dest => dest.IsSensitive, src => src.Property.IsSensitive)
.Map(dest => dest.Description, src => src.Property.Description)
Expand All @@ -28,12 +26,12 @@ public void Register(TypeAdapterConfig config)
.Map(dest => dest.PropertyId, src => src.Id)
.Map(dest => dest.Property, src => src)
.Map(dest => dest.LeaseArea, src => src.LandArea)
.Map(dest => dest.Property, src => src.AreaUnitType.GetTypeId())
.Map(dest => dest.AreaUnitTypeCode, src => src.AreaUnitType.Id)
.Map(dest => dest.ConcurrencyControlNumber, src => src.RowVersion);

config.NewConfig<Model.PropertyModel, Entity.PimsProperty> ()
.Map(dest => dest.PropertyId, src => src.Id)
.Map(dest => dest.Pid, src => src.PID == "" ? "-1" : src.PID)
.Map(dest => dest.Pid, src => src.PID == string.Empty ? "-1" : src.PID)
.Map(dest => dest.Pin, src => src.PIN)
.Map(dest => dest.ConcurrencyControlNumber, src => src.RowVersion);
}
Expand Down
4 changes: 2 additions & 2 deletions backend/api/Areas/Leases/Mapping/Lease/TenantMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public void Register(TypeAdapterConfig config)
config.NewConfig<Model.TenantModel, Entity.PimsLeaseTenant>()
.Map(dest => dest.LeaseTenantId, src => src.LeaseTenantId)
.Map(dest => dest.LeaseId, src => src.LeaseId)
.Map(dest => dest.OrganizationId, src => src.OrganizationId)
.Map(dest => dest.PersonId, src => src.PersonId)
.Map(dest => dest.OrganizationId, src => src.Id != null && src.Id.StartsWith('O') ? src.OrganizationId : null)
.Map(dest => dest.PersonId, src => src.Id != null && src.Id.StartsWith('P') ? src.PersonId : null)
.Map(dest => dest.Note, src => src.Note)
.Map(dest => dest.LessorTypeCode, src => src.PersonId != null ? LessorTypes.PERSON : LessorTypes.ORGANIZATION)
.Inherits<Api.Models.BaseAppModel, Entity.IBaseAppEntity>();
Expand Down
12 changes: 1 addition & 11 deletions backend/api/Areas/Leases/Models/Lease/PropertyModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,6 @@ public class PropertyModel
/// </summary>
public string Description { get; set; }

/// <summary>
/// get/set - Foreign key to the property area unit type.
/// </summary>
public string AreaUnitId { get; set; }

/// <summary>
/// get/set - Area unit description.
/// </summary>
public string AreaUnit { get; set; }

/// <summary>
/// get/set - Area unit type.
/// </summary>
Expand All @@ -49,7 +39,7 @@ public class PropertyModel
/// <summary>
/// get/set - The land area of the property.
/// </summary>
public Single LandArea { get; set; }
public float? LandArea { get; set; }

/// <summary>
/// get/set - The property address.
Expand Down
2 changes: 2 additions & 0 deletions backend/api/Areas/Persons/Mapping/Person/PersonMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ public void Register(TypeAdapterConfig config)
// The database supports many organizations for a person but the app currently supports only one linked organization per person.
var linkedOrganization = src.PimsPersonOrganizations?.FirstOrDefault(p => p != null && p.Organization != null)?.Organization;
if (linkedOrganization != null)
{
dest.Organization = new Model.OrganizationLinkModel { Id = linkedOrganization.Id, Text = linkedOrganization.Name };
}
});

config.NewConfig<Model.PersonModel, Entity.PimsPerson>()
Expand Down
5 changes: 4 additions & 1 deletion backend/api/Areas/Property/Controllers/SearchController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,10 @@ public IActionResult GetProperties()
public IActionResult GetProperties([FromBody] PropertyFilterModel filter)
{
filter.ThrowBadRequestIfNull($"The request must include a filter.");
if (!filter.IsValid()) throw new BadRequestException("Property filter must contain valid values.");
if (!filter.IsValid())
{
throw new BadRequestException("Property filter must contain valid values.");
}

var page = _pimsService.Property.GetPage((PropertyFilter)filter);
var result = _mapper.Map<BModel.PageModel<Models.Search.PropertyModel>>(page);
Expand Down
49 changes: 34 additions & 15 deletions backend/api/Areas/Reports/Controllers/LeaseController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public LeaseController(IPimsRepository pimsRepository, IPimsService pimsService,
/// <param name="all"></param>
/// <returns></returns>
[HttpGet]
[HasPermission(Permissions.PropertyView)]
[HasPermission(Permissions.LeaseView)]
[Produces(ContentTypes.CONTENT_TYPE_CSV, ContentTypes.CONTENT_TYPE_EXCELX)]
[ProducesResponseType(200)]
[SwaggerOperation(Tags = new[] { "lease", "report" })]
Expand All @@ -88,34 +88,32 @@ public IActionResult ExportLeases(bool all = false)
/// <param name="all"></param>
/// <returns></returns>
[HttpPost("filter")]
[HasPermission(Permissions.PropertyView)]
[HasPermission(Permissions.LeaseView)]
[Produces(ContentTypes.CONTENT_TYPE_CSV, ContentTypes.CONTENT_TYPE_EXCELX)]
[ProducesResponseType(200)]
[SwaggerOperation(Tags = new[] { "lease", "report" })]
public IActionResult ExportLeases([FromBody] Lease.Models.Search.LeaseFilterModel filter, bool all = false)
{
filter.ThrowBadRequestIfNull($"The request must include a filter.");
if (!filter.IsValid()) throw new BadRequestException("Lease filter must contain valid values.");
if (!filter.IsValid())
{
throw new BadRequestException("Lease filter must contain valid values.");
}

var accept = (string)this.Request.Headers["Accept"] ?? throw new BadRequestException($"HTTP request header 'Accept' is required.");

if (accept != ContentTypes.CONTENT_TYPE_CSV && accept != ContentTypes.CONTENT_TYPE_EXCEL && accept != ContentTypes.CONTENT_TYPE_EXCELX)
{
throw new BadRequestException($"Invalid HTTP request header 'Accept:{accept}'.");
}

//Create duplicate lease rows for every unique property lease, tenant, and term.
filter.Quantity = all ? _pimsRepository.Lease.Count() : filter.Quantity;
var page = _pimsRepository.Lease.GetPage((LeaseFilter)filter);
var leaseTerms = _mapper.Map<IEnumerable<Models.Lease.LeaseModel>>(page.Items.SelectMany(l => l.PimsLeaseTerms, (lease, term) => (lease, term)));
var leaseProperties = _mapper.Map<IEnumerable<Models.Lease.LeaseModel>>(page.Items.SelectMany(l => l.PimsPropertyLeases, (lease, property) => (lease, property)));
var leaseTenants = _mapper.Map<IEnumerable<Models.Lease.LeaseModel>>(page.Items.SelectMany(l => l.PimsLeaseTenants, (lease, tenant) => (lease, tenant)));
var leases = _mapper.Map<IEnumerable<Models.Lease.LeaseModel>>(page.Items.Where(l => !l.PimsLeaseTenants.Any() && !l.PimsLeaseTerms.Any() && !l.PimsPropertyLeases.Any()));
var allLeases = leaseTerms.Concat(leaseProperties).Concat(leaseTenants).Concat(leases);
var flatLeases = GetCrossJoinLeases(filter, all);

return accept.ToString() switch
{
ContentTypes.CONTENT_TYPE_CSV => ReportHelper.GenerateCsv(allLeases),
_ => ReportHelper.GenerateExcel(allLeases, "PIMS")
ContentTypes.CONTENT_TYPE_CSV => ReportHelper.GenerateCsv(flatLeases),
_ => ReportHelper.GenerateExcel(flatLeases, "PIMS")
};

}

/// <summary>
Expand All @@ -131,7 +129,11 @@ public IActionResult ExportLeases([FromBody] Lease.Models.Search.LeaseFilterMode
[SwaggerOperation(Tags = new[] { "lease", "report" })]
public IActionResult ExportAggregatedLeases(int fiscalYearStart)
{
if (fiscalYearStart< 1900) throw new BadRequestException("Fiscal year invalid.");
if (fiscalYearStart < 1900)
{
throw new BadRequestException("Fiscal year invalid.");
}

IEnumerable<PimsLease> leasesForFiscal = _pimsService.LeaseReportsService.GetAggregatedLeaseReport(fiscalYearStart);
var programs = _pimsRepository.Lookup.GetLeaseProgramTypes();
var regions = _pimsRepository.Lookup.GetRegions();
Expand All @@ -151,6 +153,23 @@ public IActionResult ExportAggregatedLeases(int fiscalYearStart)
}

#endregion

/// <summary>
/// Create duplicate lease rows for every unique property lease, tenant, and term.
/// </summary>
/// <param name="filter"></param>
/// <param name="all"></param>
/// <returns></returns>
public IEnumerable<LeaseModel> GetCrossJoinLeases(Lease.Models.Search.LeaseFilterModel filter, bool all = false)
{
filter.Quantity = all ? _pimsRepository.Lease.Count() : filter.Quantity;
var page = _pimsRepository.Lease.GetPage((LeaseFilter)filter);
var allLeases = page.Items.SelectMany(l => l.PimsLeaseTerms.DefaultIfEmpty(), (lease, term) => (lease, term))
.SelectMany(lt => lt.lease.PimsPropertyLeases.DefaultIfEmpty(), (leaseTerm, property) => (leaseTerm.term, leaseTerm.lease, property))
.SelectMany(ltp => ltp.lease.PimsLeaseTenants.DefaultIfEmpty(), (leaseTermProperty, tenant) => (leaseTermProperty.term, leaseTermProperty.lease, leaseTermProperty.property, tenant));
var flatLeases = _mapper.Map<IEnumerable<LeaseModel>>(allLeases);
return flatLeases;
}
#endregion
}
}
8 changes: 7 additions & 1 deletion backend/api/Areas/Reports/Controllers/PropertyController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,17 @@ public IActionResult ExportProperties(bool all = false)
public IActionResult ExportProperties([FromBody] Property.Models.Search.PropertyFilterModel filter, bool all = false)
{
filter.ThrowBadRequestIfNull($"The request must include a filter.");
if (!filter.IsValid()) throw new BadRequestException("Property filter must contain valid values.");
if (!filter.IsValid())
{
throw new BadRequestException("Property filter must contain valid values.");
}

var accept = (string)this.Request.Headers["Accept"] ?? throw new BadRequestException($"HTTP request header 'Accept' is required.");

if (accept != ContentTypes.CONTENT_TYPE_CSV && accept != ContentTypes.CONTENT_TYPE_EXCEL && accept != ContentTypes.CONTENT_TYPE_EXCELX)
{
throw new BadRequestException($"Invalid HTTP request header 'Accept:{accept}'.");
}

filter.Quantity = all ? _pimsService.Property.Count() : filter.Quantity;
var page = _pimsService.Property.GetPage((PropertyFilter)filter);
Expand Down
2 changes: 2 additions & 0 deletions backend/api/Areas/Reports/Controllers/UserController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ public IActionResult ExportUsers([FromBody] EModel.UserFilter filter, bool all =
var accept = (string)this.Request.Headers["Accept"] ?? throw new BadRequestException($"HTTP request header 'Accept' is required.");

if (accept != ContentTypes.CONTENT_TYPE_CSV && accept != ContentTypes.CONTENT_TYPE_EXCEL && accept != ContentTypes.CONTENT_TYPE_EXCELX)
{
throw new BadRequestException($"Invalid HTTP request header 'Accept:{accept}'.");
}

filter.Quantity = all ? _pimsService.User.Count() : filter.Quantity;
var page = _pimsService.User.Get(filter);
Expand Down
Loading

0 comments on commit 62e5c9a

Please sign in to comment.