Skip to content

Commit

Permalink
#1938 Added Create rig functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
jaroslavbliznak committed Jun 27, 2023
1 parent 04edb9a commit dfc11d2
Show file tree
Hide file tree
Showing 9 changed files with 329 additions and 13 deletions.
50 changes: 50 additions & 0 deletions Src/WitsmlExplorer.Api/Jobs/CreateRigJob.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 rig with jobInfo.
/// </summary>
public record CreateRigJob : Job
{
/// <summary>
/// Rig API model.
/// </summary>
public Rig Rig { get; init; }

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

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

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

/// <summary>
/// Getting name of well.
/// </summary>
/// <returns>String of well name.</returns>
public override string GetWellName()
{
return Rig.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 @@ -36,6 +36,7 @@ public enum JobType
CreateWellbore,
CreateRisk,
CreateMudLog,
CreateRig,
CreateWbGeometry,
BatchModifyWell,
ImportLogData,
Expand Down
12 changes: 6 additions & 6 deletions Src/WitsmlExplorer.Api/Query/RigQueries.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,23 +76,23 @@ public static WitsmlRigs CreateRig(Rig rig)
AirGap = rig.AirGap != null ? new WitsmlLengthMeasure { Uom = rig.AirGap.Uom, Value = rig.AirGap.Value.ToString(CultureInfo.InvariantCulture) } : null,
Name = rig.Name,
TypeRig = rig.TypeRig,
Owner = rig.Owner,
Owner = rig.Owner.NullIfEmpty(),
UidWellbore = rig.WellboreUid,
Approvals = rig.Approvals,
ClassRig = rig.ClassRig,
Approvals = rig.Approvals.NullIfEmpty(),
ClassRig = rig.ClassRig.NullIfEmpty(),
DTimStartOp = StringHelpers.ToUniversalDateTimeString(rig.DTimStartOp),
DTimEndOp = StringHelpers.ToUniversalDateTimeString(rig.DTimEndOp),
EmailAddress = rig.EmailAddress,
FaxNumber = rig.FaxNumber,
IsOffshore = StringHelpers.OptionalBooleanToString(rig.IsOffshore),
Manufacturer = rig.Manufacturer,
Manufacturer = rig.Manufacturer.NullIfEmpty(),
NameContact = rig.NameContact,
RatingDrillDepth = rig.RatingDrillDepth != null ? new WitsmlLengthMeasure { Uom = rig.RatingDrillDepth.Uom, Value = rig.RatingDrillDepth.Value.ToString(CultureInfo.InvariantCulture) } : null,
RatingWaterDepth = rig.RatingWaterDepth != null ? new WitsmlLengthMeasure { Uom = rig.RatingWaterDepth.Uom, Value = rig.RatingWaterDepth.Value.ToString(CultureInfo.InvariantCulture) } : null,
Registration = rig.Registration,
Registration = rig.Registration.NullIfEmpty(),
TelNumber = rig.TelNumber,
YearEntService = rig.YearEntService,
CommonData = new WitsmlCommonData()
CommonData = rig.CommonData == null ? null : new WitsmlCommonData()
{
SourceName = rig.CommonData.SourceName,
DTimCreation = null,
Expand Down
63 changes: 63 additions & 0 deletions Src/WitsmlExplorer.Api/Workers/Create/CreateRigWorker.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.Rig;

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 rig by specific well and wellbore.
/// </summary>
public class CreateRigWorker : BaseWorker<CreateRigJob>, IWorker
{
public CreateRigWorker(ILogger<CreateRigJob> logger, IWitsmlClientProvider witsmlClientProvider) : base(witsmlClientProvider, logger) { }
public JobType JobType => JobType.CreateRig;

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

WitsmlRigs rigToCreate = RigQueries.CreateRig(job.Rig);

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

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

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

return (workerResult, refreshAction);
}

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

if (string.IsNullOrEmpty(rig.Name))
{
throw new InvalidOperationException($"{nameof(rig.Name)} cannot be empty");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { Typography } from "@equinor/eds-core-react";
import { MenuItem } from "@material-ui/core";
import React 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 { StyledIcon } from "./ContextMenuUtils";
import Rig from "../../models/rig";
import RigPropertiesModal, { RigPropertiesModalProps } from "../Modals/RigPropertiesModal";

export interface RigsContextMenuProps {
dispatchOperation: (action: DisplayModalAction | HideModalAction | HideContextMenuAction) => void;
wellbore: Wellbore;
}

const RigsContextMenu = (props: RigsContextMenuProps): React.ReactElement => {
const { dispatchOperation, wellbore } = props;

const onClickNewRig = () => {
const newRig: Rig = {
uid: uuid(),
name: "",
wellUid: wellbore.wellUid,
wellName: wellbore.wellName,
wellboreUid: wellbore.uid,
wellboreName: wellbore.name,
airGap: null,
approvals: "",
commonData: null,
classRig: "",
dTimEndOp: "",
dTimStartOp: "",
emailAddress: "",
faxNumber: "",
manufacturer: "",
nameContact: "",
owner: "",
ratingDrillDepth: null,
ratingWaterDepth: null,
registration: "",
telNumber: "",
typeRig: "unknown",
yearEntService: null
};
const rigPropertiesModalProps: RigPropertiesModalProps = { mode: PropertiesModalMode.New, rig: newRig, dispatchOperation };
const action: DisplayModalAction = { type: OperationType.DisplayModal, payload: <RigPropertiesModal {...rigPropertiesModalProps} /> };
dispatchOperation(action);
};

return (
<ContextMenu
menuItems={[
<MenuItem key={"newRig"} onClick={onClickNewRig}>
<StyledIcon name="add" color={colors.interactive.primaryResting} />
<Typography color={"primary"}>New Rig</Typography>
</MenuItem>
]}
/>
);
};

export default RigsContextMenu;
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const RigPropertiesModal = (props: RigPropertiesModalProps): React.ReactElement
const wellboreRigJob = {
rig: updatedRig
};
await JobService.orderJob(JobType.ModifyRig, wellboreRigJob);
await JobService.orderJob(editMode ? JobType.ModifyRig : JobType.CreateRig, wellboreRigJob);
setIsLoading(false);
dispatchOperation({ type: OperationType.HideModal });
};
Expand All @@ -51,14 +51,25 @@ const RigPropertiesModal = (props: RigPropertiesModalProps): React.ReactElement
<>
{editableRig && (
<ModalDialog
heading={editMode ? `Edit properties for ${editableRig.name}` : `New Log`}
heading={editMode ? `Edit properties for ${editableRig.name}` : `New Rig`}
content={
<>
<TextField
disabled={editMode}
id="uid"
label="rig uid"
required
value={editableRig.uid}
fullWidth
error={!validText(editableRig.uid)}
helperText={editableRig.uid.length === 0 ? "A rig uid must be 1-64 characters" : ""}
inputProps={{ minLength: 1, maxLength: 64 }}
onChange={(e) => setEditableRig({ ...editableRig, uid: e.target.value })}
/>
<TextField disabled id="wellUid" label="well uid" defaultValue={editableRig.wellUid} fullWidth />
<TextField disabled id="wellName" label="well name" defaultValue={editableRig.wellName} fullWidth />
<TextField disabled id="wellboreUid" label="wellbore uid" defaultValue={editableRig.wellboreUid} fullWidth />
<TextField disabled id="wellboreName" label="wellbore name" defaultValue={editableRig.wellboreName} fullWidth />
<TextField disabled id="uid" label="rig uid" required defaultValue={editableRig.uid} fullWidth />
<TextField
id={"name"}
label={"name"}
Expand Down Expand Up @@ -153,8 +164,8 @@ const RigPropertiesModal = (props: RigPropertiesModalProps): React.ReactElement
onChange={(e) => setEditableRig({ ...editableRig, nameContact: e.target.value })}
/>
<TextField
id={"RatingDrillDepth"}
label={"RatingDrillDepth"}
id={"ratingDrillDepth"}
label={"ratingDrillDepth"}
type="number"
fullWidth
value={editableRig.ratingDrillDepth ? editableRig.ratingDrillDepth.value : ""}
Expand Down Expand Up @@ -203,7 +214,7 @@ const RigPropertiesModal = (props: RigPropertiesModalProps): React.ReactElement
/>
</>
}
confirmDisabled={!validText(editableRig.name) || !dTimStartOpValid || !dTimEndOpValid || !yearEntServiceValid}
confirmDisabled={!validText(editableRig.name) || !dTimStartOpValid || !dTimEndOpValid}
onSubmit={() => onSubmit(editableRig)}
isLoading={isLoading}
/>
Expand Down
10 changes: 9 additions & 1 deletion Src/WitsmlExplorer.Frontend/components/Sidebar/WellboreItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import ObjectService from "../../services/objectService";
import { getContextMenuPosition, preventContextMenuPropagation } from "../ContextMenus/ContextMenu";
import FluidsReportContextMenu from "../ContextMenus/FluidsReportContextMenu";
import LogsContextMenu, { LogsContextMenuProps } from "../ContextMenus/LogsContextMenu";
import RigsContextMenu, { RigsContextMenuProps } from "../ContextMenus/RigsContextMenu";
import MudLogContextMenu from "../ContextMenus/MudLogContextMenu";
import TrajectoryContextMenu from "../ContextMenus/TrajectoryContextMenu";
import TubularContextMenu from "../ContextMenus/TubularContextMenu";
Expand Down Expand Up @@ -63,6 +64,13 @@ const WellboreItem = (props: WellboreItemProps): React.ReactElement => {
dispatchOperation({ type: OperationType.DisplayContextMenu, payload: { component: <LogsContextMenu {...contextMenuProps} />, position } });
};

const onRigsContextMenu = (event: React.MouseEvent<HTMLLIElement>, wellbore: Wellbore) => {
preventContextMenuPropagation(event);
const contextMenuProps: RigsContextMenuProps = { dispatchOperation, wellbore };
const position = getContextMenuPosition(event);
dispatchOperation({ type: OperationType.DisplayContextMenu, payload: { component: <RigsContextMenu {...contextMenuProps} />, position } });
};

const onTubularsContextMenu = (event: React.MouseEvent<HTMLLIElement>, wellbore: Wellbore) => {
preventContextMenuPropagation(event);
const contextMenuProps: TubularsContextMenuProps = { dispatchNavigation, dispatchOperation, wellbore, servers };
Expand Down Expand Up @@ -117,7 +125,7 @@ const WellboreItem = (props: WellboreItemProps): React.ReactElement => {
</ObjectGroupItem>
<ObjectGroupItem objectType={ObjectType.Message} />
<ObjectGroupItem objectsOnWellbore={wellbore?.mudLogs} objectType={ObjectType.MudLog} ObjectContextMenu={MudLogContextMenu} />
<ObjectGroupItem objectType={ObjectType.Rig} />
<ObjectGroupItem objectType={ObjectType.Rig} onGroupContextMenu={(event) => onRigsContextMenu(event, wellbore)} />
<ObjectGroupItem objectType={ObjectType.Risk} />
<ObjectGroupItem objectsOnWellbore={wellbore?.trajectories} objectType={ObjectType.Trajectory} ObjectContextMenu={TrajectoryContextMenu} />
<ObjectGroupItem
Expand Down
1 change: 1 addition & 0 deletions Src/WitsmlExplorer.Frontend/services/jobService.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export enum JobType {
CopyObjectsWithParent = "CopyObjectsWithParent",
CreateWellbore = "CreateWellbore",
CreateLogObject = "CreateLogObject",
CreateRig = "CreateRig",
DeleteComponents = "DeleteComponents",
DeleteCurveValues = "DeleteCurveValues",
DeleteObjects = "DeleteObjects",
Expand Down
Loading

0 comments on commit dfc11d2

Please sign in to comment.