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   * To change this template, choose Tools | Templates
22   * and open the template in the editor.
23   */
24  package eu.ehri.project.importers.csv;
25  
26  import com.tinkerpop.frames.FramedGraph;
27  import eu.ehri.project.acl.SystemScope;
28  import eu.ehri.project.definitions.Ontology;
29  import eu.ehri.project.exceptions.ValidationError;
30  import eu.ehri.project.importers.ImportLog;
31  import eu.ehri.project.models.EntityClass;
32  import eu.ehri.project.models.HistoricalAgent;
33  import eu.ehri.project.models.base.Actioner;
34  import eu.ehri.project.models.base.PermissionScope;
35  import eu.ehri.project.models.cvoc.AuthoritativeItem;
36  import eu.ehri.project.models.cvoc.AuthoritativeSet;
37  import eu.ehri.project.persistence.Bundle;
38  import eu.ehri.project.persistence.BundleManager;
39  import eu.ehri.project.persistence.Mutation;
40  
41  import java.util.Map;
42  
43  /**
44   * Importer of historical agents loaded from a CSV file.
45   */
46  public class CsvHistoricalAgentImporter extends CsvAuthoritativeItemImporter {
47  
48      public CsvHistoricalAgentImporter(FramedGraph<?> framedGraph, PermissionScope permissionScope,
49              Actioner actioner, ImportLog log) {
50          super(framedGraph, permissionScope, actioner, log);
51      }
52  
53      @Override
54      public AuthoritativeItem importItem(Map<String, Object> itemData) throws ValidationError {
55  
56          BundleManager persister = getPersister();
57          Bundle descBundle = Bundle.of(EntityClass.HISTORICAL_AGENT_DESCRIPTION,
58                  extractUnitDescription(itemData, EntityClass.HISTORICAL_AGENT_DESCRIPTION));
59          Bundle unit = Bundle.of(EntityClass.HISTORICAL_AGENT, extractUnit(itemData))
60                  .withRelation(Ontology.DESCRIPTION_FOR_ENTITY, descBundle);
61  
62          Mutation<HistoricalAgent> mutation = persister.createOrUpdate(unit, HistoricalAgent.class);
63          HistoricalAgent frame = mutation.getNode();
64  
65          if (!permissionScope.equals(SystemScope.getInstance()) && mutation.created()) {
66              permissionScope.as(AuthoritativeSet.class).addItem(frame);
67              frame.setPermissionScope(permissionScope);
68          }
69  
70          handleCallbacks(mutation);
71          return frame;
72      }
73  }