Project

General

Profile

« Previous | Next » 

Revision fe474060

Added by Katja Luther over 5 years ago

smaller changes in abcd import

View differences:

cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/specimen/abcd206/in/Abcd206Import.java
270 270
                state.setDescriptionRefs(new ArrayList<>());
271 271
                state.setDerivedUnitSources(new ArrayList<>());
272 272
                for (int i = 0; i < unitsList.getLength(); i++) {
273
                    commitTransaction(state.getTx());
274
                    state.setTx(startTransaction());
275

  
273 276
                    if (state.getConfig().getProgressMonitor().isCanceled()) {
274 277
                        break;
275 278
                    }
......
286 289
                    this.handleSingleUnit(state, item, true);
287 290

  
288 291
                }
292
                commitTransaction(state.getTx());
293
                state.setTx(startTransaction());
289 294
                if (state.getConfig().isDeduplicateReferences()) {
290 295
                    getReferenceService().deduplicate(Reference.class, null, null);
291 296
                }
......
395 400
                        }
396 401
                        // parent-child relation:
397 402
                        if (associationType.contains("individual") || associationType.contains("culture")
398
                                || associationType.contains("sample")) {
403
                                || associationType.contains("sample") ||  associationType.contains("isolated")) {
399 404
                            DerivationEvent updatedDerivationEvent = DerivationEvent.NewSimpleInstance(currentUnit,
400 405
                                    associatedUnit, DerivationEventType.ACCESSIONING());
401 406

  
......
592 597
                for (String multimediaObject : state.getDataHolder().getMultimediaObjects().keySet()) {
593 598
                    Media media;
594 599
                    try {
595
                        media = getImageMedia(multimediaObject, READ_MEDIA_DATA);
596
                        Map<String, String> attributes = state.getDataHolder().getMultimediaObjects()
597
                                .get(multimediaObject);
598
                        if (attributes.containsKey("Context")) {
599
                            LanguageString description = LanguageString.NewInstance(attributes.get("Context"),
600
                                    Language.ENGLISH());
601
                            media.addDescription(description);
602
                        }
603
                        if (attributes.containsKey("Comment")) {
604
                            LanguageString description = LanguageString.NewInstance(attributes.get("Comment"),
605
                                    Language.ENGLISH());
606
                            media.addDescription(description);
607
                        }
608
                        if (attributes.containsKey("Creators")) {
609
                            String creators = attributes.get("Creators");
610
                            Person artist;
611
                            Team artistTeam;
612
                            String[] artists;
613
                            if (creators != null) {
614
                                if (creators.contains("&")) {
615
                                    artists = creators.split("&");
616
                                    artistTeam = new Team();
617
                                    for (String creator : artists) {
618
                                        artist = Person.NewTitledInstance(creator);
619
                                        artistTeam.addTeamMember(artist);
620
                                    }
621
                                    media.setArtist(artistTeam);
622
                                } else {
623

  
624
                                    artist = Person.NewTitledInstance(creators);
625
                                    media.setArtist(artist);
626
                                }
627
                            }
628

  
629
                        }
630
                        if (attributes.containsKey("CreateDate")) {
631
                            String createDate = attributes.get("CreateDate");
632

  
633
                            if (createDate != null) {
634

  
635
                               media.setMediaCreated(TimePeriodParser.parseString(createDate));
636
                            }
637

  
638
                        }
639

  
640

  
641
                        if (attributes.containsKey("License")) {
642
                            String licence = attributes.get("License");
643

  
644
                            if (licence != null) {
645
                               Rights right = Rights.NewInstance(licence, Language.ENGLISH(), RightsType.LICENSE());
646
                               media.addRights(right);
647
                            }
648

  
649
                        }
600
                        media = extractMedia(state, multimediaObject);
650 601

  
651 602

  
652 603

  
......
679 630
                for (String multimediaObject : state.getDataHolder().getGatheringMultimediaObjects().keySet()) {
680 631
                    Media media;
681 632
                    try {
682
                        media = getImageMedia(multimediaObject, READ_MEDIA_DATA);
683
                        Map<String, String> attributes = state.getDataHolder().getGatheringMultimediaObjects()
684
                                .get(multimediaObject);
685
                        if (attributes.containsKey("Context")) {
686
                            LanguageString description = LanguageString.NewInstance(attributes.get("Context"),
687
                                    Language.ENGLISH());
688
                            media.addDescription(description);
689
                        }
690
                        if (attributes.containsKey("Comment")) {
691
                            LanguageString description = LanguageString.NewInstance(attributes.get("Comment"),
692
                                    Language.ENGLISH());
693
                            media.addDescription(description);
694
                        }
695
                        if (attributes.containsKey("Creators")) {
696
                            String creators = attributes.get("Creators");
697
                            Person artist;
698
                            Team artistTeam;
699
                            String[] artists;
700
                            if (creators != null) {
701
                                if (creators.contains("&")) {
702
                                    artists = creators.split("&");
703
                                    artistTeam = new Team();
704
                                    for (String creator : artists) {
705
                                        artist = Person.NewTitledInstance(creator);
706
                                        artistTeam.addTeamMember(artist);
707
                                    }
708
                                    media.setArtist(artistTeam);
709
                                } else {
710

  
711
                                    artist = Person.NewTitledInstance(creators);
712
                                    media.setArtist(artist);
713
                                }
714
                            }
715

  
716
                        }
717

  
633
                        media = extractMedia(state, multimediaObject);
718 634
                        derivedUnitFacade.addFieldObjectMedia(media);
719 635

  
720 636
                    } catch (MalformedURLException e) {
......
878 794
            if (derivedUnitFacade.getType() != null
879 795
                    && (derivedUnitFacade.getType().equals(SpecimenOrObservationType.LivingSpecimen)
880 796
                            || derivedUnitFacade.getType().equals(SpecimenOrObservationType.TissueSample)
881
                            || derivedUnitFacade.getType().equals(SpecimenOrObservationType.OtherSpecimen))
797
                            || derivedUnitFacade.getType().equals(SpecimenOrObservationType.OtherSpecimen)
798
                            || derivedUnitFacade.getType().equals(SpecimenOrObservationType.MaterialSample))
882 799
                    && state.getConfig().isGetSiblings()) {
883 800
                getSiblings(state, item, derivedUnitFacade);
884 801
            }
885 802

  
886 803
        } catch (Exception e) {
887
            String message = "Error when reading record!";
804
            String message = "Error when reading record! " + itemObject.toString();
888 805
            logger.warn(message);
889 806
            state.getReport().addException(message, e);
890 807
            e.printStackTrace();
......
894 811
        return;
895 812
    }
896 813

  
814
    /**
815
     * @param state
816
     * @param multimediaObject
817
     * @return
818
     * @throws MalformedURLException
819
     */
820
    private Media extractMedia(Abcd206ImportState state, String multimediaObject) throws MalformedURLException {
821
        Media media;
822
        media = getImageMedia(multimediaObject, READ_MEDIA_DATA);
823
        Map<String, String> attributes = state.getDataHolder().getMultimediaObjects()
824
                .get(multimediaObject);
825
        if (attributes.containsKey("Context")) {
826
            LanguageString description = LanguageString.NewInstance(attributes.get("Context"),
827
                    Language.ENGLISH());
828
            media.addDescription(description);
829
        }
830
        if (attributes.containsKey("Comment")) {
831
            LanguageString description = LanguageString.NewInstance(attributes.get("Comment"),
832
                    Language.ENGLISH());
833
            media.addDescription(description);
834
        }
835
        if (attributes.containsKey("Creators")) {
836
            String creators = attributes.get("Creators");
837
            Person artist;
838
            Team artistTeam;
839
            String[] artists;
840
            if (creators != null) {
841
                if (creators.contains("&")) {
842
                    artists = creators.split("&");
843
                    artistTeam = new Team();
844
                    for (String creator : artists) {
845
                        artist = Person.NewTitledInstance(creator);
846
                        artistTeam.addTeamMember(artist);
847
                    }
848
                    media.setArtist(artistTeam);
849
                } else {
850

  
851
                    artist = Person.NewTitledInstance(creators);
852
                    media.setArtist(artist);
853
                }
854
            }
855

  
856
        }
857
        if (attributes.containsKey("CreateDate")) {
858
            String createDate = attributes.get("CreateDate");
859

  
860
            if (createDate != null) {
861

  
862
               media.setMediaCreated(TimePeriodParser.parseString(createDate));
863
            }
864

  
865
        }
866

  
867

  
868
        if (attributes.containsKey("License")) {
869
            String licence = attributes.get("License");
870

  
871
            if (licence != null) {
872
               Rights right = Rights.NewInstance(licence, Language.ENGLISH(), RightsType.LICENSE());
873
               media.addRights(right);
874
            }
875

  
876
        }
877
        return media;
878
    }
879

  
897 880
    @Override
898 881
    protected void importAssociatedUnits(Abcd206ImportState state, Object itemObject,
899 882
            DerivedUnitFacade derivedUnitFacade) {
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/specimen/abcd206/in/Abcd206ImportConfigurator.java
212 212
      result.append(":");
213 213
      result.append(this.isMoveNewTaxaToDefaultClassification());
214 214
      result.append(";");
215
      result.append("getSiblings");
216
      result.append(":");
217
      result.append(this.isGetSiblings());
218
      result.append(";");
219
      result.append("removeCountryFromLocalityText");
220
      result.append(":");
221
      result.append(this.isRemoveCountryFromLocalityText());
222
      result.append(";");
215 223

  
216 224
      result.append("mapUnitIdToCatalogNumber");
217 225
      result.append(":");
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/specimen/abcd206/in/Abcd206XMLFieldGetter.java
96 96
        }
97 97
        NodeList results, preps, ntds, ntd;
98 98
        String prep;
99
        String item;
99 100
        results = result.getChildNodes();
100 101

  
101 102
        try {
......
110 111
                            for (int m = 0; m < ntds.getLength(); m++) {
111 112
                                if (ntds.item(m).getNodeName().equals(prefix+ "preparation")) {
112 113
                                    ntd = ntds.item(m).getChildNodes();
114
                                    prep = "";
115

  
113 116
                                    for (int n = 0; n < ntd.getLength(); n++) {
117

  
118
                                        //Fix me: now only the type or the agent is imported because it is overwritten
114 119
                                        if (ntd.item(n).getNodeName().equals(prefix + "preparationType"))
115 120
                                        {
116
                                            prep = ntd.item(n).getTextContent();
121
                                            item = ntd.item(n).getTextContent().trim();
122
                                            prep += " Preparation Type: "+item +System.lineSeparator();
123

  
117 124
                                            if(DEBUG) {
118 125
                                                logger.info("ADD "+prep);
119 126
                                            }
......
125 132
                                        }
126 133
                                        if (ntd.item(n).getNodeName().equals(prefix + "preparationAgent"))
127 134
                                        {
128
                                            prep = ntd.item(n).getTextContent();
135
                                            item = ntd.item(n).getTextContent().trim();
136
                                            prep += " Preparation Agent: "+item;
129 137
                                            if(DEBUG) {
130 138
                                                logger.info("ADD "+prep);
131 139
                                            }
......
977 985
                            }
978 986
                        }
979 987
                    }else{
980
                        System.err.println(iprNodes.item(l).getNodeName());
988
                        //System.err.println(iprNodes.item(l).getNodeName());
981 989
                    }
982 990

  
983 991
                }
984 992

  
985 993
            } else{
986
                System.err.println(multimedia.item(k).getNodeName());
994
               // System.err.println(multimedia.item(k).getNodeName());
987 995
            }
988 996

  
989 997
        }

Also available in: Unified diff