Merge branch 'master' into feature8162
authorAndreas Müller <a.mueller@bgbm.org>
Tue, 5 Mar 2019 10:49:45 +0000 (11:49 +0100)
committerAndreas Müller <a.mueller@bgbm.org>
Tue, 5 Mar 2019 10:49:45 +0000 (11:49 +0100)
Conflicts:
app-import/src/main/java/eu/etaxonomy/cdm/io/plantglossary/PlantGlossaryCsvImportState.java

app-import/src/main/java/eu/etaxonomy/cdm/io/plantglossary/PlantGlossaryCategoryAsPropertiesImport.java [new file with mode: 0644]
app-import/src/main/java/eu/etaxonomy/cdm/io/plantglossary/PlantGlossaryCsvImportConfigurator.java
app-import/src/main/java/eu/etaxonomy/cdm/io/plantglossary/PlantGlossaryCsvImportState.java

diff --git a/app-import/src/main/java/eu/etaxonomy/cdm/io/plantglossary/PlantGlossaryCategoryAsPropertiesImport.java b/app-import/src/main/java/eu/etaxonomy/cdm/io/plantglossary/PlantGlossaryCategoryAsPropertiesImport.java
new file mode 100644 (file)
index 0000000..0a118a6
--- /dev/null
@@ -0,0 +1,71 @@
+/**
+* Copyright (C) 2017 EDIT
+* European Distributed Institute of Taxonomy
+* http://www.e-taxonomy.eu
+*
+* The contents of this file are subject to the Mozilla Public License Version 1.1
+* See LICENSE.TXT at the top of this package for the full license terms.
+*/
+package eu.etaxonomy.cdm.io.plantglossary;
+
+import java.io.File;
+import java.net.URI;
+import java.util.Map;
+
+import org.apache.log4j.Logger;
+import org.springframework.stereotype.Component;
+
+import eu.etaxonomy.cdm.common.CdmUtils;
+import eu.etaxonomy.cdm.io.csv.in.CsvImportBase;
+import eu.etaxonomy.cdm.model.common.IdentifiableSource;
+import eu.etaxonomy.cdm.model.common.OriginalSourceType;
+import eu.etaxonomy.cdm.model.common.TermVocabulary;
+import eu.etaxonomy.cdm.model.description.Feature;
+
+/**
+ *
+ * @author pplitzner
+ * @since Dec 7, 2018
+ *
+ */
+@Component
+public class PlantGlossaryCategoryAsPropertiesImport extends CsvImportBase<PlantGlossaryCsvImportConfigurator, PlantGlossaryCsvImportState, File>{
+    private static final long serialVersionUID = -5600766240192189822L;
+    private static Logger logger = Logger.getLogger(PlantGlossaryCategoryAsPropertiesImport.class);
+
+    @Override
+    protected void handleSingleLine(PlantGlossaryCsvImportState importState) {
+        final String HEADER_LABEL = "rdfs:label";
+        final String HEADER_DESCRIPTION = "skos:definition";
+        final String HEADER_URI = "category_URI";
+        final String HEADER_NOTES = "skos:notes";
+
+        Map<String, String> currentRecord = importState.getCurrentRecord();
+
+        String label = currentRecord.get(HEADER_LABEL);
+        if(CdmUtils.isBlank(label)){
+            // this line does not contain any vocabulary information
+            return;
+        }
+        if(importState.isTermPresent(label, getTermService())) {
+            return;
+        }
+
+        String description = currentRecord.get(HEADER_DESCRIPTION);
+        String uri = currentRecord.get(HEADER_URI);
+        Feature property = Feature.NewInstance(description, label, null);
+        property.setUri(URI.create(uri));
+        property.setIdInVocabulary(label);
+
+        TermVocabulary vocabulary = importState.getPropertyVoc();
+        vocabulary.addTerm(property);
+
+        IdentifiableSource source = IdentifiableSource.NewInstance(OriginalSourceType.Import, importState.getCitation().getTitle(), null, importState.getCitation(), null);
+        source.setIdInSource(label);
+        property.addSource(source);
+
+        getVocabularyService().saveOrUpdate(vocabulary);
+        getTermService().saveOrUpdate(property);
+    }
+
+}
\ No newline at end of file
index 1c6dd30c7ab3cfa457caad16a01e467b5fcf3c1b..7704bf9997b0cc012bc94d29b5a42a9632763c64 100644 (file)
@@ -45,6 +45,7 @@ public class PlantGlossaryCsvImportConfigurator
     protected void makeIoClassList() {
         ioClassList = new Class[] {
                 PlantGlossaryCategoryImport.class,
+                PlantGlossaryCategoryAsPropertiesImport.class,
                 PlantGlossaryStateImport.class };
     }
 
index 682350b9e31b290e1a726e2a889b07a2e1a31619..6adb144a70435bd3c13eadee09432bb97d799747 100644 (file)
@@ -21,7 +21,15 @@ import eu.etaxonomy.cdm.io.csv.in.CsvImportState;
 import eu.etaxonomy.cdm.model.agent.Institution;
 import eu.etaxonomy.cdm.model.agent.Person;
 import eu.etaxonomy.cdm.model.agent.Team;
+<<<<<<< HEAD
+=======
+import eu.etaxonomy.cdm.model.common.IdentifiableSource;
+import eu.etaxonomy.cdm.model.common.OriginalSourceType;
+import eu.etaxonomy.cdm.model.common.TermType;
+import eu.etaxonomy.cdm.model.common.TermVocabulary;
+>>>>>>> master
 import eu.etaxonomy.cdm.model.common.VerbatimTimePeriod;
+import eu.etaxonomy.cdm.model.description.Feature;
 import eu.etaxonomy.cdm.model.description.State;
 import eu.etaxonomy.cdm.model.reference.Reference;
 import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
@@ -35,6 +43,7 @@ import eu.etaxonomy.cdm.model.term.TermVocabulary;
  */
 public class PlantGlossaryCsvImportState extends CsvImportState<PlantGlossaryCsvImportConfigurator> {
 
+    private TermVocabulary<Feature> propertyVoc;
     private List<TermVocabulary> existingVocabularies = new ArrayList<>();
     private List<State> existingTerms = new ArrayList<>();
     private Set<TermVocabulary> vocabularies = new HashSet<>();
@@ -66,6 +75,10 @@ public class PlantGlossaryCsvImportState extends CsvImportState<PlantGlossaryCsv
             citation.setUri(uri);
         } catch (URISyntaxException e) {
         }
+
+        propertyVoc = TermVocabulary.NewInstance(TermType.Feature, Feature.class);
+        propertyVoc.setLabel("Plant Glossary Properties");
+        propertyVoc.addSource(IdentifiableSource.NewInstance(OriginalSourceType.Import, citation.getTitle(), null, citation, null));
     }
 
     @Override
@@ -73,6 +86,10 @@ public class PlantGlossaryCsvImportState extends CsvImportState<PlantGlossaryCsv
         super.resetSession();
     }
 
+    public TermVocabulary<Feature> getPropertyVoc() {
+        return propertyVoc;
+    }
+
     void addVocabulary(TermVocabulary vocabulary) {
         vocabularies.add(vocabulary);
     }