Project

General

Profile

Revision b8a2a1ad

IDb8a2a1ad6dbcd6b6498df0cd1b53c8880741c4b2
Parent 99634595
Child fed12afd

Added by Andreas Müller almost 3 years ago

ref #6627 add error handling to CDM light export

View differences:

cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/outputmodel/OutputModelClassificationExport.java
26 26
import eu.etaxonomy.cdm.io.common.ExportResult.ExportResultState;
27 27
import eu.etaxonomy.cdm.io.common.ICdmExport;
28 28
import eu.etaxonomy.cdm.io.common.mapping.out.IExportTransformer;
29
import eu.etaxonomy.cdm.model.agent.AgentBase;
29 30
import eu.etaxonomy.cdm.model.agent.Person;
30 31
import eu.etaxonomy.cdm.model.agent.Team;
31 32
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
......
140 141

  
141 142
        Taxon taxon = taxonNode.getTaxon();
142 143
        if (taxon == null){
143
            state.getResult().addError("There was a taxon node without a taxon: " + taxonNode.getUuid());
144
            state.getResult().addError ("There was a taxon node without a taxon: " + taxonNode.getUuid(), "handleTaxon");
144 145
            state.getResult().setState(ExportResultState.INCOMPLETE_WITH_ERROR);
145
            System.err.println("There was a taxon node without a taxon: " + taxonNode.getUuid());
146

  
147 146
        }else{
148 147
             try{
149 148
                TaxonName name = taxon.getName();
......
167 166

  
168 167
                state.getProcessor().put(table, taxon, csvLine, state);
169 168
                handleDescriptions(state, taxon);
170
                 }catch(Exception e){
171
                     state.getResult().addError("An unexpected problems trying to export taxon with id " + taxon.getId() + e.getStackTrace());
172
                     e.printStackTrace();
173
                     state.getResult().setState(ExportResultState.INCOMPLETE_WITH_ERROR);
174
                 }
169
             }catch(Exception e){
170
                 state.getResult().addError ("An unexpected problem occurred when trying to export taxon with id " + taxon.getId(), e);
171
                 state.getResult().setState(ExportResultState.INCOMPLETE_WITH_ERROR);
175 172
             }
176
           for (TaxonNode child: taxonNode.getChildNodes()){
177
               handleTaxon(state, child);
178
           }
173
       }
174
       for (TaxonNode child: taxonNode.getChildNodes()){
175
           handleTaxon(state, child);
176
       }
179 177

  
180 178
    }
181 179

  
......
195 193
            for (TaxonDescription description: descriptions){
196 194
                if (description.getElements() != null){
197 195
                    for (DescriptionElementBase element: description.getElements()){
196
                        element = CdmBase.deproxy(element);
198 197
                        if (element.getFeature().equals(Feature.COMMON_NAME())){
199 198
                            commonNameFacts.add(element);
200 199
                        }else if (element.getFeature().equals(Feature.DISTRIBUTION())){
201 200
                            distributionFacts.add(element);
202
                        }else if (element.getFeature().equals(Feature.SPECIMEN())){
201
                        }else if (element instanceof IndividualsAssociation || isSpecimenFeature(element.getFeature())){
203 202
                            specimenFacts.add(element);
204 203
                        }else{
205 204
                            simpleFacts.add(element);
......
237 236
                handleSimpleFacts(state, name, simpleFacts);
238 237
            }
239 238
        }
240

  
241

  
242 239
    }
243 240

  
244 241

  
242
    /**
243
     * @param feature
244
     * @return
245
     */
246
    private boolean isSpecimenFeature(Feature feature) {
247
        //TODO allow user defined specimen features
248
        if (feature == null){
249
            return false;
250
        }else if (feature.isSupportsIndividualAssociation()){
251
            return true;
252
        }else{
253
            return feature.equals(Feature.SPECIMEN()) || feature.equals(Feature.INDIVIDUALS_ASSOCIATION())
254
                    || feature.equals(Feature.MATERIALS_EXAMINED()) || feature.equals(Feature.OBSERVATION())
255
                    || feature.equals(Feature.OCCURRENCE())
256
                     ;
257
        }
258
    }
245 259

  
246 260
    /**
247 261
     * @param state
......
250 264
     */
251 265
    private void handleSimpleFacts(OutputModelExportState state, CdmBase cdmBase,
252 266
            List<DescriptionElementBase> simpleFacts) {
253
        OutputModelTable table = OutputModelTable.SIMPLE_FACT;
254
        String[] csvLine = new String[table.getSize()];
267
        try {
268
            OutputModelTable table = OutputModelTable.SIMPLE_FACT;
269

  
270
            for (DescriptionElementBase element: simpleFacts){
271
                handleSingleSimpleFact(state, cdmBase, table, element);
272
            }
273
        } catch (Exception e) {
274
            state.getResult().addException(e, "An unexpected error occurred when handling simple facts for " +
275
                    cdmBaseStr(cdmBase) + ": " + e.getMessage());
276
        }
277
    }
255 278

  
256
        for (DescriptionElementBase element: simpleFacts){
279
    /**
280
     * @param state
281
     * @param cdmBase
282
     * @param table
283
     * @param element
284
     */
285
    private void handleSingleSimpleFact(OutputModelExportState state, CdmBase cdmBase, OutputModelTable table,
286
            DescriptionElementBase element) {
287
        try {
288
            String[] csvLine;
257 289
            handleSource(state, element, OutputModelTable.SIMPLE_FACT);
258 290

  
259 291
            if (element instanceof TextData){
......
272 304
               String mediaUris = "";
273 305
               for (Media media: textData.getMedia()){
274 306
                   String mediaString = extractMediaUris(media.getRepresentations().iterator());
275
                   if (!StringUtils.isBlank(mediaString)){ mediaUris +=  mediaString + ";";}
276
                   else{state.getResult().addWarning("Empty Media object for uuid: " + cdmBase.getUuid() + " uuid of media: " + media.getUuid());}
307
                   if (!StringUtils.isBlank(mediaString)){
308
                       mediaUris +=  mediaString + ";";
309
                   }
310
                   else{
311
                       state.getResult().addWarning("Empty Media object for uuid: " +
312
                               cdmBase.getUuid() + " uuid of media: " + media.getUuid());
313
                   }
277 314
               }
278 315
               csvLine[table.getIndex(OutputModelTable.MEDIA_URI)] = mediaUris;
279 316
               if (textData.getFeature().equals(Feature.CITATION())){
280 317
                  // csvLine[table.getIndex(OutputModelTable.TAXON_FK)] = getId(state, cdmBase);
281 318
                   state.getProcessor().put(table, textData, csvLine, state);
282 319
               }else if (!textData.getMultilanguageText().isEmpty()){
283
                       for (Language language: textData.getMultilanguageText().keySet()){
284
                           String[] csvLineLanguage = csvLine.clone();
285
                           LanguageString langString = textData.getLanguageText(language);
320
                   for (Language language: textData.getMultilanguageText().keySet()){
321
                       String[] csvLineLanguage = csvLine.clone();
322
                       LanguageString langString = textData.getLanguageText(language);
286 323

  
287
                           csvLineLanguage[table.getIndex(OutputModelTable.FACT_TEXT)] = langString.getText();
288
                           csvLineLanguage[table.getIndex(OutputModelTable.LANGUAGE)] = language.getLabel();
289
                           state.getProcessor().put(table, textData, csvLineLanguage, state);
290
                       }
324
                       csvLineLanguage[table.getIndex(OutputModelTable.FACT_TEXT)] = langString.getText();
325
                       csvLineLanguage[table.getIndex(OutputModelTable.LANGUAGE)] = language.getLabel();
326
                       state.getProcessor().put(table, textData, csvLineLanguage, state);
327
                   }
291 328
               } else{
292

  
293 329
                   state.getProcessor().put(table, textData, csvLine, state);
294

  
295 330
               }
296 331
            }
332
        } catch (Exception e) {
333
            state.getResult().addException(e, "An unexpected error occurred when handling single simple fact " +
334
                    cdmBaseStr(element) + ": " + e.getMessage());
297 335
        }
298 336
    }
299 337

  
338

  
300 339
    /**
301 340
     * @param state
302 341
     * @param specimenFacts
303 342
     */
304 343
    private void handleSpecimenFacts(OutputModelExportState state, Taxon taxon, List<DescriptionElementBase> specimenFacts) {
305 344
        OutputModelTable table = OutputModelTable.SPECIMEN_FACT;
306
        String[] csvLine = new String[table.getSize()];
307 345

  
308 346
        for (DescriptionElementBase element: specimenFacts){
309
            csvLine = new String[table.getSize()];
310
            csvLine[table.getIndex(OutputModelTable.FACT_ID)] = getId(state, element);
311
            csvLine[table.getIndex(OutputModelTable.TAXON_FK)] = getId(state, taxon);
312
            handleSource(state, element, table);
313
            csvLine[table.getIndex(OutputModelTable.SPECIMEN_NOTES)] = createAnnotationsString(element.getAnnotations());
314

  
315
            if (element instanceof IndividualsAssociation){
316

  
317
                IndividualsAssociation indAssociation = (IndividualsAssociation)element;
318
                if (state.getSpecimenFromStore(indAssociation.getAssociatedSpecimenOrObservation().getId()) == null){
319
                    SpecimenOrObservationBase<?> specimenBase = HibernateProxyHelper.deproxy(indAssociation.getAssociatedSpecimenOrObservation());
320

  
321
                    if (specimenBase instanceof DerivedUnit){
322
                        DerivedUnit derivedUnit = (DerivedUnit)specimenBase;
323
                        handleSpecimen(state, derivedUnit);
324
                        csvLine[table.getIndex(OutputModelTable.SPECIMEN_FK)] = getId(state, indAssociation.getAssociatedSpecimenOrObservation());
325
                    }else{
326
                        //field units are not supported
327
                        state.getResult().addError("The associated Specimen of taxon " + taxon.getUuid() + " is not an DerivedUnit. Could not be exported.");
347
            try {
348
                String[] csvLine = new String[table.getSize()];
349
                csvLine[table.getIndex(OutputModelTable.FACT_ID)] = getId(state, element);
350
                csvLine[table.getIndex(OutputModelTable.TAXON_FK)] = getId(state, taxon);
351
                handleSource(state, element, table);
352
                csvLine[table.getIndex(OutputModelTable.SPECIMEN_NOTES)] = createAnnotationsString(element.getAnnotations());
353

  
354
                if (element instanceof IndividualsAssociation){
355

  
356
                    IndividualsAssociation indAssociation = (IndividualsAssociation)element;
357
                    if (state.getSpecimenFromStore(indAssociation.getAssociatedSpecimenOrObservation().getId()) == null){
358
                        SpecimenOrObservationBase<?> specimenBase = HibernateProxyHelper.deproxy(indAssociation.getAssociatedSpecimenOrObservation());
359

  
360
                        if (specimenBase instanceof DerivedUnit){
361
                            DerivedUnit derivedUnit = (DerivedUnit)specimenBase;
362
                            handleSpecimen(state, derivedUnit);
363
                            csvLine[table.getIndex(OutputModelTable.SPECIMEN_FK)] = getId(state, indAssociation.getAssociatedSpecimenOrObservation());
364
                        }else{
365
                            //field units are not supported
366
                            state.getResult().addError("The associated Specimen of taxon " + taxon.getUuid() + " is not an DerivedUnit. Could not be exported.");
367
                        }
328 368
                    }
369
                } else if (element instanceof TextData){
370
                    TextData textData = HibernateProxyHelper.deproxy(element, TextData.class);
371
                    csvLine[table.getIndex(OutputModelTable.SPECIMEN_DESCRIPTION)] = createMultilanguageString(textData.getMultilanguageText());
329 372
                }
330

  
331
            } else if (element instanceof TextData){
332
                TextData textData = HibernateProxyHelper.deproxy(element, TextData.class);
333
                csvLine[table.getIndex(OutputModelTable.SPECIMEN_DESCRIPTION)] = createMultilanguageString(textData.getMultilanguageText());
334
             }
335
            state.getProcessor().put(table, element, csvLine, state);
373
                state.getProcessor().put(table, element, csvLine, state);
374
            } catch (Exception e) {
375
                state.getResult().addException(e, "An unexpected error occurred when handling single specimen fact " +
376
                        cdmBaseStr(element) + ": " + e.getMessage());
377
            }
336 378
        }
337 379
    }
338 380

  
......
376 418
     */
377 419
    private void handleSource(OutputModelExportState state, DescriptionElementBase element, OutputModelTable factsTable) {
378 420
        OutputModelTable table = OutputModelTable.FACT_SOURCES;
379
        String[] csvLine = new String[table.getSize()];
380 421
        Set<DescriptionElementSource> sources = element.getSources();
381 422
        for (DescriptionElementSource source: sources){
382
            csvLine = new  String[table.getSize()];
383
            Reference ref = source.getCitation();
384
            if ((ref == null) && (source.getNameUsedInSource() == null)){
385
                continue;
386
            }
387
            if (ref != null){
388
                if (state.getReferenceFromStore(ref.getId()) == null){
389
                    handleReference(state, ref);
390
                    csvLine[table.getIndex(OutputModelTable.REFERENCE_FK)] = getId(state, ref);
423
            try {
424
                String[] csvLine = new  String[table.getSize()];
425
                Reference ref = source.getCitation();
426
                if ((ref == null) && (source.getNameUsedInSource() == null)){
427
                    continue;
391 428
                }
392
            }
393
            csvLine[table.getIndex(OutputModelTable.FACT_FK)] = getId(state, element);
429
                if (ref != null){
430
                    if (state.getReferenceFromStore(ref.getId()) == null){
431
                        handleReference(state, ref);
432
                        csvLine[table.getIndex(OutputModelTable.REFERENCE_FK)] = getId(state, ref);
433
                    }
434
                }
435
                csvLine[table.getIndex(OutputModelTable.FACT_FK)] = getId(state, element);
394 436

  
395
            csvLine[table.getIndex(OutputModelTable.NAME_IN_SOURCE_FK)] = getId(state, source.getNameUsedInSource());
396
            csvLine[table.getIndex(OutputModelTable.FACT_TYPE)] = factsTable.getTableName();
397
            if ( StringUtils.isBlank(csvLine[table.getIndex(OutputModelTable.REFERENCE_FK)])  && StringUtils.isBlank(csvLine[table.getIndex(OutputModelTable.NAME_IN_SOURCE_FK)])){
398
                continue;
437
                csvLine[table.getIndex(OutputModelTable.NAME_IN_SOURCE_FK)] = getId(state, source.getNameUsedInSource());
438
                csvLine[table.getIndex(OutputModelTable.FACT_TYPE)] = factsTable.getTableName();
439
                if ( StringUtils.isBlank(csvLine[table.getIndex(OutputModelTable.REFERENCE_FK)])  && StringUtils.isBlank(csvLine[table.getIndex(OutputModelTable.NAME_IN_SOURCE_FK)])){
440
                    continue;
441
                }
442
                state.getProcessor().put(table, source, csvLine, state);
443
            } catch (Exception e) {
444
                state.getResult().addException(e, "An unexpected error occurred when handling single source " +
445
                        cdmBaseStr(element) + ": " + e.getMessage());
399 446
            }
400
            state.getProcessor().put(table, source, csvLine, state);
401 447
        }
402 448

  
403 449
    }
......
408 454
     */
409 455
    private void handleDistributionFacts(OutputModelExportState state, Taxon taxon, List<DescriptionElementBase> distributionFacts) {
410 456
        OutputModelTable table = OutputModelTable.GEOGRAPHIC_AREA_FACT;
411
        String[] csvLine = new String[table.getSize()];
412 457

  
413 458
        for (DescriptionElementBase element: distributionFacts){
414
            if (element instanceof Distribution){
415
                csvLine = new  String[table.getSize()];
416
                Distribution distribution = (Distribution)element;
417
                csvLine[table.getIndex(OutputModelTable.FACT_ID)] = getId(state, element);
418
                handleSource(state, element, table);
419
                csvLine[table.getIndex(OutputModelTable.TAXON_FK)] = getId(state, taxon);
420
                if (distribution.getArea() != null){ csvLine[table.getIndex(OutputModelTable.AREA_LABEL)] = distribution.getArea().getLabel();}
421
                if (distribution.getStatus() != null){ csvLine[table.getIndex(OutputModelTable.STATUS_LABEL)] = distribution.getStatus().getLabel();}
422
                state.getProcessor().put(table, distribution, csvLine, state);
423
            } else{
424
                state.getResult().addError("The distribution description for the taxon " + taxon.getUuid() + " is not of type distribution. Could not be exported. UUID of the description element: " + element.getUuid());
459
            try {
460
                if (element instanceof Distribution){
461
                    String[] csvLine = new  String[table.getSize()];
462
                    Distribution distribution = (Distribution)element;
463
                    csvLine[table.getIndex(OutputModelTable.FACT_ID)] = getId(state, element);
464
                    handleSource(state, element, table);
465
                    csvLine[table.getIndex(OutputModelTable.TAXON_FK)] = getId(state, taxon);
466
                    if (distribution.getArea() != null){
467
                        csvLine[table.getIndex(OutputModelTable.AREA_LABEL)] = distribution.getArea().getLabel();
468
                    }
469
                    if (distribution.getStatus() != null){
470
                        csvLine[table.getIndex(OutputModelTable.STATUS_LABEL)] = distribution.getStatus().getLabel();
471
                    }
472
                    state.getProcessor().put(table, distribution, csvLine, state);
473
                } else{
474
                    state.getResult().addError("The distribution description for the taxon " + taxon.getUuid() + " is not of type distribution. Could not be exported. UUID of the description element: " + element.getUuid());
475
                }
476
            } catch (Exception e) {
477
                state.getResult().addException(e, "An unexpected error occurred when handling single distribution " +
478
                        cdmBaseStr(element) + ": " + e.getMessage());
425 479
            }
426 480
        }
427 481
    }
......
432 486
     */
433 487
    private void handleCommonNameFacts(OutputModelExportState state, Taxon taxon, List<DescriptionElementBase> commonNameFacts) {
434 488
        OutputModelTable table = OutputModelTable.COMMON_NAME_FACT;
435
        String[] csvLine = new String[table.getSize()];
436 489

  
437 490
        for (DescriptionElementBase element: commonNameFacts){
438
            if (element instanceof CommonTaxonName){
439
                csvLine = new  String[table.getSize()];
440
                CommonTaxonName commonName = (CommonTaxonName)element;
441
                csvLine[table.getIndex(OutputModelTable.FACT_ID)] = getId(state, element);
442
                handleSource(state, element, table);
443
                csvLine[table.getIndex(OutputModelTable.TAXON_FK)] = getId(state, taxon);
444
                if (commonName.getName() != null){csvLine[table.getIndex(OutputModelTable.FACT_TEXT)] = commonName.getName();}
445
                if (commonName.getLanguage() != null){csvLine[table.getIndex(OutputModelTable.LANGUAGE)] = commonName.getLanguage().getLabel();}
446
                if (commonName.getArea() != null){ csvLine[table.getIndex(OutputModelTable.AREA_LABEL)] = commonName.getArea().getLabel();}
447
                state.getProcessor().put(table, commonName, csvLine, state);
448
            } else{
449
                state.getResult().addError("The distribution description for the taxon " + taxon.getUuid() + " is not of type distribution. Could not be exported. UUID of the description element: " + element.getUuid());
491
            try {
492
                if (element instanceof CommonTaxonName){
493
                    String[] csvLine = new  String[table.getSize()];
494
                    CommonTaxonName commonName = (CommonTaxonName)element;
495
                    csvLine[table.getIndex(OutputModelTable.FACT_ID)] = getId(state, element);
496
                    handleSource(state, element, table);
497
                    csvLine[table.getIndex(OutputModelTable.TAXON_FK)] = getId(state, taxon);
498
                    if (commonName.getName() != null){csvLine[table.getIndex(OutputModelTable.FACT_TEXT)] = commonName.getName();}
499
                    if (commonName.getLanguage() != null){csvLine[table.getIndex(OutputModelTable.LANGUAGE)] = commonName.getLanguage().getLabel();}
500
                    if (commonName.getArea() != null){ csvLine[table.getIndex(OutputModelTable.AREA_LABEL)] = commonName.getArea().getLabel();}
501
                    state.getProcessor().put(table, commonName, csvLine, state);
502
                } else{
503
                    state.getResult().addError("The distribution description for the taxon " + taxon.getUuid() + " is not of type distribution. Could not be exported. UUID of the description element: " + element.getUuid());
504
                }
505
            } catch (Exception e) {
506
                state.getResult().addException(e, "An unexpected error occurred when handling single common name " +
507
                        cdmBaseStr(element) + ": " + e.getMessage());
450 508
            }
451 509
        }
452

  
453 510
    }
454 511

  
455 512
    /**
......
482 539
     * @param syn
483 540
     */
484 541
    private void handleSynonym(OutputModelExportState state, Synonym syn) {
485
       TaxonName name = syn.getName();
486
       handleName(state, name);
487

  
488
       OutputModelTable table = OutputModelTable.SYNONYM;
489
       String[] csvLine = new String[table.getSize()];
490

  
491
       csvLine[table.getIndex(OutputModelTable.SYNONYM_ID)] = getId(state, syn);
492
       csvLine[table.getIndex(OutputModelTable.TAXON_FK)] = getId(state, syn.getAcceptedTaxon());
493
       csvLine[table.getIndex(OutputModelTable.NAME_FK)] = getId(state, name);
494
       csvLine[table.getIndex(OutputModelTable.SEC_REFERENCE_FK)] = getId(state, syn.getSec());
495
       csvLine[table.getIndex(OutputModelTable.SEC_REFERENCE)] = getTitleCache(syn.getSec());
496

  
497
       state.getProcessor().put(table, syn, csvLine, state);
542
       try {
543
           TaxonName name = syn.getName();
544
           handleName(state, name);
545

  
546
           OutputModelTable table = OutputModelTable.SYNONYM;
547
           String[] csvLine = new String[table.getSize()];
548

  
549
           csvLine[table.getIndex(OutputModelTable.SYNONYM_ID)] = getId(state, syn);
550
           csvLine[table.getIndex(OutputModelTable.TAXON_FK)] = getId(state, syn.getAcceptedTaxon());
551
           csvLine[table.getIndex(OutputModelTable.NAME_FK)] = getId(state, name);
552
           csvLine[table.getIndex(OutputModelTable.SEC_REFERENCE_FK)] = getId(state, syn.getSec());
553
           csvLine[table.getIndex(OutputModelTable.SEC_REFERENCE)] = getTitleCache(syn.getSec());
554

  
555
           state.getProcessor().put(table, syn, csvLine, state);
556
        } catch (Exception e) {
557
            state.getResult().addException(e, "An unexpected error occurred when handling synonym " +
558
                    cdmBaseStr(syn) + ": " + e.getMessage());
559
        }
498 560
    }
499 561

  
500 562
    /**
......
502 564
     * @param name
503 565
     */
504 566
    private void handleName(OutputModelExportState state, TaxonName name) {
505
        Rank rank = name.getRank();
506
        OutputModelTable table = OutputModelTable.SCIENTIFIC_NAME;
507
        name = HibernateProxyHelper.deproxy(name);
508
        String[] csvLine = new String[table.getSize()];
509

  
510
        csvLine[table.getIndex(OutputModelTable.NAME_ID)] = getId(state, name);
511
        if (name.getLsid() != null){
512
            csvLine[table.getIndex(OutputModelTable.LSID)] = name.getLsid().getLsid();
513
        }else{
514
            csvLine[table.getIndex(OutputModelTable.LSID)] = "";
515
        }
567
        try {
568
            Rank rank = name.getRank();
569
            OutputModelTable table = OutputModelTable.SCIENTIFIC_NAME;
570
            name = HibernateProxyHelper.deproxy(name);
571
            String[] csvLine = new String[table.getSize()];
572

  
573
            csvLine[table.getIndex(OutputModelTable.NAME_ID)] = getId(state, name);
574
            if (name.getLsid() != null){
575
                csvLine[table.getIndex(OutputModelTable.LSID)] = name.getLsid().getLsid();
576
            }else{
577
                csvLine[table.getIndex(OutputModelTable.LSID)] = "";
578
            }
516 579

  
517
        handleIdentifier(state, name, csvLine, table);
518
        handleDescriptions(state, name);
519

  
520
        csvLine[table.getIndex(OutputModelTable.RANK)] = getTitleCache(rank);
521
        if (rank != null){
522
            csvLine[table.getIndex(OutputModelTable.RANK_SEQUENCE)] = String.valueOf(rank.getOrderIndex());
523
            if (rank.isInfraGeneric()){
524
                try {
525
                    csvLine[table.getIndex(OutputModelTable.INFRAGENERIC_RANK)] = name.getRank().getInfraGenericMarker();
526
                } catch (UnknownCdmTypeException e) {
527
                    // TODO Auto-generated catch block
528
                    e.printStackTrace();
580
            handleIdentifier(state, name, csvLine, table);
581
            handleDescriptions(state, name);
582

  
583
            csvLine[table.getIndex(OutputModelTable.RANK)] = getTitleCache(rank);
584
            if (rank != null){
585
                csvLine[table.getIndex(OutputModelTable.RANK_SEQUENCE)] = String.valueOf(rank.getOrderIndex());
586
                if (rank.isInfraGeneric()){
587
                    try {
588
                        csvLine[table.getIndex(OutputModelTable.INFRAGENERIC_RANK)] = name.getRank().getInfraGenericMarker();
589
                    } catch (UnknownCdmTypeException e) {
590
                        // TODO Auto-generated catch block
591
                        e.printStackTrace();
592
                    }
593
                }
594
                if (rank.isInfraSpecific()){
595
                    csvLine[table.getIndex(OutputModelTable.INFRASPECIFIC_RANK)] = name.getRank().getAbbreviation();
529 596
                }
597
            }else{
598
                csvLine[table.getIndex(OutputModelTable.RANK_SEQUENCE)] = "";
530 599
            }
531
            if (rank.isInfraSpecific()){
532
                csvLine[table.getIndex(OutputModelTable.INFRASPECIFIC_RANK)] = name.getRank().getAbbreviation();
600
            if (name.isProtectedTitleCache()){
601
                csvLine[table.getIndex(OutputModelTable.FULL_NAME_WITH_AUTHORS)] =name.getTitleCache();
602
            }else{
603
                //TODO: adapt the tropicos titlecache creation
604
                csvLine[table.getIndex(OutputModelTable.FULL_NAME_WITH_AUTHORS)] = name.getTitleCache();
533 605
            }
534
        }else{
535
            csvLine[table.getIndex(OutputModelTable.RANK_SEQUENCE)] = "";
536
        }
537
        if (name.isProtectedTitleCache()){
538
            csvLine[table.getIndex(OutputModelTable.FULL_NAME_WITH_AUTHORS)] =name.getTitleCache();
539
        }else{
540
            //TODO: adapt the tropicos titlecache creation
541
            csvLine[table.getIndex(OutputModelTable.FULL_NAME_WITH_AUTHORS)] = name.getTitleCache();
542
        }
543
        csvLine[table.getIndex(OutputModelTable.FULL_NAME_NO_AUTHORS)] = name.getNameCache();
544
        csvLine[table.getIndex(OutputModelTable.GENUS_UNINOMIAL)] = name.getGenusOrUninomial();
606
            csvLine[table.getIndex(OutputModelTable.FULL_NAME_NO_AUTHORS)] = name.getNameCache();
607
            csvLine[table.getIndex(OutputModelTable.GENUS_UNINOMIAL)] = name.getGenusOrUninomial();
545 608

  
546
        csvLine[table.getIndex(OutputModelTable.INFRAGENERIC_EPITHET)] = name.getInfraGenericEpithet();
547
        csvLine[table.getIndex(OutputModelTable.SPECIFIC_EPITHET)] = name.getSpecificEpithet();
609
            csvLine[table.getIndex(OutputModelTable.INFRAGENERIC_EPITHET)] = name.getInfraGenericEpithet();
610
            csvLine[table.getIndex(OutputModelTable.SPECIFIC_EPITHET)] = name.getSpecificEpithet();
548 611

  
549
        csvLine[table.getIndex(OutputModelTable.INFRASPECIFIC_EPITHET)] = name.getInfraSpecificEpithet();
550
        csvLine[table.getIndex(OutputModelTable.BAS_AUTHORTEAM_FK)] = getId(state,name.getBasionymAuthorship());
551
        if (name.getBasionymAuthorship() != null){
552
            if (state.getAuthorFromStore(name.getBasionymAuthorship().getId()) == null) {
553
                handleAuthor(state, name.getBasionymAuthorship());
554
            }
555
        }
556
        csvLine[table.getIndex(OutputModelTable.BAS_EX_AUTHORTEAM_FK)] = getId(state, name.getExBasionymAuthorship());
557
        if (name.getExBasionymAuthorship() != null){
558
            if (state.getAuthorFromStore(name.getExBasionymAuthorship().getId()) == null) {
559
                handleAuthor(state, name.getExBasionymAuthorship());
612
            csvLine[table.getIndex(OutputModelTable.INFRASPECIFIC_EPITHET)] = name.getInfraSpecificEpithet();
613
            csvLine[table.getIndex(OutputModelTable.BAS_AUTHORTEAM_FK)] = getId(state,name.getBasionymAuthorship());
614
            if (name.getBasionymAuthorship() != null){
615
                if (state.getAuthorFromStore(name.getBasionymAuthorship().getId()) == null) {
616
                    handleAuthor(state, name.getBasionymAuthorship());
617
                }
560 618
            }
619
            csvLine[table.getIndex(OutputModelTable.BAS_EX_AUTHORTEAM_FK)] = getId(state, name.getExBasionymAuthorship());
620
            if (name.getExBasionymAuthorship() != null){
621
                if (state.getAuthorFromStore(name.getExBasionymAuthorship().getId()) == null) {
622
                    handleAuthor(state, name.getExBasionymAuthorship());
623
                }
561 624

  
562
        }
563
        csvLine[table.getIndex(OutputModelTable.COMB_AUTHORTEAM_FK)] = getId(state,name.getCombinationAuthorship());
564
        if (name.getCombinationAuthorship() != null){
565
            if (state.getAuthorFromStore(name.getCombinationAuthorship().getId()) == null) {
566
                handleAuthor(state, name.getCombinationAuthorship());
567 625
            }
568
        }
569
        csvLine[table.getIndex(OutputModelTable.COMB_EX_AUTHORTEAM_FK)] = getId(state, name.getExCombinationAuthorship());
570
        if (name.getExCombinationAuthorship() != null){
571
            if (state.getAuthorFromStore(name.getExCombinationAuthorship().getId()) == null) {
572
                handleAuthor(state, name.getExCombinationAuthorship());
626
            csvLine[table.getIndex(OutputModelTable.COMB_AUTHORTEAM_FK)] = getId(state,name.getCombinationAuthorship());
627
            if (name.getCombinationAuthorship() != null){
628
                if (state.getAuthorFromStore(name.getCombinationAuthorship().getId()) == null) {
629
                    handleAuthor(state, name.getCombinationAuthorship());
630
                }
573 631
            }
632
            csvLine[table.getIndex(OutputModelTable.COMB_EX_AUTHORTEAM_FK)] = getId(state, name.getExCombinationAuthorship());
633
            if (name.getExCombinationAuthorship() != null){
634
                if (state.getAuthorFromStore(name.getExCombinationAuthorship().getId()) == null) {
635
                    handleAuthor(state, name.getExCombinationAuthorship());
636
                }
574 637

  
575
        }
638
            }
576 639

  
577
        csvLine[table.getIndex(OutputModelTable.AUTHOR_TEAM_STRING)] = name.getAuthorshipCache();
640
            csvLine[table.getIndex(OutputModelTable.AUTHOR_TEAM_STRING)] = name.getAuthorshipCache();
578 641

  
579
        Reference nomRef = (Reference)name.getNomenclaturalReference();
642
            Reference nomRef = (Reference)name.getNomenclaturalReference();
580 643

  
581
        if (nomRef != null){
582
            if (state.getReferenceFromStore(nomRef.getId()) == null){
583
                handleReference(state, nomRef);
584
            }
585
            csvLine[table.getIndex(OutputModelTable.REFERENCE_FK)] = getId(state, nomRef);
586
            csvLine[table.getIndex(OutputModelTable.PUBLICATION_TYPE)] = nomRef.getType().name();
587
            if (nomRef.getVolume() != null){
588
                csvLine[table.getIndex(OutputModelTable.VOLUME_ISSUE)] = nomRef.getVolume();
589
            }
590
            if (nomRef.getDatePublished() != null){
591
                csvLine[table.getIndex(OutputModelTable.DATE_PUBLISHED)] = nomRef.getDatePublishedString();
592
                csvLine[table.getIndex(OutputModelTable.YEAR_PUBLISHED)] = nomRef.getDatePublished().getYear();
593
            }
594
            if (name.getNomenclaturalMicroReference() != null){
595
                csvLine[table.getIndex(OutputModelTable.DETAIL)] = name.getNomenclaturalMicroReference();
596
            }
597
            nomRef = HibernateProxyHelper.deproxy(nomRef);
598
            if (nomRef.getInReference() != null){
599
                Reference inReference = nomRef.getInReference();
600
                if (inReference.getInReference() != null){
601
                    inReference = inReference.getInReference();
644
            if (nomRef != null){
645
                if (state.getReferenceFromStore(nomRef.getId()) == null){
646
                    handleReference(state, nomRef);
602 647
                }
603
                if (inReference.getAbbrevTitle() == null){
604
                    csvLine[table.getIndex(OutputModelTable.ABBREV_TITLE)] = CdmUtils.Nz(inReference.getAbbrevTitleCache());
605
                }else{
606
                    csvLine[table.getIndex(OutputModelTable.ABBREV_TITLE)] = CdmUtils.Nz(inReference.getAbbrevTitle());
648
                csvLine[table.getIndex(OutputModelTable.REFERENCE_FK)] = getId(state, nomRef);
649
                csvLine[table.getIndex(OutputModelTable.PUBLICATION_TYPE)] = nomRef.getType().name();
650
                if (nomRef.getVolume() != null){
651
                    csvLine[table.getIndex(OutputModelTable.VOLUME_ISSUE)] = nomRef.getVolume();
607 652
                }
608
                if (inReference.getTitle() == null){
609
                    csvLine[table.getIndex(OutputModelTable.FULL_TITLE)] = CdmUtils.Nz(inReference.getTitleCache());
610
                }else{
611
                    csvLine[table.getIndex(OutputModelTable.FULL_TITLE)] = CdmUtils.Nz(inReference.getTitle());
653
                if (nomRef.getDatePublished() != null){
654
                    csvLine[table.getIndex(OutputModelTable.DATE_PUBLISHED)] = nomRef.getDatePublishedString();
655
                    csvLine[table.getIndex(OutputModelTable.YEAR_PUBLISHED)] = nomRef.getDatePublished().getYear();
612 656
                }
657
                if (name.getNomenclaturalMicroReference() != null){
658
                    csvLine[table.getIndex(OutputModelTable.DETAIL)] = name.getNomenclaturalMicroReference();
659
                }
660
                nomRef = HibernateProxyHelper.deproxy(nomRef);
661
                if (nomRef.getInReference() != null){
662
                    Reference inReference = nomRef.getInReference();
663
                    if (inReference.getInReference() != null){
664
                        inReference = inReference.getInReference();
665
                    }
666
                    if (inReference.getAbbrevTitle() == null){
667
                        csvLine[table.getIndex(OutputModelTable.ABBREV_TITLE)] = CdmUtils.Nz(inReference.getAbbrevTitleCache());
668
                    }else{
669
                        csvLine[table.getIndex(OutputModelTable.ABBREV_TITLE)] = CdmUtils.Nz(inReference.getAbbrevTitle());
670
                    }
671
                    if (inReference.getTitle() == null){
672
                        csvLine[table.getIndex(OutputModelTable.FULL_TITLE)] = CdmUtils.Nz(inReference.getTitleCache());
673
                    }else{
674
                        csvLine[table.getIndex(OutputModelTable.FULL_TITLE)] = CdmUtils.Nz(inReference.getTitle());
675
                    }
613 676

  
614 677

  
615
                TeamOrPersonBase author = inReference.getAuthorship();
616
                if (author != null && (nomRef.isOfType(ReferenceType.BookSection) || nomRef.isOfType(ReferenceType.Section))){
617
                    csvLine[table.getIndex(OutputModelTable.ABBREV_REF_AUTHOR)] = CdmUtils.Nz(author.getNomenclaturalTitle());
618
                    csvLine[table.getIndex(OutputModelTable.FULL_REF_AUTHOR)] = CdmUtils.Nz(author.getTitleCache());
678
                    TeamOrPersonBase<?> author = inReference.getAuthorship();
679
                    if (author != null && (nomRef.isOfType(ReferenceType.BookSection) || nomRef.isOfType(ReferenceType.Section))){
680
                        csvLine[table.getIndex(OutputModelTable.ABBREV_REF_AUTHOR)] = CdmUtils.Nz(author.getNomenclaturalTitle());
681
                        csvLine[table.getIndex(OutputModelTable.FULL_REF_AUTHOR)] = CdmUtils.Nz(author.getTitleCache());
682
                    }else{
683
                        csvLine[table.getIndex(OutputModelTable.ABBREV_REF_AUTHOR)] = "";
684
                        csvLine[table.getIndex(OutputModelTable.FULL_REF_AUTHOR)] = "";
685
                    }
619 686
                }else{
620
                    csvLine[table.getIndex(OutputModelTable.ABBREV_REF_AUTHOR)] = "";
621
                    csvLine[table.getIndex(OutputModelTable.FULL_REF_AUTHOR)] = "";
687
                    if (nomRef.getAbbrevTitle() == null){
688
                        csvLine[table.getIndex(OutputModelTable.ABBREV_TITLE)] = CdmUtils.Nz(nomRef.getAbbrevTitleCache());
689
                    }else{
690
                        csvLine[table.getIndex(OutputModelTable.ABBREV_TITLE)] = CdmUtils.Nz(nomRef.getAbbrevTitle());
691
                    }
692
                    if (nomRef.getTitle() == null){
693
                        csvLine[table.getIndex(OutputModelTable.FULL_TITLE)] = CdmUtils.Nz(nomRef.getTitleCache());
694
                    }else{
695
                        csvLine[table.getIndex(OutputModelTable.FULL_TITLE)] = CdmUtils.Nz(nomRef.getTitle());
696
                    }
697
                    TeamOrPersonBase<?> author = nomRef.getAuthorship();
698
                    if (author != null ){
699
                        csvLine[table.getIndex(OutputModelTable.ABBREV_REF_AUTHOR)] = CdmUtils.Nz(author.getNomenclaturalTitle());
700
                        csvLine[table.getIndex(OutputModelTable.FULL_REF_AUTHOR)] = CdmUtils.Nz(author.getTitleCache());
701
                    }else{
702
                        csvLine[table.getIndex(OutputModelTable.ABBREV_REF_AUTHOR)] = "";
703
                        csvLine[table.getIndex(OutputModelTable.FULL_REF_AUTHOR)] = "";
704
                    }
705

  
622 706
                }
623 707
            }else{
624
                if (nomRef.getAbbrevTitle() == null){
625
                    csvLine[table.getIndex(OutputModelTable.ABBREV_TITLE)] = CdmUtils.Nz(nomRef.getAbbrevTitleCache());
626
                }else{
627
                    csvLine[table.getIndex(OutputModelTable.ABBREV_TITLE)] = CdmUtils.Nz(nomRef.getAbbrevTitle());
628
                }
629
                if (nomRef.getTitle() == null){
630
                    csvLine[table.getIndex(OutputModelTable.FULL_TITLE)] = CdmUtils.Nz(nomRef.getTitleCache());
631
                }else{
632
                    csvLine[table.getIndex(OutputModelTable.FULL_TITLE)] = CdmUtils.Nz(nomRef.getTitle());
633
                }
634
                TeamOrPersonBase author = nomRef.getAuthorship();
635
                if (author != null ){
636
                    csvLine[table.getIndex(OutputModelTable.ABBREV_REF_AUTHOR)] = CdmUtils.Nz(author.getNomenclaturalTitle());
637
                    csvLine[table.getIndex(OutputModelTable.FULL_REF_AUTHOR)] = CdmUtils.Nz(author.getTitleCache());
638
                }else{
639
                    csvLine[table.getIndex(OutputModelTable.ABBREV_REF_AUTHOR)] = "";
640
                    csvLine[table.getIndex(OutputModelTable.FULL_REF_AUTHOR)] = "";
641
                }
642

  
708
                csvLine[table.getIndex(OutputModelTable.PUBLICATION_TYPE)] = "";
643 709
            }
644
        }else{
645
            csvLine[table.getIndex(OutputModelTable.PUBLICATION_TYPE)] = "";
646
        }
647 710

  
648 711

  
649 712

  
650
       /*
651
        * Collation
713
            /*
714
            * Collation
652 715

  
653
        Detail
716
            Detail
654 717

  
655 718

  
656
        TitlePageYear
657
        */
658
        Set<TaxonNameDescription> descriptions = name.getDescriptions();
659
        String protologueUriString = extractURIs(descriptions, Feature.PROTOLOGUE());
719
            TitlePageYear
720
            */
721
            Set<TaxonNameDescription> descriptions = name.getDescriptions();
722
            String protologueUriString = extractURIs(state, descriptions, Feature.PROTOLOGUE());
660 723

  
661
        csvLine[table.getIndex(OutputModelTable.PROTOLOGUE_URI)] = protologueUriString;
724
            csvLine[table.getIndex(OutputModelTable.PROTOLOGUE_URI)] = protologueUriString;
662 725

  
663
        if (name.getStatus() == null || name.getStatus().isEmpty()){
664
            csvLine[table.getIndex(OutputModelTable.NOM_STATUS)] = "";
665
            csvLine[table.getIndex(OutputModelTable.NOM_STATUS_ABBREV)] = "";
666
        }else{
726
            if (name.getStatus() == null || name.getStatus().isEmpty()){
727
                csvLine[table.getIndex(OutputModelTable.NOM_STATUS)] = "";
728
                csvLine[table.getIndex(OutputModelTable.NOM_STATUS_ABBREV)] = "";
729
            }else{
667 730

  
668
            String statusStringAbbrev = extractStatusString(name, true);
669
            String statusString = extractStatusString(name, false);
731
                String statusStringAbbrev = extractStatusString(state, name, true);
732
                String statusString = extractStatusString(state, name, false);
670 733

  
671
            csvLine[table.getIndex(OutputModelTable.NOM_STATUS)] = statusString.trim();
672
            csvLine[table.getIndex(OutputModelTable.NOM_STATUS_ABBREV)] = statusStringAbbrev.trim();
673
        }
734
                csvLine[table.getIndex(OutputModelTable.NOM_STATUS)] = statusString.trim();
735
                csvLine[table.getIndex(OutputModelTable.NOM_STATUS_ABBREV)] = statusStringAbbrev.trim();
736
            }
674 737

  
675
        HomotypicalGroup group =name.getHomotypicalGroup();
738
            HomotypicalGroup group =name.getHomotypicalGroup();
676 739

  
677
        if (state.getHomotypicalGroupFromStore(group.getId()) == null){
678
            handleHomotypicalGroup(state, group);
679
        }
680
        csvLine[table.getIndex(OutputModelTable.HOMOTYPIC_GROUP_FK)] = getId(state, group);
681
        List<TaxonName> typifiedNames = new ArrayList<>();
682
        typifiedNames.addAll(group.getTypifiedNames());
683
        Collections.sort(typifiedNames, new HomotypicalGroupNameComparator(null, true));
684
        Integer  seqNumber= typifiedNames.indexOf(name);
685
        csvLine[table.getIndex(OutputModelTable.HOMOTYPIC_GROUP_SEQ)] = String.valueOf(seqNumber);
686
        state.getProcessor().put(table, name, csvLine, state);
687

  
688
/*
689
 *
690
Tropicos_ID
691
IPNI_ID
740
            if (state.getHomotypicalGroupFromStore(group.getId()) == null){
741
                handleHomotypicalGroup(state, group);
742
            }
743
            csvLine[table.getIndex(OutputModelTable.HOMOTYPIC_GROUP_FK)] = getId(state, group);
744
            List<TaxonName> typifiedNames = new ArrayList<>();
745
            typifiedNames.addAll(group.getTypifiedNames());
746
            Collections.sort(typifiedNames, new HomotypicalGroupNameComparator(null, true));
747
            Integer  seqNumber= typifiedNames.indexOf(name);
748
            csvLine[table.getIndex(OutputModelTable.HOMOTYPIC_GROUP_SEQ)] = String.valueOf(seqNumber);
749
            state.getProcessor().put(table, name, csvLine, state);
692 750

  
751
            /*
752
             *
753
            Tropicos_ID
754
            IPNI_ID
693 755

  
694
InfragenericRank
695 756

  
757
            InfragenericRank
696 758

  
697
InfraspecificRank
698
Collation
699
Volume (Issue)
700
Detail
701
DatePublished
702
YearPublished
703
TitlePageYear
704 759

  
760
            InfraspecificRank
761
            Collation
762
            Volume (Issue)
763
            Detail
764
            DatePublished
765
            YearPublished
766
            TitlePageYear
705 767

  
706 768

  
707
HomotypicGroupSequenceNumber
708 769

  
770
            HomotypicGroupSequenceNumber
709 771

  
710
 *
711
 */
772

  
773
             *
774
             */
775
        } catch (Exception e) {
776
            state.getResult().addException(e, "An unexpected error occurred when handling synonym " +
777
                    cdmBaseStr(name) + ": " + e.getMessage());
778
        }
712 779
    }
713 780

  
714 781
    /**
......
716 783
     * @param name
717 784
     */
718 785
    private void handleIdentifier(OutputModelExportState state, TaxonName name, String[] csvLine, OutputModelTable table) {
719
        Set<String>  IPNIidentifiers = name.getIdentifiers(DefinedTerm.IPNI_NAME_IDENTIFIER());
720
        Set<String>  tropicosIdentifiers = name.getIdentifiers(DefinedTerm.TROPICOS_NAME_IDENTIFIER());
721
        Set<String>  WFOIdentifiers = name.getIdentifiers(DefinedTerm.uuidWfoNameIdentifier);
722
        if (!IPNIidentifiers.isEmpty()){ extractIdentifier(IPNIidentifiers, csvLine, table.getIndex(OutputModelTable.IPNI_ID));}
723
        if (!tropicosIdentifiers.isEmpty()){extractIdentifier(tropicosIdentifiers, csvLine, table.getIndex(OutputModelTable.TROPICOS_ID));}
724
        if (!WFOIdentifiers.isEmpty()){extractIdentifier(WFOIdentifiers,  csvLine, table.getIndex(OutputModelTable.WFO_ID));}
786
        try {
787
            Set<String>  IPNIidentifiers = name.getIdentifiers(DefinedTerm.IPNI_NAME_IDENTIFIER());
788
            Set<String>  tropicosIdentifiers = name.getIdentifiers(DefinedTerm.TROPICOS_NAME_IDENTIFIER());
789
            Set<String>  WFOIdentifiers = name.getIdentifiers(DefinedTerm.uuidWfoNameIdentifier);
790
            if (!IPNIidentifiers.isEmpty()){
791
                extractIdentifier(IPNIidentifiers, csvLine, table.getIndex(OutputModelTable.IPNI_ID));
792
            }
793
            if (!tropicosIdentifiers.isEmpty()){
794
                extractIdentifier(tropicosIdentifiers, csvLine, table.getIndex(OutputModelTable.TROPICOS_ID));
795
            }
796
            if (!WFOIdentifiers.isEmpty()){
797
                extractIdentifier(WFOIdentifiers,  csvLine, table.getIndex(OutputModelTable.WFO_ID));
798
            }
799
        } catch (Exception e) {
800
            state.getResult().addException(e, "An unexpected error occurred when handling identifiers for " +
801
                    cdmBaseStr(name) + ": " + e.getMessage());
802

  
803
        }
725 804
    }
726 805

  
727 806
    /**
......
740 819
    }
741 820

  
742 821
    /**
822
     * @param state
743 823
     * @param descriptions
744 824
     * @return
745 825
     */
746
    private String extractURIs(Set<?> descriptions, Feature feature) {
826
    private String extractURIs(OutputModelExportState state,
827
            Set<? extends DescriptionBase<?>> descriptionsSet, Feature feature) {
747 828
        String mediaUriString = "";
748
        boolean first = true;
749 829
        SpecimenDescription specimenDescription;
750 830
        TaxonDescription taxonDescription;
751 831
        TaxonNameDescription nameDescription;
752
        Set<DescriptionElementBase> elements = new HashSet();
753
        Set<DescriptionBase> descriptionsSet = (Set<DescriptionBase>)descriptions;
754
        for (DescriptionBase description : descriptionsSet){
755
            if (!description.getElements().isEmpty()){
756
                if (description instanceof SpecimenDescription){
757
                    specimenDescription = (SpecimenDescription)description;
758
                    elements = specimenDescription.getElements();
759
                }else if (description instanceof TaxonDescription){
760
                    taxonDescription = (TaxonDescription) description;
761
                    elements = taxonDescription.getElements();
762
                } else if (description instanceof TaxonNameDescription){
763
                    nameDescription = (TaxonNameDescription) description;
764
                    elements = nameDescription.getElements();
765
                }
832
        Set<DescriptionElementBase> elements = new HashSet<>();
833
        for (DescriptionBase<?> description : descriptionsSet){
834
            try {
835
                if (!description.getElements().isEmpty()){
836
                    if (description instanceof SpecimenDescription){
837
                        specimenDescription = (SpecimenDescription)description;
838
                        elements = specimenDescription.getElements();
839
                    }else if (description instanceof TaxonDescription){
840
                        taxonDescription = (TaxonDescription) description;
841
                        elements = taxonDescription.getElements();
842
                    } else if (description instanceof TaxonNameDescription){
843
                        nameDescription = (TaxonNameDescription) description;
844
                        elements = nameDescription.getElements();
845
                    }
766 846

  
767
                for (DescriptionElementBase element : elements){
768
                    Feature entityFeature = HibernateProxyHelper.deproxy(element.getFeature());
769
                    if (entityFeature.equals(feature)){
770
                        if (!element.getMedia().isEmpty()){
771
                            List<Media> media = element.getMedia();
772
                            for (Media mediaElement: media){
773
                                Iterator<MediaRepresentation> it =  mediaElement.getRepresentations().iterator();
774
                                mediaUriString = extractMediaUris(it);
847
                    for (DescriptionElementBase element : elements){
848
                        Feature entityFeature = HibernateProxyHelper.deproxy(element.getFeature());
849
                        if (entityFeature.equals(feature)){
850
                            if (!element.getMedia().isEmpty()){
851
                                List<Media> media = element.getMedia();
852
                                for (Media mediaElement: media){
853
                                    Iterator<MediaRepresentation> it =  mediaElement.getRepresentations().iterator();
854
                                    mediaUriString = extractMediaUris(it);
855
                                }
775 856
                            }
776 857
                        }
777 858
                    }
778 859
                }
860
            } catch (Exception e) {
861
                state.getResult().addException(e, "An unexpected error occurred when extracting media URIs for " +
862
                        cdmBaseStr(description) + ": " + e.getMessage());
779 863
            }
780 864
        }
781 865
        return mediaUriString;
......
785 869
     * @param state
786 870
     * @param basionymAuthorship
787 871
     */
788
    private void handleAuthor(OutputModelExportState state, TeamOrPersonBase author) {
789
        if (state.getAuthorFromStore(author.getId()) != null){
790
            return;
791
        }
792
        state.addAuthorToStore(author);
793
        OutputModelTable table = OutputModelTable.NOMENCLATURAL_AUTHOR;
794
        String[] csvLine = new String[table.getSize()];
795
        OutputModelTable tableAuthorRel = OutputModelTable.NOMENCLATURAL_AUTHOR_TEAM_RELATION;
796
        String[] csvLineRel = new String[tableAuthorRel.getSize()];
797
        String[] csvLineMember = new String[table.getSize()];
798
        csvLine[table.getIndex(OutputModelTable.AUTHOR_ID)] = getId(state, author);
799
        csvLine[table.getIndex(OutputModelTable.ABBREV_AUTHOR)] = author.getNomenclaturalTitle();
800
        csvLine[table.getIndex(OutputModelTable.AUTHOR_TITLE)] = author.getTitleCache();
801
        author = HibernateProxyHelper.deproxy(author);
802
        if (author instanceof Person){
803
            Person authorPerson = (Person)author;
804
            csvLine[table.getIndex(OutputModelTable.AUTHOR_FIRST_NAME)] = authorPerson.getFirstname();
805
            csvLine[table.getIndex(OutputModelTable.AUTHOR_LASTNAME)] = authorPerson.getLastname();
806
            csvLine[table.getIndex(OutputModelTable.AUTHOR_PREFIX)] = authorPerson.getPrefix();
807
            csvLine[table.getIndex(OutputModelTable.AUTHOR_SUFFIX)] = authorPerson.getSuffix();
808
        } else{
809
            // create an entry in rel table and all members in author table, check whether the team members already in author table
810

  
811
            Team authorTeam = (Team)author;
812
            int index = 0;
813
            for (Person member: authorTeam.getTeamMembers()){
814
                csvLineRel = new String[tableAuthorRel.getSize()];
815
                csvLineRel[tableAuthorRel.getIndex(OutputModelTable.AUTHOR_TEAM_FK)] = getId(state, authorTeam);
816
                csvLineRel[tableAuthorRel.getIndex(OutputModelTable.AUTHOR_FK)] = getId(state, member);
817
                csvLineRel[tableAuthorRel.getIndex(OutputModelTable.AUTHOR_TEAM_SEQ_NUMBER)] = String.valueOf(index);
818
                state.getProcessor().put(tableAuthorRel, authorTeam.getId() +":" +member.getId(), csvLineRel, state);
819

  
820
                if (state.getAuthorFromStore(member.getId()) == null){
821
                    state.addAuthorToStore(member);
822
                    csvLineMember = new String[table.getSize()];
823
                    csvLineMember[table.getIndex(OutputModelTable.AUTHOR_ID)] = getId(state, member);
824
                    csvLineMember[table.getIndex(OutputModelTable.ABBREV_AUTHOR)] = member.getNomenclaturalTitle();
825
                    csvLineMember[table.getIndex(OutputModelTable.AUTHOR_TITLE)] = member.getTitleCache();
826
                    csvLineMember[table.getIndex(OutputModelTable.AUTHOR_FIRST_NAME)] = member.getFirstname();
827
                    csvLineMember[table.getIndex(OutputModelTable.AUTHOR_LASTNAME)] = member.getLastname();
828
                    csvLineMember[table.getIndex(OutputModelTable.AUTHOR_PREFIX)] = member.getPrefix();
829
                    csvLineMember[table.getIndex(OutputModelTable.AUTHOR_SUFFIX)] = member.getSuffix();
830
                    state.getProcessor().put(table, member, csvLineMember, state);
831
                }
832
                index++;
872
    private void handleAuthor(OutputModelExportState state, TeamOrPersonBase<?> author) {
873
        try {
874
            if (state.getAuthorFromStore(author.getId()) != null){
875
                return;
876
            }
877
            state.addAuthorToStore(author);
878
            OutputModelTable table = OutputModelTable.NOMENCLATURAL_AUTHOR;
879
            String[] csvLine = new String[table.getSize()];
880
            OutputModelTable tableAuthorRel = OutputModelTable.NOMENCLATURAL_AUTHOR_TEAM_RELATION;
881
            String[] csvLineRel = new String[tableAuthorRel.getSize()];
882
            String[] csvLineMember = new String[table.getSize()];
883
            csvLine[table.getIndex(OutputModelTable.AUTHOR_ID)] = getId(state, author);
884
            csvLine[table.getIndex(OutputModelTable.ABBREV_AUTHOR)] = author.getNomenclaturalTitle();
885
            csvLine[table.getIndex(OutputModelTable.AUTHOR_TITLE)] = author.getTitleCache();
886
            author = HibernateProxyHelper.deproxy(author);
887
            if (author instanceof Person){
888
                Person authorPerson = (Person)author;
889
                csvLine[table.getIndex(OutputModelTable.AUTHOR_FIRST_NAME)] = authorPerson.getFirstname();
890
                csvLine[table.getIndex(OutputModelTable.AUTHOR_LASTNAME)] = authorPerson.getLastname();
891
                csvLine[table.getIndex(OutputModelTable.AUTHOR_PREFIX)] = authorPerson.getPrefix();
892
                csvLine[table.getIndex(OutputModelTable.AUTHOR_SUFFIX)] = authorPerson.getSuffix();
893
            } else{
894
                // create an entry in rel table and all members in author table, check whether the team members already in author table
895

  
896
                Team authorTeam = (Team)author;
897
                int index = 0;
898
                for (Person member: authorTeam.getTeamMembers()){
899
                    csvLineRel = new String[tableAuthorRel.getSize()];
900
                    csvLineRel[tableAuthorRel.getIndex(OutputModelTable.AUTHOR_TEAM_FK)] = getId(state, authorTeam);
901
                    csvLineRel[tableAuthorRel.getIndex(OutputModelTable.AUTHOR_FK)] = getId(state, member);
902
                    csvLineRel[tableAuthorRel.getIndex(OutputModelTable.AUTHOR_TEAM_SEQ_NUMBER)] = String.valueOf(index);
903
                    state.getProcessor().put(tableAuthorRel, authorTeam.getId() +":" +member.getId(), csvLineRel, state);
904

  
905
                    if (state.getAuthorFromStore(member.getId()) == null){
906
                        state.addAuthorToStore(member);
907
                        csvLineMember = new String[table.getSize()];
908
                        csvLineMember[table.getIndex(OutputModelTable.AUTHOR_ID)] = getId(state, member);
909
                        csvLineMember[table.getIndex(OutputModelTable.ABBREV_AUTHOR)] = member.getNomenclaturalTitle();
910
                        csvLineMember[table.getIndex(OutputModelTable.AUTHOR_TITLE)] = member.getTitleCache();
911
                        csvLineMember[table.getIndex(OutputModelTable.AUTHOR_FIRST_NAME)] = member.getFirstname();
912
                        csvLineMember[table.getIndex(OutputModelTable.AUTHOR_LASTNAME)] = member.getLastname();
913
                        csvLineMember[table.getIndex(OutputModelTable.AUTHOR_PREFIX)] = member.getPrefix();
914
                        csvLineMember[table.getIndex(OutputModelTable.AUTHOR_SUFFIX)] = member.getSuffix();
915
                        state.getProcessor().put(table, member, csvLineMember, state);
916
                    }
917
                    index++;
833 918

  
919
                }
834 920
            }
921
            state.getProcessor().put(table, author, csvLine, state);
922
        } catch (Exception e) {
923
            state.getResult().addException(e, "An unexpected error occurred when handling author " +
924
                    cdmBaseStr(author) + ": " + e.getMessage());
835 925
        }
836
        state.getProcessor().put(table, author, csvLine, state);
837

  
838

  
839

  
840

  
841 926
    }
842 927

  
843 928
    /**
929
     * @param state
844 930
     * @param name
845 931
     * @param statusString
846 932
     * @return
847 933
     */
848
    private String extractStatusString(TaxonName name, boolean abbrev) {
849
        Set<NomenclaturalStatus> status = name.getStatus();
850
        if (status.isEmpty()){
851
            return "";
852
        }
853
        String statusString = "";
854
        for (NomenclaturalStatus nameStatus: status){
855
            if (nameStatus != null){
856
                if (abbrev){
857
                    if (nameStatus.getType() != null){
858
                        statusString += nameStatus.getType().getIdInVocabulary();
859
                    }
860
                }else{
861
                    if (nameStatus.getType() != null){
862
                        statusString += nameStatus.getType().getTitleCache();
934
    private String extractStatusString(OutputModelExportState state, TaxonName name, boolean abbrev) {
935
        try {
936
            Set<NomenclaturalStatus> status = name.getStatus();
937
            if (status.isEmpty()){
938
                return "";
939
            }
940
            String statusString = "";
941
            for (NomenclaturalStatus nameStatus: status){
942
                if (nameStatus != null){
943
                    if (abbrev){
944
                        if (nameStatus.getType() != null){
945
                            statusString += nameStatus.getType().getIdInVocabulary();
946
                        }
947
                    }else{
948
                        if (nameStatus.getType() != null){
949
                            statusString += nameStatus.getType().getTitleCache();
950
                        }
863 951
                    }
864
                }
865
                if (!abbrev){
952
                    if (!abbrev){
866 953

  
867
                    if (nameStatus.getRuleConsidered() != null && !StringUtils.isBlank(nameStatus.getRuleConsidered())){
868
                        statusString += " " + nameStatus.getRuleConsidered();
869
                    }
870
                    if (nameStatus.getCitation() != null){
871
                        statusString += " " + nameStatus.getCitation().getTitleCache();
872
                    }
873
                    if (nameStatus.getCitationMicroReference() != null && !StringUtils.isBlank(nameStatus.getCitationMicroReference())){
874
                        statusString += " " + nameStatus.getCitationMicroReference();
954
                        if (nameStatus.getRuleConsidered() != null && !StringUtils.isBlank(nameStatus.getRuleConsidered())){
955
                            statusString += " " + nameStatus.getRuleConsidered();
956
                        }
957
                        if (nameStatus.getCitation() != null){
958
                            statusString += " " + nameStatus.getCitation().getTitleCache();
959
                        }
960
                        if (nameStatus.getCitationMicroReference() != null && !StringUtils.isBlank(nameStatus.getCitationMicroReference())){
961
                            statusString += " " + nameStatus.getCitationMicroReference();
962
                        }
875 963
                    }
964
                    statusString += " ";
876 965
                }
877
                statusString += " ";
878 966
            }
967
            return statusString;
968
        } catch (Exception e) {
969
            state.getResult().addException(e, "An unexpected error occurred when extracting status string for " +
970
                    cdmBaseStr(name) + ": " + e.getMessage());
971
            return "";
879 972
        }
880
        return statusString;
881 973
    }
882 974

  
883 975
    /**
884 976
     * @param group
885 977
     */
886 978
    private void handleHomotypicalGroup(OutputModelExportState state, HomotypicalGroup group) {
887
        state.addHomotypicalGroupToStore(group);
888
        OutputModelTable table = OutputModelTable.HOMOTYPIC_GROUP;
889
        String[] csvLine = new String[table.getSize()];
890

  
891
        csvLine[table.getIndex(OutputModelTable.HOMOTYPIC_GROUP_ID)] = getId(state, group);
892
        List<TaxonName> typifiedNames = new ArrayList<>();
893
        typifiedNames.addAll(group.getTypifiedNames());
894
        Collections.sort(typifiedNames, new HomotypicalGroupNameComparator(null, true));
895
        String typifiedNamesString = "";
896
        for (TaxonName name: typifiedNames){
897
            //Concatenated output string for homotypic group (names and citations) + status + some name relations (e.g. “non”)
898
//TODO: nameRelations, which and how to display
899

  
900

  
901
            typifiedNamesString += name.getTitleCache()+ extractStatusString(name, true) + "; ";
902
        }
903
        typifiedNamesString = typifiedNamesString.substring(0, typifiedNamesString.length()-2);
904
        if (typifiedNamesString != null){
905
            csvLine[table.getIndex(OutputModelTable.HOMOTYPIC_GROUP_STRING)] = typifiedNamesString.trim();
906
        }else{
907
            csvLine[table.getIndex(OutputModelTable.HOMOTYPIC_GROUP_STRING)] = "";
908
        }
909
        Set<TypeDesignationBase> typeDesigantions = group.getTypeDesignations();
910
        List<TypeDesignationBase> designationList = new ArrayList<>();
911
        designationList.addAll(typeDesigantions);
912
        Collections.sort(designationList, new TypeComparator());
913
        StringBuffer typeDesignationString = new StringBuffer();
914
        for (TypeDesignationBase typeDesignation: typeDesigantions){
915
            if (typeDesignation != null && typeDesignation.getTypeStatus() != null){
916
                typeDesignationString.append(typeDesignation.getTypeStatus().getTitleCache() + ": ");
979
        try {
980
            state.addHomotypicalGroupToStore(group);
981
            OutputModelTable table = OutputModelTable.HOMOTYPIC_GROUP;
982
            String[] csvLine = new String[table.getSize()];
983

  
984
            csvLine[table.getIndex(OutputModelTable.HOMOTYPIC_GROUP_ID)] = getId(state, group);
985
            List<TaxonName> typifiedNames = new ArrayList<>();
986
            typifiedNames.addAll(group.getTypifiedNames());
987
            Collections.sort(typifiedNames, new HomotypicalGroupNameComparator(null, true));
988
            String typifiedNamesString = "";
989
            for (TaxonName name: typifiedNames){
990
                //Concatenated output string for homotypic group (names and citations) + status + some name relations (e.g. “non”)
991
                //TODO: nameRelations, which and how to display
992

  
993

  
994
                typifiedNamesString += name.getTitleCache()+ extractStatusString(state, name, true) + "; ";
917 995
            }
918
            if (typeDesignation instanceof SpecimenTypeDesignation){
919
                if (((SpecimenTypeDesignation)typeDesignation).getTypeSpecimen() != null){
920
                    typeDesignationString.append(((SpecimenTypeDesignation)typeDesignation).getTypeSpecimen().getTitleCache());
921
                    handleSpecimen(state, ((SpecimenTypeDesignation)typeDesignation).getTypeSpecimen());
922
                }
996
            typifiedNamesString = typifiedNamesString.substring(0, typifiedNamesString.length()-2);
997
            if (typifiedNamesString != null){
998
                csvLine[table.getIndex(OutputModelTable.HOMOTYPIC_GROUP_STRING)] = typifiedNamesString.trim();
923 999
            }else{
924
                if (((NameTypeDesignation)typeDesignation).getTypeName() != null){
925
                    typeDesignationString.append(((NameTypeDesignation)typeDesignation).getTypeName().getTitleCache());
1000
                csvLine[table.getIndex(OutputModelTable.HOMOTYPIC_GROUP_STRING)] = "";
1001
            }
1002
            Set<TypeDesignationBase> typeDesigantions = group.getTypeDesignations();
1003
            List<TypeDesignationBase> designationList = new ArrayList<>();
1004
            designationList.addAll(typeDesigantions);
1005
            Collections.sort(designationList, new TypeComparator());
1006
            StringBuffer typeDesignationString = new StringBuffer();
1007
            for (TypeDesignationBase typeDesignation: typeDesigantions){
1008
                if (typeDesignation != null && typeDesignation.getTypeStatus() != null){
1009
                    typeDesignationString.append(typeDesignation.getTypeStatus().getTitleCache() + ": ");
926 1010
                }
1011
                if (typeDesignation instanceof SpecimenTypeDesignation){
1012
                    if (((SpecimenTypeDesignation)typeDesignation).getTypeSpecimen() != null){
1013
                        typeDesignationString.append(((SpecimenTypeDesignation)typeDesignation).getTypeSpecimen().getTitleCache());
1014
                        handleSpecimen(state, ((SpecimenTypeDesignation)typeDesignation).getTypeSpecimen());
1015
                    }
1016
                }else{
1017
                    if (((NameTypeDesignation)typeDesignation).getTypeName() != null){
1018
                        typeDesignationString.append(((NameTypeDesignation)typeDesignation).getTypeName().getTitleCache());
1019
                    }
1020
                }
1021
                if(typeDesignation.getCitation() != null ){
1022
                    typeDesignationString.append(", "+typeDesignation.getCitation().getTitleCache());
1023
                }
1024
                //TODO...
1025
                /*
1026
                 * Sortierung:
1027
                1.  Status der Typen: a) holo, lecto, neo, syn, b) epi, paralecto, c) para (wenn überhaupt) – die jeweiligen iso immer direct mit dazu
1028
                2.  Land
1029
                3.  Sammler
1030
                4.  Nummer
1031

  
1032
                Aufbau der Typusinformationen:
1033
                Land: Lokalität mit Höhe und Koordinaten; Datum; Sammler Nummer (Herbar/Barcode, Typusart; Herbar/Barcode, Typusart …)
1034

  
1035
                 */
927 1036
            }
928
            if(typeDesignation.getCitation() != null ){
929
                typeDesignationString.append(", "+typeDesignation.getCitation().getTitleCache());
1037
            String typeDesignations = typeDesignationString.toString();
1038
            if (typeDesignations != null){
1039
                csvLine[table.getIndex(OutputModelTable.TYPE_STRING)] = typeDesignations;
1040
            }else{
1041
                csvLine[table.getIndex(OutputModelTable.TYPE_STRING)] = "";
930 1042
            }
931
            //TODO...
932
            /*
933
             * Sortierung:
934
            1.  Status der Typen: a) holo, lecto, neo, syn, b) epi, paralecto, c) para (wenn überhaupt) – die jeweiligen iso immer direct mit dazu
935
            2.  Land
936
            3.  Sammler
937
            4.  Nummer
938

  
939
            Aufbau der Typusinformationen:
940
            Land: Lokalität mit Höhe und Koordinaten; Datum; Sammler Nummer (Herbar/Barcode, Typusart; Herbar/Barcode, Typusart …)
941

  
942
             */
943
        }
944
        String typeDesignations = typeDesignationString.toString();
945
        if (typeDesignations != null){
946
            csvLine[table.getIndex(OutputModelTable.TYPE_STRING)] = typeDesignations;
947
        }else{
948
            csvLine[table.getIndex(OutputModelTable.TYPE_STRING)] = "";
1043
            state.getProcessor().put(table, String.valueOf(group.getId()), csvLine, state);
1044
        } catch (Exception e) {
1045
            state.getResult().addException(e, "An unexpected error occurred when handling homotypic group " +
1046
                    cdmBaseStr(group) + ": " + e.getMessage());
949 1047
        }
950
        state.getProcessor().put(table, String.valueOf(group.getId()), csvLine, state);
951

  
952 1048
    }
953 1049

  
954 1050
    /**
955 1051
     * @param name
956 1052
     * @return
957 1053
     */
958
    private String getTropicosTitleCache(TaxonName name) {
959
        String basionymStart = "(";
960
        String basionymEnd = ") ";
961
        String exAuthorSeperator = " ex ";
962
        TeamOrPersonBase combinationAuthor = name.getCombinationAuthorship();
963
        TeamOrPersonBase exCombinationAuthor = name.getExCombinationAuthorship();
964
        TeamOrPersonBase basionymAuthor = name.getBasionymAuthorship();
965
        TeamOrPersonBase exBasionymAuthor = name.getExBasionymAuthorship();
966

  
967
        String combinationAuthorString = "";
968
        if (combinationAuthor != null){
969
            combinationAuthor = HibernateProxyHelper.deproxy(combinationAuthor);
970
            if (combinationAuthor instanceof Team){
971
                combinationAuthorString = createTropicosTeamTitle(combinationAuthor);
972
            }else{
973
                Person person = HibernateProxyHelper.deproxy(combinationAuthor, Person.class);
974
                combinationAuthorString = createTropicosAuthorString(person);
1054
    private String getTropicosTitleCache(OutputModelExportState state, TaxonName name) {
1055
        try {
1056
            String basionymStart = "(";
1057
            String basionymEnd = ") ";
1058
            String exAuthorSeperator = " ex ";
1059
            TeamOrPersonBase<?> combinationAuthor = name.getCombinationAuthorship();
1060
            TeamOrPersonBase<?> exCombinationAuthor = name.getExCombinationAuthorship();
1061
            TeamOrPersonBase<?> basionymAuthor = name.getBasionymAuthorship();
1062
            TeamOrPersonBase<?> exBasionymAuthor = name.getExBasionymAuthorship();
1063

  
1064
            String combinationAuthorString = "";
1065
            if (combinationAuthor != null){
1066
                combinationAuthor = HibernateProxyHelper.deproxy(combinationAuthor);
1067
                if (combinationAuthor instanceof Team){
1068
                    combinationAuthorString = createTropicosTeamTitle(combinationAuthor);
1069
                }else{
1070
                    Person person = HibernateProxyHelper.deproxy(combinationAuthor, Person.class);
1071
                    combinationAuthorString = createTropicosAuthorString(person);
1072
                }
975 1073
            }
976
        }
977
        String exCombinationAuthorString = "";
978
        if (exCombinationAuthor != null){
979
            exCombinationAuthor = HibernateProxyHelper.deproxy(exCombinationAuthor);
980
            if (exCombinationAuthor instanceof Team){
981
               exCombinationAuthorString = createTropicosTeamTitle(exCombinationAuthor);
982
            }else{
983
                Person person = HibernateProxyHelper.deproxy(exCombinationAuthor, Person.class);
984
                exCombinationAuthorString = createTropicosAuthorString(person);
1074
            String exCombinationAuthorString = "";
1075
            if (exCombinationAuthor != null){
1076
                exCombinationAuthor = HibernateProxyHelper.deproxy(exCombinationAuthor);
1077
                if (exCombinationAuthor instanceof Team){
1078
                   exCombinationAuthorString = createTropicosTeamTitle(exCombinationAuthor);
1079
                }else{
1080
                    Person person = HibernateProxyHelper.deproxy(exCombinationAuthor, Person.class);
1081
                    exCombinationAuthorString = createTropicosAuthorString(person);
1082
                }
985 1083
            }
986
        }
987 1084

  
988
        String basionymAuthorString = "";
989
        if (basionymAuthor != null){
990
            basionymAuthor = HibernateProxyHelper.deproxy(basionymAuthor);
991
            if (basionymAuthor instanceof Team){
992
                basionymAuthorString =  createTropicosTeamTitle(basionymAuthor);
993
            }else{
994
                Person person = HibernateProxyHelper.deproxy(basionymAuthor, Person.class);
995
                basionymAuthorString = createTropicosAuthorString(person);
1085
            String basionymAuthorString = "";
1086
            if (basionymAuthor != null){
1087
                basionymAuthor = HibernateProxyHelper.deproxy(basionymAuthor);
1088
                if (basionymAuthor instanceof Team){
1089
                    basionymAuthorString =  createTropicosTeamTitle(basionymAuthor);
1090
                }else{
1091
                    Person person = HibernateProxyHelper.deproxy(basionymAuthor, Person.class);
1092
                    basionymAuthorString = createTropicosAuthorString(person);
1093
                }
996 1094
            }
997
        }
998 1095

  
999
        String exBasionymAuthorString = "";
1096
            String exBasionymAuthorString = "";
1000 1097

  
1001
        if (exBasionymAuthor != null){
1002
;            exBasionymAuthor = HibernateProxyHelper.deproxy(exBasionymAuthor);
1003
            if (exBasionymAuthor instanceof Team){
1004
                exBasionymAuthorString = createTropicosTeamTitle(exBasionymAuthor);
1098
            if (exBasionymAuthor != null){
1099
                exBasionymAuthor = HibernateProxyHelper.deproxy(exBasionymAuthor);
1100
                if (exBasionymAuthor instanceof Team){
1101
                    exBasionymAuthorString = createTropicosTeamTitle(exBasionymAuthor);
1005 1102

  
1006
            }else{
1007
                Person person = HibernateProxyHelper.deproxy(exBasionymAuthor, Person.class);
1008
                exBasionymAuthorString = createTropicosAuthorString(person);
1103
                }else{
1104
                    Person person = HibernateProxyHelper.deproxy(exBasionymAuthor, Person.class);
1105
                    exBasionymAuthorString = createTropicosAuthorString(person);
1106
                }
1009 1107
            }
1010
        }
1011
        String completeAuthorString =  name.getNameCache() + " ";
1108
            String completeAuthorString =  name.getNameCache() + " ";
1012 1109

  
1013
        completeAuthorString += (!CdmUtils.isBlank(exBasionymAuthorString) || !CdmUtils.isBlank(basionymAuthorString)) ? basionymStart: "";
1014
        completeAuthorString += (!CdmUtils.isBlank(exBasionymAuthorString)) ? (CdmUtils.Nz(exBasionymAuthorString) + exAuthorSeperator): "" ;
1015
        completeAuthorString += (!CdmUtils.isBlank(basionymAuthorString))? CdmUtils.Nz(basionymAuthorString):"";
1016
        completeAuthorString += (!CdmUtils.isBlank(exBasionymAuthorString) || !CdmUtils.isBlank(basionymAuthorString)) ?  basionymEnd:"";
1017
        completeAuthorString += (!CdmUtils.isBlank(exCombinationAuthorString)) ? (CdmUtils.Nz(exCombinationAuthorString) + exAuthorSeperator): "" ;
1018
        completeAuthorString += (!CdmUtils.isBlank(combinationAuthorString))? CdmUtils.Nz(combinationAuthorString):"";
1110
            completeAuthorString += (!CdmUtils.isBlank(exBasionymAuthorString) || !CdmUtils.isBlank(basionymAuthorString)) ? basionymStart: "";
1111
            completeAuthorString += (!CdmUtils.isBlank(exBasionymAuthorString)) ? (CdmUtils.Nz(exBasionymAuthorString) + exAuthorSeperator): "" ;
1112
            completeAuthorString += (!CdmUtils.isBlank(basionymAuthorString))? CdmUtils.Nz(basionymAuthorString):"";
1113
            completeAuthorString += (!CdmUtils.isBlank(exBasionymAuthorString) || !CdmUtils.isBlank(basionymAuthorString)) ?  basionymEnd:"";
1114
            completeAuthorString += (!CdmUtils.isBlank(exCombinationAuthorString)) ? (CdmUtils.Nz(exCombinationAuthorString) + exAuthorSeperator): "" ;
1115
            completeAuthorString += (!CdmUtils.isBlank(combinationAuthorString))? CdmUtils.Nz(combinationAuthorString):"";
1019 1116

  
1020 1117

  
1021
        return completeAuthorString;
1118
            return completeAuthorString;
1119
        } catch (ClassCastException e) {
1120
            state.getResult().addException(e, "An unexpected error occurred when handling tropicos title cache for " +
1121
                    cdmBaseStr(name) + ": " + e.getMessage());
1122
            return null;
1123
        }
1022 1124
    }
1023 1125

  
1024 1126
    /**
1025 1127
     * @param combinationAuthor
1026 1128
     * @return
1027 1129
     */
1028
    private String createTropicosTeamTitle(TeamOrPersonBase combinationAuthor) {
1130
    private String createTropicosTeamTitle(TeamOrPersonBase<?> combinationAuthor) {
1029 1131
        String combinationAuthorString;
1030 1132
        Team team = HibernateProxyHelper.deproxy(combinationAuthor, Team.class);
1031 1133
        Team tempTeam = Team.NewInstance();
......
1090 1192
     * @param name
1091 1193
     */
1092 1194
    private void handleReference(OutputModelExportState state, Reference reference) {
1093
        state.addReferenceToStore(reference);
1094
        OutputModelTable table = OutputModelTable.REFERENCE;
1095

  
1096
        String[] csvLine = new String[table.getSize()];
1097
        csvLine[table.getIndex(OutputModelTable.REFERENCE_ID)] = getId(state, reference);
1098
        //TODO short citations correctly
1099
        String shortCitation = createShortCitation(reference);  //Should be Author(year) like in Taxon.sec
1100
        csvLine[table.getIndex(OutputModelTable.BIBLIO_SHORT_CITATION)] = shortCitation;
1101
        //TODO get preferred title
1102
        csvLine[table.getIndex(OutputModelTable.REF_TITLE)] = reference.getTitle();
1103
        csvLine[table.getIndex(OutputModelTable.ABBREV_REF_TITLE)] = reference.getTitle();
1104
        csvLine[table.getIndex(OutputModelTable.DATE_PUBLISHED)] = reference.getDatePublishedString();
1105
        //TBC
1106
        csvLine[table.getIndex(OutputModelTable.EDITION)] = reference.getEdition();
1107
        csvLine[table.getIndex(OutputModelTable.EDITOR)] = reference.getEditor();
1108
        csvLine[table.getIndex(OutputModelTable.ISBN)] = reference.getIsbn();
1109
        csvLine[table.getIndex(OutputModelTable.ISSN)] = reference.getIssn();
1110
        csvLine[table.getIndex(OutputModelTable.ORGANISATION)] = reference.getOrganization();
1111
        csvLine[table.getIndex(OutputModelTable.PAGES)] = reference.getPages();
1112
        csvLine[table.getIndex(OutputModelTable.PLACE_PUBLISHED)] = reference.getPlacePublished();
1113
        csvLine[table.getIndex(OutputModelTable.PUBLISHER)] = reference.getPublisher();
1114
        csvLine[table.getIndex(OutputModelTable.REF_ABSTRACT)] = reference.getReferenceAbstract();
1115
        csvLine[table.getIndex(OutputModelTable.SERIES_PART)] = reference.getSeriesPart();
1116
        csvLine[table.getIndex(OutputModelTable.VOLUME)] = reference.getVolume();
1117
        csvLine[table.getIndex(OutputModelTable.YEAR)] = reference.getYear();
1118
        if ( reference.getAuthorship() != null){
1119
            csvLine[table.getIndex(OutputModelTable.AUTHORSHIP_TITLE)] = reference.getAuthorship().getTitleCache();
1120
            csvLine[table.getIndex(OutputModelTable.AUTHOR_FK)] = getId(state,reference.getAuthorship());
1121
        }
1195
        try {
1196
            state.addReferenceToStore(reference);
1197
            OutputModelTable table = OutputModelTable.REFERENCE;
1198

  
1199
            String[] csvLine = new String[table.getSize()];
1200
            csvLine[table.getIndex(OutputModelTable.REFERENCE_ID)] = getId(state, reference);
1201
            //TODO short citations correctly
1202
            String shortCitation = createShortCitation(reference);  //Should be Author(year) like in Taxon.sec
1203
            csvLine[table.getIndex(OutputModelTable.BIBLIO_SHORT_CITATION)] = shortCitation;
1204
            //TODO get preferred title
1205
            csvLine[table.getIndex(OutputModelTable.REF_TITLE)] = reference.getTitle();
1206
            csvLine[table.getIndex(OutputModelTable.ABBREV_REF_TITLE)] = reference.getTitle();
1207
            csvLine[table.getIndex(OutputModelTable.DATE_PUBLISHED)] = reference.getDatePublishedString();
1208
            //TBC
1209
            csvLine[table.getIndex(OutputModelTable.EDITION)] = reference.getEdition();
1210
            csvLine[table.getIndex(OutputModelTable.EDITOR)] = reference.getEditor();
1211
            csvLine[table.getIndex(OutputModelTable.ISBN)] = reference.getIsbn();
1212
            csvLine[table.getIndex(OutputModelTable.ISSN)] = reference.getIssn();
1213
            csvLine[table.getIndex(OutputModelTable.ORGANISATION)] = reference.getOrganization();
1214
            csvLine[table.getIndex(OutputModelTable.PAGES)] = reference.getPages();
1215
            csvLine[table.getIndex(OutputModelTable.PLACE_PUBLISHED)] = reference.getPlacePublished();
1216
            csvLine[table.getIndex(OutputModelTable.PUBLISHER)] = reference.getPublisher();
1217
            csvLine[table.getIndex(OutputModelTable.REF_ABSTRACT)] = reference.getReferenceAbstract();
1218
            csvLine[table.getIndex(OutputModelTable.SERIES_PART)] = reference.getSeriesPart();
1219
            csvLine[table.getIndex(OutputModelTable.VOLUME)] = reference.getVolume();
1220
            csvLine[table.getIndex(OutputModelTable.YEAR)] = reference.getYear();
1221
            if ( reference.getAuthorship() != null){
1222
                csvLine[table.getIndex(OutputModelTable.AUTHORSHIP_TITLE)] = reference.getAuthorship().getTitleCache();
1223
                csvLine[table.getIndex(OutputModelTable.AUTHOR_FK)] = getId(state,reference.getAuthorship());
1224
            }
1122 1225

  
1123
        csvLine[table.getIndex(OutputModelTable.IN_REFERENCE)] = getId(state, reference.getInReference());
1124
        if (reference.getInReference() != null && state.getReferenceFromStore(reference.getInReference().getId()) == null){
1125
            handleReference(state, reference.getInReference());
1226
            csvLine[table.getIndex(OutputModelTable.IN_REFERENCE)] = getId(state, reference.getInReference());
1227
            if (reference.getInReference() != null && state.getReferenceFromStore(reference.getInReference().getId()) == null){
1228
                handleReference(state, reference.getInReference());
1229
            }
1230
            if ( reference.getInstitution() != null){ csvLine[table.getIndex(OutputModelTable.INSTITUTION)] = reference.getInstitution().getTitleCache();}
1231
            if ( reference.getLsid() != null){ csvLine[table.getIndex(OutputModelTable.LSID)] = reference.getLsid().getLsid();}
1232
            if ( reference.getSchool() != null){ csvLine[table.getIndex(OutputModelTable.SCHOOL)] = reference.getSchool().getTitleCache();}
1233
            if ( reference.getUri() != null){ csvLine[table.getIndex(OutputModelTable.URI)] = reference.getUri().toString();}
1234
            csvLine[table.getIndex(OutputModelTable.REF_TYPE)] = reference.getType().getKey();
1235

  
1236
            state.getProcessor().put(table, reference, csvLine, state);
1237
        } catch (Exception e) {
1238
            state.getResult().addException(e, "An unexpected error occurred when handling reference " +
1239
                    cdmBaseStr(reference) + ": " + e.getMessage());
1126 1240
        }
1127
        if ( reference.getInstitution() != null){ csvLine[table.getIndex(OutputModelTable.INSTITUTION)] = reference.getInstitution().getTitleCache();}
1128
        if ( reference.getLsid() != null){ csvLine[table.getIndex(OutputModelTable.LSID)] = reference.getLsid().getLsid();}
1129
        if ( reference.getSchool() != null){ csvLine[table.getIndex(OutputModelTable.SCHOOL)] = reference.getSchool().getTitleCache();}
1130
        if ( reference.getUri() != null){ csvLine[table.getIndex(OutputModelTable.URI)] = reference.getUri().toString();}
1131
        csvLine[table.getIndex(OutputModelTable.REF_TYPE)] = reference.getType().getKey();
1132

  
1133
        state.getProcessor().put(table, reference, csvLine, state);
1134 1241

  
1135 1242
    }
1136 1243

  
......
1140 1247
     * @return
1141 1248
     */
1142 1249
    private String createShortCitation(Reference reference) {
1143
        TeamOrPersonBase authorship = reference.getAuthorship();
1250
        TeamOrPersonBase<?> authorship = reference.getAuthorship();
1144 1251
        String shortCitation = "";
1145 1252
        if (authorship == null) {
1146 1253
            return null;
......
1188 1295
     */
1189 1296

  
1190 1297
    private void handleSpecimenTypeDesignations(OutputModelExportState state, TaxonName name){
1191
       Set<SpecimenTypeDesignation> typeDesignations = name.getSpecimenTypeDesignations();
1192
       OutputModelTable table = OutputModelTable.TYPE_DESIGNATION;
1193
       String nameId = getId(state, name);
1194
       String[] csvLine = new String[table.getSize()];
1195
        for (SpecimenTypeDesignation specimenType: typeDesignations){
1196
            csvLine = new String[table.getSize()];
1197
            DerivedUnit specimen = specimenType.getTypeSpecimen();
1198
            if (state.getSpecimenFromStore(specimen.getId()) == null){
1199
                handleSpecimen(state, specimen);
1298
       try {
1299
           Set<SpecimenTypeDesignation> typeDesignations = name.getSpecimenTypeDesignations();
1300
           OutputModelTable table = OutputModelTable.TYPE_DESIGNATION;
1301
           String nameId = getId(state, name);
1302
           String[] csvLine = new String[table.getSize()];
1303
            for (SpecimenTypeDesignation specimenType: typeDesignations){
1304
                csvLine = new String[table.getSize()];
1305
                DerivedUnit specimen = specimenType.getTypeSpecimen();
1306
                if (state.getSpecimenFromStore(specimen.getId()) == null){
1307
                    handleSpecimen(state, specimen);
1308
                }
1309
                csvLine[table.getIndex(OutputModelTable.SPECIMEN_FK)] = getId(state, specimenType.getTypeSpecimen());
1310
                csvLine[table.getIndex(OutputModelTable.NAME_FK)] = nameId;
1311
                csvLine[table.getIndex(OutputModelTable.TYPE_VERBATIM_CITATION)] = specimenType.getTypeSpecimen().generateTitle();
1312
                //TODO: add link to existing Vorcabulary
1313
                csvLine[table.getIndex(OutputModelTable.TYPE_CATEGORY)] = "";
1314
                csvLine[table.getIndex(OutputModelTable.TYPE_DESIGNATED_BY_STRING)] = specimenType.getCitation().getTitleCache();
1315
                csvLine[table.getIndex(OutputModelTable.TYPE_DESIGNATED_BY_REF_FK)] = getId(state, specimenType.getCitation());
1200 1316
            }
1201
            csvLine[table.getIndex(OutputModelTable.SPECIMEN_FK)] = getId(state, specimenType.getTypeSpecimen());
1202
            csvLine[table.getIndex(OutputModelTable.NAME_FK)] = nameId;
1203
            csvLine[table.getIndex(OutputModelTable.TYPE_VERBATIM_CITATION)] = specimenType.getTypeSpecimen().generateTitle();
1204
            //TODO: add link to existing Vorcabulary
1205
            csvLine[table.getIndex(OutputModelTable.TYPE_CATEGORY)] = "";
1206
            csvLine[table.getIndex(OutputModelTable.TYPE_DESIGNATED_BY_STRING)] = specimenType.getCitation().getTitleCache();
1207
            csvLine[table.getIndex(OutputModelTable.TYPE_DESIGNATED_BY_REF_FK)] = getId(state, specimenType.getCitation());
1317
        } catch (Exception e) {
1318
            state.getResult().addException(e, "An unexpected error occurred when handling specimen type designations for " +
1319
                    cdmBaseStr(name) + ": " + e.getMessage());
1208 1320
        }
1209 1321
    }
1210 1322

  
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)