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

Scaffold-s66 #3552

Merged
merged 3 commits into from
Oct 30, 2023
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
6 changes: 3 additions & 3 deletions source/backend/api/Models/Concepts/Product/ProductMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ public void Register(TypeAdapterConfig config)
{
config.NewConfig<Entity.PimsProduct, ProductModel>()
.Map(dest => dest.Id, src => src.Internal_Id)
.Map(dest => dest.ParentProject, src => src.ParentProject)
.Map(dest => dest.ParentProjectId, src => src.ParentProjectId)
//.Map(dest => dest.ParentProject, src => src.ParentProject) // Todo: Fix This.
//.Map(dest => dest.ParentProjectId, src => src.ParentProjectId) // Todo: Fix This.
.Map(dest => dest.AcquisitionFiles, src => src.PimsAcquisitionFiles)
.Map(dest => dest.Code, src => src.Code)
.Map(dest => dest.Description, src => src.Description)
Expand All @@ -23,7 +23,7 @@ public void Register(TypeAdapterConfig config)

config.NewConfig<ProductModel, Entity.PimsProduct>()
.Map(dest => dest.Internal_Id, src => src.Id)
.Map(dest => dest.ParentProjectId, src => src.ParentProjectId)
//.Map(dest => dest.ParentProjectId, src => src.ParentProjectId) // Todo: Fix This.
.Map(dest => dest.PimsAcquisitionFiles, src => src.AcquisitionFiles)
.Map(dest => dest.Code, src => src.Code)
.Map(dest => dest.Description, src => src.Description)
Expand Down
4 changes: 2 additions & 2 deletions source/backend/api/Models/Concepts/Project/ProjectMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public void Register(TypeAdapterConfig config)
.Map(dest => dest.Code, src => src.Code)
.Map(dest => dest.Description, src => src.Description)
.Map(dest => dest.Note, src => src.Note)
.Map(dest => dest.Products, src => src.PimsProducts)
//.Map(dest => dest.Products, src => src.PimsProducts) // TODO: Fix this.
.Map(dest => dest.AppLastUpdateUserid, src => src.AppLastUpdateUserid)
.Map(dest => dest.AppLastUpdateTimestamp, src => src.AppLastUpdateTimestamp)
.Inherits<Entity.IBaseEntity, BaseModel>();
Expand All @@ -32,7 +32,7 @@ public void Register(TypeAdapterConfig config)
.Map(dest => dest.Code, src => src.Code)
.Map(dest => dest.Description, src => src.Description)
.Map(dest => dest.Note, src => src.Note)
.Map(dest => dest.PimsProducts, src => src.Products)
//.Map(dest => dest.PimsProducts, src => src.Products) // TODO: Fix this.
.Inherits<BaseModel, Entity.IBaseEntity>();
}
}
Expand Down
24 changes: 12 additions & 12 deletions source/backend/api/Models/Concepts/Take/TakeMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ public void Register(TypeAdapterConfig config)
config.NewConfig<Entity.PimsTake, TakeModel>()
.Map(dest => dest.Id, src => src.TakeId)
.Map(dest => dest.Description, src => src.Description)
.Map(dest => dest.IsSurplus, src => src.IsSurplus)
.Map(dest => dest.IsSurplus, src => src.IsThereSurplus)
.Map(dest => dest.LicenseToConstructArea, src => src.LicenseToConstructArea)
.Map(dest => dest.LtcEndDt, src => src.LtcEndDt)
.Map(dest => dest.NewRightOfWayArea, src => src.NewRightOfWayArea)
.Map(dest => dest.NewRightOfWayArea, src => src.StatutoryRightOfWayArea)
.Map(dest => dest.LandActArea, src => src.LandActArea)
.Map(dest => dest.LandActEndDt, src => src.LandActEndDt)
.Map(dest => dest.PropertyAcquisitionFile, src => src.PropertyAcquisitionFile)
Expand All @@ -24,23 +24,23 @@ public void Register(TypeAdapterConfig config)
.Map(dest => dest.TakeTypeCode, src => src.TakeTypeCode)
.Map(dest => dest.TakeStatusTypeCode, src => src.TakeStatusTypeCode)
.Map(dest => dest.LandActTypeCode, src => src.LandActTypeCodeNavigation)
.Map(dest => dest.IsLicenseToConstruct, src => src.IsLicenseToConstruct)
.Map(dest => dest.IsNewRightOfWay, src => src.IsNewRightOfWay)
.Map(dest => dest.IsLandAct, src => src.IsLandAct)
.Map(dest => dest.IsStatutoryRightOfWay, src => src.IsStatutoryRightOfWay)
.Map(dest => dest.IsLicenseToConstruct, src => src.IsNewLicenseToConstruct)
//.Map(dest => dest.IsNewRightOfWay, src => src.IsNewRightOfWay) // TODO: Fix this
.Map(dest => dest.IsLandAct, src => src.IsNewLandAct)
//.Map(dest => dest.IsStatutoryRightOfWay, src => src.IsStatutoryRightOfWay) // TODO: Fix this
.Inherits<Entity.IBaseAppEntity, Api.Models.BaseAppModel>();

config.NewConfig<TakeModel, Entity.PimsTake>()
.Map(dest => dest.TakeId, src => src.Id)
.Map(dest => dest.Description, src => src.Description)
.Map(dest => dest.IsSurplus, src => src.IsSurplus)
.Map(dest => dest.IsNewRightOfWay, src => src.IsNewRightOfWay)
.Map(dest => dest.IsLandAct, src => src.IsLandAct)
.Map(dest => dest.IsStatutoryRightOfWay, src => src.IsStatutoryRightOfWay)
.Map(dest => dest.IsLicenseToConstruct, src => src.IsLicenseToConstruct)
.Map(dest => dest.IsThereSurplus, src => src.IsSurplus)
//.Map(dest => dest.IsNewRightOfWay, src => src.IsNewRightOfWay) // TODO: Fix this.
.Map(dest => dest.IsNewLandAct, src => src.IsLandAct)
//.Map(dest => dest.IsStatutoryRightOfWay, src => src.IsStatutoryRightOfWay) // TODO: Fix this
.Map(dest => dest.IsNewLicenseToConstruct, src => src.IsLicenseToConstruct)
.Map(dest => dest.LicenseToConstructArea, src => src.LicenseToConstructArea)
.Map(dest => dest.LtcEndDt, src => src.LtcEndDt)
.Map(dest => dest.NewRightOfWayArea, src => src.NewRightOfWayArea)
.Map(dest => dest.StatutoryRightOfWayArea, src => src.NewRightOfWayArea)
.Map(dest => dest.LandActArea, src => src.LandActArea)
.Map(dest => dest.LandActEndDt, src => src.LandActEndDt)
.Map(dest => dest.PropertyAcquisitionFile, src => src.PropertyAcquisitionFile)
Expand Down
11 changes: 7 additions & 4 deletions source/backend/api/Services/ProjectService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,9 @@ public PimsProject Add(PimsProject project)
{
throw new ArgumentNullException(nameof(project), "Project cannot be null.");
}
CheckForDuplicateProducts(project.PimsProducts, project.Id);

// TODO: Verify this is not needed
//CheckForDuplicateProducts(project.PimsProducts, project.Id);

var newProject = _projectRepository.Add(project);
_projectRepository.CommitTransaction();
Expand All @@ -147,15 +149,16 @@ public PimsProject Update(PimsProject project)
project.ThrowIfNull(nameof(project));
_logger.LogInformation($"Updating project with id ${project.Internal_Id}");

CheckForDuplicateProducts(project.PimsProducts, project.Id);
// TODO: Verify this is not needed
//CheckForDuplicateProducts(project.PimsProducts, project.Id);
var updatedProject = _projectRepository.Update(project);
AddNoteIfStatusChanged(project);
_projectRepository.CommitTransaction();

return updatedProject;
}

private void CheckForDuplicateProducts(IEnumerable<PimsProduct> products, long projectId)
/*private void CheckForDuplicateProducts(IEnumerable<PimsProduct> products, long projectId)
{
var duplicateProductsInArray = products.GroupBy(p => (p.Code, p.Description)).Where(g => g.Count() > 1).Select(g => g.Key);
if (duplicateProductsInArray.Any())
Expand All @@ -168,7 +171,7 @@ private void CheckForDuplicateProducts(IEnumerable<PimsProduct> products, long p
{
throw new DuplicateEntityException($"Unable to add project with duplicated product codes: {string.Join(", ", duplicateProducts.Select(dp => dp.Code))}");
}
}
}*/

private async Task<Paged<PimsProject>> GetPageAsync(ProjectFilter filter, IEnumerable<short> userRegions)
{
Expand Down
2 changes: 1 addition & 1 deletion source/backend/dal/Repositories/ProductRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
public IList<PimsProduct> GetByProject(long projectId)
{
return this.Context.PimsProducts.AsNoTracking()
.Where(p => p.ParentProjectId == projectId)
.Where(p => p.PimsProjectProducts.All(x => x.ProjectId == projectId))

Check warning on line 34 in source/backend/dal/Repositories/ProductRepository.cs

View check run for this annotation

Codecov / codecov/patch

source/backend/dal/Repositories/ProductRepository.cs#L34

Added line #L34 was not covered by tests
.Include(p => p.PimsAcquisitionFiles)
.OrderBy(p => p.Code)
.ToArray();
Expand Down
10 changes: 6 additions & 4 deletions source/backend/dal/Repositories/ProjectRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@

return Context.PimsProjects
.AsNoTracking()
.Include(x => x.PimsProducts)
.Include(x => x.PimsProjectProducts)
.ThenInclude(x => x.Product)

Check warning on line 78 in source/backend/dal/Repositories/ProjectRepository.cs

View check run for this annotation

Codecov / codecov/patch

source/backend/dal/Repositories/ProjectRepository.cs#L77-L78

Added lines #L77 - L78 were not covered by tests
.Include(x => x.ProjectStatusTypeCodeNavigation)
.Include(x => x.RegionCodeNavigation)
.Include(x => x.CostTypeCode)
Expand All @@ -93,10 +94,11 @@
{
User.ThrowIfNotAuthorized(Permissions.ProjectAdd);

foreach (var product in project.PimsProducts)
// TODO: Fix this
/*foreach (var product in project.PimsProducts)
{

Check warning on line 99 in source/backend/dal/Repositories/ProjectRepository.cs

View workflow job for this annotation

GitHub Actions / build-backend

Remove this commented out code.

Check warning on line 99 in source/backend/dal/Repositories/ProjectRepository.cs

View workflow job for this annotation

GitHub Actions / Sync Keycloak

Remove this commented out code.
product.ParentProject = project;
}
}*/

Context.PimsProjects.Add(project);
return project;
Expand All @@ -115,7 +117,7 @@
var existingProject = Context.PimsProjects
.FirstOrDefault(x => x.Id == project.Id) ?? throw new KeyNotFoundException();

this.Context.UpdateChild<PimsProject, long, PimsProduct, long>(p => p.PimsProducts, project.Id, project.PimsProducts.ToArray(), true);
this.Context.UpdateGrandchild<PimsProject, long, PimsProjectProduct>(p => p.PimsProjectProducts, pp => pp.Product, project.Id, project.PimsProjectProducts.ToArray(), true);

Check warning on line 120 in source/backend/dal/Repositories/ProjectRepository.cs

View check run for this annotation

Codecov / codecov/patch

source/backend/dal/Repositories/ProjectRepository.cs#L120

Added line #L120 was not covered by tests

Context.Entry(existingProject).CurrentValues.SetValues(project);

Expand Down
13 changes: 13 additions & 0 deletions source/backend/entities/Partials/ProjectProduct.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System.ComponentModel.DataAnnotations.Schema;

namespace Pims.Dal.Entities
{
/// <summary>
/// PimsProjectProduct class, provides an entity for the datamodel to manage projects.
/// </summary>
public partial class PimsProjectProduct : StandardIdentityBaseAppEntity<long>, IBaseAppEntity
{
[NotMapped]
public override long Internal_Id { get => this.ProjectProductId; set => this.ProjectProductId = value; }
}
}
Loading
Loading