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);
53 private static String ALL_SYNONYM_FROM_CLAUSE
= " FROM Taxon INNER JOIN Taxon AS Parent " +
54 " ON Taxon.TAX_TAX_IDPARENT = Parent.TAX_ID " +
55 " WHERE (Taxon.TAX_VALID = 0) " +
56 " AND (Taxon.TAX_AUT_ID <> " + A_AUCT
+ " OR Taxon.TAX_AUT_ID IS NULL)";
59 * @see eu.etaxonomy.cdm.io.common.CdmIoBase#doCheck(eu.etaxonomy.cdm.io.common.IImportConfigurator)
62 protected boolean doCheck(FaunaEuropaeaImportState state
) {
63 boolean result
= true;
64 FaunaEuropaeaImportConfigurator fauEuConfig
= state
.getConfig();
65 logger
.warn("Checking for Taxa not yet fully implemented");
66 result
&= checkTaxonStatus(fauEuConfig
);
72 * @see eu.etaxonomy.cdm.io.common.CdmIoBase#isIgnore(eu.etaxonomy.cdm.io.common.IImportConfigurator)
74 protected boolean isIgnore(FaunaEuropaeaImportState state
) {
75 return ! (state
.getConfig().isDoTaxonomicallyIncluded() ||
76 state
.getConfig().isDoMisappliedNames() || state
.getConfig().isDoHeterotypicSynonyms());
79 private boolean checkTaxonStatus(FaunaEuropaeaImportConfigurator fauEuConfig
) {
80 boolean result
= true;
82 Source source
= fauEuConfig
.getSource();
84 ResultSet rs
= source
.getResultSet(sqlStr
);
86 // } catch (SQLException e) {
87 // e.printStackTrace();
92 protected boolean doInvoke(FaunaEuropaeaImportState state
) {
94 boolean success
= true;
96 Map
<String
, MapWrapper
<?
extends CdmBase
>> stores
= state
.getStores();
97 MapWrapper
<TaxonBase
> taxonStore
= (MapWrapper
<TaxonBase
>)stores
.get(ICdmIO
.TAXON_STORE
);
98 // taxonStore.makeEmpty();
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 TaxonBase taxon
= getTaxonService().find(UUID
.fromString("ac7b30dc-6207-4c71-9752-ee0fb838a271"));
108 ReferenceBase
<?
> sourceRef
= taxon
.getSec();
110 TaxonomicTree tree
= getTaxonomicTreeFor(state
, sourceRef
);
111 commitTransaction(txStatus
);
113 ProfilerController
.memorySnapshot();
114 if (state
.getConfig().isDoTaxonomicallyIncluded()) {
115 success
= processParentsChildren(state
);
117 ProfilerController
.memorySnapshot();
118 if (state
.getConfig().isDoMisappliedNames()) {
119 success
= processMisappliedNames(state
);
121 ProfilerController
.memorySnapshot();
122 if (state
.getConfig().isDoHeterotypicSynonyms()) {
123 if(logger
.isInfoEnabled()) {
124 logger
.info("Start making heterotypic synonym relationships...");
126 success
= processHeterotypicSynonyms(state
, ALL_SYNONYM_FROM_CLAUSE
);
128 ProfilerController
.memorySnapshot();
130 logger
.info("End making taxa...");
135 /** Retrieve child-parent uuid map from CDM DB */
136 private boolean processParentsChildren(FaunaEuropaeaImportState state
) {
138 int limit
= state
.getConfig().getLimitSave();
140 TransactionStatus txStatus
= null;
142 Map
<UUID
, UUID
> childParentMap
= null;
143 FaunaEuropaeaImportConfigurator fauEuConfig
= state
.getConfig();
144 Source source
= fauEuConfig
.getSource();
146 boolean success
= true;
151 String selectColumns
= " SELECT Taxon.UUID AS ChildUuid, Parent.UUID AS ParentUuid ";
153 String fromClause
= " FROM Taxon INNER JOIN Taxon AS Parent " +
154 " ON Taxon.TAX_TAX_IDPARENT = Parent.TAX_ID " +
155 " WHERE (Taxon.TAX_VALID <> 0) AND (Taxon.TAX_AUT_ID <> " + A_AUCT
+ " OR Taxon.TAX_AUT_ID IS NULL )";
157 String orderClause
= " ORDER BY Taxon.TAX_RNK_ID ASC";
160 selectCount
+ fromClause
;
163 selectColumns
+ fromClause
+ orderClause
;
165 if(logger
.isInfoEnabled()) { logger
.info("Start making taxonomically included relationships..."); }
169 ResultSet rs
= source
.getResultSet(countQuery
);
171 int count
= rs
.getInt(1);
173 rs
= source
.getResultSet(selectQuery
);
175 if (logger
.isInfoEnabled()) {
176 logger
.info("Number of rows: " + count
);
177 logger
.info("Count Query: " + countQuery
);
178 logger
.info("Select Query: " + selectQuery
);
183 if ((i
++ % limit
) == 0) {
185 txStatus
= startTransaction();
186 childParentMap
= new HashMap
<UUID
, UUID
>(limit
);
188 if(logger
.isInfoEnabled()) {
189 logger
.info("Taxonomically included retrieved: " + (i
-1));
193 String childUuidStr
= rs
.getString("ChildUuid");
194 String parentUuidStr
= rs
.getString("ParentUuid");
195 UUID childUuid
= UUID
.fromString(childUuidStr
);
196 UUID parentUuid
= UUID
.fromString(parentUuidStr
);
198 if (!childParentMap
.containsKey(childUuid
)) {
200 childParentMap
.put(childUuid
, parentUuid
);
203 if(logger
.isDebugEnabled()) {
204 logger
.debug("Duplicated child UUID (" + childUuid
+ ")");
207 if (((i
% limit
) == 0 && i
!= 1 ) || i
== count
) {
209 success
= createParentChildRelationships(state
, childParentMap
);
211 childParentMap
= null;
212 commitTransaction(txStatus
);
214 if(logger
.isInfoEnabled()) {
215 logger
.info("i = " + i
+ " - Transaction committed");
220 } catch (SQLException e
) {
221 logger
.error("SQLException:" + e
);
228 /** Retrieve misapplied name / accepted taxon uuid map from CDM DB */
229 private boolean processMisappliedNames(FaunaEuropaeaImportState state
) {
231 int limit
= state
.getConfig().getLimitSave();
233 TransactionStatus txStatus
= null;
235 Map
<UUID
, UUID
> childParentMap
= null;
236 FaunaEuropaeaImportConfigurator fauEuConfig
= state
.getConfig();
237 Source source
= fauEuConfig
.getSource();
239 boolean success
= true;
244 String selectColumns
= " SELECT Taxon.UUID AS MisappliedUuid, Parent.UUID AS AcceptedUuid ";
246 String fromClause
= " FROM Taxon INNER JOIN Taxon AS Parent " +
247 " ON Taxon.TAX_TAX_IDPARENT = Parent.TAX_ID " +
248 " WHERE (Taxon.TAX_VALID = 0) AND (Taxon.TAX_AUT_ID = " + A_AUCT
+ ")";
250 String orderClause
= " ORDER BY dbo.Taxon.TAX_RNK_ID ASC ";
253 selectCount
+ fromClause
;
256 selectColumns
+ fromClause
+ orderClause
;
258 if(logger
.isInfoEnabled()) { logger
.info("Start making misapplied name relationships..."); }
262 ResultSet rs
= source
.getResultSet(countQuery
);
264 int count
= rs
.getInt(1);
266 rs
= source
.getResultSet(selectQuery
);
268 if (logger
.isInfoEnabled()) {
269 logger
.info("Number of rows: " + count
);
270 logger
.info("Count Query: " + countQuery
);
271 logger
.info("Select Query: " + selectQuery
);
276 if ((i
++ % limit
) == 0) {
278 txStatus
= startTransaction();
279 childParentMap
= new HashMap
<UUID
, UUID
>(limit
);
281 if(logger
.isInfoEnabled()) {
282 logger
.info("Misapplied names retrieved: " + (i
-1) );
286 String childUuidStr
= rs
.getString("MisappliedUuid");
287 String parentUuidStr
= rs
.getString("AcceptedUuid");
288 UUID childUuid
= UUID
.fromString(childUuidStr
);
289 UUID parentUuid
= UUID
.fromString(parentUuidStr
);
291 if (!childParentMap
.containsKey(childUuid
)) {
293 childParentMap
.put(childUuid
, parentUuid
);
296 if(logger
.isDebugEnabled()) {
297 logger
.debug("Duplicated child UUID (" + childUuid
+ ")");
301 if (((i
% limit
) == 0 && i
!= 1 ) || i
== count
) {
303 success
= createMisappliedNameRelationships(state
, childParentMap
);
305 childParentMap
= null;
306 commitTransaction(txStatus
);
308 if(logger
.isInfoEnabled()) {
309 logger
.info("i = " + i
+ " - Transaction committed");
314 } catch (SQLException e
) {
315 logger
.error("SQLException:" + e
);
322 /** Retrieve synonyms from FauEuDB DB */
323 private boolean processHeterotypicSynonyms(FaunaEuropaeaImportState state
, String fromClause
) {
325 FaunaEuropaeaImportConfigurator fauEuConfig
= state
.getConfig();
326 Source source
= fauEuConfig
.getSource();
327 boolean success
= true;
332 String selectColumns
= " SELECT Taxon.UUID AS SynonymUuid, Parent.UUID AS AcceptedUuid ";
334 String orderClause
= " ORDER BY dbo.Taxon.TAX_RNK_ID ASC ";
337 selectCount
+ fromClause
;
340 selectColumns
+ fromClause
+ orderClause
;
341 logger
.debug(selectQuery
);
345 ResultSet rs
= source
.getResultSet(countQuery
);
347 int count
= rs
.getInt(1);
349 rs
= source
.getResultSet(selectQuery
);
351 if (logger
.isInfoEnabled()) {
352 logger
.info("Number of rows: " + count
);
353 logger
.info("Count Query: " + countQuery
);
354 logger
.info("Select Query: " + selectQuery
);
357 success
= storeSynonymRelationships(rs
, count
, state
);
359 } catch (SQLException e
) {
360 logger
.error("SQLException:" + e
);
367 private boolean storeSynonymRelationships(ResultSet rs
, int count
, FaunaEuropaeaImportState state
)
368 throws SQLException
{
370 TransactionStatus txStatus
= null;
371 Map
<UUID
, UUID
> synonymAcceptedMap
= null;
373 boolean success
= true;
374 int limit
= state
.getConfig().getLimitSave();
378 if ((i
++ % limit
) == 0) {
380 txStatus
= startTransaction();
381 synonymAcceptedMap
= new HashMap
<UUID
, UUID
>(limit
);
383 if(logger
.isInfoEnabled()) {
384 logger
.info("Synonyms retrieved: " + (i
-1));
388 String synonymUuidStr
= rs
.getString("SynonymUuid");
389 String acceptedUuidStr
= rs
.getString("AcceptedUuid");
390 UUID synonymUuid
= UUID
.fromString(synonymUuidStr
);
391 UUID acceptedUuid
= UUID
.fromString(acceptedUuidStr
);
393 if (!synonymAcceptedMap
.containsKey(synonymUuid
)) {
395 synonymAcceptedMap
.put(synonymUuid
, acceptedUuid
);
398 if(logger
.isDebugEnabled()) {
399 logger
.debug("Duplicated synonym UUID (" + synonymUuid
+ ")");
403 if (((i
% limit
) == 0 && i
!= 1 ) || i
== count
) {
405 success
= createHeterotypicSynonyms(state
, synonymAcceptedMap
);
407 synonymAcceptedMap
= null;
408 commitTransaction(txStatus
);
410 if(logger
.isInfoEnabled()) {
411 logger
.info("i = " + i
+ " - Transaction committed");
419 /* Creates parent-child relationships.
420 * Parent-child pairs are retrieved in blocks via findByUUID(Set<UUID>) from CDM DB.
422 private boolean createParentChildRelationships(FaunaEuropaeaImportState state
, Map
<UUID
, UUID
> childParentMap
) {
424 TaxonBase taxon
= getTaxonService().find(UUID
.fromString("ac7b30dc-6207-4c71-9752-ee0fb838a271"));
425 ReferenceBase
<?
> sourceRef
= taxon
.getSec();
426 boolean success
= true;
427 int limit
= state
.getConfig().getLimitSave();
429 TaxonomicTree tree
= getTaxonomicTreeFor(state
, sourceRef
);
431 Set
<TaxonBase
> childSet
= new HashSet
<TaxonBase
>(limit
);
433 Set
<UUID
> childKeysSet
= childParentMap
.keySet();
434 Set
<UUID
> parentValuesSet
= new HashSet
<UUID
>(childParentMap
.values());
436 if (logger
.isTraceEnabled()) {
437 logger
.trace("Start reading children and parents");
439 List
<TaxonBase
> children
= getTaxonService().find(childKeysSet
);
440 List
<TaxonBase
> parents
= getTaxonService().find(parentValuesSet
);
441 Map
<UUID
, TaxonBase
> parentsMap
= new HashMap
<UUID
, TaxonBase
>(parents
.size());
442 for (TaxonBase taxonBase
: parents
){
443 parentsMap
.put(taxonBase
.getUuid(), taxonBase
);
446 if (logger
.isTraceEnabled()) {
447 logger
.debug("End reading children and parents");
448 for (UUID uuid
: childKeysSet
) {
449 logger
.trace("child uuid query: " + uuid
);
451 for (UUID uuid
: parentValuesSet
) {
452 logger
.trace("parent uuid query: " + uuid
);
454 for (TaxonBase tb
: children
) {
455 logger
.trace("child uuid result: " + tb
.getUuid());
457 for (TaxonBase tb
: parents
) {
458 logger
.trace("parent uuid result: " + tb
.getUuid());
462 UUID mappedParentUuid
= null;
463 UUID childUuid
= null;
465 for (TaxonBase child
: children
) {
468 Taxon childTaxon
= child
.deproxy(child
, Taxon
.class);
469 childUuid
= childTaxon
.getUuid();
470 mappedParentUuid
= childParentMap
.get(childUuid
);
471 TaxonBase parent
= null;
473 TaxonBase potentialParent
= parentsMap
.get(mappedParentUuid
);
474 // for (TaxonBase potentialParent : parents ) {
475 // parentUuid = potentialParent.getUuid();
476 // if(parentUuid.equals(mappedParentUuid)) {
477 parent
= potentialParent
;
478 if (logger
.isDebugEnabled()) {
479 logger
.debug("Parent (" + mappedParentUuid
+ ") found for child (" + childUuid
+ ")");
485 Taxon parentTaxon
= parent
.deproxy(parent
, Taxon
.class);
487 if (childTaxon
!= null && parentTaxon
!= null) {
489 tree
.addParentChild(parentTaxon
, childTaxon
, sourceRef
, null);
491 if (logger
.isDebugEnabled()) {
492 logger
.debug("Parent-child (" + mappedParentUuid
+ "-" + childUuid
+
493 ") relationship created");
495 if (childTaxon
!= null && !childSet
.contains(childTaxon
)) {
497 childSet
.add(childTaxon
);
499 if (logger
.isTraceEnabled()) {
500 logger
.trace("Child taxon (" + childUuid
+ ") added to Set");
504 if (logger
.isDebugEnabled()) {
505 logger
.debug("Duplicated child taxon (" + childUuid
+ ")");
509 if (logger
.isDebugEnabled()) {
510 logger
.debug("Parent(" + mappedParentUuid
+ ") or child (" + childUuid
+ " is null");
514 } catch (Exception e
) {
515 logger
.error("Error creating taxonomically included relationship parent-child (" +
516 mappedParentUuid
+ "-" + childUuid
+ ")", e
);
520 if (logger
.isTraceEnabled()) {
521 logger
.trace("Start saving childSet");
523 getTaxonService().save(childSet
);
524 if (logger
.isTraceEnabled()) {
525 logger
.trace("End saving childSet");
528 parentValuesSet
= null;
537 /* Creates misapplied name relationships.
538 * Misapplied name-accepted taxon pairs are retrieved in blocks via findByUUID(Set<UUID>) from CDM DB.
540 private boolean createMisappliedNameRelationships(FaunaEuropaeaImportState state
, Map
<UUID
, UUID
> fromToMap
) {
542 TaxonBase taxon
= getTaxonService().find(UUID
.fromString("ac7b30dc-6207-4c71-9752-ee0fb838a271"));
543 ReferenceBase
<?
> sourceRef
= taxon
.getSec();
544 boolean success
= true;
545 int limit
= state
.getConfig().getLimitSave();
547 Set
<TaxonBase
> misappliedNameSet
= new HashSet
<TaxonBase
>(limit
);
549 Set
<UUID
> misappliedNamesSet
= fromToMap
.keySet();
550 Set
<UUID
> acceptedTaxaSet
= new HashSet
<UUID
>(fromToMap
.values());
552 if (logger
.isTraceEnabled()) {
553 logger
.trace("Start reading misapplied names and accepted taxa");
555 List
<TaxonBase
> misappliedNames
= getTaxonService().find(misappliedNamesSet
);
556 List
<TaxonBase
> acceptedTaxa
= getTaxonService().find(acceptedTaxaSet
);
557 Map
<UUID
, TaxonBase
> acceptedTaxaMap
= new HashMap
<UUID
, TaxonBase
>(acceptedTaxa
.size());
558 for (TaxonBase taxonBase
: acceptedTaxa
){
559 acceptedTaxaMap
.put(taxonBase
.getUuid(), taxonBase
);
562 if (logger
.isTraceEnabled()) {
563 logger
.info("End reading misapplied names and accepted taxa");
564 for (UUID uuid
: misappliedNamesSet
) {
565 logger
.trace("misapplied name uuid query: " + uuid
);
567 for (UUID uuid
: acceptedTaxaSet
) {
568 logger
.trace("accepted taxon uuid query: " + uuid
);
570 for (TaxonBase tb
: misappliedNames
) {
571 logger
.trace("misapplied name uuid result: " + tb
.getUuid());
573 for (TaxonBase tb
: acceptedTaxa
) {
574 logger
.trace("accepted taxon uuid result: " + tb
.getUuid());
578 UUID mappedAcceptedTaxonUuid
= null;
579 UUID misappliedNameUuid
= null;
580 Taxon misappliedNameTaxon
= null;
581 TaxonBase acceptedTaxonBase
= null;
582 Taxon acceptedTaxon
= null;
584 for (TaxonBase misappliedName
: misappliedNames
) {
587 misappliedNameTaxon
= misappliedName
.deproxy(misappliedName
, Taxon
.class);
588 misappliedNameUuid
= misappliedNameTaxon
.getUuid();
589 mappedAcceptedTaxonUuid
= fromToMap
.get(misappliedNameUuid
);
590 acceptedTaxonBase
= null;
592 acceptedTaxonBase
= acceptedTaxaMap
.get(mappedAcceptedTaxonUuid
);
593 if (logger
.isDebugEnabled()) {
594 logger
.debug("Parent (" + mappedAcceptedTaxonUuid
+ ") found for child (" + misappliedNameUuid
+ ")");
597 acceptedTaxon
= acceptedTaxonBase
.deproxy(acceptedTaxonBase
, Taxon
.class);
599 if (misappliedNameTaxon
!= null && acceptedTaxon
!= null) {
601 acceptedTaxon
.addMisappliedName(misappliedNameTaxon
, sourceRef
, null);
603 if (logger
.isDebugEnabled()) {
604 logger
.debug("Accepted taxon / misapplied name (" + mappedAcceptedTaxonUuid
+ "-" + misappliedNameUuid
+
605 ") relationship created");
607 if (!misappliedNameSet
.contains(misappliedNameTaxon
)) {
609 misappliedNameSet
.add(misappliedNameTaxon
);
611 if (logger
.isTraceEnabled()) {
612 logger
.trace("Misapplied name taxon (" + misappliedNameUuid
+ ") added to Set");
616 if (logger
.isDebugEnabled()) {
617 logger
.debug("Duplicated misapplied name taxon (" + misappliedNameUuid
+ ")");
621 if (logger
.isDebugEnabled()) {
622 logger
.debug("Accepted taxon (" + mappedAcceptedTaxonUuid
+ ") or misapplied name (" + misappliedNameUuid
+ " is null");
626 if (misappliedNameTaxon
!= null && !misappliedNameSet
.contains(misappliedNameTaxon
)) {
627 misappliedNameSet
.add(misappliedNameTaxon
);
628 if (logger
.isTraceEnabled()) {
629 logger
.trace("Misapplied name taxon (" + misappliedNameUuid
+ ") added to Set");
632 if (logger
.isDebugEnabled()) {
633 logger
.debug("Duplicated misapplied name taxon (" + misappliedNameUuid
+ ")");
637 } catch (Exception e
) {
638 logger
.error("Error creating misapplied name relationship accepted taxon-misapplied name (" +
639 mappedAcceptedTaxonUuid
+ "-" + misappliedNameUuid
+ ")", e
);
643 if (logger
.isTraceEnabled()) {
644 logger
.trace("Start saving misappliedNameSet");
646 getTaxonService().save(misappliedNameSet
);
647 if (logger
.isTraceEnabled()) {
648 logger
.trace("End saving misappliedNameSet");
651 acceptedTaxaSet
= null;
652 misappliedNameSet
= null;
653 misappliedNames
= null;
660 /* Creates heterotypic synonym relationships.
661 * Synonym-accepted taxon pairs are retrieved in blocks via findByUUID(Set<UUID>) from CDM DB.
663 private boolean createHeterotypicSynonyms(FaunaEuropaeaImportState state
, Map
<UUID
, UUID
> fromToMap
) {
665 int limit
= state
.getConfig().getLimitSave();
666 boolean success
= true;
668 Set
<TaxonBase
> synonymSet
= new HashSet
<TaxonBase
>(limit
);
670 Set
<UUID
> synonymUuidSet
= fromToMap
.keySet();
671 Set
<UUID
> acceptedTaxaUuidSet
= new HashSet
<UUID
>(fromToMap
.values());
673 if (logger
.isTraceEnabled()) {
674 logger
.trace("Reading synonym names and accepted taxa...");
676 List
<TaxonBase
> synonyms
= getTaxonService().find(synonymUuidSet
);
677 List
<TaxonBase
> acceptedTaxa
= getTaxonService().find(acceptedTaxaUuidSet
);
678 Map
<UUID
, TaxonBase
> acceptedTaxaMap
= new HashMap
<UUID
, TaxonBase
>(acceptedTaxa
.size());
679 for (TaxonBase taxonBase
: acceptedTaxa
){
680 acceptedTaxaMap
.put(taxonBase
.getUuid(), taxonBase
);
683 if (logger
.isTraceEnabled()) {
684 logger
.trace("End reading synonyms names and accepted taxa");
685 for (UUID uuid
: synonymUuidSet
) {
686 logger
.trace("synonym uuid query: " + uuid
);
688 for (UUID uuid
: acceptedTaxaUuidSet
) {
689 logger
.trace("accepted taxon uuid query: " + uuid
);
691 for (TaxonBase tb
: synonyms
) {
692 logger
.trace("synonym uuid result: " + tb
.getUuid());
694 for (TaxonBase tb
: acceptedTaxa
) {
695 logger
.trace("accepted taxon uuid result: " + tb
.getUuid());
699 UUID mappedAcceptedTaxonUuid
= null;
700 UUID synonymUuid
= null;
701 Synonym synonym
= null;
702 TaxonBase acceptedTaxonBase
= null;
703 Taxon acceptedTaxon
= null;
705 for (TaxonBase synonymTaxonBase
: synonyms
) {
708 synonym
= synonymTaxonBase
.deproxy(synonymTaxonBase
, Synonym
.class);
709 synonymUuid
= synonym
.getUuid();
710 mappedAcceptedTaxonUuid
= fromToMap
.get(synonymUuid
);
711 acceptedTaxonBase
= null;
713 acceptedTaxonBase
= acceptedTaxaMap
.get(mappedAcceptedTaxonUuid
);
714 if (logger
.isDebugEnabled()) {
715 logger
.debug("Parent (" + mappedAcceptedTaxonUuid
+ ") found for child (" + synonymUuid
+ ")");
717 acceptedTaxon
= acceptedTaxonBase
.deproxy(acceptedTaxonBase
, Taxon
.class);
719 if (synonym
!= null && acceptedTaxon
!= null) {
721 //TODO: in case original genus exists must add synonym to original genus instead of to accepted taxon
722 acceptedTaxon
.addSynonym(synonym
, SynonymRelationshipType
.HETEROTYPIC_SYNONYM_OF());
724 if (logger
.isDebugEnabled()) {
725 logger
.debug("Accepted taxon - synonym (" + mappedAcceptedTaxonUuid
+ " - " + synonymUuid
+
726 ") relationship created");
728 if (synonym
!= null && !synonymSet
.contains(synonym
)) {
730 synonymSet
.add(synonym
);
732 if (logger
.isTraceEnabled()) {
733 logger
.trace("Synonym (" + synonymUuid
+ ") added to Set");
737 if (logger
.isDebugEnabled()) {
738 logger
.debug("Duplicated synonym (" + synonymUuid
+ ")");
742 if (logger
.isDebugEnabled()) {
743 logger
.debug("Accepted taxon (" + mappedAcceptedTaxonUuid
+ ") or misapplied name (" + synonymUuid
+ " is null");
746 } catch (Exception e
) {
747 logger
.error("Error creating synonym relationship: accepted taxon-synonym (" +
748 mappedAcceptedTaxonUuid
+ "-" + synonymUuid
+ ")", e
);
751 if (logger
.isTraceEnabled()) {
752 logger
.trace("Start saving synonymSet");
754 getTaxonService().save(synonymSet
);
755 if (logger
.isTraceEnabled()) {
756 logger
.trace("End saving synonymSet");
759 acceptedTaxaUuidSet
= null;