Project

General

Profile

« Previous | Next » 

Revision 432b7493

Added by Andreas Müller over 7 years ago

ref #6252 latest Salvador image import changes

View differences:

app-import/src/main/java/eu/etaxonomy/cdm/io/berlinModel/in/BerlinModelFactsImport.java
35 35
import eu.etaxonomy.cdm.io.common.IOValidator;
36 36
import eu.etaxonomy.cdm.io.common.ResultSetPartitioner;
37 37
import eu.etaxonomy.cdm.io.common.Source;
38
import eu.etaxonomy.cdm.model.agent.AgentBase;
39
import eu.etaxonomy.cdm.model.agent.Person;
40
import eu.etaxonomy.cdm.model.agent.Team;
38 41
import eu.etaxonomy.cdm.model.common.Annotation;
39 42
import eu.etaxonomy.cdm.model.common.AnnotationType;
40 43
import eu.etaxonomy.cdm.model.common.CdmBase;
......
42 45
import eu.etaxonomy.cdm.model.common.LanguageString;
43 46
import eu.etaxonomy.cdm.model.common.Marker;
44 47
import eu.etaxonomy.cdm.model.common.MarkerType;
48
import eu.etaxonomy.cdm.model.common.OriginalSourceType;
45 49
import eu.etaxonomy.cdm.model.common.Representation;
46 50
import eu.etaxonomy.cdm.model.common.TermType;
47 51
import eu.etaxonomy.cdm.model.common.TermVocabulary;
......
58 62
import eu.etaxonomy.cdm.model.media.ImageFile;
59 63
import eu.etaxonomy.cdm.model.media.Media;
60 64
import eu.etaxonomy.cdm.model.media.MediaRepresentation;
65
import eu.etaxonomy.cdm.model.media.Rights;
66
import eu.etaxonomy.cdm.model.media.RightsType;
61 67
import eu.etaxonomy.cdm.model.reference.Reference;
68
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
62 69
import eu.etaxonomy.cdm.model.taxon.Taxon;
63 70
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
64 71
import eu.etaxonomy.cdm.strategy.exceptions.UnknownCdmTypeException;
72
import eu.etaxonomy.cdm.strategy.parser.TimePeriodParser;
65 73

  
66 74
/**
67 75
 * @author a.mueller
......
684 692
	 * @param media
685 693
	 * @param media
686 694
	 * @param descriptionSet
695
	 * @throws URISyntaxException
687 696
	 *
688 697
	 */
689 698
	private TaxonDescription makeImage(BerlinModelImportState state, String fact, Media media, Set<TaxonDescription> descriptionSet, Taxon taxon) {
690 699
		TaxonDescription taxonDescription = null;
691
		Reference sourceRef = state.getTransactionalSourceReference();
692
		URI uri;
693
		ImageInfo imageInfo = null;
694
		try {
695
			uri = new URI(fact.trim());
696
		} catch (URISyntaxException e) {
697
			logger.warn("URISyntaxException. Image could not be imported: " + fact);
698
			return null;
699
		}
700 700
		try {
701
			if (!state.getConfig().isSalvador()){
702
			    imageInfo = ImageInfo.NewInstance(uri, 0);
703
			}
704
		} catch (IOException e) {
705
			logger.error("IOError reading image metadata." , e);
706
		} catch (HttpException e) {
707
			logger.error("HttpException reading image metadata." , e);
708
		}
709
		Integer size = null;
710
		String mimeType = imageInfo == null ? null : imageInfo.getMimeType();
711
		String suffix = imageInfo == null ? null : imageInfo.getSuffix();
712
		MediaRepresentation mediaRepresentation = MediaRepresentation.NewInstance(mimeType, suffix);
713
		media.addRepresentation(mediaRepresentation);
714
		ImageFile image = ImageFile.NewInstance(uri, size, imageInfo);
715
		mediaRepresentation.addRepresentationPart(image);
701
	        Reference sourceRef = state.getTransactionalSourceReference();
702
    		URI uri;
703
    		URI thumbUri;
704
    		ImageInfo imageInfo = null;
705
    		ImageInfo thumbImageInfo = null;
706
    		if (!state.getConfig().isSalvador()){
707
    		    String thumbs = "thumbs/";
708
    		    String uriStr = "http://media.e-taxonomy.eu/salvador/berendsohn-et-al-%s/%s.jpg";
709
    		    Integer intFact = Integer.valueOf(fact);
710
    		    String vol = "2009";
711
    		    int page = intFact + 249;
712
                if (intFact >= 263){
713
    		        vol = "2016";
714
    		    }else if (intFact >= 142){
715
    		        vol = "2012";
716
    		        page = intFact + (intFact < 255 ? 3 : 4);
717
    		    }
718
    		    Reference ref = getSalvadorReference(vol);
719
    		    media.addSource(OriginalSourceType.PrimaryMediaSource, "Fig. " + fact, null, ref, String.valueOf(page));
720
    		    media.setArtist(getSalvadorArtist());
721
    		    media.addRights(getSalvadorCopyright(vol));
722
    		    uriStr = String.format(uriStr, vol, fact);
723
    		    String thumbUriStr = String.format(uriStr, vol, thumbs + fact);
724
    		    uri = new URI(uriStr);
725
    		    thumbUri = new URI(thumbUriStr);
726
    		    if (!state.getConfig().isSalvador()){
727
                    try {
728
                        imageInfo = ImageInfo.NewInstance(uri, 0);
729
                    } catch (IOException | HttpException e) {
730
                        logger.error("Error when reading image meta: " + e);
731
                    }
732
                    try {
733
                        thumbImageInfo = ImageInfo.NewInstance(thumbUri, 0);
734
                    } catch (IOException | HttpException e) {
735
                        logger.error("Error when reading image meta: " + e);
736
                    }
737
                }
738
    		}else{
739
    		    uri = new URI(fact.trim());
740
    		    thumbUri = null;
741
    		}
716 742

  
717
		taxonDescription = taxon.getOrCreateImageGallery(sourceRef == null ? null :sourceRef.getTitleCache());
743
    		Integer size = null;
718 744

  
745
    		makeMediaRepresentation(media, uri, imageInfo, size);
746
    		if (thumbUri != null){
747
                makeMediaRepresentation(media, thumbUri, thumbImageInfo, size);
748
    		}
749

  
750
    		taxonDescription = taxon.getOrCreateImageGallery(sourceRef == null ? null :sourceRef.getTitleCache());
751
		} catch (URISyntaxException e) {
752
            logger.warn("URISyntaxException. Image could not be imported: " + fact);
753
            return null;
754
        }
719 755
		return taxonDescription;
720 756
	}
721 757

  
758
    private Rights getSalvadorCopyright(String vol) {
759
        String text;
760
        if ("2009".equals(vol)){
761
            text = "(c) Botanic Garden and Botanical Museum Berlin-Dahlem & Asociación Jardín Botánico La Laguna. Berlin, Antiguo Cuscatlán 2009.";
762
        }else if ("2012".equals(vol)){
763
            text = "(c) Botanic Garden and Botanical Museum Berlin-Dahlem & Asociación Jardín Botánico La Laguna. Berlin, Antiguo Cuscatlán 2012.";
764
        }else if ("2016".equals(vol)){
765
            text = "(c) Jardín Botánico y Museo Botánico Berlin-Dahlem & Asociación Jardín Botánico La Laguna. Berlin, Antiguo Cuscatlán 2016.";
766
        }else{
767
            throw new RuntimeException("Volume not recognized: " + vol);
768
        }
769
        Rights result = Rights.NewInstance(text, Language.SPANISH_CASTILIAN(), RightsType.COPYRIGHT());
770
        return result;
771
    }
772

  
773

  
774
    private Integer salvadorArtistId;
775
    private AgentBase<?> getSalvadorArtist() {
776
        if (salvadorArtistId == null){
777
            Person person = Person.NewInstance();
778
            person.setFirstname("José Gerver");
779
            person.setLastname("Molina");
780
            salvadorArtistId = getAgentService().save(person).getId();
781
            return person;
782
        }else{
783
            return getAgentService().find(salvadorArtistId);
784
        }
785
    }
786

  
787
    private Integer salvadorRef1Id;
788
    private Integer salvadorRef2Id;
789
    private Integer salvadorRef3Id;
790

  
791
    private Reference getSalvadorReference(String vol){
792
        if (salvadorRef1Id == null){
793
            makeSalvadorReferences();
794
        }
795
        if ("2009".equals(vol)){
796
            return getReferenceService().find(salvadorRef1Id);
797
        }else if ("2012".equals(vol)){
798
            return getReferenceService().find(salvadorRef2Id);
799
        }else if ("2016".equals(vol)){
800
            return getReferenceService().find(salvadorRef3Id);
801
        }else{
802
            throw new RuntimeException("Volume not recognized: " + vol);
803
        }
804

  
805
    }
806

  
807
    private void makeSalvadorReferences() {
808
        Person walter = Person.NewTitledInstance("Berendsohn, W. G.");
809
        walter.setFirstname("Walter G.");
810
        walter.setLastname("Berendsohn");
811
        Person katja = Person.NewTitledInstance("Gruber, Anne Kathrina");
812
        katja.setFirstname("Anne Katharina");
813
        katja.setLastname("Gruber");
814
        Person monte = Person.NewTitledInstance("Monterrosa Salomón, J.");
815
        Person olmedo = Person.NewTitledInstance("Olmedo Galán, P.");
816
        Person rodriguez = Person.NewTitledInstance("Rodríguez Delcid, D");
817

  
818
        Team team1 = Team.NewInstance();
819
        team1.addTeamMember(walter);
820
        team1.addTeamMember(katja);
821
        team1.addTeamMember(monte);
822

  
823
        Team team2 = Team.NewInstance();
824
        team2.addTeamMember(walter);
825
        team2.addTeamMember(katja);
826
        team2.addTeamMember(rodriguez);
827
        team2.addTeamMember(olmedo);
828

  
829
        Reference vol1 = ReferenceFactory.newBook();
830
        Reference vol2 = ReferenceFactory.newBook();
831
        Reference vol3 = ReferenceFactory.newBook();
832

  
833
        vol1.setAuthorship(team1);
834
        vol2.setAuthorship(team1);
835
        vol3.setAuthorship(team2);
836

  
837
        vol1.setDatePublished(TimePeriodParser.parseString("2009"));
838
        vol2.setDatePublished(TimePeriodParser.parseString("2012"));
839
        vol3.setDatePublished(TimePeriodParser.parseString("2016"));
840

  
841
        Reference englera = ReferenceFactory.newPrintSeries("Englera");
842
        vol1.setInSeries(englera);
843
        vol2.setInSeries(englera);
844
        vol3.setInSeries(englera);
845

  
846
        vol1.setTitle("Nova Silva Cuscatlanica, Árboles nativos e introducidos de El Salvador - Parte 1: Angiospermae - Familias A-L");
847
        vol2.setTitle("Nova Silva Cuscatlanica, Árboles nativos e introducidos de El Salvador - Parte 2: Angiospermae - Familias M-P y Pteridophyta");
848
        vol3.setTitle("Nova Silva Cuscatlanica, Árboles nativos e introducidos de El Salvador - Parte 3: Angiospermae - Familias R-Z y Gymnospermae");
849

  
850
        vol1.setVolume("29(1)");
851
        vol2.setVolume("29(2)");
852
        vol3.setVolume("29(3)");
853

  
854
        vol1.setPages("1-438");
855
        vol2.setVolume("1-300");
856
        vol3.setVolume("1-356");
857

  
858
        salvadorRef1Id = getReferenceService().save(vol1).getId();
859
        salvadorRef2Id = getReferenceService().find(getReferenceService().saveOrUpdate(vol2)).getId();
860
        salvadorRef3Id = getReferenceService().find(getReferenceService().saveOrUpdate(vol3)).getId();
861
        return;
862
    }
863

  
864

  
865
    /**
866
     * @param media
867
     * @param uri
868
     * @param imageInfo
869
     * @param size
870
     */
871
    private void makeMediaRepresentation(Media media, URI uri, ImageInfo imageInfo, Integer size) {
872
        String mimeType = imageInfo == null ? null : imageInfo.getMimeType();
873
        String suffix = imageInfo == null ? null : imageInfo.getSuffix();
874
        MediaRepresentation mediaRepresentation = MediaRepresentation.NewInstance(mimeType, suffix);
875
        media.addRepresentation(mediaRepresentation);
876
        ImageFile image = ImageFile.NewInstance(uri, size, imageInfo);
877
        mediaRepresentation.addRepresentationPart(image);
878
    }
879

  
722 880
	private TaxonBase<?> getTaxon(Map<String, TaxonBase> taxonMap, Integer taxonIdObj, Number taxonId){
723 881
		if (taxonIdObj != null){
724 882
			return taxonMap.get(String.valueOf(taxonId));
app-import/src/main/java/eu/etaxonomy/cdm/io/berlinModel/in/BerlinModelTaxonRelationImport.java
60 60
 */
61 61
@Component
62 62
public class BerlinModelTaxonRelationImport  extends BerlinModelImportBase  {
63
	private static final Logger logger = Logger.getLogger(BerlinModelTaxonRelationImport.class);
63
    private static final long serialVersionUID = -7234926279240842557L;
64

  
65
    private static final Logger logger = Logger.getLogger(BerlinModelTaxonRelationImport.class);
64 66

  
65 67
	public static final String TREE_NAMESPACE = "PTRefFk";
66 68

  

Also available in: Unified diff