Project

General

Profile

Revision daf61d74

IDdaf61d749eefef751c3be520093c9193442f26cf
Parent eba2d1f7
Child ad8c4e9b

Added by Andreas Müller about 2 years ago

ref #8689 fix issus in Cdm2Cdm import and add "removeImportSource" configuration

View differences:

cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/cdm2cdm/Cdm2CdmImportBase.java
85 85
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
86 86
import eu.etaxonomy.cdm.model.permission.User;
87 87
import eu.etaxonomy.cdm.model.reference.OriginalSourceBase;
88
import eu.etaxonomy.cdm.model.reference.OriginalSourceType;
88 89
import eu.etaxonomy.cdm.model.reference.Reference;
89 90
import eu.etaxonomy.cdm.model.taxon.Classification;
90 91
import eu.etaxonomy.cdm.model.taxon.Synonym;
......
187 188
        }
188 189
    }
189 190

  
190
    /**
191
     * @param class1
192
     * @return
193
     */
194 191
    private Set<UUID> loadExistingUuids(Class<? extends CdmBase> clazz) {
195 192
        List<UUID> list = getCommonService().listUuid(clazz);
196 193
        Set<UUID> result = new HashSet<>(list);
......
687 684
            result.setGrantedAuthorities(new HashSet<>());
688 685
            setInvisible(result, "groups", new HashSet<>());
689 686
        }
687
        result.setPerson(detache(user.getPerson()));
690 688
        return result;
691 689
    }
692 690

  
......
701 699
    protected Rights handlePersistedRights(Rights rights) throws IllegalAccessException, InvocationTargetException, NoSuchFieldException, SecurityException, IllegalArgumentException, NoSuchMethodException {
702 700
        Rights result = handlePersisted((LanguageStringBase)rights);
703 701
        result.setAgent(detache(rights.getAgent()));
704
        result.setType(rights.getType());
702
        result.setType(detache(rights.getType()));
705 703
        //complete
706 704
        return result;
707 705
    }
......
759 757
    protected <T extends SourcedEntityBase> T  handlePersisted(SourcedEntityBase sourcedEntity) throws IllegalAccessException, InvocationTargetException, NoSuchFieldException, SecurityException, IllegalArgumentException, NoSuchMethodException {
760 758
        int originalId = sourcedEntity.getId();
761 759
        T result = handlePersisted((AnnotatableEntity)sourcedEntity);
762
        if (!result.isPersited() && getState().getConfig().isAddSources()){
763
            Reference sourceRef = getSourceReference(getState());
764
//            OriginalSourceBase<?> newSource = result.addImportSource(String.valueOf(originalId), sourcedEntity.getClass().getSimpleName(),
765
//                    sourceRef, null);
766
//            getCommonService().save(newSource);
767
        }
768 760
        //complete
769 761
        handleCollection(result, SourcedEntityBase.class, "sources", OriginalSourceBase.class);
762
        if (!result.isPersited()){
763
            if(getState().getConfig().isRemoveImportSources()){
764
                filterImportSources(result.getSources());
765
            }
766
            if (getState().getConfig().isAddSources()){
767
                Reference sourceRef = getSourceReference(getState());
768
                OriginalSourceBase<?> newSource = result.addImportSource(String.valueOf(originalId), sourcedEntity.getClass().getSimpleName(),
769
                        sourceRef, null);
770
                getCommonService().save(newSource);
771
                addExistingObject(newSource);
772
            }
773
        }
770 774
        return result;
771 775
    }
772 776

  
777
    /**
778
     * @param sources
779
     */
780
    private void filterImportSources(Set<OriginalSourceBase<?>> sources) {
781
        Set<OriginalSourceBase<?>> toDelete = new HashSet<>();
782
        for (OriginalSourceBase<?> osb: sources){
783
            if (osb.getType() == OriginalSourceType.Import){
784
                toDelete.add(osb);
785
            }
786
        }
787
        for (OriginalSourceBase<?> osb: toDelete){
788
            sources.remove(osb);
789
        }
790
    }
791

  
773 792
    protected <T extends IdentifiableEntity> T  handlePersisted(IdentifiableEntity identifiableEntity) throws IllegalAccessException, InvocationTargetException, NoSuchFieldException, SecurityException, IllegalArgumentException, NoSuchMethodException {
774 793
        T result = handlePersisted((SourcedEntityBase)identifiableEntity);
775 794
        //complete
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/cdm2cdm/Cdm2CdmImportConfigurator.java
35 35
    private boolean doTaxa = true;
36 36
    private boolean doDescriptions = true;
37 37
    private boolean addSources = true;
38
    private boolean removeImportSources = false;
38 39

  
39 40
//***************************** NewInstance ************************/
40 41

  
......
115 116
    public void setAddSources(boolean addSources) {
116 117
        this.addSources = addSources;
117 118
    }
119

  
120
    public boolean isRemoveImportSources() {
121
        return removeImportSources;
122
    }
123
    public void setRemoveImportSources(boolean removeImportSources) {
124
        this.removeImportSources = removeImportSources;
125
    }
118 126
}

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)