Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PSP-7158 Show markers positioned corresponding to that file #4147

Merged
merged 11 commits into from
Jul 9, 2024
37 changes: 29 additions & 8 deletions source/backend/api/Services/AcquisitionFileService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,12 @@ public PimsAcquisitionFile Add(PimsAcquisitionFile acquisitionFile, IEnumerable<

PopulateAcquisitionChecklist(acquisitionFile);

// Update file specific marker locations
foreach (var incomingAcquisitionProperty in acquisitionFile.PimsPropertyAcquisitionFiles)
{
_propertyService.PopulateNewFileProperty(incomingAcquisitionProperty);
}

acquisitionFile.AcquisitionFileStatusTypeCode = AcquisitionStatusTypes.ACTIVE.ToString();
var newAcqFile = _acqFileRepository.Add(acquisitionFile);
_acqFileRepository.CommitTransaction();
Expand Down Expand Up @@ -282,7 +288,7 @@ public PimsAcquisitionFile Update(PimsAcquisitionFile acquisitionFile, IEnumerab

public PimsAcquisitionFile UpdateProperties(PimsAcquisitionFile acquisitionFile, IEnumerable<UserOverrideCode> userOverrides)
{
_logger.LogInformation("Updating acquisition file properties...");
_logger.LogInformation("Updating acquisition file properties with AcquisitionFile id: {id}", acquisitionFile.Internal_Id);
_user.ThrowIfNotAllAuthorized(Permissions.AcquisitionFileEdit, Permissions.PropertyView, Permissions.PropertyAdd);
_user.ThrowInvalidAccessToAcquisitionFile(_userRepository, _acqFileRepository, acquisitionFile.Internal_Id);

Expand All @@ -299,30 +305,45 @@ public PimsAcquisitionFile UpdateProperties(PimsAcquisitionFile acquisitionFile,
}

// Get the current properties in the research file
var currentProperties = _acquisitionFilePropertyRepository.GetPropertiesByAcquisitionFileId(acquisitionFile.Internal_Id);
var currentFileProperties = _acquisitionFilePropertyRepository.GetPropertiesByAcquisitionFileId(acquisitionFile.Internal_Id);

// Check if the property is new or if it is being updated
foreach (var incomingAcquisitionProperty in acquisitionFile.PimsPropertyAcquisitionFiles)
{
// If the property is not new, check if the name has been updated.
if (incomingAcquisitionProperty.Internal_Id != 0)
{
PimsPropertyAcquisitionFile existingProperty = currentProperties.FirstOrDefault(x => x.Internal_Id == incomingAcquisitionProperty.Internal_Id);
if (existingProperty.PropertyName != incomingAcquisitionProperty.PropertyName)
var needsUpdate = false;
PimsPropertyAcquisitionFile existingFileProperty = currentFileProperties.FirstOrDefault(x => x.Internal_Id == incomingAcquisitionProperty.Internal_Id);
if (existingFileProperty.PropertyName != incomingAcquisitionProperty.PropertyName)
{
existingFileProperty.PropertyName = incomingAcquisitionProperty.PropertyName;
needsUpdate = true;
}

var incomingGeom = incomingAcquisitionProperty.Location;
var existingGeom = existingFileProperty.Location;
if (existingGeom is null || (incomingGeom is not null && !existingGeom.EqualsExact(incomingGeom)))
{
_propertyService.UpdateFilePropertyLocation(incomingAcquisitionProperty, existingFileProperty);
needsUpdate = true;
}

if (needsUpdate)
{
existingProperty.PropertyName = incomingAcquisitionProperty.PropertyName;
_acquisitionFilePropertyRepository.Update(existingProperty);
_acquisitionFilePropertyRepository.Update(existingFileProperty);
}
}
else
{
// New property needs to be added
_acquisitionFilePropertyRepository.Add(incomingAcquisitionProperty);
var newFileProperty = _propertyService.PopulateNewFileProperty(incomingAcquisitionProperty);
_acquisitionFilePropertyRepository.Add(newFileProperty);
}
}

// The ones not on the new set should be deleted
List<PimsPropertyAcquisitionFile> differenceSet = currentProperties.Where(x => !acquisitionFile.PimsPropertyAcquisitionFiles.Any(y => y.Internal_Id == x.Internal_Id)).ToList();
List<PimsPropertyAcquisitionFile> differenceSet = currentFileProperties.Where(x => !acquisitionFile.PimsPropertyAcquisitionFiles.Any(y => y.Internal_Id == x.Internal_Id)).ToList();
foreach (var deletedProperty in differenceSet)
{
var acqFileProperties = _acquisitionFilePropertyRepository.GetPropertiesByAcquisitionFileId(acquisitionFile.Internal_Id).FirstOrDefault(ap => ap.PropertyId == deletedProperty.PropertyId);
Expand Down
5 changes: 5 additions & 0 deletions source/backend/api/Services/IPropertyService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ public interface IPropertyService

void UpdateLocation(PimsProperty incomingProperty, ref PimsProperty propertyToUpdate, IEnumerable<UserOverrideCode> overrideCodes);

T PopulateNewFileProperty<T>(T fileProperty);

void UpdateFilePropertyLocation<T>(T incomingFileProperty, T filePropertyToUpdate)
where T : IWithPropertyEntity;

IList<PimsHistoricalFileNumber> GetHistoricalNumbersForPropertyId(long propertyId);

IList<PimsHistoricalFileNumber> UpdateHistoricalFileNumbers(long propertyId, IEnumerable<PimsHistoricalFileNumber> pimsHistoricalNumbers);
Expand Down
40 changes: 40 additions & 0 deletions source/backend/api/Services/PropertyService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,40 @@ public void UpdateLocation(PimsProperty incomingProperty, ref PimsProperty prope
}
}

public T PopulateNewFileProperty<T>(T fileProperty)
{
// TODO: Remove this casting when LOCATION gets added to all remaining file-property types (research, disposition, lease)
if (fileProperty is PimsPropertyAcquisitionFile acquisitionFileProperty)
{
// convert spatial location from lat/long (4326) to BC Albers (3005) for database storage
var geom = acquisitionFileProperty.Location;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this casting check for null?

if (geom is not null && geom.SRID != SpatialReference.BCALBERS)
{
var newCoords = _coordinateService.TransformCoordinates(geom.SRID, SpatialReference.BCALBERS, geom.Coordinate);
acquisitionFileProperty.Location = GeometryHelper.CreatePoint(newCoords, SpatialReference.BCALBERS);
}
}

return fileProperty;
}

public void UpdateFilePropertyLocation<T>(T incomingFileProperty, T filePropertyToUpdate)
where T : IWithPropertyEntity
{
// TODO: Remove this casting when LOCATION gets added to all remaining file-property types (research, disposition, lease)
if (incomingFileProperty is PimsPropertyAcquisitionFile incomingAcquisitionProperty
&& filePropertyToUpdate is PimsPropertyAcquisitionFile acquisitionPropertyToUpdate)
{
// convert spatial location from lat/long (4326) to BC Albers (3005) for database storage
var geom = incomingAcquisitionProperty.Location;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does the above casting also check for null?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also - a note that this casting will go away this sprint with the story to use location on other file types

if (geom is not null && geom.SRID != SpatialReference.BCALBERS)
{
var newCoords = _coordinateService.TransformCoordinates(geom.SRID, SpatialReference.BCALBERS, geom.Coordinate);
acquisitionPropertyToUpdate.Location = GeometryHelper.CreatePoint(newCoords, SpatialReference.BCALBERS);
}
}
}

public IList<PimsHistoricalFileNumber> GetHistoricalNumbersForPropertyId(long propertyId)
{

Expand Down Expand Up @@ -415,6 +449,12 @@ public List<T> TransformAllPropertiesToLatLong<T>(List<T> fileProperties)
{
foreach (var fileProperty in fileProperties)
{
// TODO: Remove this casting when LOCATION gets added to all remaining file-property types (research, disposition, lease)
if (fileProperty is PimsPropertyAcquisitionFile acquisitionFileProperty && acquisitionFileProperty.Location is not null)
{
acquisitionFileProperty.Location = TransformCoordinates(acquisitionFileProperty.Location);
}

TransformPropertyToLatLong(fileProperty.Property);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public void Register(TypeAdapterConfig config)
.Map(dest => dest.Id, src => src.PropertyAcquisitionFileId)
.Map(dest => dest.PropertyName, src => src.PropertyName)
.Map(dest => dest.DisplayOrder, src => src.DisplayOrder)
.Map(dest => dest.Location, src => src.Location)
.Map(dest => dest.Property, src => src.Property)
.Map(dest => dest.PropertyId, src => src.PropertyId)
.Map(dest => dest.File, src => src.AcquisitionFile)
Expand All @@ -27,6 +28,7 @@ public void Register(TypeAdapterConfig config)
.Map(dest => dest.AcquisitionFileId, src => src.FileId)
.Map(dest => dest.PropertyName, src => src.PropertyName)
.Map(dest => dest.DisplayOrder, src => src.DisplayOrder)
.Map(dest => dest.Location, src => src.Location)
.Inherits<BaseConcurrentModel, Entity.IBaseEntity>();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,15 @@ public class FilePropertyModel : BaseConcurrentModel
public long Id { get; set; }

/// <summary>
/// get/set - The descriptive name of the property for this acquisition file.
/// get/set - The descriptive name of the property for this file.
/// </summary>
public string PropertyName { get; set; }

/// <summary>
/// get/set - The location of the property in the context of this file.
/// </summary>
public GeometryModel Location { get; set; }

/// <summary>
/// get/set - The order to display the relationship.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ public class GeometryModel
#region Properties

/// <summary>
/// get/set - The cordinate for the geometry.
/// get/set - The coordinate for the geometry.
/// </summary>
public CoordinateModel Coordinate { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1344,6 +1344,7 @@ public void UpdateProperties_MatchProperties_NewProperty_Success()
RegionCode = 1,
}
);
propertyService.Setup(x => x.PopulateNewFileProperty(It.IsAny<PimsPropertyAcquisitionFile>())).Returns<PimsPropertyAcquisitionFile>(x => x);

var userRepository = this._helper.GetService<Mock<IUserRepository>>();
userRepository.Setup(x => x.GetUserInfoByKeycloakUserId(It.IsAny<Guid>())).Returns(EntityHelper.CreateUser(1, Guid.NewGuid(), "Test", regionCode: 1));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { PIMS_Property_Location_View } from '@/models/layers/pimsPropertyLocatio
export interface LocationFeatureDataset {
selectingComponentId: string | null;
location: LatLngLiteral;
fileLocation: LatLngLiteral | null;
pimsFeature: Feature<Geometry, PIMS_Property_Location_View> | null;
parcelFeature: Feature<Geometry, PMBC_FullyAttributed_Feature_Properties> | null;
regionFeature: Feature<Geometry, MOT_RegionalBoundary_Feature_Properties> | null;
Expand Down Expand Up @@ -44,6 +45,7 @@ const useLocationFeatureLoader = () => {
const result: LocationFeatureDataset = {
selectingComponentId: null,
location: latLng,
fileLocation: latLng,
pimsFeature: null,
parcelFeature: null,
regionFeature: null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ describe('LayerPopupView component', () => {
geometry: { type: 'Point', coordinates: [] },
},
location: { lat: 0, lng: 0 },
fileLocation: null,
parcelFeature: null,
regionFeature: null,
districtFeature: null,
Expand All @@ -112,6 +113,7 @@ describe('LayerPopupView component', () => {
geometry: { type: 'Point', coordinates: [] },
},
location: { lat: 0, lng: 0 },
fileLocation: null,
pimsFeature: null,
regionFeature: null,
districtFeature: null,
Expand Down Expand Up @@ -139,6 +141,7 @@ describe('LayerPopupView component', () => {
geometry: { type: 'Point', coordinates: [] },
},
location: { lat: 0, lng: 0 },
fileLocation: null,
pimsFeature: {
type: 'Feature',
properties: null as any,
Expand Down Expand Up @@ -184,12 +187,13 @@ describe('LayerPopupView component', () => {
expect(history.location.pathname).toBe('/mapview/sidebar/acquisition/new');
});

it('Hides subdivision and consolidation if not in the pims system', async () => {
it('hides subdivision and consolidation if not in the pims system', async () => {
const { getByTestId, getByText, queryByText } = setup({
layerPopup: { data: {} } as any,
featureDataset: {
pimsFeature: null,
location: { lat: 0, lng: 0 },
fileLocation: null,
parcelFeature: null,
regionFeature: null,
districtFeature: null,
Expand All @@ -206,7 +210,7 @@ describe('LayerPopupView component', () => {
expect(consolidationLink).not.toBeInTheDocument();
});

it('handles create create subdivision action', async () => {
it('handles create subdivision action', async () => {
const propertyId = 1;

const { getByTestId, getByText } = setup({
Expand All @@ -218,6 +222,7 @@ describe('LayerPopupView component', () => {
geometry: { type: 'Point', coordinates: [] },
},
location: { lat: 0, lng: 0 },
fileLocation: null,
parcelFeature: null,
regionFeature: null,
districtFeature: null,
Expand Down Expand Up @@ -245,6 +250,7 @@ describe('LayerPopupView component', () => {
geometry: { type: 'Point', coordinates: [] },
},
location: { lat: 0, lng: 0 },
fileLocation: null,
parcelFeature: null,
regionFeature: null,
districtFeature: null,
Expand Down
2 changes: 2 additions & 0 deletions source/frontend/src/components/propertySelector/models.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { MultiPolygon, Polygon } from 'geojson';
import { LatLngLiteral } from 'leaflet';

import { AreaUnitTypes } from '@/constants';

Expand All @@ -8,6 +9,7 @@ export interface IMapProperty {
pin?: string;
latitude?: number;
longitude?: number;
fileLocation?: LatLngLiteral;
polygon?: Polygon | MultiPolygon;
planNumber?: string;
address?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,14 +207,7 @@ export const PropertySelectorSearchContainer: React.FC<IPropertySelectorSearchCo
);
};

export const featureToLocationFeatureDataset = (
feature: Feature<
Geometry,
{
[name: string]: any;
}
>,
) => {
export const featureToLocationFeatureDataset = (feature: Feature<Geometry, GeoJsonProperties>) => {
const center = getFeatureBoundedCenter(feature);
return {
parcelFeature: feature,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ describe('Disposition List View', () => {
displayOrder: null,
file: null,
propertyName: null,
location: null,
rowVersion: null,
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ describe('Disposition search results table', () => {
displayOrder: null,
file: null,
propertyName: null,
location: null,
rowVersion: null,
},
{
Expand All @@ -99,6 +100,7 @@ describe('Disposition search results table', () => {
displayOrder: null,
file: null,
propertyName: null,
location: null,
rowVersion: null,
},
{
Expand All @@ -109,6 +111,7 @@ describe('Disposition search results table', () => {
displayOrder: null,
file: null,
propertyName: null,
location: null,
rowVersion: null,
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ describe('LeaseHeaderAddresses component', () => {
id: 0,
propertyId: 0,
propertyName: null,
location: null,
rowVersion: null,
},
{
Expand All @@ -77,6 +78,7 @@ describe('LeaseHeaderAddresses component', () => {
id: 0,
propertyId: 0,
propertyName: null,
location: null,
rowVersion: null,
},
{
Expand All @@ -89,6 +91,7 @@ describe('LeaseHeaderAddresses component', () => {
id: 0,
propertyId: 0,
propertyName: null,
location: null,
rowVersion: null,
},
{
Expand All @@ -101,6 +104,7 @@ describe('LeaseHeaderAddresses component', () => {
id: 0,
propertyId: 0,
propertyName: null,
location: null,
rowVersion: null,
},
{
Expand All @@ -113,6 +117,7 @@ describe('LeaseHeaderAddresses component', () => {
id: 0,
propertyId: 0,
propertyName: null,
location: null,
rowVersion: null,
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ describe('Lease Surplus Declaration', () => {
id: 0,
propertyId: 0,
propertyName: null,
location: null,
rowVersion: null,
},
],
Expand Down Expand Up @@ -103,6 +104,7 @@ describe('Lease Surplus Declaration', () => {
id: 0,
propertyId: 0,
propertyName: null,
location: null,
rowVersion: null,
},
],
Expand Down Expand Up @@ -144,6 +146,7 @@ describe('Lease Surplus Declaration', () => {
id: 0,
propertyId: 0,
propertyName: null,
location: null,
rowVersion: null,
},
],
Expand Down
Loading
Loading