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

[DEV-11445] implement submission filter parity #141

Merged
merged 7 commits into from
Mar 7, 2024
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
76 changes: 66 additions & 10 deletions Examples/SubmissionFilterExample/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,88 @@ private static string GetToken() =>

public static async Task Main()
{
var filters = new OrFilter //https://developer.indicodata.ai/docs/filter-submissions
var client = new IndicoClient(GetToken(), new Uri("https://try.indico.io"));

var submissionClient = client.Submissions();
var submissionIds = new List<int>() { };
var workflowIds = new List<int>() { 3106 };

// Example 1
// List all submissions that are complete or failed
var orFilter = new OrFilter
{
Or = new List<IFilter>
{
new SubmissionFilter
{
InputFilename = "",
Status = SubmissionStatus.COMPLETE,
Retrieved = false
},
new SubmissionFilter
{
InputFilename = "",
Status = SubmissionStatus.FAILED,
Retrieved = false
}
}
};

var client = new IndicoClient(GetToken(), new Uri("https://try.indico.io"));
var submissions = await submissionClient.ListAsync(submissionIds, workflowIds, orFilter, limit: 10);
Console.WriteLine(submissions);

var submissionClient = client.Submissions();
var submissionIds = new List<int>() { };
var workflowIds = new List<int>() { 3106 };
// Example 2
// List all submissions that are COMPLETE and FAILED
var andFilter = new AndFilter
{
And = new List<IFilter>
{
new SubmissionFilter
{
Status = SubmissionStatus.COMPLETE,
},
new SubmissionFilter
{
Status = SubmissionStatus.FAILED,
}
}
};

submissions = await submissionClient.ListAsync(submissionIds, workflowIds, andFilter, limit: 10);
Console.WriteLine(submissions);

// Example 3
// List all submissions that are retrieved and have a filename that contains 'property'
var subFilter = new SubmissionFilter
{
Retrieved = true,
InputFilename = "property"
};

submissions = await submissionClient.ListAsync(submissionIds, workflowIds, subFilter, limit: 10);
Console.WriteLine(submissions);

// Example 4
// List all submissions that are created and updated within a certain date range
var dateRangeFilter = new DateRangeFilter()
{
From = "2022-01-01",
To = DateTime.Now.ToString("yyyy-MM-dd")
};
subFilter = new SubmissionFilter
{
CreatedAt = dateRangeFilter,
UpdatedAt = dateRangeFilter
};

submissions = await submissionClient.ListAsync(submissionIds, workflowIds, subFilter, limit: 10);
Console.WriteLine(submissions);

// Example 5
// List all submissions that are not in progress of being reviewed and are completed
subFilter = new SubmissionFilter
{
Status = SubmissionStatus.COMPLETE,
ReviewInProgress = false
};

var submissions = await submissionClient.ListAsync(submissionIds, workflowIds, filters, limit: 1000);
submissions = await submissionClient.ListAsync(submissionIds, workflowIds, subFilter, limit: 10);
Console.WriteLine(submissions);
}
}
Expand Down
57 changes: 52 additions & 5 deletions IndicoV2.Abstractions/Submissions/Models/FilterConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using v2SubmissionFilter = IndicoV2.Submissions.Models.SubmissionFilter;
using ssSubmissionFilter = IndicoV2.StrawberryShake.SubmissionFilter;
using System.Linq;
using IndicoV2.StrawberryShake;

namespace IndicoV2.Submissions.Models
{
Expand All @@ -15,12 +16,58 @@ public static ssSubmissionFilter ConvertToSs(this IFilter filter)
{
if (filter is v2SubmissionFilter submissionFilter)
{
return new ssSubmissionFilter()
// Note: you have to not reference or set a field at all for StrawberryShake Code Generator to decide to not serialize it
var ssFilter = new ssSubmissionFilter();
if (submissionFilter.FileType != null)
{
InputFilename = submissionFilter.InputFilename,
Retrieved = submissionFilter.Retrieved,
Status = (StrawberryShake.SubmissionStatus?)submissionFilter.Status
};
ssFilter.Filetype = submissionFilter.FileType.Select(x => (FileType)Enum.Parse(typeof(FileType), x)).ToList();
}
if (string.IsNullOrEmpty(submissionFilter.InputFilename))
{
ssFilter.InputFilename = submissionFilter.InputFilename;
}
if (submissionFilter.Retrieved.HasValue)
{
ssFilter.Retrieved = submissionFilter.Retrieved;
}
if (submissionFilter.Status.HasValue)
{
ssFilter.Status = (StrawberryShake.SubmissionStatus?)submissionFilter.Status;
}
if (submissionFilter.Reviews != null)
{
ssFilter.Reviews = new ReviewFilter()
{
Rejected = submissionFilter.Reviews.Rejected,
CreatedBy = submissionFilter.Reviews.CreatedBy,
ReviewType = (StrawberryShake.ReviewType)submissionFilter.Reviews.ReviewType
};
}
if (submissionFilter.ReviewInProgress.HasValue)
{
ssFilter.ReviewInProgress = submissionFilter.ReviewInProgress;
}
if (submissionFilter.FilesDeleted.HasValue)
{
ssFilter.FilesDeleted = submissionFilter.FilesDeleted;
}
if (submissionFilter.CreatedAt != null)
{
ssFilter.CreatedAt = new StrawberryShake.DateRangeFilter()
{
From = submissionFilter.CreatedAt.From,
To = submissionFilter.CreatedAt.To,
};
}
if (submissionFilter.UpdatedAt != null)
{
ssFilter.UpdatedAt = new StrawberryShake.DateRangeFilter()
{
From = submissionFilter.UpdatedAt.From,
To = submissionFilter.UpdatedAt.To
};
}
return ssFilter;
}
else if (filter is AndFilter andfilter)
{
Expand Down
81 changes: 71 additions & 10 deletions IndicoV2.Abstractions/Submissions/Models/ISubmission.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

using IndicoV2.CommonModels.Pagination;
using System;

namespace IndicoV2.Submissions.Models
{
Expand All @@ -13,44 +13,105 @@ public interface ISubmission
/// </summary>
int Id { get; }

/// <summary>
/// Dataset id.
/// </summary>
int DatasetId { get; }

/// <summary>
/// Workflow id.
/// </summary>
int WorkflowId { get; }

/// <summary>
/// Submission status. See <c><see cref="SubmissionStatus"/></c>.
/// </summary>
SubmissionStatus Status { get; }

/// <summary>
/// Dataset id.
/// Datetime the submission was created.
/// </summary>
int DatasetId { get; }
DateTimeOffset? CreatedAt { get; }

/// <summary>
/// Workflow id.
/// Datetime the submission was updated.
/// </summary>
int WorkflowId { get; }
DateTimeOffset? UpdatedAt { get; }

/// <summary>
/// Id of the user who created the submission.
/// </summary>
int? CreatedBy { get; }

/// <summary>
/// Id of the user who updated the submission.
/// </summary>
int? UpdatedBy { get; }

/// <summary>
/// Datetime the submission reached a completed state.
/// </summary>
DateTimeOffset? CompletedAt { get; }

/// <summary>
/// Submission input file.
/// Submission errors.
/// </summary>
string Errors { get; }

/// <summary>
/// Submission files have been deleted from file store.
/// </summary>
bool? FilesDeleted { get; }

/// <summary>
/// List of submission input files.
/// </summary>
SubmissionFile[] InputFiles { get; }

/// <summary>
/// Local URL to first stored input.
/// </summary>
string InputFile { get; }

/// <summary>
/// Submission name of input file.
/// Original name of first file.
/// </summary>
string InputFilename { get; }

/// <summary>
/// Submission result file.
/// Local URL to most recently stored output.
/// </summary>
string ResultFile { get; }

/// <summary>
/// List of submission output files.
/// </summary>
SubmissionOutput[] OutputFiles { get; }

/// <summary>
/// Is submission retrieved.
/// </summary>
bool Retrieved { get; }

/// <summary>
/// Submission errors.
/// Latest auto review for submission.
/// </summary>
string Errors { get; }
Review AutoReview { get; }

/// <summary>
/// List of submission retries.
/// </summary>
SubmissionRetry[] Retries { get; }

/// <summary>
/// Completed reviews of this submission, without changes.
/// </summary>
Review[] Reviews { get; }

/// <summary>
/// True if the submission is being actively reviewed.
/// </summary>
bool? ReviewInProgress { get; }

}
}
Loading
Loading