Project

General

Profile

Revision 00a62062

ID00a620627c38a643624f0622e146254b4b128229
Parent 4f8e5d8d
Child d98c659b, ee7d980d

Added by Patrick Plitzner about 7 years ago

  • removed @Cascade for country in GatheringEvent because DefinedTerms should not be cascaded
    • added new service method to occurence service to find all CDM entities that are not saved via cascading
    • added tests for new method
    • added test for concurrent session saving of terms
    • made use of method for specimen import via DataImportView

View differences:

eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/dataimport/DataImportView.java
9 9
*/
10 10
package eu.etaxonomy.taxeditor.editor.view.dataimport;
11 11

  
12
import java.util.ArrayList;
12 13
import java.util.Collection;
13 14

  
14 15
import org.apache.log4j.Logger;
......
48 49

  
49 50
    protected final Logger logger = Logger.getLogger(DataImportView.class);
50 51

  
51
    protected Collection<T> results;
52
    protected Collection<T> results = new ArrayList<T>();
52 53

  
53 54
    protected OccurenceQuery query;
54 55

  
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/dataimport/SaveImportedSpecimenAction.java
8 8
import org.eclipse.ui.IWorkbenchWindow;
9 9
import org.eclipse.ui.PlatformUI;
10 10

  
11
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
11 12
import eu.etaxonomy.cdm.api.service.IOccurrenceService;
13
import eu.etaxonomy.cdm.api.service.ITermService;
12 14
import eu.etaxonomy.cdm.ext.occurrence.gbif.GbifResponse;
15
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
16
import eu.etaxonomy.cdm.model.common.ICdmBase;
17
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
13 18
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
14 19
import eu.etaxonomy.taxeditor.store.CdmStore;
15 20

  
......
35 40
                        data = ((GbifResponse) item.getData()).getDerivedUnitFacade().innerFieldUnit();
36 41
                    }
37 42
                    if(data instanceof SpecimenOrObservationBase){
38
                        dataImportView.getConversationHolder().bind();
39
                        CdmStore.getService(IOccurrenceService.class).saveOrUpdate((SpecimenOrObservationBase<?>) data);
43
                        ConversationHolder conversation = dataImportView.getConversationHolder();
44
                        SpecimenOrObservationBase<?> specimen = (SpecimenOrObservationBase<?>) data;
45
                        conversation.bind();
46
                        IOccurrenceService occurrenceService = CdmStore.getService(IOccurrenceService.class);
47
                        for(ICdmBase cdmEntity:occurrenceService.getNonCascadedAssociatedElements(specimen)){
48
                            if(cdmEntity instanceof DefinedTermBase){
49
                                persistTerm((DefinedTermBase<?>) cdmEntity, CdmStore.getService(ITermService.class), conversation);
50
                            }
51
                            else if(cdmEntity instanceof TaxonNameBase){
52
                                //user interaction
53
                            }
54
                        }
55
                        occurrenceService.saveOrUpdate(specimen);
40 56
                        dataImportView.getConversationHolder().commit(true);
41 57
                    }
42 58
                }
......
44 60
        }
45 61
    }
46 62

  
63
    private void persistTerm(DefinedTermBase<?> term, ITermService termService, ConversationHolder conversation){
64
        if(term!=null){
65
            //if the term does not exist in the DB save it
66
            if(termService.find(term.getUuid())==null){
67
                termService.saveOrUpdate(term);
68
            }
69
        }
70
    }
71

  
72

  
47 73
    /* (non-Javadoc)
48 74
     * @see org.eclipse.jface.action.Action#getText()
49 75
     */
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/dataimport/transientServices/TransientOccurenceService.java
36 36
import eu.etaxonomy.cdm.api.service.util.TaxonRelationshipEdge;
37 37
import eu.etaxonomy.cdm.common.monitor.IProgressMonitor;
38 38
import eu.etaxonomy.cdm.model.common.Annotation;
39
import eu.etaxonomy.cdm.model.common.ICdmBase;
39 40
import eu.etaxonomy.cdm.model.common.ISourceable;
40 41
import eu.etaxonomy.cdm.model.common.IdentifiableSource;
41 42
import eu.etaxonomy.cdm.model.common.LSID;
......
914 915
		return defaultService.findWithoutFlush(uuid);
915 916
	}
916 917

  
918
    /* (non-Javadoc)
919
     * @see eu.etaxonomy.cdm.api.service.IOccurrenceService#getNonCascadedAssociatedElements(eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase, eu.etaxonomy.cdm.api.conversation.ConversationHolder)
920
     */
921
    @Override
922
    public Collection<ICdmBase> getNonCascadedAssociatedElements(SpecimenOrObservationBase<?> specimen) {
923
        return defaultService.getNonCascadedAssociatedElements(specimen);
924
    }
925

  
917 926
}

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)