Project

General

Profile

Revision 651101eb

ID651101eb58e666ffc13a828447aa5604b95cfae8
Parent 7d9b356f
Child cd602b47

Added by Andreas Müller over 3 years ago

cleanup

View differences:

cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/specimen/SpecimenImportBase.java
1004 1004
	     * @param state : the ABCD import state
1005 1005
	     */
1006 1006
	    protected void addTaxonNode(Taxon taxon, STATE state, boolean preferredFlag) {
1007
	        SpecimenImportConfiguratorBase config = state.getConfig();
1007
	        SpecimenImportConfiguratorBase<?,?,?> config = state.getConfig();
1008 1008
	        logger.info("link taxon to a taxonNode "+taxon.getTitleCache());
1009 1009
	        //only add nodes if not already existing in current classification or default classification
1010 1010

  
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/specimen/abcd206/in/Abcd206Import.java
64 64
import eu.etaxonomy.cdm.model.reference.Reference;
65 65
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
66 66
import eu.etaxonomy.cdm.model.taxon.Classification;
67
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
68 67

  
69 68
/**
70 69
 * @author p.kelbert
......
103 102
        MapWrapper<TeamOrPersonBase<?>> authorStore = (MapWrapper<TeamOrPersonBase<?>>)stores.get(ICdmIO.TEAM_STORE);
104 103
        state.setPersonStore(authorStore);
105 104
        MapWrapper<Reference> referenceStore = (MapWrapper<Reference>)stores.get(ICdmIO.REFERENCE_STORE);
106
        MapWrapper<TaxonBase> taxonBaseStore = (MapWrapper<TaxonBase>)stores.get(ICdmIO.TAXON_STORE);
107 105
        URI sourceUri = config.getSourceUri();
108 106
        try{
109 107
            state.setTx(startTransaction());
......
254 252
                state.setAssociationRefs(new ArrayList<OriginalSourceBase<?>>());
255 253
                state.setDescriptionRefs(new ArrayList<OriginalSourceBase<?>>());
256 254
                state.setDerivedUnitSources(new ArrayList<OriginalSourceBase<?>>());
257
                int length = unitsList.getLength();
258 255
                for (int i = 0; i < unitsList.getLength(); i++) {
259 256
                    if(state.getConfig().getProgressMonitor().isCanceled()){
260 257
                        break;
......
297 294
     * @param item
298 295
     */
299 296
    private void getSiblings(Abcd206ImportState state, Object item, DerivedUnitFacade facade) {
300
        NodeList unitAssociationList = null;
301

  
302 297
        String unitId = facade.getCatalogNumber();
303 298

  
304
            UnitAssociationParser unitParser = new UnitAssociationParser(state.getPrefix(), state.getReport(), state.getCdmRepository());
305
            UnitAssociationWrapper unitAssociationWrapper = null;
306
            for (URI accessPoint: state.getActualAccesPoint()){
307
                unitAssociationWrapper = unitParser.parseSiblings(unitId, accessPoint);
308
                if (unitAssociationWrapper.getAssociatedUnits() != null){
309
                    break;
310
                }
299
        UnitAssociationParser unitParser = new UnitAssociationParser(state.getPrefix(), state.getReport(), state.getCdmRepository());
300
        UnitAssociationWrapper unitAssociationWrapper = null;
301
        for (URI accessPoint: state.getActualAccesPoint()){
302
            unitAssociationWrapper = unitParser.parseSiblings(unitId, accessPoint);
303
            if (unitAssociationWrapper.getAssociatedUnits() != null){
304
                break;
311 305
            }
306
        }
312 307

  
313
           DerivedUnit currentUnit = state.getDerivedUnitBase();
314
         //  DerivationEvent currentDerivedFrom = currentUnit.getDerivedFrom();
315
           FieldUnit currentFieldUnit = facade.getFieldUnit(false);
316
            if(unitAssociationWrapper!=null){
317
                NodeList associatedUnits = unitAssociationWrapper.getAssociatedUnits();
318
                if(associatedUnits!=null){
319
                    for(int m=0;m<associatedUnits.getLength();m++){
320
                        if(associatedUnits.item(m) instanceof Element){
321
                            state.reset();
322
                            String associationType = AbcdParseUtility.parseFirstTextContent(((Element) associatedUnits.item(m)).getElementsByTagName(state.getPrefix()+"AssociationType"));
323

  
324
                            Abcd206ImportParser.setUnitPropertiesXML((Element) associatedUnits.item(m), new Abcd206XMLFieldGetter(state.getDataHolder(), unitAssociationWrapper.getPrefix()), state);
325
                           // logger.debug("derived unit: " + state.getDerivedUnitBase().toString() + " associated unit: " +state.getDataHolder().getKindOfUnit() + ", " + state.getDataHolder().accessionNumber + ", " + state.getDataHolder().getRecordBasis() + ", " + state.getDataHolder().getUnitID());
326

  
327
                            handleSingleUnit(state, associatedUnits.item(m), false);
328

  
329
                            DerivedUnit associatedUnit = state.getDerivedUnitBase();
330
                            FieldUnit associatedFieldUnit = null;
331
                            java.util.Collection<FieldUnit> associatedFieldUnits = state.getCdmRepository().getOccurrenceService().getFieldUnits(associatedUnit.getUuid());
332
                            //ignore field unit if associated unit has more than one
333
                            if(associatedFieldUnits.size()>1){
334
                                state.getReport().addInfoMessage(String.format("%s has more than one field unit.", associatedUnit));
335
                            }
336
                            else if(associatedFieldUnits.size()==1){
337
                                associatedFieldUnit = associatedFieldUnits.iterator().next();
338
                            }
339
                            //parent-child relation:
340
                            if(associationType.contains("individual") || associationType.contains("culture") || associationType.contains("sample")){
341
                                DerivationEvent updatedDerivationEvent = DerivationEvent.NewSimpleInstance(currentUnit, associatedUnit, DerivationEventType.ACCESSIONING());
342
                                if(associatedFieldUnit!=null && associatedFieldUnit != currentFieldUnit){
343
                                    associatedFieldUnit.removeDerivationEvent(updatedDerivationEvent);
344
                                    state.getCdmRepository().getOccurrenceService().delete(associatedFieldUnit);
345
                                }
346
                                state.getReport().addDerivate(associatedUnit, currentUnit, state.getConfig());
308
       DerivedUnit currentUnit = state.getDerivedUnitBase();
309
     //  DerivationEvent currentDerivedFrom = currentUnit.getDerivedFrom();
310
       FieldUnit currentFieldUnit = facade.getFieldUnit(false);
311
        if(unitAssociationWrapper!=null){
312
            NodeList associatedUnits = unitAssociationWrapper.getAssociatedUnits();
313
            if(associatedUnits!=null){
314
                for(int m=0;m<associatedUnits.getLength();m++){
315
                    if(associatedUnits.item(m) instanceof Element){
316
                        state.reset();
317
                        String associationType = AbcdParseUtility.parseFirstTextContent(((Element) associatedUnits.item(m)).getElementsByTagName(state.getPrefix()+"AssociationType"));
318

  
319
                        Abcd206ImportParser.setUnitPropertiesXML((Element) associatedUnits.item(m), new Abcd206XMLFieldGetter(state.getDataHolder(), unitAssociationWrapper.getPrefix()), state);
320
                       // logger.debug("derived unit: " + state.getDerivedUnitBase().toString() + " associated unit: " +state.getDataHolder().getKindOfUnit() + ", " + state.getDataHolder().accessionNumber + ", " + state.getDataHolder().getRecordBasis() + ", " + state.getDataHolder().getUnitID());
321

  
322
                        handleSingleUnit(state, associatedUnits.item(m), false);
323

  
324
                        DerivedUnit associatedUnit = state.getDerivedUnitBase();
325
                        FieldUnit associatedFieldUnit = null;
326
                        java.util.Collection<FieldUnit> associatedFieldUnits = state.getCdmRepository().getOccurrenceService().getFieldUnits(associatedUnit.getUuid());
327
                        //ignore field unit if associated unit has more than one
328
                        if(associatedFieldUnits.size()>1){
329
                            state.getReport().addInfoMessage(String.format("%s has more than one field unit.", associatedUnit));
330
                        }
331
                        else if(associatedFieldUnits.size()==1){
332
                            associatedFieldUnit = associatedFieldUnits.iterator().next();
333
                        }
334
                        //parent-child relation:
335
                        if(associationType.contains("individual") || associationType.contains("culture") || associationType.contains("sample")){
336
                            DerivationEvent updatedDerivationEvent = DerivationEvent.NewSimpleInstance(currentUnit, associatedUnit, DerivationEventType.ACCESSIONING());
337
                            if(associatedFieldUnit!=null && associatedFieldUnit != currentFieldUnit){
338
                                associatedFieldUnit.removeDerivationEvent(updatedDerivationEvent);
339
                                state.getCdmRepository().getOccurrenceService().delete(associatedFieldUnit);
347 340
                            }
348
                            save(associatedUnit, state);
341
                            state.getReport().addDerivate(associatedUnit, currentUnit, state.getConfig());
342
                        }
343
                        save(associatedUnit, state);
349 344

  
350 345
                    }
351 346
                }
352 347
            }
353 348
        }
354
            state.reset();
355
            state.setDerivedUnitBase(currentUnit);
349
        state.reset();
350
        state.setDerivedUnitBase(currentUnit);
356 351

  
357 352
    }
358 353

  
cdmlib-io/src/test/java/eu/etaxonomy/cdm/io/specimen/abcd206/in/AbcdGgbnImportTest.java
123 123
         */
124 124
        List<TaxonNode> nodes = taxonNodeService.list(TaxonNode.class, 100, 0, null, null);
125 125
        // TODO: this needs to be fixed, the sortindex should never be -1
126
//        for (TaxonNode node: nodes){
127
//           assertTrue("The sortindex should not be smaller than 0", node.getSortIndex() > -1 );
128
//
129
//        }
126
        for (TaxonNode node: nodes){
127
            System.out.println(node.treeIndex());
128
            assertTrue("The sortindex should not be smaller than 0", node.getSortIndex() > -1 );
129
	}
130 130
        assertEquals("Number of taxon nodes is incorrect", 4, taxonNodeService.count(TaxonNode.class));
131 131
        assertEquals("Number of taxa is incorrect", 3, taxonService.count(TaxonBase.class));
132 132
        assertEquals(1, taxonService.findByTitle(Taxon.class, "Campanula bononiensis", MatchMode.ANYWHERE, null, null, null, null, null).getRecords().size());
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/taxon/Classification.java
218 218
            node.setTaxon(null);
219 219
        }
220 220

  
221
        ArrayList<TaxonNode> childNodes = new ArrayList<TaxonNode>(node.getChildNodes());
221
        ArrayList<TaxonNode> childNodes = new ArrayList<>(node.getChildNodes());
222 222
        for (TaxonNode childNode : childNodes){
223 223
            if (childNode != null){
224 224
                node.deleteChildNode(childNode);

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)