Skip to content

Commit

Permalink
FIX-2009 Fix IndexCurve, renaming, constants
Browse files Browse the repository at this point in the history
  • Loading branch information
jaroslavbliznak committed Nov 23, 2023
1 parent ce42f5a commit 62b3250
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 28 deletions.
1 change: 0 additions & 1 deletion Src/Witsml/CommonConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,4 @@ public static class CommonConstants
public const int DefaultNumberOfRoundedPlaces = 3;
public const string DataSeparator = ",";
public const string NewLine = "\n";
public const string DefaultUnit = "unitless";
}
14 changes: 10 additions & 4 deletions Src/WitsmlExplorer.Api/Workers/Modify/ModifyLogCurveInfoWorker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ public ModifyLogCurveInfoWorker(ILogger<ModifyLogCurveInfoJob> logger, IWitsmlCl
}

var originalLogCurveInfoMnemonic = originalLogCurveInfo.Mnemonic;
var isLogCurveInfoMnemonicUpdated = originalLogCurveInfoMnemonic != job.LogCurveInfo.Mnemonic;
if (logHeader.IndexCurve.Value == originalLogCurveInfoMnemonic && isLogCurveInfoMnemonicUpdated)
{
throw new InvalidOperationException($"IndexCurve Mnemonic: {originalLogCurveInfoMnemonic} cannot be modified.");
}

WitsmlLogs modifyLogCurveInfoQuery = GetModifyLogCurveInfoQuery(job, originalLogCurveInfo);
QueryResult modifyLogCurveInfoResult = await client.UpdateInStoreAsync(modifyLogCurveInfoQuery);
if (modifyLogCurveInfoResult.IsSuccessful)
Expand All @@ -66,11 +72,11 @@ public ModifyLogCurveInfoWorker(ILogger<ModifyLogCurveInfoJob> logger, IWitsmlCl
return (new WorkerResult(GetTargetWitsmlClientOrThrow().GetServerHostname(), false, errorMessage, modifyLogCurveInfoResult.Reason), null);
}

if (originalLogCurveInfoMnemonic != job.LogCurveInfo.Mnemonic)
if (isLogCurveInfoMnemonicUpdated)
{
var originalMnemonics = GetMnemonics(logHeader, originalLogCurveInfoMnemonic);
var updatedMnemonics = string.Join(",", GetMnemonics(logHeader, job.LogCurveInfo.Mnemonic));
var updatedUnits = string.Join(",", GetUnits(logHeader, job.LogCurveInfo.Unit));
var updatedMnemonics = string.Join(CommonConstants.DataSeparator, GetMnemonics(logHeader, job.LogCurveInfo.Mnemonic));
var updatedUnits = string.Join(CommonConstants.DataSeparator, GetUnits(logHeader, job.LogCurveInfo.Unit));
WitsmlLog modifyLogData = GetModifyLogDataQuery(job, updatedMnemonics, updatedUnits);

await using LogDataReader logDataReader = new(client, logHeader, originalMnemonics, Logger);
Expand Down Expand Up @@ -172,7 +178,7 @@ private static void Verify(ModifyLogCurveInfoJob job)

private static List<string> GetUnits(WitsmlLog log, string newUnit)
{
var indexCurveUnit = log.LogCurveInfo.FirstOrDefault(x => x.Mnemonic == log.IndexCurve.Value)?.Unit ?? CommonConstants.DefaultUnit;
var indexCurveUnit = log.LogCurveInfo.FirstOrDefault(x => x.Mnemonic == log.IndexCurve.Value)?.Unit;
return new List<string> { indexCurveUnit, newUnit };
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const LogCurveInfoPropertiesModal = (props: LogCurveInfoPropertiesModalProps): R
const { logCurveInfo, dispatchOperation, selectedLog } = props;
const [editableLogCurveInfo, setEditableLogCurveInfo] = useState<LogCurveInfo>(null);
const [isLoading, setIsLoading] = useState<boolean>(false);
const isIndexCurve = logCurveInfo?.mnemonic === selectedLog?.indexCurve;

const onSubmit = async () => {
setIsLoading(true);
Expand Down Expand Up @@ -51,22 +52,39 @@ const LogCurveInfoPropertiesModal = (props: LogCurveInfoPropertiesModalProps): R
error={editableLogCurveInfo.mnemonic.length === 0}
helperText={editableLogCurveInfo.mnemonic.length === 0 ? "A logCurveInfo mnemonic cannot be empty. Size must be 1 to 64 characters." : ""}
fullWidth
disabled={isIndexCurve}
inputProps={{ minLength: 1, maxLength: 64 }}
onChange={(e) => setEditableLogCurveInfo({ ...editableLogCurveInfo, mnemonic: e.target.value })}
onChange={(e) =>
setEditableLogCurveInfo({
...editableLogCurveInfo,
mnemonic: e.target.value
})
}
/>
<TextField
id="unit"
label="unit"
defaultValue={editableLogCurveInfo.unit}
error={editableLogCurveInfo.unit == null || editableLogCurveInfo.unit.length === 0}
helperText={editableLogCurveInfo.unit == null || editableLogCurveInfo.unit.length === 0 ? "A unit cannot be empty." : ""}
onChange={(e) => setEditableLogCurveInfo({ ...editableLogCurveInfo, unit: e.target.value })}
helperText={editableLogCurveInfo.unit == null || editableLogCurveInfo.unit.length === 0 ? "A unit cannot be empty. Size must be 1 to 64 characters." : ""}
inputProps={{ minLength: 1, maxLength: 64 }}
onChange={(e) =>
setEditableLogCurveInfo({
...editableLogCurveInfo,
unit: e.target.value
})
}
/>
<TextField
id="curveDescription"
label="curveDescription"
defaultValue={editableLogCurveInfo.curveDescription}
onChange={(e) => setEditableLogCurveInfo({ ...editableLogCurveInfo, curveDescription: e.target.value })}
onChange={(e) =>
setEditableLogCurveInfo({
...editableLogCurveInfo,
curveDescription: e.target.value
})
}
/>
<TextField disabled id="typeLogData" label="typeLogData" defaultValue={editableLogCurveInfo.typeLogData} fullWidth />
<TextField disabled id="mnemAlias" label="mnemAlias" defaultValue={editableLogCurveInfo.mnemAlias} fullWidth />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ public async void ModifyLogCurveInfoProperties_Execute_ValidResults()
await _worker.Execute(job);

Assert.Single(updatedLogs);
Assert.Equal(expectedMnemonic, updatedLogs.First().Logs.First().LogCurveInfo.First().Mnemonic);
Assert.Equal(expectedUnit, updatedLogs.First().Logs.First().LogCurveInfo.First().Unit);
Assert.Equal(expectedCurveDescription, updatedLogs.First().Logs.First().LogCurveInfo.First().CurveDescription);
Assert.Equal(expectedMnemonic, updatedLogs.FirstOrDefault()?.Logs.FirstOrDefault()?.LogCurveInfo.FirstOrDefault()?.Mnemonic);
Assert.Equal(expectedUnit, updatedLogs.FirstOrDefault()?.Logs.FirstOrDefault()?.LogCurveInfo.FirstOrDefault()?.Unit);
Assert.Equal(expectedCurveDescription, updatedLogs.FirstOrDefault()?.Logs.FirstOrDefault()?.LogCurveInfo.FirstOrDefault()?.CurveDescription);
}

[Fact]
Expand Down Expand Up @@ -129,7 +129,7 @@ public async void RenameMnemonic_Execute_ValidResults()
await _worker.Execute(job);

Assert.Single(updatedLogs);
Assert.Equal(expectedMnemonic, updatedLogs.First().Logs.First().LogCurveInfo.First().Mnemonic);
Assert.Equal(expectedMnemonic, updatedLogs.FirstOrDefault()?.Logs.FirstOrDefault()?.LogCurveInfo.FirstOrDefault()?.Mnemonic);
}

private WitsmlLogs GetTestWitsmlLogs()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@

namespace WitsmlExplorer.IntegrationTests.Api.Workers
{
public class RenameMnemonicWorkerTests
public class ModifyLogCurveInfoWorkerTests
{
private readonly ModifyLogCurveInfoWorker _worker;
private const string WellUid = "";
private const string WellboreUid = "";
private const string LogUid = "";

public RenameMnemonicWorkerTests()
public ModifyLogCurveInfoWorkerTests()
{
IConfiguration configuration = ConfigurationReader.GetConfig();
WitsmlClientProvider witsmlClientProvider = new(configuration);
Expand All @@ -34,10 +34,7 @@ public RenameMnemonicWorkerTests()
[Fact(Skip = "Should only be run manually")]
public async void ValidInputRenameMnemonicShouldReturnSuccess()
{
ModifyLogCurveInfoJob job = CreateJobTemplate() with
{
LogCurveInfo = new LogCurveInfo() { Mnemonic = ""}
};
ModifyLogCurveInfoJob job = CreateJobTemplate() with { LogCurveInfo = new LogCurveInfo() { Mnemonic = "" } };

(WorkerResult result, RefreshAction _) = await _worker.Execute(job);

Expand All @@ -46,15 +43,7 @@ public async void ValidInputRenameMnemonicShouldReturnSuccess()

private static ModifyLogCurveInfoJob CreateJobTemplate()
{
return new ModifyLogCurveInfoJob
{
LogReference = new ObjectReference
{
WellUid = WellUid,
WellboreUid = WellboreUid,
Uid = LogUid
}
};
return new ModifyLogCurveInfoJob { LogReference = new ObjectReference { WellUid = WellUid, WellboreUid = WellboreUid, Uid = LogUid } };
}
}
}

0 comments on commit 62b3250

Please sign in to comment.