Revision 5947a91a
Added by Andreas Müller almost 12 years ago
cdm-pesi/src/main/java/eu/etaxonomy/cdm/io/pesi/out/PesiDescriptionExport.java | ||
---|---|---|
14 | 14 |
import java.sql.Connection; |
15 | 15 |
import java.sql.PreparedStatement; |
16 | 16 |
import java.sql.SQLException; |
17 |
import java.sql.Types; |
|
17 | 18 |
import java.util.Arrays; |
18 | 19 |
import java.util.HashSet; |
19 | 20 |
import java.util.List; |
... | ... | |
27 | 28 |
import eu.etaxonomy.cdm.io.berlinModel.BerlinModelTransformer; |
28 | 29 |
import eu.etaxonomy.cdm.io.common.DbExportStateBase; |
29 | 30 |
import eu.etaxonomy.cdm.io.common.Source; |
31 |
import eu.etaxonomy.cdm.io.common.mapping.DbIgnoreMapper; |
|
30 | 32 |
import eu.etaxonomy.cdm.io.common.mapping.UndefinedTransformerMethodException; |
31 | 33 |
import eu.etaxonomy.cdm.io.common.mapping.out.CollectionExportMapping; |
32 | 34 |
import eu.etaxonomy.cdm.io.common.mapping.out.DbAreaMapper; |
35 |
import eu.etaxonomy.cdm.io.common.mapping.out.DbConstantMapper; |
|
33 | 36 |
import eu.etaxonomy.cdm.io.common.mapping.out.DbDescriptionElementTaxonMapper; |
34 | 37 |
import eu.etaxonomy.cdm.io.common.mapping.out.DbDistributionStatusMapper; |
35 | 38 |
import eu.etaxonomy.cdm.io.common.mapping.out.DbExportIgnoreMapper; |
... | ... | |
41 | 44 |
import eu.etaxonomy.cdm.io.common.mapping.out.DbSingleSourceMapper; |
42 | 45 |
import eu.etaxonomy.cdm.io.common.mapping.out.DbStringMapper; |
43 | 46 |
import eu.etaxonomy.cdm.io.common.mapping.out.DbTextDataMapper; |
47 |
import eu.etaxonomy.cdm.io.common.mapping.out.DbTimePeriodMapper; |
|
44 | 48 |
import eu.etaxonomy.cdm.io.common.mapping.out.IdMapper; |
45 | 49 |
import eu.etaxonomy.cdm.io.common.mapping.out.MethodMapper; |
46 | 50 |
import eu.etaxonomy.cdm.io.profiler.ProfilerController; |
... | ... | |
64 | 68 |
import eu.etaxonomy.cdm.model.location.TdwgArea; |
65 | 69 |
import eu.etaxonomy.cdm.model.name.NonViralName; |
66 | 70 |
import eu.etaxonomy.cdm.model.name.TaxonNameBase; |
71 |
import eu.etaxonomy.cdm.model.reference.Reference; |
|
67 | 72 |
import eu.etaxonomy.cdm.model.taxon.Taxon; |
68 | 73 |
import eu.etaxonomy.cdm.model.taxon.TaxonBase; |
69 | 74 |
/** |
... | ... | |
180 | 185 |
occurrenceMapping.initialize(state); |
181 | 186 |
|
182 | 187 |
// Get specific mappings: (CDM) DescriptionElement -> (PESI) Additional taxon source |
183 |
PesiExportMapping addittionalSourceMapping = getAdditionalTaxonSourceMapping(); |
|
184 |
addittionalSourceMapping.initialize(state); |
|
188 |
PesiExportMapping addSourceSourceMapping = getAddTaxonSourceSourceMapping(); |
|
189 |
addSourceSourceMapping.initialize(state); |
|
190 |
PesiExportMapping additionalSourceMapping = getAdditionalTaxonSourceMapping(); |
|
191 |
additionalSourceMapping.initialize(state); |
|
185 | 192 |
|
186 | 193 |
// Get specific mappings: (CDM) DescriptionElement -> (PESI) Additional taxon source |
187 | 194 |
PesiExportMapping vernacularMapping = getVernacularNamesMapping(); |
... | ... | |
212 | 219 |
for (Taxon taxon : list) { |
213 | 220 |
countTaxa++; |
214 | 221 |
doCount(count++, modCount, pluralString); |
215 |
success &= handleSingleTaxon(taxon, state, notesMapping, occurrenceMapping, addittionalSourceMapping, vernacularMapping, imageMapping); |
|
222 |
success &= handleSingleTaxon(taxon, state, notesMapping, occurrenceMapping, addSourceSourceMapping, |
|
223 |
additionalSourceMapping, vernacularMapping, imageMapping); |
|
216 | 224 |
} |
217 | 225 |
list = null; |
218 | 226 |
state.setCurrentTaxon(null); |
... | ... | |
277 | 285 |
} |
278 | 286 |
|
279 | 287 |
private boolean handleSingleTaxon(Taxon taxon, PesiExportState state, PesiExportMapping notesMapping, PesiExportMapping occurrenceMapping, |
280 |
PesiExportMapping addittionalSourceMapping, PesiExportMapping vernacularMapping, PesiExportMapping imageMapping) throws SQLException { |
|
288 |
PesiExportMapping addSourceSourceMapping, PesiExportMapping additionalSourceMapping, |
|
289 |
PesiExportMapping vernacularMapping, PesiExportMapping imageMapping) throws SQLException { |
|
281 | 290 |
boolean success = true; |
282 | 291 |
Set<DescriptionBase<?>> descriptions = new HashSet<DescriptionBase<?>>(); |
283 | 292 |
descriptions.addAll(taxon.getDescriptions()); |
... | ... | |
292 | 301 |
boolean isImageGallery = desc.isImageGallery(); |
293 | 302 |
for (DescriptionElementBase element : desc.getElements()){ |
294 | 303 |
success &= handleDescriptionElement(state, notesMapping, occurrenceMapping, vernacularMapping, imageMapping, |
295 |
isImageGallery, element); |
|
304 |
addSourceSourceMapping, additionalSourceMapping, isImageGallery, element);
|
|
296 | 305 |
} |
297 | 306 |
} |
298 | 307 |
return success; |
... | ... | |
300 | 309 |
|
301 | 310 |
private boolean handleDescriptionElement(PesiExportState state, PesiExportMapping notesMapping, |
302 | 311 |
PesiExportMapping occurrenceMapping, PesiExportMapping vernacularMapping, PesiExportMapping imageMapping, |
303 |
boolean isImageGallery, DescriptionElementBase element) throws SQLException { |
|
312 |
PesiExportMapping addSourceSourceMapping, PesiExportMapping additionalSourceMapping, boolean isImageGallery, DescriptionElementBase element) throws SQLException {
|
|
304 | 313 |
try { |
305 | 314 |
boolean success = true; |
306 | 315 |
if (isImageGallery){ |
... | ... | |
310 | 319 |
}else if (isCommonName(element)){ |
311 | 320 |
countCommonName++; |
312 | 321 |
if (element.isInstanceOf(TextData.class)){ |
313 |
// |
|
322 |
//we do not import text data common names
|
|
314 | 323 |
}else{ |
315 | 324 |
success &= vernacularMapping.invoke(element); |
316 | 325 |
} |
... | ... | |
326 | 335 |
} |
327 | 336 |
}else if (isAdditionalTaxonSource(element)){ |
328 | 337 |
countAdditionalSources++; |
329 |
// success &= addittionalSourceMapping.invoke(element); |
|
338 |
success &= addSourceSourceMapping.invoke(element); |
|
339 |
success &= additionalSourceMapping.invoke(element); |
|
330 | 340 |
}else if (isExcludedNote(element)){ |
331 | 341 |
//do nothing |
332 | 342 |
}else if (isPesiNote(element)){ |
... | ... | |
418 | 428 |
if (feature == null){ |
419 | 429 |
return false; |
420 | 430 |
} |
421 |
return (feature.equals(Feature.CITATION())); |
|
431 |
return (feature.equals(Feature.CITATION()) || feature.equals(Feature.ADDITIONAL_PUBLICATION()));
|
|
422 | 432 |
} |
423 | 433 |
|
424 | 434 |
private boolean isOccurrence(DescriptionElementBase element) { |
... | ... | |
607 | 617 |
* @return The <code>Note_2</code> attribute. |
608 | 618 |
* @see MethodMapper |
609 | 619 |
*/ |
610 |
@SuppressWarnings("unused") |
|
611 |
private static String getNote_2(DescriptionElementBase descriptionElement) { |
|
612 |
logger.warn("Not yet implemented"); |
|
620 |
@SuppressWarnings("unused") //used for mapper |
|
621 |
private static String getNote_2(DescriptionElementBase element) { |
|
622 |
//E+M map links -> medium |
|
623 |
if (element.getFeature() != null && element.getFeature().getUuid().equals(BerlinModelTransformer.uuidFeatureMaps)){ |
|
624 |
String text = CdmBase.deproxy(element, TextData.class).getText(Language.ENGLISH()); |
|
625 |
if (text.contains("medium")){ |
|
626 |
return "medium"; |
|
627 |
} |
|
628 |
} |
|
613 | 629 |
return null; |
614 | 630 |
} |
615 | 631 |
|
... | ... | |
782 | 798 |
mapping.addMapper(IdMapper.NewInstance("NoteId")); |
783 | 799 |
mapping.addMapper(DbTextDataMapper.NewInstance(Language.ENGLISH(), "Note_1")); |
784 | 800 |
//TODO |
785 |
mapping.addMapper(DbExportNotYetImplementedMapper.NewInstance("Note_2", "Need to research what Note_2 is for"));
|
|
801 |
mapping.addMapper(MethodMapper.NewInstance("Note_2", this, DescriptionElementBase.class));
|
|
786 | 802 |
mapping.addMapper(MethodMapper.NewInstance("NoteCategoryFk", this, DescriptionElementBase.class )); |
787 | 803 |
|
788 | 804 |
mapping.addMapper(MethodMapper.NewInstance("NoteCategoryCache", this, DescriptionElementBase.class, PesiExportState.class )); |
... | ... | |
849 | 865 |
|
850 | 866 |
return mapping; |
851 | 867 |
} |
868 |
|
|
869 |
|
|
870 |
/** |
|
871 |
* Returns the CDM to PESI specific export mappings for additional taxon sources to create a new |
|
872 |
* source for the additional source |
|
873 |
* @see #{@link PesiDescriptionExport#getAdditionalTaxonSourceMapping()} |
|
874 |
* @return The {@link PesiExportMapping PesiExportMapping}. |
|
875 |
*/ |
|
876 |
private PesiExportMapping getAddTaxonSourceSourceMapping() { |
|
877 |
PesiExportMapping sourceMapping = new PesiExportMapping(PesiSourceExport.dbTableName); |
|
878 |
|
|
879 |
sourceMapping.addMapper(IdMapper.NewInstance("SourceId")); |
|
880 |
sourceMapping.addMapper(DbConstantMapper.NewInstance("SourceCategoryFk", Types.INTEGER, PesiTransformer.REF_UNRESOLVED)); |
|
881 |
sourceMapping.addMapper(DbConstantMapper.NewInstance("SourceCategoryCache", Types.VARCHAR, PesiTransformer.REF_STR_UNRESOLVED)); |
|
882 |
|
|
883 |
// sourceMapping.addMapper(MethodMapper.NewInstance("NomRefCache", PesiSourceExport.class, "getNomRefCache", Reference.class)); |
|
884 |
|
|
885 |
sourceMapping.addMapper(DbTextDataMapper.NewInstance(Language.ENGLISH(), "NomRefCache")); |
|
886 |
|
|
887 |
return sourceMapping; |
|
888 |
} |
|
852 | 889 |
|
890 |
|
|
853 | 891 |
/** |
854 | 892 |
* Returns the CDM to PESI specific export mappings for additional taxon sources. |
893 |
* @see #{@link PesiDescriptionExport#getAddTaxonSourceSourceMapping()} |
|
855 | 894 |
* @return The {@link PesiExportMapping PesiExportMapping}. |
856 | 895 |
*/ |
857 | 896 |
private PesiExportMapping getAdditionalTaxonSourceMapping() { |
897 |
|
|
858 | 898 |
PesiExportMapping mapping = new PesiExportMapping(dbAdditionalSourceTableName); |
859 | 899 |
|
860 | 900 |
mapping.addMapper(MethodMapper.NewInstance("TaxonFk", this, DescriptionElementBase.class, PesiExportState.class)); |
861 | 901 |
|
862 |
mapping.addMapper(DbSingleSourceMapper.NewInstance("SourceFk", of (DbSingleSourceMapper.EXCLUDE.WITH_ID) , ! IS_CACHE)); |
|
863 |
mapping.addMapper(DbSingleSourceMapper.NewInstance("SourceNameCache", of(DbSingleSourceMapper.EXCLUDE.WITH_ID) , ! IS_CACHE)); |
|
902 |
mapping.addMapper(IdMapper.NewInstance("SourceFk")); |
|
903 |
mapping.addMapper(DbTextDataMapper.NewInstance(Language.ENGLISH(), "SourceNameCache")); |
|
904 |
|
|
905 |
mapping.addMapper(DbConstantMapper.NewInstance("SourceUseFk", Types.INTEGER, PesiTransformer.NOMENCLATURAL_REFERENCE)); |
|
906 |
mapping.addMapper(DbConstantMapper.NewInstance("SourceUseCache", Types.VARCHAR, PesiTransformer.STR_NOMENCLATURAL_REFERENCE)); |
|
864 | 907 |
|
865 |
// mapping.addMapper(MethodMapper.NewInstance("SourceUseFk", this)); |
|
866 |
// mapping.addMapper(MethodMapper.NewInstance("SourceUseCache", this)); |
|
867 |
// mapping.addMapper(MethodMapper.NewInstance("SourceFk", this.getClass(), "getSourceFk", standardMethodParameter, PesiExportState.class)); |
|
868 |
// mapping.addMapper(MethodMapper.NewInstance("SourceNameCache", this)); |
|
869 |
// mapping.addMapper(MethodMapper.NewInstance("SourceDetail", this)); |
|
908 |
// mapping.addMapper(DbIgnoreMapper.NewInstance("SourceDetail", "SourceDetails not available for additional sources")); |
|
870 | 909 |
|
871 | 910 |
return mapping; |
872 | 911 |
} |
Also available in: Unified diff
latest changes for PESI export, moving old IOs to extra package