-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#1938 Added Create rig functionality
- Loading branch information
1 parent
04edb9a
commit dfc11d2
Showing
9 changed files
with
329 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
Src/WitsmlExplorer.Frontend/components/ContextMenus/RigsContextMenu.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.