Skip to content

Commit

Permalink
Merge branch 'psp-7993' into psp-7995
Browse files Browse the repository at this point in the history
  • Loading branch information
devinleighsmith committed Mar 22, 2024
2 parents ac9f240 + a1053c1 commit b75659b
Show file tree
Hide file tree
Showing 34 changed files with 604 additions and 489 deletions.
4 changes: 2 additions & 2 deletions source/backend/api/Pims.Api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<UserSecretsId>0ef6255f-9ea0-49ec-8c65-c172304b4926</UserSecretsId>
<Version>5.0.1-76.5</Version>
<Version>5.0.1-76.5</Version>
<Version>5.0.1-76.16</Version>
<Version>5.0.1-76.16</Version>
<AssemblyVersion>5.0.1.76</AssemblyVersion>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<ProjectGuid>16BC0468-78F6-4C91-87DA-7403C919E646</ProjectGuid>
Expand Down
31 changes: 28 additions & 3 deletions source/backend/api/Services/AcquisitionFileService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -745,10 +745,10 @@ private void TransferPropertiesOfInterest(PimsAcquisitionFile acquisitionFile, b
{
// Get the current properties in the research file
var currentProperties = _acquisitionFilePropertyRepository.GetPropertiesByAcquisitionFileId(acquisitionFile.Internal_Id);
var propertiesOfInterest = currentProperties.Where(p => p.Property.IsPropertyOfInterest);

// PSP-6111 Business rule: Transfer properties of interest to core inventory when acquisition file is completed
foreach (var acquisitionProperty in propertiesOfInterest)
// PSP-7892 Business rule: Process all properties in the acq file (not only properties of interest).
foreach (var acquisitionProperty in currentProperties)
{
var property = acquisitionProperty.Property;
var takes = _takeRepository.GetAllByPropertyAcquisitionFileId(acquisitionProperty.Internal_Id);
Expand Down Expand Up @@ -776,11 +776,36 @@ private void TransferPropertiesOfInterest(PimsAcquisitionFile acquisitionFile, b
isOtherInterest = false;
}

if (!userOverride && (isOwned || isOtherInterest))
// PSP-7892: Follow ownership priority when updating an existing property
if (property.IsOwned || isOwned)
{
isOwned = true;
isOtherInterest = false;
isPropertyOfInterest = false;
}
else if(property.IsOtherInterest || isOtherInterest)
{
isOwned = false;
isOtherInterest = true;
isPropertyOfInterest = false;
}
else if(property.IsPropertyOfInterest || isPropertyOfInterest)
{
isOwned = false;
isOtherInterest = false;
isPropertyOfInterest = true;
}

if (!userOverride && property.IsPropertyOfInterest && (isOwned || isOtherInterest))
{
throw new UserOverrideException(UserOverrideCode.PoiToInventory, "You have one or more take(s) that will be added to MoTI Inventory. Do you want to acknowledge and proceed?");
}

if (!userOverride && property.IsOtherInterest && isOwned)
{
throw new UserOverrideException(UserOverrideCode.PoiToInventory, "You have one or more take(s) that will be changed from 'Other Interest' to 'Core Inventory'. Do you want to acknowledge and proceed?");
}

PropertyOwnershipState ownership = new() { isOwned = isOwned, isPropertyOfInterest = isPropertyOfInterest, isOtherInterest = isOtherInterest, isDisposed = false };
_propertyRepository.TransferFileProperty(property, ownership);
}
Expand Down
20 changes: 7 additions & 13 deletions source/backend/api/Services/PropertyOperationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,25 +129,19 @@ public IEnumerable<PimsPropertyOperation> ConsolidateProperty(IEnumerable<PimsPr
throw new BusinessRuleViolationException("Consolidations must contain at least two different parent properties.");
}

// either the property exists in pims, and is present in the source properties list, or the property does not have a match in PIMS at all (neither pid nor property_id).
if (destinationProperty?.PropertyId > 0)
try
{
if (!dbSourceProperties.Any(sp => sp.PropertyId == destinationProperty?.PropertyId))
var dbDestinationProperty = _propertyService.GetByPid(destinationProperty?.Pid?.ToString());

// if the property exists in pims, it must also be present in the source properties list.
if (!dbSourceProperties.Any(sp => sp.PropertyId == dbDestinationProperty?.PropertyId))
{
throw new BusinessRuleViolationException("Consolidated child property may not be in the PIMS inventory unless also in the parent property list.");
}
}
else
catch (KeyNotFoundException)
{
try
{
_propertyService.GetByPid(destinationProperty?.Pid?.ToString());
throw new BusinessRuleViolationException("Consolidated child may not already be in the PIMS inventory.");
}
catch (KeyNotFoundException)
{
// ignore exception, the pid should not exist.
}
// ignore exception, the pid should not exist.
}

// retire the source properties
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@ public void Register(TypeAdapterConfig config)
.Map(dest => dest.DocumentReference, src => src.DocumentReference)
.Map(dest => dest.ResearchSummary, src => src.ResearchSummary)
.Map(dest => dest.Property, src => src.Property)
.Map(dest => dest.PropertyId, src => src.PropertyId)
.Map(dest => dest.File, src => src.ResearchFile)
.Map(dest => dest.FileId, src => src.ResearchFileId)
.Map(dest => dest.PurposeTypes, src => src.PimsPrfPropResearchPurposeTypes)
.Inherits<Entity.IBaseEntity, BaseConcurrentModel>();

config.NewConfig<ResearchFilePropertyModel, Entity.PimsPropertyResearchFile>()
.Map(dest => dest.PropertyResearchFileId, src => src.Id)
.Map(dest => dest.Property, src => src.Property)
.Map(dest => dest.PropertyId, src => src.Property.Id)
.Map(dest => dest.PropertyId, src => src.PropertyId)
.Map(dest => dest.ResearchFileId, src => src.FileId)
.Map(dest => dest.PropertyName, src => src.PropertyName)
.Map(dest => dest.DisplayOrder, src => src.DisplayOrder)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ public void Consolidate_Should_Fail_DestinationInInventory()
var service = this.CreateDispositionServiceWithPermissions(Permissions.PropertyEdit);
var propertyService = this._helper.GetService<Mock<IPropertyService>>();
propertyService.Setup(x => x.GetMultipleById(It.IsAny<List<long>>())).Returns(new List<PimsProperty> { EntityHelper.CreateProperty(3), EntityHelper.CreateProperty(4) });
propertyService.Setup(x => x.GetByPid(It.IsAny<string>())).Returns(EntityHelper.CreateProperty(4));
propertyService.Setup(x => x.GetByPid(It.IsAny<string>())).Returns(EntityHelper.CreateProperty(2));

var operationOne = EntityHelper.CreatePropertyOperation();
operationOne.SourceProperty.PropertyId = 5;
Expand All @@ -400,30 +400,6 @@ public void Consolidate_Should_Fail_DestinationInInventory()
exception.WithMessage("Consolidated child property may not be in the PIMS inventory unless also in the parent property list.");
}

[Fact]
public void Consolidate_Should_Fail_PidExists()
{
// Arrange
var service = this.CreateDispositionServiceWithPermissions(Permissions.PropertyEdit);
var propertyService = this._helper.GetService<Mock<IPropertyService>>();
propertyService.Setup(x => x.GetMultipleById(It.IsAny<List<long>>())).Returns(new List<PimsProperty> { EntityHelper.CreateProperty(3), EntityHelper.CreateProperty(4) });
propertyService.Setup(x => x.GetByPid(It.IsAny<string>())).Returns(EntityHelper.CreateProperty(4));

var operationOne = EntityHelper.CreatePropertyOperation();
operationOne.SourceProperty.PropertyId = 5;
operationOne.DestinationPropertyId = 0;
operationOne.DestinationProperty.PropertyId = 0;

var operations = new List<PimsPropertyOperation>() { operationOne, EntityHelper.CreatePropertyOperation() };

// Act
Action act = () => service.ConsolidateProperty(operations);

// Assert
var exception = act.Should().Throw<BusinessRuleViolationException>();
exception.WithMessage("Consolidated child may not already be in the PIMS inventory.");
}

[Fact]
public void Consolidate_Success()
{
Expand Down
2 changes: 1 addition & 1 deletion source/frontend/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "frontend",
"version": "5.0.1-76.5",
"version": "5.0.1-76.16",
"private": true,
"dependencies": {
"@bcgov/bc-sans": "1.0.1",
Expand Down
Loading

0 comments on commit b75659b

Please sign in to comment.