Skip to content

Commit a440096

Browse files
authored
Merge pull request #10 from relativitydev/REL-1018089-Alias-Samples
Rel 1018089 alias samples
2 parents 2b07e11 + 050210d commit a440096

28 files changed

Lines changed: 481 additions & 128 deletions
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
. "$global:rootDir\Helpers\EndpointsClass.ps1"
2+
. "$global:rootDir\Helpers\WriteInformationClass.ps1"
3+
. "$global:rootDir\Helpers\BaseExportService.ps1"
4+
5+
# Your workspace ID: this is where we point to the workspace where we want to export from
6+
[int]$workspaceId = 1022188
7+
8+
# Export settings parameters
9+
# Your view ID: view will provide us with available data to export, requires folder to be visible there.
10+
# Your folder ID: our targetted folder. If you want to export from the workspace root, the ID is different from the workspace ID.
11+
# ExportSourceType: ExportFolder or ExportFolderWithSubfolders
12+
[int]$viewId = 1003684
13+
[int]$folderID = 1003697
14+
[bool]$withSubfolders = $true
15+
16+
# ArtifactIds: Example: 1003668 - Extracted Text, 1003677 - Folder Name, 1003676 - Artifact ID, 1003667 - Control Number
17+
$fulltextPrecedenceFieldsArtifactIds = '[1003668,1003677]'
18+
19+
# Aliases can use only artifact IDs that are in the fieldArtifactIDs list
20+
# Key is the artifact ID of the field, value is the alias
21+
$fieldArtifactIds = '[1003676,1003667]'
22+
$aliases = '{
23+
"1003676": "Artifact ID - Field1",
24+
"1003667": "Control Number - Field2"
25+
}'
26+
27+
# Job related data
28+
$jobId = New-Guid
29+
[string]$applicationName = "Export-Service-Sample-Powershell"
30+
[string]$applicationId = "Sample-Job-" + $MyInvocation.MyCommand.Name.Replace(".ps1", "")
31+
[int]$exportSourceType = if ($withSubfolders) { 3 } else { 2 }
32+
33+
# Export job settings
34+
[string]$exportJobSettings =
35+
'{
36+
"settings": {
37+
"ExportSourceSettings": {
38+
"ArtifactTypeID":10,
39+
"ExportSourceType":' + $exportSourceType + ',
40+
"ExportSourceArtifactID":' + $folderID + ',
41+
"ViewID":' + $viewId + ',
42+
"StartAtDocumentNumber":1
43+
},
44+
"ExportArtifactSettings": {
45+
"FileNamePattern":"{identifier}",
46+
"ExportNative":true,
47+
"ExportPdf":true,
48+
"ExportImages":true,
49+
"ExportFullText":true,
50+
"ExportMultiChoicesAsNested":false,
51+
"ImageExportSettings": {
52+
"ImagePrecedenceArtifactIDs":[-1],
53+
"TypeOfImage":2,
54+
},
55+
"FullTextExportSettings": {
56+
"ExportFullTextAsFile":true,
57+
"TextFileEncoding":"utf-8",
58+
"PrecedenceFieldsArtifactIDs":' + $fulltextPrecedenceFieldsArtifactIds + '
59+
},
60+
"NativeFilesExportSettings": {
61+
"NativePrecedenceArtifactIDs":[-1]
62+
},
63+
"FieldArtifactIDs":' + $fieldArtifactIds + ',
64+
"FieldAliases":' + $aliases + ',
65+
"ApplyFileNamePatternToImages":false
66+
},
67+
"ExportOutputSettings": {
68+
"LoadFileSettings": {
69+
"LoadFileFormat":"CSV",
70+
"ImageLoadFileFormat":"IPRO",
71+
"PdfLoadFileFormat":"IPRO",
72+
"Encoding":"utf-8",
73+
"DelimitersSettings": {
74+
"NestedValueDelimiter":"B",
75+
"RecordDelimiter":"E",
76+
"QuoteDelimiter":"D",
77+
"NewlineDelimiter":"C",
78+
"MultiRecordDelimiter":"A"
79+
},
80+
"ExportMsAccess": false
81+
},
82+
"VolumeSettings": {
83+
"VolumePrefix":"VOL_FOLDER",
84+
"VolumeStartNumber":"1",
85+
"VolumeMaxSizeInMegabytes":100,
86+
"VolumeDigitPadding":5
87+
},
88+
"SubdirectorySettings": {
89+
"SubdirectoryStartNumber":1,
90+
"MaxNumberOfFilesInDirectory":100,
91+
"ImageSubdirectoryPrefix":"IMAGE_",
92+
"NativeSubdirectoryPrefix":"NATIVE_",
93+
"FullTextSubdirectoryPrefix":"FULLTEXT_",
94+
"PdfSubdirectoryPrefix":"PDFS_",
95+
"SubdirectoryDigitPadding":5
96+
},
97+
"CreateArchive":false,
98+
"FolderStructure":0
99+
}
100+
},
101+
"applicationName":"' + $applicationName + '",
102+
"correlationID":"' + $applicationId + '"
103+
}'
104+
105+
# Create, run export job and display export job result
106+
$global:Endpoints = [Endpoints]::new($workspaceId)
107+
$global:WriteInformation = [WriteInformation]::new()
108+
$global:BaseExportService = [BaseExportService]::new()
109+
110+
Context "Exports native, fulltext, images and PDF files from folder" {
111+
Describe "Create export job" {
112+
$global:BaseExportService.createExportJob($jobId, $exportJobSettings)
113+
}
114+
115+
Describe "Start export job" {
116+
$global:BaseExportService.startExportJob($jobId)
117+
}
118+
119+
Describe "Wait for export job to be completed" {
120+
$global:BaseExportService.waitForExportJobToBeCompleted($jobId)
121+
}
122+
123+
Describe "Export job summary" {
124+
$global:BaseExportService.exportJobResult($jobId)
125+
}
126+
}
127+

Relativity.Export.Samples.RelConsole/Helpers/Logger.cs

Lines changed: 30 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -23,31 +23,6 @@ public Logger(string[] args)
2323
_args = args;
2424
}
2525

26-
public void PrintJobJson(ExportJobSettings settings, bool print = false)
27-
{
28-
if (!_args.Contains("-json"))
29-
{
30-
if (!print)
31-
return;
32-
}
33-
34-
// create JSON for preview
35-
var serializerOptions = new JsonSerializerOptions()
36-
{
37-
WriteIndented = true,
38-
};
39-
40-
var json = JsonSerializer.Serialize(settings, serializerOptions);
41-
42-
var panel = new Panel(new JsonText(json))
43-
.RoundedBorder()
44-
.BorderColor(Color.Orange1)
45-
.Header("[aquamarine1]Job JSON[/]", Justify.Center);
46-
47-
AnsiConsole.Write(panel);
48-
}
49-
50-
5126
public void LogWarning(string message, bool hideTimeStamp = false)
5227
{
5328
Log(new SampleLog(LogLevel.Warning, $"[orange1]{message}[/]", hideTimeStamp));
@@ -95,61 +70,53 @@ public void Log(SampleLog log)
9570
AnsiConsole.Write(table);
9671
}
9772

98-
public void PrintSampleData(Dictionary<string, string> data)
73+
public void PrintJobJson(ExportJobSettings settings, bool print = false)
74+
{
75+
if (!_args.Contains("-json"))
76+
{
77+
if (!print)
78+
return;
79+
}
80+
81+
// create JSON for preview
82+
var serializerOptions = new JsonSerializerOptions()
83+
{
84+
WriteIndented = true,
85+
};
86+
87+
var json = JsonSerializer.Serialize(settings, serializerOptions);
88+
89+
var panel = new Panel(new JsonText(json))
90+
.RoundedBorder()
91+
.BorderColor(Color.Orange1)
92+
.Header("[aquamarine1]Job JSON[/]", Justify.Center);
93+
94+
AnsiConsole.Write(panel);
95+
}
96+
97+
public void PrintDictionaryData<K, V>(Dictionary<K, V> data, string header) where K : notnull
9998
{
10099
var dataGrid = new Grid()
101100
.AddColumn(new GridColumn().NoWrap())
102101
.AddColumn(new GridColumn().NoWrap());
103102

104103
foreach (var record in data)
105104
{
106-
dataGrid.AddRow(new Markup[]
107-
{
105+
dataGrid.AddRow(
106+
[
108107
new Markup($"[orange1]{record.Key}[/]"),
109-
new Markup(record.Value)
110-
});
108+
new Markup(record.Value?.ToString() ?? "#null")
109+
]);
111110
}
112111

113112
var sampleData = new Panel(dataGrid)
114113
.RoundedBorder()
115114
.BorderColor(Color.Orange1)
116-
.Header("[aquamarine1]Sample Data[/]", Justify.Center);
115+
.Header($"[aquamarine1]{header}[/]", Justify.Center);
117116

118117
AnsiConsole.Write(sampleData);
119118
}
120119

121-
public void PrintExportJobResult(string finalMessage, ExportJob exportJob)
122-
{
123-
int processed = exportJob.ProcessedRecords - exportJob.RecordsWithErrors - exportJob.RecordsWithWarnings ?? 0;
124-
125-
LogInformation(finalMessage, hideTimeStamp: true);
126-
AnsiConsole.WriteLine();
127-
AnsiConsole.Write(new BreakdownChart()
128-
.Width(60)
129-
.AddItem("Processed", processed, Color.Green)
130-
.AddItem("Records with errors", exportJob.RecordsWithErrors ?? 0, Color.Red)
131-
.AddItem("Records with warnings", exportJob.RecordsWithWarnings ?? 0, Color.Yellow));
132-
AnsiConsole.WriteLine();
133-
}
134-
135-
public void PrintBulkExportJobResult(string finalMessage, List<ExportStatus?> exportStatuses)
136-
{
137-
int successJobs = exportStatuses.Count(s => s == ExportStatus.Completed);
138-
int failedJobs = exportStatuses.Count(s => s == ExportStatus.Failed);
139-
int cancelledJobs = exportStatuses.Count(s => s == ExportStatus.Cancelled);
140-
int completedWithErrorsJobs = exportStatuses.Count(s => s == ExportStatus.CompletedWithErrors);
141-
142-
LogInformation(string.IsNullOrEmpty(finalMessage) ? "Bulk export completed" : finalMessage, hideTimeStamp: true);
143-
AnsiConsole.WriteLine();
144-
AnsiConsole.Write(new BreakdownChart()
145-
.Width(60)
146-
.AddItem("Success", successJobs, Color.Green)
147-
.AddItem("Completed With Errors", completedWithErrorsJobs, Color.OrangeRed1)
148-
.AddItem("Failed", failedJobs, Color.Red)
149-
.AddItem("Cancelled", cancelledJobs, Color.Yellow));
150-
AnsiConsole.WriteLine();
151-
}
152-
153120
private string LevelToMessage(LogLevel logLevel) => logLevel switch
154121
{
155122
LogLevel.Information => "[bold][aquamarine1]<INFO>[/][/]",
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
using Relativity.Export.V1.Model;
2+
using Spectre.Console;
3+
4+
namespace Relativity.Export.Samples.RelConsole.Helpers;
5+
6+
public static class LoggerExtensions
7+
{
8+
public static void PrintAliases(this Logger logger, Dictionary<int, string> data)
9+
{
10+
logger.PrintDictionaryData(data, "Field Aliases");
11+
}
12+
13+
public static void PrintSampleData(this Logger logger, Dictionary<string, string> data)
14+
{
15+
logger.PrintDictionaryData(data, "Sample Data");
16+
}
17+
18+
public static void PrintExportJobResult(this Logger logger, string finalMessage, ExportJob exportJob)
19+
{
20+
int processed = exportJob.ProcessedRecords - exportJob.RecordsWithErrors - exportJob.RecordsWithWarnings ?? 0;
21+
22+
logger.LogInformation(finalMessage, hideTimeStamp: true);
23+
AnsiConsole.WriteLine();
24+
AnsiConsole.Write(new BreakdownChart()
25+
.Width(60)
26+
.AddItem("Processed", processed, Color.Green)
27+
.AddItem("Records with errors", exportJob.RecordsWithErrors ?? 0, Color.Red)
28+
.AddItem("Records with warnings", exportJob.RecordsWithWarnings ?? 0, Color.Yellow));
29+
AnsiConsole.WriteLine();
30+
}
31+
32+
public static void PrintBulkExportJobResult(this Logger logger, string finalMessage, List<ExportStatus?> exportStatuses)
33+
{
34+
int successJobs = exportStatuses.Count(s => s == ExportStatus.Completed);
35+
int failedJobs = exportStatuses.Count(s => s == ExportStatus.Failed);
36+
int cancelledJobs = exportStatuses.Count(s => s == ExportStatus.Cancelled);
37+
int completedWithErrorsJobs = exportStatuses.Count(s => s == ExportStatus.CompletedWithErrors);
38+
39+
logger.LogInformation(string.IsNullOrEmpty(finalMessage) ? "Bulk export completed" : finalMessage, hideTimeStamp: true);
40+
AnsiConsole.WriteLine();
41+
AnsiConsole.Write(new BreakdownChart()
42+
.Width(60)
43+
.AddItem("Success", successJobs, Color.Green)
44+
.AddItem("Completed With Errors", completedWithErrorsJobs, Color.OrangeRed1)
45+
.AddItem("Failed", failedJobs, Color.Red)
46+
.AddItem("Cancelled", cancelledJobs, Color.Yellow));
47+
AnsiConsole.WriteLine();
48+
}
49+
}

Relativity.Export.Samples.RelConsole/Helpers/OutputHelper.cs

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ public static class OutputHelper
1111
{
1212
private static string[] _args = default!;
1313
private static Dictionary<int, MethodInfo> _sampleRunner = new();
14+
private static List<SampleMetadata> _samples = new();
1415
private static StatusContext _statusContext = default!;
1516
private static object _statusLock = new();
1617

@@ -19,17 +20,15 @@ public static async Task StartAsync(string[] args, string relativityUrl, string
1920
try
2021
{
2122
_args = args;
22-
List<SampleMetadata> samples;
2323
int selectedSampleId = -1;
2424
bool isSampleValid = args.Length > 0 && Int32.TryParse(args[0], out selectedSampleId);
2525

26-
samples = GetSamples(isSampleValid ? selectedSampleId : -1);
26+
GetSamples(isSampleValid ? selectedSampleId : -1);
2727

2828
if (!args.Contains("-noui"))
2929
{
30-
31-
var samplesPanel = GetSamplesPanel(samples);
32-
var metadataPanel = GetSampleMetadataPanel(samples.FirstOrDefault(s => s.ID == selectedSampleId));
30+
var samplesPanel = GetSamplesPanel();
31+
var metadataPanel = GetSampleMetadataPanel(_samples.FirstOrDefault(s => s.ID == selectedSampleId));
3332

3433
Columns[] dataColumns =
3534
[
@@ -126,9 +125,9 @@ public static void ClearStatus()
126125
}
127126
}
128127

129-
private static List<SampleMetadata> GetSamples(int selectedSampleId)
128+
private static void GetSamples(int selectedSampleId)
130129
{
131-
List<SampleMetadata> samples = new();
130+
_samples = new();
132131
var sampleMethods = Assembly.GetExecutingAssembly()
133132
.GetTypes()
134133
.SelectMany(type => type.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly))
@@ -155,11 +154,9 @@ private static List<SampleMetadata> GetSamples(int selectedSampleId)
155154
!string.IsNullOrEmpty(data.Description) ? data.Description : "No description",
156155
sampleID == selectedSampleId); // is sample currently selected
157156

158-
samples.Add(sampleMetadata);
159-
_sampleRunner.Add(i + 1, sampleMethods[i]);
157+
_samples.Add(sampleMetadata);
158+
_sampleRunner.Add(sampleID, sampleMethods[i]);
160159
}
161-
162-
return samples;
163160
}
164161

165162
private static Panel GetSampleMetadataPanel(SampleMetadata? sample)
@@ -201,20 +198,20 @@ private static Panel GetSampleMetadataPanel(SampleMetadata? sample)
201198
return metadataPanel;
202199
}
203200

204-
private static Panel GetSamplesPanel(List<SampleMetadata> samplesMetadata)
201+
private static Panel GetSamplesPanel()
205202
{
206203
var samplesTable = new Table()
207204
.Expand();
208205

209206
samplesTable.AddColumns("ID", "Name");
210207

211-
foreach (var sample in samplesMetadata.OrderBy(s => s.ID))
208+
foreach (var sample in _samples)
212209
{
213-
IRenderable[] rows = new IRenderable[]
214-
{
210+
IRenderable[] rows =
211+
[
215212
new Markup(sample.ID.ToString(), new Style(sample.IsSelected ? Color.Aquamarine1 : Color.Orange1)),
216213
new Markup(sample.Name, new Style(sample.IsSelected ? Color.Aquamarine1 : Color.Orange1))
217-
};
214+
];
218215

219216
samplesTable.AddRow(rows);
220217
}

0 commit comments

Comments
 (0)