View Javadoc

1   /*
2    * Copyright 2015 Data Archiving and Networked Services (an institute of
3    * Koninklijke Nederlandse Akademie van Wetenschappen), King's College London,
4    * Georg-August-Universitaet Goettingen Stiftung Oeffentlichen Rechts
5    *
6    * Licensed under the EUPL, Version 1.1 or – as soon they will be approved by
7    * the European Commission - subsequent versions of the EUPL (the "Licence");
8    * You may not use this work except in compliance with the Licence.
9    * You may obtain a copy of the Licence at:
10   *
11   * https://joinup.ec.europa.eu/software/page/eupl
12   *
13   * Unless required by applicable law or agreed to in writing, software
14   * distributed under the Licence is distributed on an "AS IS" basis,
15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   * See the Licence for the specific language governing
17   * permissions and limitations under the Licence.
18   */
19  
20  /**
21   */
22  package eu.ehri.project.importers.ead;
23  
24  import eu.ehri.project.importers.base.ItemImporter;
25  import eu.ehri.project.importers.properties.XmlImportProperties;
26  import eu.ehri.project.importers.util.ImportHelpers;
27  import org.slf4j.Logger;
28  import org.slf4j.LoggerFactory;
29  
30  import java.util.List;
31  import java.util.Map;
32  
33  /**
34   * Handler for importing EAD files converted from the USHMM Solr index file.
35   * These files were converted using the solr2ead XSLT stylesheet.
36   */
37  public class UshmmHandler extends EadHandler {
38  
39      private static final Logger logger = LoggerFactory.getLogger(UshmmHandler.class);
40  
41      private int count;
42  
43      public UshmmHandler(ItemImporter<Map<String, Object>, ?> importer) {
44          super(importer, new XmlImportProperties("ushmm.properties"));
45  
46      }
47  
48      @Override
49      protected void extractIdentifier(Map<String, Object> currentGraph) {
50          //not all units have ids, and some have multiple, find the "irn"
51          if (currentGraph.containsKey(ImportHelpers.OBJECT_IDENTIFIER)) {
52              if (currentGraph.get(ImportHelpers.OBJECT_IDENTIFIER) instanceof List) {
53                  logger.debug("class of identifier: " + currentGraph.get(ImportHelpers.OBJECT_IDENTIFIER).getClass());
54                  List<String> identifiers = (List<String>) currentGraph.get(ImportHelpers.OBJECT_IDENTIFIER);
55                  List<String> identifierType = (List<String>) currentGraph.get("objectIdentifierType");
56                  for (int i = 0; i < identifiers.size(); i++) {
57                      if (identifierType.get(i).equals("irn")) {
58                          logger.debug("found official id: " + identifiers.get(i));
59                          currentGraph.put(ImportHelpers.OBJECT_IDENTIFIER, identifiers.get(i));
60                      } else {
61                          logger.debug("found other form of identifier: " + identifiers.get(i));
62                          addOtherIdentifier(currentGraph, identifiers.get(i));
63                          //currentGraph.put("otherIdentifiers", identifiers.get(i));
64                      }
65                  }
66                  currentGraph.remove("objectIdentifierType");
67              }
68          } else {
69              logger.error("no unitid found, setting {}", ++count);
70              currentGraph.put(ImportHelpers.OBJECT_IDENTIFIER, "ushmmID" + count);
71          }
72      }
73  }