Revision 59ef8f07
Added by Andreas Müller about 8 years ago
app-import/src/main/java/eu/etaxonomy/cdm/app/common/CdmDestinations.java | ||
---|---|---|
521 | 521 |
} |
522 | 522 |
|
523 | 523 |
|
524 |
public static ICdmDataSource cdm_production_edaphobase(){ |
|
525 |
DatabaseTypeEnum dbType = DatabaseTypeEnum.MySQL; |
|
526 |
String cdmServer = "160.45.63.171"; |
|
527 |
String cdmDB = "cdm_production_edaphobase"; |
|
528 |
String cdmUserName = "edit"; |
|
529 |
return makeDestination(dbType, cdmServer, cdmDB, -1, cdmUserName, null); |
|
530 |
} |
|
531 |
|
|
532 |
|
|
524 | 533 |
public static ICdmDataSource cdm_production_diptera(){ |
525 | 534 |
DatabaseTypeEnum dbType = DatabaseTypeEnum.MySQL; |
526 | 535 |
String cdmServer = "160.45.63.171"; |
app-import/src/main/java/eu/etaxonomy/cdm/app/edaphobase/EdaphobaseActivator.java | ||
---|---|---|
13 | 13 |
|
14 | 14 |
import org.apache.log4j.Logger; |
15 | 15 |
|
16 |
import eu.etaxonomy.cdm.api.service.ITermService; |
|
16 | 17 |
import eu.etaxonomy.cdm.app.common.CdmDestinations; |
17 | 18 |
import eu.etaxonomy.cdm.app.common.CdmImportSources; |
18 | 19 |
import eu.etaxonomy.cdm.database.DbSchemaValidation; |
... | ... | |
21 | 22 |
import eu.etaxonomy.cdm.io.common.IImportConfigurator.CHECK; |
22 | 23 |
import eu.etaxonomy.cdm.io.common.Source; |
23 | 24 |
import eu.etaxonomy.cdm.io.edaphobase.EdaphobaseImportConfigurator; |
25 |
import eu.etaxonomy.cdm.model.description.Feature; |
|
26 |
import eu.etaxonomy.cdm.model.description.FeatureNode; |
|
27 |
import eu.etaxonomy.cdm.model.description.FeatureTree; |
|
24 | 28 |
|
25 | 29 |
/** |
26 | 30 |
* @author a.mueller |
... | ... | |
36 | 40 |
|
37 | 41 |
static final Source edaphoSource = CdmImportSources.EDAPHOBASE(); |
38 | 42 |
|
39 |
static final ICdmDataSource cdmDestination = CdmDestinations.cdm_local_edaphobase(); |
|
43 |
// static final ICdmDataSource cdmDestination = CdmDestinations.localH2(); |
|
44 |
// static final ICdmDataSource cdmDestination = CdmDestinations.cdm_local_edaphobase(); |
|
45 |
static final ICdmDataSource cdmDestination = CdmDestinations.cdm_production_edaphobase(); |
|
40 | 46 |
|
41 | 47 |
//feature tree uuid |
42 |
public static final UUID featureTreeUuid = UUID.fromString("a543d66a-e310-4b3e-a9fa-b729afefad16");
|
|
48 |
private static final UUID featureTreeUuid = UUID.fromString("a543d66a-e310-4b3e-a9fa-b729afefad16");
|
|
43 | 49 |
private static final String featureTreeTitle = "Edaphobase Presentation Feature Tree"; |
44 | 50 |
|
45 | 51 |
//classification |
46 | 52 |
static final UUID classificationUuid = UUID.fromString("91231ebf-1c7a-47b9-a56c-b45b33137244"); |
47 | 53 |
static final String classificationTitle = "Edaphobase"; |
54 |
static final UUID secUuid = UUID.fromString("95dcb1b6-5197-4ce6-b2fa-c6482119d2ea"); |
|
55 |
static final String secundumTitle = "Edaphobase"; |
|
48 | 56 |
|
49 | 57 |
private static final boolean doTaxa = true; |
58 |
private static final boolean doSynonyms = true; |
|
59 |
private static final boolean doReferences = true; |
|
50 | 60 |
|
51 | 61 |
|
52 | 62 |
|
... | ... | |
59 | 69 |
config.setDbSchemaValidation(dbSchemaValidation); |
60 | 70 |
config.setClassificationUuid(classificationUuid); |
61 | 71 |
config.setClassificationName(classificationTitle); |
72 |
config.setEdaphobaseSecundumTitle(secundumTitle); |
|
73 |
config.setSecUuid(secUuid); |
|
62 | 74 |
config.setDoTaxa(doTaxa); |
75 |
config.setDoReferences(doReferences); |
|
76 |
config.setDoSynonyms(doSynonyms); |
|
63 | 77 |
|
64 | 78 |
CdmDefaultImport<EdaphobaseImportConfigurator> myImport = new CdmDefaultImport<EdaphobaseImportConfigurator>(); |
65 | 79 |
myImport.invoke(config); |
80 |
|
|
81 |
FeatureTree tree = makeFeatureNodes(myImport.getCdmAppController().getTermService()); |
|
82 |
myImport.getCdmAppController().getFeatureTreeService().saveOrUpdate(tree); |
|
83 |
} |
|
84 |
|
|
85 |
private FeatureTree makeFeatureNodes(ITermService service){ |
|
86 |
|
|
87 |
FeatureTree result = FeatureTree.NewInstance(featureTreeUuid); |
|
88 |
result.setTitleCache(featureTreeTitle, true); |
|
89 |
FeatureNode root = result.getRoot(); |
|
90 |
FeatureNode newNode; |
|
91 |
|
|
92 |
Feature distributionFeature = (Feature)service.find(Feature.DISTRIBUTION().getUuid()); |
|
93 |
newNode = FeatureNode.NewInstance(distributionFeature); |
|
94 |
root.addChild(newNode); |
|
95 |
|
|
96 |
return result; |
|
66 | 97 |
} |
67 | 98 |
|
68 | 99 |
/** |
app-import/src/main/java/eu/etaxonomy/cdm/io/edaphobase/EdaphobaseAuthorImport.java | ||
---|---|---|
36 | 36 |
public class EdaphobaseAuthorImport extends EdaphobaseImportBase { |
37 | 37 |
private static final long serialVersionUID = -9138378836474086070L; |
38 | 38 |
|
39 |
@SuppressWarnings("unused") |
|
40 | 39 |
private static final Logger logger = Logger.getLogger(EdaphobaseAuthorImport.class); |
41 | 40 |
|
42 | 41 |
private static final String tableName = "tax_taxon"; |
... | ... | |
94 | 93 |
String query = "SELECT DISTINCT t.tax_author_name " |
95 | 94 |
+ " FROM tax_taxon t" |
96 | 95 |
+ " WHERE TRIM(t.tax_author_name) <>'' AND t.tax_author_name IS NOT NULL"; |
96 |
|
|
97 | 97 |
ResultSet rs = state.getConfig().getSource().getResultSet(query); |
98 | 98 |
try { |
99 | 99 |
while(rs.next()){ |
app-import/src/main/java/eu/etaxonomy/cdm/io/edaphobase/EdaphobaseClassificationImport.java | ||
---|---|---|
23 | 23 |
import eu.etaxonomy.cdm.io.common.IPartitionedIO; |
24 | 24 |
import eu.etaxonomy.cdm.io.common.ResultSetPartitioner; |
25 | 25 |
import eu.etaxonomy.cdm.model.common.CdmBase; |
26 |
import eu.etaxonomy.cdm.model.name.TaxonNameBase; |
|
26 | 27 |
import eu.etaxonomy.cdm.model.reference.Reference; |
27 | 28 |
import eu.etaxonomy.cdm.model.taxon.Classification; |
28 | 29 |
import eu.etaxonomy.cdm.model.taxon.Synonym; |
29 |
import eu.etaxonomy.cdm.model.taxon.SynonymRelationshipType; |
|
30 | 30 |
import eu.etaxonomy.cdm.model.taxon.Taxon; |
31 | 31 |
import eu.etaxonomy.cdm.model.taxon.TaxonBase; |
32 | 32 |
|
... | ... | |
87 | 87 |
Set<TaxonBase> taxaToSave = new HashSet<>(); |
88 | 88 |
try { |
89 | 89 |
while (rs.next()){ |
90 |
Integer id = rs.getInt("taxon_id");
|
|
90 |
int id = rs.getInt("taxon_id");
|
|
91 | 91 |
//parentTaxonFk |
92 | 92 |
boolean isValid = rs.getBoolean("valid"); |
93 | 93 |
// boolean idDeleted = rs.getBoolean("deleted"); |
... | ... | |
97 | 97 |
// boolean isGroup = rs.getBoolean("taxonomic_group"); |
98 | 98 |
Integer parentTaxonFk = nullSafeInt(rs, "parent_taxon_fk"); |
99 | 99 |
|
100 |
if (id != null && parentTaxonFk != null){ |
|
101 |
if (isValid){ |
|
102 |
Taxon child = state.getRelatedObject(TAXON_NAMESPACE, id.toString(), Taxon.class); |
|
103 |
Taxon parent = state.getRelatedObject(TAXON_NAMESPACE, parentTaxonFk.toString(), Taxon.class); |
|
104 |
if (parent != null){ |
|
105 |
classification.addParentChild(parent, child, sourceReference, null); |
|
106 |
}else{ |
|
107 |
logger.warn("Parent taxon " + parentTaxonFk + " not found for taxon " + id ); |
|
108 |
} |
|
100 |
if (parentTaxonFk != null){ |
|
101 |
TaxonBase<?> parent = state.getRelatedObject(TAXON_NAMESPACE, parentTaxonFk.toString(), TaxonBase.class); |
|
102 |
if (parent == null){ |
|
103 |
logger.warn("Parent taxon " + parentTaxonFk + " not found for taxon " + id ); |
|
109 | 104 |
}else{ |
110 |
Synonym synonym = state.getRelatedObject(TAXON_NAMESPACE, id.toString(), Synonym.class); |
|
111 |
if (synonym == null){ |
|
112 |
logger.warn("Synonym " + id + " not found for taxon "); |
|
113 |
} |
|
114 |
Taxon accepted = state.getRelatedObject(TAXON_NAMESPACE, parentTaxonFk.toString(), Taxon.class); |
|
115 |
if (accepted != null){ |
|
116 |
accepted.addSynonym(synonym, SynonymRelationshipType.SYNONYM_OF()); |
|
105 |
|
|
106 |
TaxonNameBase<?,?> parentName = parent.getName(); |
|
107 |
|
|
108 |
TaxonBase<?> child = state.getRelatedObject(TAXON_NAMESPACE, String.valueOf(id), TaxonBase.class); |
|
109 |
// TaxonNameBase<?,?> childName = child.getName(); |
|
110 |
|
|
111 |
// handleMissingNameParts(CdmBase.deproxy(childName, NonViralName.class), CdmBase.deproxy(parentName, NonViralName.class)); |
|
112 |
|
|
113 |
if (isValid){ |
|
114 |
if (parent.isInstanceOf(Synonym.class)){ |
|
115 |
logger.warn("Parent taxon (" + parentTaxonFk + " is not valid for valid child " + id); |
|
116 |
}else{ |
|
117 |
Taxon accParent = CdmBase.deproxy(parent, Taxon.class); |
|
118 |
classification.addParentChild(accParent, (Taxon)child, sourceReference, null); |
|
119 |
taxaToSave.add(accParent); |
|
120 |
} |
|
117 | 121 |
}else{ |
118 |
logger.warn("Accepted(parent) taxon " + parentTaxonFk + " not found for taxon " + id ); |
|
122 |
// Synonym synonym = CdmBase.deproxy(child, Synonym.class); |
|
123 |
// if (synonym == null){ |
|
124 |
// logger.warn("Synonym " + id + " not found for taxon "); |
|
125 |
// } |
|
126 |
// if(parent.isInstanceOf(Synonym.class)){ |
|
127 |
// String message = "Taxon ("+parentTaxonFk+") is not accepted but synonym. Can't add synonym ("+id+")"; |
|
128 |
// logger.warn(message); |
|
129 |
// }else{ |
|
130 |
// Taxon accepted = CdmBase.deproxy(parent, Taxon.class); |
|
131 |
//// accepted.addSynonym(synonym, SynonymRelationshipType.SYNONYM_OF()); |
|
132 |
// taxaToSave.add(accepted); |
|
133 |
// } |
|
119 | 134 |
} |
120 | 135 |
} |
121 |
|
|
122 | 136 |
} |
123 | 137 |
|
124 | 138 |
// //id |
... | ... | |
129 | 143 |
|
130 | 144 |
} |
131 | 145 |
} catch (SQLException e) { |
132 |
// TODO Auto-generated catch block |
|
133 | 146 |
e.printStackTrace(); |
134 | 147 |
} |
135 | 148 |
|
... | ... | |
137 | 150 |
return true; |
138 | 151 |
} |
139 | 152 |
|
153 |
// /** |
|
154 |
// * @param childName |
|
155 |
// * @param parentName |
|
156 |
// */ |
|
157 |
// private void handleMissingNameParts(NonViralName<?> childName, NonViralName<?> parentName) { |
|
158 |
// if (childName.getGenusOrUninomial()) |
|
159 |
// } |
|
160 |
|
|
140 | 161 |
@Override |
141 | 162 |
public Map<Object, Map<String, ? extends CdmBase>> getRelatedObjectsForPartition(ResultSet rs, |
142 | 163 |
EdaphobaseImportState state) { |
app-import/src/main/java/eu/etaxonomy/cdm/io/edaphobase/EdaphobaseImportBase.java | ||
---|---|---|
24 | 24 |
|
25 | 25 |
protected static final String TAXON_NAMESPACE = "tax_taxon"; |
26 | 26 |
protected static final String CLASSIFICATION_NAMESPACE = "Classification"; |
27 |
protected static final String REFERENCE_NAMESPACE = "lit_document"; |
|
27 | 28 |
|
28 | 29 |
/** |
29 | 30 |
* @param tableName |
app-import/src/main/java/eu/etaxonomy/cdm/io/edaphobase/EdaphobaseImportConfigurator.java | ||
---|---|---|
36 | 36 |
public boolean isDoTaxa() {return doTaxa;} |
37 | 37 |
public void setDoTaxa(boolean doTaxa) {this.doTaxa = doTaxa;} |
38 | 38 |
|
39 |
private boolean doSynonyms = true; |
|
40 |
public boolean isDoSynonyms() {return doSynonyms;} |
|
41 |
public void setDoSynonyms(boolean doSynonyms) {this.doSynonyms = doSynonyms;} |
|
42 |
|
|
43 |
private boolean doReferences = true; |
|
44 |
public boolean isDoReferences() {return doReferences;} |
|
45 |
public void setDoReferences(boolean doReferences) {this.doReferences = doReferences;} |
|
46 |
|
|
47 |
private String edaphobaseSecundumTitle; |
|
48 |
public String getEdaphobaseSecundumTitle() {return edaphobaseSecundumTitle;} |
|
49 |
public void setEdaphobaseSecundumTitle(String edaphobaseSecundumTitle) {this.edaphobaseSecundumTitle = edaphobaseSecundumTitle;} |
|
50 |
|
|
39 | 51 |
|
40 | 52 |
/** |
41 | 53 |
* @param source |
... | ... | |
62 | 74 |
protected void makeIoClassList() { |
63 | 75 |
ioClassList = new Class[]{ |
64 | 76 |
EdaphobaseAuthorImport.class, |
77 |
EdaphobaseReferenceImport.class, |
|
78 |
EdaphobaseInReferenceImport.class, |
|
65 | 79 |
EdaphobaseTaxonImport.class, |
80 |
EdaphobaseSynonymyImport.class, |
|
66 | 81 |
EdaphobaseClassificationImport.class |
67 | 82 |
}; |
68 | 83 |
} |
... | ... | |
74 | 89 |
return sourceRef; |
75 | 90 |
} |
76 | 91 |
|
92 |
|
|
77 | 93 |
} |
app-import/src/main/java/eu/etaxonomy/cdm/io/edaphobase/EdaphobaseInReferenceImport.java | ||
---|---|---|
1 |
// $Id$ |
|
2 |
/** |
|
3 |
* Copyright (C) 2015 EDIT |
|
4 |
* European Distributed Institute of Taxonomy |
|
5 |
* http://www.e-taxonomy.eu |
|
6 |
* |
|
7 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
|
8 |
* See LICENSE.TXT at the top of this package for the full license terms. |
|
9 |
*/ |
|
10 |
package eu.etaxonomy.cdm.io.edaphobase; |
|
11 |
|
|
12 |
import java.sql.ResultSet; |
|
13 |
import java.sql.SQLException; |
|
14 |
import java.util.HashMap; |
|
15 |
import java.util.HashSet; |
|
16 |
import java.util.Map; |
|
17 |
import java.util.Set; |
|
18 |
|
|
19 |
import org.apache.log4j.Logger; |
|
20 |
import org.springframework.stereotype.Component; |
|
21 |
|
|
22 |
import eu.etaxonomy.cdm.io.common.IPartitionedIO; |
|
23 |
import eu.etaxonomy.cdm.io.common.ResultSetPartitioner; |
|
24 |
import eu.etaxonomy.cdm.model.common.CdmBase; |
|
25 |
import eu.etaxonomy.cdm.model.reference.Reference; |
|
26 |
|
|
27 |
/** |
|
28 |
* @author a.mueller |
|
29 |
* @date 18.12.2015 |
|
30 |
* |
|
31 |
*/ |
|
32 |
@Component |
|
33 |
public class EdaphobaseInReferenceImport extends EdaphobaseImportBase { |
|
34 |
private static final long serialVersionUID = 6895687693249076160L; |
|
35 |
|
|
36 |
private static final Logger logger = Logger.getLogger(EdaphobaseInReferenceImport.class); |
|
37 |
|
|
38 |
private static final String tableName = "lit_document"; |
|
39 |
|
|
40 |
private static final String pluralString = "documents"; |
|
41 |
|
|
42 |
/** |
|
43 |
* @param tableName |
|
44 |
* @param pluralString |
|
45 |
*/ |
|
46 |
public EdaphobaseInReferenceImport() { |
|
47 |
super(tableName, pluralString); |
|
48 |
} |
|
49 |
|
|
50 |
@Override |
|
51 |
protected String getIdQuery(EdaphobaseImportState state) { |
|
52 |
return " SELECT DISTINCT document_id " |
|
53 |
+ " FROM lit_document ld INNER JOIN tax_taxon t ON t.tax_document = ld.document_id " |
|
54 |
+ " WHERE ld.parent_document_fk_document_id IS NOT NULL " |
|
55 |
+ " ORDER BY document_id "; |
|
56 |
} |
|
57 |
|
|
58 |
@Override |
|
59 |
protected String getRecordQuery(EdaphobaseImportConfigurator config) { |
|
60 |
String result = " SELECT document_id, parent_document_fk_document_id " |
|
61 |
+ " FROM lit_document ld " |
|
62 |
+ " WHERE ld.document_id IN (@IDSET)"; |
|
63 |
result = result.replace("@IDSET", IPartitionedIO.ID_LIST_TOKEN); |
|
64 |
return result; |
|
65 |
} |
|
66 |
|
|
67 |
@Override |
|
68 |
public boolean doPartition(ResultSetPartitioner partitioner, EdaphobaseImportState state) { |
|
69 |
ResultSet rs = partitioner.getResultSet(); |
|
70 |
Set<Reference> referencesToSave = new HashSet<>(); |
|
71 |
try { |
|
72 |
while (rs.next()){ |
|
73 |
handleSingleReference(state, rs, referencesToSave); |
|
74 |
} |
|
75 |
} catch (SQLException e) { |
|
76 |
e.printStackTrace(); |
|
77 |
} |
|
78 |
getReferenceService().saveOrUpdate(referencesToSave); |
|
79 |
return true; |
|
80 |
} |
|
81 |
|
|
82 |
/** |
|
83 |
* @param state |
|
84 |
* @param rs |
|
85 |
* @param referencesToSave |
|
86 |
* @throws SQLException |
|
87 |
*/ |
|
88 |
private void handleSingleReference(EdaphobaseImportState state, ResultSet rs, Set<Reference> referencesToSave) throws SQLException { |
|
89 |
Integer id = rs.getInt("document_id"); |
|
90 |
Integer parentId = rs.getInt("parent_document_fk_document_id"); |
|
91 |
// Integer documentType = nullSafeInt(rs, "document_type"); |
|
92 |
|
|
93 |
Reference<?> child = state.getRelatedObject(REFERENCE_NAMESPACE, String.valueOf(id), Reference.class); |
|
94 |
Reference<?> parent = state.getRelatedObject(REFERENCE_NAMESPACE, String.valueOf(parentId), Reference.class); |
|
95 |
if (child == null){ |
|
96 |
logger.warn("Child reference for document_id " + id + " is NULL" ); |
|
97 |
}else if (parent == null){ |
|
98 |
logger.warn("Parent reference for document_type_fk_document_type_id " + parentId + " is NULL" ); |
|
99 |
}else{ |
|
100 |
child.setInReference(parent); |
|
101 |
referencesToSave.add(child); |
|
102 |
} |
|
103 |
} |
|
104 |
|
|
105 |
@Override |
|
106 |
public Map<Object, Map<String, ? extends CdmBase>> getRelatedObjectsForPartition(ResultSet rs, |
|
107 |
EdaphobaseImportState state) { |
|
108 |
Map<Object, Map<String, ? extends CdmBase>> result = new HashMap<>(); |
|
109 |
Set<String> referenceIdSet = new HashSet<String>(); |
|
110 |
|
|
111 |
try { |
|
112 |
while (rs.next()){ |
|
113 |
handleForeignKey(rs, referenceIdSet, "document_id"); |
|
114 |
handleForeignKey(rs, referenceIdSet, "parent_document_fk_document_id"); |
|
115 |
} |
|
116 |
} catch (SQLException e) { |
|
117 |
e.printStackTrace(); |
|
118 |
} |
|
119 |
|
|
120 |
//reference map |
|
121 |
String nameSpace = REFERENCE_NAMESPACE; |
|
122 |
Class<?> cdmClass = Reference.class; |
|
123 |
Set<String> idSet = referenceIdSet; |
|
124 |
Map<String, Reference> referenceMap = (Map<String, Reference>)getCommonService().getSourcedObjectsByIdInSource(cdmClass, idSet, nameSpace); |
|
125 |
result.put(nameSpace, referenceMap); |
|
126 |
|
|
127 |
return result; |
|
128 |
} |
|
129 |
|
|
130 |
|
|
131 |
|
|
132 |
@Override |
|
133 |
protected boolean doCheck(EdaphobaseImportState state) { |
|
134 |
return false; |
|
135 |
} |
|
136 |
|
|
137 |
@Override |
|
138 |
protected boolean isIgnore(EdaphobaseImportState state) { |
|
139 |
return ! state.getConfig().isDoReferences(); |
|
140 |
} |
|
141 |
|
|
142 |
} |
app-import/src/main/java/eu/etaxonomy/cdm/io/edaphobase/EdaphobaseReferenceImport.java | ||
---|---|---|
13 | 13 |
import java.sql.SQLException; |
14 | 14 |
import java.util.HashMap; |
15 | 15 |
import java.util.HashSet; |
16 |
import java.util.List; |
|
17 | 16 |
import java.util.Map; |
18 | 17 |
import java.util.Set; |
19 |
import java.util.UUID; |
|
20 | 18 |
|
19 |
import org.apache.commons.lang3.StringUtils; |
|
21 | 20 |
import org.apache.log4j.Logger; |
22 |
import org.codehaus.plexus.util.StringUtils; |
|
23 | 21 |
import org.springframework.stereotype.Component; |
24 | 22 |
|
23 |
import eu.etaxonomy.cdm.common.DOI; |
|
25 | 24 |
import eu.etaxonomy.cdm.io.common.IPartitionedIO; |
26 | 25 |
import eu.etaxonomy.cdm.io.common.ImportHelper; |
27 | 26 |
import eu.etaxonomy.cdm.io.common.ResultSetPartitioner; |
28 |
import eu.etaxonomy.cdm.io.common.mapping.UndefinedTransformerMethodException; |
|
29 |
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase; |
|
30 | 27 |
import eu.etaxonomy.cdm.model.common.CdmBase; |
31 |
import eu.etaxonomy.cdm.model.name.Rank; |
|
32 |
import eu.etaxonomy.cdm.model.name.ZoologicalName; |
|
28 |
import eu.etaxonomy.cdm.model.common.TimePeriod; |
|
33 | 29 |
import eu.etaxonomy.cdm.model.reference.Reference; |
34 |
import eu.etaxonomy.cdm.model.taxon.Synonym; |
|
35 |
import eu.etaxonomy.cdm.model.taxon.Taxon; |
|
36 |
import eu.etaxonomy.cdm.model.taxon.TaxonBase; |
|
30 |
import eu.etaxonomy.cdm.model.reference.ReferenceFactory; |
|
37 | 31 |
|
38 | 32 |
/** |
39 | 33 |
* @author a.mueller |
... | ... | |
42 | 36 |
*/ |
43 | 37 |
@Component |
44 | 38 |
public class EdaphobaseReferenceImport extends EdaphobaseImportBase { |
45 |
private static final long serialVersionUID = -9138378836474086070L; |
|
46 |
private static final Logger logger = Logger.getLogger(EdaphobaseReferenceImport.class); |
|
39 |
private static final long serialVersionUID = 6895687693249076160L; |
|
47 | 40 |
|
48 |
private static final String tableName = "tax_taxon"; |
|
41 |
@SuppressWarnings("unused") |
|
42 |
private static final Logger logger = Logger.getLogger(EdaphobaseReferenceImport.class); |
|
49 | 43 |
|
50 |
private static final String pluralString = "taxa";
|
|
44 |
private static final String tableName = "lit_document";
|
|
51 | 45 |
|
52 |
private static final Object AUTHOR_NAMESPACE = "tax_author_name"; |
|
46 |
private static final String pluralString = "documents"; |
|
47 |
// |
|
48 |
// private static final Object AUTHOR_NAMESPACE = "tax_author_name"; |
|
53 | 49 |
|
54 | 50 |
/** |
55 | 51 |
* @param tableName |
... | ... | |
61 | 57 |
|
62 | 58 |
@Override |
63 | 59 |
protected String getIdQuery(EdaphobaseImportState state) { |
64 |
return "SELECT DISTINCT taxon_id FROM tax_taxon t " |
|
65 |
+ " ORDER BY taxon_id"; |
|
60 |
return " SELECT DISTINCT document_id " |
|
61 |
+ " FROM lit_document ld INNER JOIN tax_taxon t ON t.tax_document = ld.document_id " |
|
62 |
+ " UNION " |
|
63 |
+ " SELECT DISTINCT pd.document_id " |
|
64 |
+ " FROM lit_document ld INNER JOIN tax_taxon t ON t.tax_document = ld.document_id " |
|
65 |
+ " INNER JOIN lit_document pd ON pd.document_id = ld.parent_document_fk_document_id " |
|
66 |
+ " ORDER BY document_id "; |
|
66 | 67 |
} |
67 | 68 |
|
68 | 69 |
@Override |
69 | 70 |
protected String getRecordQuery(EdaphobaseImportConfigurator config) { |
70 |
String result = " SELECT DISTINCT t.*, r.value as rankStr, pr.value as parentRankStr, ppr.value as grandParentRankStr, " |
|
71 |
+ " pt.name as parentName, ppt.name as grandParentName " |
|
72 |
+ " FROM tax_taxon t " |
|
73 |
+ " LEFT JOIN tax_taxon pt ON t.parent_taxon_fk = pt.taxon_id " |
|
74 |
+ " LEFT JOIN tax_taxon ppt ON pt.parent_taxon_fk = ppt.taxon_id" |
|
75 |
+ " LEFT OUTER JOIN tax_rank_en r ON r.element_id = t.tax_rank_fk " |
|
76 |
+ " LEFT OUTER JOIN tax_rank_en pr ON pr.element_id = pt.tax_rank_fk " |
|
77 |
+ " LEFT OUTER JOIN tax_rank_en ppr ON pr.element_id = ppt.tax_rank_fk " |
|
78 |
+ " WHERE t.taxon_id IN (@IDSET)"; |
|
71 |
String result = " SELECT * " |
|
72 |
+ " FROM lit_document ld " |
|
73 |
+ " WHERE ld.document_id IN (@IDSET)"; |
|
79 | 74 |
result = result.replace("@IDSET", IPartitionedIO.ID_LIST_TOKEN); |
80 | 75 |
return result; |
81 | 76 |
} |
82 | 77 |
|
83 |
@Override |
|
84 |
protected void doInvoke(EdaphobaseImportState state) { |
|
85 |
super.doInvoke(state); |
|
86 |
} |
|
87 |
|
|
88 |
|
|
89 | 78 |
@Override |
90 | 79 |
public boolean doPartition(ResultSetPartitioner partitioner, EdaphobaseImportState state) { |
91 | 80 |
ResultSet rs = partitioner.getResultSet(); |
92 |
Set<TaxonBase> taxaToSave = new HashSet<>();
|
|
81 |
Set<Reference> referencesToSave = new HashSet<>();
|
|
93 | 82 |
try { |
94 | 83 |
while (rs.next()){ |
95 |
// // "JPASampleBook" |
|
96 |
// // "JPAJournal" |
|
97 |
// // "JPASample" |
|
98 |
// "JPAThesis" |
|
99 |
// // "JPALitOther" |
|
100 |
// // "JPACollection" |
|
101 |
// // "JPADocument" |
|
102 |
// // "JPABibliography" |
|
103 |
// // "JPAProject" |
|
104 |
// // "JPARawData" |
|
105 |
// "JPAArticle" |
|
106 |
// "JPABook" |
|
107 |
// "JPAChapter" |
|
108 |
// // "JPACollectionObject" |
|
109 |
// // "JPACollectionContainer" |
|
110 |
|
|
111 |
|
|
112 |
|
|
113 |
Integer id = nullSafeInt(rs, "taxon_id"); |
|
114 |
Integer year = nullSafeInt(rs, "tax_year"); |
|
115 |
boolean isBrackets = rs.getBoolean("tax_brackets"); |
|
116 |
String remark = rs.getString("remark"); |
|
117 |
String nameStr = rs.getString("name"); |
|
118 |
String authorName = rs.getString("tax_author_name"); |
|
119 |
//parentTaxonFk |
|
120 |
//rankFk |
|
121 |
//document |
|
122 |
boolean isValid = rs.getBoolean("valid"); |
|
123 |
boolean idDeleted = rs.getBoolean("deleted"); |
|
124 |
String displayString = rs.getString("display_string"); |
|
125 |
Integer version = nullSafeInt(rs, "versionfield"); |
|
126 |
String pages = rs.getString("pages"); |
|
127 |
String treeIndex = rs.getString("path_to_root"); |
|
128 |
// Integer rankFk = nullSafeInt(rs, "tax_rank_fk"); |
|
129 |
String nameAddition = rs.getString("name_addition"); |
|
130 |
String officialRemark = rs.getString("official_remark"); |
|
131 |
boolean isGroup = rs.getBoolean("taxonomic_group"); |
|
132 |
String rankStr = rs.getString("rankStr"); |
|
133 |
String parentRankStr = rs.getString("parentRankStr"); |
|
134 |
String grandParentRankStr = rs.getString("grandParentRankStr"); |
|
135 |
String parentNameStr = rs.getString("parentName"); |
|
136 |
String grandParentNameStr = rs.getString("grandParentName"); |
|
137 |
|
|
138 |
|
|
139 |
TaxonBase<?> taxonBase; |
|
140 |
Reference<?> sec = null; //TODO |
|
141 |
|
|
142 |
//Name etc. |
|
143 |
Rank rank = makeRank(state, rankStr); |
|
144 |
ZoologicalName name = ZoologicalName.NewInstance(rank); |
|
145 |
setNamePart(nameStr, rank, name); |
|
146 |
Rank parentRank = makeRank(state, parentRankStr); |
|
147 |
setNamePart(parentNameStr, parentRank, name); |
|
148 |
Rank parentParentRank = makeRank(state, grandParentRankStr); |
|
149 |
setNamePart(grandParentNameStr, parentParentRank, name); |
|
150 |
|
|
151 |
//Authors |
|
152 |
if (StringUtils.isNotBlank(authorName)){ |
|
153 |
TeamOrPersonBase<?> author = state.getRelatedObject(AUTHOR_NAMESPACE, authorName, TeamOrPersonBase.class); |
|
154 |
if (author == null){ |
|
155 |
logger.warn("Author not found in state: " + authorName); |
|
156 |
}else{ |
|
157 |
if (isBrackets){ |
|
158 |
name.setBasionymAuthorship(author); |
|
159 |
name.setOriginalPublicationYear(year); |
|
160 |
}else{ |
|
161 |
name.setCombinationAuthorship(author); |
|
162 |
name.setPublicationYear(year); |
|
163 |
} |
|
164 |
} |
|
165 |
} |
|
166 | 84 |
|
167 |
|
|
168 |
if (isValid){ |
|
169 |
taxonBase = Taxon.NewInstance(name, sec); |
|
170 |
}else{ |
|
171 |
taxonBase = Synonym.NewInstance(name, sec); |
|
172 |
} |
|
173 |
taxaToSave.add(taxonBase); |
|
174 |
|
|
175 |
//remarks |
|
176 |
doNotes(taxonBase, remark); |
|
177 |
|
|
178 |
//id |
|
179 |
ImportHelper.setOriginalSource(taxonBase, state.getTransactionalSourceReference(), id, TAXON_NAMESPACE); |
|
180 |
ImportHelper.setOriginalSource(name, state.getTransactionalSourceReference(), id, TAXON_NAMESPACE); |
|
85 |
handleSingleReference(state, rs, referencesToSave); |
|
181 | 86 |
|
182 | 87 |
} |
183 | 88 |
} catch (SQLException e) { |
... | ... | |
185 | 90 |
e.printStackTrace(); |
186 | 91 |
} |
187 | 92 |
|
188 |
getTaxonService().saveOrUpdate(taxaToSave); |
|
93 |
getReferenceService().saveOrUpdate(referencesToSave); |
|
94 |
|
|
189 | 95 |
return true; |
190 | 96 |
} |
191 | 97 |
|
192 |
|
|
193 |
@Override |
|
194 |
public Map<Object, Map<String, ? extends CdmBase>> getRelatedObjectsForPartition(ResultSet rs, |
|
195 |
EdaphobaseImportState state) { |
|
196 |
Map<Object, Map<String, ? extends CdmBase>> result = new HashMap<>(); |
|
197 |
Map<String, TeamOrPersonBase<?>> authorMap = new HashMap<>(); |
|
198 |
Set<String> authorSet = new HashSet<>(); |
|
199 |
try { |
|
200 |
while (rs.next()){ |
|
201 |
String authorStr = rs.getString("tax_author_name"); |
|
202 |
authorSet.add(authorStr); |
|
203 |
} |
|
204 |
} catch (SQLException e) { |
|
205 |
e.printStackTrace(); |
|
98 |
/** |
|
99 |
* @param state |
|
100 |
* @param rs |
|
101 |
* @param referencesToSave |
|
102 |
* @throws SQLException |
|
103 |
*/ |
|
104 |
private void handleSingleReference(EdaphobaseImportState state, ResultSet rs, Set<Reference> referencesToSave) throws SQLException { |
|
105 |
Integer id = nullSafeInt(rs, "document_id"); |
|
106 |
String dtype = rs.getString("dtype"); |
|
107 |
String issue = rs.getString("issue"); |
|
108 |
String orderer = rs.getString("orderer"); |
|
109 |
String place = rs.getString("place"); |
|
110 |
Integer pageFrom = nullSafeInt(rs, "page_from"); |
|
111 |
Integer pageTo = nullSafeInt(rs, "page_to"); |
|
112 |
String subtitle = rs.getString("subtitle"); |
|
113 |
Integer year = nullSafeInt(rs, "year"); |
|
114 |
String isbn = rs.getString("isbn"); |
|
115 |
//refers_to_literature |
|
116 |
//refers_to_collection |
|
117 |
//refers_to_observation |
|
118 |
String remark = rs.getString("remark"); |
|
119 |
String volume = rs.getString("volume"); |
|
120 |
//abbreviation (no record) |
|
121 |
String title = rs.getString("title"); |
|
122 |
String issn = rs.getString("issn"); |
|
123 |
//circulation //2 records |
|
124 |
String keywords = rs.getString("keywords"); |
|
125 |
String abstractt = rs.getString("abstract"); |
|
126 |
String parallel_title = rs.getString("parallel_title"); |
|
127 |
//language_fk_language_id |
|
128 |
//document_type_fk_document_type_id |
|
129 |
//editor_fk_person_id |
|
130 |
Integer editorFk = nullSafeInt(rs, "editor_fk_person_id"); |
|
131 |
|
|
132 |
// Integer parentFk = nullSafeInt(rs, "parent_document_fk_document_id"); |
|
133 |
//publisher_fk_publisher_id |
|
134 |
//deleted |
|
135 |
//chapter_no |
|
136 |
//versionfield |
|
137 |
String doi = rs.getString("doi"); |
|
138 |
String displayString = rs.getString("display_string"); |
|
139 |
//aquisistion_date, aquisition_type, adoption_date, ex_colletion, barcode_prefix, barcode_org_prefix |
|
140 |
//barcode_type, collection_status, barcode, typus_form, |
|
141 |
|
|
142 |
//taxon_for_scope, taxon_is_scope |
|
143 |
//language_fk, document_type_backup |
|
144 |
|
|
145 |
Integer documentType = nullSafeInt(rs, "document_type"); |
|
146 |
//normalized_title, normalized_abk_official_remark |
|
147 |
|
|
148 |
Reference<?> ref = makeReferenceType(documentType, dtype); |
|
149 |
ref.setTitle(title); |
|
150 |
ref.setPlacePublished(place); |
|
151 |
ref.setIssn(issn); |
|
152 |
ref.setIsbn(isbn); |
|
153 |
if (pageFrom != null || pageTo != null){ |
|
154 |
String pageStr = pageFrom == null ? "" : String.valueOf(pageFrom); |
|
155 |
pageStr = pageTo == null ? pageStr : "-" + pageTo; |
|
156 |
ref.setPages(pageStr); |
|
206 | 157 |
} |
207 |
|
|
208 |
//Authors |
|
209 |
Set<UUID> uuidSet = new HashSet<>(); |
|
210 |
for (String authorStr : authorSet){ |
|
211 |
UUID uuid = state.getAuthorUuid(authorStr); |
|
212 |
uuidSet.add(uuid); |
|
158 |
if (year != null){ |
|
159 |
ref.setDatePublished(TimePeriod.NewInstance(year)); |
|
213 | 160 |
} |
214 |
List<TeamOrPersonBase<?>> authors = (List)getAgentService().find(uuidSet); |
|
215 |
Map<UUID, TeamOrPersonBase<?>> authorUuidMap = new HashMap<>(); |
|
216 |
for (TeamOrPersonBase<?> author : authors){ |
|
217 |
authorUuidMap.put(author.getUuid(), author); |
|
161 |
ref.setVolume(volume); |
|
162 |
ref.setReferenceAbstract(abstractt); |
|
163 |
if (StringUtils.isNotBlank(doi)){ |
|
164 |
try { |
|
165 |
String doiStr = doi; |
|
166 |
if (doiStr.startsWith("dx.doi.org/")){ |
|
167 |
doiStr = doiStr.substring(11); |
|
168 |
} |
|
169 |
ref.setDoi(DOI.fromString(doiStr)); |
|
170 |
} catch (IllegalArgumentException e) { |
|
171 |
logger.warn("DOI could not be parsed: " + doi); |
|
172 |
} |
|
218 | 173 |
} |
174 |
ref.setEdition(issue); |
|
219 | 175 |
|
220 |
for (String authorStr : authorSet){ |
|
221 |
UUID uuid = state.getAuthorUuid(authorStr); |
|
222 |
TeamOrPersonBase<?> author = authorUuidMap.get(uuid); |
|
223 |
authorMap.put(authorStr, author); |
|
224 |
} |
|
225 |
result.put(AUTHOR_NAMESPACE, authorMap); |
|
176 |
//id |
|
177 |
ImportHelper.setOriginalSource(ref, state.getTransactionalSourceReference(), id, REFERENCE_NAMESPACE); |
|
226 | 178 |
|
227 |
return result;
|
|
179 |
referencesToSave.add(ref);
|
|
228 | 180 |
} |
229 | 181 |
|
230 |
private void setNamePart(String nameStr, Rank rank, ZoologicalName name) { |
|
231 |
if (rank != null){ |
|
232 |
if (rank.isSupraGeneric() || rank.isGenus()){ |
|
233 |
if (StringUtils.isBlank(name.getGenusOrUninomial())){ |
|
234 |
name.setGenusOrUninomial(nameStr); |
|
235 |
} |
|
236 |
}else if (rank.isInfraGeneric()){ |
|
237 |
if (StringUtils.isBlank(name.getInfraGenericEpithet())){ |
|
238 |
name.setInfraGenericEpithet(nameStr); |
|
239 |
} |
|
240 |
}else if (rank.isSpeciesAggregate() || rank.isSpecies()){ |
|
241 |
if (StringUtils.isBlank(name.getSpecificEpithet())){ |
|
242 |
name.setSpecificEpithet(nameStr); |
|
243 |
} |
|
244 |
}else if (rank.isInfraSpecific()){ |
|
245 |
if (StringUtils.isBlank(name.getInfraSpecificEpithet())){ |
|
246 |
name.setInfraSpecificEpithet(nameStr); |
|
247 |
} |
|
248 |
} |
|
182 |
|
|
183 |
/** |
|
184 |
* @param documentType |
|
185 |
* @return |
|
186 |
*/ |
|
187 |
private Reference<?> makeReferenceType(Integer documentType, String dtype) { |
|
188 |
if (documentType == 11914){ |
|
189 |
return ReferenceFactory.newArticle(); |
|
190 |
} else if (documentType == 11916){ |
|
191 |
return ReferenceFactory.newBook(); |
|
192 |
} else if (documentType == 11915){ |
|
193 |
return ReferenceFactory.newPrintSeries(); |
|
194 |
} else if (documentType == 11913){ |
|
195 |
return ReferenceFactory.newJournal(); |
|
196 |
} else if (documentType == 11917){ |
|
197 |
return ReferenceFactory.newBookSection(); |
|
198 |
} else if (documentType == 11912 || documentType == 11919 || documentType == 11924 ){ |
|
199 |
Reference<?> ref = ReferenceFactory.newGeneric(); |
|
200 |
return ref; |
|
201 |
} else { |
|
202 |
throw new RuntimeException("DocumentType not yet supported: " + documentType + ", " + dtype); |
|
249 | 203 |
} |
250 | 204 |
} |
251 | 205 |
|
252 |
private Rank makeRank(EdaphobaseImportState state, String rankStr) { |
|
253 |
Rank rank = null; |
|
254 |
try { |
|
255 |
rank = state.getTransformer().getRankByKey(rankStr); |
|
256 |
} catch (UndefinedTransformerMethodException e) { |
|
257 |
e.printStackTrace(); |
|
258 |
} |
|
259 |
return rank; |
|
206 |
@Override |
|
207 |
public Map<Object, Map<String, ? extends CdmBase>> getRelatedObjectsForPartition(ResultSet rs, |
|
208 |
EdaphobaseImportState state) { |
|
209 |
Map<Object, Map<String, ? extends CdmBase>> result = new HashMap<>(); |
|
210 |
// Map<String, TeamOrPersonBase<?>> authorMap = new HashMap<>(); |
|
211 |
// Set<String> authorSet = new HashSet<>(); |
|
212 |
// try { |
|
213 |
// while (rs.next()){ |
|
214 |
// String authorStr = rs.getString("tax_author_name"); |
|
215 |
// authorSet.add(authorStr); |
|
216 |
// } |
|
217 |
// } catch (SQLException e) { |
|
218 |
// e.printStackTrace(); |
|
219 |
// } |
|
220 |
// |
|
221 |
// //Authors |
|
222 |
// Set<UUID> uuidSet = new HashSet<>(); |
|
223 |
// for (String authorStr : authorSet){ |
|
224 |
// UUID uuid = state.getAuthorUuid(authorStr); |
|
225 |
// uuidSet.add(uuid); |
|
226 |
// } |
|
227 |
// List<TeamOrPersonBase<?>> authors = (List)getAgentService().find(uuidSet); |
|
228 |
// Map<UUID, TeamOrPersonBase<?>> authorUuidMap = new HashMap<>(); |
|
229 |
// for (TeamOrPersonBase<?> author : authors){ |
|
230 |
// authorUuidMap.put(author.getUuid(), author); |
|
231 |
// } |
|
232 |
// |
|
233 |
// for (String authorStr : authorSet){ |
|
234 |
// UUID uuid = state.getAuthorUuid(authorStr); |
|
235 |
// TeamOrPersonBase<?> author = authorUuidMap.get(uuid); |
|
236 |
// authorMap.put(authorStr, author); |
|
237 |
// } |
|
238 |
// result.put(AUTHOR_NAMESPACE, authorMap); |
|
239 |
|
|
240 |
return result; |
|
260 | 241 |
} |
261 | 242 |
|
243 |
|
|
244 |
|
|
262 | 245 |
@Override |
263 | 246 |
protected boolean doCheck(EdaphobaseImportState state) { |
264 | 247 |
return false; |
... | ... | |
266 | 249 |
|
267 | 250 |
@Override |
268 | 251 |
protected boolean isIgnore(EdaphobaseImportState state) { |
269 |
return ! state.getConfig().isDoTaxa();
|
|
252 |
return ! state.getConfig().isDoReferences();
|
|
270 | 253 |
} |
271 | 254 |
|
272 | 255 |
} |
app-import/src/main/java/eu/etaxonomy/cdm/io/edaphobase/EdaphobaseSynonymyImport.java | ||
---|---|---|
1 |
// $Id$ |
|
2 |
/** |
|
3 |
* Copyright (C) 2015 EDIT |
|
4 |
* European Distributed Institute of Taxonomy |
|
5 |
* http://www.e-taxonomy.eu |
|
6 |
* |
|
7 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
|
8 |
* See LICENSE.TXT at the top of this package for the full license terms. |
|
9 |
*/ |
|
10 |
package eu.etaxonomy.cdm.io.edaphobase; |
|
11 |
|
|
12 |
import java.sql.ResultSet; |
|
13 |
import java.sql.SQLException; |
|
14 |
import java.util.HashMap; |
|
15 |
import java.util.HashSet; |
|
16 |
import java.util.Map; |
|
17 |
import java.util.Set; |
|
18 |
|
|
19 |
import org.apache.log4j.Logger; |
|
20 |
import org.springframework.stereotype.Component; |
|
21 |
|
|
22 |
import eu.etaxonomy.cdm.io.common.IPartitionedIO; |
|
23 |
import eu.etaxonomy.cdm.io.common.ResultSetPartitioner; |
|
24 |
import eu.etaxonomy.cdm.model.common.CdmBase; |
|
25 |
import eu.etaxonomy.cdm.model.reference.Reference; |
|
26 |
import eu.etaxonomy.cdm.model.taxon.Synonym; |
|
27 |
import eu.etaxonomy.cdm.model.taxon.SynonymRelationshipType; |
|
28 |
import eu.etaxonomy.cdm.model.taxon.Taxon; |
|
29 |
import eu.etaxonomy.cdm.model.taxon.TaxonBase; |
|
30 |
|
|
31 |
/** |
|
32 |
* @author a.mueller |
|
33 |
* @date 21.12.2015 |
|
34 |
* |
|
35 |
*/ |
|
36 |
@Component |
|
37 |
public class EdaphobaseSynonymyImport extends EdaphobaseImportBase { |
|
38 |
private static final long serialVersionUID = 6641343927320994726L; |
|
39 |
|
|
40 |
private static final Logger logger = Logger.getLogger(EdaphobaseSynonymyImport.class); |
|
41 |
|
|
42 |
private static final String tableName = "tax_synonym"; |
|
43 |
|
|
44 |
private static final String pluralString = "synonym relationships"; |
|
45 |
|
|
46 |
|
|
47 |
/** |
|
48 |
* @param tableName |
|
49 |
* @param pluralString |
|
50 |
*/ |
|
51 |
public EdaphobaseSynonymyImport() { |
|
52 |
super(tableName, pluralString); |
|
53 |
} |
|
54 |
|
|
55 |
@Override |
|
56 |
protected String getIdQuery(EdaphobaseImportState state) { |
|
57 |
return "SELECT tax_synonym_id " |
|
58 |
+ " FROM tax_synonym " |
|
59 |
+ " ORDER BY tax_synonym.a_taxon_fk_taxon_id "; |
|
60 |
} |
|
61 |
|
|
62 |
@Override |
|
63 |
protected String getRecordQuery(EdaphobaseImportConfigurator config) { |
|
64 |
String result = "SELECT sr.* " |
|
65 |
+ " FROM tax_synonym sr" |
|
66 |
+ " WHERE tax_synonym_id IN (@IDSET)"; |
|
67 |
result = result.replace("@IDSET", IPartitionedIO.ID_LIST_TOKEN); |
|
68 |
return result; |
|
69 |
} |
|
70 |
|
|
71 |
|
|
72 |
@Override |
|
73 |
public boolean doPartition(ResultSetPartitioner partitioner, EdaphobaseImportState state) { |
|
74 |
ResultSet rs = partitioner.getResultSet(); |
|
75 |
Map<String, TaxonBase> map = partitioner.getObjectMap(TAXON_NAMESPACE); |
|
76 |
Reference<?> sourceReference = state.getTransactionalSourceReference(); |
|
77 |
|
|
78 |
Set<TaxonBase> taxaToSave = new HashSet<>(); |
|
79 |
try { |
|
80 |
while (rs.next()){ |
|
81 |
int id = rs.getInt("tax_synonym_id"); |
|
82 |
//parentTaxonFk |
|
83 |
// boolean isValid = rs.getBoolean("valid"); |
|
84 |
Integer synId = nullSafeInt(rs, "a_taxon_fk_taxon_id"); |
|
85 |
Integer accId = nullSafeInt(rs, "b_taxon_fk_taxon_id"); |
|
86 |
|
|
87 |
|
|
88 |
if (synId == null || accId == null){ |
|
89 |
logger.warn("Either a_taxon or b_taxon is NULL for tax_synonym " + id); |
|
90 |
}else{ |
|
91 |
TaxonBase<?> synonymCandidate = state.getRelatedObject(TAXON_NAMESPACE, String.valueOf(synId), TaxonBase.class); |
|
92 |
if (synonymCandidate == null){ |
|
93 |
logger.warn("Synonym " + synId + " not found for synonymRelations (tax_synonym): " + id); |
|
94 |
}else if (synonymCandidate.isInstanceOf(Taxon.class)){ |
|
95 |
String message = "Synonym ("+synId+") is not synonym but accepted (valid). Can't add synonym relationship for tax_synonym: "+id; |
|
96 |
logger.warn(message); |
|
97 |
}else{ |
|
98 |
Synonym synonym = CdmBase.deproxy(synonymCandidate, Synonym.class); |
|
99 |
TaxonBase<?> accepted = state.getRelatedObject(TAXON_NAMESPACE, String.valueOf(accId), TaxonBase.class); |
|
100 |
if (accepted == null){ |
|
101 |
logger.warn("Accepted(parent) taxon " + accId + " not found for tax_synonym " + id ); |
|
102 |
}else if(accepted.isInstanceOf(Synonym.class)){ |
|
103 |
String message = "Taxon ("+accId+") is not accepted but synonym. Can't add synonym relationship for tax_synonym: "+id; |
|
104 |
logger.warn(message); |
|
105 |
}else{ |
|
106 |
Taxon taxon = CdmBase.deproxy(accepted, Taxon.class); |
|
107 |
taxon.addSynonym(synonym, SynonymRelationshipType.SYNONYM_OF()); |
|
108 |
taxaToSave.add(synonym); |
|
109 |
taxaToSave.add(taxon); |
|
110 |
} |
|
111 |
} |
|
112 |
} |
|
113 |
|
|
114 |
// //id |
|
115 |
// String nameSpace = "tax_taxon"; |
|
116 |
// ImportHelper.setOriginalSource(taxonBase, state.getTransactionalSourceReference(), id, nameSpace); |
|
117 |
// ImportHelper.setOriginalSource(name, state.getTransactionalSourceReference(), id, nameSpace); |
|
118 |
|
|
119 |
|
|
120 |
} |
|
121 |
} catch (SQLException e) { |
|
122 |
// TODO Auto-generated catch block |
|
123 |
e.printStackTrace(); |
|
124 |
} |
|
125 |
|
|
126 |
getTaxonService().saveOrUpdate(taxaToSave); |
|
127 |
return true; |
|
128 |
} |
|
129 |
|
|
130 |
@Override |
|
131 |
public Map<Object, Map<String, ? extends CdmBase>> getRelatedObjectsForPartition(ResultSet rs, |
|
132 |
EdaphobaseImportState state) { |
|
133 |
String nameSpace; |
|
134 |
Class<?> cdmClass; |
|
135 |
Set<String> idSet; |
|
136 |
Map<Object, Map<String, ? extends CdmBase>> result = new HashMap<>(); |
|
137 |
|
|
138 |
try{ |
|
139 |
Set<String> taxonIdSet = new HashSet<String>(); |
|
140 |
while (rs.next()){ |
|
141 |
handleForeignKey(rs, taxonIdSet, "a_taxon_fk_taxon_id"); |
|
142 |
handleForeignKey(rs, taxonIdSet, "b_taxon_fk_taxon_id"); |
|
143 |
} |
|
144 |
|
|
145 |
//name map |
|
146 |
nameSpace = TAXON_NAMESPACE; |
|
147 |
cdmClass = TaxonBase.class; |
|
148 |
idSet = taxonIdSet; |
|
149 |
Map<String, TaxonBase> taxonMap = (Map<String, TaxonBase>)getCommonService().getSourcedObjectsByIdInSource(cdmClass, idSet, nameSpace); |
|
150 |
result.put(nameSpace, taxonMap); |
|
151 |
|
|
152 |
} catch (SQLException e) { |
|
153 |
throw new RuntimeException(e); |
|
154 |
} |
|
155 |
|
|
156 |
return result; |
|
157 |
} |
|
158 |
|
|
159 |
|
|
160 |
@Override |
|
161 |
protected boolean doCheck(EdaphobaseImportState state) { |
|
162 |
return false; |
|
163 |
} |
|
164 |
|
|
165 |
@Override |
|
166 |
protected boolean isIgnore(EdaphobaseImportState state) { |
|
167 |
return ! state.getConfig().isDoSynonyms(); |
|
168 |
} |
|
169 |
|
|
170 |
} |
app-import/src/main/java/eu/etaxonomy/cdm/io/edaphobase/EdaphobaseTaxonImport.java | ||
---|---|---|
31 | 31 |
import eu.etaxonomy.cdm.model.name.Rank; |
32 | 32 |
import eu.etaxonomy.cdm.model.name.ZoologicalName; |
33 | 33 |
import eu.etaxonomy.cdm.model.reference.Reference; |
34 |
import eu.etaxonomy.cdm.model.reference.ReferenceFactory; |
|
34 | 35 |
import eu.etaxonomy.cdm.model.taxon.Synonym; |
35 | 36 |
import eu.etaxonomy.cdm.model.taxon.Taxon; |
36 | 37 |
import eu.etaxonomy.cdm.model.taxon.TaxonBase; |
... | ... | |
92 | 93 |
Set<TaxonBase> taxaToSave = new HashSet<>(); |
93 | 94 |
try { |
94 | 95 |
while (rs.next()){ |
95 |
Integer id = nullSafeInt(rs, "taxon_id"); |
|
96 |
Integer year = nullSafeInt(rs, "tax_year"); |
|
97 |
boolean isBrackets = rs.getBoolean("tax_brackets"); |
|
98 |
String remark = rs.getString("remark"); |
|
99 |
String nameStr = rs.getString("name"); |
|
100 |
String authorName = rs.getString("tax_author_name"); |
|
101 |
//parentTaxonFk |
|
102 |
//rankFk |
|
103 |
//document |
|
104 |
boolean isValid = rs.getBoolean("valid"); |
|
105 |
boolean idDeleted = rs.getBoolean("deleted"); |
|
106 |
String displayString = rs.getString("display_string"); |
|
107 |
Integer version = nullSafeInt(rs, "versionfield"); |
|
108 |
String pages = rs.getString("pages"); |
|
109 |
String treeIndex = rs.getString("path_to_root"); |
|
110 |
// Integer rankFk = nullSafeInt(rs, "tax_rank_fk"); |
|
111 |
String nameAddition = rs.getString("name_addition"); |
|
112 |
String officialRemark = rs.getString("official_remark"); |
|
113 |
boolean isGroup = rs.getBoolean("taxonomic_group"); |
|
114 |
String rankStr = rs.getString("rankStr"); |
|
115 |
String parentRankStr = rs.getString("parentRankStr"); |
|
116 |
String grandParentRankStr = rs.getString("grandParentRankStr"); |
|
117 |
String parentNameStr = rs.getString("parentName"); |
|
118 |
String grandParentNameStr = rs.getString("grandParentName"); |
|
119 |
|
|
120 |
|
|
121 |
TaxonBase<?> taxonBase; |
|
122 |
Reference<?> sec = null; //TODO |
|
123 |
|
|
124 |
//Name etc. |
|
125 |
Rank rank = makeRank(state, rankStr); |
|
126 |
ZoologicalName name = ZoologicalName.NewInstance(rank); |
|
127 |
setNamePart(nameStr, rank, name); |
|
128 |
Rank parentRank = makeRank(state, parentRankStr); |
|
129 |
setNamePart(parentNameStr, parentRank, name); |
|
130 |
Rank parentParentRank = makeRank(state, grandParentRankStr); |
|
131 |
setNamePart(grandParentNameStr, parentParentRank, name); |
|
132 |
|
|
133 |
//Authors |
|
134 |
if (StringUtils.isNotBlank(authorName)){ |
|
135 |
TeamOrPersonBase<?> author = state.getRelatedObject(AUTHOR_NAMESPACE, authorName, TeamOrPersonBase.class); |
|
136 |
if (author == null){ |
|
137 |
logger.warn("Author not found in state: " + authorName); |
|
138 |
}else{ |
|
139 |
if (isBrackets){ |
|
140 |
name.setBasionymAuthorship(author); |
|
141 |
name.setOriginalPublicationYear(year); |
|
142 |
}else{ |
|
143 |
name.setCombinationAuthorship(author); |
|
144 |
name.setPublicationYear(year); |
|
145 |
} |
|
146 |
} |
|
147 |
} |
|
148 |
|
|
149 |
|
|
150 |
if (isValid){ |
|
151 |
taxonBase = Taxon.NewInstance(name, sec); |
|
152 |
}else{ |
|
153 |
taxonBase = Synonym.NewInstance(name, sec); |
|
154 |
} |
|
155 |
taxaToSave.add(taxonBase); |
|
156 |
|
|
157 |
//remarks |
|
158 |
doNotes(taxonBase, remark); |
|
159 |
|
|
160 |
//id |
|
161 |
ImportHelper.setOriginalSource(taxonBase, state.getTransactionalSourceReference(), id, TAXON_NAMESPACE); |
|
162 |
ImportHelper.setOriginalSource(name, state.getTransactionalSourceReference(), id, TAXON_NAMESPACE); |
|
96 |
makeSingleTaxon(state, rs, taxaToSave); |
|
163 | 97 |
|
164 | 98 |
} |
165 | 99 |
} catch (SQLException e) { |
... | ... | |
171 | 105 |
return true; |
172 | 106 |
} |
173 | 107 |
|
108 |
/** |
|
109 |
* @param state |
|
110 |
* @param rs |
|
111 |
* @param taxaToSave |
|
112 |
* @throws SQLException |
|
113 |
*/ |
|
114 |
private void makeSingleTaxon(EdaphobaseImportState state, ResultSet rs, Set<TaxonBase> taxaToSave) |
|
115 |
throws SQLException { |
|
116 |
Integer id = nullSafeInt(rs, "taxon_id"); |
|
117 |
Integer year = nullSafeInt(rs, "tax_year"); |
|
118 |
boolean isBrackets = rs.getBoolean("tax_brackets"); |
|
119 |
String remark = rs.getString("remark"); |
|
120 |
String nameStr = rs.getString("name"); |
|
121 |
String authorName = rs.getString("tax_author_name"); |
|
122 |
//parentTaxonFk |
|
123 |
//rankFk |
|
124 |
Integer nomRefId = nullSafeInt(rs, "tax_document"); |
|
125 |
boolean isValid = rs.getBoolean("valid"); |
|
126 |
boolean idDeleted = rs.getBoolean("deleted"); |
|
127 |
String displayString = rs.getString("display_string"); |
|
128 |
Integer version = nullSafeInt(rs, "versionfield"); |
|
129 |
String pages = rs.getString("pages"); |
|
130 |
String treeIndex = rs.getString("path_to_root"); |
|
131 |
// Integer rankFk = nullSafeInt(rs, "tax_rank_fk"); |
|
132 |
String nameAddition = rs.getString("name_addition"); |
|
133 |
String officialRemark = rs.getString("official_remark"); |
|
134 |
boolean isGroup = rs.getBoolean("taxonomic_group"); |
|
135 |
String rankStr = rs.getString("rankStr"); |
|
136 |
String parentRankStr = rs.getString("parentRankStr"); |
|
137 |
String grandParentRankStr = rs.getString("grandParentRankStr"); |
|
138 |
String parentNameStr = rs.getString("parentName"); |
|
139 |
String grandParentNameStr = rs.getString("grandParentName"); |
|
140 |
|
|
141 |
TaxonBase<?> taxonBase; |
|
142 |
|
|
143 |
//Name etc. |
|
144 |
Rank rank = makeRank(state, rankStr); |
|
145 |
ZoologicalName name = ZoologicalName.NewInstance(rank); |
|
146 |
setNamePart(nameStr, rank, name); |
|
147 |
Rank parentRank = makeRank(state, parentRankStr); |
|
148 |
setNamePart(parentNameStr, parentRank, name); |
|
149 |
Rank parentParentRank = makeRank(state, grandParentRankStr); |
|
150 |
setNamePart(grandParentNameStr, parentParentRank, name); |
|
151 |
|
|
152 |
//Authors |
|
153 |
if (StringUtils.isNotBlank(authorName)){ |
|
154 |
TeamOrPersonBase<?> author = state.getRelatedObject(AUTHOR_NAMESPACE, authorName, TeamOrPersonBase.class); |
|
155 |
if (author == null){ |
|
156 |
logger.warn("Author not found in state: " + authorName); |
|
157 |
}else{ |
|
158 |
if (isBrackets){ |
|
159 |
name.setBasionymAuthorship(author); |
|
160 |
name.setOriginalPublicationYear(year); |
|
161 |
}else{ |
|
162 |
name.setCombinationAuthorship(author); |
|
163 |
name.setPublicationYear(year); |
|
164 |
} |
|
165 |
} |
|
166 |
} |
|
167 |
|
|
168 |
//nomRef |
|
169 |
if (nomRefId != null){ |
|
170 |
Reference<?> nomRef = state.getRelatedObject(REFERENCE_NAMESPACE, String.valueOf(nomRefId), Reference.class); |
|
171 |
if (nomRef == null){ |
|
172 |
logger.warn("Reference " + nomRefId + " could not be found"); |
|
173 |
} |
|
174 |
name.setNomenclaturalReference(nomRef); |
|
175 |
} |
|
176 |
name.setNomenclaturalMicroReference(StringUtils.isBlank(pages)? null : pages); |
|
177 |
|
|
178 |
|
|
179 |
Reference<?> secRef = state.getRelatedObject(REFERENCE_NAMESPACE, state.getConfig().getSecUuid().toString(), Reference.class); |
|
180 |
if (secRef == null){ |
|
181 |
secRef = makeSecRef(state); |
|
182 |
} |
|
183 |
if (isValid){ |
|
184 |
taxonBase = Taxon.NewInstance(name, secRef); |
|
185 |
}else{ |
|
186 |
taxonBase = Synonym.NewInstance(name, secRef); |
|
187 |
} |
|
188 |
taxaToSave.add(taxonBase); |
|
189 |
|
|
190 |
//remarks |
|
191 |
doNotes(taxonBase, remark); |
|
192 |
|
|
193 |
//id |
|
194 |
ImportHelper.setOriginalSource(taxonBase, state.getTransactionalSourceReference(), id, TAXON_NAMESPACE); |
|
195 |
ImportHelper.setOriginalSource(name, state.getTransactionalSourceReference(), id, TAXON_NAMESPACE); |
|
196 |
} |
|
197 |
|
|
198 |
|
|
199 |
/** |
|
200 |
* @param state |
|
201 |
* @return |
|
202 |
*/ |
|
203 |
private Reference<?> makeSecRef(EdaphobaseImportState state) { |
|
204 |
Reference<?> ref = ReferenceFactory.newDatabase(); |
|
205 |
ref.setTitle(state.getConfig().getEdaphobaseSecundumTitle()); |
|
206 |
ref.setUuid(state.getConfig().getSecUuid()); |
|
207 |
state.addRelatedObject(REFERENCE_NAMESPACE, ref.getUuid().toString(), ref); |
|
208 |
getReferenceService().save(ref); |
|
209 |
return ref; |
|
210 |
} |
|
174 | 211 |
|
175 | 212 |
@Override |
176 | 213 |
public Map<Object, Map<String, ? extends CdmBase>> getRelatedObjectsForPartition(ResultSet rs, |
... | ... | |
178 | 215 |
Map<Object, Map<String, ? extends CdmBase>> result = new HashMap<>(); |
179 | 216 |
Map<String, TeamOrPersonBase<?>> authorMap = new HashMap<>(); |
180 | 217 |
Set<String> authorSet = new HashSet<>(); |
218 |
Set<String> referenceIdSet = new HashSet<String>(); |
|
219 |
|
|
181 | 220 |
try { |
182 | 221 |
while (rs.next()){ |
183 | 222 |
String authorStr = rs.getString("tax_author_name"); |
184 | 223 |
authorSet.add(authorStr); |
224 |
handleForeignKey(rs, referenceIdSet, "tax_document"); |
|
185 | 225 |
} |
186 | 226 |
} catch (SQLException e) { |
187 | 227 |
e.printStackTrace(); |
... | ... | |
206 | 246 |
} |
207 | 247 |
result.put(AUTHOR_NAMESPACE, authorMap); |
208 | 248 |
|
249 |
//reference map |
|
250 |
String nameSpace = REFERENCE_NAMESPACE; |
|
251 |
Class<?> cdmClass = Reference.class; |
|
252 |
Set<String> idSet = referenceIdSet; |
|
253 |
Map<String, Reference<?>> referenceMap = (Map<String, Reference<?>>)getCommonService().getSourcedObjectsByIdInSource(cdmClass, idSet, nameSpace); |
|
254 |
result.put(nameSpace, referenceMap); |
|
255 |
|
|
256 |
//secundum |
|
257 |
UUID secUuid = state.getConfig().getSecUuid(); |
|
258 |
Reference<?> secRef = getReferenceService().find(secUuid); |
|
259 |
referenceMap.put(secUuid.toString(), secRef); |
|
260 |
|
|
209 | 261 |
return result; |
210 | 262 |
} |
211 | 263 |
|
Also available in: Unified diff
Latest changes to Edaphobase import