-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathExport_Folder_All.cs
203 lines (174 loc) · 7.16 KB
/
Export_Folder_All.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
using Relativity.Export.Samples.RelConsole.Helpers;
using Relativity.Export.V1.Builders.ExportSettings;
using Relativity.Export.V1.Model.ExportJobSettings;
namespace Relativity.Export.Samples.RelConsole.SampleCollection;
public partial class BaseExportService
{
[SampleMetadata(nameof(Export_FromFolder_All), "Exports native, fulltext, images and PDF files from folder")]
public async Task Export_FromFolder_All()
{
// Your workspace ID.
// This is where we point to the workspace where we want to export from.
int workspaceID = 1020245;
// Your View ID.
// View will provide us with available data to export, requires folder to be visible there.
int viewID = 1042326;
// Your Folder ID.
// Our targetted folder. If you want to export from the workspace root,
// the ID is different from the workspace ID.
int folderID = 1003697;
// Job related data
Guid jobID = Guid.NewGuid();
string? applicationName = "Export-Service-Sample-App";
string? correlationID = "Sample-Job-0001";
_logger.PrintSampleData(new Dictionary<string, string>
{
{"Workspace ID", workspaceID.ToString() },
{"View ID", viewID.ToString() },
{"Folder ID", folderID.ToString() },
{"Artifact Type ID", "10" },
{"Job ID", jobID.ToString() },
{"Application Name", applicationName },
{"Correlation ID", correlationID }
});
// Export source settings
var sourceSettings = ExportSourceSettingsBuilder.Create()
.FromFolder(exportSourceArtifactID: folderID, viewID: viewID)
.WithSubfolders() // include subfolders
.WithCustomStartAtDocumentNumber(1)
.Build();
// Select and assign an order to long text fields that Relativity checks for text when performing an export.
// You must provide at least one long text field to use this functionality
// If there won't be a value for a field, the next field in the list will be used
// Example:
// 1003668 - Extracted Text
// 1003677 - Folder Name
// If there won't be any value for Extracted Text, Folder Name will be used
List<int> fulltextPrecedenceFieldsArtifactIds = new() { 1003668, 1003677 };
// Artifact settings
var artifactSettings = ExportArtifactSettingsBuilder.Create()
.WithDefaultFileNamePattern()
.WithoutApplyingFileNamePatternToImages()
.ExportImages(settings => settings
.WithImagePrecedenceArtifactIDs(new List<int> { -1 }) // Exports images
.WithTypeOfImage(ImageType.Pdf))
.ExportFullText(settings => settings
.ExportFullTextAsFile()
.WithTextFileEncoding("UTF-8")
.WithPrecedenceFieldsArtifactIDs(fulltextPrecedenceFieldsArtifactIds))
.ExportNative(settings => settings
.WithNativePrecedenceArtifactIDs(new List<int> { -1 })) // Exports native files
.ExportPdf() // Export PDF files
.WithFieldArtifactIDs(new List<int> { 1003676, 1003667 }) // Fields to export
.WithoutFieldAliases()
.WithoutExportingMultiChoicesAsNested()
.Build();
// Subdirectory settings
var subdirectorySettings = SubdirectorySettingsBuilder.Create()
.WithSubdirectoryStartNumber(1)
.WithMaxNumberOfFilesInDirectory(100)
.WithDefaultPrefixes()
.OverridePrefixDefaults(prefixes =>
{
// Optional overrides
prefixes.FullTextSubdirectoryPrefix = "FULLTEXT_";
prefixes.NativeSubdirectoryPrefix = "NATIVE_";
prefixes.ImageSubdirectoryPrefix = "IMAGE_";
prefixes.PdfSubdirectoryPrefix = "PDF_";
})
.WithSubdirectoryDigitPadding(5)
.Build();
// Volume settings
var volumeSettings = VolumeSettingsBuilder.Create()
.WithVolumePrefix("VOL_FOLDER_")
.WithVolumeStartNumber(1)
.WithVolumeMaxSizeInMegabytes(100)
.WithVolumeDigitPadding(5)
.Build();
// Loadfile settings
var loadfileSettings = LoadFileSettingsBuilder.Create()
.WithoutExportingMsAccess()
.WithoutCustomCultureInfo()
.WithDefaultDateTimeFormat()
.WithLoadFileFormat(LoadFileFormat.CSV)
.WithEncoding("UTF-8")
.WithImageLoadFileFormat(ImageLoadFileFormat.IPRO)
.WithPdfFileFormat(PdfLoadFileFormat.IPRO_FullText)
.WithDelimiterSettings(delimiters =>
delimiters.WithDefaultDelimiters())
.Build();
// Output settings
var outputSettings = ExportOutputSettingsBuilder.Create()
.WithoutArchiveCreation()
.WithDefaultFolderStructure()
.WithoutTransferJobID()
.WithDefaultDestinationPath()
.WithSubdirectorySettings(subdirectorySettings)
.WithVolumeSettings(volumeSettings)
.WithLoadFileSettings(loadfileSettings)
.Build();
// Connect all settings in the Job builder
var jobSettings = ExportJobSettingsBuilder.Create()
.WithExportSourceSettings(sourceSettings)
.WithExportArtifactSettings(artifactSettings)
.WithExportOutputSettings(outputSettings)
.Build();
// Create proxy to use IExportJobManager
using Relativity.Export.V1.IExportJobManager jobManager = _serviceFactory.CreateProxy<Relativity.Export.V1.IExportJobManager>();
_logger.PrintJobJson(jobSettings);
// Create export job
_logger.LogInformation("Creating job");
var validationResult = await jobManager.CreateAsync(
workspaceID,
jobID,
jobSettings,
applicationName,
correlationID);
if (validationResult is null)
{
_logger.LogError("Something went wrong. Received empty response.");
return;
}
// check validation result
if (!validationResult.IsSuccess)
{
_logger.LogError($"<{validationResult.ErrorCode}> {validationResult.ErrorMessage}");
// iterate errors and print them
foreach (var validationError in validationResult.Value.ValidationErrors)
{
_logger.LogError($"{validationError.Key} - {validationError.Value}");
}
return;
}
_logger.LogInformation("Job created successfully");
// Start export job
_logger.LogInformation($"Stating job with <{jobID}> ID");
var startResponse = await jobManager.StartAsync(workspaceID, jobID);
// Check for errors that occured during job start
if (!string.IsNullOrEmpty(startResponse.ErrorMessage))
{
_logger.LogError($"<{startResponse.ErrorCode}> {startResponse.ErrorMessage}");
return;
}
// Get status of the job and await for the completed state
_logger.LogInformation("Awaiting job status updates");
var jobResult = await WaitForJobToBeCompletedAsync(async () =>
{
return await jobManager.GetAsync(workspaceID, jobID);
});
string resultData =
$"Export job ID: {jobResult.ExportJobID}\n"
+ $"Correlation ID: {jobResult.Value.CorrelationID}\n"
+ $"Job status: {jobResult.Value.JobStatus}\n"
+ $"Job error count: {jobResult.Value.JobErrorsCount}\n"
+ $"Total records: {jobResult.Value.TotalRecords}\n"
+ $"Processed records: {jobResult.Value.ProcessedRecords}\n"
+ $"Exported files count: {jobResult.Value.ExportedFilesCount}\n"
+ $"Total size of exported files: {jobResult.Value.TotalSizeOfExportedFiles}\n"
+ $"Records with warnings: {jobResult.Value.RecordsWithErrors}\n"
+ $"Records with errors: {jobResult.Value.RecordsWithErrors}\n"
+ $"Output URL: [orange1]{jobResult.Value.ExportJobOutput.OutputUrl}[/]";
_logger.LogInformation("Job Completed");
_logger.PrintExportJobResult(resultData, jobResult.Value);
}
}