Revision 1669c273
Added by Andreas Müller over 11 years ago
app-import/src/main/java/eu/etaxonomy/cdm/io/globis/GlobisImageImport.java | ||
---|---|---|
9 | 9 |
|
10 | 10 |
package eu.etaxonomy.cdm.io.globis; |
11 | 11 |
|
12 |
import java.io.IOException; |
|
12 | 13 |
import java.net.MalformedURLException; |
13 | 14 |
import java.net.URI; |
14 | 15 |
import java.sql.ResultSet; |
... | ... | |
18 | 19 |
import java.util.Map; |
19 | 20 |
import java.util.Set; |
20 | 21 |
|
22 |
import org.apache.http.client.ClientProtocolException; |
|
21 | 23 |
import org.apache.log4j.Logger; |
22 | 24 |
import org.springframework.stereotype.Component; |
23 | 25 |
|
26 |
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade; |
|
27 |
import eu.etaxonomy.cdm.common.UriUtils; |
|
24 | 28 |
import eu.etaxonomy.cdm.io.common.IOValidator; |
25 | 29 |
import eu.etaxonomy.cdm.io.common.ResultSetPartitioner; |
26 | 30 |
import eu.etaxonomy.cdm.io.globis.validation.GlobisImageImportValidator; |
27 | 31 |
import eu.etaxonomy.cdm.model.common.CdmBase; |
28 | 32 |
import eu.etaxonomy.cdm.model.common.Language; |
33 |
import eu.etaxonomy.cdm.model.description.DescriptionElementBase; |
|
34 |
import eu.etaxonomy.cdm.model.description.SpecimenDescription; |
|
35 |
import eu.etaxonomy.cdm.model.description.TextData; |
|
29 | 36 |
import eu.etaxonomy.cdm.model.media.Media; |
37 |
import eu.etaxonomy.cdm.model.occurrence.Specimen; |
|
30 | 38 |
import eu.etaxonomy.cdm.model.reference.Reference; |
31 | 39 |
import eu.etaxonomy.cdm.model.taxon.Taxon; |
32 | 40 |
|
... | ... | |
76 | 84 |
protected String getRecordQuery(GlobisImportConfigurator config) { |
77 | 85 |
String strRecordQuery = |
78 | 86 |
" SELECT i.*, NULL as Created_When, NULL as Created_Who," + |
79 |
" NULL as Updated_who, NULL as Updated_When, NULL as Notes " + |
|
87 |
" NULL as Updated_who, NULL as Updated_When, NULL as Notes, st.SpecCurrspecID " +
|
|
80 | 88 |
" FROM " + getTableName() + " i " + |
89 |
" LEFT JOIN specTax st ON i.spectaxID = st.SpecTaxID " + |
|
81 | 90 |
" WHERE ( i.BildId IN (" + ID_LIST_TOKEN + ") )"; |
82 | 91 |
return strRecordQuery; |
83 | 92 |
} |
... | ... | |
93 | 102 |
|
94 | 103 |
Set<Media> objectsToSave = new HashSet<Media>(); |
95 | 104 |
|
96 |
// Map<String, Taxon> taxonMap = (Map<String, Taxon>) partitioner.getObjectMap(TAXON_NAMESPACE); |
|
105 |
Map<String, Specimen> typeMap = (Map<String, Specimen>) partitioner.getObjectMap(GlobisSpecTaxImport.TYPE_NAMESPACE); |
|
106 |
|
|
107 |
Map<String, Taxon> taxonMap = (Map<String, Taxon>) partitioner.getObjectMap(TAXON_NAMESPACE); |
|
97 | 108 |
// Map<String, DerivedUnit> ecoFactDerivedUnitMap = (Map<String, DerivedUnit>) partitioner.getObjectMap(ECO_FACT_DERIVED_UNIT_NAMESPACE); |
98 | 109 |
|
99 | 110 |
ResultSet rs = partitioner.getResultSet(); |
... | ... | |
111 | 122 |
|
112 | 123 |
Integer spectaxID = nullSafeInt(rs, "spectaxID"); |
113 | 124 |
|
114 |
//ignore: [file lab2], same as Dateiname04 but less data
|
|
125 |
Integer taxonID = nullSafeInt(rs, "SpecCurrspecID");
|
|
115 | 126 |
|
127 |
String copyright = rs.getString("copyright"); |
|
116 | 128 |
|
129 |
//ignore: |
|
130 |
// [file lab2], same as Dateiname04 but less data |
|
131 |
// Dateipfad |
|
132 |
Set<Media> recordMedia = new HashSet<Media>(); |
|
117 | 133 |
|
118 | 134 |
try { |
119 | 135 |
|
120 |
//source ref |
|
121 |
Reference<?> sourceRef = state.getTransactionalSourceReference(); |
|
122 |
|
|
123 |
//make image path |
|
136 |
//make image path |
|
124 | 137 |
String pathShort = rs.getString("Dateipfad_kurz"); |
125 | 138 |
String fileOS = rs.getString("file OS"); |
126 |
pathShort.replace(fileOS, ""); |
|
127 |
//TODO move to config |
|
128 |
String newPath = "http://globis-images.insects-online.de/images/"; |
|
129 |
String path = pathShort.replace("image:Webversionen", newPath); |
|
139 |
pathShort= pathShort.replace(fileOS, ""); |
|
140 |
String newPath = state.getConfig().getImageBaseUrl(); |
|
141 |
String path = pathShort.replace("image:Webversionen/", newPath); |
|
130 | 142 |
|
143 |
Media singleMedia = makeMedia(state, rs, "file OS", "Legende 1", path, objectsToSave ); |
|
144 |
recordMedia.add(singleMedia); |
|
145 |
singleMedia = makeMedia(state, rs, "Dateinamen02", "Legende 2", path, objectsToSave ); |
|
146 |
recordMedia.add(singleMedia); |
|
147 |
singleMedia = makeMedia(state, rs, "Dateinamen03", "Legende 3", path, objectsToSave ); |
|
148 |
recordMedia.add(singleMedia); |
|
149 |
singleMedia = makeMedia(state, rs, "Dateinamen04", "Legende 4", path, objectsToSave ); |
|
150 |
recordMedia.add(singleMedia); |
|
131 | 151 |
|
152 |
if (spectaxID != null){ |
|
153 |
String collectionCode = transformCopyright2CollectionCode(copyright); |
|
154 |
String id = GlobisSpecTaxImport.getTypeId(spectaxID, collectionCode); |
|
155 |
Specimen typeSpecimen = typeMap.get(id); |
|
156 |
if (typeSpecimen != null){ |
|
157 |
DerivedUnitFacade facade = DerivedUnitFacade.NewInstance(typeSpecimen); |
|
158 |
for (Media media: recordMedia){ |
|
159 |
facade.addDerivedUnitMedia(media); |
|
160 |
} |
|
161 |
}else{ |
|
162 |
//TODO |
|
163 |
} |
|
164 |
}else{ |
|
165 |
//TODO |
|
166 |
} |
|
132 | 167 |
|
133 |
Media media1 = makeMedia(state, rs, "file OS", "Legende 1", path ); |
|
134 |
Media media2 = makeMedia(state, rs, "Dateiname02", "Legende 2", path ); |
|
135 |
Media media3 = makeMedia(state, rs, "Dateiname03", "Legende 3", path ); |
|
136 |
Media media4 = makeMedia(state, rs, "Dateiname04", "Legende 4", path ); |
|
137 |
|
|
138 | 168 |
|
139 |
//TODO |
|
140 |
this.doIdCreatedUpdatedNotes(state, media1, rs, bildID, IMAGE_NAMESPACE); |
|
141 | 169 |
|
142 |
save(objectsToSave, media1); |
|
143 | 170 |
|
144 |
|
|
145 |
|
|
146 | 171 |
} catch (Exception e) { |
147 | 172 |
logger.warn("Exception in Einzelbilder: bildID " + bildID + ". " + e.getMessage()); |
148 |
// e.printStackTrace();
|
|
173 |
e.printStackTrace(); |
|
149 | 174 |
} |
150 | 175 |
|
151 | 176 |
} |
152 | 177 |
|
153 |
// logger.warn("Specimen: " + countSpecimen + ", Descriptions: " + countDescriptions ); |
|
154 |
|
|
155 |
logger.warn(pluralString + " to save: " + objectsToSave.size()); |
|
178 |
logger.info(pluralString + " to save: " + objectsToSave.size()); |
|
156 | 179 |
getMediaService().save(objectsToSave); |
157 | 180 |
|
158 | 181 |
return success; |
... | ... | |
162 | 185 |
} |
163 | 186 |
} |
164 | 187 |
|
165 |
private void save(Set<Media> objectsToSave, Media media) { |
|
166 |
if (media != null){ |
|
167 |
objectsToSave.add(media); |
|
168 |
} |
|
169 |
} |
|
170 |
|
|
171 |
|
|
172 |
|
|
173 |
|
|
174 |
private Media makeMedia(GlobisImportState state, ResultSet rs, String fileNameAttr, String legendAttr, String path) throws SQLException { |
|
188 |
private Media makeMedia(GlobisImportState state, ResultSet rs, String fileNameAttr, String legendAttr, String path, Set<Media> objectsToSave) throws SQLException { |
|
175 | 189 |
Media media = null; |
176 | 190 |
String fileName = rs.getString(fileNameAttr); |
177 | 191 |
String legend = rs.getString(legendAttr); |
192 |
Integer bildID = rs.getInt("BildID"); |
|
178 | 193 |
|
179 | 194 |
URI uri = URI.create(path+fileName); |
180 | 195 |
|
181 | 196 |
// Media media = ImageInfo.NewInstanceWithMetaData(uri, null); |
182 | 197 |
|
183 | 198 |
try { |
184 |
media = this.getImageMedia(uri.toString(), true, false); |
|
199 |
boolean readMediaData = state.getConfig().isDoReadMediaData(); |
|
200 |
if (isBlank(legend) && readMediaData){ |
|
201 |
if (UriUtils.isOk(UriUtils.getResponse(uri, null))){ |
|
202 |
logger.warn("Image exists but legend is null " + uri + ", bildID" + bildID ); |
|
203 |
}else{ |
|
204 |
return null; |
|
205 |
} |
|
206 |
} |
|
207 |
|
|
208 |
media = this.getImageMedia(uri.toString(), readMediaData, false); |
|
185 | 209 |
media.putTitle(Language.ENGLISH(), legend); |
210 |
this.doIdCreatedUpdatedNotes(state, media, rs, bildID, IMAGE_NAMESPACE); |
|
211 |
|
|
212 |
objectsToSave.add(media); |
|
213 |
|
|
214 |
|
|
186 | 215 |
} catch (MalformedURLException e) { |
187 | 216 |
e.printStackTrace(); |
217 |
} catch (ClientProtocolException e) { |
|
218 |
e.printStackTrace(); |
|
219 |
} catch (IOException e) { |
|
220 |
e.printStackTrace(); |
|
188 | 221 |
} |
189 | 222 |
|
190 | 223 |
return media; |
191 | 224 |
} |
225 |
|
|
226 |
private String transformCopyright2CollectionCode(String copyright){ |
|
227 |
|
|
228 |
if (isBlank(copyright)){ |
|
229 |
return ""; |
|
230 |
}else if(copyright.matches("Museum f.?r Naturkunde der Humboldt-Universit.?t, Berlin")){ |
|
231 |
return "MFNB"; |
|
232 |
}else if(copyright.matches("Staatliches Museum f.?r Tierkunde Dresden")){ |
|
233 |
return "SMTD"; |
|
234 |
}else if(copyright.equals("Natural History Museum, London")){ |
|
235 |
return "BMNH"; |
|
236 |
}else if(copyright.matches("Zoologische Staatssammlung M.?nchen")){ |
|
237 |
return "ZSSM"; |
|
238 |
}else if(copyright.matches("Staatliches Museum f.?r Naturkunde Karlsruhe")){ |
|
239 |
return "SMNK"; |
|
240 |
}else if(copyright.matches("Deutsches Entomologisches Institut M.?ncheberg")){ |
|
241 |
return "DEIE"; |
|
242 |
}else if(copyright.equals("Forschungsinstitut und Naturmuseum Senckenberg")){ |
|
243 |
return "SMFM"; |
|
244 |
}else if(copyright.matches("Mus.?um National d.?Histoire Naturelle, Paris")){ |
|
245 |
return "MNHN"; |
|
246 |
}else if(copyright.equals("Naturhistorisches Museum Wien")){ |
|
247 |
return "NHMW"; |
|
248 |
}else if(copyright.equals("Naturhistoriska Riksmuseet Stockholm")){ |
|
249 |
return "NRMS"; |
|
250 |
}else if(copyright.matches("Staatliches Museum f.?r Naturkunde Stuttgart")){ |
|
251 |
return "SMNS"; |
|
252 |
}else if(copyright.equals("United States National Museum of Natural History, Washington")){ |
|
253 |
return "USNM"; |
|
254 |
}else if(copyright.matches("Zentrum f.?r Biodokumentation des Saarlandes")){ |
|
255 |
return "ZFBS"; |
|
256 |
}else if(copyright.equals("Zoological Museum, University of Copenhagen")){ |
|
257 |
return "ZMUC"; |
|
258 |
}else if(copyright.equals("Zoologisches Forschungsinstitut und Museum \"Alexander Koenig\", Bonn")){ |
|
259 |
return "ZFMK"; |
|
260 |
}else if(copyright.equals("Zoologisches Forschungsmuseum \"Alexander Koenig\", Bonn")){ |
|
261 |
return "ZFMK"; |
|
262 |
}else if(copyright.matches("Zoologisches Institut der Martin-Luther-Universit.?t Halle-Wittenberg")){ |
|
263 |
return "ZIUH"; |
|
264 |
}else if(copyright.matches("Zoologisches Institut Universit.?t T.?bingen")){ |
|
265 |
return "ZIUT"; |
|
266 |
}else{ |
|
267 |
logger.warn("Unknown copyright entry: " + copyright); |
|
268 |
return ""; |
|
269 |
} |
|
270 |
|
|
271 |
|
|
272 |
} |
|
192 | 273 |
|
193 | 274 |
|
194 | 275 |
|
... | ... | |
196 | 277 |
* @see eu.etaxonomy.cdm.io.berlinModel.in.IPartitionedIO#getRelatedObjectsForPartition(java.sql.ResultSet) |
197 | 278 |
*/ |
198 | 279 |
public Map<Object, Map<String, ? extends CdmBase>> getRelatedObjectsForPartition(ResultSet rs) { |
280 |
String nameSpace; |
|
281 |
Class cdmClass; |
|
282 |
Set<String> idSet; |
|
199 | 283 |
Map<Object, Map<String, ? extends CdmBase>> result = new HashMap<Object, Map<String, ? extends CdmBase>>(); |
200 |
return result; //not needed |
|
284 |
try{ |
|
285 |
Set<String> currSpecIdSet = new HashSet<String>(); |
|
286 |
Set<String> typeIdSet = new HashSet<String>(); |
|
287 |
|
|
288 |
while (rs.next()){ |
|
289 |
handleForeignKey(rs, currSpecIdSet, "SpecCurrspecID"); |
|
290 |
handleTypeKey(rs, typeIdSet, "spectaxID", "copyright"); |
|
291 |
} |
|
292 |
|
|
293 |
//taxon map |
|
294 |
nameSpace = TAXON_NAMESPACE; |
|
295 |
cdmClass = Taxon.class; |
|
296 |
idSet = currSpecIdSet; |
|
297 |
Map<String, Taxon> taxonMap = (Map<String, Taxon>)getCommonService().getSourcedObjectsByIdInSource(cdmClass, idSet, nameSpace); |
|
298 |
result.put(nameSpace, taxonMap); |
|
299 |
|
|
300 |
//type map |
|
301 |
nameSpace = GlobisSpecTaxImport.TYPE_NAMESPACE; |
|
302 |
cdmClass = Specimen.class; |
|
303 |
idSet = typeIdSet; |
|
304 |
Map<String, Specimen> typeMap = (Map<String, Specimen>)getCommonService().getSourcedObjectsByIdInSource(cdmClass, idSet, nameSpace); |
|
305 |
result.put(nameSpace, typeMap); |
|
306 |
|
|
307 |
|
|
308 |
} catch (SQLException e) { |
|
309 |
throw new RuntimeException(e); |
|
310 |
} |
|
311 |
return result; |
|
312 |
} |
|
313 |
|
|
314 |
private void handleTypeKey(ResultSet rs, Set<String> idSet, String specTaxIdAttr, String copyrightAttr) |
|
315 |
throws SQLException { |
|
316 |
Integer specTaxId = nullSafeInt(rs, specTaxIdAttr); |
|
317 |
if (specTaxId != null){ |
|
318 |
String copyright = rs.getString(copyrightAttr); |
|
319 |
if (isNotBlank(copyright)){ |
|
320 |
String id = GlobisSpecTaxImport.getTypeId(specTaxId, transformCopyright2CollectionCode(copyright)); |
|
321 |
idSet.add(id); |
|
322 |
} |
|
323 |
} |
|
201 | 324 |
} |
202 | 325 |
|
203 | 326 |
/* (non-Javadoc) |
app-import/src/main/java/eu/etaxonomy/cdm/io/globis/GlobisImportBase.java | ||
---|---|---|
215 | 215 |
throws SQLException{ |
216 | 216 |
boolean success = true; |
217 | 217 |
//id |
218 |
success &= ImportHelper.setOriginalSource(identifiableEntity, state.getConfig().getSourceReference(), id, namespace);
|
|
218 |
success &= ImportHelper.setOriginalSource(identifiableEntity, state.getTransactionalSourceReference(), id, namespace);
|
|
219 | 219 |
//createdUpdateNotes |
220 | 220 |
success &= doCreatedUpdatedNotes(state, identifiableEntity, rs, namespace); |
221 | 221 |
return success; |
app-import/src/main/java/eu/etaxonomy/cdm/io/globis/GlobisImportConfigurator.java | ||
---|---|---|
46 | 46 |
private boolean doImages = true; |
47 | 47 |
private boolean doCurrentTaxa = true; |
48 | 48 |
private boolean doSpecTaxa = true; |
49 |
private boolean doCommonNames = true; |
|
50 |
|
|
51 |
private boolean doReadMediaData = true; |
|
52 |
|
|
49 | 53 |
private DO_REFERENCES doReferences = DO_REFERENCES.ALL; |
50 | 54 |
|
55 |
private String imageBaseUrl = "http://globis-images.insects-online.de/images/"; |
|
51 | 56 |
|
52 | 57 |
private static IInputTransformer defaultTransformer = new GlobisTransformer(); |
53 | 58 |
|
... | ... | |
183 | 188 |
} |
184 | 189 |
|
185 | 190 |
|
191 |
public void setDoCommonNames(boolean doCommonNames) { |
|
192 |
this.doCommonNames = doCommonNames; |
|
193 |
} |
|
194 |
|
|
195 |
|
|
196 |
public boolean isDoCommonNames() { |
|
197 |
return doCommonNames; |
|
198 |
} |
|
199 |
|
|
200 |
|
|
201 |
public void setImageBaseUrl(String imageBaseUrl) { |
|
202 |
this.imageBaseUrl = imageBaseUrl; |
|
203 |
} |
|
204 |
|
|
205 |
|
|
206 |
public String getImageBaseUrl() { |
|
207 |
return imageBaseUrl; |
|
208 |
} |
|
209 |
|
|
210 |
|
|
211 |
public void setDoReadMediaData(boolean doReadMediaData) { |
|
212 |
this.doReadMediaData = doReadMediaData; |
|
213 |
} |
|
214 |
|
|
215 |
|
|
216 |
public boolean isDoReadMediaData() { |
|
217 |
return doReadMediaData; |
|
218 |
} |
|
219 |
|
|
220 |
|
|
186 | 221 |
|
187 | 222 |
|
188 | 223 |
} |
app-import/src/main/java/eu/etaxonomy/cdm/io/globis/GlobisSpecTaxImport.java | ||
---|---|---|
33 | 33 |
import eu.etaxonomy.cdm.io.globis.validation.GlobisSpecTaxaImportValidator; |
34 | 34 |
import eu.etaxonomy.cdm.model.common.CdmBase; |
35 | 35 |
import eu.etaxonomy.cdm.model.common.Extension; |
36 |
import eu.etaxonomy.cdm.model.common.IdentifiableSource; |
|
36 | 37 |
import eu.etaxonomy.cdm.model.common.Marker; |
37 | 38 |
import eu.etaxonomy.cdm.model.common.MarkerType; |
38 | 39 |
import eu.etaxonomy.cdm.model.location.WaterbodyOrCountry; |
... | ... | |
41 | 42 |
import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignation; |
42 | 43 |
import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignationStatus; |
43 | 44 |
import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignationTest; |
45 |
import eu.etaxonomy.cdm.model.name.TaxonNameBase; |
|
44 | 46 |
import eu.etaxonomy.cdm.model.name.ZoologicalName; |
45 | 47 |
import eu.etaxonomy.cdm.model.occurrence.Collection; |
46 | 48 |
import eu.etaxonomy.cdm.model.occurrence.DerivationEvent; |
... | ... | |
71 | 73 |
private static final String pluralString = "taxa"; |
72 | 74 |
private static final String dbTableName = "specTax"; |
73 | 75 |
private static final Class cdmTargetClass = Reference.class; |
76 |
public static final String SPEC_TAX_NAMESPACE = dbTableName; |
|
77 |
public static final String TYPE_NAMESPACE = dbTableName + ".SpecTypeDepository"; |
|
74 | 78 |
|
75 | 79 |
public GlobisSpecTaxImport(){ |
76 | 80 |
super(pluralString, dbTableName, cdmTargetClass); |
... | ... | |
116 | 120 |
boolean success = true; |
117 | 121 |
|
118 | 122 |
Set<TaxonBase> objectsToSave = new HashSet<TaxonBase>(); |
123 |
Set<TaxonNameBase> namesToSave = new HashSet<TaxonNameBase>(); |
|
119 | 124 |
|
120 | 125 |
Map<String, Taxon> taxonMap = (Map<String, Taxon>) partitioner.getObjectMap(TAXON_NAMESPACE); |
121 | 126 |
Map<String, Reference> referenceMap = (Map<String, Reference>) partitioner.getObjectMap(REFERENCE_NAMESPACE); |
... | ... | |
143 | 148 |
Taxon acceptedTaxon = taxonMap.get(String.valueOf(acceptedTaxonId)); |
144 | 149 |
TaxonBase<?> thisTaxon = null; |
145 | 150 |
|
151 |
ZoologicalName name = null; |
|
146 | 152 |
if (isBlank(specSystaxRank) ){ |
147 |
//TODO
|
|
153 |
name = makeName(state, rs);
|
|
148 | 154 |
}else if (specSystaxRank.equals("synonym")){ |
149 | 155 |
Synonym synonym = getSynonym(state, rs); |
150 | 156 |
if (acceptedTaxon == null){ |
... | ... | |
162 | 168 |
thisTaxon = acceptedTaxon; |
163 | 169 |
}else{ |
164 | 170 |
logger.warn(String.format("Unhandled specSystaxRank %s in specTaxId %d", specSystaxRank, specTaxId)); |
171 |
name = makeName(state, rs); |
|
165 | 172 |
} |
166 | 173 |
|
167 | 174 |
if (thisTaxon != null){ |
168 |
ZoologicalName name = CdmBase.deproxy(thisTaxon.getName(), ZoologicalName.class); |
|
169 |
|
|
170 |
handleNomRef(state, referenceMap, rs, name); |
|
171 |
|
|
172 |
handleTypeInformation(state,rs, name, specTaxId); |
|
173 |
|
|
175 |
name = CdmBase.deproxy(thisTaxon.getName(), ZoologicalName.class); |
|
176 |
} |
|
177 |
if (name == null){ |
|
178 |
name = makeName(state, rs); |
|
179 |
} |
|
174 | 180 |
|
181 |
handleNomRef(state, referenceMap, rs, name); |
|
182 |
|
|
183 |
handleTypeInformation(state,rs, name, specTaxId); |
|
184 |
|
|
185 |
|
|
175 | 186 |
// this.doIdCreatedUpdatedNotes(state, ref, rs, refId, REFERENCE_NAMESPACE); |
176 |
|
|
187 |
|
|
188 |
if (acceptedTaxon != null){ |
|
177 | 189 |
objectsToSave.add(acceptedTaxon); |
178 | 190 |
} |
191 |
namesToSave.add(name); |
|
179 | 192 |
|
180 | 193 |
|
181 | 194 |
} catch (Exception e) { |
... | ... | |
185 | 198 |
|
186 | 199 |
} |
187 | 200 |
|
188 |
// logger.warn("Specimen: " + countSpecimen + ", Descriptions: " + countDescriptions ); |
|
189 |
|
|
190 | 201 |
logger.warn(pluralString + " to save: " + objectsToSave.size()); |
191 | 202 |
getTaxonService().save(objectsToSave); |
203 |
getNameService().save(namesToSave); |
|
192 | 204 |
|
193 | 205 |
return success; |
194 | 206 |
} catch (Exception e) { |
... | ... | |
223 | 235 |
if (specTypeDepositories.length == 0){ |
224 | 236 |
Specimen specimen = makeSingleTypeSpecimen(fieldObservation); |
225 | 237 |
makeTypeDesignation(name, rs, specimen); |
238 |
makeTypeIdInSource(state, specimen, "null", specTaxId); |
|
226 | 239 |
} |
227 | 240 |
for (String specTypeDepositoryStr : specTypeDepositories){ |
228 | 241 |
specTypeDepositoryStr = specTypeDepositoryStr.trim(); |
... | ... | |
233 | 246 |
if (specTypeDepositoryStr.equals("??")){ |
234 | 247 |
//unknown |
235 | 248 |
specimen.setTitleCache("??", true); |
249 |
makeTypeIdInSource(state, specimen, "??", specTaxId); |
|
250 |
|
|
236 | 251 |
}else{ |
237 |
specTypeDepositoryStr = makeAdditionalSpecimenInformation(
|
|
252 |
specTypeDepositoryStr = makeAdditionalSpecimenInformation( |
|
238 | 253 |
specTypeDepositoryStr, specimen, specTaxId); |
239 | 254 |
|
240 |
makeCollection(specTypeDepositoryStr, specimen, specTaxId); |
|
255 |
Collection collection = makeCollection(specTypeDepositoryStr, specimen, specTaxId); |
|
256 |
String collectionCode = collection.getCode(); |
|
257 |
if (isBlank(collectionCode)){ |
|
258 |
collectionCode = collection.getName(); |
|
259 |
} |
|
260 |
if (isBlank(collectionCode)){ |
|
261 |
logger.warn("Collection has empty representation: " + specTypeDepositoryStr + ", specTaxId" + specTaxId); |
|
262 |
} |
|
263 |
makeTypeIdInSource(state, specimen, collectionCode , specTaxId); |
|
241 | 264 |
} |
242 | 265 |
|
243 | 266 |
//type Designation |
... | ... | |
248 | 271 |
} |
249 | 272 |
|
250 | 273 |
|
274 |
private void makeTypeIdInSource(GlobisImportState state, Specimen specimen, String collectionCode, Integer specTaxId) { |
|
275 |
String namespace = TYPE_NAMESPACE; |
|
276 |
String id = getTypeId(specTaxId, collectionCode); |
|
277 |
IdentifiableSource source = IdentifiableSource.NewInstance(id, namespace, state.getTransactionalSourceReference(), null); |
|
278 |
specimen.addSource(source); |
|
279 |
} |
|
280 |
|
|
281 |
|
|
282 |
|
|
283 |
|
|
284 |
public static String getTypeId(Integer specTaxId, String collectionCode) { |
|
285 |
String result = String.valueOf(specTaxId) + "@" + collectionCode; |
|
286 |
return result; |
|
287 |
} |
|
288 |
|
|
289 |
|
|
251 | 290 |
|
252 | 291 |
|
253 | 292 |
private boolean hasTypeInformation(ResultSet rs) throws SQLException { |
... | ... | |
267 | 306 |
* @param specimen |
268 | 307 |
* @param specTaxId |
269 | 308 |
*/ |
270 |
protected void makeCollection(String specTypeDepositoryStr, Specimen specimen, Integer specTaxId) {
|
|
309 |
protected Collection makeCollection(String specTypeDepositoryStr, Specimen specimen, Integer specTaxId) {
|
|
271 | 310 |
//TODO deduplicate |
272 | 311 |
Map<String, Collection> collectionMap = new HashMap<String, Collection>(); |
273 | 312 |
|
274 |
|
|
275 | 313 |
//Collection |
276 | 314 |
specTypeDepositoryStr = specTypeDepositoryStr.replace("Washington, D.C.", "Washington@ D.C."); |
277 | 315 |
|
316 |
Collection collection; |
|
278 | 317 |
if (specTypeDepositoryStr.equals("BMNH, London and/or MNHN, Paris")){ |
279 | 318 |
//TODO deduplicate |
280 |
Collection collection = Collection.NewInstance();
|
|
319 |
collection = Collection.NewInstance(); |
|
281 | 320 |
collection.setName(specTypeDepositoryStr); |
282 | 321 |
specimen.setCollection(collection); |
283 | 322 |
}else if (specTypeDepositoryStr.equals("coll. L. V. Kaabak, A .V. Sotshivko & V. V. Titov, Moscow")){ |
284 |
Collection collection = Collection.NewInstance();
|
|
323 |
collection = Collection.NewInstance(); |
|
285 | 324 |
collection.setName("coll. L. V. Kaabak, A .V. Sotshivko & V. V. Titov"); |
286 | 325 |
collection.setTownOrLocation("Moscow"); |
287 | 326 |
specimen.setCollection(collection); |
288 | 327 |
}else if (specTypeDepositoryStr.matches("coll. R. E. Parrott?, Port Hope, Ontario")){ |
289 | 328 |
//TODO deduplicate |
290 |
Collection collection = Collection.NewInstance();
|
|
329 |
collection = Collection.NewInstance(); |
|
291 | 330 |
collection.setName("coll. R. E. Parrott"); |
292 | 331 |
collection.setTownOrLocation("Port Hope, Ontario"); |
293 | 332 |
specimen.setCollection(collection); |
... | ... | |
296 | 335 |
String[] split = specTypeDepositoryStr.split(","); |
297 | 336 |
if (split.length != 2){ |
298 | 337 |
if (split.length == 1 && split[0].startsWith("coll.")){ |
299 |
Collection collection = Collection.NewInstance();
|
|
338 |
collection = Collection.NewInstance(); |
|
300 | 339 |
collection.setName(split[0]); |
301 | 340 |
specimen.setCollection(collection); |
302 | 341 |
}else{ |
303 | 342 |
logger.warn("Split size is not 2: " + specTypeDepositoryStr + " (specTaxID:" + specTaxId + ")"); |
343 |
collection = Collection.NewInstance(); |
|
344 |
collection.setCode("??"); |
|
304 | 345 |
} |
305 | 346 |
|
306 | 347 |
}else{ |
307 | 348 |
String collectionStr = split[0]; |
308 | 349 |
String location = split[1].replace("Washington@ D.C.", "Washington, D.C."); |
309 | 350 |
|
310 |
Collection collection = collectionMap.get(collectionStr);
|
|
351 |
collection = collectionMap.get(collectionStr); |
|
311 | 352 |
if (collection == null){ |
312 | 353 |
collection = Collection.NewInstance(); |
313 | 354 |
collection.setCode(collectionStr); |
... | ... | |
318 | 359 |
} |
319 | 360 |
|
320 | 361 |
specimen.setCollection(collection); |
321 |
|
|
322 | 362 |
} |
323 | 363 |
} |
364 |
return collection; |
|
324 | 365 |
} |
325 | 366 |
|
326 | 367 |
|
... | ... | |
500 | 541 |
|
501 | 542 |
|
502 | 543 |
private Synonym getSynonym(GlobisImportState state, ResultSet rs) throws SQLException { |
544 |
ZoologicalName name = makeName(state, rs); |
|
545 |
|
|
546 |
Synonym synonym = Synonym.NewInstance(name, state.getTransactionalSourceReference()); |
|
547 |
|
|
548 |
return synonym; |
|
549 |
} |
|
550 |
|
|
551 |
|
|
552 |
|
|
553 |
|
|
554 |
/** |
|
555 |
* @param state |
|
556 |
* @param rs |
|
557 |
* @return |
|
558 |
* @throws SQLException |
|
559 |
*/ |
|
560 |
protected ZoologicalName makeName(GlobisImportState state, ResultSet rs) |
|
561 |
throws SQLException { |
|
503 | 562 |
//rank |
504 | 563 |
String rankStr = rs.getString("SpecRank"); |
505 | 564 |
Rank rank = null; |
... | ... | |
521 | 580 |
String yearStr = rs.getString("SpecYear"); |
522 | 581 |
String authorAndYearStr = CdmUtils.concat(", ", authorStr, yearStr); |
523 | 582 |
handleAuthorAndYear(authorAndYearStr, name); |
524 |
|
|
525 |
Synonym synonym = Synonym.NewInstance(name, state.getTransactionalSourceReference()); |
|
526 |
|
|
527 |
return synonym; |
|
583 |
return name; |
|
528 | 584 |
} |
529 | 585 |
|
530 | 586 |
|
Also available in: Unified diff
latest updates to the Globis import