Skip to content

Commit

Permalink
Merge pull request #2171 from petrlicman/RemoveDuplicities#2044
Browse files Browse the repository at this point in the history
Remove duplicities #2044
  • Loading branch information
petrlicman authored Dec 4, 2023
2 parents e519cfc + 7b901d7 commit 9fd3008
Show file tree
Hide file tree
Showing 89 changed files with 229 additions and 308 deletions.
4 changes: 2 additions & 2 deletions Src/Witsml/Data/MudLog/WitsmlMudLog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ namespace Witsml.Data.MudLog
{
public class WitsmlMudLog : WitsmlObjectOnWellbore
{
public override WitsmlMudLogs AsSingletonWitsmlList()
public override WitsmlMudLogs AsItemInWitsmlList()
{
return new WitsmlMudLogs()
{
MudLogs = this.AsSingletonList()
MudLogs = this.AsItemInList()
};
}

Expand Down
4 changes: 2 additions & 2 deletions Src/Witsml/Data/Rig/WitsmlRig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ namespace Witsml.Data.Rig
{
public class WitsmlRig : WitsmlObjectOnWellbore
{
public override WitsmlRigs AsSingletonWitsmlList()
public override WitsmlRigs AsItemInWitsmlList()
{
return new WitsmlRigs()
{
Rigs = this.AsSingletonList()
Rigs = this.AsItemInList()
};
}

Expand Down
4 changes: 2 additions & 2 deletions Src/Witsml/Data/Tubular/WitsmlTubular.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ namespace Witsml.Data.Tubular
{
public class WitsmlTubular : WitsmlObjectOnWellbore
{
public override WitsmlTubulars AsSingletonWitsmlList()
public override WitsmlTubulars AsItemInWitsmlList()
{
return new WitsmlTubulars()
{
Tubulars = this.AsSingletonList()
Tubulars = this.AsItemInList()
};
}

Expand Down
4 changes: 2 additions & 2 deletions Src/Witsml/Data/WitsmlBhaRun.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ namespace Witsml.Data
{
public class WitsmlBhaRun : WitsmlObjectOnWellbore
{
public override WitsmlBhaRuns AsSingletonWitsmlList()
public override WitsmlBhaRuns AsItemInWitsmlList()
{
return new WitsmlBhaRuns()
{
BhaRuns = this.AsSingletonList()
BhaRuns = this.AsItemInList()
};
}

Expand Down
2 changes: 1 addition & 1 deletion Src/Witsml/Data/WitsmlChangeLog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public WitsmlChangeLogs AsSingletonWitsmlList()
{
return new WitsmlChangeLogs()
{
ChangeLogs = this.AsSingletonList()
ChangeLogs = this.AsItemInList()
};
}

Expand Down
4 changes: 2 additions & 2 deletions Src/Witsml/Data/WitsmlFluidsReport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ namespace Witsml.Data
{
public class WitsmlFluidsReport : WitsmlObjectOnWellbore
{
public override WitsmlFluidsReports AsSingletonWitsmlList()
public override WitsmlFluidsReports AsItemInWitsmlList()
{
return new WitsmlFluidsReports()
{
FluidsReports = this.AsSingletonList()
FluidsReports = this.AsItemInList()
};
}

Expand Down
4 changes: 2 additions & 2 deletions Src/Witsml/Data/WitsmlFormationMarker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ namespace Witsml.Data
{
public class WitsmlFormationMarker : WitsmlObjectOnWellbore
{
public override WitsmlFormationMarkers AsSingletonWitsmlList()
public override WitsmlFormationMarkers AsItemInWitsmlList()
{
return new WitsmlFormationMarkers()
{
FormationMarkers = this.AsSingletonList()
FormationMarkers = this.AsItemInList()
};
}

Expand Down
4 changes: 2 additions & 2 deletions Src/Witsml/Data/WitsmlLog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ namespace Witsml.Data
{
public class WitsmlLog : WitsmlObjectOnWellbore
{
public override WitsmlLogs AsSingletonWitsmlList()
public override WitsmlLogs AsItemInWitsmlList()
{
return new WitsmlLogs()
{
Logs = this.AsSingletonList()
Logs = this.AsItemInList()
};
}

Expand Down
4 changes: 2 additions & 2 deletions Src/Witsml/Data/WitsmlMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ namespace Witsml.Data
[XmlRoot]
public class WitsmlMessage : WitsmlObjectOnWellbore
{
public override WitsmlMessages AsSingletonWitsmlList()
public override WitsmlMessages AsItemInWitsmlList()
{
return new WitsmlMessages()
{
Messages = this.AsSingletonList()
Messages = this.AsItemInList()
};
}

Expand Down
2 changes: 1 addition & 1 deletion Src/Witsml/Data/WitsmlObjectOnWellbore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Witsml.Data
{
public abstract class WitsmlObjectOnWellbore
{
public abstract IWitsmlQueryType AsSingletonWitsmlList();
public abstract IWitsmlQueryType AsItemInWitsmlList();

[XmlAttribute("uidWell")]
public string UidWell { get; set; }
Expand Down
4 changes: 2 additions & 2 deletions Src/Witsml/Data/WitsmlRisk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ namespace Witsml.Data
{
public class WitsmlRisk : WitsmlObjectOnWellbore
{
public override WitsmlRisks AsSingletonWitsmlList()
public override WitsmlRisks AsItemInWitsmlList()
{
return new WitsmlRisks()
{
Risks = this.AsSingletonList()
Risks = this.AsItemInList()
};
}
[XmlElement("objectReference")]
Expand Down
4 changes: 2 additions & 2 deletions Src/Witsml/Data/WitsmlTrajectory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ namespace Witsml.Data
{
public class WitsmlTrajectory : WitsmlObjectOnWellbore
{
public override WitsmlTrajectories AsSingletonWitsmlList()
public override WitsmlTrajectories AsItemInWitsmlList()
{
return new WitsmlTrajectories()
{
Trajectories = this.AsSingletonList()
Trajectories = this.AsItemInList()
};
}

Expand Down
4 changes: 2 additions & 2 deletions Src/Witsml/Data/WitsmlWbGeometry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ namespace Witsml.Data
{
public class WitsmlWbGeometry : WitsmlObjectOnWellbore
{
public override WitsmlWbGeometrys AsSingletonWitsmlList()
public override WitsmlWbGeometrys AsItemInWitsmlList()
{
return new WitsmlWbGeometrys()
{
WbGeometrys = this.AsSingletonList()
WbGeometrys = this.AsItemInList()
};
}

Expand Down
2 changes: 1 addition & 1 deletion Src/Witsml/Extensions/ListExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace Witsml.Extensions
{
public static class ListExtensions
{
public static List<T> AsSingletonList<T>(this T item)
public static List<T> AsItemInList<T>(this T item)
{
return new List<T> { item };
}
Expand Down
6 changes: 4 additions & 2 deletions Src/WitsmlExplorer.Api/Configuration/Dependencies.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ namespace WitsmlExplorer.Api.Configuration
{
public static class Dependencies
{
private const string MissingDatabaseConfigMessage = "Did not detect any configuration for database";

public static void ConfigureDependencies(this IServiceCollection services, IConfiguration configuration)
{
services.RegisterAssemblyPublicNonGenericClasses(Assembly.GetAssembly(typeof(Program)))
Expand Down Expand Up @@ -55,8 +57,8 @@ private static void AddRepository<TDocument, T>(IServiceCollection services, ICo
}
else
{
Log.Error("Did not detect any configuration for database");
return;
Log.Error(MissingDatabaseConfigMessage);
throw new ApplicationException(MissingDatabaseConfigMessage);
}

}
Expand Down
2 changes: 1 addition & 1 deletion Src/WitsmlExplorer.Api/Configuration/ServerCredentials.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public ServerCredentials(string host, ICredentials creds)

public bool Equals(ServerCredentials other)
{
return (Host.EqualsIgnoreCase(other.Host)) &&
return (other != null && Host.EqualsIgnoreCase(other.Host)) &&
(UserId == other.UserId) &&
(Password == other.Password);
}
Expand Down
55 changes: 13 additions & 42 deletions Src/WitsmlExplorer.Api/Extensions/WebApplicationExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,88 +6,59 @@

namespace WitsmlExplorer.Api.Extensions
{

public static class WebApplicationExtensions
{
private static readonly string ApiPath = "/api";
public static void MapGet(this IEndpointRouteBuilder endpoints, string pattern, Delegate handler, bool useOAuth2)
{
var routeHandlerBuilder = endpoints.MapGet(ApiPath + pattern, handler);
if (useOAuth2)
{
endpoints.MapGet(ApiPath + pattern, handler).RequireAuthorization();
}
else
{
endpoints.MapGet(ApiPath + pattern, handler);
routeHandlerBuilder.RequireAuthorization();
}
}

public static void MapGet(this IEndpointRouteBuilder endpoints, string pattern, Delegate handler, bool useOAuth2, params string[] policyNames)
{
var routeHandlerBuilder = endpoints.MapGet(ApiPath + pattern, handler);
if (useOAuth2)
{
endpoints.MapGet(ApiPath + pattern, handler).RequireAuthorization(policyNames);
}
else
{
endpoints.MapGet(ApiPath + pattern, handler);
}
}
public static void MapPost(this IEndpointRouteBuilder endpoints, string pattern, Delegate handler, bool useOAuth2)
{
if (useOAuth2)
{
endpoints.MapPost(ApiPath + pattern, handler).RequireAuthorization();
}
else
{
endpoints.MapPost(ApiPath + pattern, handler);
routeHandlerBuilder.RequireAuthorization(policyNames);
}
}

public static void MapPost(this IEndpointRouteBuilder endpoints, string pattern, Delegate handler, bool useOAuth2, params string[] policyNames)
{
var routeHandlerBuilder = endpoints.MapPost(ApiPath + pattern, handler);
if (useOAuth2)
{
endpoints.MapPost(ApiPath + pattern, handler).RequireAuthorization(policyNames);
}
else
{
endpoints.MapPost(ApiPath + pattern, handler);
routeHandlerBuilder.RequireAuthorization(policyNames);
}
}
public static void MapDelete(this IEndpointRouteBuilder endpoints, string pattern, Delegate handler, bool useOAuth2, params string[] policyNames)
{
var routeHandlerBuilder = endpoints.MapDelete(ApiPath + pattern, handler);
if (useOAuth2)
{
endpoints.MapDelete(ApiPath + pattern, handler).RequireAuthorization(policyNames);
}
else
{
endpoints.MapDelete(ApiPath + pattern, handler);
routeHandlerBuilder.RequireAuthorization(policyNames);
}
}

public static void MapPatch(this IEndpointRouteBuilder endpoints, string pattern, Delegate handler, bool useOAuth2, params string[] policyNames)
{
var routeHandlerBuilder = endpoints.MapPatch(ApiPath + pattern, handler);
if (useOAuth2)
{
endpoints.MapPatch(ApiPath + pattern, handler).RequireAuthorization(policyNames);
}
else
{
endpoints.MapPatch(ApiPath + pattern, handler);
routeHandlerBuilder.RequireAuthorization(policyNames);
}
}

public static void MapHub<T>(this IEndpointRouteBuilder endpoints, string pattern, bool useOAuth2, params string[] policyNames) where T : Hub
{
var routeHandlerBuilder = endpoints.MapHub<T>(pattern);
if (useOAuth2)
{
endpoints.MapHub<T>(pattern).RequireAuthorization(policyNames);
}
else
{
endpoints.MapHub<T>(pattern);
routeHandlerBuilder.RequireAuthorization(policyNames);
}
}
}
Expand Down
10 changes: 2 additions & 8 deletions Src/WitsmlExplorer.Api/Jobs/DeleteEmptyMnemonicsJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,11 @@ namespace WitsmlExplorer.Api.Jobs
public record DeleteEmptyMnemonicsJob : Job
{

public ICollection<WellReference> Wells { get; init; }
public ICollection<WellboreReference> Wellbores { get; init; }
public ICollection<WellReference> Wells { get; init; } = new List<WellReference>();
public ICollection<WellboreReference> Wellbores { get; init; } = new List<WellboreReference>();
public double NullDepthValue { get; init; }
public DateTime NullTimeValue { get; init; }

public DeleteEmptyMnemonicsJob()
{
Wells = new List<WellReference>();
Wellbores = new List<WellboreReference>();
}

public override string Description()
{
return "DeleteEmptyMnemonicsJob"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Net;

namespace WitsmlExplorer.Api.Middleware
{
Expand All @@ -8,7 +9,7 @@ public class WitsmlUnsupportedCapabilityException : Exception

public WitsmlUnsupportedCapabilityException(string message) : base(message)
{
StatusCode = 500;
StatusCode = (int)HttpStatusCode.InternalServerError;
}
}
}
2 changes: 1 addition & 1 deletion Src/WitsmlExplorer.Api/Models/BhaRun.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public override WitsmlBhaRuns ToWitsml()
DTimStartDrilling = StringHelpers.ToUniversalDateTimeString(DTimStartDrilling),
DTimStopDrilling = StringHelpers.ToUniversalDateTimeString(DTimStopDrilling),
CommonData = CommonData?.ToWitsml()
}.AsSingletonWitsmlList();
}.AsItemInWitsmlList();
}
}
}
2 changes: 1 addition & 1 deletion Src/WitsmlExplorer.Api/Models/FluidsReport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public override WitsmlFluidsReports ToWitsml()
NumReport = NumReport,
Fluids = Fluids?.Select(fluid => fluid?.ToWitsml())?.ToList(),
CommonData = CommonData?.ToWitsml()
}.AsSingletonWitsmlList();
}.AsItemInWitsmlList();
}
}
}
2 changes: 1 addition & 1 deletion Src/WitsmlExplorer.Api/Models/FormationMarker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public override WitsmlFormationMarkers ToWitsml()
Chronostratigraphic = Chronostratigraphic?.ToWitsmlChronostratigraphyStruct(),
Description = Description,
CommonData = CommonData?.ToWitsml()
}.AsSingletonWitsmlList();
}.AsItemInWitsmlList();
}
}
}
4 changes: 2 additions & 2 deletions Src/WitsmlExplorer.Api/Models/LogObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public override WitsmlLogs ToWitsml()
UidWellbore = WellboreUid,
NameWellbore = WellboreName,
IndexType = IndexType,
ObjectGrowing = StringHelpers.OptionalBooleanToString(ObjectGrowing),
ObjectGrowing = StringHelpers.NullableBooleanToString(ObjectGrowing),
ServiceCompany = ServiceCompany,
RunNumber = RunNumber,
IndexCurve = IndexCurve != null ? new WitsmlIndexCurve { Value = IndexCurve } : null,
Expand All @@ -52,7 +52,7 @@ public override WitsmlLogs ToWitsml()
log.EndDateTimeIndex = EndIndex;
}

return log.AsSingletonWitsmlList();
return log.AsItemInWitsmlList();
}
}
}
Loading

0 comments on commit 9fd3008

Please sign in to comment.