Skip to content

Commit

Permalink
[Simint/Alpha] delete routines endpoint (#361)
Browse files Browse the repository at this point in the history
  • Loading branch information
polomani authored Feb 6, 2024
1 parent 77c31d1 commit 2723d62
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 2 deletions.
12 changes: 12 additions & 0 deletions CogniteSdk.Types/Alpha/Simulators/SimulatorRoutineDelete.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright 2024 Cognite AS
// SPDX-License-Identifier: Apache-2.0

namespace CogniteSdk.Alpha
{
/// <summary>
/// The simulator routine delete class.
/// </summary>
public class SimulatorRoutineDelete : ItemsWithoutCursor<Identity>
{
}
}
10 changes: 10 additions & 0 deletions CogniteSdk.Types/Alpha/Simulators/SimulatorRoutineRevision.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@ public class SimulatorRoutineRevision
/// </summary>
public string SimulatorExternalId { get; set; }

/// <summary>
/// The external id of the model.
/// </summary>
public string ModelExternalId { get; set; }

/// <summary>
/// The external id of the simulator integration.
/// </summary>
public string SimulatorIntegrationExternalId { get; set; }

/// <summary>
/// The id of the user who created the revision.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ public class SimulatorRoutineRevisionFilter
/// </summary>
public IEnumerable<string> SimulatorExternalIds { get; set; }

/// <summary>
/// Filter by model external Ids
/// </summary>
public IEnumerable<string> ModelExternalIds { get; set; }

/// <summary>
/// Filter by created time
/// </summary>
Expand Down
12 changes: 12 additions & 0 deletions CogniteSdk/src/Resources/Alpha/Simulators.cs
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,18 @@ public async Task<IEnumerable<SimulatorRoutine>> CreateSimulatorRoutinesPredefin
return await RunAsync(req).ConfigureAwait(false);
}

/// <summary>
/// Asyncronously deletes simulator routines.
/// </summary>
/// <param name="items">The simulator routine items to delete.</param>
/// <param name="token">Optional cancellation token</param>
public async Task<EmptyResponse> DeleteSimulatorRoutinesAsync(IEnumerable<Identity> items, CancellationToken token = default)
{
var query = new SimulatorRoutineDelete { Items = items };
var req = Simulators.deleteSimulatorRoutines(query, GetContext(token));
return await RunAsync(req).ConfigureAwait(false);
}

/// <summary>
/// Asyncronously creates a set of simulation routine revisions .
/// </summary>
Expand Down
17 changes: 16 additions & 1 deletion CogniteSdk/test/fsharp/Alpha/Simulators.fs
Original file line number Diff line number Diff line change
Expand Up @@ -630,13 +630,18 @@ let ``Create simulator routines is Ok`` () =
resList.Items
|> Seq.find (fun item -> item.ExternalId = routineExternalIdPredefined)

let! resDeleteRoutine =
azureDevClient.Alpha.Simulators.DeleteSimulatorRoutinesAsync([ new Identity(resListRoutine.Id) ])

// Assert
test <@ Seq.length resRoutine = 1 @>
test <@ Seq.length resRoutinePredefined = 1 @>

test <@ resListRoutine.Name = routineToCreate.Name @>
test <@ resListRoutinePredefined.CalculationType = routineToCreatePredefined.CalculationType @>
test <@ resListRoutinePredefined.Name = "Rate by Nodal Analysis" @>

test <@ isNull resDeleteRoutine |> not @>
finally
azureDevClient.Alpha.Simulators.DeleteAsync([ new Identity(simulatorExternalId) ])
|> ignore
Expand Down Expand Up @@ -911,7 +916,17 @@ let ``Create simulator routine revisions is Ok`` () =
azureDevClient.Alpha.Simulators.CreateSimulatorRoutineRevisionsAsync([ revisionToCreate ])

let! resListRevisions =
azureDevClient.Alpha.Simulators.ListSimulatorRoutineRevisionsAsync(new SimulatorRoutineRevisionQuery())
azureDevClient.Alpha.Simulators.ListSimulatorRoutineRevisionsAsync(
new SimulatorRoutineRevisionQuery(
Filter =
SimulatorRoutineRevisionFilter(
RoutineExternalIds = [ routineExternalId ],
SimulatorIntegrationExternalIds = [ integrationCreated.ExternalId ],
SimulatorExternalIds = [ simulatorExternalId ],
CreatedTime = TimeRange(Min = now - 10000L)
)
)
)

let revisionFound =
resListRevisions.Items
Expand Down
9 changes: 9 additions & 0 deletions Oryx.Cognite/src/Alpha/Simulators.fs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,15 @@ module Simulators =
|> withAlphaHeader
|> HttpHandler.list query routinesUrl

let deleteSimulatorRoutines
(items: SimulatorRoutineDelete)
(source: HttpHandler<unit>)
: HttpHandler<EmptyResponse> =
source
|> withLogMessage "simulators:deleteSimulatorRoutines"
|> withAlphaHeader
|> HttpHandler.delete items routinesUrl

let createSimulatorRoutines
(items: SimulatorRoutineCreateCommandItem seq)
(source: HttpHandler<unit>)
Expand Down
2 changes: 1 addition & 1 deletion version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.21.0
3.22.0

0 comments on commit 2723d62

Please sign in to comment.