From: Andreas Müller Date: Mon, 28 Sep 2009 23:15:55 +0000 (+0000) Subject: image gallery in Berlin Model import X-Git-Tag: 3.0.3~1723 X-Git-Url: https://dev.e-taxonomy.eu/gitweb/cdmlib.git/commitdiff_plain/673a5e4c3eff8de593af9e339c2d6a669523f565 image gallery in Berlin Model import --- diff --git a/cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/berlinModel/in/BerlinModelFactsImport.java b/cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/berlinModel/in/BerlinModelFactsImport.java index c18df30405..ab531f2cf7 100644 --- a/cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/berlinModel/in/BerlinModelFactsImport.java +++ b/cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/berlinModel/in/BerlinModelFactsImport.java @@ -216,32 +216,10 @@ public class BerlinModelFactsImport extends BerlinModelImportBase { //for diptera images if (categoryFk == 51){ //TODO check also FactCategory string isImage = true; - String uri = fact; - Integer size = null; - ImageMetaData imageMetaData = new ImageMetaData(); - URL url; - try { - url = new URL(fact.trim()); - } catch (MalformedURLException e) { - logger.warn("Malformed URL. Image could not be imported: " + CdmUtils.Nz(uri)); - continue; - } - imageMetaData.readFrom(url); media = Media.NewInstance(); - MediaRepresentation mediaRepresentation = MediaRepresentation.NewInstance(imageMetaData.getMimeType(), null); - media.addRepresentation(mediaRepresentation); - ImageFile image = ImageFile.NewInstance(uri, size, imageMetaData); - mediaRepresentation.addRepresentationPart(image); - for (TaxonDescription desc: descriptionSet){ - if (desc.isImageGallery()){ - taxonDescription = desc; - } - } + taxonDescription = makeImage(state, fact, media, descriptionSet, taxon); if (taxonDescription == null){ - taxonDescription = TaxonDescription.NewInstance(); - taxonDescription.setTitleCache(sourceRef == null ? "Image Galery":sourceRef.getTitleCache()+"-Image Galery"); - taxon.addDescription(taxonDescription); - taxonDescription.setImageGallery(true); + continue; } } //all others (no image) @@ -384,6 +362,37 @@ public class BerlinModelFactsImport extends BerlinModelImportBase { } + /** + * @param state + * @param media + * @param media + * @param descriptionSet + * + */ + private TaxonDescription makeImage(BerlinModelImportState state, String fact, Media media, Set descriptionSet, Taxon taxon) { + TaxonDescription taxonDescription = null; + ReferenceBase sourceRef = state.getConfig().getSourceReference(); + String uri = fact; + Integer size = null; + ImageMetaData imageMetaData = new ImageMetaData(); + URL url; + try { + url = new URL(fact.trim()); + } catch (MalformedURLException e) { + logger.warn("Malformed URL. Image could not be imported: " + CdmUtils.Nz(uri)); + return null; + } + imageMetaData.readFrom(url); + MediaRepresentation mediaRepresentation = MediaRepresentation.NewInstance(imageMetaData.getMimeType(), null); + media.addRepresentation(mediaRepresentation); + ImageFile image = ImageFile.NewInstance(uri, size, imageMetaData); + mediaRepresentation.addRepresentationPart(image); + + taxonDescription = taxon.getOrCreateImageGallery(sourceRef == null ? null :sourceRef.getTitleCache()); + + return taxonDescription; + } + private TaxonBase getTaxon(MapWrapper taxonMap, Object taxonIdObj, Integer taxonId){ if (taxonIdObj != null){ return taxonMap.get(taxonId);