2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.cdm
.io
.faunaEuropaea
;
12 import static eu
.etaxonomy
.cdm
.io
.faunaEuropaea
.FaunaEuropaeaTransformer
.A_AUCT
;
14 import java
.sql
.ResultSet
;
15 import java
.sql
.SQLException
;
16 import java
.util
.HashMap
;
17 import java
.util
.HashSet
;
18 import java
.util
.List
;
21 import java
.util
.UUID
;
23 import org
.apache
.log4j
.Logger
;
24 import org
.springframework
.stereotype
.Component
;
25 import org
.springframework
.transaction
.TransactionStatus
;
27 import eu
.etaxonomy
.cdm
.io
.common
.ICdmIO
;
28 import eu
.etaxonomy
.cdm
.io
.common
.MapWrapper
;
29 import eu
.etaxonomy
.cdm
.io
.common
.Source
;
30 import eu
.etaxonomy
.cdm
.io
.profiler
.ProfilerController
;
31 import eu
.etaxonomy
.cdm
.model
.agent
.TeamOrPersonBase
;
32 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
33 import eu
.etaxonomy
.cdm
.model
.reference
.ReferenceBase
;
34 import eu
.etaxonomy
.cdm
.model
.taxon
.Synonym
;
35 import eu
.etaxonomy
.cdm
.model
.taxon
.SynonymRelationshipType
;
36 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
37 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
38 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonomicTree
;
43 * @author a.babadshanjan
48 public class FaunaEuropaeaRelTaxonIncludeImport
extends FaunaEuropaeaImportBase
{
50 public static final String OS_NAMESPACE_TAXON
= "Taxon";
51 private static final Logger logger
= Logger
.getLogger(FaunaEuropaeaRelTaxonIncludeImport
.class);
52 private static final String acceptedTaxonUUID
= "EC765B43-E909-4D32-8822-34DA186424E8"; // any accepted taxon uuid, taken from original fauna europaea database
54 private ReferenceBase
<?
> sourceRef
;
55 private static String ALL_SYNONYM_FROM_CLAUSE
= " FROM Taxon INNER JOIN Taxon AS Parent " +
56 " ON Taxon.TAX_TAX_IDPARENT = Parent.TAX_ID " +
57 " WHERE (Taxon.TAX_VALID = 0) " +
58 " AND (Taxon.TAX_AUT_ID <> " + A_AUCT
+ " OR Taxon.TAX_AUT_ID IS NULL)";
61 * @see eu.etaxonomy.cdm.io.common.CdmIoBase#doCheck(eu.etaxonomy.cdm.io.common.IImportConfigurator)
64 protected boolean doCheck(FaunaEuropaeaImportState state
) {
65 boolean result
= true;
66 FaunaEuropaeaImportConfigurator fauEuConfig
= state
.getConfig();
67 logger
.warn("Checking for Taxa not yet fully implemented");
68 result
&= checkTaxonStatus(fauEuConfig
);
74 * @see eu.etaxonomy.cdm.io.common.CdmIoBase#isIgnore(eu.etaxonomy.cdm.io.common.IImportConfigurator)
76 protected boolean isIgnore(FaunaEuropaeaImportState state
) {
77 return ! (state
.getConfig().isDoTaxonomicallyIncluded() ||
78 state
.getConfig().isDoMisappliedNames() || state
.getConfig().isDoHeterotypicSynonyms());
81 private boolean checkTaxonStatus(FaunaEuropaeaImportConfigurator fauEuConfig
) {
82 boolean result
= true;
84 Source source
= fauEuConfig
.getSource();
86 ResultSet rs
= source
.getResultSet(sqlStr
);
88 // } catch (SQLException e) {
89 // e.printStackTrace();
94 protected boolean doInvoke(FaunaEuropaeaImportState state
) {
96 boolean success
= true;
98 Map
<String
, MapWrapper
<?
extends CdmBase
>> stores
= state
.getStores();
100 MapWrapper
<TeamOrPersonBase
> authorStore
= (MapWrapper
<TeamOrPersonBase
>)stores
.get(ICdmIO
.TEAM_STORE
);
101 authorStore
.makeEmpty();
103 if(logger
.isInfoEnabled()) { logger
.info("Start making relationships..."); }
105 TransactionStatus txStatus
= startTransaction();
107 // the uuid of an accepted taxon is needed here. any accepted taxon will do.
108 TaxonBase taxon
= getTaxonService().find(UUID
.fromString(acceptedTaxonUUID
));
109 sourceRef
= taxon
.getSec();
111 TaxonomicTree tree
= getTaxonomicTreeFor(state
, sourceRef
);
112 commitTransaction(txStatus
);
114 //ProfilerController.memorySnapshot();
115 if (state
.getConfig().isDoTaxonomicallyIncluded()) {
116 success
= processParentsChildren(state
);
118 //ProfilerController.memorySnapshot();
119 if (state
.getConfig().isDoMisappliedNames()) {
120 success
= processMisappliedNames(state
);
122 //ProfilerController.memorySnapshot();
123 if (state
.getConfig().isDoHeterotypicSynonyms()) {
124 if(logger
.isInfoEnabled()) {
125 logger
.info("Start making heterotypic synonym relationships...");
127 success
= processHeterotypicSynonyms(state
, ALL_SYNONYM_FROM_CLAUSE
);
129 //ProfilerController.memorySnapshot();
131 logger
.info("End making taxa...");
136 /** Retrieve child-parent uuid map from CDM DB */
137 private boolean processParentsChildren(FaunaEuropaeaImportState state
) {
139 int limit
= state
.getConfig().getLimitSave();
141 TransactionStatus txStatus
= null;
143 Map
<UUID
, UUID
> childParentMap
= null;
144 FaunaEuropaeaImportConfigurator fauEuConfig
= state
.getConfig();
145 Source source
= fauEuConfig
.getSource();
147 boolean success
= true;
152 String selectColumns
= " SELECT Taxon.UUID AS ChildUuid, Parent.UUID AS ParentUuid ";
154 String fromClause
= " FROM Taxon INNER JOIN Taxon AS Parent " +
155 " ON Taxon.TAX_TAX_IDPARENT = Parent.TAX_ID " +
156 " WHERE (Taxon.TAX_VALID <> 0) AND (Taxon.TAX_AUT_ID <> " + A_AUCT
+ " OR Taxon.TAX_AUT_ID IS NULL )";
158 String orderClause
= " ORDER BY Taxon.TAX_RNK_ID ASC";
161 selectCount
+ fromClause
;
164 selectColumns
+ fromClause
+ orderClause
;
166 if(logger
.isInfoEnabled()) { logger
.info("Start making taxonomically included relationships..."); }
170 ResultSet rs
= source
.getResultSet(countQuery
);
172 int count
= rs
.getInt(1);
174 rs
= source
.getResultSet(selectQuery
);
176 if (logger
.isInfoEnabled()) {
177 logger
.info("Number of rows: " + count
);
178 logger
.info("Count Query: " + countQuery
);
179 logger
.info("Select Query: " + selectQuery
);
184 if ((i
++ % limit
) == 0) {
186 txStatus
= startTransaction();
187 childParentMap
= new HashMap
<UUID
, UUID
>(limit
);
189 if(logger
.isInfoEnabled()) {
190 logger
.info("Taxonomically included retrieved: " + (i
-1));
194 String childUuidStr
= rs
.getString("ChildUuid");
195 String parentUuidStr
= rs
.getString("ParentUuid");
196 UUID childUuid
= UUID
.fromString(childUuidStr
);
197 UUID parentUuid
= UUID
.fromString(parentUuidStr
);
199 if (!childParentMap
.containsKey(childUuid
)) {
201 childParentMap
.put(childUuid
, parentUuid
);
204 if(logger
.isDebugEnabled()) {
205 logger
.debug("Duplicated child UUID (" + childUuid
+ ")");
208 if (((i
% limit
) == 0 && i
!= 1 ) || i
== count
) {
210 success
= createParentChildRelationships(state
, childParentMap
);
212 childParentMap
= null;
213 commitTransaction(txStatus
);
215 if(logger
.isInfoEnabled()) {
216 logger
.info("i = " + i
+ " - Transaction committed");
221 } catch (SQLException e
) {
222 logger
.error("SQLException:" + e
);
229 /** Retrieve misapplied name / accepted taxon uuid map from CDM DB */
230 private boolean processMisappliedNames(FaunaEuropaeaImportState state
) {
232 int limit
= state
.getConfig().getLimitSave();
234 TransactionStatus txStatus
= null;
236 Map
<UUID
, UUID
> childParentMap
= null;
237 FaunaEuropaeaImportConfigurator fauEuConfig
= state
.getConfig();
238 Source source
= fauEuConfig
.getSource();
240 boolean success
= true;
245 String selectColumns
= " SELECT Taxon.UUID AS MisappliedUuid, Parent.UUID AS AcceptedUuid ";
247 String fromClause
= " FROM Taxon INNER JOIN Taxon AS Parent " +
248 " ON Taxon.TAX_TAX_IDPARENT = Parent.TAX_ID " +
249 " WHERE (Taxon.TAX_VALID = 0) AND (Taxon.TAX_AUT_ID = " + A_AUCT
+ ")";
251 String orderClause
= " ORDER BY dbo.Taxon.TAX_RNK_ID ASC ";
254 selectCount
+ fromClause
;
257 selectColumns
+ fromClause
+ orderClause
;
259 if(logger
.isInfoEnabled()) { logger
.info("Start making misapplied name relationships..."); }
263 ResultSet rs
= source
.getResultSet(countQuery
);
265 int count
= rs
.getInt(1);
267 rs
= source
.getResultSet(selectQuery
);
269 if (logger
.isInfoEnabled()) {
270 logger
.info("Number of rows: " + count
);
271 logger
.info("Count Query: " + countQuery
);
272 logger
.info("Select Query: " + selectQuery
);
277 if ((i
++ % limit
) == 0) {
279 txStatus
= startTransaction();
280 childParentMap
= new HashMap
<UUID
, UUID
>(limit
);
282 if(logger
.isInfoEnabled()) {
283 logger
.info("Misapplied names retrieved: " + (i
-1) );
287 String childUuidStr
= rs
.getString("MisappliedUuid");
288 String parentUuidStr
= rs
.getString("AcceptedUuid");
289 UUID childUuid
= UUID
.fromString(childUuidStr
);
290 UUID parentUuid
= UUID
.fromString(parentUuidStr
);
292 if (!childParentMap
.containsKey(childUuid
)) {
294 childParentMap
.put(childUuid
, parentUuid
);
297 if(logger
.isDebugEnabled()) {
298 logger
.debug("Duplicated child UUID (" + childUuid
+ ")");
302 if (((i
% limit
) == 0 && i
!= 1 ) || i
== count
) {
304 success
= createMisappliedNameRelationships(state
, childParentMap
);
306 childParentMap
= null;
307 commitTransaction(txStatus
);
309 if(logger
.isInfoEnabled()) {
310 logger
.info("i = " + i
+ " - Transaction committed");
315 } catch (SQLException e
) {
316 logger
.error("SQLException:" + e
);
324 /** Retrieve synonyms from FauEuDB DB */
325 private boolean processHeterotypicSynonyms(FaunaEuropaeaImportState state
, String fromClause
) {
327 FaunaEuropaeaImportConfigurator fauEuConfig
= state
.getConfig();
328 Source source
= fauEuConfig
.getSource();
329 boolean success
= true;
334 String selectColumns
= " SELECT Taxon.UUID AS SynonymUuid, Parent.UUID AS AcceptedUuid ";
336 String orderClause
= " ORDER BY dbo.Taxon.TAX_RNK_ID ASC ";
339 selectCount
+ fromClause
;
342 selectColumns
+ fromClause
+ orderClause
;
343 logger
.debug(selectQuery
);
347 ResultSet rs
= source
.getResultSet(countQuery
);
349 int count
= rs
.getInt(1);
351 rs
= source
.getResultSet(selectQuery
);
353 if (logger
.isInfoEnabled()) {
354 logger
.info("Number of rows: " + count
);
355 logger
.info("Count Query: " + countQuery
);
356 logger
.info("Select Query: " + selectQuery
);
359 success
= storeSynonymRelationships(rs
, count
, state
);
361 } catch (SQLException e
) {
362 logger
.error("SQLException:" + e
);
371 private boolean storeSynonymRelationships(ResultSet rs
, int count
, FaunaEuropaeaImportState state
)
372 throws SQLException
{
374 TransactionStatus txStatus
= null;
375 Map
<UUID
, UUID
> synonymAcceptedMap
= null;
377 boolean success
= true;
378 int limit
= state
.getConfig().getLimitSave();
382 if ((i
++ % limit
) == 0) {
384 txStatus
= startTransaction();
385 synonymAcceptedMap
= new HashMap
<UUID
, UUID
>(limit
);
387 if(logger
.isInfoEnabled()) {
388 logger
.info("Synonyms retrieved: " + (i
-1));
392 String synonymUuidStr
= rs
.getString("SynonymUuid");
393 String acceptedUuidStr
= rs
.getString("AcceptedUuid");
394 UUID synonymUuid
= UUID
.fromString(synonymUuidStr
);
395 UUID acceptedUuid
= UUID
.fromString(acceptedUuidStr
);
397 if (!synonymAcceptedMap
.containsKey(synonymUuid
)) {
399 synonymAcceptedMap
.put(synonymUuid
, acceptedUuid
);
402 if(logger
.isDebugEnabled()) {
403 logger
.debug("Duplicated synonym UUID (" + synonymUuid
+ ")");
407 if (((i
% limit
) == 0 && i
!= 1 ) || i
== count
) {
409 success
= createHeterotypicSynonyms(state
, synonymAcceptedMap
);
411 synonymAcceptedMap
= null;
412 commitTransaction(txStatus
);
414 if(logger
.isInfoEnabled()) {
415 logger
.info("i = " + i
+ " - Transaction committed");
426 /* Creates parent-child relationships.
427 * Parent-child pairs are retrieved in blocks via findByUUID(Set<UUID>) from CDM DB.
429 private boolean createParentChildRelationships(FaunaEuropaeaImportState state
, Map
<UUID
, UUID
> childParentMap
) {
430 //gets the taxon "Hydroscaphidae"(family)
431 TaxonBase taxon
= getTaxonService().find(UUID
.fromString(acceptedTaxonUUID
));
432 sourceRef
= taxon
.getSec();
433 boolean success
= true;
434 int limit
= state
.getConfig().getLimitSave();
436 TaxonomicTree tree
= getTaxonomicTreeFor(state
, sourceRef
);
438 Set
<TaxonBase
> childSet
= new HashSet
<TaxonBase
>(limit
);
440 Set
<UUID
> childKeysSet
= childParentMap
.keySet();
441 Set
<UUID
> parentValuesSet
= new HashSet
<UUID
>(childParentMap
.values());
443 if (logger
.isTraceEnabled()) {
444 logger
.trace("Start reading children and parents");
446 List
<TaxonBase
> children
= getTaxonService().find(childKeysSet
);
447 List
<TaxonBase
> parents
= getTaxonService().find(parentValuesSet
);
448 Map
<UUID
, TaxonBase
> parentsMap
= new HashMap
<UUID
, TaxonBase
>(parents
.size());
449 for (TaxonBase taxonBase
: parents
){
450 parentsMap
.put(taxonBase
.getUuid(), taxonBase
);
453 if (logger
.isTraceEnabled()) {
454 logger
.debug("End reading children and parents");
455 for (UUID uuid
: childKeysSet
) {
456 logger
.trace("child uuid query: " + uuid
);
458 for (UUID uuid
: parentValuesSet
) {
459 logger
.trace("parent uuid query: " + uuid
);
461 for (TaxonBase tb
: children
) {
462 logger
.trace("child uuid result: " + tb
.getUuid());
464 for (TaxonBase tb
: parents
) {
465 logger
.trace("parent uuid result: " + tb
.getUuid());
469 UUID mappedParentUuid
= null;
470 UUID childUuid
= null;
472 for (TaxonBase child
: children
) {
475 Taxon childTaxon
= child
.deproxy(child
, Taxon
.class);
476 childUuid
= childTaxon
.getUuid();
477 mappedParentUuid
= childParentMap
.get(childUuid
);
478 TaxonBase parent
= null;
480 TaxonBase potentialParent
= parentsMap
.get(mappedParentUuid
);
481 // for (TaxonBase potentialParent : parents ) {
482 // parentUuid = potentialParent.getUuid();
483 // if(parentUuid.equals(mappedParentUuid)) {
484 parent
= potentialParent
;
485 if (logger
.isDebugEnabled()) {
486 logger
.debug("Parent (" + mappedParentUuid
+ ") found for child (" + childUuid
+ ")");
492 Taxon parentTaxon
= parent
.deproxy(parent
, Taxon
.class);
494 if (childTaxon
!= null && parentTaxon
!= null) {
496 tree
.addParentChild(parentTaxon
, childTaxon
, sourceRef
, null);
498 if (logger
.isDebugEnabled()) {
499 logger
.debug("Parent-child (" + mappedParentUuid
+ "-" + childUuid
+
500 ") relationship created");
502 if (childTaxon
!= null && !childSet
.contains(childTaxon
)) {
504 childSet
.add(childTaxon
);
506 if (logger
.isTraceEnabled()) {
507 logger
.trace("Child taxon (" + childUuid
+ ") added to Set");
511 if (logger
.isDebugEnabled()) {
512 logger
.debug("Duplicated child taxon (" + childUuid
+ ")");
516 if (logger
.isDebugEnabled()) {
517 logger
.debug("Parent(" + mappedParentUuid
+ ") or child (" + childUuid
+ " is null");
521 } catch (Exception e
) {
522 logger
.error("Error creating taxonomically included relationship parent-child (" +
523 mappedParentUuid
+ "-" + childUuid
+ ")", e
);
527 if (logger
.isTraceEnabled()) {
528 logger
.trace("Start saving childSet");
530 getTaxonService().save(childSet
);
531 if (logger
.isTraceEnabled()) {
532 logger
.trace("End saving childSet");
535 parentValuesSet
= null;
544 /* Creates misapplied name relationships.
545 * Misapplied name-accepted taxon pairs are retrieved in blocks via findByUUID(Set<UUID>) from CDM DB.
547 private boolean createMisappliedNameRelationships(FaunaEuropaeaImportState state
, Map
<UUID
, UUID
> fromToMap
) {
549 //gets the taxon "Hydroscaphidae" (family)
551 TaxonBase taxon
= getTaxonService().find(UUID
.fromString(acceptedTaxonUUID
));
552 sourceRef
= taxon
.getSec();
553 boolean success
= true;
554 int limit
= state
.getConfig().getLimitSave();
556 Set
<TaxonBase
> misappliedNameSet
= new HashSet
<TaxonBase
>(limit
);
558 Set
<UUID
> misappliedNamesSet
= fromToMap
.keySet();
559 Set
<UUID
> acceptedTaxaSet
= new HashSet
<UUID
>(fromToMap
.values());
561 if (logger
.isTraceEnabled()) {
562 logger
.trace("Start reading misapplied names and accepted taxa");
564 List
<TaxonBase
> misappliedNames
= getTaxonService().find(misappliedNamesSet
);
565 List
<TaxonBase
> acceptedTaxa
= getTaxonService().find(acceptedTaxaSet
);
566 Map
<UUID
, TaxonBase
> acceptedTaxaMap
= new HashMap
<UUID
, TaxonBase
>(acceptedTaxa
.size());
567 for (TaxonBase taxonBase
: acceptedTaxa
){
568 acceptedTaxaMap
.put(taxonBase
.getUuid(), taxonBase
);
571 if (logger
.isTraceEnabled()) {
572 logger
.info("End reading misapplied names and accepted taxa");
573 for (UUID uuid
: misappliedNamesSet
) {
574 logger
.trace("misapplied name uuid query: " + uuid
);
576 for (UUID uuid
: acceptedTaxaSet
) {
577 logger
.trace("accepted taxon uuid query: " + uuid
);
579 for (TaxonBase tb
: misappliedNames
) {
580 logger
.trace("misapplied name uuid result: " + tb
.getUuid());
582 for (TaxonBase tb
: acceptedTaxa
) {
583 logger
.trace("accepted taxon uuid result: " + tb
.getUuid());
587 UUID mappedAcceptedTaxonUuid
= null;
588 UUID misappliedNameUuid
= null;
589 Taxon misappliedNameTaxon
= null;
590 TaxonBase acceptedTaxonBase
= null;
591 Taxon acceptedTaxon
= null;
593 for (TaxonBase misappliedName
: misappliedNames
) {
596 misappliedNameTaxon
= misappliedName
.deproxy(misappliedName
, Taxon
.class);
597 misappliedNameUuid
= misappliedNameTaxon
.getUuid();
598 mappedAcceptedTaxonUuid
= fromToMap
.get(misappliedNameUuid
);
599 acceptedTaxonBase
= null;
601 acceptedTaxonBase
= acceptedTaxaMap
.get(mappedAcceptedTaxonUuid
);
602 if (logger
.isDebugEnabled()) {
603 logger
.debug("Parent (" + mappedAcceptedTaxonUuid
+ ") found for child (" + misappliedNameUuid
+ ")");
606 acceptedTaxon
= acceptedTaxonBase
.deproxy(acceptedTaxonBase
, Taxon
.class);
608 if (misappliedNameTaxon
!= null && acceptedTaxon
!= null) {
610 acceptedTaxon
.addMisappliedName(misappliedNameTaxon
, sourceRef
, null);
612 if (logger
.isDebugEnabled()) {
613 logger
.debug("Accepted taxon / misapplied name (" + mappedAcceptedTaxonUuid
+ "-" + misappliedNameUuid
+
614 ") relationship created");
616 if (!misappliedNameSet
.contains(misappliedNameTaxon
)) {
618 misappliedNameSet
.add(misappliedNameTaxon
);
620 if (logger
.isTraceEnabled()) {
621 logger
.trace("Misapplied name taxon (" + misappliedNameUuid
+ ") added to Set");
625 if (logger
.isDebugEnabled()) {
626 logger
.debug("Duplicated misapplied name taxon (" + misappliedNameUuid
+ ")");
630 if (logger
.isDebugEnabled()) {
631 logger
.debug("Accepted taxon (" + mappedAcceptedTaxonUuid
+ ") or misapplied name (" + misappliedNameUuid
+ " is null");
635 if (misappliedNameTaxon
!= null && !misappliedNameSet
.contains(misappliedNameTaxon
)) {
636 misappliedNameSet
.add(misappliedNameTaxon
);
637 if (logger
.isTraceEnabled()) {
638 logger
.trace("Misapplied name taxon (" + misappliedNameUuid
+ ") added to Set");
641 if (logger
.isDebugEnabled()) {
642 logger
.debug("Duplicated misapplied name taxon (" + misappliedNameUuid
+ ")");
646 } catch (Exception e
) {
647 logger
.error("Error creating misapplied name relationship accepted taxon-misapplied name (" +
648 mappedAcceptedTaxonUuid
+ "-" + misappliedNameUuid
+ ")", e
);
652 if (logger
.isTraceEnabled()) {
653 logger
.trace("Start saving misappliedNameSet");
655 getTaxonService().save(misappliedNameSet
);
656 if (logger
.isTraceEnabled()) {
657 logger
.trace("End saving misappliedNameSet");
660 acceptedTaxaSet
= null;
661 misappliedNameSet
= null;
662 misappliedNames
= null;
669 /* Creates heterotypic synonym relationships.
670 * Synonym-accepted taxon pairs are retrieved in blocks via findByUUID(Set<UUID>) from CDM DB.
672 private boolean createHeterotypicSynonyms(FaunaEuropaeaImportState state
, Map
<UUID
, UUID
> fromToMap
) {
674 int limit
= state
.getConfig().getLimitSave();
675 boolean success
= true;
677 Set
<TaxonBase
> synonymSet
= new HashSet
<TaxonBase
>(limit
);
679 Set
<UUID
> synonymUuidSet
= fromToMap
.keySet();
680 Set
<UUID
> acceptedTaxaUuidSet
= new HashSet
<UUID
>(fromToMap
.values());
682 if (logger
.isTraceEnabled()) {
683 logger
.trace("Reading synonym names and accepted taxa...");
685 List
<TaxonBase
> synonyms
= getTaxonService().find(synonymUuidSet
);
686 List
<TaxonBase
> acceptedTaxa
= getTaxonService().find(acceptedTaxaUuidSet
);
687 Map
<UUID
, TaxonBase
> acceptedTaxaMap
= new HashMap
<UUID
, TaxonBase
>(acceptedTaxa
.size());
688 for (TaxonBase taxonBase
: acceptedTaxa
){
689 acceptedTaxaMap
.put(taxonBase
.getUuid(), taxonBase
);
692 if (logger
.isTraceEnabled()) {
693 logger
.trace("End reading synonyms names and accepted taxa");
694 for (UUID uuid
: synonymUuidSet
) {
695 logger
.trace("synonym uuid query: " + uuid
);
697 for (UUID uuid
: acceptedTaxaUuidSet
) {
698 logger
.trace("accepted taxon uuid query: " + uuid
);
700 for (TaxonBase tb
: synonyms
) {
701 logger
.trace("synonym uuid result: " + tb
.getUuid());
703 for (TaxonBase tb
: acceptedTaxa
) {
704 logger
.trace("accepted taxon uuid result: " + tb
.getUuid());
708 UUID mappedAcceptedTaxonUuid
= null;
709 UUID synonymUuid
= null;
710 Synonym synonym
= null;
711 TaxonBase acceptedTaxonBase
= null;
712 Taxon acceptedTaxon
= null;
714 for (TaxonBase synonymTaxonBase
: synonyms
) {
717 synonym
= synonymTaxonBase
.deproxy(synonymTaxonBase
, Synonym
.class);
718 synonymUuid
= synonym
.getUuid();
719 mappedAcceptedTaxonUuid
= fromToMap
.get(synonymUuid
);
720 acceptedTaxonBase
= null;
722 acceptedTaxonBase
= acceptedTaxaMap
.get(mappedAcceptedTaxonUuid
);
723 if (logger
.isDebugEnabled()) {
724 logger
.debug("Parent (" + mappedAcceptedTaxonUuid
+ ") found for child (" + synonymUuid
+ ")");
726 acceptedTaxon
= acceptedTaxonBase
.deproxy(acceptedTaxonBase
, Taxon
.class);
728 if (synonym
!= null && acceptedTaxon
!= null) {
730 //TODO: in case original genus exists must add synonym to original genus instead of to accepted taxon
731 acceptedTaxon
.addSynonym(synonym
, SynonymRelationshipType
.HETEROTYPIC_SYNONYM_OF());
733 if (logger
.isDebugEnabled()) {
734 logger
.debug("Accepted taxon - synonym (" + mappedAcceptedTaxonUuid
+ " - " + synonymUuid
+
735 ") relationship created");
737 if (synonym
!= null && !synonymSet
.contains(synonym
)) {
739 synonymSet
.add(synonym
);
741 if (logger
.isTraceEnabled()) {
742 logger
.trace("Synonym (" + synonymUuid
+ ") added to Set");
746 if (logger
.isDebugEnabled()) {
747 logger
.debug("Duplicated synonym (" + synonymUuid
+ ")");
751 if (logger
.isDebugEnabled()) {
752 logger
.debug("Accepted taxon (" + mappedAcceptedTaxonUuid
+ ") or misapplied name (" + synonymUuid
+ " is null");
755 } catch (Exception e
) {
756 logger
.error("Error creating synonym relationship: accepted taxon-synonym (" +
757 mappedAcceptedTaxonUuid
+ "-" + synonymUuid
+ ")", e
);
760 if (logger
.isTraceEnabled()) {
761 logger
.trace("Start saving synonymSet");
763 getTaxonService().save(synonymSet
);
764 if (logger
.isTraceEnabled()) {
765 logger
.trace("End saving synonymSet");
768 acceptedTaxaUuidSet
= null;