Revision 6457f4a5
Added by Patrick Plitzner about 8 years ago
app-import/src/main/java/eu/etaxonomy/cdm/io/redlist/gefaesspflanzen/RedListGefaesspflanzenImportTaxa.java | ||
---|---|---|
25 | 25 |
import eu.etaxonomy.cdm.io.common.ResultSetPartitioner; |
26 | 26 |
import eu.etaxonomy.cdm.model.common.CdmBase; |
27 | 27 |
import eu.etaxonomy.cdm.model.name.BotanicalName; |
28 |
import eu.etaxonomy.cdm.model.name.Rank; |
|
29 |
import eu.etaxonomy.cdm.model.taxon.Synonym; |
|
28 | 30 |
import eu.etaxonomy.cdm.model.taxon.Taxon; |
29 | 31 |
import eu.etaxonomy.cdm.model.taxon.TaxonBase; |
30 | 32 |
|
... | ... | |
70 | 72 |
super.doInvoke(state); |
71 | 73 |
} |
72 | 74 |
|
73 |
|
|
74 | 75 |
@Override |
75 | 76 |
public boolean doPartition(ResultSetPartitioner partitioner, RedListGefaesspflanzenImportState state) { |
76 | 77 |
ResultSet rs = partitioner.getResultSet(); |
... | ... | |
93 | 94 |
long id = rs.getLong("NAMNR"); |
94 | 95 |
String gueltString = rs.getString("GUELT"); |
95 | 96 |
|
96 |
BotanicalName name = state.getRelatedObject(Namespace.NAME_NAMESPACE,String.valueOf(id), BotanicalName.class); |
|
97 |
TaxonBase taxon = Taxon.NewInstance(name, null); |
|
97 |
// BotanicalName name = state.getRelatedObject(Namespace.NAME_NAMESPACE,String.valueOf(id), BotanicalName.class); |
|
98 |
BotanicalName name = BotanicalName.NewInstance(Rank.GENUS()); |
|
99 |
name.setGenusOrUninomial(String.valueOf(id)); |
|
100 |
|
|
101 |
TaxonBase taxonBase = null; |
|
102 |
if(gueltString.equals("1")){ |
|
103 |
taxonBase = Taxon.NewInstance(name, null); |
|
104 |
} |
|
105 |
else if(gueltString.equals("x")){ |
|
106 |
taxonBase = Synonym.NewInstance(name, null); |
|
107 |
} |
|
108 |
else if(gueltString.equals("b")){ |
|
109 |
taxonBase = Synonym.NewInstance(name, null); |
|
110 |
} |
|
111 |
if(taxonBase==null){ |
|
112 |
logger.error("NAMNR: "+id+" Taxon for name "+name+" could not be created."); |
|
113 |
return; |
|
114 |
} |
|
98 | 115 |
|
99 |
taxaToSave.add(taxon); |
|
116 |
taxaToSave.add(taxonBase);
|
|
100 | 117 |
|
101 | 118 |
//id |
102 |
ImportHelper.setOriginalSource(taxon, state.getTransactionalSourceReference(), id, Namespace.TAXON_NAMESPACE); |
|
119 |
ImportHelper.setOriginalSource(taxonBase, state.getTransactionalSourceReference(), id, Namespace.TAXON_NAMESPACE); |
|
120 |
state.getTaxonMap().put(id, taxonBase.getUuid()); |
|
103 | 121 |
} |
104 | 122 |
|
105 | 123 |
@Override |
106 | 124 |
public Map<Object, Map<String, ? extends CdmBase>> getRelatedObjectsForPartition(ResultSet rs, |
107 | 125 |
RedListGefaesspflanzenImportState state) { |
108 | 126 |
Map<Object, Map<String, ? extends CdmBase>> result = new HashMap<>(); |
109 |
Map<String, BotanicalName> nameMap = new HashMap<String, BotanicalName>(); |
|
110 |
try { |
|
111 |
while (rs.next()){ |
|
112 |
long id = rs.getLong("NAMNR"); |
|
113 |
nameMap.put(String.valueOf(id), (BotanicalName) getNameService().load(state.getNameMap().get(id))); |
|
114 |
} |
|
115 |
} catch (SQLException e) { |
|
116 |
e.printStackTrace(); |
|
117 |
} |
|
118 |
result.put(Namespace.NAME_NAMESPACE, nameMap); |
|
127 |
// Map<String, BotanicalName> nameMap = new HashMap<String, BotanicalName>();
|
|
128 |
// try {
|
|
129 |
// while (rs.next()){
|
|
130 |
// long id = rs.getLong("NAMNR");
|
|
131 |
// nameMap.put(String.valueOf(id), (BotanicalName) getNameService().load(state.getNameMap().get(id)));
|
|
132 |
// }
|
|
133 |
// } catch (SQLException e) {
|
|
134 |
// e.printStackTrace();
|
|
135 |
// }
|
|
136 |
// result.put(Namespace.NAME_NAMESPACE, nameMap);
|
|
119 | 137 |
|
120 | 138 |
return result; |
121 | 139 |
} |
Also available in: Unified diff
Import taxon hierarchy