4 package eu
.etaxonomy
.cdm
.io
.berlinModel
;
6 import java
.sql
.ResultSet
;
7 import java
.sql
.SQLException
;
8 import java
.util
.HashMap
;
9 import java
.util
.HashSet
;
13 import org
.apache
.log4j
.Logger
;
15 import eu
.etaxonomy
.cdm
.api
.application
.CdmApplicationController
;
16 import eu
.etaxonomy
.cdm
.api
.service
.INameService
;
17 import eu
.etaxonomy
.cdm
.io
.common
.IIO
;
18 import eu
.etaxonomy
.cdm
.io
.common
.MapWrapper
;
19 import eu
.etaxonomy
.cdm
.io
.common
.Source
;
20 import eu
.etaxonomy
.cdm
.model
.common
.Annotation
;
21 import eu
.etaxonomy
.cdm
.model
.media
.ImageFile
;
22 import eu
.etaxonomy
.cdm
.model
.media
.Media
;
23 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameBase
;
24 import eu
.etaxonomy
.cdm
.model
.name
.TypeDesignationStatus
;
25 import eu
.etaxonomy
.cdm
.model
.occurrence
.Specimen
;
26 import eu
.etaxonomy
.cdm
.model
.reference
.ReferenceBase
;
27 import eu
.etaxonomy
.cdm
.strategy
.exceptions
.UnknownCdmTypeException
;
35 public class BerlinModelTypesIO
extends BerlinModelIOBase
implements IIO
<BerlinModelImportConfigurator
> {
36 private static final Logger logger
= Logger
.getLogger(BerlinModelTypesIO
.class);
38 private static int modCount
= 10000;
40 public boolean check(BerlinModelImportConfigurator bmiConfig
){
41 boolean result
= true;
42 logger
.warn("Checking for Types not yet implemented");
43 //result &= checkArticlesWithoutJournal(bmiConfig);
44 //result &= checkPartOfJournal(bmiConfig);
49 public static boolean invoke(BerlinModelImportConfigurator bmiConfig
, CdmApplicationController cdmApp
,
50 MapWrapper
<TaxonNameBase
> taxonNameMap
, MapWrapper
<ReferenceBase
> referenceMap
){
52 boolean result
= true;
53 Set
<TaxonNameBase
> taxonNameStore
= new HashSet
<TaxonNameBase
>();
54 Source source
= bmiConfig
.getSource();
55 INameService nameService
= cdmApp
.getNameService();
57 Map
<Integer
, Specimen
> typeMap
= new HashMap
<Integer
, Specimen
>();
61 logger
.info("start makeTypes ...");
63 boolean delete
= bmiConfig
.isDeleteAll();
66 //get data from database
68 " SELECT TypeDesignation.*, TypeStatus.Status " +
69 " FROM TypeDesignation INNER JOIN" +
70 " TypeStatus ON TypeDesignation.TypeStatusFk = TypeStatus.TypeStatusId " +
72 ResultSet rs
= source
.getResultSet(strQuery
) ;
78 if ((i
++ % modCount
) == 0){ logger
.info("Types handled: " + (i
-1));}
80 int typeDesignationId
= rs
.getInt("typeDesignationId");
81 int nameId
= rs
.getInt("nameFk");
82 int typeStatusFk
= rs
.getInt("typeStatusFk");
83 int refFk
= rs
.getInt("refFk");
84 String refDetail
= rs
.getString("refDetail");
85 String status
= rs
.getString("Status");
86 String typePhrase
= rs
.getString("typePhrase");
94 TaxonNameBase taxonNameBase
= taxonNameMap
.get(nameId
);
96 if (taxonNameBase
!= null){
98 TypeDesignationStatus typeDesignationStatus
= BerlinModelTransformer
.typeStatusId2TypeStatus(typeStatusFk
);
99 ReferenceBase citation
= referenceMap
.get(refFk
);
101 Specimen specimen
= Specimen
.NewInstance();
102 specimen
.setTitleCache(typePhrase
);
103 boolean addToAllNames
= true;
104 String originalNameString
= null;
105 taxonNameBase
.addSpecimenTypeDesignation(specimen
, typeDesignationStatus
, citation
, refDetail
, originalNameString
, addToAllNames
);
106 typeMap
.put(typeDesignationId
, specimen
);
107 taxonNameStore
.add(taxonNameBase
);
110 //Update, Created, Notes, origId
111 //doIdCreatedUpdatedNotes(bmiConfig, media, rs, nameFactId);
113 }catch (UnknownCdmTypeException e
) {
114 logger
.warn("TypeStatus '" + status
+ "' not yet implemented");
118 logger
.warn("TaxonName for TypeDesignation " + typeDesignationId
+ " does not exist in store");
123 result
&= makeFigures(typeMap
, source
);
126 logger
.info("Names to save: " + taxonNameStore
.size());
127 nameService
.saveTaxonNameAll(taxonNameStore
);
129 logger
.info("end makeTypes ...");
131 } catch (SQLException e
) {
132 logger
.error("SQLException:" + e
);
138 private static boolean makeFigures(Map
<Integer
, Specimen
> typeMap
, Source source
){
140 //get data from database
143 " FROM TypeFigure " +
145 ResultSet rs
= source
.getResultSet(strQuery
) ;
151 if ((i
++ % modCount
) == 0){ logger
.info("TypesFigures handled: " + (i
-1));}
153 Integer typeFigureId
= rs
.getInt("typeFigureId");
154 Integer typeDesignationFk
= rs
.getInt("typeDesignationFk");
155 Integer collectionFk
= rs
.getInt("collectionFk");
156 String filename
= rs
.getString("filename");
157 String figurePhrase
= rs
.getString("figurePhrase");
159 String mimeType
= null; //"image/jpg";
160 String suffix
= null; //"jpg";
161 Media media
= ImageFile
.NewMediaInstance(null, null, filename
, mimeType
, suffix
, null, null, null);
162 if (figurePhrase
!= null) {
163 media
.addAnnotation(Annotation
.NewDefaultLanguageInstance(figurePhrase
));
165 Specimen typeSpecimen
= typeMap
.get(typeDesignationFk
);
166 if (typeSpecimen
!= null) {
167 typeSpecimen
.addMedia(media
);
180 } catch (SQLException e
) {
181 logger
.error("SQLException:" + e
);