Revision 48014773
Added by Andreas Müller almost 9 years ago
app-import/src/main/java/eu/etaxonomy/cdm/io/caryo/CaryoTaxonImport.java | ||
---|---|---|
1 | 1 |
/** |
2 | 2 |
* Copyright (C) 2007 EDIT |
3 |
* European Distributed Institute of Taxonomy
|
|
3 |
* European Distributed Institute of Taxonomy |
|
4 | 4 |
* http://www.e-taxonomy.eu |
5 |
*
|
|
5 |
* |
|
6 | 6 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
7 | 7 |
* See LICENSE.TXT at the top of this package for the full license terms. |
8 | 8 |
*/ |
... | ... | |
58 | 58 |
@Component |
59 | 59 |
public class CaryoTaxonImport extends DbImportBase<CaryoImportState, CaryoImportConfigurator> { |
60 | 60 |
private static final Logger logger = Logger.getLogger(CaryoTaxonImport.class); |
61 |
|
|
62 |
private int modCount = 10000; |
|
61 |
|
|
62 |
private final int modCount = 10000;
|
|
63 | 63 |
private static final String pluralString = "taxa"; |
64 | 64 |
private static final String dbTableName = "CARYOPHYLLALES"; |
65 | 65 |
|
66 | 66 |
|
67 |
|
|
68 |
private Map<String, Taxon> familyMap = new HashMap<String, Taxon>(); |
|
69 |
private Map<String, Person> personMap = new HashMap<String, Person>(); |
|
70 |
private Map<String, Team> teamMap = new HashMap<String, Team>(); |
|
71 |
private Map<String, TeamOrPersonBase> inAuthorMap = new HashMap<String, TeamOrPersonBase>(); |
|
72 |
private Map<String, IJournal> journalMap = new HashMap<String, IJournal>(); |
|
73 |
private Map<String, IBook> bookMap = new HashMap<String, IBook>(); |
|
74 |
|
|
75 |
|
|
67 |
|
|
68 |
private final Map<String, Taxon> familyMap = new HashMap<String, Taxon>();
|
|
69 |
private final Map<String, Person> personMap = new HashMap<String, Person>();
|
|
70 |
private final Map<String, Team> teamMap = new HashMap<String, Team>();
|
|
71 |
private final Map<String, TeamOrPersonBase> inAuthorMap = new HashMap<String, TeamOrPersonBase>();
|
|
72 |
private final Map<String, IJournal> journalMap = new HashMap<String, IJournal>();
|
|
73 |
private final Map<String, IBook> bookMap = new HashMap<String, IBook>();
|
|
74 |
|
|
75 |
|
|
76 | 76 |
private Classification classification; |
77 | 77 |
|
78 |
|
|
79 |
|
|
78 |
|
|
79 |
|
|
80 | 80 |
public CaryoTaxonImport(){ |
81 | 81 |
super(dbTableName, pluralString); |
82 | 82 |
} |
83 | 83 |
|
84 |
|
|
85 |
|
|
86 |
|
|
84 |
|
|
85 |
|
|
86 |
|
|
87 | 87 |
/* (non-Javadoc) |
88 | 88 |
* @see eu.etaxonomy.cdm.io.common.DbImportBase#getIdQuery(eu.etaxonomy.cdm.io.common.DbImportStateBase) |
89 | 89 |
*/ |
90 | 90 |
@Override |
91 | 91 |
protected String getIdQuery(CaryoImportState state) { |
92 |
String strRecordQuery =
|
|
93 |
" SELECT ID " +
|
|
92 |
String strRecordQuery = |
|
93 |
" SELECT ID " + |
|
94 | 94 |
" FROM " + dbTableName + |
95 |
" ORDER BY id ";
|
|
96 |
return strRecordQuery;
|
|
95 |
" ORDER BY id "; |
|
96 |
return strRecordQuery; |
|
97 | 97 |
} |
98 | 98 |
|
99 | 99 |
|
... | ... | |
102 | 102 |
*/ |
103 | 103 |
@Override |
104 | 104 |
protected String getRecordQuery(CaryoImportConfigurator config) { |
105 |
String strRecordQuery =
|
|
106 |
" SELECT t.* " +
|
|
105 |
String strRecordQuery = |
|
106 |
" SELECT t.* " + |
|
107 | 107 |
" FROM " + getTableName() + " t " + |
108 | 108 |
" WHERE ( t.ID IN (" + ID_LIST_TOKEN + ") )"; |
109 | 109 |
return strRecordQuery; |
110 | 110 |
} |
111 |
|
|
111 |
|
|
112 | 112 |
|
113 | 113 |
|
114 | 114 |
/* (non-Javadoc) |
... | ... | |
117 | 117 |
@Override |
118 | 118 |
public boolean doPartition(ResultSetPartitioner partitioner, CaryoImportState state) { |
119 | 119 |
boolean success = true; |
120 |
|
|
120 |
|
|
121 | 121 |
Set<TaxonBase> objectsToSave = new HashSet<TaxonBase>(); |
122 |
|
|
122 |
|
|
123 | 123 |
// Map<String, Taxon> taxonMap = (Map<String, Taxon>) partitioner.getObjectMap(TAXON_NAMESPACE); |
124 | 124 |
|
125 |
|
|
125 |
|
|
126 | 126 |
classification = getClassification(state); |
127 |
|
|
127 |
|
|
128 | 128 |
try { |
129 | 129 |
doFamilies(state); |
130 | 130 |
doAuthors(state); |
131 | 131 |
doInAuthors(state); |
132 | 132 |
doJournals(state); |
133 | 133 |
doBooks(state); |
134 |
|
|
134 |
|
|
135 | 135 |
ResultSet rs = partitioner.getResultSet(); |
136 |
|
|
136 |
|
|
137 | 137 |
int i = 0; |
138 | 138 |
Reference<?> sec = state.getTransactionalSourceReference(); |
139 | 139 |
|
140 | 140 |
//for each reference |
141 | 141 |
while (rs.next()){ |
142 |
|
|
142 |
|
|
143 | 143 |
if ((i++ % modCount) == 0 && i!= 1 ){ logger.info(pluralString + " handled: " + (i-1));} |
144 |
|
|
144 |
|
|
145 | 145 |
Integer id = rs.getInt("Id"); |
146 | 146 |
Integer taxonId = rs.getInt("NCUGenID"); |
147 | 147 |
String genus = rs.getString("Genus"); |
... | ... | |
151 | 151 |
String typeStr = rs.getString("Type"); |
152 | 152 |
String nomStatusStr = rs.getString("NomenclaturalStatus"); |
153 | 153 |
String basioStr = rs.getString("Basionym"); |
154 |
|
|
154 |
|
|
155 | 155 |
// ,[EtInCitation] |
156 | 156 |
// ,[Gender] |
157 |
|
|
157 |
|
|
158 | 158 |
// ,[Basionym] |
159 | 159 |
// ,[OriginalCitation] |
160 |
|
|
161 |
|
|
160 |
|
|
161 |
|
|
162 | 162 |
BotanicalName name = BotanicalName.NewInstance(Rank.GENUS()); |
163 | 163 |
name.setGenusOrUninomial(genus); |
164 | 164 |
makeAuthors(name, autoren, id); |
... | ... | |
166 | 166 |
name.setNomenclaturalReference(nomRef); |
167 | 167 |
name.setNomenclaturalMicroReference(pages); |
168 | 168 |
makeStatus(name, nomStatusStr, id); |
169 |
|
|
170 |
|
|
169 |
|
|
170 |
|
|
171 | 171 |
Taxon taxon = Taxon.NewInstance(name, state.getTransactionalSourceReference()); |
172 | 172 |
handleTypes(state, rs, taxon, typeStr, id); |
173 | 173 |
handleBasionym(state, rs, taxon, basioStr, id); |
174 |
|
|
174 |
|
|
175 | 175 |
Taxon parent = familyMap.get(family); |
176 |
|
|
176 |
|
|
177 | 177 |
classification.addParentChild(parent, taxon, sec, null); |
178 |
|
|
178 |
|
|
179 | 179 |
taxon.addSource(OriginalSourceType.Import, String.valueOf(taxonId), "NCUGenID", sec, null); |
180 |
|
|
181 |
|
|
182 |
|
|
180 |
|
|
181 |
|
|
182 |
|
|
183 | 183 |
objectsToSave.add(taxon); |
184 | 184 |
|
185 | 185 |
} |
186 |
|
|
186 |
|
|
187 | 187 |
logger.warn(pluralString + " to save: " + objectsToSave.size()); |
188 |
getTaxonService().save(objectsToSave);
|
|
189 |
|
|
188 |
getTaxonService().save(objectsToSave); |
|
189 |
|
|
190 | 190 |
return success; |
191 | 191 |
} catch (SQLException e) { |
192 | 192 |
logger.error("SQLException:" + e); |
... | ... | |
206 | 206 |
taxon.addSynonym(syn, SynonymRelationshipType.HOMOTYPIC_SYNONYM_OF()); |
207 | 207 |
getTaxonService().save(syn); |
208 | 208 |
} |
209 |
|
|
209 |
|
|
210 | 210 |
} |
211 | 211 |
|
212 | 212 |
|
... | ... | |
241 | 241 |
String species = type.substring(0, i); |
242 | 242 |
typeName.setSpecificEpithet(species); |
243 | 243 |
type = type.substring(i + 1).trim(); |
244 |
|
|
244 |
|
|
245 | 245 |
int posBracket = type.indexOf("(", 2); |
246 | 246 |
if (posBracket > 0){ |
247 | 247 |
String bracket = type.substring(posBracket); |
... | ... | |
254 | 254 |
} |
255 | 255 |
type = makeTypeNomStatus(typeName, type); |
256 | 256 |
|
257 |
|
|
257 |
|
|
258 | 258 |
makeAuthors(typeName, type, id); |
259 | 259 |
} |
260 |
|
|
260 |
|
|
261 | 261 |
desig.setTypeName(typeName); |
262 | 262 |
} |
263 | 263 |
name.addTypeDesignation(desig, true); |
264 | 264 |
} |
265 |
|
|
266 |
|
|
265 |
|
|
266 |
|
|
267 | 267 |
} |
268 | 268 |
|
269 | 269 |
|
... | ... | |
282 | 282 |
|
283 | 283 |
private void makeStatus(BotanicalName name, String nomStatusStr, Integer id) throws SQLException { |
284 | 284 |
// ,[NomenclaturalStatus] |
285 |
|
|
285 |
|
|
286 | 286 |
if (StringUtils.isNotBlank(nomStatusStr)){ |
287 | 287 |
NomenclaturalStatusType nomStatusType; |
288 | 288 |
try { |
... | ... | |
305 | 305 |
nomStatusType = NomenclaturalStatusType.DOUBTFUL(); |
306 | 306 |
} |
307 | 307 |
} |
308 |
|
|
308 |
|
|
309 | 309 |
NomenclaturalStatus status = NomenclaturalStatus.NewInstance(nomStatusType); |
310 | 310 |
name.addStatus(status); |
311 | 311 |
} |
312 |
|
|
312 |
|
|
313 | 313 |
} |
314 | 314 |
|
315 | 315 |
|
... | ... | |
322 | 322 |
String bookTitle = rs.getString("BookTitle"); |
323 | 323 |
String inAutorStr = rs.getString("InAutor"); |
324 | 324 |
String autorenStr = rs.getString("Autoren"); |
325 |
|
|
325 |
|
|
326 | 326 |
TeamOrPersonBase<?> author = getNomRefAuthor(autorenStr, id); |
327 | 327 |
if (StringUtils.isNotBlank(periodicalTitle)){ |
328 | 328 |
IJournal journal = journalMap.get(periodicalTitle); |
... | ... | |
378 | 378 |
Integer[] preDate2 = getDay(pre2, id); |
379 | 379 |
// tp.setEndMonth(preDate2[1]); |
380 | 380 |
// tp.setEndDay(preDate2[0]); |
381 |
|
|
381 |
|
|
382 | 382 |
// if (StringUtils.isNotBlank(modi1) || StringUtils.isNotBlank(modi2)){ |
383 | 383 |
// tp.setFreeText(date); |
384 | 384 |
// } |
... | ... | |
440 | 440 |
return result; |
441 | 441 |
} |
442 | 442 |
|
443 |
|
|
443 |
|
|
444 | 444 |
private TeamOrPersonBase<?> getInAuthor(String inAutorStr) { |
445 | 445 |
if (StringUtils.isBlank(inAutorStr)){ |
446 | 446 |
return null; |
... | ... | |
456 | 456 |
|
457 | 457 |
private void makeAuthors(BotanicalName name, String autoren, Integer id) { |
458 | 458 |
String[] parsedAuthorTeams = getParsedAuthors(autoren); |
459 |
name.setBasionymAuthorTeam(getTeam(parsedAuthorTeams[0], id));
|
|
460 |
name.setExBasionymAuthorTeam(getTeam(parsedAuthorTeams[1], id));
|
|
461 |
name.setCombinationAuthorTeam(getTeam(parsedAuthorTeams[2], id));
|
|
462 |
name.setExCombinationAuthorTeam(getTeam(parsedAuthorTeams[3], id));
|
|
463 |
|
|
459 |
name.setBasionymAuthorship(getTeam(parsedAuthorTeams[0], id));
|
|
460 |
name.setExBasionymAuthorship(getTeam(parsedAuthorTeams[1], id));
|
|
461 |
name.setCombinationAuthorship(getTeam(parsedAuthorTeams[2], id));
|
|
462 |
name.setExCombinationAuthorship(getTeam(parsedAuthorTeams[3], id));
|
|
463 |
|
|
464 | 464 |
} |
465 |
|
|
465 |
|
|
466 | 466 |
private TeamOrPersonBase<?> getNomRefAuthor(String authorStr, Integer id) { |
467 | 467 |
String[] parsedAuthorTeams = getParsedAuthors(authorStr); |
468 | 468 |
TeamOrPersonBase<?> team = getTeam(parsedAuthorTeams[2], id); |
... | ... | |
485 | 485 |
} |
486 | 486 |
return result; |
487 | 487 |
} |
488 |
|
|
488 |
|
|
489 | 489 |
|
490 | 490 |
private void doInAuthors(CaryoImportState state) throws SQLException { |
491 | 491 |
Source source = state.getConfig().getSource(); |
... | ... | |
500 | 500 |
getAgentService().save(team); |
501 | 501 |
} |
502 | 502 |
} |
503 |
|
|
503 |
|
|
504 | 504 |
} |
505 | 505 |
|
506 | 506 |
|
... | ... | |
602 | 602 |
doTeam("Maerkl."); |
603 | 603 |
doTeam("Vierh."); |
604 | 604 |
doTeam("Exell"); |
605 |
|
|
605 |
|
|
606 | 606 |
} |
607 | 607 |
|
608 | 608 |
|
... | ... | |
657 | 657 |
|
658 | 658 |
|
659 | 659 |
private String[] getParsedAuthors(String autorenStr) { |
660 |
String[] result = new String[4];
|
|
660 |
String[] result = new String[4]; |
|
661 | 661 |
String basioFull = null; |
662 | 662 |
String origFull; |
663 | 663 |
|
... | ... | |
674 | 674 |
result[1] = splitBasio[1]; |
675 | 675 |
result[2] = splitOrig[0]; |
676 | 676 |
result[3] = splitOrig[1]; |
677 |
|
|
677 |
|
|
678 | 678 |
return result; |
679 | 679 |
} |
680 | 680 |
|
... | ... | |
682 | 682 |
|
683 | 683 |
|
684 | 684 |
private String[] splitExAuthors(String author) { |
685 |
String[] result = new String[2];
|
|
685 |
String[] result = new String[2]; |
|
686 | 686 |
if (author != null){ |
687 | 687 |
String[] split = author.split("\\sex\\s"); |
688 | 688 |
if (split.length > 1){ |
... | ... | |
705 | 705 |
while (rs.next()){ |
706 | 706 |
String bookStr = rs.getString("BookTitle"); |
707 | 707 |
if (bookMap.get(bookStr) == null ){ |
708 |
|
|
709 |
IBook book = ReferenceFactory.newBook();
|
|
708 |
|
|
709 |
IBook book = ReferenceFactory.newBook(); |
|
710 | 710 |
|
711 | 711 |
book.setTitle(bookStr); |
712 |
|
|
712 |
|
|
713 | 713 |
bookMap.put(bookStr, book); |
714 | 714 |
getReferenceService().save((Reference<?>)book); |
715 | 715 |
} |
... | ... | |
726 | 726 |
while (rs.next()){ |
727 | 727 |
String periodical = rs.getString("PeriodicalTitle"); |
728 | 728 |
if (journalMap.get(periodical) == null ){ |
729 |
|
|
730 |
Reference<?> journal = ReferenceFactory.newJournal();
|
|
729 |
|
|
730 |
Reference<?> journal = ReferenceFactory.newJournal(); |
|
731 | 731 |
|
732 | 732 |
journal.setTitle(periodical); |
733 |
|
|
733 |
|
|
734 | 734 |
journalMap.put(periodical, journal); |
735 | 735 |
getReferenceService().save(journal); |
736 | 736 |
} |
... | ... | |
747 | 747 |
while (rs.next()){ |
748 | 748 |
String family = rs.getString("family"); |
749 | 749 |
if (familyMap.get(family) == null ){ |
750 |
|
|
750 |
|
|
751 | 751 |
BotanicalName name = BotanicalName.NewInstance(Rank.FAMILY()); |
752 | 752 |
name.setGenusOrUninomial(family); |
753 | 753 |
Taxon taxon = Taxon.NewInstance(name, state.getTransactionalSourceReference()); |
754 | 754 |
classification.addChildTaxon(taxon, null, null); |
755 | 755 |
// taxon.addSource(id, idNamespace, citation, null); |
756 |
|
|
756 |
|
|
757 | 757 |
familyMap.put(family, taxon); |
758 | 758 |
getTaxonService().save(taxon); |
759 | 759 |
} |
760 | 760 |
} |
761 |
|
|
761 |
|
|
762 | 762 |
} |
763 | 763 |
|
764 | 764 |
private Classification getClassification(CaryoImportState state) { |
... | ... | |
786 | 786 |
Map<Object, Map<String, ? extends CdmBase>> result = new HashMap<Object, Map<String, ? extends CdmBase>>(); |
787 | 787 |
// try{ |
788 | 788 |
// Set<String> taxonIdSet = new HashSet<String>(); |
789 |
//
|
|
789 |
// |
|
790 | 790 |
// while (rs.next()){ |
791 | 791 |
//// handleForeignKey(rs, taxonIdSet, "taxonId"); |
792 | 792 |
// } |
793 |
//
|
|
793 |
// |
|
794 | 794 |
// //taxon map |
795 | 795 |
// nameSpace = TAXON_NAMESPACE; |
796 | 796 |
// cdmClass = Taxon.class; |
... | ... | |
798 | 798 |
// Map<String, Taxon> objectMap = (Map<String, Taxon>)getCommonService().getSourcedObjectsByIdInSource(cdmClass, idSet, nameSpace); |
799 | 799 |
// result.put(nameSpace, objectMap); |
800 | 800 |
// |
801 |
//
|
|
801 |
// |
|
802 | 802 |
// } catch (SQLException e) { |
803 | 803 |
// throw new RuntimeException(e); |
804 | 804 |
// } |
805 | 805 |
return result; |
806 | 806 |
} |
807 |
|
|
807 |
|
|
808 | 808 |
/* (non-Javadoc) |
809 | 809 |
* @see eu.etaxonomy.cdm.io.common.CdmIoBase#doCheck(eu.etaxonomy.cdm.io.common.IImportConfigurator) |
810 | 810 |
*/ |
... | ... | |
812 | 812 |
protected boolean doCheck(CaryoImportState state){ |
813 | 813 |
return true; |
814 | 814 |
} |
815 |
|
|
816 |
|
|
815 |
|
|
816 |
|
|
817 | 817 |
/* (non-Javadoc) |
818 | 818 |
* @see eu.etaxonomy.cdm.io.common.CdmIoBase#isIgnore(eu.etaxonomy.cdm.io.common.IImportConfigurator) |
819 | 819 |
*/ |
820 |
protected boolean isIgnore(CaryoImportState state){ |
|
820 |
@Override |
|
821 |
protected boolean isIgnore(CaryoImportState state){ |
|
821 | 822 |
return ! state.getConfig().isDoTaxa(); |
822 | 823 |
} |
823 | 824 |
|
Also available in: Unified diff
Rename NonViralName authorteams to authorship #4968