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
.berlinModel
;
12 import static eu
.etaxonomy
.cdm
.io
.berlinModel
.BerlinModelTransformer
.NAME_REL_HAS_SAME_TYPE_AS
;
13 import static eu
.etaxonomy
.cdm
.io
.berlinModel
.BerlinModelTransformer
.NAME_REL_IS_BASIONYM_FOR
;
14 import static eu
.etaxonomy
.cdm
.io
.berlinModel
.BerlinModelTransformer
.NAME_REL_IS_CONSERVED_TYPE_OF
;
15 import static eu
.etaxonomy
.cdm
.io
.berlinModel
.BerlinModelTransformer
.NAME_REL_IS_FEMALE_PARENT_OF
;
16 import static eu
.etaxonomy
.cdm
.io
.berlinModel
.BerlinModelTransformer
.NAME_REL_IS_FIRST_PARENT_OF
;
17 import static eu
.etaxonomy
.cdm
.io
.berlinModel
.BerlinModelTransformer
.NAME_REL_IS_LATER_HOMONYM_OF
;
18 import static eu
.etaxonomy
.cdm
.io
.berlinModel
.BerlinModelTransformer
.NAME_REL_IS_LECTOTYPE_OF
;
19 import static eu
.etaxonomy
.cdm
.io
.berlinModel
.BerlinModelTransformer
.NAME_REL_IS_MALE_PARENT_OF
;
20 import static eu
.etaxonomy
.cdm
.io
.berlinModel
.BerlinModelTransformer
.NAME_REL_IS_ORTHOGRAPHIC_VARIANT_OF
;
21 import static eu
.etaxonomy
.cdm
.io
.berlinModel
.BerlinModelTransformer
.NAME_REL_IS_REJECTED_TYPE_OF
;
22 import static eu
.etaxonomy
.cdm
.io
.berlinModel
.BerlinModelTransformer
.NAME_REL_IS_REPLACED_SYNONYM_FOR
;
23 import static eu
.etaxonomy
.cdm
.io
.berlinModel
.BerlinModelTransformer
.NAME_REL_IS_SECOND_PARENT_OF
;
24 import static eu
.etaxonomy
.cdm
.io
.berlinModel
.BerlinModelTransformer
.NAME_REL_IS_TYPE_OF
;
25 import static eu
.etaxonomy
.cdm
.io
.berlinModel
.BerlinModelTransformer
.NAME_REL_TYPE_NOT_DESIGNATED
;
27 import java
.sql
.ResultSet
;
28 import java
.sql
.SQLException
;
29 import java
.util
.HashSet
;
33 import org
.apache
.log4j
.Logger
;
34 import org
.springframework
.stereotype
.Component
;
36 import eu
.etaxonomy
.cdm
.io
.common
.ICdmIO
;
37 import eu
.etaxonomy
.cdm
.io
.common
.IImportConfigurator
;
38 import eu
.etaxonomy
.cdm
.io
.common
.MapWrapper
;
39 import eu
.etaxonomy
.cdm
.io
.common
.Source
;
40 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
41 import eu
.etaxonomy
.cdm
.model
.name
.BotanicalName
;
42 import eu
.etaxonomy
.cdm
.model
.name
.HybridRelationshipType
;
43 import eu
.etaxonomy
.cdm
.model
.name
.NameRelationshipType
;
44 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameBase
;
45 import eu
.etaxonomy
.cdm
.model
.reference
.ReferenceBase
;
46 import eu
.etaxonomy
.cdm
.strategy
.exceptions
.UnknownCdmTypeException
;
54 public class BerlinModelTaxonNameRelationImport
extends BerlinModelImportBase
{
55 private static final Logger logger
= Logger
.getLogger(BerlinModelTaxonNameRelationImport
.class);
57 private static int modCount
= 5000;
59 public BerlinModelTaxonNameRelationImport(){
64 * @see eu.etaxonomy.cdm.io.common.CdmIoBase#doCheck(eu.etaxonomy.cdm.io.common.IImportConfigurator)
67 protected boolean doCheck(IImportConfigurator config
){
68 boolean result
= true;
69 logger
.warn("Checking for TaxonNameRelations not yet implemented");
70 //result &= checkArticlesWithoutJournal(bmiConfig);
71 //result &= checkPartOfJournal(bmiConfig);
77 * @see eu.etaxonomy.cdm.io.common.CdmIoBase#doInvoke(eu.etaxonomy.cdm.io.common.IImportConfigurator, eu.etaxonomy.cdm.api.application.CdmApplicationController, java.util.Map)
80 protected boolean doInvoke(IImportConfigurator config
,
81 Map
<String
, MapWrapper
<?
extends CdmBase
>> stores
){
83 MapWrapper
<TaxonNameBase
> taxonNameMap
= (MapWrapper
<TaxonNameBase
>)stores
.get(ICdmIO
.TAXONNAME_STORE
);
84 MapWrapper
<ReferenceBase
> referenceMap
= (MapWrapper
<ReferenceBase
>)stores
.get(ICdmIO
.REFERENCE_STORE
);
86 Set
<TaxonNameBase
> nameStore
= new HashSet
<TaxonNameBase
>();
87 BerlinModelImportConfigurator bmiConfig
= (BerlinModelImportConfigurator
)config
;
88 Source source
= bmiConfig
.getSource();
90 logger
.info("start makeNameRelationships ...");
93 //get data from database
95 " SELECT RelName.*, FromName.nameId as name1Id, ToName.nameId as name2Id, RefDetail.Details " +
96 " FROM Name as FromName INNER JOIN " +
97 " RelName ON FromName.NameId = RelName.NameFk1 INNER JOIN " +
98 " Name AS ToName ON RelName.NameFk2 = ToName.NameId LEFT OUTER JOIN "+
99 " RefDetail ON RelName.RefDetailFK = RefDetail.RefDetailId " +
101 ResultSet rs
= source
.getResultSet(strQuery
) ;
107 if ((i
++ % modCount
) == 0 && i
!= 1 ){ logger
.info("RelName handled: " + (i
-1));}
109 int relNameId
= rs
.getInt("RelNameId");
110 int name1Id
= rs
.getInt("name1Id");
111 int name2Id
= rs
.getInt("name2Id");
112 int relRefFk
= rs
.getInt("refFk");
113 String details
= rs
.getString("details");
114 int relQualifierFk
= rs
.getInt("relNameQualifierFk");
116 TaxonNameBase nameFrom
= taxonNameMap
.get(name1Id
);
117 TaxonNameBase nameTo
= taxonNameMap
.get(name2Id
);
119 ReferenceBase citation
= referenceMap
.get(relRefFk
);
120 //TODO (preliminaryFlag = true testen
121 String microcitation
= details
;
122 String rule
= null; //TODO
124 if (nameFrom
!= null && nameTo
!= null){
125 if (relQualifierFk
== NAME_REL_IS_BASIONYM_FOR
){
126 nameTo
.addBasionym(nameFrom
, citation
, microcitation
, rule
);
127 }else if (relQualifierFk
== NAME_REL_IS_LATER_HOMONYM_OF
){
128 nameFrom
.addRelationshipToName(nameTo
, NameRelationshipType
.LATER_HOMONYM(), citation
, microcitation
, rule
) ;
129 }else if (relQualifierFk
== NAME_REL_IS_REPLACED_SYNONYM_FOR
){
130 nameFrom
.addRelationshipToName(nameTo
, NameRelationshipType
.REPLACED_SYNONYM(), citation
, microcitation
, rule
) ;
131 }else if (relQualifierFk
== NAME_REL_HAS_SAME_TYPE_AS
){
132 nameTo
.getHomotypicalGroup().merge(nameFrom
.getHomotypicalGroup());//nameFrom.addRelationshipToName(nameTo, NameRelationshipType.REPLACED_SYNONYM(), rule) ;
133 }else if (relQualifierFk
== NAME_REL_IS_TYPE_OF
|| relQualifierFk
== NAME_REL_IS_REJECTED_TYPE_OF
|| relQualifierFk
== NAME_REL_IS_CONSERVED_TYPE_OF
|| relQualifierFk
== NAME_REL_IS_LECTOTYPE_OF
|| relQualifierFk
== NAME_REL_TYPE_NOT_DESIGNATED
){
135 String originalNameString
= null;
136 boolean isRejectedType
= (relQualifierFk
== NAME_REL_IS_REJECTED_TYPE_OF
);
137 boolean isConservedType
= (relQualifierFk
== NAME_REL_IS_CONSERVED_TYPE_OF
);
138 boolean isLectoType
= (relQualifierFk
== NAME_REL_IS_LECTOTYPE_OF
);
139 boolean isNotDesignated
= (relQualifierFk
== NAME_REL_TYPE_NOT_DESIGNATED
);
141 //TODO addToAllNames true or false?
142 nameTo
.addNameTypeDesignation(nameFrom
, citation
, microcitation
, originalNameString
, isRejectedType
, isConservedType
, isLectoType
, isNotDesignated
, false);
144 }else if (relQualifierFk
== NAME_REL_IS_ORTHOGRAPHIC_VARIANT_OF
){
145 nameFrom
.addRelationshipToName(nameTo
, NameRelationshipType
.ORTHOGRAPHIC_VARIANT(), citation
, microcitation
, rule
) ;
146 }else if (relQualifierFk
== NAME_REL_IS_FIRST_PARENT_OF
|| relQualifierFk
== NAME_REL_IS_SECOND_PARENT_OF
|| relQualifierFk
== NAME_REL_IS_FEMALE_PARENT_OF
|| relQualifierFk
== NAME_REL_IS_MALE_PARENT_OF
){
147 //HybridRelationships
148 if (! (nameTo
instanceof BotanicalName
) || ! (nameFrom
instanceof BotanicalName
)){
149 logger
.warn("HybridrelationshipNames ("+name1Id
+"," + name2Id
+") must be of type BotanicalName but are not");
152 HybridRelationshipType hybridRelType
= BerlinModelTransformer
.relNameId2HybridRel(relQualifierFk
);
153 BotanicalName parent
= (BotanicalName
)nameFrom
;
154 BotanicalName child
= (BotanicalName
)nameTo
;
156 //TODO bug when trying to persist
157 //parent.addHybridChild(child, hybridRelType, rule);
158 logger
.warn("HybridRelationships not yet implemented");
161 } catch (UnknownCdmTypeException e
) {
167 logger
.warn("NameRelationShipType " + relQualifierFk
+ " not yet implemented");
169 nameStore
.add(nameFrom
);
176 if (nameFrom
== null){
177 logger
.warn("from TaxonName for RelName (" + relNameId
+ ") does not exist in store");
180 logger
.warn("to TaxonNames for RelName (" + relNameId
+ ") does not exist in store");
184 logger
.info("TaxonName to save: " + nameStore
.size());
185 getNameService().saveTaxonNameAll(nameStore
);
187 logger
.info("end makeNameRelationships ...");
189 } catch (SQLException e
) {
190 logger
.error("SQLException:" + e
);
197 * @see eu.etaxonomy.cdm.io.common.CdmIoBase#isIgnore(eu.etaxonomy.cdm.io.common.IImportConfigurator)
199 protected boolean isIgnore(IImportConfigurator config
){
200 return ! config
.isDoRelNames();