7
7
8
8
import com .nuix .superutilities .SuperUtilities ;
9
9
import com .nuix .superutilities .loadfiles .*;
10
+ import com .nuix .superutilities .misc .BoundedProgressInfo ;
10
11
import com .nuix .superutilities .misc .FormatUtility ;
12
+ import com .nuix .superutilities .misc .PeriodicGatedConsumer ;
11
13
import com .nuix .superutilities .misc .PlaceholderResolver ;
12
14
import com .nuix .superutilities .reporting .SimpleWorksheet ;
13
15
import com .nuix .superutilities .reporting .SimpleXlsx ;
@@ -57,38 +59,48 @@ public class CustomExporter {
57
59
private SimpleTextFileWriter errorLog = null ;
58
60
59
61
private boolean exportText = false ;
60
- private Map <String , Object > textExportSettings = new HashMap <String , Object >();
62
+ private Map <String , Object > textExportSettings = new HashMap <>();
61
63
private String textFileNameTemplate = "{export_directory}\\ TEXT\\ {guid}.txt" ;
62
64
63
65
private boolean exportNatives = false ;
64
- private Map <String , Object > emailExportSettings = new HashMap <String , Object >();
66
+ private Map <String , Object > emailExportSettings = new HashMap <>();
65
67
private String nativeFileNameTemplate = "{export_directory}\\ NATIVES\\ {guid}.{extension}" ;
66
68
67
69
private boolean exportPdfs = false ;
68
- private Map <String , Object > pdfExportSettings = new HashMap <String , Object >();
70
+ private Map <String , Object > pdfExportSettings = new HashMap <>();
69
71
private String pdfFileNameTemplate = "{export_directory}\\ PDF\\ {guid}.pdf" ;
70
72
71
73
private boolean exportTiffs = false ;
72
- private Map <String , Object > tiffExportSettings = new HashMap <String , Object >();
74
+ private Map <String , Object > tiffExportSettings = new HashMap <>();
73
75
private String tiffFileNameTemplate = "{export_directory}\\ IMAGE\\ {guid}.{extension}" ;
74
76
75
77
private boolean exportJson = false ;
76
78
private String jsonFileNameTemplate = "{export_directory}\\ JSON\\ {guid}.json" ;
77
79
private JsonExporter jsonExporter = null ;
78
80
81
+ private Consumer <String > messageLoggedCallback = null ;
82
+ private PeriodicGatedConsumer <BoundedProgressInfo > progressCallback = null ;
83
+
79
84
/**
80
85
* -- SETTER --
81
86
* Sets whether DAT contents should additionally be exported as an XLSX spreadsheet.
82
87
*/
83
88
@ Setter
84
89
private boolean exportXlsx = false ;
90
+
85
91
/**
86
92
* -- SETTER --
87
93
* Sets whether final DAT will be kept by moving it to final export directory/
88
94
*/
89
95
@ Setter
90
96
private boolean keepOriginalDat = false ;
91
97
98
+ /**
99
+ * Whether to skip export of natives for slip-sheeted items.
100
+ */
101
+ @ Setter
102
+ private boolean skipNativesSlipsheetedItems = false ;
103
+
92
104
/**
93
105
* -- SETTER --
94
106
* Allows you to provide a Map of headers to rename. Intended to provide a way to rename headers that Nuix automatically adds
@@ -129,6 +141,31 @@ public class CustomExporter {
129
141
public CustomExporter () {
130
142
}
131
143
144
+ /***
145
+ * Provides a callback to be invoked when progress is made during initial batch export or during
146
+ * restructuring phase. Will be wrapped in a {@link PeriodicGatedConsumer} with an interval of 5 seconds
147
+ * if not already an instance of {@link PeriodicGatedConsumer}.
148
+ * @param progressCallback The progress info consumer.
149
+ */
150
+ public void whenProgressEventOccurs (Consumer <BoundedProgressInfo > progressCallback ) {
151
+ if (progressCallback instanceof PeriodicGatedConsumer ) {
152
+ this .progressCallback = (PeriodicGatedConsumer <BoundedProgressInfo >) progressCallback ;
153
+ } else {
154
+ this .progressCallback = new PeriodicGatedConsumer <>(progressCallback , 5000 );
155
+ }
156
+ }
157
+
158
+ private void fireProgressEvent (String stage , long current , long total ) {
159
+ BoundedProgressInfo info = new BoundedProgressInfo (stage , current , total );
160
+ if (progressCallback != null ) {
161
+ progressCallback .accept (info );
162
+ }
163
+ }
164
+
165
+ public void whenMessageLogged (Consumer <String > messageLoggedCallback ) {
166
+ this .messageLoggedCallback = messageLoggedCallback ;
167
+ }
168
+
132
169
/***
133
170
* Assigns a dynamically calculated placeholder to this instance.
134
171
* @param placeholderName Placeholder name with "{" or "}". For example "my_value". Placeholder in templates can then be referred to using "{my_value}". It is
@@ -245,7 +282,13 @@ public void setColumnRemovals(Collection<String> columnHeaders) {
245
282
246
283
private void logInfo (String format , Object ... params ) {
247
284
String message = String .format (format , params );
248
- System .out .println (message );
285
+
286
+ if (messageLoggedCallback != null ) {
287
+ messageLoggedCallback .accept (message );
288
+ } else {
289
+ System .out .println (message );
290
+ }
291
+
249
292
if (generalLog != null ) {
250
293
try {
251
294
generalLog .writeLine (message );
@@ -259,7 +302,13 @@ private void logInfo(String format, Object... params) {
259
302
260
303
private void logError (String format , Object ... params ) {
261
304
String message = String .format (format , params );
262
- System .out .println (message );
305
+
306
+ if (messageLoggedCallback != null ) {
307
+ messageLoggedCallback .accept ("ERROR: " + message );
308
+ } else {
309
+ System .err .println (message );
310
+ }
311
+
263
312
if (errorLog != null ) {
264
313
try {
265
314
errorLog .writeLine (message );
@@ -298,12 +347,7 @@ public String evaluate(Item item) {
298
347
}
299
348
}
300
349
if (!hasGuid ) {
301
- exportProfile = exportProfile .addMetadata ("GUID" , new ItemExpression <String >() {
302
- @ Override
303
- public String evaluate (Item item ) {
304
- return item .getGuid ();
305
- }
306
- });
350
+ exportProfile = exportProfile .addMetadata ("GUID" , Item ::getGuid );
307
351
}
308
352
}
309
353
return exportProfile ;
@@ -421,7 +465,6 @@ public void exportItems(Case nuixCase, File exportDirectory, List<Item> items) t
421
465
exporter .addProduct ("tiff" , productSettings );
422
466
}
423
467
424
-
425
468
exportDirectory .mkdirs ();
426
469
File tempDatFile = new File (exportTempDirectory , "loadfile.dat" );
427
470
File finalDatFile = new File (exportDirectory , "loadfile.dat" );
@@ -448,6 +491,8 @@ public void itemProcessed(ItemEventInfo info) {
448
491
logError ("BatchExporter reports error while exporting item with GUID '%s':\n %s" ,
449
492
info .getItem ().getGuid (), FormatUtility .debugString (info .getFailure ()));
450
493
}
494
+
495
+ fireProgressEvent ("BatchExport: " + info .getStage (), info .getStageCount (), items .size ());
451
496
}
452
497
});
453
498
@@ -469,6 +514,9 @@ public void itemProcessed(ItemEventInfo info) {
469
514
exporter .setStampingOptions (stampingSettings );
470
515
}
471
516
517
+ // Forward setting regarding natives slipsheet generation
518
+ exporter .setSkipNativesSlipsheetedItems (skipNativesSlipsheetedItems );
519
+
472
520
logInfo ("Beginning temp export using BatchExporter..." );
473
521
exporter .exportItems (items );
474
522
logInfo ("Finished temp export using BatchExporter" );
@@ -495,6 +543,8 @@ public void itemProcessed(ItemEventInfo info) {
495
543
496
544
@ Override
497
545
public void accept (LinkedHashMap <String , String > record ) {
546
+ fireProgressEvent ("Export Restructure" , recordsProcessed , items .size ());
547
+
498
548
// Periodically log progress
499
549
long diffMillis = System .currentTimeMillis () - restructureStartMillis ;
500
550
if (diffMillis > 2 * 1000 || recordsProcessed % 100 == 0 ) {
0 commit comments