1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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.base.Actioner;
33 import eu.ehri.project.models.base.PermissionScope;
34 import eu.ehri.project.models.cvoc.AuthoritativeItem;
35 import eu.ehri.project.models.cvoc.Concept;
36 import eu.ehri.project.models.cvoc.Vocabulary;
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
45
46 public class CsvConceptImporter extends CsvAuthoritativeItemImporter {
47
48 public CsvConceptImporter(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.CVOC_CONCEPT_DESCRIPTION,
58 extractUnitDescription(itemData, EntityClass.CVOC_CONCEPT_DESCRIPTION));
59 Bundle unit = Bundle.of(EntityClass.CVOC_CONCEPT, extractUnit(itemData))
60 .withRelation(Ontology.DESCRIPTION_FOR_ENTITY, descBundle);
61
62 Mutation<Concept> mutation = persister.createOrUpdate(unit, Concept.class);
63 Concept frame = mutation.getNode();
64
65 if (!permissionScope.equals(SystemScope.getInstance()) && mutation.created()) {
66 permissionScope.as(Vocabulary.class).addItem(frame);
67 frame.setPermissionScope(permissionScope);
68 }
69
70 handleCallbacks(mutation);
71 return frame;
72 }
73 }