21
21
22
22
import javax .faces .context .FacesContext ;
23
23
import javax .xml .parsers .ParserConfigurationException ;
24
+ import javax .xml .stream .XMLStreamException ;
24
25
import javax .xml .transform .TransformerException ;
25
26
import javax .xml .xpath .XPathExpressionException ;
26
27
29
30
import org .apache .logging .log4j .Logger ;
30
31
import org .kitodo .api .dataeditor .rulesetmanagement .FunctionalMetadata ;
31
32
import org .kitodo .api .externaldatamanagement .SingleHit ;
33
+ import org .kitodo .api .schemaconverter .DataRecord ;
32
34
import org .kitodo .api .schemaconverter .ExemplarRecord ;
35
+ import org .kitodo .api .schemaconverter .MetadataFormat ;
33
36
import org .kitodo .data .database .beans .ImportConfiguration ;
34
37
import org .kitodo .data .database .exceptions .DAOException ;
35
38
import org .kitodo .exceptions .CatalogException ;
53
56
54
57
public class CatalogImportDialog extends MetadataImportDialog implements Serializable {
55
58
private static final Logger logger = LogManager .getLogger (CatalogImportDialog .class );
56
- private final LazyHitModel hitModel = new LazyHitModel () ;
59
+ private final LazyHitModel hitModel ;
57
60
58
61
private static final String ID_PARAMETER_NAME = "ID" ;
59
62
private static final String HITSTABLE_NAME = "hitlistDialogForm:hitlistDialogTable" ;
@@ -64,6 +67,10 @@ public class CatalogImportDialog extends MetadataImportDialog implements Serial
64
67
private int numberOfChildren = 0 ;
65
68
private String opacErrorMessage = "" ;
66
69
private boolean additionalImport = false ;
70
+ private String selectedField = "" ;
71
+ private String searchTerm = "" ;
72
+ private int importDepth = 2 ;
73
+
67
74
68
75
/**
69
76
* Standard constructor.
@@ -72,6 +79,7 @@ public class CatalogImportDialog extends MetadataImportDialog implements Serial
72
79
*/
73
80
CatalogImportDialog (CreateProcessForm createProcessForm ) {
74
81
super (createProcessForm );
82
+ this .hitModel = new LazyHitModel (this );
75
83
}
76
84
77
85
/**
@@ -87,11 +95,11 @@ public void getSelectedRecord() {
87
95
* @return list of search fields
88
96
*/
89
97
public List <String > getSearchFields () {
90
- if (Objects .isNull (hitModel . getImportConfiguration ())) {
98
+ if (Objects .isNull (createProcessForm . getCurrentImportConfiguration ())) {
91
99
return new LinkedList <>();
92
100
} else {
93
101
try {
94
- return ServiceManager .getImportService ().getAvailableSearchFields (hitModel . getImportConfiguration ());
102
+ return ServiceManager .getImportService ().getAvailableSearchFields (createProcessForm . getCurrentImportConfiguration ());
95
103
} catch (IllegalArgumentException e ) {
96
104
Helper .setErrorMessage (e .getLocalizedMessage (), logger , e );
97
105
return new LinkedList <>();
@@ -104,8 +112,8 @@ public List<String> getSearchFields() {
104
112
*/
105
113
public void search () {
106
114
try {
107
- if (skipHitList (hitModel . getImportConfiguration (), hitModel . getSelectedField ())) {
108
- getRecordById (hitModel . getSearchTerm ());
115
+ if (skipHitList (createProcessForm . getCurrentImportConfiguration (), getSelectedField ())) {
116
+ getRecordById (getSearchTerm ());
109
117
} else {
110
118
List <?> hits = hitModel .load (0 , 10 , null , SortOrder .ASCENDING , Collections .EMPTY_MAP );
111
119
if (hits .size () == 1 ) {
@@ -175,16 +183,21 @@ public void getRecordHierarchy() {
175
183
createProcessForm .setChildProcesses (new LinkedList <>());
176
184
int projectId = this .createProcessForm .getProject ().getId ();
177
185
int templateId = this .createProcessForm .getTemplate ().getId ();
178
- ImportConfiguration importConfiguration = this .hitModel .getImportConfiguration ();
179
-
180
- // import current and ancestors
181
- LinkedList <TempProcess > processes = ServiceManager .getImportService ().importProcessHierarchy (
182
- currentRecordId , importConfiguration , projectId , templateId , hitModel .getImportDepth (),
183
- createProcessForm .getRulesetManagement ().getFunctionalKeys (
184
- FunctionalMetadata .HIGHERLEVEL_IDENTIFIER ));
185
- // import children
186
- if (this .importChildren ) {
187
- importChildren (projectId , templateId , importConfiguration , processes );
186
+ ImportConfiguration importConfiguration = createProcessForm .getCurrentImportConfiguration ();
187
+
188
+ LinkedList <TempProcess > processes ;
189
+ if (MetadataFormat .EAD .name ().equals (importConfiguration .getMetadataFormat ())) {
190
+ processes = createEadProcesses (importConfiguration );
191
+ } else {
192
+ // import current and ancestors
193
+ processes = ServiceManager .getImportService ().importProcessHierarchy (currentRecordId ,
194
+ importConfiguration , projectId , templateId , getImportDepth (),
195
+ createProcessForm .getRulesetManagement ().getFunctionalKeys (
196
+ FunctionalMetadata .HIGHERLEVEL_IDENTIFIER ));
197
+ // import children
198
+ if (this .importChildren ) {
199
+ importChildren (projectId , templateId , importConfiguration , processes );
200
+ }
188
201
}
189
202
190
203
if (!createProcessForm .getProcesses ().isEmpty () && additionalImport ) {
@@ -196,15 +209,39 @@ public void getRecordHierarchy() {
196
209
attachToExistingParentAndGenerateAtstslIfNotExist (currentTempProcess );
197
210
showMessageAndRecord (importConfiguration , processes );
198
211
}
212
+
199
213
} catch (IOException | ProcessGenerationException | XPathExpressionException | URISyntaxException
200
- | ParserConfigurationException | UnsupportedFormatException | SAXException | DAOException
201
- | ConfigException | TransformerException | NoRecordFoundException | InvalidMetadataValueException
202
- | NoSuchMetadataFieldException e ) {
214
+ | ParserConfigurationException | UnsupportedFormatException | SAXException | DAOException
215
+ | ConfigException | TransformerException | NoRecordFoundException | InvalidMetadataValueException
216
+ | NoSuchMetadataFieldException | XMLStreamException e ) {
203
217
throw new CatalogException (e .getLocalizedMessage ());
204
218
}
205
219
}
206
220
}
207
221
222
+ private LinkedList <TempProcess > createEadProcesses (ImportConfiguration importConfiguration ) throws NoRecordFoundException ,
223
+ XPathExpressionException , IOException , ParserConfigurationException , SAXException , XMLStreamException ,
224
+ UnsupportedFormatException , ProcessGenerationException , URISyntaxException , InvalidMetadataValueException ,
225
+ TransformerException , NoSuchMetadataFieldException {
226
+ LinkedList <TempProcess > processes = new LinkedList <>();
227
+ DataRecord externalRecord = ServiceManager .getImportService ()
228
+ .importExternalDataRecord (importConfiguration , this .currentRecordId , false );
229
+ createProcessForm .setXmlString (externalRecord .getOriginalData ().toString ());
230
+ if (createProcessForm .limitExceeded (externalRecord .getOriginalData ().toString ())) {
231
+ createProcessForm .calculateNumberOfEadElements ();
232
+ Ajax .update ("maxNumberOfRecordsExceededDialog" );
233
+ PrimeFaces .current ().executeScript ("PF('maxNumberOfRecordsExceededDialog').show();" );
234
+ } else {
235
+ LinkedList <TempProcess > eadProcesses = ServiceManager .getImportService ()
236
+ .parseImportedEADCollection (externalRecord , importConfiguration ,
237
+ createProcessForm .getProject ().getId (), createProcessForm .getTemplate ().getId (),
238
+ createProcessForm .getSelectedEadLevel (), createProcessForm .getSelectedParentEadLevel ());
239
+ createProcessForm .setChildProcesses (new LinkedList <>(eadProcesses .subList (1 , eadProcesses .size () - 1 )));
240
+ processes = new LinkedList <>(Collections .singletonList (eadProcesses .get (0 )));
241
+ }
242
+ return processes ;
243
+ }
244
+
208
245
private void showMessageAndRecord (ImportConfiguration importConfiguration , LinkedList <TempProcess > processes ) {
209
246
String summary = Helper .getTranslation ("newProcess.catalogueSearch.importSuccessfulSummary" );
210
247
String detail = Helper .getTranslation ("newProcess.catalogueSearch.importSuccessfulDetail" ,
@@ -238,7 +275,7 @@ private void getRecordById(String recordId) {
238
275
try {
239
276
if (this .importChildren ) {
240
277
this .numberOfChildren = ServiceManager .getImportService ().getNumberOfChildren (
241
- this . hitModel . getImportConfiguration (), this .currentRecordId );
278
+ createProcessForm . getCurrentImportConfiguration (), this .currentRecordId );
242
279
}
243
280
if (this .importChildren && this .numberOfChildren > NUMBER_OF_CHILDREN_WARNING_THRESHOLD ) {
244
281
Ajax .update ("manyChildrenWarningDialog" );
@@ -294,7 +331,7 @@ public LinkedList<ExemplarRecord> getExemplarRecords() {
294
331
*/
295
332
public void setSelectedExemplarRecord (ExemplarRecord selectedExemplarRecord ) {
296
333
try {
297
- ImportService .setSelectedExemplarRecord (selectedExemplarRecord , this . hitModel . getImportConfiguration (),
334
+ ImportService .setSelectedExemplarRecord (selectedExemplarRecord , createProcessForm . getCurrentImportConfiguration (),
298
335
this .createProcessForm .getProcessMetadata ().getProcessDetailsElements ());
299
336
String summary = Helper .getTranslation ("newProcess.catalogueSearch.exemplarRecordSelectedSummary" );
300
337
String detail = Helper .getTranslation ("newProcess.catalogueSearch.exemplarRecordSelectedDetail" ,
@@ -303,7 +340,7 @@ public void setSelectedExemplarRecord(ExemplarRecord selectedExemplarRecord) {
303
340
Ajax .update (FORM_CLIENTID );
304
341
} catch (ParameterNotFoundException e ) {
305
342
Helper .setErrorMessage ("newProcess.catalogueSearch.exemplarRecordParameterNotFoundError" ,
306
- new Object [] {e .getMessage (), this . hitModel . getImportConfiguration ().getTitle () });
343
+ new Object [] {e .getMessage (), createProcessForm . getCurrentImportConfiguration ().getTitle () });
307
344
}
308
345
}
309
346
@@ -314,8 +351,8 @@ public void setSelectedExemplarRecord(ExemplarRecord selectedExemplarRecord) {
314
351
*/
315
352
public boolean isParentIdSearchFieldConfigured () {
316
353
try {
317
- return Objects .nonNull (this . hitModel . getImportConfiguration ()) && ServiceManager .getImportService ()
318
- .isParentIdSearchFieldConfigured (this . hitModel . getImportConfiguration ());
354
+ return Objects .nonNull (createProcessForm . getCurrentImportConfiguration ()) && ServiceManager .getImportService ()
355
+ .isParentIdSearchFieldConfigured (createProcessForm . getCurrentImportConfiguration ());
319
356
} catch (ConfigException e ) {
320
357
return false ;
321
358
}
@@ -360,4 +397,59 @@ public void setAdditionalImport(boolean additionalImport) {
360
397
this .additionalImport = additionalImport ;
361
398
}
362
399
400
+
401
+ /**
402
+ * Get searchTerm.
403
+ *
404
+ * @return value of searchTerm
405
+ */
406
+ public String getSearchTerm () {
407
+ return this .searchTerm ;
408
+ }
409
+
410
+ /**
411
+ * Set searchTerm.
412
+ *
413
+ * @param searchTerm as java.lang.String
414
+ */
415
+ public void setSearchTerm (String searchTerm ) {
416
+ this .searchTerm = searchTerm ;
417
+ }
418
+
419
+ /**
420
+ * Get selectedField.
421
+ *
422
+ * @return value of selectedField
423
+ */
424
+ public String getSelectedField () {
425
+ return this .selectedField ;
426
+ }
427
+
428
+ /**
429
+ * Set selectedField.
430
+ *
431
+ * @param field as String
432
+ */
433
+ public void setSelectedField (String field ) {
434
+ this .selectedField = field ;
435
+ }
436
+
437
+ /**
438
+ * Get import depth.
439
+ *
440
+ * @return import depth
441
+ */
442
+ public int getImportDepth () {
443
+ return importDepth ;
444
+ }
445
+
446
+ /**
447
+ * Set import depth.
448
+ *
449
+ * @param depth import depth
450
+ */
451
+ public void setImportDepth (int depth ) {
452
+ importDepth = depth ;
453
+ }
454
+
363
455
}
0 commit comments