Revision f2be28b3
Added by Andreas Müller over 11 years ago
app-import/src/main/java/eu/etaxonomy/cdm/io/globis/GlobisImageImport.java | ||
---|---|---|
18 | 18 |
import java.util.HashSet; |
19 | 19 |
import java.util.Map; |
20 | 20 |
import java.util.Set; |
21 |
import java.util.UUID; |
|
22 |
import java.util.regex.Matcher; |
|
23 |
import java.util.regex.Pattern; |
|
21 | 24 |
|
22 | 25 |
import org.apache.http.client.ClientProtocolException; |
23 | 26 |
import org.apache.log4j.Logger; |
... | ... | |
28 | 31 |
import eu.etaxonomy.cdm.io.common.IOValidator; |
29 | 32 |
import eu.etaxonomy.cdm.io.common.ResultSetPartitioner; |
30 | 33 |
import eu.etaxonomy.cdm.io.globis.validation.GlobisImageImportValidator; |
34 |
import eu.etaxonomy.cdm.model.common.Annotation; |
|
31 | 35 |
import eu.etaxonomy.cdm.model.common.CdmBase; |
32 | 36 |
import eu.etaxonomy.cdm.model.common.Language; |
37 |
import eu.etaxonomy.cdm.model.common.Marker; |
|
38 |
import eu.etaxonomy.cdm.model.common.MarkerType; |
|
33 | 39 |
import eu.etaxonomy.cdm.model.description.DescriptionElementBase; |
34 |
import eu.etaxonomy.cdm.model.description.SpecimenDescription; |
|
40 |
import eu.etaxonomy.cdm.model.description.Feature; |
|
41 |
import eu.etaxonomy.cdm.model.description.TaxonDescription; |
|
35 | 42 |
import eu.etaxonomy.cdm.model.description.TextData; |
36 | 43 |
import eu.etaxonomy.cdm.model.media.Media; |
44 |
import eu.etaxonomy.cdm.model.name.ZoologicalName; |
|
45 |
import eu.etaxonomy.cdm.model.occurrence.Collection; |
|
46 |
import eu.etaxonomy.cdm.model.occurrence.DeterminationEvent; |
|
37 | 47 |
import eu.etaxonomy.cdm.model.occurrence.Specimen; |
38 | 48 |
import eu.etaxonomy.cdm.model.reference.Reference; |
49 |
import eu.etaxonomy.cdm.model.reference.ReferenceFactory; |
|
39 | 50 |
import eu.etaxonomy.cdm.model.taxon.Taxon; |
51 |
import eu.etaxonomy.cdm.model.taxon.TaxonBase; |
|
40 | 52 |
|
41 | 53 |
|
42 | 54 |
/** |
... | ... | |
49 | 61 |
private static final Logger logger = Logger.getLogger(GlobisImageImport.class); |
50 | 62 |
|
51 | 63 |
private int modCount = 10000; |
64 |
|
|
65 |
private UUID uuidArtNonSpecTaxMarkerType = UUID.fromString("be362085-0f5b-4314-96d1-78b9b129ef6d") ; |
|
52 | 66 |
private static final String pluralString = "images"; |
53 | 67 |
private static final String dbTableName = "Einzelbilder"; |
54 |
private static final Class cdmTargetClass = Media |
|
55 |
.class; //not needed |
|
68 |
private static final Class cdmTargetClass = Media.class; //not needed |
|
56 | 69 |
|
57 | 70 |
private static final String IMAGE_NAMESPACE = "Einzelbilder"; |
71 |
private static UUID uuidGartRef = UUID.fromString("af85470f-6e54-4304-9d29-fd117cd56161"); |
|
58 | 72 |
|
59 | 73 |
public GlobisImageImport(){ |
60 | 74 |
super(pluralString, dbTableName, cdmTargetClass); |
... | ... | |
105 | 119 |
Map<String, Specimen> typeMap = (Map<String, Specimen>) partitioner.getObjectMap(GlobisSpecTaxImport.TYPE_NAMESPACE); |
106 | 120 |
|
107 | 121 |
Map<String, Taxon> taxonMap = (Map<String, Taxon>) partitioner.getObjectMap(TAXON_NAMESPACE); |
108 |
// Map<String, DerivedUnit> ecoFactDerivedUnitMap = (Map<String, DerivedUnit>) partitioner.getObjectMap(ECO_FACT_DERIVED_UNIT_NAMESPACE);
|
|
122 |
Map<String, ZoologicalName> specTaxNameMap = (Map<String, ZoologicalName>) partitioner.getObjectMap(GlobisSpecTaxImport.SPEC_TAX_NAMESPACE);
|
|
109 | 123 |
|
110 | 124 |
ResultSet rs = partitioner.getResultSet(); |
111 | 125 |
|
126 |
Reference<?> refGart = getReferenceService().find(uuidGartRef); |
|
127 |
|
|
128 |
|
|
112 | 129 |
try { |
113 | 130 |
|
114 | 131 |
int i = 0; |
115 | 132 |
|
116 |
//for each reference
|
|
133 |
//for each record
|
|
117 | 134 |
while (rs.next()){ |
118 | 135 |
|
119 | 136 |
if ((i++ % modCount) == 0 && i!= 1 ){ logger.info(pluralString + " handled: " + (i-1));} |
120 | 137 |
|
121 | 138 |
Integer bildID = rs.getInt("BildID"); |
122 |
|
|
123 | 139 |
Integer spectaxID = nullSafeInt(rs, "spectaxID"); |
124 |
|
|
125 | 140 |
Integer taxonID = nullSafeInt(rs, "SpecCurrspecID"); |
126 |
|
|
127 | 141 |
String copyright = rs.getString("copyright"); |
142 |
String specimenId = rs.getString("specimenID"); |
|
143 |
String bemerkungen = rs.getString("Bemerkungen"); |
|
144 |
String artNotSpecTax = rs.getString("Art non spectax"); |
|
145 |
String motiv = rs.getString("Motiv"); |
|
128 | 146 |
|
129 | 147 |
//ignore: |
130 | 148 |
// [file lab2], same as Dateiname04 but less data |
131 | 149 |
// Dateipfad |
150 |
|
|
132 | 151 |
Set<Media> recordMedia = new HashSet<Media>(); |
133 | 152 |
|
134 | 153 |
try { |
135 | 154 |
|
136 |
//make image path |
|
137 |
String pathShort = rs.getString("Dateipfad_kurz"); |
|
138 |
String fileOS = rs.getString("file OS"); |
|
139 |
pathShort= pathShort.replace(fileOS, ""); |
|
140 |
String newPath = state.getConfig().getImageBaseUrl(); |
|
141 |
String path = pathShort.replace("image:Webversionen/", newPath); |
|
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); |
|
151 |
|
|
152 |
if (spectaxID != null){ |
|
155 |
makeAllMedia(state, rs, recordMedia, objectsToSave); |
|
156 |
|
|
157 |
String title = null; |
|
158 |
|
|
159 |
Specimen specimen = null; |
|
160 |
if (spectaxID != null){ |
|
161 |
//try to find type specimen |
|
162 |
if (isNotBlank(motiv) && (motiv.startsWith("type specimen"))){ |
|
163 |
String collectionCode = transformCopyright2CollectionCode(copyright); |
|
164 |
String id = GlobisSpecTaxImport.getTypeId(spectaxID, collectionCode); |
|
165 |
specimen = typeMap.get(id); |
|
166 |
} |
|
167 |
|
|
168 |
//try to find specTaxName |
|
169 |
ZoologicalName specTaxTaxonName = specTaxNameMap.get(String.valueOf(spectaxID)); |
|
170 |
if (specTaxTaxonName != null){ |
|
171 |
title = " taxon name " + specTaxTaxonName.getTitleCache(); |
|
172 |
}else{ |
|
173 |
title = " spectaxID " + spectaxID; |
|
174 |
} |
|
175 |
}else{ |
|
176 |
title = " name " + getNameFromFileOs(rs) + (isBlank(specimenId)? "" : " (specimenId: " + specimenId + ")"); |
|
177 |
} |
|
178 |
|
|
179 |
//not type specimen |
|
180 |
if (specimen == null){ |
|
181 |
specimen = Specimen.NewInstance(); |
|
182 |
specimen.setTitleCache("Specimen for " + title ); |
|
153 | 183 |
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 | 184 |
//TODO |
185 |
Collection collection = getCollection(collectionCode); |
|
186 |
specimen.setCollection(collection); |
|
166 | 187 |
} |
167 | 188 |
|
168 | 189 |
|
190 |
//source |
|
191 |
specimen.addSource(String.valueOf(bildID), IMAGE_NAMESPACE, state.getTransactionalSourceReference(), null); |
|
169 | 192 |
|
193 |
//GART id (specimenID) |
|
194 |
if (isNotBlank(specimenId)){ |
|
195 |
specimen.addSource(specimenId, "", refGart, null); |
|
196 |
} |
|
197 |
//bemerkungen |
|
198 |
if (isNotBlank(bemerkungen)){ |
|
199 |
Annotation annotation = Annotation.NewInstance(bemerkungen, null, null); |
|
200 |
specimen.addAnnotation(annotation); |
|
201 |
} |
|
202 |
//media |
|
203 |
DerivedUnitFacade facade = DerivedUnitFacade.NewInstance(specimen); |
|
204 |
for (Media media: recordMedia){ |
|
205 |
facade.addDerivedUnitMedia(media); |
|
206 |
} |
|
207 |
//art non spectax |
|
208 |
if (isNotBlank(artNotSpecTax)){ |
|
209 |
if (artNotSpecTax.equalsIgnoreCase("ja")){ |
|
210 |
MarkerType artNotSpecTaxMarker = getMarkerType(state, uuidArtNonSpecTaxMarkerType , "Art non spectax", "This marker is true if in the orginal data the 'Art non spectax' was 'ja'", null) ; |
|
211 |
specimen.addMarker(Marker.NewInstance(artNotSpecTaxMarker, true)); |
|
212 |
}else{ |
|
213 |
logger.warn(artNotSpecTax + " is not a valid value for 'Art non spectax' (BildID: " + bildID + ")" ); |
|
214 |
} |
|
215 |
} |
|
216 |
|
|
217 |
if (spectaxID != null){ |
|
218 |
|
|
219 |
//add to image gallery (discuss if this is also needed if taxon is already added to type specimen |
|
220 |
// Taxon taxon = taxonMap.get(String.valueOf(taxonID)); |
|
221 |
ZoologicalName specTaxTaxonName = specTaxNameMap.get(String.valueOf(spectaxID)); |
|
222 |
|
|
223 |
// |
|
224 |
// if (taxon == null){ |
|
225 |
//// taxon = specTaxMap.get(String.valueOf(spectaxID)); |
|
226 |
//// specTaxName = specTaxMap.g |
|
227 |
// } |
|
228 |
// if (taxon == null){ |
|
229 |
// logger.warn("No taxon available for specTaxID: " + spectaxID); |
|
230 |
// }else{ |
|
231 |
// name = CdmBase.deproxy(taxon.getName(), ZoologicalName.class); |
|
232 |
// } |
|
233 |
|
|
234 |
//TODO FIXME |
|
235 |
|
|
236 |
if (specTaxTaxonName == null){ |
|
237 |
logger.warn("Name could not be found for spectaxID: " + spectaxID + " in BildID: " + bildID); |
|
238 |
}else{ |
|
239 |
Taxon taxon = null; |
|
240 |
for (Taxon specTaxTaxon: specTaxTaxonName.getTaxa()){ |
|
241 |
taxon = specTaxTaxon; |
|
242 |
} |
|
243 |
if (taxon == null){ |
|
244 |
//FIXME |
|
245 |
Reference undefinedSec = null; |
|
246 |
taxon = Taxon.NewInstance(specTaxTaxonName, undefinedSec); |
|
247 |
} |
|
248 |
|
|
249 |
DeterminationEvent determinationEvent = DeterminationEvent.NewInstance(); |
|
250 |
determinationEvent.setTaxon(taxon); |
|
251 |
determinationEvent.setIdentifiedUnit(specimen); |
|
252 |
} |
|
253 |
|
|
254 |
|
|
255 |
|
|
256 |
|
|
257 |
// if (taxon != null){ |
|
258 |
// TaxonDescription taxonDescription = getTaxonDescription(taxon, true, true); |
|
259 |
// if (taxonDescription.getElements().size() == 0){ |
|
260 |
// TextData textData = TextData.NewInstance(Feature.IMAGE()); |
|
261 |
// taxonDescription.addElement(textData); |
|
262 |
// } |
|
263 |
// Set<DescriptionElementBase> elements = taxonDescription.getElements(); |
|
264 |
// TextData textData = CdmBase.deproxy(elements.iterator().next(), TextData.class); |
|
265 |
// for (Media media: recordMedia){ |
|
266 |
// textData.addMedia(media); |
|
267 |
// } |
|
268 |
// } |
|
269 |
} |
|
170 | 270 |
|
171 | 271 |
} catch (Exception e) { |
172 | 272 |
logger.warn("Exception in Einzelbilder: bildID " + bildID + ". " + e.getMessage()); |
... | ... | |
184 | 284 |
return false; |
185 | 285 |
} |
186 | 286 |
} |
287 |
|
|
288 |
private Collection getCollection(String collectionCode) { |
|
289 |
//TODO |
|
290 |
return null; |
|
291 |
} |
|
292 |
|
|
293 |
|
|
294 |
|
|
295 |
|
|
296 |
private String getNameFromFileOs(ResultSet rs) throws SQLException { |
|
297 |
String fileOS = rs.getString("file OS"); |
|
298 |
Pattern pattern = Pattern.compile("(.+)(_...._..\\.jpg)"); |
|
299 |
Matcher matcher = pattern.matcher(fileOS); |
|
300 |
if (matcher.matches()){ |
|
301 |
String match = matcher.group(1); |
|
302 |
return match; |
|
303 |
}else{ |
|
304 |
logger.warn("FileOS does not match: " + fileOS); |
|
305 |
return fileOS; |
|
306 |
} |
|
307 |
} |
|
308 |
|
|
309 |
|
|
310 |
|
|
311 |
|
|
312 |
private void makeAllMedia(GlobisImportState state, ResultSet rs, Set<Media> recordMedia, Set<Media> objectsToSave) throws SQLException{ |
|
313 |
//make image path |
|
314 |
String pathShort = rs.getString("Dateipfad_kurz"); |
|
315 |
String fileOS = rs.getString("file OS"); |
|
316 |
pathShort= pathShort.replace(fileOS, ""); |
|
317 |
String newPath = state.getConfig().getImageBaseUrl(); |
|
318 |
String path = pathShort.replace("image:Webversionen/", newPath); |
|
319 |
|
|
320 |
Media singleMedia = makeMedia(state, rs, "file OS", "Legende 1", path, objectsToSave ); |
|
321 |
recordMedia.add(singleMedia); |
|
322 |
singleMedia = makeMedia(state, rs, "Dateinamen02", "Legende 2", path, objectsToSave ); |
|
323 |
recordMedia.add(singleMedia); |
|
324 |
singleMedia = makeMedia(state, rs, "Dateinamen03", "Legende 3", path, objectsToSave ); |
|
325 |
recordMedia.add(singleMedia); |
|
326 |
singleMedia = makeMedia(state, rs, "Dateinamen04", "Legende 4", path, objectsToSave ); |
|
327 |
recordMedia.add(singleMedia); |
|
328 |
|
|
329 |
} |
|
187 | 330 |
|
188 | 331 |
private Media makeMedia(GlobisImportState state, ResultSet rs, String fileNameAttr, String legendAttr, String path, Set<Media> objectsToSave) throws SQLException { |
189 | 332 |
Media media = null; |
... | ... | |
191 | 334 |
String legend = rs.getString(legendAttr); |
192 | 335 |
Integer bildID = rs.getInt("BildID"); |
193 | 336 |
|
194 |
URI uri = URI.create(path+fileName); |
|
337 |
String uriStr = path+fileName; |
|
338 |
uriStr = uriStr.replace(" ", "%20"); |
|
339 |
|
|
340 |
URI uri = URI.create(uriStr); |
|
195 | 341 |
|
196 | 342 |
// Media media = ImageInfo.NewInstanceWithMetaData(uri, null); |
197 | 343 |
|
... | ... | |
283 | 429 |
Map<Object, Map<String, ? extends CdmBase>> result = new HashMap<Object, Map<String, ? extends CdmBase>>(); |
284 | 430 |
try{ |
285 | 431 |
Set<String> currSpecIdSet = new HashSet<String>(); |
432 |
Set<String> specTaxIdSet = new HashSet<String>(); |
|
286 | 433 |
Set<String> typeIdSet = new HashSet<String>(); |
287 | 434 |
|
288 | 435 |
while (rs.next()){ |
... | ... | |
290 | 437 |
handleTypeKey(rs, typeIdSet, "spectaxID", "copyright"); |
291 | 438 |
} |
292 | 439 |
|
440 |
//specTax map |
|
441 |
nameSpace = GlobisSpecTaxImport.SPEC_TAX_NAMESPACE; |
|
442 |
cdmClass = TaxonBase.class; |
|
443 |
idSet = specTaxIdSet; |
|
444 |
Map<String, TaxonBase> specTaxMap = (Map<String, TaxonBase>)getCommonService().getSourcedObjectsByIdInSource(cdmClass, idSet, nameSpace); |
|
445 |
result.put(nameSpace, specTaxMap); |
|
446 |
|
|
293 | 447 |
//taxon map |
294 | 448 |
nameSpace = TAXON_NAMESPACE; |
295 | 449 |
cdmClass = Taxon.class; |
... | ... | |
297 | 451 |
Map<String, Taxon> taxonMap = (Map<String, Taxon>)getCommonService().getSourcedObjectsByIdInSource(cdmClass, idSet, nameSpace); |
298 | 452 |
result.put(nameSpace, taxonMap); |
299 | 453 |
|
454 |
|
|
300 | 455 |
//type map |
301 | 456 |
nameSpace = GlobisSpecTaxImport.TYPE_NAMESPACE; |
302 | 457 |
cdmClass = Specimen.class; |
... | ... | |
343 | 498 |
|
344 | 499 |
|
345 | 500 |
|
501 |
/* (non-Javadoc) |
|
502 |
* @see eu.etaxonomy.cdm.io.globis.GlobisImportBase#doInvoke(eu.etaxonomy.cdm.io.globis.GlobisImportState) |
|
503 |
*/ |
|
504 |
@Override |
|
505 |
protected void doInvoke(GlobisImportState state) { |
|
506 |
Reference refGart = ReferenceFactory.newGeneric(); |
|
507 |
refGart.setTitleCache("GART"); |
|
508 |
refGart.setUuid(uuidGartRef); |
|
509 |
getReferenceService().saveOrUpdate(refGart); |
|
510 |
super.doInvoke(state); |
|
511 |
} |
|
512 |
|
|
513 |
|
|
514 |
|
|
515 |
|
|
346 | 516 |
|
347 | 517 |
} |
app-import/src/main/java/eu/etaxonomy/cdm/io/globis/GlobisImportBase.java | ||
---|---|---|
57 | 57 |
|
58 | 58 |
protected static final String REFERENCE_NAMESPACE = "Literatur"; |
59 | 59 |
protected static final String TAXON_NAMESPACE = "current_species"; |
60 |
|
|
61 |
|
|
60 |
protected static final String COLLECTION_NAMESPACE = "Collection"; |
|
61 |
|
|
62 | 62 |
private String pluralString; |
63 | 63 |
private String dbTableName; |
64 | 64 |
//TODO needed? |
app-import/src/main/java/eu/etaxonomy/cdm/io/globis/GlobisSpecTaxImport.java | ||
---|---|---|
13 | 13 |
import java.sql.SQLException; |
14 | 14 |
import java.util.HashMap; |
15 | 15 |
import java.util.HashSet; |
16 |
import java.util.List; |
|
16 | 17 |
import java.util.Map; |
17 | 18 |
import java.util.Set; |
18 | 19 |
import java.util.regex.Matcher; |
19 | 20 |
import java.util.regex.Pattern; |
20 | 21 |
|
21 |
import org.apache.commons.lang.StringUtils; |
|
22 | 22 |
import org.apache.log4j.Logger; |
23 | 23 |
import org.springframework.stereotype.Component; |
24 | 24 |
|
25 | 25 |
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade; |
26 | 26 |
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade.DerivedUnitType; |
27 | 27 |
import eu.etaxonomy.cdm.common.CdmUtils; |
28 |
import eu.etaxonomy.cdm.io.common.IImportConfigurator; |
|
29 | 28 |
import eu.etaxonomy.cdm.io.common.IOValidator; |
30 | 29 |
import eu.etaxonomy.cdm.io.common.ResultSetPartitioner; |
31 | 30 |
import eu.etaxonomy.cdm.io.common.mapping.IMappingImport; |
32 |
import eu.etaxonomy.cdm.io.globis.validation.GlobisReferenceImportValidator; |
|
33 | 31 |
import eu.etaxonomy.cdm.io.globis.validation.GlobisSpecTaxaImportValidator; |
34 | 32 |
import eu.etaxonomy.cdm.model.common.CdmBase; |
35 |
import eu.etaxonomy.cdm.model.common.Extension; |
|
36 | 33 |
import eu.etaxonomy.cdm.model.common.IdentifiableSource; |
37 | 34 |
import eu.etaxonomy.cdm.model.common.Marker; |
38 | 35 |
import eu.etaxonomy.cdm.model.common.MarkerType; |
... | ... | |
41 | 38 |
import eu.etaxonomy.cdm.model.name.Rank; |
42 | 39 |
import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignation; |
43 | 40 |
import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignationStatus; |
44 |
import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignationTest; |
|
45 | 41 |
import eu.etaxonomy.cdm.model.name.TaxonNameBase; |
46 | 42 |
import eu.etaxonomy.cdm.model.name.ZoologicalName; |
47 | 43 |
import eu.etaxonomy.cdm.model.occurrence.Collection; |
48 | 44 |
import eu.etaxonomy.cdm.model.occurrence.DerivationEvent; |
49 |
import eu.etaxonomy.cdm.model.occurrence.DerivationEventType; |
|
50 |
import eu.etaxonomy.cdm.model.occurrence.DerivedUnitBase; |
|
51 | 45 |
import eu.etaxonomy.cdm.model.occurrence.FieldObservation; |
52 | 46 |
import eu.etaxonomy.cdm.model.occurrence.Specimen; |
53 | 47 |
import eu.etaxonomy.cdm.model.reference.Reference; |
54 |
import eu.etaxonomy.cdm.model.reference.ReferenceFactory; |
|
55 |
import eu.etaxonomy.cdm.model.reference.ReferenceType; |
|
56 | 48 |
import eu.etaxonomy.cdm.model.taxon.Synonym; |
57 | 49 |
import eu.etaxonomy.cdm.model.taxon.SynonymRelationshipType; |
58 | 50 |
import eu.etaxonomy.cdm.model.taxon.Taxon; |
... | ... | |
150 | 142 |
|
151 | 143 |
ZoologicalName name = null; |
152 | 144 |
if (isBlank(specSystaxRank) ){ |
153 |
name = makeName(state, rs); |
|
145 |
name = makeName(state, rs, specTaxId);
|
|
154 | 146 |
}else if (specSystaxRank.equals("synonym")){ |
155 |
Synonym synonym = getSynonym(state, rs); |
|
147 |
Synonym synonym = getSynonym(state, rs, specTaxId);
|
|
156 | 148 |
if (acceptedTaxon == null){ |
157 | 149 |
if (acceptedTaxonId == null){ |
158 | 150 |
logger.warn("Synonym has no accepted taxon defined. SpecTaxId: "+ specTaxId); |
... | ... | |
168 | 160 |
thisTaxon = acceptedTaxon; |
169 | 161 |
}else{ |
170 | 162 |
logger.warn(String.format("Unhandled specSystaxRank %s in specTaxId %d", specSystaxRank, specTaxId)); |
171 |
name = makeName(state, rs); |
|
163 |
name = makeName(state, rs, specTaxId);
|
|
172 | 164 |
} |
173 | 165 |
|
174 | 166 |
if (thisTaxon != null){ |
175 | 167 |
name = CdmBase.deproxy(thisTaxon.getName(), ZoologicalName.class); |
176 |
} |
|
177 |
if (name == null){ |
|
178 |
name = makeName(state, rs); |
|
168 |
}else{ |
|
169 |
if (name == null){ |
|
170 |
name = makeName(state, rs, specTaxId); |
|
171 |
} |
|
172 |
thisTaxon = Taxon.NewInstance(name, sourceRef); |
|
173 |
objectsToSave.add(thisTaxon); |
|
179 | 174 |
} |
180 | 175 |
|
181 | 176 |
handleNomRef(state, referenceMap, rs, name); |
... | ... | |
214 | 209 |
|
215 | 210 |
|
216 | 211 |
private void handleTypeInformation(GlobisImportState state, ResultSet rs, ZoologicalName name, Integer specTaxId) throws SQLException { |
217 |
|
|
218 |
|
|
219 | 212 |
if (! hasTypeInformation(rs)){ |
220 | 213 |
return; |
221 | 214 |
} |
... | ... | |
252 | 245 |
specTypeDepositoryStr = makeAdditionalSpecimenInformation( |
253 | 246 |
specTypeDepositoryStr, specimen, specTaxId); |
254 | 247 |
|
255 |
Collection collection = makeCollection(specTypeDepositoryStr, specimen, specTaxId); |
|
248 |
Collection collection = makeCollection(state, specTypeDepositoryStr, specimen, specTaxId);
|
|
256 | 249 |
String collectionCode = collection.getCode(); |
257 | 250 |
if (isBlank(collectionCode)){ |
258 | 251 |
collectionCode = collection.getName(); |
... | ... | |
302 | 295 |
|
303 | 296 |
|
304 | 297 |
/** |
298 |
* @param state |
|
305 | 299 |
* @param specTypeDepositoryStr |
306 | 300 |
* @param specimen |
307 | 301 |
* @param specTaxId |
308 | 302 |
*/ |
309 |
protected Collection makeCollection(String specTypeDepositoryStr, Specimen specimen, Integer specTaxId) { |
|
310 |
//TODO deduplicate |
|
311 |
Map<String, Collection> collectionMap = new HashMap<String, Collection>(); |
|
303 |
protected Collection makeCollection(GlobisImportState state, String specTypeDepositoryStr, Specimen specimen, Integer specTaxId) { |
|
312 | 304 |
|
313 | 305 |
//Collection |
314 | 306 |
specTypeDepositoryStr = specTypeDepositoryStr.replace("Washington, D.C.", "Washington@ D.C."); |
315 | 307 |
|
316 | 308 |
Collection collection; |
317 | 309 |
if (specTypeDepositoryStr.equals("BMNH, London and/or MNHN, Paris")){ |
318 |
//TODO deduplicate |
|
319 |
collection = Collection.NewInstance(); |
|
320 |
collection.setName(specTypeDepositoryStr); |
|
310 |
collection = state.getRelatedObject(COLLECTION_NAMESPACE, specTypeDepositoryStr, Collection.class); |
|
311 |
if (collection == null){ |
|
312 |
collection = Collection.NewInstance(); |
|
313 |
collection.setName(specTypeDepositoryStr); |
|
314 |
collection.setTownOrLocation("London or Paris"); |
|
315 |
state.addRelatedObject(COLLECTION_NAMESPACE, collection.getName(), collection); |
|
316 |
} |
|
321 | 317 |
specimen.setCollection(collection); |
322 | 318 |
}else if (specTypeDepositoryStr.equals("coll. L. V. Kaabak, A .V. Sotshivko & V. V. Titov, Moscow")){ |
323 |
collection = Collection.NewInstance(); |
|
324 |
collection.setName("coll. L. V. Kaabak, A .V. Sotshivko & V. V. Titov"); |
|
325 |
collection.setTownOrLocation("Moscow"); |
|
319 |
String colName = "coll. L. V. Kaabak, A .V. Sotshivko & V. V. Titov"; |
|
320 |
collection = state.getRelatedObject(COLLECTION_NAMESPACE, colName, Collection.class); |
|
321 |
if (collection == null){ |
|
322 |
collection = Collection.NewInstance(); |
|
323 |
collection.setName(colName); |
|
324 |
collection.setTownOrLocation("Moscow"); |
|
325 |
state.addRelatedObject(COLLECTION_NAMESPACE, collection.getName(), collection); |
|
326 |
} |
|
326 | 327 |
specimen.setCollection(collection); |
327 | 328 |
}else if (specTypeDepositoryStr.matches("coll. R. E. Parrott?, Port Hope, Ontario")){ |
328 |
//TODO deduplicate |
|
329 |
collection = Collection.NewInstance(); |
|
330 |
collection.setName("coll. R. E. Parrott"); |
|
331 |
collection.setTownOrLocation("Port Hope, Ontario"); |
|
329 |
String colName = "coll. R. E. Parrott"; |
|
330 |
collection = state.getRelatedObject(COLLECTION_NAMESPACE, colName, Collection.class); |
|
331 |
if (collection == null){ |
|
332 |
collection = Collection.NewInstance(); |
|
333 |
collection.setName(colName); |
|
334 |
collection.setTownOrLocation("Port Hope, Ontario"); |
|
335 |
state.addRelatedObject(COLLECTION_NAMESPACE, collection.getName(), collection); |
|
336 |
} |
|
332 | 337 |
specimen.setCollection(collection); |
333 | 338 |
}else{ |
334 | 339 |
|
335 | 340 |
String[] split = specTypeDepositoryStr.split(","); |
336 | 341 |
if (split.length != 2){ |
337 | 342 |
if (split.length == 1 && split[0].startsWith("coll.")){ |
338 |
collection = Collection.NewInstance(); |
|
339 |
collection.setName(split[0]); |
|
343 |
collection = state.getRelatedObject(COLLECTION_NAMESPACE, split[0], Collection.class); |
|
344 |
if (collection == null){ |
|
345 |
collection = Collection.NewInstance(); |
|
346 |
collection.setName(split[0]); |
|
347 |
state.addRelatedObject(COLLECTION_NAMESPACE, collection.getName(), collection); |
|
348 |
} |
|
340 | 349 |
specimen.setCollection(collection); |
341 | 350 |
}else{ |
342 | 351 |
logger.warn("Split size is not 2: " + specTypeDepositoryStr + " (specTaxID:" + specTaxId + ")"); |
343 | 352 |
collection = Collection.NewInstance(); |
344 | 353 |
collection.setCode("??"); |
354 |
//TODO deduplicate ?? |
|
345 | 355 |
} |
346 | 356 |
|
347 | 357 |
}else{ |
348 | 358 |
String collectionStr = split[0]; |
349 | 359 |
String location = split[1].replace("Washington@ D.C.", "Washington, D.C."); |
350 | 360 |
|
351 |
collection = collectionMap.get(collectionStr);
|
|
361 |
collection = state.getRelatedObject(COLLECTION_NAMESPACE, collectionStr, Collection.class);
|
|
352 | 362 |
if (collection == null){ |
353 | 363 |
collection = Collection.NewInstance(); |
354 | 364 |
collection.setCode(collectionStr); |
355 | 365 |
collection.setTownOrLocation(split[1]); |
356 |
}else if (CdmUtils.nullSafeEqual(location, collection.getTownOrLocation())){ |
|
366 |
state.addRelatedObject(COLLECTION_NAMESPACE, collection.getCode(), collection); |
|
367 |
|
|
368 |
}else if (! CdmUtils.nullSafeEqual(location, collection.getTownOrLocation())){ |
|
357 | 369 |
String message = "Location (%s) is not equal to location (%s) of existing collection"; |
358 | 370 |
logger.warn(String.format(message, location, collection.getTownOrLocation(), collection.getCode())); |
359 | 371 |
} |
... | ... | |
540 | 552 |
|
541 | 553 |
|
542 | 554 |
|
543 |
private Synonym getSynonym(GlobisImportState state, ResultSet rs) throws SQLException { |
|
544 |
ZoologicalName name = makeName(state, rs); |
|
555 |
private Synonym getSynonym(GlobisImportState state, ResultSet rs, Integer specTaxId) throws SQLException {
|
|
556 |
ZoologicalName name = makeName(state, rs, specTaxId);
|
|
545 | 557 |
|
546 | 558 |
Synonym synonym = Synonym.NewInstance(name, state.getTransactionalSourceReference()); |
547 | 559 |
|
... | ... | |
554 | 566 |
/** |
555 | 567 |
* @param state |
556 | 568 |
* @param rs |
569 |
* @param specTaxId |
|
557 | 570 |
* @return |
558 | 571 |
* @throws SQLException |
559 | 572 |
*/ |
560 |
protected ZoologicalName makeName(GlobisImportState state, ResultSet rs) |
|
573 |
protected ZoologicalName makeName(GlobisImportState state, ResultSet rs, Integer specTaxId)
|
|
561 | 574 |
throws SQLException { |
562 | 575 |
//rank |
563 | 576 |
String rankStr = rs.getString("SpecRank"); |
... | ... | |
580 | 593 |
String yearStr = rs.getString("SpecYear"); |
581 | 594 |
String authorAndYearStr = CdmUtils.concat(", ", authorStr, yearStr); |
582 | 595 |
handleAuthorAndYear(authorAndYearStr, name); |
596 |
|
|
597 |
name.addSource(String.valueOf(specTaxId), SPEC_TAX_NAMESPACE, state.getTransactionalSourceReference(), null); |
|
583 | 598 |
return name; |
584 | 599 |
} |
585 | 600 |
|
... | ... | |
611 | 626 |
} |
612 | 627 |
|
613 | 628 |
|
614 |
|
|
615 |
|
|
616 |
private boolean isInfraSpecies(GlobisImportState state, ResultSet rs, Rank rank) { |
|
617 |
// TODO Auto-generated method stub |
|
618 |
return false; |
|
619 |
} |
|
620 |
|
|
621 |
|
|
622 |
|
|
623 |
|
|
624 |
private Reference<?> getJournal(GlobisImportState state, ResultSet rs, String refJournal) throws SQLException { |
|
625 |
|
|
626 |
|
|
627 |
Reference<?> journal = ReferenceFactory.newJournal(); |
|
628 |
String issn = rs.getString("RefISSN"); |
|
629 |
if (StringUtils.isNotBlank(issn)){ |
|
630 |
issn.replaceAll("ISSN", "").trim(); |
|
631 |
journal.setIssn(issn); |
|
632 |
} |
|
633 |
|
|
634 |
|
|
635 |
|
|
636 |
//TODO deduplicate |
|
637 |
journal.setTitle(refJournal); |
|
638 |
return journal; |
|
639 |
} |
|
640 |
|
|
641 |
|
|
642 |
|
|
643 |
|
|
644 |
/* (non-Javadoc) |
|
645 |
* @see eu.etaxonomy.cdm.io.common.mapping.IMappingImport#createObject(java.sql.ResultSet, eu.etaxonomy.cdm.io.common.ImportStateBase) |
|
646 |
*/ |
|
647 |
public Reference<?> createObject(ResultSet rs, GlobisImportState state) |
|
648 |
throws SQLException { |
|
649 |
Reference<?> ref; |
|
650 |
String refType = rs.getString("RefType"); |
|
651 |
if (refType == null){ |
|
652 |
ref = ReferenceFactory.newGeneric(); |
|
653 |
}else if (refType == "book"){ |
|
654 |
ref = ReferenceFactory.newBook(); |
|
655 |
}else if (refType == "paper in journal"){ |
|
656 |
ref = ReferenceFactory.newArticle(); |
|
657 |
}else if (refType.startsWith("unpublished") ){ |
|
658 |
ref = ReferenceFactory.newGeneric(); |
|
659 |
}else if (refType.endsWith("paper in journal")){ |
|
660 |
ref = ReferenceFactory.newArticle(); |
|
661 |
}else if (refType == "paper in book"){ |
|
662 |
ref = ReferenceFactory.newBookSection(); |
|
663 |
}else if (refType == "paper in journalwebsite"){ |
|
664 |
ref = ReferenceFactory.newArticle(); |
|
665 |
}else{ |
|
666 |
logger.warn("Unknown reference type: " + refType); |
|
667 |
ref = ReferenceFactory.newGeneric(); |
|
668 |
} |
|
669 |
return ref; |
|
670 |
} |
|
671 |
|
|
672 | 629 |
/* (non-Javadoc) |
673 | 630 |
* @see eu.etaxonomy.cdm.io.berlinModel.in.IPartitionedIO#getRelatedObjectsForPartition(java.sql.ResultSet) |
674 | 631 |
*/ |
... | ... | |
700 | 657 |
Map<String, Reference> referenceMap = (Map<String, Reference>)getCommonService().getSourcedObjectsByIdInSource(cdmClass, idSet, nameSpace); |
701 | 658 |
result.put(nameSpace, referenceMap); |
702 | 659 |
|
660 |
//collection map |
|
661 |
nameSpace = COLLECTION_NAMESPACE; |
|
662 |
List<Collection> listCollection = getCollectionService().list(Collection.class, null, null, null, null); |
|
663 |
Map<String, Collection> collectionMap = new HashMap<String, Collection>(); |
|
664 |
for (Collection collection : listCollection){ |
|
665 |
collectionMap.put(collection.getCode(), collection); |
|
666 |
if (isBlank(collection.getCode())){ |
|
667 |
logger.warn("Collection code is blank: " + collection); |
|
668 |
} |
|
669 |
} |
|
670 |
result.put(nameSpace, collectionMap); |
|
703 | 671 |
|
704 | 672 |
} catch (SQLException e) { |
705 | 673 |
throw new RuntimeException(e); |
... | ... | |
727 | 695 |
|
728 | 696 |
|
729 | 697 |
|
698 |
@Override |
|
699 |
public Reference createObject(ResultSet rs, GlobisImportState state) |
|
700 |
throws SQLException { |
|
701 |
// not needed |
|
702 |
return null; |
|
703 |
} |
|
704 |
|
|
705 |
|
|
706 |
|
|
707 |
|
|
730 | 708 |
|
731 | 709 |
} |
Also available in: Unified diff
latest globis