Skip to content

Commit 77e8d44

Browse files
authored
Merge pull request #17 from IndicoDataSolutions/meg/submissiondetails
[CAT-457] update bp connector
2 parents 9f5eedc + dfe4cac commit 77e8d44

5 files changed

Lines changed: 168 additions & 49 deletions

File tree

Indico.BluePrism.Connector.Tests/Helpers/EnumerableExtensionsTests.cs

Lines changed: 68 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Data;
34
using System.Linq;
45
using FluentAssertions;
56
using Indico.BluePrism.Connector.Helpers;
@@ -37,17 +38,71 @@ public void ToDetailedDataTable_ShouldReturnValidObject(int id, SubmissionStatus
3738
{
3839
Id = id,
3940
Status = status,
40-
InputFile = inputFile
41+
InputFile = inputFile,
42+
SubmissionFiles = new List<SubmissionFiles>()
43+
{
44+
new SubmissionFiles()
45+
{
46+
Filename = "test.pdf",
47+
Id = 1,
48+
NumPages = 1
49+
50+
}
51+
}
4152
};
4253

4354
//Act
4455
var dataTable = new List<Submission>() { testObject }.ToDetailedDataTable();
4556

57+
4658
//Assert
4759
dataTable.Should().NotBeNull();
4860
dataTable.Rows[0][nameof(testObject.Id)].Should().Equals(id);
4961
dataTable.Rows[0][nameof(testObject.Status)].Should().Equals(status);
5062
dataTable.Rows[0][nameof(testObject.InputFile)].Should().Equals(inputFile);
63+
dataTable.Rows[0][nameof(testObject.SubmissionFiles)].Should().NotBeNull();
64+
var subfiles = dataTable.Rows[0][nameof(testObject.SubmissionFiles)];
65+
subfiles.Should().BeAssignableTo<DataTable>();
66+
(subfiles as DataTable).Rows[0]["Filename"].Should().NotBeNull();
67+
(subfiles as DataTable).Rows[0]["Id"].Should().Be(1);
68+
}
69+
70+
[TestCase(1, SubmissionStatus.COMPLETE, "test")]
71+
[TestCase(2, SubmissionStatus.FAILED, "test2")]
72+
public void ToDetailedDataTable_ShouldReturnValidObjectOfPage(int id, SubmissionStatus status, string inputFile)
73+
{
74+
//Arrange
75+
var testObject = new Submission
76+
{
77+
Id = id,
78+
Status = status,
79+
InputFile = inputFile,
80+
SubmissionFiles = new List<SubmissionFiles>()
81+
{
82+
new SubmissionFiles()
83+
{
84+
Filename = "test.pdf",
85+
Id = 1,
86+
NumPages = 1
87+
88+
}
89+
}
90+
};
91+
92+
//Act
93+
var dataTable = new List<Submission>() { testObject }.ToDetailedDataTable();
94+
95+
96+
//Assert
97+
dataTable.Should().NotBeNull();
98+
dataTable.Rows[0][nameof(testObject.Id)].Should().Equals(id);
99+
dataTable.Rows[0][nameof(testObject.Status)].Should().Equals(status);
100+
dataTable.Rows[0][nameof(testObject.InputFile)].Should().Equals(inputFile);
101+
dataTable.Rows[0][nameof(testObject.SubmissionFiles)].Should().NotBeNull();
102+
var subfiles = dataTable.Rows[0][nameof(testObject.SubmissionFiles)];
103+
subfiles.Should().BeAssignableTo<DataTable>();
104+
(subfiles as DataTable).Rows[0]["Filename"].Should().NotBeNull();
105+
(subfiles as DataTable).Rows[0]["Id"].Should().Be(1);
51106
}
52107

53108
[TestCase(0)]
@@ -60,7 +115,18 @@ public void ToDetailedDataTable_ShouldReturnAllElements(int count)
60115

61116
for (int i = 0; i < count; i++)
62117
{
63-
list.Add(new Submission { Id = i });
118+
list.Add(new Submission { Id = i,
119+
SubmissionFiles = new List<SubmissionFiles>()
120+
{
121+
new SubmissionFiles()
122+
{
123+
Filename = "test.pdf",
124+
Id = 1,
125+
NumPages = 1
126+
127+
}
128+
}
129+
});
64130
}
65131

66132
//Act

Indico.BluePrism.Connector/Helpers/EnumerableExtensions.cs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
using System;
2+
using System.Collections;
23
using System.Collections.Generic;
34
using System.Data;
5+
using System.Linq;
46
using System.Reflection;
7+
using Indico.Entity;
58

69
namespace Indico.BluePrism.Connector.Helpers
710
{
@@ -20,6 +23,7 @@ public static DataTable ToIdDataTable<T>(this IEnumerable<T> list, string column
2023
return result;
2124
}
2225

26+
2327
public static DataTable ToDetailedDataTable<T>(this IEnumerable<T> items)
2428
{
2529
var tb = new DataTable(typeof(T).Name);
@@ -28,15 +32,23 @@ public static DataTable ToDetailedDataTable<T>(this IEnumerable<T> items)
2832

2933
foreach (var prop in props)
3034
{
35+
//unsupported properties -- basically complex objects... except collections.
3136
if (prop.PropertyType != typeof(string) && prop.PropertyType.IsClass)
3237
{
3338
throw new NotSupportedException($"Type {prop.PropertyType} is not supported.");
3439
}
35-
40+
3641
if (prop.PropertyType.IsEnum)
3742
{
3843
tb.Columns.Add(prop.Name, typeof(string));
3944
}
45+
//collections of sub-objects (for example, submission files), as data tables
46+
//the typecheck for string is because string is technically IEnumerable<char>
47+
else if (prop.PropertyType != typeof(string) && typeof(IEnumerable).IsAssignableFrom(prop.PropertyType))
48+
{
49+
50+
tb.Columns.Add(prop.Name, typeof(DataTable));
51+
}
4052
else
4153
{
4254
tb.Columns.Add(prop.Name, prop.PropertyType);
@@ -45,6 +57,7 @@ public static DataTable ToDetailedDataTable<T>(this IEnumerable<T> items)
4557

4658
foreach (var item in items)
4759
{
60+
//doing some unsafe type things here to get the member variables and serialize them
4861
var values = new object[props.Length];
4962
for (var i = 0; i < props.Length; i++)
5063
{
@@ -54,6 +67,16 @@ public static DataTable ToDetailedDataTable<T>(this IEnumerable<T> items)
5467
{
5568
values[i] = value.ToString();
5669
}
70+
if (prop.PropertyType != typeof(string) && typeof(IEnumerable).IsAssignableFrom(prop.PropertyType))
71+
{
72+
//todo: figure out how to do this generically but for now just assign the type based on the name...
73+
if(prop.Name == "SubmissionFiles")
74+
{
75+
var submissionFiles = value as IEnumerable<SubmissionFiles>;
76+
values[i] = submissionFiles?.ToDetailedDataTable();
77+
}
78+
79+
}
5780
else
5881
{
5982
values[i] = prop.GetValue(item, null);
@@ -65,5 +88,8 @@ public static DataTable ToDetailedDataTable<T>(this IEnumerable<T> items)
6588

6689
return tb;
6790
}
91+
6892
}
93+
94+
6995
}

Indico.BluePrism.Connector/IIndicoConnector.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,7 @@ public interface IIndicoConnector
2727
/// <param name="limit">Submission count limit. Default value is 1000.</param>
2828
/// <returns></returns>
2929
DataTable ListSubmissions(DataTable submissionIds, DataTable workflowIds, string inputFileName, string status, string retrieved, decimal limit = 1000);
30+
31+
DataTable GetSubmissionFileDetails(DataTable submissionIds);
3032
}
3133
}

Indico.BluePrism.Connector/Indico.BluePrism.Connector.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
99

1010
<IndicoBP_Output Condition="'$(IndicoBP_Output)' == ''"></IndicoBP_Output>
11-
<AppendTargetFrameworkToOutputPath Condition="'$(IndicoBP_Output)' != ''">false</AppendTargetFrameworkToOutputPath>
11+
<AppendTargetFrameworkToOutputPath Condition="'$(IndicoBP_Output)' != ''">true</AppendTargetFrameworkToOutputPath>
1212
<OutputPath Condition="$(IndicoBP_Output) != ''">$(IndicoBP_Output)</OutputPath>
1313
</PropertyGroup>
1414

@@ -20,7 +20,7 @@
2020
</Target>
2121

2222
<ItemGroup>
23-
<PackageReference Include="IndicoClient" Version="2.0.0-preview5" />
23+
<PackageReference Include="IndicoClient" Version="2.0.0.1251918" />
2424
</ItemGroup>
2525

2626
</Project>

Indico.BluePrism.Connector/IndicoConnector.cs

Lines changed: 69 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.ComponentModel.Design;
34
using System.Data;
45
using System.Linq;
56
using System.Threading;
@@ -85,50 +86,7 @@ public DataTable WorkflowSubmission(DataTable filepaths, DataTable uris, decimal
8586

8687
public DataTable ListSubmissions(DataTable submissionIds, DataTable workflowIds, string inputFileName, string status, string retrieved, decimal limit = 1000)
8788
{
88-
bool? parsedRetrieved = null;
89-
SubmissionStatus? parsedStatus = null;
90-
91-
if (string.IsNullOrWhiteSpace(inputFileName))
92-
{
93-
inputFileName = null;
94-
}
95-
96-
if (!string.IsNullOrEmpty(status))
97-
{
98-
if (!Enum.TryParse(status, out SubmissionStatus statusValue))
99-
{
100-
throw new ArgumentException("Wrong status value provided. Please provide one of the valid submission statuses.");
101-
}
102-
else
103-
{
104-
parsedStatus = statusValue;
105-
}
106-
}
107-
108-
if (!string.IsNullOrEmpty(retrieved))
109-
{
110-
if (!bool.TryParse(retrieved, out bool retrievedValue))
111-
{
112-
throw new ArgumentException("Wrong retreived value provided. Please provide \"True\" or \"False\" as a value.");
113-
}
114-
else
115-
{
116-
parsedRetrieved = retrievedValue;
117-
}
118-
}
119-
120-
var submissionFilter = new SubmissionFilter
121-
{
122-
InputFilename = inputFileName,
123-
Status = parsedStatus,
124-
Retrieved = parsedRetrieved
125-
};
126-
127-
var submissionIdsList = submissionIds?.ToList<decimal>().Select(s => Convert.ToInt32(s)).ToList();
128-
var workflowIdsList = workflowIds?.ToList<decimal>().Select(w => Convert.ToInt32(w)).ToList();
129-
int limitInt = Convert.ToInt32(limit);
130-
131-
var result = Task.Run(async () => await _submissionsClient.ListAsync(submissionIdsList, workflowIdsList, submissionFilter, limitInt)).GetAwaiter().GetResult();
89+
var result = CallListSubmissions(submissionIds, workflowIds, inputFileName, status, retrieved, limit);
13290

13391
return result.ToDetailedDataTable();
13492
}
@@ -194,6 +152,15 @@ private async Task<JObject> SubmitReviewAsync(int submissionId, JObject changes,
194152
}
195153
}
196154

155+
private async Task<string> GenerateSubmissionResult(int submissionId)
156+
{
157+
using (var tokenSource = new CancellationTokenSource(_timeout))
158+
{
159+
var jobId = await _submissionsClient.GenerateSubmissionResultAsync(submissionId);
160+
return jobId;
161+
}
162+
}
163+
197164
private static bool HasAnyRows(DataTable dataTable)
198165
{
199166
if (dataTable == null || dataTable.Rows.Count == 0)
@@ -203,5 +170,63 @@ private static bool HasAnyRows(DataTable dataTable)
203170

204171
return true;
205172
}
173+
174+
private IEnumerable<ISubmission> CallListSubmissions(DataTable submissionIds, DataTable workflowIds, string inputFileName, string status, string retrieved, decimal limit = 1000)
175+
{
176+
bool? parsedRetrieved = null;
177+
SubmissionStatus? parsedStatus = null;
178+
179+
if (string.IsNullOrWhiteSpace(inputFileName))
180+
{
181+
inputFileName = null;
182+
}
183+
184+
if (!string.IsNullOrEmpty(status))
185+
{
186+
if (!Enum.TryParse(status, out SubmissionStatus statusValue))
187+
{
188+
throw new ArgumentException("Wrong status value provided. Please provide one of the valid submission statuses.");
189+
}
190+
else
191+
{
192+
parsedStatus = statusValue;
193+
}
194+
}
195+
196+
if (!string.IsNullOrEmpty(retrieved))
197+
{
198+
if (!bool.TryParse(retrieved, out bool retrievedValue))
199+
{
200+
throw new ArgumentException("Wrong retreived value provided. Please provide \"True\" or \"False\" as a value.");
201+
}
202+
else
203+
{
204+
parsedRetrieved = retrievedValue;
205+
}
206+
}
207+
208+
var submissionFilter = new SubmissionFilter
209+
{
210+
InputFilename = inputFileName,
211+
Status = parsedStatus,
212+
Retrieved = parsedRetrieved
213+
};
214+
215+
var submissionIdsList = submissionIds?.ToList<decimal>().Select(s => Convert.ToInt32(s)).ToList();
216+
var workflowIdsList = workflowIds?.ToList<decimal>().Select(w => Convert.ToInt32(w)).ToList();
217+
int limitInt = Convert.ToInt32(limit);
218+
219+
var result = Task.Run(async () => await _submissionsClient.ListAsync(submissionIdsList, workflowIdsList, submissionFilter, limitInt)).GetAwaiter().GetResult();
220+
return result;
221+
}
222+
public DataTable GetSubmissionFileDetails(DataTable submissionIds)
223+
{
224+
225+
var submissionIdsList = submissionIds?.ToList<decimal>().Select(s => Convert.ToInt32(s)).ToList();
226+
227+
var result = CallListSubmissions(submissionIds, new DataTable(), "", "", "");
228+
var parsed = result.Select(x => x.SubmissionFiles.Select(y => new { y.Filename, NumPages = y.NumPages, Id = y.Id, SubmissionId = x.Id }));
229+
return parsed.ToDetailedDataTable();
230+
}
206231
}
207232
}

0 commit comments

Comments
 (0)