Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CAT-688] Migrate ListWorkflows call from V1 to V2 #118

Merged
merged 4 commits into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,4 @@ IndicoV2.StrawberryShake/Generated/
user.runsettings
/IndicoV2/Properties/PublishProfiles
/Indico/Properties/PublishProfiles
/.graphqlrc.json
2 changes: 2 additions & 0 deletions IndicoV2.Abstractions/Workflows/Models/IWorkflow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@ public interface IWorkflow
int Id { get; }

bool ReviewEnabled { get; }

string Name { get; }
}
}
14 changes: 14 additions & 0 deletions IndicoV2.Abstractions/Workflows/Models/Workflow.cs
meghanhickey marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Text;
using IndicoV2.StrawberryShake;

namespace IndicoV2.Workflows.Models
{
public class Workflow : IWorkflow
{
public int Id { get; set; } = 0;
public bool ReviewEnabled { get; set; } = false;
public string Name { get; set; }
}
}
13 changes: 13 additions & 0 deletions IndicoV2.IntegrationTests/Workflows/WorkflowClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using IndicoV2.IntegrationTests.Utils.Configs;
using IndicoV2.IntegrationTests.Utils.DataHelpers;
using IndicoV2.Workflows;
using IndicoV2.Workflows.Models;
using NUnit.Framework;
using Unity;

Expand Down Expand Up @@ -61,5 +62,17 @@ public async Task AddData_ShouldReturnResult()

result.Should().NotBeNull();
}

[Test]
public async Task ListWorkflows_ShouldReturnResult()
{
var result = await _workflowsClient.ListAsync(_dataSetId);
result.Should().NotBeNull();
foreach (Workflow wf in result)
{
wf.Id.Should().BeGreaterThan(0);
wf.Name.Should().NotBeNull();
}
}
}
}
21 changes: 21 additions & 0 deletions IndicoV2.StrawberryShake/Workflows/WorkflowSsClient.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Collections.Generic;
using IndicoV2.StrawberryShake.Exceptions;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Data;
using Newtonsoft.Json.Linq;

namespace IndicoV2.StrawberryShake.Workflows
{
Expand All @@ -23,5 +27,22 @@ public async Task<WorkflowStatus> GetStatus(int workflowId, CancellationToken ca

return response.Workflows.Workflows.Single().Status.Value;
}

public async Task<IListWorkflows_Workflows> ListAsync(int datasetId, CancellationToken cancellationToken)
{
int?[] datasetIds = { datasetId };
var response = await ExecuteAsync(() =>
_services.GetRequiredService<ListWorkflowsQuery>().ExecuteAsync(Array.AsReadOnly(datasetIds), cancellationToken));
return response.Workflows;
}

public async Task<IListWorkflows_Workflows> ListAsync(int[] datasetIds, CancellationToken cancellationToken)
{
var nullableDatasetIds = datasetIds.Cast<int?>().ToArray();
var response = await ExecuteAsync(() =>
_services.GetRequiredService<ListWorkflowsQuery>().ExecuteAsync(Array.AsReadOnly(nullableDatasetIds), cancellationToken));
return response.Workflows;
}

}
}
10 changes: 10 additions & 0 deletions IndicoV2.StrawberryShake/Workflows/Workflows.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,13 @@ mutation WorkflowAddData($workflowId: Int!) {
}
}
}

query ListWorkflows($datasetIds: [Int]){
workflows(datasetIds: $datasetIds){
workflows {
id
name
reviewEnabled
}
}
}

This file was deleted.

15 changes: 0 additions & 15 deletions IndicoV2.V1Adapters/Workflows/Models/V1WorkflowAdapter.cs

This file was deleted.

31 changes: 0 additions & 31 deletions IndicoV2.V1Adapters/Workflows/WorkflowsV1ClientAdapter.cs

This file was deleted.

27 changes: 19 additions & 8 deletions IndicoV2/Workflows/WorkflowsClient.cs
Original file line number Diff line number Diff line change
@@ -1,34 +1,45 @@
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using System.Linq;
using IndicoV2.StrawberryShake;
using IndicoV2.V1Adapters.Workflows;
using IndicoV2.Workflows.Models;

namespace IndicoV2.Workflows
{
public class WorkflowsClient : IWorkflowsClient
{
private readonly WorkflowsV1ClientAdapter _legacy;
meghanhickey marked this conversation as resolved.
Show resolved Hide resolved
private readonly IndicoStrawberryShakeClient _strawberryShake;
private readonly IndicoClient _indicoClient;

public WorkflowsClient(IndicoClient indicoClient)
{
_legacy = new WorkflowsV1ClientAdapter(indicoClient.LegacyClient);
_indicoClient = indicoClient;
_strawberryShake = indicoClient.IndicoStrawberryShakeClient;
}

public Task<IEnumerable<IWorkflow>> ListAsync(int dataSetId, CancellationToken cancellationToken = default) =>
_legacy.ListAsync(dataSetId, cancellationToken);
public async Task<IEnumerable<IWorkflow>> ListAsync(int dataSetId, CancellationToken cancellationToken = default)
{
var result = await _strawberryShake.Workflows().ListAsync(dataSetId, cancellationToken);
return result.Workflows.Select(x => ToWorkflow(x)).ToList();
}

public Task<IEnumerable<IWorkflow>>
ListAsync(int[] dataSetIds, CancellationToken cancellationToken = default) =>
_legacy.ListAsync(dataSetIds, cancellationToken);
public async Task<IEnumerable<IWorkflow>>ListAsync(int[] dataSetIds, CancellationToken cancellationToken = default)
{
var result = await _strawberryShake.Workflows().ListAsync(dataSetIds, cancellationToken);
return result.Workflows.Select(x => ToWorkflow(x)).ToList();
}

public Task<IWorkflowAddDataResult> AddDataAsync(int workflowId, CancellationToken cancellationToken) =>
_strawberryShake.Workflows().AddData(workflowId, cancellationToken);

public Task<WorkflowStatus> GetStatusAsync(int workflowId, CancellationToken cancellationToken) =>
_strawberryShake.Workflows().GetStatus(workflowId, cancellationToken);

private Workflow ToWorkflow(IListWorkflows_Workflows_Workflows workflow) => new Workflow {
goatrocks marked this conversation as resolved.
Show resolved Hide resolved
Id = workflow.Id ?? 0,
ReviewEnabled = workflow.ReviewEnabled ?? false,
Name = workflow.Name,
};
}
}