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
.in
;
12 import java
.sql
.ResultSet
;
13 import java
.sql
.SQLException
;
14 import java
.util
.HashMap
;
15 import java
.util
.HashSet
;
19 import org
.apache
.log4j
.Logger
;
20 import org
.springframework
.stereotype
.Component
;
22 import eu
.etaxonomy
.cdm
.io
.berlinModel
.BerlinModelTransformer
;
23 import eu
.etaxonomy
.cdm
.io
.common
.ICdmIO
;
24 import eu
.etaxonomy
.cdm
.io
.common
.IImportConfigurator
;
25 import eu
.etaxonomy
.cdm
.io
.common
.MapWrapper
;
26 import eu
.etaxonomy
.cdm
.io
.common
.Source
;
27 import eu
.etaxonomy
.cdm
.model
.common
.Annotation
;
28 import eu
.etaxonomy
.cdm
.model
.media
.ImageFile
;
29 import eu
.etaxonomy
.cdm
.model
.media
.Media
;
30 import eu
.etaxonomy
.cdm
.model
.name
.SpecimenTypeDesignationStatus
;
31 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameBase
;
32 import eu
.etaxonomy
.cdm
.model
.occurrence
.Specimen
;
33 import eu
.etaxonomy
.cdm
.model
.reference
.ReferenceBase
;
34 import eu
.etaxonomy
.cdm
.strategy
.exceptions
.UnknownCdmTypeException
;
42 public class BerlinModelTypesImport
extends BerlinModelImportBase
/*implements IIO<BerlinModelImportConfigurator>*/ {
43 private static final Logger logger
= Logger
.getLogger(BerlinModelTypesImport
.class);
45 private static int modCount
= 10000;
47 public BerlinModelTypesImport(){
52 * @see eu.etaxonomy.cdm.io.common.CdmIoBase#doCheck(eu.etaxonomy.cdm.io.common.IImportConfigurator)
55 protected boolean doCheck(BerlinModelImportState state
){
56 boolean result
= true;
57 logger
.warn("Checking for Types not yet implemented");
58 //result &= checkArticlesWithoutJournal(bmiConfig);
59 //result &= checkPartOfJournal(bmiConfig);
65 * @see eu.etaxonomy.cdm.io.common.CdmIoBase#doInvoke(eu.etaxonomy.cdm.io.common.IImportConfigurator, eu.etaxonomy.cdm.api.application.CdmApplicationController, java.util.Map)
68 protected boolean doInvoke(BerlinModelImportState state
){
70 MapWrapper
<TaxonNameBase
> taxonNameMap
= (MapWrapper
<TaxonNameBase
>)state
.getStore(ICdmIO
.TAXONNAME_STORE
);
71 MapWrapper
<ReferenceBase
> referenceMap
= (MapWrapper
<ReferenceBase
>)state
.getStore(ICdmIO
.REFERENCE_STORE
);
73 boolean result
= true;
74 Set
<TaxonNameBase
> taxonNameStore
= new HashSet
<TaxonNameBase
>();
75 BerlinModelImportConfigurator config
= state
.getConfig();
76 Source source
= config
.getSource();
78 Map
<Integer
, Specimen
> typeMap
= new HashMap
<Integer
, Specimen
>();
80 logger
.info("start makeTypes ...");
83 //get data from database
85 " SELECT TypeDesignation.*, TypeStatus.Status " +
86 " FROM TypeDesignation LEFT OUTER JOIN " +
87 " TypeStatus ON TypeDesignation.TypeStatusFk = TypeStatus.TypeStatusId " +
89 ResultSet rs
= source
.getResultSet(strQuery
) ;
95 if ((i
++ % modCount
) == 0 && i
!= 1 ){ logger
.info("Types handled: " + (i
-1));}
97 int typeDesignationId
= rs
.getInt("typeDesignationId");
98 int nameId
= rs
.getInt("nameFk");
99 int typeStatusFk
= rs
.getInt("typeStatusFk");
100 int refFk
= rs
.getInt("refFk");
101 String refDetail
= rs
.getString("refDetail");
102 String status
= rs
.getString("Status");
103 String typePhrase
= rs
.getString("typePhrase");
106 boolean isNotDesignated
= false;
115 TaxonNameBase
<?
,?
> taxonNameBase
= taxonNameMap
.get(nameId
);
117 if (taxonNameBase
!= null){
119 SpecimenTypeDesignationStatus typeDesignationStatus
= BerlinModelTransformer
.typeStatusId2TypeStatus(typeStatusFk
);
120 ReferenceBase citation
= referenceMap
.get(refFk
);
122 Specimen specimen
= Specimen
.NewInstance();
123 specimen
.setTitleCache(typePhrase
);
124 boolean addToAllNames
= true;
125 String originalNameString
= null;
126 taxonNameBase
.addSpecimenTypeDesignation(specimen
, typeDesignationStatus
, citation
, refDetail
, originalNameString
, isNotDesignated
, addToAllNames
);
128 typeMap
.put(typeDesignationId
, specimen
);
129 taxonNameStore
.add(taxonNameBase
);
132 //Update, Created, Notes, origId
133 //doIdCreatedUpdatedNotes(bmiConfig, media, rs, nameFactId);
135 }catch (UnknownCdmTypeException e
) {
136 logger
.warn("TypeStatus '" + status
+ "' not yet implemented");
141 logger
.warn("TaxonName for TypeDesignation " + typeDesignationId
+ " does not exist in store");
147 result
&= makeFigures(typeMap
, source
);
150 logger
.info("Names to save: " + taxonNameStore
.size());
151 getNameService().saveTaxonNameAll(taxonNameStore
);
153 logger
.info("end makeTypes ..." + getSuccessString(result
));
155 } catch (SQLException e
) {
156 logger
.error("SQLException:" + e
);
162 private static boolean makeFigures(Map
<Integer
, Specimen
> typeMap
, Source source
){
163 boolean success
= true;
165 //get data from database
168 " FROM TypeFigure " +
170 ResultSet rs
= source
.getResultSet(strQuery
) ;
176 if ((i
++ % modCount
) == 0){ logger
.info("TypesFigures handled: " + (i
-1));}
178 Integer typeFigureId
= rs
.getInt("typeFigureId");
179 Integer typeDesignationFk
= rs
.getInt("typeDesignationFk");
180 Integer collectionFk
= rs
.getInt("collectionFk");
181 String filename
= rs
.getString("filename");
182 String figurePhrase
= rs
.getString("figurePhrase");
184 String mimeType
= null; //"image/jpg";
185 String suffix
= null; //"jpg";
186 Media media
= ImageFile
.NewMediaInstance(null, null, filename
, mimeType
, suffix
, null, null, null);
187 if (figurePhrase
!= null) {
188 media
.addAnnotation(Annotation
.NewDefaultLanguageInstance(figurePhrase
));
190 Specimen typeSpecimen
= typeMap
.get(typeDesignationFk
);
191 if (typeSpecimen
!= null) {
192 typeSpecimen
.addMedia(media
);
205 } catch (SQLException e
) {
206 logger
.error("SQLException:" + e
);
214 * @see eu.etaxonomy.cdm.io.common.CdmIoBase#isIgnore(eu.etaxonomy.cdm.io.common.IImportConfigurator)
216 protected boolean isIgnore(BerlinModelImportState state
){
217 return ! state
.getConfig().isDoTypes();