Skip to content

Commit

Permalink
Merge branch 'main' into remove-import-id
Browse files Browse the repository at this point in the history
  • Loading branch information
MiraGeowerkstatt authored Dec 12, 2024
2 parents c425cab + f92fd94 commit ac8e154
Show file tree
Hide file tree
Showing 6 changed files with 248 additions and 104 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
- Filtering striae for `not specified` returned wrong results.
- Filtering by `borehole status` did not work.
- When saving with ctrl+s in the borehole sections, the form content was reset.
- When copying a borehole, the nested collections of observations were not copied.
- There was a bug when changing the order, transparency or visibility of custom WMS user layers.
- The borehole status was not translated everywhere in the workflow panel.

Expand Down
1 change: 1 addition & 0 deletions src/api/BdmsContextExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ public static void SeedData(this BdmsContext context)
.RuleFor(o => o.PrecisionLocationY, f => f.PickRandom(Enumerable.Range(0, 10)))
.RuleFor(o => o.PrecisionLocationXLV03, f => f.PickRandom(Enumerable.Range(0, 10)))
.RuleFor(o => o.PrecisionLocationYLV03, f => f.PickRandom(Enumerable.Range(0, 10)))
.RuleFor(o => o.Observations, _ => new Collection<Observation>())
.FinishWith((f, o) => { o.AlternateName = o.OriginalName; });

Borehole SeededBoreholes(int seed) => fakeBoreholes.UseSeed(seed).Generate();
Expand Down
109 changes: 54 additions & 55 deletions src/api/Controllers/BoreholeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,31 +117,6 @@ public async Task<ActionResult<Borehole>> GetByIdAsync(int id)
return Ok(borehole);
}

private IQueryable<Borehole> GetBoreholesWithIncludes()
{
return Context.Boreholes.Include(b => b.Stratigraphies).ThenInclude(s => s.Layers).ThenInclude(l => l.LayerColorCodes)
.Include(b => b.Stratigraphies).ThenInclude(s => s.Layers).ThenInclude(l => l.LayerDebrisCodes)
.Include(b => b.Stratigraphies).ThenInclude(s => s.Layers).ThenInclude(l => l.LayerGrainAngularityCodes)
.Include(b => b.Stratigraphies).ThenInclude(s => s.Layers).ThenInclude(l => l.LayerGrainShapeCodes)
.Include(b => b.Stratigraphies).ThenInclude(s => s.Layers).ThenInclude(l => l.LayerOrganicComponentCodes)
.Include(b => b.Stratigraphies).ThenInclude(s => s.Layers).ThenInclude(l => l.LayerUscs3Codes)
.Include(b => b.Stratigraphies).ThenInclude(s => s.LithologicalDescriptions)
.Include(b => b.Stratigraphies).ThenInclude(s => s.FaciesDescriptions)
.Include(b => b.Stratigraphies).ThenInclude(s => s.ChronostratigraphyLayers)
.Include(b => b.Stratigraphies).ThenInclude(s => s.LithostratigraphyLayers)
.Include(b => b.Completions).ThenInclude(c => c.Casings).ThenInclude(c => c.CasingElements)
.Include(b => b.Completions).ThenInclude(c => c.Instrumentations)
.Include(b => b.Completions).ThenInclude(c => c.Backfills)
.Include(b => b.Sections).ThenInclude(s => s.SectionElements)
.Include(b => b.Observations)
.Include(b => b.BoreholeCodelists)
.Include(b => b.Workflows)
.Include(b => b.BoreholeFiles)
.Include(b => b.BoreholeGeometry)
.Include(b => b.Workgroup)
.Include(b => b.UpdatedBy);
}

/// <summary>
/// Asynchronously copies a <see cref="Borehole"/>.
/// </summary>
Expand Down Expand Up @@ -170,36 +145,7 @@ public async Task<ActionResult<int>> CopyAsync([Required] int id, [Required] int
.SingleOrDefaultAsync(b => b.Id == id)
.ConfigureAwait(false);

if (borehole == null)
{
return NotFound();
}

if (borehole.Observations != null)
{
// Include FieldMeasurementResults and HydrotestResults separately since Entity Framework does not support casting in an Include statement
var fieldMeasurements = borehole.Observations.OfType<FieldMeasurement>().ToList();
#pragma warning disable CS8603
// Cannot include null test for fieldMeasurementResults and hydrotestResults since they are not yet loaded
// if there are no fieldMeasurementResults of hydrotestResults the LoadAsync method will be called but have no effect
foreach (var fieldMeasurement in fieldMeasurements)
{
await Context.Entry(fieldMeasurement)
.Collection(f => f.FieldMeasurementResults)
.LoadAsync()
.ConfigureAwait(false);
}

var hydrotests = borehole.Observations.OfType<Hydrotest>().ToList();
foreach (var hydrotest in hydrotests)
{
await Context.Entry(hydrotest)
.Collection(h => h.HydrotestResults)
.LoadAsync()
.ConfigureAwait(false);
}
#pragma warning restore CS8603
}
if (borehole == null) return NotFound();

// Set ids of copied entities to zero. Entities with an id of zero are added as new entities to the DB.
borehole.Id = 0;
Expand Down Expand Up @@ -293,6 +239,30 @@ await Context.Entry(hydrotest)
hydrotestResult.Id = 0;
}
}

if (hydrotest.HydrotestKindCodes != null)
{
foreach (var hydrotestKindCode in hydrotest.HydrotestKindCodes)
{
hydrotestKindCode.HydrotestId = 0;
}
}

if (hydrotest.HydrotestEvaluationMethodCodes != null)
{
foreach (var hydrotestEvaluationMethodCode in hydrotest.HydrotestEvaluationMethodCodes)
{
hydrotestEvaluationMethodCode.HydrotestId = 0;
}
}

if (hydrotest.HydrotestFlowDirectionCodes != null)
{
foreach (var hydrotestFlowDirectionCode in hydrotest.HydrotestFlowDirectionCodes)
{
hydrotestFlowDirectionCode.HydrotestId = 0;
}
}
}
}

Expand Down Expand Up @@ -327,4 +297,33 @@ await Context.Entry(hydrotest)
if (entity == null) return default;
return await Task.FromResult<int?>(entity.Id).ConfigureAwait(false);
}

private IQueryable<Borehole> GetBoreholesWithIncludes()
{
return Context.Boreholes.Include(b => b.Stratigraphies).ThenInclude(s => s.Layers).ThenInclude(l => l.LayerColorCodes)
.Include(b => b.Stratigraphies).ThenInclude(s => s.Layers).ThenInclude(l => l.LayerDebrisCodes)
.Include(b => b.Stratigraphies).ThenInclude(s => s.Layers).ThenInclude(l => l.LayerGrainAngularityCodes)
.Include(b => b.Stratigraphies).ThenInclude(s => s.Layers).ThenInclude(l => l.LayerGrainShapeCodes)
.Include(b => b.Stratigraphies).ThenInclude(s => s.Layers).ThenInclude(l => l.LayerOrganicComponentCodes)
.Include(b => b.Stratigraphies).ThenInclude(s => s.Layers).ThenInclude(l => l.LayerUscs3Codes)
.Include(b => b.Stratigraphies).ThenInclude(s => s.LithologicalDescriptions)
.Include(b => b.Stratigraphies).ThenInclude(s => s.FaciesDescriptions)
.Include(b => b.Stratigraphies).ThenInclude(s => s.ChronostratigraphyLayers)
.Include(b => b.Stratigraphies).ThenInclude(s => s.LithostratigraphyLayers)
.Include(b => b.Completions).ThenInclude(c => c.Casings).ThenInclude(c => c.CasingElements)
.Include(b => b.Completions).ThenInclude(c => c.Instrumentations)
.Include(b => b.Completions).ThenInclude(c => c.Backfills)
.Include(b => b.Sections).ThenInclude(s => s.SectionElements)
.Include(b => b.Observations).ThenInclude(o => (o as FieldMeasurement)!.FieldMeasurementResults)
.Include(b => b.Observations).ThenInclude(o => (o as Hydrotest)!.HydrotestResults)
.Include(b => b.Observations).ThenInclude(o => (o as Hydrotest)!.HydrotestEvaluationMethodCodes)
.Include(b => b.Observations).ThenInclude(o => (o as Hydrotest)!.HydrotestFlowDirectionCodes)
.Include(b => b.Observations).ThenInclude(o => (o as Hydrotest)!.HydrotestKindCodes)
.Include(b => b.BoreholeCodelists)
.Include(b => b.Workflows)
.Include(b => b.BoreholeFiles)
.Include(b => b.BoreholeGeometry)
.Include(b => b.Workgroup)
.Include(b => b.UpdatedBy);
}
}
2 changes: 1 addition & 1 deletion src/api/Models/Borehole.cs
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ public class Borehole : IChangeTracking, IIdentifyable
/// <summary>
/// Gets the <see cref="Borehole"/>'s observations.
/// </summary>
public ICollection<Observation>? Observations { get; }
public ICollection<Observation>? Observations { get; set; }

/// <summary>
/// Gets the <see cref="Borehole"/>'s workflows.
Expand Down
Loading

0 comments on commit ac8e154

Please sign in to comment.