Revision 273e1f05
Added by Patrick Plitzner about 5 years ago
app-import/src/main/java/eu/etaxonomy/cdm/io/prometheus/PrometheusPropertiesActivator.java | ||
---|---|---|
1 |
package eu.etaxonomy.cdm.io.prometheus; |
|
2 |
|
|
3 |
import java.io.IOException; |
|
4 |
import java.net.URI; |
|
5 |
|
|
6 |
import org.apache.log4j.Logger; |
|
7 |
|
|
8 |
import eu.etaxonomy.cdm.app.common.CdmDestinations; |
|
9 |
import eu.etaxonomy.cdm.database.DatabaseTypeEnum; |
|
10 |
import eu.etaxonomy.cdm.database.DbSchemaValidation; |
|
11 |
import eu.etaxonomy.cdm.database.ICdmDataSource; |
|
12 |
import eu.etaxonomy.cdm.io.common.CdmDefaultImport; |
|
13 |
import eu.etaxonomy.cdm.io.common.IImportConfigurator.CHECK; |
|
14 |
|
|
15 |
/** |
|
16 |
* |
|
17 |
* @author pplitzner |
|
18 |
* @date 18.02.2019 |
|
19 |
* |
|
20 |
*/ |
|
21 |
public class PrometheusPropertiesActivator { |
|
22 |
@SuppressWarnings("unused") |
|
23 |
private static final Logger logger = Logger.getLogger(PrometheusPropertiesActivator.class); |
|
24 |
|
|
25 |
private void doImport(ICdmDataSource cdmDestination) throws IOException{ |
|
26 |
|
|
27 |
/* |
|
28 |
* Source file: |
|
29 |
* extracted data from xml-exported prometheus ontology |
|
30 |
*/ |
|
31 |
URI uri = URI.create("file:/home/pplitzner/projects/Additivity/prometheus_extract/new_qualitative_properties.csv"); |
|
32 |
PrometheusPropertiesCsvImportConfigurator config = PrometheusPropertiesCsvImportConfigurator.NewInstance(uri, cdmDestination); |
|
33 |
config.setCheck(CHECK.IMPORT_WITHOUT_CHECK); |
|
34 |
config.setDbSchemaValidation(DbSchemaValidation.VALIDATE); |
|
35 |
|
|
36 |
CdmDefaultImport<PrometheusPropertiesCsvImportConfigurator> myImport = new CdmDefaultImport<>(); |
|
37 |
|
|
38 |
System.out.println("Start import from ("+ cdmDestination.toString() + ") ..."); |
|
39 |
myImport.invoke(config); |
|
40 |
System.out.println("End import from ("+ cdmDestination.toString() + ")..."); |
|
41 |
} |
|
42 |
|
|
43 |
public static void main(String[] args) { |
|
44 |
PrometheusPropertiesActivator activator = new PrometheusPropertiesActivator(); |
|
45 |
try { |
|
46 |
ICdmDataSource dataSource = CdmDestinations.makeDestination(DatabaseTypeEnum.MySQL, "127.0.0.1", "empty", 3306, "root", null); |
|
47 |
// ICdmDataSource dataSource = CdmDestinations.cdm_additivity_ontology(); |
|
48 |
activator.doImport(dataSource); |
|
49 |
} catch (IOException e) { |
|
50 |
e.printStackTrace(); |
|
51 |
} |
|
52 |
} |
|
53 |
} |
app-import/src/main/java/eu/etaxonomy/cdm/io/prometheus/PrometheusPropertiesCsvImportConfigurator.java | ||
---|---|---|
1 |
/** |
|
2 |
* Copyright (C) 2017 EDIT |
|
3 |
* European Distributed Institute of Taxonomy |
|
4 |
* http://www.e-taxonomy.eu |
|
5 |
* |
|
6 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
|
7 |
* See LICENSE.TXT at the top of this package for the full license terms. |
|
8 |
*/ |
|
9 |
package eu.etaxonomy.cdm.io.prometheus; |
|
10 |
|
|
11 |
import java.io.IOException; |
|
12 |
import java.net.URI; |
|
13 |
|
|
14 |
import eu.etaxonomy.cdm.database.ICdmDataSource; |
|
15 |
import eu.etaxonomy.cdm.io.csv.in.CsvImportConfiguratorBase; |
|
16 |
|
|
17 |
/** |
|
18 |
* |
|
19 |
* @author pplitzner |
|
20 |
* @date 18.02.2019 |
|
21 |
* |
|
22 |
*/ |
|
23 |
public class PrometheusPropertiesCsvImportConfigurator |
|
24 |
extends CsvImportConfiguratorBase{ |
|
25 |
|
|
26 |
private static final long serialVersionUID = 987286481306951779L; |
|
27 |
|
|
28 |
public static PrometheusPropertiesCsvImportConfigurator NewInstance(URI source, |
|
29 |
ICdmDataSource cdmDestination) throws IOException { |
|
30 |
return new PrometheusPropertiesCsvImportConfigurator(source, cdmDestination); |
|
31 |
} |
|
32 |
|
|
33 |
// ****************** CONSTRUCTOR *****************************/ |
|
34 |
|
|
35 |
private PrometheusPropertiesCsvImportConfigurator(URI source, |
|
36 |
ICdmDataSource cdmDestination) throws IOException{ |
|
37 |
super(source, cdmDestination, null); |
|
38 |
} |
|
39 |
|
|
40 |
// ************************************* |
|
41 |
|
|
42 |
|
|
43 |
@Override |
|
44 |
@SuppressWarnings("unchecked") |
|
45 |
protected void makeIoClassList() { |
|
46 |
ioClassList = new Class[] { |
|
47 |
PrometheusPropertiesImport.class }; |
|
48 |
} |
|
49 |
|
|
50 |
@Override |
|
51 |
public PrometheusPropertiesCsvImportState getNewState() { |
|
52 |
return new PrometheusPropertiesCsvImportState(this); |
|
53 |
} |
|
54 |
|
|
55 |
} |
app-import/src/main/java/eu/etaxonomy/cdm/io/prometheus/PrometheusPropertiesCsvImportState.java | ||
---|---|---|
1 |
/** |
|
2 |
* Copyright (C) 2017 EDIT |
|
3 |
* European Distributed Institute of Taxonomy |
|
4 |
* http://www.e-taxonomy.eu |
|
5 |
* |
|
6 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
|
7 |
* See LICENSE.TXT at the top of this package for the full license terms. |
|
8 |
*/ |
|
9 |
package eu.etaxonomy.cdm.io.prometheus; |
|
10 |
|
|
11 |
import java.util.ArrayList; |
|
12 |
import java.util.List; |
|
13 |
|
|
14 |
import eu.etaxonomy.cdm.api.service.ITermService; |
|
15 |
import eu.etaxonomy.cdm.io.csv.in.CsvImportState; |
|
16 |
import eu.etaxonomy.cdm.model.agent.Person; |
|
17 |
import eu.etaxonomy.cdm.model.common.TermType; |
|
18 |
import eu.etaxonomy.cdm.model.common.TermVocabulary; |
|
19 |
import eu.etaxonomy.cdm.model.common.VerbatimTimePeriod; |
|
20 |
import eu.etaxonomy.cdm.model.description.Feature; |
|
21 |
import eu.etaxonomy.cdm.model.description.State; |
|
22 |
import eu.etaxonomy.cdm.model.reference.Reference; |
|
23 |
import eu.etaxonomy.cdm.model.reference.ReferenceFactory; |
|
24 |
|
|
25 |
/** |
|
26 |
* |
|
27 |
* @author pplitzner |
|
28 |
* @date 18.02.2019 |
|
29 |
* |
|
30 |
*/ |
|
31 |
public class PrometheusPropertiesCsvImportState extends CsvImportState<PrometheusPropertiesCsvImportConfigurator> { |
|
32 |
|
|
33 |
private List<State> existingTerms = new ArrayList<>(); |
|
34 |
private final TermVocabulary<Feature> propertiesVoc; |
|
35 |
private final Reference citation; |
|
36 |
|
|
37 |
|
|
38 |
protected PrometheusPropertiesCsvImportState(PrometheusPropertiesCsvImportConfigurator config) { |
|
39 |
super(config); |
|
40 |
propertiesVoc = TermVocabulary.NewInstance(TermType.Feature); |
|
41 |
propertiesVoc.setLabel("Properties"); |
|
42 |
|
|
43 |
citation = ReferenceFactory.newGeneric(); |
|
44 |
citation.setTitle("The Prometheus Description Model: an examination of the taxonomic description-building process and its representation."); |
|
45 |
Person author = Person.NewInstance(null, "Pullan", null, "M."); |
|
46 |
citation.setAuthorship(author); |
|
47 |
VerbatimTimePeriod datePublished = VerbatimTimePeriod.NewVerbatimInstance(); |
|
48 |
datePublished.setStartYear(2005); |
|
49 |
citation.setDatePublished(datePublished); |
|
50 |
citation.setVolume("54"); |
|
51 |
citation.setPages("751-756"); |
|
52 |
} |
|
53 |
|
|
54 |
@Override |
|
55 |
public void resetSession(){ |
|
56 |
super.resetSession(); |
|
57 |
} |
|
58 |
|
|
59 |
public boolean isTermPresent(String termName, ITermService termService) { |
|
60 |
if(existingTerms.isEmpty()){ |
|
61 |
existingTerms = termService.list(State.class, null, null, null, null); |
|
62 |
} |
|
63 |
return existingTerms.stream().map(term->term.getLabel()).anyMatch(label->label.equals(termName)); |
|
64 |
} |
|
65 |
|
|
66 |
public TermVocabulary<Feature> getPropertiesVoc() { |
|
67 |
return propertiesVoc; |
|
68 |
} |
|
69 |
|
|
70 |
Reference getCitation() { |
|
71 |
return citation; |
|
72 |
} |
|
73 |
|
|
74 |
} |
app-import/src/main/java/eu/etaxonomy/cdm/io/prometheus/PrometheusPropertiesImport.java | ||
---|---|---|
1 |
/** |
|
2 |
* Copyright (C) 2017 EDIT |
|
3 |
* European Distributed Institute of Taxonomy |
|
4 |
* http://www.e-taxonomy.eu |
|
5 |
* |
|
6 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
|
7 |
* See LICENSE.TXT at the top of this package for the full license terms. |
|
8 |
*/ |
|
9 |
package eu.etaxonomy.cdm.io.prometheus; |
|
10 |
|
|
11 |
import java.io.File; |
|
12 |
import java.util.Map; |
|
13 |
|
|
14 |
import org.apache.log4j.Logger; |
|
15 |
import org.springframework.stereotype.Component; |
|
16 |
|
|
17 |
import eu.etaxonomy.cdm.common.CdmUtils; |
|
18 |
import eu.etaxonomy.cdm.io.csv.in.CsvImportBase; |
|
19 |
import eu.etaxonomy.cdm.model.common.IdentifiableSource; |
|
20 |
import eu.etaxonomy.cdm.model.common.OriginalSourceType; |
|
21 |
import eu.etaxonomy.cdm.model.common.TermVocabulary; |
|
22 |
import eu.etaxonomy.cdm.model.description.Feature; |
|
23 |
|
|
24 |
/** |
|
25 |
* |
|
26 |
* @author pplitzner |
|
27 |
* @date 18.02.2019 |
|
28 |
* |
|
29 |
*/ |
|
30 |
@Component |
|
31 |
public class PrometheusPropertiesImport extends CsvImportBase<PrometheusPropertiesCsvImportConfigurator, PrometheusPropertiesCsvImportState, File>{ |
|
32 |
private static final long serialVersionUID = -5600766240192189822L; |
|
33 |
private static Logger logger = Logger.getLogger(PrometheusPropertiesImport.class); |
|
34 |
|
|
35 |
final String HEADER_LABEL = "NEW_QUALITATIVE_PROPERTIES - NEW_QUALITATIVE_PROPERTY - term"; |
|
36 |
|
|
37 |
@Override |
|
38 |
protected void handleSingleLine(PrometheusPropertiesCsvImportState importState) { |
|
39 |
|
|
40 |
Map<String, String> currentRecord = importState.getCurrentRecord(); |
|
41 |
|
|
42 |
String termLabel = currentRecord.get(HEADER_LABEL); |
|
43 |
//check if already present |
|
44 |
if(CdmUtils.isBlank(termLabel) || importState.isTermPresent(termLabel, getTermService())){ |
|
45 |
return; |
|
46 |
} |
|
47 |
|
|
48 |
Feature structure = Feature.NewInstance(null, termLabel, null); |
|
49 |
structure.setIdInVocabulary(termLabel); |
|
50 |
|
|
51 |
TermVocabulary vocabulary = importState.getPropertiesVoc(); |
|
52 |
vocabulary.addTerm(structure); |
|
53 |
|
|
54 |
IdentifiableSource source = IdentifiableSource.NewInstance(OriginalSourceType.Import, importState.getCitation().getTitle(), null, importState.getCitation(), null); |
|
55 |
source.setIdInSource(termLabel); |
|
56 |
structure.addSource(source); |
|
57 |
|
|
58 |
getVocabularyService().saveOrUpdate(vocabulary); |
|
59 |
getTermService().saveOrUpdate(structure); |
|
60 |
} |
|
61 |
|
|
62 |
} |
Also available in: Unified diff
Implement Prometheus properties import