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
;
39 import eu
.etaxonomy
.cdm
.persistence
.query
.MatchMode
;
44 * @author a.babadshanjan
49 public class FaunaEuropaeaRelTaxonIncludeImport
extends FaunaEuropaeaImportBase
{
51 public static final String OS_NAMESPACE_TAXON
= "Taxon";
52 private static final Logger logger
= Logger
.getLogger(FaunaEuropaeaRelTaxonIncludeImport
.class);
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();
99 // MapWrapper<TaxonBase> taxonStore = (MapWrapper<TaxonBase>)stores.get(ICdmIO.TAXON_STORE);
100 // taxonStore.makeEmpty();
101 // taxonStore = null;
102 MapWrapper
<TeamOrPersonBase
> authorStore
= (MapWrapper
<TeamOrPersonBase
>)stores
.get(ICdmIO
.TEAM_STORE
);
103 authorStore
.makeEmpty();
105 if(logger
.isInfoEnabled()) { logger
.info("Start making relationships..."); }
107 TransactionStatus txStatus
= startTransaction();
109 TaxonBase taxon
= getTaxonService().find(UUID
.fromString("5932B630-5299-4A65-A4BF-BC38C6C108E2"));
110 sourceRef
= taxon
.getSec();
112 TaxonomicTree tree
= getTaxonomicTreeFor(state
, sourceRef
);
113 commitTransaction(txStatus
);
115 //ProfilerController.memorySnapshot();
116 if (state
.getConfig().isDoTaxonomicallyIncluded()) {
117 success
= processParentsChildren(state
);
119 //ProfilerController.memorySnapshot();
120 if (state
.getConfig().isDoMisappliedNames()) {
121 success
= processMisappliedNames(state
);
123 //ProfilerController.memorySnapshot();
124 if (state
.getConfig().isDoHeterotypicSynonyms()) {
125 if(logger
.isInfoEnabled()) {
126 logger
.info("Start making heterotypic synonym relationships...");
128 success
= processHeterotypicSynonyms(state
, ALL_SYNONYM_FROM_CLAUSE
);
130 //ProfilerController.memorySnapshot();
132 logger
.info("End making taxa...");
137 /** Retrieve child-parent uuid map from CDM DB */
138 private boolean processParentsChildren(FaunaEuropaeaImportState state
) {
140 int limit
= state
.getConfig().getLimitSave();
142 TransactionStatus txStatus
= null;
144 Map
<UUID
, UUID
> childParentMap
= null;
145 FaunaEuropaeaImportConfigurator fauEuConfig
= state
.getConfig();
146 Source source
= fauEuConfig
.getSource();
148 boolean success
= true;
153 String selectColumns
= " SELECT Taxon.UUID AS ChildUuid, Parent.UUID AS ParentUuid ";
155 String fromClause
= " FROM Taxon INNER JOIN Taxon AS Parent " +
156 " ON Taxon.TAX_TAX_IDPARENT = Parent.TAX_ID " +
157 " WHERE (Taxon.TAX_VALID <> 0) AND (Taxon.TAX_AUT_ID <> " + A_AUCT
+ " OR Taxon.TAX_AUT_ID IS NULL )";
159 String orderClause
= " ORDER BY Taxon.TAX_RNK_ID ASC";
162 selectCount
+ fromClause
;
165 selectColumns
+ fromClause
+ orderClause
;
167 if(logger
.isInfoEnabled()) { logger
.info("Start making taxonomically included relationships..."); }
171 ResultSet rs
= source
.getResultSet(countQuery
);
173 int count
= rs
.getInt(1);
175 rs
= source
.getResultSet(selectQuery
);
177 if (logger
.isInfoEnabled()) {
178 logger
.info("Number of rows: " + count
);
179 logger
.info("Count Query: " + countQuery
);
180 logger
.info("Select Query: " + selectQuery
);
185 if ((i
++ % limit
) == 0) {
187 txStatus
= startTransaction();
188 childParentMap
= new HashMap
<UUID
, UUID
>(limit
);
190 if(logger
.isInfoEnabled()) {
191 logger
.info("Taxonomically included retrieved: " + (i
-1));
195 String childUuidStr
= rs
.getString("ChildUuid");
196 String parentUuidStr
= rs
.getString("ParentUuid");
197 UUID childUuid
= UUID
.fromString(childUuidStr
);
198 UUID parentUuid
= UUID
.fromString(parentUuidStr
);
200 if (!childParentMap
.containsKey(childUuid
)) {
202 childParentMap
.put(childUuid
, parentUuid
);
205 if(logger
.isDebugEnabled()) {
206 logger
.debug("Duplicated child UUID (" + childUuid
+ ")");
209 if (((i
% limit
) == 0 && i
!= 1 ) || i
== count
) {
211 success
= createParentChildRelationships(state
, childParentMap
);
213 childParentMap
= null;
214 commitTransaction(txStatus
);
216 if(logger
.isInfoEnabled()) {
217 logger
.info("i = " + i
+ " - Transaction committed");
222 } catch (SQLException e
) {
223 logger
.error("SQLException:" + e
);
230 /** Retrieve misapplied name / accepted taxon uuid map from CDM DB */
231 private boolean processMisappliedNames(FaunaEuropaeaImportState state
) {
233 int limit
= state
.getConfig().getLimitSave();
235 TransactionStatus txStatus
= null;
237 Map
<UUID
, UUID
> childParentMap
= null;
238 FaunaEuropaeaImportConfigurator fauEuConfig
= state
.getConfig();
239 Source source
= fauEuConfig
.getSource();
241 boolean success
= true;
246 String selectColumns
= " SELECT Taxon.UUID AS MisappliedUuid, Parent.UUID AS AcceptedUuid ";
248 String fromClause
= " FROM Taxon INNER JOIN Taxon AS Parent " +
249 " ON Taxon.TAX_TAX_IDPARENT = Parent.TAX_ID " +
250 " WHERE (Taxon.TAX_VALID = 0) AND (Taxon.TAX_AUT_ID = " + A_AUCT
+ ")";
252 String orderClause
= " ORDER BY dbo.Taxon.TAX_RNK_ID ASC ";
255 selectCount
+ fromClause
;
258 selectColumns
+ fromClause
+ orderClause
;
260 if(logger
.isInfoEnabled()) { logger
.info("Start making misapplied name relationships..."); }
264 ResultSet rs
= source
.getResultSet(countQuery
);
266 int count
= rs
.getInt(1);
268 rs
= source
.getResultSet(selectQuery
);
270 if (logger
.isInfoEnabled()) {
271 logger
.info("Number of rows: " + count
);
272 logger
.info("Count Query: " + countQuery
);
273 logger
.info("Select Query: " + selectQuery
);
278 if ((i
++ % limit
) == 0) {
280 txStatus
= startTransaction();
281 childParentMap
= new HashMap
<UUID
, UUID
>(limit
);
283 if(logger
.isInfoEnabled()) {
284 logger
.info("Misapplied names retrieved: " + (i
-1) );
288 String childUuidStr
= rs
.getString("MisappliedUuid");
289 String parentUuidStr
= rs
.getString("AcceptedUuid");
290 UUID childUuid
= UUID
.fromString(childUuidStr
);
291 UUID parentUuid
= UUID
.fromString(parentUuidStr
);
293 if (!childParentMap
.containsKey(childUuid
)) {
295 childParentMap
.put(childUuid
, parentUuid
);
298 if(logger
.isDebugEnabled()) {
299 logger
.debug("Duplicated child UUID (" + childUuid
+ ")");
303 if (((i
% limit
) == 0 && i
!= 1 ) || i
== count
) {
305 success
= createMisappliedNameRelationships(state
, childParentMap
);
307 childParentMap
= null;
308 commitTransaction(txStatus
);
310 if(logger
.isInfoEnabled()) {
311 logger
.info("i = " + i
+ " - Transaction committed");
316 } catch (SQLException e
) {
317 logger
.error("SQLException:" + e
);
325 /** Retrieve synonyms from FauEuDB DB */
326 private boolean processHeterotypicSynonyms(FaunaEuropaeaImportState state
, String fromClause
) {
328 FaunaEuropaeaImportConfigurator fauEuConfig
= state
.getConfig();
329 Source source
= fauEuConfig
.getSource();
330 boolean success
= true;
335 String selectColumns
= " SELECT Taxon.UUID AS SynonymUuid, Parent.UUID AS AcceptedUuid ";
337 String orderClause
= " ORDER BY dbo.Taxon.TAX_RNK_ID ASC ";
340 selectCount
+ fromClause
;
343 selectColumns
+ fromClause
+ orderClause
;
344 logger
.debug(selectQuery
);
348 ResultSet rs
= source
.getResultSet(countQuery
);
350 int count
= rs
.getInt(1);
352 rs
= source
.getResultSet(selectQuery
);
354 if (logger
.isInfoEnabled()) {
355 logger
.info("Number of rows: " + count
);
356 logger
.info("Count Query: " + countQuery
);
357 logger
.info("Select Query: " + selectQuery
);
360 success
= storeSynonymRelationships(rs
, count
, state
);
362 } catch (SQLException e
) {
363 logger
.error("SQLException:" + e
);
372 private boolean storeSynonymRelationships(ResultSet rs
, int count
, FaunaEuropaeaImportState state
)
373 throws SQLException
{
375 TransactionStatus txStatus
= null;
376 Map
<UUID
, UUID
> synonymAcceptedMap
= null;
378 boolean success
= true;
379 int limit
= state
.getConfig().getLimitSave();
383 if ((i
++ % limit
) == 0) {
385 txStatus
= startTransaction();
386 synonymAcceptedMap
= new HashMap
<UUID
, UUID
>(limit
);
388 if(logger
.isInfoEnabled()) {
389 logger
.info("Synonyms retrieved: " + (i
-1));
393 String synonymUuidStr
= rs
.getString("SynonymUuid");
394 String acceptedUuidStr
= rs
.getString("AcceptedUuid");
395 UUID synonymUuid
= UUID
.fromString(synonymUuidStr
);
396 UUID acceptedUuid
= UUID
.fromString(acceptedUuidStr
);
398 if (!synonymAcceptedMap
.containsKey(synonymUuid
)) {
400 synonymAcceptedMap
.put(synonymUuid
, acceptedUuid
);
403 if(logger
.isDebugEnabled()) {
404 logger
.debug("Duplicated synonym UUID (" + synonymUuid
+ ")");
408 if (((i
% limit
) == 0 && i
!= 1 ) || i
== count
) {
410 success
= createHeterotypicSynonyms(state
, synonymAcceptedMap
);
412 synonymAcceptedMap
= null;
413 commitTransaction(txStatus
);
415 if(logger
.isInfoEnabled()) {
416 logger
.info("i = " + i
+ " - Transaction committed");
427 /* Creates parent-child relationships.
428 * Parent-child pairs are retrieved in blocks via findByUUID(Set<UUID>) from CDM DB.
430 private boolean createParentChildRelationships(FaunaEuropaeaImportState state
, Map
<UUID
, UUID
> childParentMap
) {
431 //gets the taxon "Hydroscaphidae"(family)
432 TaxonBase taxon
= getTaxonService().find(UUID
.fromString("5932B630-5299-4A65-A4BF-BC38C6C108E2"));
433 sourceRef
= taxon
.getSec();
434 boolean success
= true;
435 int limit
= state
.getConfig().getLimitSave();
437 TaxonomicTree tree
= getTaxonomicTreeFor(state
, sourceRef
);
439 Set
<TaxonBase
> childSet
= new HashSet
<TaxonBase
>(limit
);
441 Set
<UUID
> childKeysSet
= childParentMap
.keySet();
442 Set
<UUID
> parentValuesSet
= new HashSet
<UUID
>(childParentMap
.values());
444 if (logger
.isTraceEnabled()) {
445 logger
.trace("Start reading children and parents");
447 List
<TaxonBase
> children
= getTaxonService().find(childKeysSet
);
448 List
<TaxonBase
> parents
= getTaxonService().find(parentValuesSet
);
449 Map
<UUID
, TaxonBase
> parentsMap
= new HashMap
<UUID
, TaxonBase
>(parents
.size());
450 for (TaxonBase taxonBase
: parents
){
451 parentsMap
.put(taxonBase
.getUuid(), taxonBase
);
454 if (logger
.isTraceEnabled()) {
455 logger
.debug("End reading children and parents");
456 for (UUID uuid
: childKeysSet
) {
457 logger
.trace("child uuid query: " + uuid
);
459 for (UUID uuid
: parentValuesSet
) {
460 logger
.trace("parent uuid query: " + uuid
);
462 for (TaxonBase tb
: children
) {
463 logger
.trace("child uuid result: " + tb
.getUuid());
465 for (TaxonBase tb
: parents
) {
466 logger
.trace("parent uuid result: " + tb
.getUuid());
470 UUID mappedParentUuid
= null;
471 UUID childUuid
= null;
473 for (TaxonBase child
: children
) {
476 Taxon childTaxon
= child
.deproxy(child
, Taxon
.class);
477 childUuid
= childTaxon
.getUuid();
478 mappedParentUuid
= childParentMap
.get(childUuid
);
479 TaxonBase parent
= null;
481 TaxonBase potentialParent
= parentsMap
.get(mappedParentUuid
);
482 // for (TaxonBase potentialParent : parents ) {
483 // parentUuid = potentialParent.getUuid();
484 // if(parentUuid.equals(mappedParentUuid)) {
485 parent
= potentialParent
;
486 if (logger
.isDebugEnabled()) {
487 logger
.debug("Parent (" + mappedParentUuid
+ ") found for child (" + childUuid
+ ")");
493 Taxon parentTaxon
= parent
.deproxy(parent
, Taxon
.class);
495 if (childTaxon
!= null && parentTaxon
!= null) {
497 tree
.addParentChild(parentTaxon
, childTaxon
, sourceRef
, null);
499 if (logger
.isDebugEnabled()) {
500 logger
.debug("Parent-child (" + mappedParentUuid
+ "-" + childUuid
+
501 ") relationship created");
503 if (childTaxon
!= null && !childSet
.contains(childTaxon
)) {
505 childSet
.add(childTaxon
);
507 if (logger
.isTraceEnabled()) {
508 logger
.trace("Child taxon (" + childUuid
+ ") added to Set");
512 if (logger
.isDebugEnabled()) {
513 logger
.debug("Duplicated child taxon (" + childUuid
+ ")");
517 if (logger
.isDebugEnabled()) {
518 logger
.debug("Parent(" + mappedParentUuid
+ ") or child (" + childUuid
+ " is null");
522 } catch (Exception e
) {
523 logger
.error("Error creating taxonomically included relationship parent-child (" +
524 mappedParentUuid
+ "-" + childUuid
+ ")", e
);
528 if (logger
.isTraceEnabled()) {
529 logger
.trace("Start saving childSet");
531 getTaxonService().save(childSet
);
532 if (logger
.isTraceEnabled()) {
533 logger
.trace("End saving childSet");
536 parentValuesSet
= null;
545 /* Creates misapplied name relationships.
546 * Misapplied name-accepted taxon pairs are retrieved in blocks via findByUUID(Set<UUID>) from CDM DB.
548 private boolean createMisappliedNameRelationships(FaunaEuropaeaImportState state
, Map
<UUID
, UUID
> fromToMap
) {
550 //gets the taxon "Hydroscaphidae" (family)
552 TaxonBase taxon
= getTaxonService().find(UUID
.fromString("5932B630-5299-4A65-A4BF-BC38C6C108E2"));
553 sourceRef
= taxon
.getSec();
554 boolean success
= true;
555 int limit
= state
.getConfig().getLimitSave();
557 Set
<TaxonBase
> misappliedNameSet
= new HashSet
<TaxonBase
>(limit
);
559 Set
<UUID
> misappliedNamesSet
= fromToMap
.keySet();
560 Set
<UUID
> acceptedTaxaSet
= new HashSet
<UUID
>(fromToMap
.values());
562 if (logger
.isTraceEnabled()) {
563 logger
.trace("Start reading misapplied names and accepted taxa");
565 List
<TaxonBase
> misappliedNames
= getTaxonService().find(misappliedNamesSet
);
566 List
<TaxonBase
> acceptedTaxa
= getTaxonService().find(acceptedTaxaSet
);
567 Map
<UUID
, TaxonBase
> acceptedTaxaMap
= new HashMap
<UUID
, TaxonBase
>(acceptedTaxa
.size());
568 for (TaxonBase taxonBase
: acceptedTaxa
){
569 acceptedTaxaMap
.put(taxonBase
.getUuid(), taxonBase
);
572 if (logger
.isTraceEnabled()) {
573 logger
.info("End reading misapplied names and accepted taxa");
574 for (UUID uuid
: misappliedNamesSet
) {
575 logger
.trace("misapplied name uuid query: " + uuid
);
577 for (UUID uuid
: acceptedTaxaSet
) {
578 logger
.trace("accepted taxon uuid query: " + uuid
);
580 for (TaxonBase tb
: misappliedNames
) {
581 logger
.trace("misapplied name uuid result: " + tb
.getUuid());
583 for (TaxonBase tb
: acceptedTaxa
) {
584 logger
.trace("accepted taxon uuid result: " + tb
.getUuid());
588 UUID mappedAcceptedTaxonUuid
= null;
589 UUID misappliedNameUuid
= null;
590 Taxon misappliedNameTaxon
= null;
591 TaxonBase acceptedTaxonBase
= null;
592 Taxon acceptedTaxon
= null;
594 for (TaxonBase misappliedName
: misappliedNames
) {
597 misappliedNameTaxon
= misappliedName
.deproxy(misappliedName
, Taxon
.class);
598 misappliedNameUuid
= misappliedNameTaxon
.getUuid();
599 mappedAcceptedTaxonUuid
= fromToMap
.get(misappliedNameUuid
);
600 acceptedTaxonBase
= null;
602 acceptedTaxonBase
= acceptedTaxaMap
.get(mappedAcceptedTaxonUuid
);
603 if (logger
.isDebugEnabled()) {
604 logger
.debug("Parent (" + mappedAcceptedTaxonUuid
+ ") found for child (" + misappliedNameUuid
+ ")");
607 acceptedTaxon
= acceptedTaxonBase
.deproxy(acceptedTaxonBase
, Taxon
.class);
609 if (misappliedNameTaxon
!= null && acceptedTaxon
!= null) {
611 acceptedTaxon
.addMisappliedName(misappliedNameTaxon
, sourceRef
, null);
613 if (logger
.isDebugEnabled()) {
614 logger
.debug("Accepted taxon / misapplied name (" + mappedAcceptedTaxonUuid
+ "-" + misappliedNameUuid
+
615 ") relationship created");
617 if (!misappliedNameSet
.contains(misappliedNameTaxon
)) {
619 misappliedNameSet
.add(misappliedNameTaxon
);
621 if (logger
.isTraceEnabled()) {
622 logger
.trace("Misapplied name taxon (" + misappliedNameUuid
+ ") added to Set");
626 if (logger
.isDebugEnabled()) {
627 logger
.debug("Duplicated misapplied name taxon (" + misappliedNameUuid
+ ")");
631 if (logger
.isDebugEnabled()) {
632 logger
.debug("Accepted taxon (" + mappedAcceptedTaxonUuid
+ ") or misapplied name (" + misappliedNameUuid
+ " is null");
636 if (misappliedNameTaxon
!= null && !misappliedNameSet
.contains(misappliedNameTaxon
)) {
637 misappliedNameSet
.add(misappliedNameTaxon
);
638 if (logger
.isTraceEnabled()) {
639 logger
.trace("Misapplied name taxon (" + misappliedNameUuid
+ ") added to Set");
642 if (logger
.isDebugEnabled()) {
643 logger
.debug("Duplicated misapplied name taxon (" + misappliedNameUuid
+ ")");
647 } catch (Exception e
) {
648 logger
.error("Error creating misapplied name relationship accepted taxon-misapplied name (" +
649 mappedAcceptedTaxonUuid
+ "-" + misappliedNameUuid
+ ")", e
);
653 if (logger
.isTraceEnabled()) {
654 logger
.trace("Start saving misappliedNameSet");
656 getTaxonService().save(misappliedNameSet
);
657 if (logger
.isTraceEnabled()) {
658 logger
.trace("End saving misappliedNameSet");
661 acceptedTaxaSet
= null;
662 misappliedNameSet
= null;
663 misappliedNames
= null;
670 /* Creates heterotypic synonym relationships.
671 * Synonym-accepted taxon pairs are retrieved in blocks via findByUUID(Set<UUID>) from CDM DB.
673 private boolean createHeterotypicSynonyms(FaunaEuropaeaImportState state
, Map
<UUID
, UUID
> fromToMap
) {
675 int limit
= state
.getConfig().getLimitSave();
676 boolean success
= true;
678 Set
<TaxonBase
> synonymSet
= new HashSet
<TaxonBase
>(limit
);
680 Set
<UUID
> synonymUuidSet
= fromToMap
.keySet();
681 Set
<UUID
> acceptedTaxaUuidSet
= new HashSet
<UUID
>(fromToMap
.values());
683 if (logger
.isTraceEnabled()) {
684 logger
.trace("Reading synonym names and accepted taxa...");
686 List
<TaxonBase
> synonyms
= getTaxonService().find(synonymUuidSet
);
687 List
<TaxonBase
> acceptedTaxa
= getTaxonService().find(acceptedTaxaUuidSet
);
688 Map
<UUID
, TaxonBase
> acceptedTaxaMap
= new HashMap
<UUID
, TaxonBase
>(acceptedTaxa
.size());
689 for (TaxonBase taxonBase
: acceptedTaxa
){
690 acceptedTaxaMap
.put(taxonBase
.getUuid(), taxonBase
);
693 if (logger
.isTraceEnabled()) {
694 logger
.trace("End reading synonyms names and accepted taxa");
695 for (UUID uuid
: synonymUuidSet
) {
696 logger
.trace("synonym uuid query: " + uuid
);
698 for (UUID uuid
: acceptedTaxaUuidSet
) {
699 logger
.trace("accepted taxon uuid query: " + uuid
);
701 for (TaxonBase tb
: synonyms
) {
702 logger
.trace("synonym uuid result: " + tb
.getUuid());
704 for (TaxonBase tb
: acceptedTaxa
) {
705 logger
.trace("accepted taxon uuid result: " + tb
.getUuid());
709 UUID mappedAcceptedTaxonUuid
= null;
710 UUID synonymUuid
= null;
711 Synonym synonym
= null;
712 TaxonBase acceptedTaxonBase
= null;
713 Taxon acceptedTaxon
= null;
715 for (TaxonBase synonymTaxonBase
: synonyms
) {
718 synonym
= synonymTaxonBase
.deproxy(synonymTaxonBase
, Synonym
.class);
719 synonymUuid
= synonym
.getUuid();
720 mappedAcceptedTaxonUuid
= fromToMap
.get(synonymUuid
);
721 acceptedTaxonBase
= null;
723 acceptedTaxonBase
= acceptedTaxaMap
.get(mappedAcceptedTaxonUuid
);
724 if (logger
.isDebugEnabled()) {
725 logger
.debug("Parent (" + mappedAcceptedTaxonUuid
+ ") found for child (" + synonymUuid
+ ")");
727 acceptedTaxon
= acceptedTaxonBase
.deproxy(acceptedTaxonBase
, Taxon
.class);
729 if (synonym
!= null && acceptedTaxon
!= null) {
731 //TODO: in case original genus exists must add synonym to original genus instead of to accepted taxon
732 acceptedTaxon
.addSynonym(synonym
, SynonymRelationshipType
.HETEROTYPIC_SYNONYM_OF());
734 if (logger
.isDebugEnabled()) {
735 logger
.debug("Accepted taxon - synonym (" + mappedAcceptedTaxonUuid
+ " - " + synonymUuid
+
736 ") relationship created");
738 if (synonym
!= null && !synonymSet
.contains(synonym
)) {
740 synonymSet
.add(synonym
);
742 if (logger
.isTraceEnabled()) {
743 logger
.trace("Synonym (" + synonymUuid
+ ") added to Set");
747 if (logger
.isDebugEnabled()) {
748 logger
.debug("Duplicated synonym (" + synonymUuid
+ ")");
752 if (logger
.isDebugEnabled()) {
753 logger
.debug("Accepted taxon (" + mappedAcceptedTaxonUuid
+ ") or misapplied name (" + synonymUuid
+ " is null");
756 } catch (Exception e
) {
757 logger
.error("Error creating synonym relationship: accepted taxon-synonym (" +
758 mappedAcceptedTaxonUuid
+ "-" + synonymUuid
+ ")", e
);
761 if (logger
.isTraceEnabled()) {
762 logger
.trace("Start saving synonymSet");
764 getTaxonService().save(synonymSet
);
765 if (logger
.isTraceEnabled()) {
766 logger
.trace("End saving synonymSet");
769 acceptedTaxaUuidSet
= null;