Skip to content

Commit

Permalink
Merge pull request #1986 from jaroslavbliznak/FIX-457-Create-trajecto…
Browse files Browse the repository at this point in the history
…ries

FIX-457 Create trajectory
  • Loading branch information
janburak committed Aug 3, 2023
2 parents 24483e5 + 5523da6 commit d4a90fc
Show file tree
Hide file tree
Showing 10 changed files with 512 additions and 10 deletions.
50 changes: 50 additions & 0 deletions Src/WitsmlExplorer.Api/Jobs/CreateTrajectoryJob.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using WitsmlExplorer.Api.Models;

namespace WitsmlExplorer.Api.Jobs;

/// <summary>
/// Job for create trajectory with jobInfo.
/// </summary>
public record CreateTrajectoryJob : Job
{
/// <summary>
/// Trajectory API model.
/// </summary>
public Trajectory Trajectory { get; init; }

/// <summary>
/// Getting description of created trajectory.
/// </summary>
/// <returns>String of job info which provide Trajectory Uid and Name, WellUid, WellboreUid.</returns>
public override string Description()
{
return $"Create Trajectory - Uid: {Trajectory.Uid}; Name: {Trajectory.Name}; WellUid: {Trajectory.WellUid}; WellboreUid: {Trajectory.WellboreUid};";
}

/// <summary>
/// Getting name of trajectory.
/// </summary>
/// <returns>String of trajectory name.</returns>
public override string GetObjectName()
{
return Trajectory.Name;
}

/// <summary>
/// Getting name of wellbore.
/// </summary>
/// <returns>String of wellbore name.</returns>
public override string GetWellboreName()
{
return Trajectory.WellboreName;
}

/// <summary>
/// Getting name of well.
/// </summary>
/// <returns>String of well name.</returns>
public override string GetWellName()
{
return Trajectory.WellName;
}
}
1 change: 1 addition & 0 deletions Src/WitsmlExplorer.Api/Models/JobType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public enum JobType
CreateRisk,
CreateMudLog,
CreateRig,
CreateTrajectory,
CreateWbGeometry,
BatchModifyWell,
ImportLogData,
Expand Down
18 changes: 9 additions & 9 deletions Src/WitsmlExplorer.Api/Models/Trajectory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ namespace WitsmlExplorer.Api.Models
{
public class Trajectory : ObjectOnWellbore
{
public decimal? MdMin { get; internal init; }
public decimal? MdMax { get; internal init; }
public string AziRef { get; internal init; }
public string DTimTrajStart { get; internal init; }
public string DTimTrajEnd { get; internal init; }
public List<TrajectoryStation> TrajectoryStations { get; internal init; }
public string ServiceCompany { get; internal init; }
public string DateTimeCreation { get; internal init; }
public string DateTimeLastChange { get; internal init; }
public decimal? MdMin { get; init; }
public decimal? MdMax { get; init; }
public string AziRef { get; init; }
public string DTimTrajStart { get; init; }
public string DTimTrajEnd { get; init; }
public List<TrajectoryStation> TrajectoryStations { get; init; }
public string ServiceCompany { get; init; }
public string DateTimeCreation { get; init; }
public string DateTimeLastChange { get; init; }
}
}
28 changes: 28 additions & 0 deletions Src/WitsmlExplorer.Api/Query/TrajectoryQueries.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,34 @@ public static WitsmlTrajectories DeleteTrajectoryStations(string wellUid, string
}.AsSingletonList()
};
}

/// <summary>
/// Create trajectories witsml model.
/// </summary>
/// <param name="trajectory">API model of trajectory data.</param>
/// <returns>New instance of WitsmlTrajectories model with added trajectory data.</returns>
public static WitsmlTrajectories CreateTrajectory(Trajectory trajectory)
{
return new()
{
Trajectories = new WitsmlTrajectory
{
UidWell = trajectory.WellUid,
NameWell = trajectory.WellName,
NameWellbore = trajectory.WellboreName,
Uid = trajectory.Uid,
Name = trajectory.Name,
UidWellbore = trajectory.WellboreUid,
MdMin = trajectory.MdMin != null ? new WitsmlMeasuredDepthCoord() { Value = trajectory.MdMin.Value.ToString(CultureInfo.InvariantCulture) } : null,
MdMax = trajectory.MdMax != null ? new WitsmlMeasuredDepthCoord() { Value = trajectory.MdMax.Value.ToString(CultureInfo.InvariantCulture) } : null,
AziRef = trajectory.AziRef.NullIfEmpty(),
ServiceCompany = trajectory.ServiceCompany.NullIfEmpty(),
DTimTrajStart = StringHelpers.ToUniversalDateTimeString(trajectory.DTimTrajStart),
DTimTrajEnd = StringHelpers.ToUniversalDateTimeString(trajectory.DTimTrajEnd),
}.AsSingletonList()
};
}

public static WitsmlTrajectories UpdateTrajectoryStation(TrajectoryStation trajectoryStation, ObjectReference trajectoryReference)
{
WitsmlTrajectoryStation ts = new()
Expand Down
63 changes: 63 additions & 0 deletions Src/WitsmlExplorer.Api/Workers/Create/CreateTrajectoryWorker.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using System;
using System.Threading.Tasks;

using Microsoft.Extensions.Logging;

using Witsml;
using Witsml.Data;

using WitsmlExplorer.Api.Jobs;
using WitsmlExplorer.Api.Models;
using WitsmlExplorer.Api.Query;
using WitsmlExplorer.Api.Services;

namespace WitsmlExplorer.Api.Workers.Create;

/// <summary>
/// Worker for creating new trajectory by specific well and wellbore.
/// </summary>
public class CreateTrajectoryWorker : BaseWorker<CreateTrajectoryJob>, IWorker
{
public CreateTrajectoryWorker(ILogger<CreateTrajectoryJob> logger, IWitsmlClientProvider witsmlClientProvider) : base(witsmlClientProvider, logger) { }
public JobType JobType => JobType.CreateTrajectory;

/// <summary>
/// Create new trajectory on wellbore for witsml client.
/// </summary>
/// <param name="job">Job info of created trajectory.</param>
/// <returns>Task of workerResult with refresh objects.</returns>
public override async Task<(WorkerResult, RefreshAction)> Execute(CreateTrajectoryJob job)
{
Verify(job.Trajectory);

WitsmlTrajectories trajectoryToCreate = TrajectoryQueries.CreateTrajectory(job.Trajectory);

QueryResult addToStoreResult = await GetTargetWitsmlClientOrThrow().AddToStoreAsync(trajectoryToCreate);

if (!addToStoreResult.IsSuccessful)
{
string errorMessage = "Failed to create trajectory.";
Logger.LogError("{ErrorMessage}. {jobDescription}", errorMessage, job.Description());
return (new WorkerResult(GetTargetWitsmlClientOrThrow().GetServerHostname(), false, errorMessage, addToStoreResult.Reason), null);
}

Logger.LogInformation("Trajectory created. {jobDescription}", job.Description());
RefreshObjects refreshAction = new(GetTargetWitsmlClientOrThrow().GetServerHostname(), job.Trajectory.WellUid, job.Trajectory.WellboreUid, EntityType.Trajectory);
WorkerResult workerResult = new(GetTargetWitsmlClientOrThrow().GetServerHostname(), true, $"Trajectory {job.Trajectory.Name} add for {job.Trajectory.WellboreName}");

return (workerResult, refreshAction);
}

private static void Verify(Trajectory trajectory)
{
if (string.IsNullOrEmpty(trajectory.Uid))
{
throw new InvalidOperationException($"{nameof(trajectory.Uid)} cannot be empty");
}

if (string.IsNullOrEmpty(trajectory.Name))
{
throw new InvalidOperationException($"{nameof(trajectory.Name)} cannot be empty");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import { Typography } from "@equinor/eds-core-react";
import { MenuItem } from "@material-ui/core";
import React, { useContext } from "react";
import { v4 as uuid } from "uuid";
import { DisplayModalAction, HideContextMenuAction, HideModalAction } from "../../contexts/operationStateReducer";
import OperationType from "../../contexts/operationType";
import Wellbore from "../../models/wellbore";
import { colors } from "../../styles/Colors";
import { PropertiesModalMode } from "../Modals/ModalParts";
import ContextMenu from "./ContextMenu";
import { menuItemText, onClickRefresh, StyledIcon } from "./ContextMenuUtils";
import TrajectoryPropertiesModal, { TrajectoryPropertiesModalProps } from "../Modals/TrajectoryPropertiesModal";
import { ObjectType } from "../../models/objectType";
import { pasteObjectOnWellbore } from "./CopyUtils";
import { useClipboardReferencesOfType } from "./UseClipboardReferences";
import NavigationContext from "../../contexts/navigationContext";
import { Server } from "../../models/server";
import Trajectory from "../../models/trajectory";

export interface TrajectoriesContextMenuProps {
dispatchOperation: (action: DisplayModalAction | HideModalAction | HideContextMenuAction) => void;
wellbore: Wellbore;
servers: Server[];
setIsLoading?: (arg: boolean) => void;
}

const TrajectoriesContextMenu = (props: TrajectoriesContextMenuProps): React.ReactElement => {
const { dispatchOperation, wellbore, servers, setIsLoading } = props;
const { dispatchNavigation } = useContext(NavigationContext);
const trajectoryReferences = useClipboardReferencesOfType(ObjectType.Trajectory);

const onClickNewTrajectory = () => {
const newTrajectory: Trajectory = {
uid: uuid(),
name: "",
wellUid: wellbore.wellUid,
wellName: wellbore.wellName,
wellboreUid: wellbore.uid,
wellboreName: wellbore.name,
serviceCompany: "",
aziRef: "",
dTimTrajEnd: "",
dTimTrajStart: "",
mdMax: null,
mdMin: null,
trajectoryStations: []
};
const trajectoryPropertiesModalProps: TrajectoryPropertiesModalProps = { mode: PropertiesModalMode.New, trajectory: newTrajectory, dispatchOperation };
const action: DisplayModalAction = { type: OperationType.DisplayModal, payload: <TrajectoryPropertiesModal {...trajectoryPropertiesModalProps} /> };
dispatchOperation(action);
};

return (
<ContextMenu
menuItems={[
setIsLoading ? (
<MenuItem key={"refresh"} onClick={() => onClickRefresh(dispatchOperation, dispatchNavigation, wellbore.wellUid, wellbore.uid, ObjectType.Trajectory, setIsLoading)}>
<StyledIcon name="refresh" color={colors.interactive.primaryResting} />
<Typography color={"primary"}>{`Refresh Trajectories`}</Typography>
</MenuItem>
) : null,
<MenuItem key={"newTrajectory"} onClick={onClickNewTrajectory}>
<StyledIcon name="add" color={colors.interactive.primaryResting} />
<Typography color={"primary"}>New Trajectory</Typography>
</MenuItem>,
<MenuItem
key={"pasteTrajectory"}
onClick={() => pasteObjectOnWellbore(servers, trajectoryReferences, dispatchOperation, wellbore)}
disabled={trajectoryReferences === null}
>
<StyledIcon name="paste" color={colors.interactive.primaryResting} />
<Typography color={"primary"}>{menuItemText("paste", "trajectory", trajectoryReferences?.objectUids)}</Typography>
</MenuItem>
]}
/>
);
};

export default TrajectoriesContextMenu;
Loading

0 comments on commit d4a90fc

Please sign in to comment.