Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into feature/1952-gap-anal…
Browse files Browse the repository at this point in the history
…yzer-functionality

# Conflicts:
#	Src/WitsmlExplorer.Api/Models/JobType.cs
  • Loading branch information
jaroslavbliznak committed Sep 20, 2023
2 parents c60eaef + bdbad76 commit e0d9ee8
Show file tree
Hide file tree
Showing 18 changed files with 1,751 additions and 11 deletions.
68 changes: 68 additions & 0 deletions Src/WitsmlExplorer.Api/Jobs/MissingDataJob.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
using System.Collections.Generic;
using System.Linq;

using Microsoft.IdentityModel.Tokens;

using WitsmlExplorer.Api.Jobs.Common;
using WitsmlExplorer.Api.Models;

namespace WitsmlExplorer.Api.Jobs
{
public record MissingDataJob : Job
{
public IEnumerable<WellReference> WellReferences { get; init; }
public IEnumerable<WellboreReference> WellboreReferences { get; init; }
public IEnumerable<MissingDataCheck> MissingDataChecks { get; init; }

public override string Description()
{
return $"Missing Data Agent"
+ $" - WellUids: {GetWellUid()};"
+ $" WellboreUids: {string.Join(", ", WellboreReferences.Select(w => w.WellboreUid))}";
}

public override string GetObjectName()
{
return null;
}

public override string GetWellboreName()
{
return WellboreReferences.IsNullOrEmpty() ? null : string.Join(", ", WellboreReferences.Select(w => w.WellboreName));
}

public override string GetWellName()
{
var wellNames = new List<string>();

if (!WellboreReferences.IsNullOrEmpty())
{
wellNames.AddRange(WellboreReferences.Select(w => w.WellName).Distinct());
}

if (!WellReferences.IsNullOrEmpty())
{
wellNames.AddRange(WellReferences.Select(w => w.WellName).Distinct());
}

return string.Join(", ", wellNames.Distinct());
}

private string GetWellUid()
{
var wellUids = new List<string>();

if (!WellboreReferences.IsNullOrEmpty())
{
wellUids.AddRange(WellboreReferences.Select(w => w.WellUid).Distinct());
}

if (!WellReferences.IsNullOrEmpty())
{
wellUids.AddRange(WellReferences.Select(w => w.WellUid).Distinct());
}

return string.Join(", ", wellUids.Distinct());
}
}
}
1 change: 1 addition & 0 deletions Src/WitsmlExplorer.Api/Models/JobType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public enum JobType
ReplaceComponents,
ReplaceObjects,
CheckLogHeader,
MissingData,
AnalyzeGaps
}
}
10 changes: 10 additions & 0 deletions Src/WitsmlExplorer.Api/Models/MissingDataCheck.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System.Collections.Generic;

namespace WitsmlExplorer.Api.Models
{
public class MissingDataCheck
{
public EntityType ObjectType { get; set; }
public IEnumerable<string> Properties { get; set; }
}
}
17 changes: 17 additions & 0 deletions Src/WitsmlExplorer.Api/Models/Reports/MissingDataReport.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

namespace WitsmlExplorer.Api.Models.Reports
{
public class MissingDataReport : BaseReport { }

public class MissingDataReportItem
{
public string ObjectType { get; set; }
public string Property { get; init; }
public string WellUid { get; init; }
public string WellName { get; init; }
public string WellboreUid { get; init; }
public string WellboreName { get; init; }
public string ObjectUid { get; init; }
public string ObjectName { get; init; }
}
}
103 changes: 103 additions & 0 deletions Src/WitsmlExplorer.Api/Query/QueryHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;

using WitsmlExplorer.Api.Extensions;

namespace WitsmlExplorer.Api.Query
{
public static class QueryHelper
{
/// <summary>
/// Adds properties to an object based on a list of property names.
/// </summary>
/// <typeparam name="T">The type of the object.</typeparam>
/// <param name="obj">The object to which properties will be added.</param>
/// <param name="properties">A collection of property names to add, optionally supporting nested properties (e.g., "commonData.sourceName").</param>
/// <returns>The modified object with added properties.</returns>
public static T AddPropertiesToObject<T>(T obj, IEnumerable<string> properties)
{
foreach (string property in properties)
{
obj = AddPropertyToObject(obj, property);
}
return obj;
}

/// <summary>
/// Adds a single property to an object based on its name.
/// </summary>
/// <typeparam name="T">The type of the object.</typeparam>
/// <param name="obj">The object to which the property will be added.</param>
/// <param name="property">The name of the property to add, optionally supporting nested properties (e.g., "commonData.sourceName").</param>
/// <returns>The modified object with the added property.</returns>
public static T AddPropertyToObject<T>(T obj, string property)
{
string childProperty = null;
if (property.Contains('.'))
{
var propertyParts = property.Split(".", 2);
property = propertyParts[0];
childProperty = propertyParts[1];
}

PropertyInfo propertyInfo = obj.GetType().GetProperty(property.CapitalizeFirstLetter());

if (propertyInfo == null || !propertyInfo.CanWrite)
{
throw new ArgumentException($"{property} must be a supported property of a {obj.GetType()}.");
}

object instance = GetOrCreateInstanceOfProperty(obj, propertyInfo);

if (!string.IsNullOrEmpty(childProperty))
{
instance = AddPropertyToObject(instance, childProperty);
}

propertyInfo.SetValue(obj, instance);

return obj;
}

private static object GetOrCreateInstanceOfProperty(object obj, PropertyInfo propertyInfo)
{
Type propertyType = propertyInfo.PropertyType;

object instance = (propertyType == typeof(string)
? ""
: propertyInfo.GetValue(obj, null))
?? (propertyType == typeof(string[])
? new string[] { "" }
: Activator.CreateInstance(propertyType));

if (propertyType.IsGenericType && propertyType.GetGenericTypeDefinition() == typeof(List<>))
{
Type listObjectType = propertyType.GetGenericArguments()[0];
object listObjectInstance = listObjectType == typeof(string)
? ""
: Activator.CreateInstance(listObjectType);
((IList)instance).Add(listObjectInstance);
}

return instance;
}

/// <summary>
/// Retrieves a property from an object based on its name, supporting nested properties.
/// </summary>
/// <param name="obj">The object from which to retrieve the property.</param>
/// <param name="property">The name of the property to retrieve, possibly nested (e.g., "commonData.sourceName").</param>
/// <returns>The value of the specified property.</returns>
public static object GetPropertyFromObject(object obj, string property)
{
var propertyParts = property.Split(".");
foreach (var propertyPart in propertyParts)
{
obj = obj?.GetType().GetProperty(propertyPart.CapitalizeFirstLetter())?.GetValue(obj, null);
}
return obj;
}
}
}
Loading

0 comments on commit e0d9ee8

Please sign in to comment.