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

Global log curve priority #2544

Merged
merged 23 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from 16 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
26 changes: 20 additions & 6 deletions Src/WitsmlExplorer.Api/HttpHandlers/LogCurvePriorityHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,31 @@ namespace WitsmlExplorer.Api.HttpHandlers
{
public static class LogCurvePriorityHandler
{
[Produces(typeof(List<string>))]
public static async Task<IResult> GetPrioritizedCurves(string wellUid, string wellboreUid, ILogCurvePriorityService logCurvePriorityService)
[Produces(typeof(string[]))]
public static async Task<IResult> GetPrioritizedLocalCurves(string wellUid, string wellboreUid, ILogCurvePriorityService logCurvePriorityService)
{
var prioritizedCurves = await logCurvePriorityService.GetPrioritizedLocalCurves(wellUid, wellboreUid) ?? new List<string>();
return TypedResults.Ok(prioritizedCurves);
}

[Produces(typeof(string[]))]
public static async Task<IResult> GetPrioritizedUniversalCurves(ILogCurvePriorityService logCurvePriorityService)
{
var prioritizedCurves = await logCurvePriorityService.GetPrioritizedCurves(wellUid, wellboreUid) ?? new List<string>();
var prioritizedCurves = await logCurvePriorityService.GetPrioritizedUniversalCurves() ?? new List<string>();
return TypedResults.Ok(prioritizedCurves);
}

[Produces(typeof(IList<string>))]
public static async Task<IResult> SetPrioritizedCurves(string wellUid, string wellboreUid, IList<string> prioritizedCurves, ILogCurvePriorityService logCurvePriorityService)
[Produces(typeof(List<string>))]
public static async Task<IResult> SetPrioritizedLocalCurves(string wellUid, string wellboreUid, IList<string> prioritizedCurves, ILogCurvePriorityService logCurvePriorityService)
{
var createdPrioritizedCurves = await logCurvePriorityService.SetPrioritizedLocalCurves(wellUid, wellboreUid, prioritizedCurves) ?? new List<string>();
return TypedResults.Ok(createdPrioritizedCurves);
}

[Produces(typeof(List<string>))]
public static async Task<IResult> SetPrioritizedGlobalUniversalCurves(List<string> prioritizedCurves, ILogCurvePriorityService logCurvePriorityService)
eliasbruvik marked this conversation as resolved.
Show resolved Hide resolved
{
var createdPrioritizedCurves = await logCurvePriorityService.SetPrioritizedCurves(wellUid, wellboreUid, prioritizedCurves) ?? new List<string>();
var createdPrioritizedCurves = await logCurvePriorityService.SetPrioritizedUniversalCurves(prioritizedCurves) ?? new List<string>();
return TypedResults.Ok(createdPrioritizedCurves);
}
}
Expand Down
6 changes: 4 additions & 2 deletions Src/WitsmlExplorer.Api/Routes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@ public static void ConfigureApi(this WebApplication app, IConfiguration configur
app.MapGet("/wells/{wellUid}/wellbores/{wellboreUid}/idonly/{objectType}/{objectUid}", ObjectHandler.GetObjectIdOnly, useOAuth2);
app.MapGet("/wells/{wellUid}/wellbores/{wellboreUid}/countexpandable", ObjectHandler.GetExpandableObjectsCount, useOAuth2);

app.MapGet("/wells/{wellUid}/wellbores/{wellboreUid}/logCurvePriority", LogCurvePriorityHandler.GetPrioritizedCurves, useOAuth2);
app.MapPost("/wells/{wellUid}/wellbores/{wellboreUid}/logCurvePriority", LogCurvePriorityHandler.SetPrioritizedCurves, useOAuth2);
app.MapGet("/wells/{wellUid}/wellbores/{wellboreUid}/logCurvePriority", LogCurvePriorityHandler.GetPrioritizedLocalCurves, useOAuth2);
app.MapGet("/universal/getLogCurvePriority", LogCurvePriorityHandler.GetPrioritizedUniversalCurves, useOAuth2);
app.MapPost("/universal/logCurvePriority", LogCurvePriorityHandler.SetPrioritizedGlobalUniversalCurves, useOAuth2);
app.MapPost("/wells/{wellUid}/wellbores/{wellboreUid}/logCurvePriority", LogCurvePriorityHandler.SetPrioritizedLocalCurves, useOAuth2);

Dictionary<EntityType, string> types = EntityTypeHelper.ToPluralLowercase();
Dictionary<EntityType, string> routes = types.ToDictionary(entry => entry.Key, entry => "/wells/{wellUid}/wellbores/{wellboreUid}/" + entry.Value);
Expand Down
81 changes: 58 additions & 23 deletions Src/WitsmlExplorer.Api/Services/LogCurvePriorityService.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

using Microsoft.IdentityModel.Tokens;
Expand All @@ -13,70 +10,85 @@ namespace WitsmlExplorer.Api.Services
{
public interface ILogCurvePriorityService
{
Task<IList<string>> GetPrioritizedCurves(string wellUid, string wellboreUid);
Task<IList<string>> SetPrioritizedCurves(string wellUid, string wellboreUid, IList<string> prioritizedCurves);
Task<IList<string>> GetPrioritizedLocalCurves(string wellUid, string wellboreUid);
Task<IList<string>> SetPrioritizedLocalCurves(string wellUid, string wellboreUid, IList<string> prioritizedCurves);
Task<IList<string>> SetPrioritizedUniversalCurves(List<string> prioritizedCurves);
Task<IList<string>> GetPrioritizedUniversalCurves();
}

public class LogCurvePriorityService : ILogCurvePriorityService
public class LogCurvePriorityService(
IDocumentRepository<LogCurvePriority, string>
logCurvePriorityRepository)
: ILogCurvePriorityService
{
private readonly IDocumentRepository<LogCurvePriority, string> logCurvePriorityRepository;

public LogCurvePriorityService(IDocumentRepository<LogCurvePriority, string> logCurvePriorityRepository)
{
this.logCurvePriorityRepository = logCurvePriorityRepository;
}

public async Task<IList<string>> GetPrioritizedCurves(string wellUid, string wellboreUid)
private const string Global = "global";
eliasbruvik marked this conversation as resolved.
Show resolved Hide resolved
public async Task<IList<string>> GetPrioritizedLocalCurves(string wellUid, string wellboreUid)
{
string logCurvePriorityId = GetLogCurvePriorityId(wellUid, wellboreUid);
LogCurvePriority logCurvePriority = await logCurvePriorityRepository.GetDocumentAsync(logCurvePriorityId);
return logCurvePriority?.PrioritizedCurves;
}

public async Task<IList<string>> SetPrioritizedCurves(string wellUid, string wellboreUid, IList<string> prioritizedCurves)
public async Task<IList<string>> SetPrioritizedLocalCurves(string wellUid, string wellboreUid, IList<string> prioritizedCurves)
{
if (prioritizedCurves.IsNullOrEmpty())
{
await DeleteLogCurvePriorityObject(wellUid, wellboreUid);
return null;
}

IList<string> currentPrioritizedCurves = await GetPrioritizedCurves(wellUid, wellboreUid);
if (currentPrioritizedCurves == null)
string logCurvePriorityId = GetLogCurvePriorityId(wellUid, wellboreUid);
LogCurvePriority logCurvePriority = await logCurvePriorityRepository.GetDocumentAsync(logCurvePriorityId);
if (logCurvePriority == null)
{
return await CreatePrioritizedCurves(wellUid, wellboreUid, prioritizedCurves);
}

string logCurvePriorityId = GetLogCurvePriorityId(wellUid, wellboreUid);
LogCurvePriority logCurvePriorityToUpdate = CreateLogCurvePriorityObject(wellUid, wellboreUid, prioritizedCurves);
LogCurvePriority logCurvePriorityToUpdate = CreateLogCurvePriorityLocalObject(wellUid, wellboreUid, prioritizedCurves);
LogCurvePriority updatedLogCurvePriority = await logCurvePriorityRepository.UpdateDocumentAsync(logCurvePriorityId, logCurvePriorityToUpdate);
return updatedLogCurvePriority.PrioritizedCurves;
}

public async Task<IList<string>> GetPrioritizedUniversalCurves()
{
LogCurvePriority logCurvePriorityGlobal = await logCurvePriorityRepository.GetDocumentAsync(Global);
return logCurvePriorityGlobal?.PrioritizedCurves;
}

public async Task<IList<string>> SetPrioritizedUniversalCurves(List<string> prioritizedCurves)
{
var globalDocument = await logCurvePriorityRepository.GetDocumentAsync(Global);
if (globalDocument == null)
{
return await CreatePrioritizedUniversalCurves(prioritizedCurves);
}
return await UpdatePrioritizedUniversalCurves(prioritizedCurves);
}


private async Task<IList<string>> CreatePrioritizedCurves(string wellUid, string wellboreUid, IList<string> prioritizedCurves)
{
LogCurvePriority logCurvePriorityToCreate = CreateLogCurvePriorityObject(wellUid, wellboreUid, prioritizedCurves);
LogCurvePriority logCurvePriorityToCreate = CreateLogCurvePriorityLocalObject(wellUid, wellboreUid, prioritizedCurves);
LogCurvePriority inserted = await logCurvePriorityRepository.CreateDocumentAsync(logCurvePriorityToCreate);
return inserted.PrioritizedCurves;
}

private async Task DeleteLogCurvePriorityObject(string wellUid, string wellboreUid)
{
IList<string> currentPrioritizedCurves = await GetPrioritizedCurves(wellUid, wellboreUid);
IList<string> currentPrioritizedCurves = await GetPrioritizedLocalCurves(wellUid, wellboreUid);
if (currentPrioritizedCurves != null)
{
string logCurvePriorityId = GetLogCurvePriorityId(wellUid, wellboreUid);
await logCurvePriorityRepository.DeleteDocumentAsync(logCurvePriorityId);
}
return;
}

private string GetLogCurvePriorityId(string wellUid, string wellboreUid)
{
return $"{wellUid}-{wellboreUid}";
}

private LogCurvePriority CreateLogCurvePriorityObject(string wellUid, string wellboreUid, IList<string> prioritizedCurves)
private LogCurvePriority CreateLogCurvePriorityLocalObject(string wellUid, string wellboreUid, IList<string> prioritizedCurves)
{
string logCurvePriorityId = GetLogCurvePriorityId(wellUid, wellboreUid);
LogCurvePriority logCurvePriorityObject = new(logCurvePriorityId)
Expand All @@ -85,5 +97,28 @@ private LogCurvePriority CreateLogCurvePriorityObject(string wellUid, string wel
};
return logCurvePriorityObject;
}

private async Task<IList<string>> CreatePrioritizedUniversalCurves(List<string> logCurvePriorities)
{
LogCurvePriority logCurvePriorityToCreate = CreateLogCurveUniversalPriorityObject(logCurvePriorities);
LogCurvePriority inserted = await logCurvePriorityRepository.CreateDocumentAsync(logCurvePriorityToCreate);
return inserted.PrioritizedCurves;
}

private async Task<IList<string>> UpdatePrioritizedUniversalCurves(List<string> logCurvePriorities)
{
LogCurvePriority logCurvePriorityToCreate = CreateLogCurveUniversalPriorityObject(logCurvePriorities);
LogCurvePriority updated = await logCurvePriorityRepository.UpdateDocumentAsync(Global, logCurvePriorityToCreate);
return updated.PrioritizedCurves;
}

private LogCurvePriority CreateLogCurveUniversalPriorityObject(List<string> prioritizedCurves)
{
LogCurvePriority logCurvePriorityObject = new(Global)
{
PrioritizedCurves = prioritizedCurves
};
return logCurvePriorityObject;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,19 @@ export default function LogCurveInfoListView() {
const [hideEmptyMnemonics, setHideEmptyMnemonics] = useState<boolean>(false);
const [showOnlyPrioritizedCurves, setShowOnlyPrioritizedCurves] =
useState<boolean>(false);
const [prioritizedCurves, setPrioritizedCurves] = useState<string[]>([]);
const [prioritizedLocalCurves, setPrioritizedLocalCurves] = useState<
string[]
>([]);
const [prioritizedUniversalCurves, setPrioritizedUniversalCurves] = useState<
string[]
>([]);
const logObjects = new Map<string, LogObject>([[objectUid, logObject]]);
const isDepthIndex = logType === RouterLogType.DEPTH;
const isFetching = isFetchingLog || isFetchingLogCurveInfo;
const allPrioritizedCurves = [
...prioritizedLocalCurves,
...prioritizedUniversalCurves
].filter((value, index, self) => self.indexOf(value) === index);

useExpandSidebarNodes(
wellUid,
Expand All @@ -76,16 +85,24 @@ export default function LogCurveInfoListView() {

useEffect(() => {
if (logObject) {
const getLogCurvePriority = async () => {
const getLogCurveLocalPriority = async () => {
const prioritizedCurves =
await LogCurvePriorityService.getPrioritizedCurves(
false,
wellUid,
wellboreUid
);
setPrioritizedCurves(prioritizedCurves);
setPrioritizedLocalCurves(prioritizedCurves);
};

getLogCurvePriority().catch(truncateAbortHandler);
const getLogCurveUniversalPriority = async () => {
const prioritizedCurves =
await LogCurvePriorityService.getPrioritizedCurves(true);
setPrioritizedUniversalCurves(prioritizedCurves);
};

getLogCurveLocalPriority().catch(truncateAbortHandler);
getLogCurveUniversalPriority().catch(truncateAbortHandler);
setShowOnlyPrioritizedCurves(false);
}
}, [logObject]);
Expand All @@ -101,8 +118,10 @@ export default function LogCurveInfoListView() {
selectedLog: logObject,
selectedServer: connectedServer,
servers,
prioritizedCurves,
setPrioritizedCurves
prioritizedLocalCurves,
setPrioritizedLocalCurves,
prioritizedUniversalCurves,
setPrioritizedUniversalCurves
};
const position = getContextMenuPosition(event);
dispatchOperation({
Expand Down Expand Up @@ -130,7 +149,9 @@ export default function LogCurveInfoListView() {
<CommonPanelContainer key="showPriority">
<Switch
checked={showOnlyPrioritizedCurves}
disabled={prioritizedCurves.length === 0 && !showOnlyPrioritizedCurves}
disabled={
allPrioritizedCurves.length === 0 && !showOnlyPrioritizedCurves
}
onChange={() =>
setShowOnlyPrioritizedCurves(!showOnlyPrioritizedCurves)
}
Expand All @@ -154,7 +175,7 @@ export default function LogCurveInfoListView() {
columns={getColumns(
isDepthIndex,
showOnlyPrioritizedCurves,
prioritizedCurves,
allPrioritizedCurves,
logObjects,
hideEmptyMnemonics,
true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,16 @@ export default function MultiLogsCurveInfoListView() {
const [hideEmptyMnemonics, setHideEmptyMnemonics] = useState<boolean>(false);
const [showOnlyPrioritizedCurves, setShowOnlyPrioritizedCurves] =
useState<boolean>(false);
const [prioritizedCurves, setPrioritizedCurves] = useState<string[]>([]);
const [prioritizedLocalCurves, setPrioritizedLocalCurves] = useState<
string[]
>([]);
const [prioritizedUniversalCurves, setPrioritizedUniversalCurves] = useState<
string[]
>([]);
const allPrioritizedCurves = [
...prioritizedLocalCurves,
...prioritizedUniversalCurves
].filter((value, index, self) => self.indexOf(value) === index);
const { objects: allLogs, isFetching: isFetchingLogs } = useGetObjects(
connectedServer,
wellUid,
Expand Down Expand Up @@ -87,16 +96,24 @@ export default function MultiLogsCurveInfoListView() {
};
getMnemonics();

const getLogCurvePriority = async () => {
const getLogCurveLocalPriority = async () => {
const prioritizedCurves =
await LogCurvePriorityService.getPrioritizedCurves(
false,
wellUid,
wellboreUid
);
setPrioritizedCurves(prioritizedCurves);
setPrioritizedLocalCurves(prioritizedCurves);
};

getLogCurvePriority().catch(truncateAbortHandler);
const getLogCurveUniversalPriority = async () => {
const prioritizedCurves =
await LogCurvePriorityService.getPrioritizedCurves(true);
setPrioritizedUniversalCurves(prioritizedCurves);
};

getLogCurveLocalPriority().catch(truncateAbortHandler);
getLogCurveUniversalPriority().catch(truncateAbortHandler);
setShowOnlyPrioritizedCurves(false);
}
}, [allLogs]);
Expand All @@ -114,8 +131,10 @@ export default function MultiLogsCurveInfoListView() {
selectedLog: selectedLog,
selectedServer: connectedServer,
servers,
prioritizedCurves,
setPrioritizedCurves,
prioritizedLocalCurves,
setPrioritizedLocalCurves,
prioritizedUniversalCurves,
setPrioritizedUniversalCurves,
isMultiLog
};
const position = getContextMenuPosition(event);
Expand All @@ -140,7 +159,9 @@ export default function MultiLogsCurveInfoListView() {
<CommonPanelContainer key="showPriority">
<Switch
checked={showOnlyPrioritizedCurves}
disabled={prioritizedCurves.length === 0 && !showOnlyPrioritizedCurves}
disabled={
allPrioritizedCurves.length === 0 && !showOnlyPrioritizedCurves
}
onChange={() =>
setShowOnlyPrioritizedCurves(!showOnlyPrioritizedCurves)
}
Expand All @@ -164,7 +185,7 @@ export default function MultiLogsCurveInfoListView() {
columns={getColumns(
isDepthIndex,
showOnlyPrioritizedCurves,
prioritizedCurves,
allPrioritizedCurves,
logObjects,
hideEmptyMnemonics
)}
Expand Down
Loading