2 * Copyright (C) 2017 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
9 package eu
.etaxonomy
.cdm
.io
.cdmLight
;
12 import java
.util
.ArrayList
;
13 import java
.util
.Collection
;
14 import java
.util
.Collections
;
15 import java
.util
.Comparator
;
16 import java
.util
.HashMap
;
17 import java
.util
.HashSet
;
18 import java
.util
.Iterator
;
19 import java
.util
.List
;
22 import java
.util
.UUID
;
24 import org
.apache
.commons
.lang3
.StringUtils
;
25 import org
.springframework
.beans
.factory
.annotation
.Autowired
;
26 import org
.springframework
.stereotype
.Component
;
28 import eu
.etaxonomy
.cdm
.api
.service
.dto
.CondensedDistribution
;
29 import eu
.etaxonomy
.cdm
.api
.service
.name
.TypeDesignationSetFormatter
;
30 import eu
.etaxonomy
.cdm
.api
.service
.name
.TypeDesignationSetManager
;
31 import eu
.etaxonomy
.cdm
.common
.CdmUtils
;
32 import eu
.etaxonomy
.cdm
.common
.monitor
.IProgressMonitor
;
33 import eu
.etaxonomy
.cdm
.compare
.name
.TypeComparator
;
34 import eu
.etaxonomy
.cdm
.compare
.taxon
.HomotypicGroupTaxonComparator
;
35 import eu
.etaxonomy
.cdm
.ext
.geo
.IEditGeoService
;
36 import eu
.etaxonomy
.cdm
.filter
.TaxonNodeFilter
;
37 import eu
.etaxonomy
.cdm
.format
.reference
.OriginalSourceFormatter
;
38 import eu
.etaxonomy
.cdm
.hibernate
.HibernateProxyHelper
;
39 import eu
.etaxonomy
.cdm
.io
.common
.CdmExportBase
;
40 import eu
.etaxonomy
.cdm
.io
.common
.ExportResult
.ExportResultState
;
41 import eu
.etaxonomy
.cdm
.io
.common
.TaxonNodeOutStreamPartitioner
;
42 import eu
.etaxonomy
.cdm
.io
.common
.XmlExportState
;
43 import eu
.etaxonomy
.cdm
.io
.common
.mapping
.out
.IExportTransformer
;
44 import eu
.etaxonomy
.cdm
.model
.agent
.AgentBase
;
45 import eu
.etaxonomy
.cdm
.model
.agent
.Person
;
46 import eu
.etaxonomy
.cdm
.model
.agent
.Team
;
47 import eu
.etaxonomy
.cdm
.model
.agent
.TeamOrPersonBase
;
48 import eu
.etaxonomy
.cdm
.model
.common
.Annotation
;
49 import eu
.etaxonomy
.cdm
.model
.common
.AnnotationType
;
50 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
51 import eu
.etaxonomy
.cdm
.model
.common
.ICdmBase
;
52 import eu
.etaxonomy
.cdm
.model
.common
.IIdentifiableEntity
;
53 import eu
.etaxonomy
.cdm
.model
.common
.IdentifiableEntity
;
54 import eu
.etaxonomy
.cdm
.model
.common
.IdentifiableSource
;
55 import eu
.etaxonomy
.cdm
.model
.common
.Identifier
;
56 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
57 import eu
.etaxonomy
.cdm
.model
.common
.LanguageString
;
58 import eu
.etaxonomy
.cdm
.model
.description
.CommonTaxonName
;
59 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionBase
;
60 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionElementBase
;
61 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionElementSource
;
62 import eu
.etaxonomy
.cdm
.model
.description
.Distribution
;
63 import eu
.etaxonomy
.cdm
.model
.description
.Feature
;
64 import eu
.etaxonomy
.cdm
.model
.description
.IndividualsAssociation
;
65 import eu
.etaxonomy
.cdm
.model
.description
.TaxonDescription
;
66 import eu
.etaxonomy
.cdm
.model
.description
.TaxonInteraction
;
67 import eu
.etaxonomy
.cdm
.model
.description
.TaxonNameDescription
;
68 import eu
.etaxonomy
.cdm
.model
.description
.TextData
;
69 import eu
.etaxonomy
.cdm
.model
.location
.NamedArea
;
70 import eu
.etaxonomy
.cdm
.model
.media
.ExternalLink
;
71 import eu
.etaxonomy
.cdm
.model
.media
.Media
;
72 import eu
.etaxonomy
.cdm
.model
.media
.MediaRepresentation
;
73 import eu
.etaxonomy
.cdm
.model
.media
.MediaRepresentationPart
;
74 import eu
.etaxonomy
.cdm
.model
.name
.HomotypicalGroup
;
75 import eu
.etaxonomy
.cdm
.model
.name
.NameRelationship
;
76 import eu
.etaxonomy
.cdm
.model
.name
.NameRelationshipType
;
77 import eu
.etaxonomy
.cdm
.model
.name
.NameTypeDesignation
;
78 import eu
.etaxonomy
.cdm
.model
.name
.NomenclaturalSource
;
79 import eu
.etaxonomy
.cdm
.model
.name
.NomenclaturalStatus
;
80 import eu
.etaxonomy
.cdm
.model
.name
.Rank
;
81 import eu
.etaxonomy
.cdm
.model
.name
.SpecimenTypeDesignation
;
82 import eu
.etaxonomy
.cdm
.model
.name
.TaxonName
;
83 import eu
.etaxonomy
.cdm
.model
.name
.TextualTypeDesignation
;
84 import eu
.etaxonomy
.cdm
.model
.name
.TypeDesignationBase
;
85 import eu
.etaxonomy
.cdm
.model
.occurrence
.DerivedUnit
;
86 import eu
.etaxonomy
.cdm
.model
.occurrence
.FieldUnit
;
87 import eu
.etaxonomy
.cdm
.model
.occurrence
.GatheringEvent
;
88 import eu
.etaxonomy
.cdm
.model
.occurrence
.MediaSpecimen
;
89 import eu
.etaxonomy
.cdm
.model
.occurrence
.SpecimenOrObservationBase
;
90 import eu
.etaxonomy
.cdm
.model
.reference
.NamedSource
;
91 import eu
.etaxonomy
.cdm
.model
.reference
.OriginalSourceType
;
92 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
93 import eu
.etaxonomy
.cdm
.model
.reference
.ReferenceType
;
94 import eu
.etaxonomy
.cdm
.model
.taxon
.Classification
;
95 import eu
.etaxonomy
.cdm
.model
.taxon
.Synonym
;
96 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
97 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
98 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
99 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonRelationship
;
100 import eu
.etaxonomy
.cdm
.model
.term
.DefinedTerm
;
101 import eu
.etaxonomy
.cdm
.persistence
.dto
.TaxonNodeDto
;
102 import eu
.etaxonomy
.cdm
.persistence
.dto
.TaxonNodeDtoByRankAndNameComparator
;
103 import eu
.etaxonomy
.cdm
.strategy
.cache
.HTMLTagRules
;
104 import eu
.etaxonomy
.cdm
.strategy
.cache
.TagEnum
;
105 import eu
.etaxonomy
.cdm
.strategy
.cache
.TaggedText
;
106 import eu
.etaxonomy
.cdm
.strategy
.exceptions
.UnknownCdmTypeException
;
113 public class CdmLightClassificationExport
114 extends CdmExportBase
<CdmLightExportConfigurator
, CdmLightExportState
, IExportTransformer
, File
>{
116 private static final long serialVersionUID
= 2518643632756927053L;
118 private static final String IPNI_NAME_IDENTIFIER
= "Ipni Name Identifier";
119 private static final String TROPICOS_NAME_IDENTIFIER
= "Tropicos Name Identifier";
120 private static final String WFO_NAME_IDENTIFIER
= "WFO Name Identifier";
123 IEditGeoService geoService
;
125 public CdmLightClassificationExport() {
127 this.ioName
= this.getClass().getSimpleName();
131 public long countSteps(CdmLightExportState state
) {
132 TaxonNodeFilter filter
= state
.getConfig().getTaxonNodeFilter();
133 return getTaxonNodeService().count(filter
);
137 protected void doInvoke(CdmLightExportState state
) {
140 IProgressMonitor monitor
= state
.getConfig().getProgressMonitor();
141 CdmLightExportConfigurator config
= state
.getConfig();
142 if (config
.getTaxonNodeFilter().hasClassificationFilter()) {
143 Classification classification
= getClassificationService()
144 .load(config
.getTaxonNodeFilter().getClassificationFilter().get(0).getUuid());
145 state
.setRootId(classification
.getRootNode().getUuid());
147 } else if (config
.getTaxonNodeFilter().hasSubtreeFilter()) {
148 state
.setRootId(config
.getTaxonNodeFilter().getSubtreeFilter().get(0).getUuid());
150 @SuppressWarnings("unchecked")
151 TaxonNodeOutStreamPartitioner
<XmlExportState
> partitioner
= TaxonNodeOutStreamPartitioner
.NewInstance(this,
152 state
, state
.getConfig().getTaxonNodeFilter(), 100, monitor
, null);
154 handleMetaData(state
);
155 monitor
.subTask("Start partitioning");
157 TaxonNode node
= partitioner
.next();
158 while (node
!= null) {
159 handleTaxonNode(state
, node
);
160 node
= partitioner
.next();
162 // get rootNode and create helperObjects
163 if (state
.getRootId() != null) {
164 List
<TaxonNodeDto
> childrenOfRoot
= state
.getNodeChildrenMap().get(state
.getRootId());
166 Comparator
<TaxonNodeDto
> comp
= state
.getConfig().getComparator();
168 comp
= new TaxonNodeDtoByRankAndNameComparator();
170 if (childrenOfRoot
!= null) {
171 Collections
.sort(childrenOfRoot
, comp
);
172 OrderHelper helper
= new OrderHelper(state
.getRootId());
173 helper
.setOrderIndex(state
.getActualOrderIndexAndUpdate());
174 state
.getOrderHelperMap().put(state
.getRootId(), helper
);
176 for (TaxonNodeDto child
: childrenOfRoot
) {
177 OrderHelper childHelper
= new OrderHelper(child
.getTaxonUuid());
178 helper
.addChild(childHelper
);
179 childHelper
.setOrderIndex(state
.getActualOrderIndexAndUpdate());
180 childHelper
.addChildren(
181 createOrderHelper(state
.getNodeChildrenMap().get(child
.getUuid()), state
));
185 state
.getNodeChildrenMap().clear();
186 for (OrderHelper order
: state
.getOrderHelperMap().values()) {
187 setOrderIndex(state
, order
);
191 state
.getProcessor().createFinalResult(state
);
192 } catch (Exception e
) {
193 state
.getResult().addException(e
,
194 "An unexpected error occurred in main method doInvoke() " + e
.getMessage());
199 private void setOrderIndex(CdmLightExportState state
, OrderHelper order
) {
201 if (order
.getTaxonUuid() != null
202 && state
.getProcessor().hasRecord(CdmLightExportTable
.TAXON
, order
.getTaxonUuid().toString())) {
203 String
[] csvLine
= state
.getProcessor().getRecord(CdmLightExportTable
.TAXON
,
204 order
.getTaxonUuid().toString());
205 csvLine
[CdmLightExportTable
.TAXON
.getIndex(CdmLightExportTable
.SORT_INDEX
)] = String
206 .valueOf(order
.getOrderIndex());
209 if (order
.getChildren() == null) {
212 for (OrderHelper helper
: order
.getChildren()) {
213 setOrderIndex(state
, helper
);
217 private List
<OrderHelper
> createOrderHelper(List
<TaxonNodeDto
> nodes
, CdmLightExportState state
) {
218 List
<TaxonNodeDto
> children
= nodes
;
219 // alreadySortedNodes.add(parentUuid);
220 if (children
== null) {
223 Comparator
<TaxonNodeDto
> comp
= state
.getConfig().getComparator();
225 comp
= new TaxonNodeDtoByRankAndNameComparator();
227 Collections
.sort(children
, comp
);
228 // TODO: nochmal checken!!!
229 OrderHelper helperChild
;
230 List
<OrderHelper
> childrenHelper
= new ArrayList
<>();
231 for (TaxonNodeDto child
: children
) {
232 helperChild
= new OrderHelper(child
.getTaxonUuid());
233 helperChild
.setOrderIndex(state
.getActualOrderIndexAndUpdate());
235 if (state
.getNodeChildrenMap().get(child
.getUuid()) != null) {
236 children
= state
.getNodeChildrenMap().get(child
.getUuid());
237 helperChild
.addChildren(createOrderHelper(children
, state
));
239 childrenHelper
.add(helperChild
);
241 return childrenHelper
;
244 private void handleTaxonNode(CdmLightExportState state
, TaxonNode taxonNode
) {
246 if (taxonNode
== null) {
247 String message
= "TaxonNode for given taxon node UUID not found. ";
249 state
.getResult().addWarning(message
);
252 TaxonNode root
= taxonNode
;
253 List
<TaxonNodeDto
> childNodes
;
254 if (root
.hasChildNodes()) {
255 childNodes
= new ArrayList
<>();
256 for (TaxonNode child
: root
.getChildNodes()) {
258 childNodes
.add(new TaxonNodeDto(child
));
261 state
.getNodeChildrenMap().put(root
.getUuid(), childNodes
);
263 // add root to node map
266 TaxonNodeDto rootDto
= new TaxonNodeDto(root
);
267 UUID parentUuid
= root
.getParent() != null ? root
.getParent().getUuid()
268 : state
.getClassificationUUID(root
);
269 List
<TaxonNodeDto
> children
= state
.getNodeChildrenMap().get(parentUuid
);
270 if (children
!= null && !children
.contains(rootDto
)) {
271 state
.getNodeChildrenMap().get(parentUuid
).add(rootDto
);
272 } else if (state
.getNodeChildrenMap().get(parentUuid
) == null) {
273 List
<TaxonNodeDto
> rootList
= new ArrayList
<>();
274 rootList
.add(rootDto
);
275 state
.getNodeChildrenMap().put(parentUuid
, rootList
);
278 if (root
.hasTaxon()) {
279 handleTaxon(state
, root
);
282 } catch (Exception e
) {
283 state
.getResult().addException(e
, "An unexpected error occurred when handling taxonNode "
284 + taxonNode
.getUuid() + ": " + e
.getMessage() + e
.getStackTrace());
289 private void handleTaxon(CdmLightExportState state
, TaxonNode taxonNode
) {
292 if (taxonNode
== null) {
293 state
.getResult().addError("The taxonNode was null.", "handleTaxon");
294 state
.getResult().setState(ExportResultState
.INCOMPLETE_WITH_ERROR
);
297 if (taxonNode
.getTaxon() == null) {
298 state
.getResult().addError("There was a taxon node without a taxon: " + taxonNode
.getUuid(),
300 state
.getResult().setState(ExportResultState
.INCOMPLETE_WITH_ERROR
);
302 Taxon taxon
= CdmBase
.deproxy(taxonNode
.getTaxon());
305 TaxonName name
= taxon
.getName();
306 handleName(state
, name
, taxon
, true);
307 HomotypicalGroup homotypicGroup
= taxon
.getHomotypicGroup();
309 int homotypicGroupIndex
= 0;
310 handleHomotypicalGroup(state
, homotypicGroup
, taxon
, homotypicGroupIndex
);
311 homotypicGroupIndex
++;
312 for (Synonym syn
: taxon
.getSynonymsInGroup(homotypicGroup
)) {
313 handleSynonym(state
, syn
, index
);
316 List
<HomotypicalGroup
> heterotypicHomotypicGroups
= taxon
.getHeterotypicSynonymyGroups();
317 for (HomotypicalGroup group
: heterotypicHomotypicGroups
){
318 handleHomotypicalGroup(state
, group
, taxon
, homotypicGroupIndex
);
319 for (Synonym syn
: taxon
.getSynonymsInGroup(group
)) {
320 handleSynonym(state
, syn
, index
);
323 homotypicGroupIndex
++;
327 for (Taxon tax
: taxon
.getAllProParteSynonyms()) {
328 handleProPartePartialMisapplied(state
, tax
, taxon
, true, false, index
);
333 for (Taxon tax
: taxon
.getAllMisappliedNames()) {
334 handleProPartePartialMisapplied(state
, tax
, taxon
, false, true, index
);
338 CdmLightExportTable table
= CdmLightExportTable
.TAXON
;
339 String
[] csvLine
= new String
[table
.getSize()];
341 csvLine
[table
.getIndex(CdmLightExportTable
.TAXON_ID
)] = getId(state
, taxon
);
342 csvLine
[table
.getIndex(CdmLightExportTable
.NAME_FK
)] = getId(state
, name
);
343 Taxon parent
= (taxonNode
.getParent() == null) ?
null : taxonNode
.getParent().getTaxon();
344 csvLine
[table
.getIndex(CdmLightExportTable
.PARENT_FK
)] = getId(state
, parent
);
345 csvLine
[table
.getIndex(CdmLightExportTable
.SEC_REFERENCE_FK
)] = getId(state
, taxon
.getSec());
346 if (taxon
.getSec() != null && taxon
.getSec().getDatePublished() != null
347 && taxon
.getSec().getDatePublished().getFreeText() != null) {
348 String sec_string
= taxon
.getSec().getTitleCache() + ". "
349 + taxon
.getSec().getDatePublished().getFreeText();
350 sec_string
= sec_string
.replace("..", ".");
351 csvLine
[table
.getIndex(CdmLightExportTable
.SEC_REFERENCE
)] = sec_string
;
353 csvLine
[table
.getIndex(CdmLightExportTable
.SEC_REFERENCE
)] = getTitleCache(taxon
.getSec());
355 if (taxon
.getSec() != null) {
356 if (!state
.getReferenceStore().contains((taxon
.getSec().getUuid()))) {
357 handleReference(state
, taxon
.getSec());
360 csvLine
[table
.getIndex(CdmLightExportTable
.APPENDED_PHRASE
)] = taxon
.getAppendedPhrase();
361 csvLine
[table
.getIndex(CdmLightExportTable
.CLASSIFICATION_ID
)] = getId(state
,
362 taxonNode
.getClassification());
363 csvLine
[table
.getIndex(CdmLightExportTable
.CLASSIFICATION_TITLE
)] = taxonNode
.getClassification()
366 csvLine
[table
.getIndex(CdmLightExportTable
.PUBLISHED
)] = taxon
.isPublish() ?
"1" : "0";
367 csvLine
[table
.getIndex(CdmLightExportTable
.EXCLUDED
)] = taxonNode
.isExcluded() ?
"1" : "0";
368 Map
<Language
, LanguageString
> notesMap
= taxonNode
.getStatusNote();
369 String statusNotes
= "";
370 if (!notesMap
.isEmpty() && notesMap
.size() == 1) {
371 statusNotes
= notesMap
.values().iterator().next().getText();
372 } else if (!notesMap
.isEmpty()) {
373 statusNotes
= notesMap
.get(Language
.getDefaultLanguage()) != null
374 ? notesMap
.get(Language
.getDefaultLanguage()).getText() : null;
375 if (statusNotes
== null) {
376 statusNotes
= notesMap
.values().iterator().next().getText();
379 csvLine
[table
.getIndex(CdmLightExportTable
.STATUS_NOTES
)] = statusNotes
;
381 csvLine
[table
.getIndex(CdmLightExportTable
.UNPLACED
)] = taxonNode
.isUnplaced() ?
"1" : "0";
382 csvLine
[table
.getIndex(CdmLightExportTable
.DOUBTFUL
)] = taxonNode
.isDoubtful() ?
"1" : "0";
383 state
.getProcessor().put(table
, taxon
, csvLine
);
384 handleDescriptions(state
, taxon
);
385 } catch (Exception e
) {
386 state
.getResult().addException(e
,
387 "An unexpected problem occurred when trying to export taxon with id " + taxon
.getId() + " " + taxon
.getTitleCache());
388 state
.getResult().setState(ExportResultState
.INCOMPLETE_WITH_ERROR
);
392 taxonNode
.removeNullValueFromChildren();
394 } catch (Exception e
) {
395 state
.getResult().addException(e
, "An unexpected error occurred when handling the taxon node of "
396 + cdmBaseStr(taxonNode
.getTaxon()) + ", titleCache:"+ taxonNode
.getTaxon().getTitleCache()+": " + e
.getMessage());
400 private void handleDescriptions(CdmLightExportState state
, CdmBase cdmBase
) {
401 String titleCache
= null;
404 if (cdmBase
instanceof Taxon
) {
405 Taxon taxon
= HibernateProxyHelper
.deproxy(cdmBase
, Taxon
.class);
406 titleCache
= taxon
.getTitleCache();
407 Set
<TaxonDescription
> descriptions
= taxon
.getDescriptions();
408 List
<DescriptionElementBase
> simpleFacts
= new ArrayList
<>();
409 List
<DescriptionElementBase
> specimenFacts
= new ArrayList
<>();
410 List
<DescriptionElementBase
> distributionFacts
= new ArrayList
<>();
411 List
<DescriptionElementBase
> taxonInteractionsFacts
= new ArrayList
<>();
412 List
<DescriptionElementBase
> commonNameFacts
= new ArrayList
<>();
413 List
<DescriptionElementBase
> usageFacts
= new ArrayList
<>();
414 for (TaxonDescription description
: descriptions
) {
415 if (description
.getElements() != null) {
416 for (DescriptionElementBase element
: description
.getElements()) {
417 element
= CdmBase
.deproxy(element
);
418 handleAnnotations(element
);
419 if (element
.getFeature().equals(Feature
.COMMON_NAME())) {
420 commonNameFacts
.add(element
);
421 } else if (element
.getFeature().equals(Feature
.DISTRIBUTION())) {
422 distributionFacts
.add(element
);
423 } else if (element
instanceof IndividualsAssociation
424 || isSpecimenFeature(element
.getFeature())) {
425 specimenFacts
.add(element
);
426 } else if (element
.getFeature().isSupportsTaxonInteraction()) {
427 taxonInteractionsFacts
.add(element
);
429 simpleFacts
.add(element
);
434 if (!commonNameFacts
.isEmpty()) {
435 handleCommonNameFacts(state
, taxon
, commonNameFacts
);
437 if (!distributionFacts
.isEmpty()) {
438 handleDistributionFacts(state
, taxon
, distributionFacts
);
440 if (!specimenFacts
.isEmpty()) {
441 handleSpecimenFacts(state
, taxon
, specimenFacts
);
443 if (!simpleFacts
.isEmpty()) {
444 handleSimpleFacts(state
, taxon
, simpleFacts
);
446 if (!taxonInteractionsFacts
.isEmpty()) {
447 handleTaxonInteractionsFacts(state
, taxon
, taxonInteractionsFacts
);
449 } else if (cdmBase
instanceof TaxonName
) {
450 TaxonName name
= CdmBase
.deproxy(cdmBase
, TaxonName
.class);
451 titleCache
= name
.getTitleCache();
452 Set
<TaxonNameDescription
> descriptions
= name
.getDescriptions();
453 List
<DescriptionElementBase
> simpleFacts
= new ArrayList
<>();
454 for (TaxonNameDescription description
: descriptions
) {
455 if (description
.getElements() != null) {
456 for (DescriptionElementBase element
: description
.getElements()) {
457 simpleFacts
.add(element
);
461 if (!simpleFacts
.isEmpty()) {
462 handleSimpleFacts(state
, name
, simpleFacts
);
465 } catch (Exception e
) {
466 state
.getResult().addException(e
, "An unexpected error occurred when handling description of "
467 + cdmBaseStr(cdmBase
) + (titleCache
!= null?
(" " +titleCache
) : "")+": " + e
.getMessage());
471 private void handleAnnotations(DescriptionElementBase element
) {
472 // TODO Auto-generated method stub
475 private void handleMetaData(CdmLightExportState state
) {
476 CdmLightExportTable table
= CdmLightExportTable
.METADATA
;
477 String
[] csvLine
= new String
[table
.getSize()];
478 // csvLine[table.getIndex(CdmLightExportTable.INSTANCE_ID)] = state.getConfig().getInctanceId();
479 // csvLine[table.getIndex(CdmLightExportTable.INSTANCE_NAME)] = state.getConfig().getInstanceName();
480 csvLine
[table
.getIndex(CdmLightExportTable
.DATASET_BASE_URL
)] = state
.getConfig().getBase_url();
481 csvLine
[table
.getIndex(CdmLightExportTable
.DATASET_CONTRIBUTOR
)] = state
.getConfig().getContributor();
482 csvLine
[table
.getIndex(CdmLightExportTable
.DATASET_CREATOR
)] = state
.getConfig().getCreator();
483 csvLine
[table
.getIndex(CdmLightExportTable
.DATASET_DESCRIPTION
)] = state
.getConfig().getDescription();
484 csvLine
[table
.getIndex(CdmLightExportTable
.DATASET_DOWNLOAD_LINK
)] = state
.getConfig().getDataset_download_link();
485 csvLine
[table
.getIndex(CdmLightExportTable
.DATASET_KEYWORDS
)] = state
.getConfig().getKeywords();
486 csvLine
[table
.getIndex(CdmLightExportTable
.DATASET_LANDINGPAGE
)] = state
.getConfig().getDataSet_landing_page();
488 csvLine
[table
.getIndex(CdmLightExportTable
.DATASET_LANGUAGE
)] = state
.getConfig().getLanguage() != null? state
.getConfig().getLanguage().getLabel(): null;
489 csvLine
[table
.getIndex(CdmLightExportTable
.DATASET_LICENCE
)] = state
.getConfig().getLicence();
490 csvLine
[table
.getIndex(CdmLightExportTable
.DATASET_LOCATION
)] = state
.getConfig().getLocation();
491 csvLine
[table
.getIndex(CdmLightExportTable
.DATASET_RECOMMENDED_CITATTION
)] = state
.getConfig().getRecommended_citation();
492 csvLine
[table
.getIndex(CdmLightExportTable
.DATASET_TITLE
)] = state
.getConfig().getTitle();
493 state
.getProcessor().put(table
, "", csvLine
);
496 private boolean isSpecimenFeature(Feature feature
) {
497 // TODO allow user defined specimen features
498 if (feature
== null) {
500 } else if (feature
.isSupportsIndividualAssociation()) {
503 return feature
.equals(Feature
.SPECIMEN()) || feature
.equals(Feature
.INDIVIDUALS_ASSOCIATION())
504 || feature
.equals(Feature
.MATERIALS_EXAMINED()) || feature
.equals(Feature
.OBSERVATION())
505 || feature
.equals(Feature
.OCCURRENCE());
509 private void handleSimpleFacts(CdmLightExportState state
, CdmBase cdmBase
,
510 List
<DescriptionElementBase
> simpleFacts
) {
511 String titleCache
= null;
513 CdmLightExportTable table
;
514 if (cdmBase
instanceof TaxonName
) {
515 titleCache
= ((TaxonName
)cdmBase
).getTitleCache();
516 table
= CdmLightExportTable
.NAME_FACT
;
518 if (cdmBase
instanceof Taxon
){
519 titleCache
= ((Taxon
)cdmBase
).getTitleCache();
521 table
= CdmLightExportTable
.SIMPLE_FACT
;
523 CdmLightExportTable tableMedia
= CdmLightExportTable
.MEDIA
;
524 for (DescriptionElementBase element
: simpleFacts
) {
525 if (element
.getModifyingText().isEmpty() && !element
.getMedia().isEmpty()) {
526 handleSimpleMediaFact(state
, cdmBase
, tableMedia
, element
);
528 handleSingleSimpleFact(state
, cdmBase
, table
, element
);
531 } catch (Exception e
) {
532 state
.getResult().addException(e
, "An unexpected error occurred when handling simple facts for "
533 + cdmBaseStr(cdmBase
) + (titleCache
!= null?
(" " +titleCache
) : "")+ ": " + e
.getMessage());
537 private void handleTaxonInteractionsFacts(CdmLightExportState state
, CdmBase cdmBase
,
538 List
<DescriptionElementBase
> taxonInteractionsFacts
) {
539 CdmLightExportTable table
= CdmLightExportTable
.TAXON_INTERACTION_FACT
;
540 String titleCache
= null;
541 if (cdmBase
instanceof TaxonBase
){
542 titleCache
= ((TaxonBase
)cdmBase
).getTitleCache();
544 for (DescriptionElementBase element
: taxonInteractionsFacts
) {
548 String
[] csvLine
= new String
[table
.getSize()];
550 csvLine
[table
.getIndex(CdmLightExportTable
.FACT_ID
)] = getId(state
, element
);
551 handleSource(state
, element
, table
);
552 csvLine
[table
.getIndex(CdmLightExportTable
.TAXON_FK
)] = getId(state
, cdmBase
);
553 csvLine
[table
.getIndex(CdmLightExportTable
.TAXON2_FK
)] = getId(state
,
554 ((TaxonInteraction
) element
).getTaxon2());
555 csvLine
[table
.getIndex(CdmLightExportTable
.DESCRIPTION
)] = createMultilanguageString(
556 ((TaxonInteraction
) element
).getDescription());
557 state
.getProcessor().put(table
, element
, csvLine
);
559 } catch (Exception e
) {
560 state
.getResult().addException(e
, "An unexpected error occurred when handling taxon interaction"
561 + cdmBaseStr(element
) + (titleCache
!= null?
(" " +titleCache
) : "")+ ": " + e
.getMessage());
566 private void handleSimpleMediaFact(CdmLightExportState state
, CdmBase cdmBase
, CdmLightExportTable table
,
567 DescriptionElementBase element
) {
570 handleSource(state
, element
, CdmLightExportTable
.MEDIA
);
572 if (element
instanceof TextData
) {
573 TextData textData
= (TextData
) element
;
574 csvLine
= new String
[table
.getSize()];
575 csvLine
[table
.getIndex(CdmLightExportTable
.FACT_ID
)] = getId(state
, element
);
576 if (cdmBase
instanceof Taxon
) {
577 csvLine
[table
.getIndex(CdmLightExportTable
.TAXON_FK
)] = getId(state
, cdmBase
);
578 csvLine
[table
.getIndex(CdmLightExportTable
.NAME_FK
)] = "";
579 } else if (cdmBase
instanceof TaxonName
) {
580 csvLine
[table
.getIndex(CdmLightExportTable
.TAXON_FK
)] = "";
581 csvLine
[table
.getIndex(CdmLightExportTable
.NAME_FK
)] = getId(state
, cdmBase
);
584 String mediaUris
= "";
585 for (Media media
: textData
.getMedia()) {
586 String mediaString
= extractMediaUris(media
.getRepresentations().iterator());
587 if (!StringUtils
.isBlank(mediaString
)) {
588 mediaUris
+= mediaString
+ ";";
590 state
.getResult().addWarning("Empty Media object for " + cdmBase
.getUserFriendlyTypeName() + " "
591 + cdmBase
.getUuid() + " (media: " + media
.getUuid() + ")");
594 csvLine
[table
.getIndex(CdmLightExportTable
.MEDIA_URI
)] = mediaUris
;
597 } catch (Exception e
) {
598 state
.getResult().addException(e
, "An unexpected error occurred when handling single simple fact "
599 + cdmBaseStr(element
) + ": " + e
.getMessage());
604 private void handleSingleSimpleFact(CdmLightExportState state
, CdmBase cdmBase
, CdmLightExportTable table
,
605 DescriptionElementBase element
) {
608 handleSource(state
, element
, CdmLightExportTable
.SIMPLE_FACT
);
610 if (element
instanceof TextData
) {
611 TextData textData
= (TextData
) element
;
612 csvLine
= new String
[table
.getSize()];
613 csvLine
[table
.getIndex(CdmLightExportTable
.FACT_ID
)] = getId(state
, element
);
614 if (cdmBase
instanceof Taxon
) {
615 csvLine
[table
.getIndex(CdmLightExportTable
.TAXON_FK
)] = getId(state
, cdmBase
);
616 } else if (cdmBase
instanceof TaxonName
) {
617 csvLine
[table
.getIndex(CdmLightExportTable
.NAME_FK
)] = getId(state
, cdmBase
);
619 csvLine
[table
.getIndex(CdmLightExportTable
.FACT_CATEGORY
)] = textData
.getFeature().getLabel();
621 String mediaUris
= "";
622 for (Media media
: textData
.getMedia()) {
623 String mediaString
= extractMediaUris(media
.getRepresentations().iterator());
624 if (!StringUtils
.isBlank(mediaString
)) {
625 mediaUris
+= mediaString
+ ";";
627 state
.getResult().addWarning("Empty Media object for uuid: " + cdmBase
.getUuid()
628 + " uuid of media: " + media
.getUuid());
631 csvLine
[table
.getIndex(CdmLightExportTable
.MEDIA_URI
)] = mediaUris
;
632 if (textData
.getFeature().equals(Feature
.CITATION())) {
633 state
.getProcessor().put(table
, textData
, csvLine
);
634 } else if (!textData
.getMultilanguageText().isEmpty()) {
635 for (Language language
: textData
.getMultilanguageText().keySet()) {
636 String
[] csvLineLanguage
= csvLine
.clone();
637 LanguageString langString
= textData
.getLanguageText(language
);
638 String text
= langString
.getText();
639 if (state
.getConfig().isFilterIntextReferences()) {
640 text
= filterIntextReferences(langString
.getText());
642 csvLineLanguage
[table
.getIndex(CdmLightExportTable
.FACT_TEXT
)] = text
;
643 csvLineLanguage
[table
.getIndex(CdmLightExportTable
.LANGUAGE
)] = language
.getLabel();
644 state
.getProcessor().put(table
, textData
, csvLineLanguage
);
647 state
.getProcessor().put(table
, textData
, csvLine
);
650 } catch (Exception e
) {
651 state
.getResult().addException(e
, "An unexpected error occurred when handling single simple fact "
652 + cdmBaseStr(element
) + ": " + e
.getMessage());
656 private String
filterIntextReferences(String text
) {
658 * (<cdm:reference cdmId='fbd19251-efee-4ded-b780-915000f66d41'
659 * intextId='1352d42c-e201-4155-a02a-55360d3b563e'>Ridley in Fl. Malay
660 * Pen. 3 (1924) 22</cdm:reference>)
662 String newText
= text
.replaceAll("<cdm:reference cdmId='[a-z0-9\\-]*' intextId='[a-z0-9\\-]*'>", "");
663 newText
= newText
.replaceAll("</cdm:reference>", "");
665 newText
= newText
.replaceAll("<cdm:key cdmId='[a-z0-9\\-]*' intextId='[a-z0-9\\-]*'>", "");
666 newText
= newText
.replaceAll("</cdm:key>", "");
670 private void handleSpecimenFacts(CdmLightExportState state
, Taxon taxon
,
671 List
<DescriptionElementBase
> specimenFacts
) {
672 CdmLightExportTable table
= CdmLightExportTable
.SPECIMEN_FACT
;
674 for (DescriptionElementBase element
: specimenFacts
) {
676 String
[] csvLine
= new String
[table
.getSize()];
677 csvLine
[table
.getIndex(CdmLightExportTable
.FACT_ID
)] = getId(state
, element
);
678 csvLine
[table
.getIndex(CdmLightExportTable
.TAXON_FK
)] = getId(state
, taxon
);
679 handleSource(state
, element
, table
);
680 csvLine
[table
.getIndex(CdmLightExportTable
.SPECIMEN_NOTES
)] = createAnnotationsString(
681 element
.getAnnotations());
683 if (element
instanceof IndividualsAssociation
) {
685 IndividualsAssociation indAssociation
= (IndividualsAssociation
) element
;
686 if (indAssociation
.getAssociatedSpecimenOrObservation() == null) {
688 .addWarning("There is an individual association with no specimen associated (Taxon "
689 + taxon
.getTitleCache() + "(" + taxon
.getUuid() + "). Could not be exported.");
692 if (!state
.getSpecimenStore()
693 .contains((indAssociation
.getAssociatedSpecimenOrObservation().getUuid()))) {
694 SpecimenOrObservationBase
<?
> specimenBase
= HibernateProxyHelper
.deproxy(
695 indAssociation
.getAssociatedSpecimenOrObservation(),
696 SpecimenOrObservationBase
.class);
698 handleSpecimen(state
, specimenBase
);
699 csvLine
[table
.getIndex(CdmLightExportTable
.SPECIMEN_FK
)] = getId(state
,
700 indAssociation
.getAssociatedSpecimenOrObservation());
703 } else if (element
instanceof TextData
) {
704 TextData textData
= HibernateProxyHelper
.deproxy(element
, TextData
.class);
705 csvLine
[table
.getIndex(CdmLightExportTable
.SPECIMEN_DESCRIPTION
)] = createMultilanguageString(
706 textData
.getMultilanguageText());
708 state
.getProcessor().put(table
, element
, csvLine
);
709 } catch (Exception e
) {
710 state
.getResult().addException(e
, "An unexpected error occurred when handling single specimen fact "
711 + cdmBaseStr(element
) + ": " + e
.getMessage());
716 private String
createMultilanguageString(Map
<Language
, LanguageString
> multilanguageText
) {
718 int index
= multilanguageText
.size();
719 for (LanguageString langString
: multilanguageText
.values()) {
720 text
+= langString
.getText();
729 private String
createAnnotationsString(Set
<Annotation
> annotations
) {
730 StringBuffer strBuff
= new StringBuffer();
732 for (Annotation ann
: annotations
) {
733 if (ann
.getAnnotationType() == null || !ann
.getAnnotationType().equals(AnnotationType
.TECHNICAL())) {
734 strBuff
.append(ann
.getText());
735 strBuff
.append("; ");
739 if (strBuff
.length() > 2) {
740 return strBuff
.substring(0, strBuff
.length() - 2);
746 private void handleSource(CdmLightExportState state
, DescriptionElementBase element
,
747 CdmLightExportTable factsTable
) {
748 CdmLightExportTable table
= CdmLightExportTable
.FACT_SOURCES
;
750 Set
<DescriptionElementSource
> sources
= element
.getSources();
752 for (DescriptionElementSource source
: sources
) {
753 if (!(source
.getType().equals(OriginalSourceType
.Import
)
754 && state
.getConfig().isExcludeImportSources())) {
755 String
[] csvLine
= new String
[table
.getSize()];
756 Reference ref
= source
.getCitation();
757 if ((ref
== null) && (source
.getNameUsedInSource() == null)) {
761 if (!state
.getReferenceStore().contains(ref
.getUuid())) {
762 handleReference(state
, ref
);
765 csvLine
[table
.getIndex(CdmLightExportTable
.REFERENCE_FK
)] = getId(state
, ref
);
767 csvLine
[table
.getIndex(CdmLightExportTable
.FACT_FK
)] = getId(state
, element
);
769 csvLine
[table
.getIndex(CdmLightExportTable
.NAME_IN_SOURCE_FK
)] = getId(state
,
770 source
.getNameUsedInSource());
771 csvLine
[table
.getIndex(CdmLightExportTable
.FACT_TYPE
)] = factsTable
.getTableName();
772 if (StringUtils
.isBlank(csvLine
[table
.getIndex(CdmLightExportTable
.REFERENCE_FK
)])
773 && StringUtils
.isBlank(csvLine
[table
.getIndex(CdmLightExportTable
.NAME_IN_SOURCE_FK
)])) {
776 state
.getProcessor().put(table
, source
, csvLine
);
780 } catch (Exception e
) {
781 state
.getResult().addException(e
, "An unexpected error occurred when handling single source "
782 + cdmBaseStr(element
) + ": " + e
.getMessage());
787 private void handleDistributionFacts(CdmLightExportState state
, Taxon taxon
,
788 List
<DescriptionElementBase
> distributionFacts
) {
790 CdmLightExportTable table
= CdmLightExportTable
.GEOGRAPHIC_AREA_FACT
;
791 Set
<Distribution
> distributions
= new HashSet
<>();
792 for (DescriptionElementBase element
: distributionFacts
) {
794 if (element
instanceof Distribution
) {
795 String
[] csvLine
= new String
[table
.getSize()];
796 Distribution distribution
= (Distribution
) element
;
797 distributions
.add(distribution
);
798 csvLine
[table
.getIndex(CdmLightExportTable
.FACT_ID
)] = getId(state
, element
);
799 handleSource(state
, element
, table
);
800 csvLine
[table
.getIndex(CdmLightExportTable
.TAXON_FK
)] = getId(state
, taxon
);
801 if (distribution
.getArea() != null) {
802 csvLine
[table
.getIndex(CdmLightExportTable
.AREA_LABEL
)] = distribution
.getArea().getLabel();
804 if (distribution
.getStatus() != null) {
805 csvLine
[table
.getIndex(CdmLightExportTable
.STATUS_LABEL
)] = distribution
.getStatus().getLabel();
807 state
.getProcessor().put(table
, distribution
, csvLine
);
810 .addError("The distribution description for the taxon " + taxon
.getUuid()
811 + " is not of type distribution. Could not be exported. UUID of the description element: "
812 + element
.getUuid());
814 } catch (Exception e
) {
815 state
.getResult().addException(e
, "An unexpected error occurred when handling single distribution "
816 + cdmBaseStr(element
) + ": " + e
.getMessage());
819 if(state
.getConfig().isCreateCondensedDistributionString()){
820 List
<Language
> langs
= new ArrayList
<>();
821 langs
.add(Language
.ENGLISH());
823 CondensedDistribution conDis
= geoService
.getCondensedDistribution(
824 //TODO add CondensedDistributionConfiguration to export configuration
825 distributions
, true, null, state
.getConfig().getCondensedDistributionConfiguration(), langs
);
826 CdmLightExportTable tableCondensed
=
827 CdmLightExportTable
.SIMPLE_FACT
;
828 String
[] csvLine
= new String
[tableCondensed
.getSize()];
829 //the computed fact has no uuid, TODO: remember the uuid for later reference assignment
830 UUID randomUuid
= UUID
.randomUUID();
831 csvLine
[tableCondensed
.getIndex(CdmLightExportTable
.FACT_ID
)] =
832 randomUuid
.toString();
833 csvLine
[tableCondensed
.getIndex(CdmLightExportTable
.TAXON_FK
)] =
835 csvLine
[tableCondensed
.getIndex(CdmLightExportTable
.FACT_TEXT
)] =
837 csvLine
[tableCondensed
.getIndex(CdmLightExportTable
.LANGUAGE
)] =Language
.ENGLISH().toString();
839 csvLine
[tableCondensed
.getIndex(CdmLightExportTable
.FACT_CATEGORY
)] =
840 "CondensedDistribution";
842 state
.getProcessor().put(tableCondensed
, taxon
, csvLine
);
846 private void handleCommonNameFacts(CdmLightExportState state
, Taxon taxon
,
847 List
<DescriptionElementBase
> commonNameFacts
) {
848 CdmLightExportTable table
= CdmLightExportTable
.COMMON_NAME_FACT
;
850 for (DescriptionElementBase element
: commonNameFacts
) {
852 if (element
instanceof CommonTaxonName
) {
853 String
[] csvLine
= new String
[table
.getSize()];
854 CommonTaxonName commonName
= (CommonTaxonName
) element
;
855 csvLine
[table
.getIndex(CdmLightExportTable
.FACT_ID
)] = getId(state
, element
);
856 handleSource(state
, element
, table
);
857 csvLine
[table
.getIndex(CdmLightExportTable
.TAXON_FK
)] = getId(state
, taxon
);
858 if (commonName
.getName() != null) {
859 csvLine
[table
.getIndex(CdmLightExportTable
.FACT_TEXT
)] = commonName
.getName();
861 if (commonName
.getLanguage() != null) {
862 csvLine
[table
.getIndex(CdmLightExportTable
.LANGUAGE
)] = commonName
.getLanguage().getLabel();
864 if (commonName
.getArea() != null) {
865 csvLine
[table
.getIndex(CdmLightExportTable
.AREA_LABEL
)] = commonName
.getArea().getLabel();
867 state
.getProcessor().put(table
, commonName
, csvLine
);
868 } else if (element
instanceof TextData
){
869 String
[] csvLine
= new String
[table
.getSize()];
870 TextData commonName
= (TextData
) element
;
871 csvLine
[table
.getIndex(CdmLightExportTable
.FACT_ID
)] = getId(state
, element
);
872 handleSource(state
, element
, table
);
873 csvLine
[table
.getIndex(CdmLightExportTable
.TAXON_FK
)] = getId(state
, taxon
);
874 if (commonName
.getMultilanguageText() != null) {
875 csvLine
[table
.getIndex(CdmLightExportTable
.FACT_TEXT
)] = createMultilanguageString(commonName
.getMultilanguageText());
877 state
.getProcessor().put(table
, commonName
, csvLine
);
880 .addError("The common name description for the taxon " + taxon
.getUuid()
881 + " is not of type common name. Could not be exported. UUID of the description element: "
882 + element
.getUuid());
884 } catch (Exception e
) {
885 state
.getResult().addException(e
, "An unexpected error occurred when handling single common name "
886 + cdmBaseStr(element
) + " - "+taxon
.getTitleCache()+ ": " + e
.getMessage());
891 private String
getTitleCache(IIdentifiableEntity identEntity
) {
892 if (identEntity
== null) {
896 return identEntity
.getTitleCache();
899 private String
getId(CdmLightExportState state
, ICdmBase cdmBase
) {
900 if (cdmBase
== null) {
903 // TODO make configurable
904 return cdmBase
.getUuid().toString();
907 private void handleSynonym(CdmLightExportState state
, Synonym synonym
, int index
) {
909 if (isUnpublished(state
.getConfig(), synonym
)) {
912 TaxonName name
= synonym
.getName();
913 handleName(state
, name
, synonym
.getAcceptedTaxon());
915 CdmLightExportTable table
= CdmLightExportTable
.SYNONYM
;
916 String
[] csvLine
= new String
[table
.getSize()];
918 csvLine
[table
.getIndex(CdmLightExportTable
.SYNONYM_ID
)] = getId(state
, synonym
);
919 csvLine
[table
.getIndex(CdmLightExportTable
.TAXON_FK
)] = getId(state
, synonym
.getAcceptedTaxon());
920 csvLine
[table
.getIndex(CdmLightExportTable
.NAME_FK
)] = getId(state
, name
);
921 if (synonym
.getSec() != null && !state
.getReferenceStore().contains(synonym
.getSec().getUuid())) {
922 handleReference(state
, synonym
.getSec());
924 csvLine
[table
.getIndex(CdmLightExportTable
.APPENDED_PHRASE
)] = synonym
.getAppendedPhrase();
925 csvLine
[table
.getIndex(CdmLightExportTable
.SYN_SEC_REFERENCE_FK
)] = getId(state
, synonym
.getSec());
926 csvLine
[table
.getIndex(CdmLightExportTable
.SYN_SEC_REFERENCE
)] = getTitleCache(synonym
.getSec());
927 csvLine
[table
.getIndex(CdmLightExportTable
.PUBLISHED
)] = synonym
.isPublish() ?
"1" : "0";
928 csvLine
[table
.getIndex(CdmLightExportTable
.IS_PRO_PARTE
)] = "0";
929 csvLine
[table
.getIndex(CdmLightExportTable
.IS_PARTIAL
)] = "0";
930 csvLine
[table
.getIndex(CdmLightExportTable
.IS_MISAPPLIED
)] = "0";
931 csvLine
[table
.getIndex(CdmLightExportTable
.SORT_INDEX
)] = String
.valueOf(index
);
932 state
.getProcessor().put(table
, synonym
, csvLine
);
933 } catch (Exception e
) {
934 state
.getResult().addException(e
, "An unexpected error occurred when handling synonym "
935 + cdmBaseStr(synonym
) + ": " + e
.getMessage());
940 * Handles misapplied names (including pro parte and partial as well as pro
941 * parte and partial synonyms
943 private void handleProPartePartialMisapplied(CdmLightExportState state
, Taxon taxon
, Taxon accepted
, boolean isProParte
, boolean isMisapplied
, int index
) {
945 Taxon ppSyonym
= taxon
;
946 if (isUnpublished(state
.getConfig(), ppSyonym
)) {
949 TaxonName name
= ppSyonym
.getName();
950 handleName(state
, name
, accepted
);
952 CdmLightExportTable table
= CdmLightExportTable
.SYNONYM
;
953 String
[] csvLine
= new String
[table
.getSize()];
955 csvLine
[table
.getIndex(CdmLightExportTable
.SYNONYM_ID
)] = getId(state
, ppSyonym
);
956 csvLine
[table
.getIndex(CdmLightExportTable
.TAXON_FK
)] = getId(state
, accepted
);
957 csvLine
[table
.getIndex(CdmLightExportTable
.NAME_FK
)] = getId(state
, name
);
959 Reference secRef
= ppSyonym
.getSec();
961 if (secRef
!= null && !state
.getReferenceStore().contains(secRef
.getUuid())) {
962 handleReference(state
, secRef
);
964 csvLine
[table
.getIndex(CdmLightExportTable
.SEC_REFERENCE_FK
)] = getId(state
, secRef
);
965 csvLine
[table
.getIndex(CdmLightExportTable
.SEC_REFERENCE
)] = getTitleCache(secRef
);
966 Set
<TaxonRelationship
> rels
= accepted
.getTaxonRelations(ppSyonym
);
967 TaxonRelationship rel
= null;
968 boolean isPartial
= false;
969 if (rels
.size() == 1){
970 rel
= rels
.iterator().next();
972 }else if (rels
.size() > 1){
973 Iterator
<TaxonRelationship
> iterator
= rels
.iterator();
974 while (iterator
.hasNext()){
975 rel
= iterator
.next();
976 if (isProParte
&& rel
.getType().isAnySynonym()){
978 } else if (isMisapplied
&& rel
.getType().isAnyMisappliedName()){
986 Reference synSecRef
= rel
.getCitation();
987 if (synSecRef
!= null && !state
.getReferenceStore().contains(synSecRef
.getUuid())) {
988 handleReference(state
, synSecRef
);
990 csvLine
[table
.getIndex(CdmLightExportTable
.SYN_SEC_REFERENCE_FK
)] = getId(state
, synSecRef
);
991 csvLine
[table
.getIndex(CdmLightExportTable
.SYN_SEC_REFERENCE
)] = getTitleCache(synSecRef
);
992 isProParte
= rel
.getType().isProParte();
993 isPartial
= rel
.getType().isPartial();
996 state
.getResult().addWarning("An unexpected error occurred when handling "
997 + "pro parte/partial synonym or misapplied name " + cdmBaseStr(taxon
) );
1002 csvLine
[table
.getIndex(CdmLightExportTable
.IS_PRO_PARTE
)] = isProParte ?
"1" : "0";
1003 csvLine
[table
.getIndex(CdmLightExportTable
.IS_PARTIAL
)] = isPartial ?
"1" : "0";
1004 csvLine
[table
.getIndex(CdmLightExportTable
.IS_MISAPPLIED
)] = isMisapplied ?
"1" : "0";
1005 csvLine
[table
.getIndex(CdmLightExportTable
.SORT_INDEX
)] = String
.valueOf(index
);
1006 state
.getProcessor().put(table
, ppSyonym
, csvLine
);
1007 } catch (Exception e
) {
1008 state
.getResult().addException(e
, "An unexpected error occurred when handling "
1009 + "pro parte/partial synonym or misapplied name " + cdmBaseStr(taxon
) + ": " + e
.getMessage());
1014 private void handleName(CdmLightExportState state
, TaxonName name
, Taxon acceptedTaxon
){
1015 handleName(state
, name
, acceptedTaxon
, false);
1018 private void handleName(CdmLightExportState state
, TaxonName name
, Taxon acceptedTaxon
, boolean acceptedName
) {
1019 if (name
== null || state
.getNameStore().containsKey(name
.getId())) {
1023 Rank rank
= name
.getRank();
1024 CdmLightExportTable table
= CdmLightExportTable
.SCIENTIFIC_NAME
;
1025 name
= HibernateProxyHelper
.deproxy(name
);
1026 state
.getNameStore().put(name
.getId(), name
.getUuid());
1027 String
[] csvLine
= new String
[table
.getSize()];
1029 csvLine
[table
.getIndex(CdmLightExportTable
.NAME_ID
)] = getId(state
, name
);
1030 if (name
.getLsid() != null) {
1031 csvLine
[table
.getIndex(CdmLightExportTable
.LSID
)] = name
.getLsid().getLsid();
1033 csvLine
[table
.getIndex(CdmLightExportTable
.LSID
)] = "";
1036 handleIdentifier(state
, name
);
1037 handleDescriptions(state
, name
);
1039 csvLine
[table
.getIndex(CdmLightExportTable
.RANK
)] = getTitleCache(rank
);
1041 csvLine
[table
.getIndex(CdmLightExportTable
.RANK_SEQUENCE
)] = String
.valueOf(rank
.getOrderIndex());
1042 if (rank
.isInfraGeneric()) {
1044 csvLine
[table
.getIndex(CdmLightExportTable
.INFRAGENERIC_RANK
)] = name
.getRank()
1045 .getInfraGenericMarker();
1046 } catch (UnknownCdmTypeException e
) {
1047 state
.getResult().addError("Infrageneric marker expected but not available for rank "
1048 + name
.getRank().getTitleCache());
1051 if (rank
.isInfraSpecific()) {
1052 csvLine
[table
.getIndex(CdmLightExportTable
.INFRASPECIFIC_RANK
)] = name
.getRank().getAbbreviation();
1055 csvLine
[table
.getIndex(CdmLightExportTable
.RANK_SEQUENCE
)] = "";
1057 if (name
.isProtectedTitleCache()) {
1058 csvLine
[table
.getIndex(CdmLightExportTable
.FULL_NAME_WITH_AUTHORS
)] = name
.getTitleCache();
1060 // TODO: adapt the tropicos titlecache creation
1061 csvLine
[table
.getIndex(CdmLightExportTable
.FULL_NAME_WITH_AUTHORS
)] = name
.getTitleCache();
1065 if (!state
.getConfig().isAddHTML()) {
1066 csvLine
[table
.getIndex(CdmLightExportTable
.FULL_NAME_WITH_REF
)] = name
.getFullTitleCache();
1068 List
<TaggedText
> taggedFullTitleCache
= name
.getTaggedFullTitle();
1069 List
<TaggedText
> taggedName
= name
.getTaggedName();
1071 String fullTitleWithHtml
= createNameWithItalics(taggedFullTitleCache
);
1072 // TODO: adapt the tropicos titlecache creation
1073 csvLine
[table
.getIndex(CdmLightExportTable
.FULL_NAME_WITH_REF
)] = fullTitleWithHtml
.trim();
1076 csvLine
[table
.getIndex(CdmLightExportTable
.FULL_NAME_NO_AUTHORS
)] = name
.getNameCache();
1077 csvLine
[table
.getIndex(CdmLightExportTable
.GENUS_UNINOMIAL
)] = name
.getGenusOrUninomial();
1079 csvLine
[table
.getIndex(CdmLightExportTable
.INFRAGENERIC_EPITHET
)] = name
.getInfraGenericEpithet();
1080 csvLine
[table
.getIndex(CdmLightExportTable
.SPECIFIC_EPITHET
)] = name
.getSpecificEpithet();
1082 csvLine
[table
.getIndex(CdmLightExportTable
.INFRASPECIFIC_EPITHET
)] = name
.getInfraSpecificEpithet();
1084 csvLine
[table
.getIndex(CdmLightExportTable
.APPENDED_PHRASE
)] = name
.getAppendedPhrase();
1086 csvLine
[table
.getIndex(CdmLightExportTable
.BAS_AUTHORTEAM_FK
)] = getId(state
, name
.getBasionymAuthorship());
1087 if (name
.getBasionymAuthorship() != null) {
1088 if (state
.getAuthorFromStore(name
.getBasionymAuthorship().getId()) == null) {
1089 handleAuthor(state
, name
.getBasionymAuthorship());
1092 csvLine
[table
.getIndex(CdmLightExportTable
.BAS_EX_AUTHORTEAM_FK
)] = getId(state
,
1093 name
.getExBasionymAuthorship());
1094 if (name
.getExBasionymAuthorship() != null) {
1095 if (state
.getAuthorFromStore(name
.getExBasionymAuthorship().getId()) == null) {
1096 handleAuthor(state
, name
.getExBasionymAuthorship());
1100 csvLine
[table
.getIndex(CdmLightExportTable
.COMB_AUTHORTEAM_FK
)] = getId(state
,
1101 name
.getCombinationAuthorship());
1102 if (name
.getCombinationAuthorship() != null) {
1103 if (state
.getAuthorFromStore(name
.getCombinationAuthorship().getId()) == null) {
1104 handleAuthor(state
, name
.getCombinationAuthorship());
1107 csvLine
[table
.getIndex(CdmLightExportTable
.COMB_EX_AUTHORTEAM_FK
)] = getId(state
,
1108 name
.getExCombinationAuthorship());
1109 if (name
.getExCombinationAuthorship() != null) {
1110 if (state
.getAuthorFromStore(name
.getExCombinationAuthorship().getId()) == null) {
1111 handleAuthor(state
, name
.getExCombinationAuthorship());
1116 csvLine
[table
.getIndex(CdmLightExportTable
.AUTHOR_TEAM_STRING
)] = name
.getAuthorshipCache();
1118 Reference nomRef
= name
.getNomenclaturalReference();
1120 NomenclaturalSource nomenclaturalSource
= name
.getNomenclaturalSource();
1121 if (nomenclaturalSource
!= null &&nomenclaturalSource
.getNameUsedInSource() != null){
1122 handleName(state
, nomenclaturalSource
.getNameUsedInSource(), null);
1123 csvLine
[table
.getIndex(CdmLightExportTable
.NAME_USED_IN_SOURCE
)] = getId(state
, nomenclaturalSource
.getNameUsedInSource());
1126 if (nomRef
!= null) {
1127 if (!state
.getReferenceStore().contains(nomRef
.getUuid())) {
1128 handleReference(state
, nomRef
);
1130 csvLine
[table
.getIndex(CdmLightExportTable
.REFERENCE_FK
)] = getId(state
, nomRef
);
1131 csvLine
[table
.getIndex(CdmLightExportTable
.PUBLICATION_TYPE
)] = nomRef
.getType().name();
1132 if (nomRef
.getVolume() != null) {
1133 csvLine
[table
.getIndex(CdmLightExportTable
.VOLUME_ISSUE
)] = nomRef
.getVolume();
1134 csvLine
[table
.getIndex(CdmLightExportTable
.COLLATION
)] = createCollatation(name
);
1136 if (nomRef
.getDatePublished() != null) {
1137 csvLine
[table
.getIndex(CdmLightExportTable
.DATE_PUBLISHED
)] = nomRef
.getTimePeriodPublishedString();
1138 csvLine
[table
.getIndex(CdmLightExportTable
.YEAR_PUBLISHED
)] = nomRef
.getDatePublished().getYear();
1139 csvLine
[table
.getIndex(CdmLightExportTable
.VERBATIM_DATE
)] = nomRef
.getDatePublished()
1142 if (name
.getNomenclaturalMicroReference() != null) {
1143 csvLine
[table
.getIndex(CdmLightExportTable
.DETAIL
)] = name
.getNomenclaturalMicroReference();
1145 nomRef
= HibernateProxyHelper
.deproxy(nomRef
);
1146 if (nomRef
.getInReference() != null) {
1147 Reference inReference
= nomRef
.getInReference();
1148 if (inReference
.getDatePublished() != null && nomRef
.getDatePublished() == null) {
1149 csvLine
[table
.getIndex(CdmLightExportTable
.DATE_PUBLISHED
)] = inReference
1150 .getDatePublishedString();
1151 csvLine
[table
.getIndex(CdmLightExportTable
.YEAR_PUBLISHED
)] = inReference
.getDatePublished()
1154 if (nomRef
.getVolume() == null && inReference
.getVolume() != null) {
1155 csvLine
[table
.getIndex(CdmLightExportTable
.VOLUME_ISSUE
)] = inReference
.getVolume();
1156 csvLine
[table
.getIndex(CdmLightExportTable
.COLLATION
)] = createCollatation(name
);
1158 if (inReference
.getInReference() != null) {
1159 inReference
= inReference
.getInReference();
1161 if (inReference
.getAbbrevTitle() == null) {
1162 csvLine
[table
.getIndex(CdmLightExportTable
.ABBREV_TITLE
)] = CdmUtils
1163 .Nz(inReference
.getTitle());
1165 csvLine
[table
.getIndex(CdmLightExportTable
.ABBREV_TITLE
)] = CdmUtils
1166 .Nz(inReference
.getAbbrevTitle());
1168 if (inReference
.getTitle() == null) {
1169 csvLine
[table
.getIndex(CdmLightExportTable
.FULL_TITLE
)] = CdmUtils
1170 .Nz(inReference
.getAbbrevTitle()!= null? inReference
.getAbbrevTitle(): inReference
.getTitleCache());
1172 csvLine
[table
.getIndex(CdmLightExportTable
.FULL_TITLE
)] = CdmUtils
.Nz(inReference
.getTitle());
1175 TeamOrPersonBase
<?
> author
= inReference
.getAuthorship();
1177 && (nomRef
.isOfType(ReferenceType
.BookSection
) || nomRef
.isOfType(ReferenceType
.Section
))) {
1178 csvLine
[table
.getIndex(CdmLightExportTable
.ABBREV_REF_AUTHOR
)] = author
.isProtectedTitleCache()
1179 ? author
.getTitleCache() : CdmUtils
.Nz(author
.getNomenclaturalTitleCache());
1180 csvLine
[table
.getIndex(CdmLightExportTable
.FULL_REF_AUTHOR
)] = CdmUtils
1181 .Nz(author
.getTitleCache());
1183 csvLine
[table
.getIndex(CdmLightExportTable
.ABBREV_REF_AUTHOR
)] = "";
1184 csvLine
[table
.getIndex(CdmLightExportTable
.FULL_REF_AUTHOR
)] = "";
1187 if (nomRef
.getAbbrevTitle() == null) {
1188 csvLine
[table
.getIndex(CdmLightExportTable
.ABBREV_TITLE
)] = CdmUtils
1189 .Nz(nomRef
.getTitle()!= null? nomRef
.getTitle():nomRef
.getAbbrevTitleCache());
1191 csvLine
[table
.getIndex(CdmLightExportTable
.ABBREV_TITLE
)] = CdmUtils
1192 .Nz(nomRef
.getAbbrevTitle());
1194 if (nomRef
.getTitle() == null) {
1195 csvLine
[table
.getIndex(CdmLightExportTable
.FULL_TITLE
)] = CdmUtils
1196 .Nz(nomRef
.getAbbrevTitle()!= null? nomRef
.getAbbrevTitle(): nomRef
.getTitleCache());
1198 csvLine
[table
.getIndex(CdmLightExportTable
.FULL_TITLE
)] = CdmUtils
.Nz(nomRef
.getTitle());
1200 TeamOrPersonBase
<?
> author
= nomRef
.getAuthorship();
1201 if (author
!= null) {
1202 csvLine
[table
.getIndex(CdmLightExportTable
.ABBREV_REF_AUTHOR
)] = author
.isProtectedTitleCache()
1203 ? author
.getTitleCache() : CdmUtils
.Nz(author
.getNomenclaturalTitleCache());
1204 csvLine
[table
.getIndex(CdmLightExportTable
.FULL_REF_AUTHOR
)] = CdmUtils
1205 .Nz(author
.getTitleCache());
1207 csvLine
[table
.getIndex(CdmLightExportTable
.ABBREV_REF_AUTHOR
)] = "";
1208 csvLine
[table
.getIndex(CdmLightExportTable
.FULL_REF_AUTHOR
)] = "";
1213 csvLine
[table
.getIndex(CdmLightExportTable
.PUBLICATION_TYPE
)] = "";
1223 String protologueUriString
= extractProtologueURIs(state
, name
);
1225 csvLine
[table
.getIndex(CdmLightExportTable
.PROTOLOGUE_URI
)] = protologueUriString
;
1226 Collection
<TypeDesignationBase
> specimenTypeDesignations
= new ArrayList
<>();
1227 List
<TextualTypeDesignation
> textualTypeDesignations
= new ArrayList
<>();
1228 for (TypeDesignationBase
<?
> typeDesignation
: name
.getTypeDesignations()) {
1229 if (typeDesignation
.isInstanceOf(TextualTypeDesignation
.class)) {
1231 if (((TextualTypeDesignation
) typeDesignation
).isVerbatim() ){
1232 Set
<IdentifiableSource
> sources
= typeDesignation
.getSources();
1233 boolean isProtologue
= false;
1234 if (sources
!= null && !sources
.isEmpty()){
1235 IdentifiableSource source
= sources
.iterator().next();
1236 if (name
.getNomenclaturalReference() != null){
1237 isProtologue
= source
.getCitation() != null? source
.getCitation().getUuid().equals(name
.getNomenclaturalReference().getUuid()): false;
1241 csvLine
[table
.getIndex(CdmLightExportTable
.PROTOLOGUE_TYPE_STATEMENT
)] = ((TextualTypeDesignation
) typeDesignation
)
1242 .getPreferredText(Language
.DEFAULT());
1244 textualTypeDesignations
.add((TextualTypeDesignation
) typeDesignation
);
1248 textualTypeDesignations
.add((TextualTypeDesignation
) typeDesignation
);
1250 } else if (typeDesignation
.isInstanceOf(SpecimenTypeDesignation
.class)) {
1251 SpecimenTypeDesignation specimenType
= HibernateProxyHelper
.deproxy(typeDesignation
, SpecimenTypeDesignation
.class);
1252 specimenTypeDesignations
.add(specimenType
);
1253 handleSpecimenType(state
, specimenType
);
1256 }else if (typeDesignation
instanceof NameTypeDesignation
){
1257 specimenTypeDesignations
.add(HibernateProxyHelper
.deproxy(typeDesignation
, NameTypeDesignation
.class));
1260 TypeDesignationSetManager manager
= new TypeDesignationSetManager(specimenTypeDesignations
, name
);
1261 HTMLTagRules rules
= new HTMLTagRules();
1262 rules
.addRule(TagEnum
.name
, "i");
1263 String test
= manager
.print(false, false, false, rules
);;
1264 csvLine
[table
.getIndex(CdmLightExportTable
.TYPE_SPECIMEN
)] = manager
.print(false, false, false, rules
);
1266 StringBuilder stringbuilder
= new StringBuilder();
1268 for (TextualTypeDesignation typeDesignation
: textualTypeDesignations
) {
1269 stringbuilder
.append(typeDesignation
.getPreferredText(Language
.DEFAULT()));
1270 if (typeDesignation
.getSources() != null && !typeDesignation
.getSources().isEmpty() ){
1271 stringbuilder
.append( " [");
1273 for (IdentifiableSource source
: typeDesignation
.getSources()){
1274 if (source
.getCitation() != null){
1275 stringbuilder
.append(OriginalSourceFormatter
.INSTANCE
.format(source
));
1277 if (index
< typeDesignation
.getSources().size()) {
1278 stringbuilder
.append( ", ");
1282 stringbuilder
.append( "]");
1284 if (i
< textualTypeDesignations
.size()) {
1285 stringbuilder
.append( "; ");
1287 stringbuilder
.append(".");
1291 csvLine
[table
.getIndex(CdmLightExportTable
.TYPE_STATEMENT
)] = stringbuilder
.toString();
1294 if (name
.getStatus() == null || name
.getStatus().isEmpty()) {
1295 csvLine
[table
.getIndex(CdmLightExportTable
.NOM_STATUS
)] = "";
1296 csvLine
[table
.getIndex(CdmLightExportTable
.NOM_STATUS_ABBREV
)] = "";
1299 String statusStringAbbrev
= extractStatusString(state
, name
, true);
1300 String statusString
= extractStatusString(state
, name
, false);
1302 csvLine
[table
.getIndex(CdmLightExportTable
.NOM_STATUS
)] = statusString
.trim();
1303 csvLine
[table
.getIndex(CdmLightExportTable
.NOM_STATUS_ABBREV
)] = statusStringAbbrev
.trim();
1306 HomotypicalGroup group
= HibernateProxyHelper
.deproxy(name
.getHomotypicalGroup(), HomotypicalGroup
.class);
1308 csvLine
[table
.getIndex(CdmLightExportTable
.HOMOTYPIC_GROUP_FK
)] = getId(state
, group
);
1309 List
<TaxonName
> typifiedNames
= new ArrayList
<>();
1310 if (acceptedTaxon
!= null){
1311 HomotypicGroupTaxonComparator comparator
= new HomotypicGroupTaxonComparator(acceptedTaxon
);
1312 List
<Synonym
> synonymsInGroup
= null;
1313 if (group
.equals(acceptedTaxon
.getHomotypicGroup())){
1314 synonymsInGroup
= acceptedTaxon
.getHomotypicSynonymsByHomotypicGroup(comparator
);
1315 typifiedNames
.add(name
);
1317 synonymsInGroup
= acceptedTaxon
.getSynonymsInGroup(group
, comparator
);
1320 synonymsInGroup
.stream().forEach(synonym
-> typifiedNames
.add(HibernateProxyHelper
.deproxy(synonym
.getName(), TaxonName
.class)));
1323 typifiedNames
.addAll(group
.getTypifiedNames());
1327 Integer seqNumber
= typifiedNames
.indexOf(name
);
1328 csvLine
[table
.getIndex(CdmLightExportTable
.HOMOTYPIC_GROUP_SEQ
)] = String
.valueOf(seqNumber
);
1329 state
.getProcessor().put(table
, name
, csvLine
);
1330 handleNameRelationships(state
, name
);
1332 } catch (Exception e
) {
1333 state
.getResult().addException(e
,
1334 "An unexpected error occurred when handling the name " + cdmBaseStr(name
) + ": " + name
.getTitleCache() + ": " + e
.getMessage());
1336 e
.printStackTrace();
1341 * @param specimenType
1343 private void handleSpecimenType_(CdmLightExportState state
, SpecimenTypeDesignation specimenType
) {
1344 if (specimenType
.getTypeSpecimen() != null){
1345 DerivedUnit specimen
= specimenType
.getTypeSpecimen();
1346 if(specimen
!= null && !state
.getSpecimenStore().contains( specimen
.getUuid())){
1347 handleSpecimen(state
, specimen
);
1350 CdmLightExportTable table
= CdmLightExportTable
.TYPE_DESIGNATION
;
1351 String
[] csvLine
= new String
[table
.getSize()];
1352 //TYPE_ID, SPECIMEN_FK, TYPE_VERBATIM_CITATION, TYPE_STATUS, TYPE_DESIGNATED_BY_STRING, TYPE_DESIGNATED_BY_REF_FK};
1353 //Specimen_Fk und den Typusangaben (Art des Typus [holo, lecto, etc.], Quelle, Designation-Quelle, +
1354 Set
<TaxonName
> typifiedNames
= specimenType
.getTypifiedNames();
1355 for (TaxonName name
: typifiedNames
){
1356 csvLine
[table
.getIndex(CdmLightExportTable
.TYPE_STATUS
)] = specimenType
.getTypeStatus() != null? specimenType
.getTypeStatus().getDescription(): "";
1357 csvLine
[table
.getIndex(CdmLightExportTable
.TYPE_ID
)] = getId(state
, specimenType
);
1358 csvLine
[table
.getIndex(CdmLightExportTable
.TYPIFIED_NAME_FK
)] = getId(state
, name
);
1359 csvLine
[table
.getIndex(CdmLightExportTable
.SPECIMEN_FK
)] = getId(state
, specimenType
.getTypeSpecimen());
1360 if (specimenType
.getSources() != null && !specimenType
.getSources().isEmpty()){
1361 String sourceString
= "";
1363 for (IdentifiableSource source
: specimenType
.getSources()){
1364 if (source
.getCitation()!= null){
1365 sourceString
= sourceString
.concat(source
.getCitation().getCitation());
1368 if (index
!= specimenType
.getSources().size()){
1369 sourceString
.concat(", ");
1372 csvLine
[table
.getIndex(CdmLightExportTable
.TYPE_INFORMATION_REF_STRING
)] = sourceString
;
1374 if (specimenType
.getDesignationSource() != null && specimenType
.getDesignationSource().getCitation() != null && !state
.getReferenceStore().contains(specimenType
.getDesignationSource().getCitation().getUuid())){
1375 handleReference(state
, specimenType
.getDesignationSource().getCitation());
1376 csvLine
[table
.getIndex(CdmLightExportTable
.TYPE_DESIGNATED_BY_REF_FK
)] = specimenType
.getDesignationSource() != null ?
getId(state
, specimenType
.getDesignationSource().getCitation()): "";
1379 state
.getProcessor().put(table
, specimenType
, csvLine
);
1385 * @param specimenType
1387 private void handleSpecimenType(CdmLightExportState state
, SpecimenTypeDesignation specimenType
) {
1388 if (specimenType
.getTypeSpecimen() != null){
1389 DerivedUnit specimen
= specimenType
.getTypeSpecimen();
1390 if(specimen
!= null && !state
.getSpecimenStore().contains( specimen
.getUuid())){
1391 handleSpecimen(state
, specimen
);
1394 CdmLightExportTable table
= CdmLightExportTable
.TYPE_DESIGNATION
;
1395 String
[] csvLine
= new String
[table
.getSize()];
1397 csvLine
[table
.getIndex(CdmLightExportTable
.TYPE_STATUS
)] = specimenType
.getTypeStatus() != null? specimenType
.getTypeStatus().getDescription(): "";
1398 csvLine
[table
.getIndex(CdmLightExportTable
.TYPE_ID
)] = getId(state
, specimenType
);
1399 csvLine
[table
.getIndex(CdmLightExportTable
.SPECIMEN_FK
)] = getId(state
, specimenType
.getTypeSpecimen());
1400 if (specimenType
.getSources() != null && !specimenType
.getSources().isEmpty()){
1401 String sourceString
= "";
1403 List
<IdentifiableSource
> sources
= new ArrayList
<>(specimenType
.getSources());
1404 Comparator
<IdentifiableSource
> compareByYear
= new Comparator
<IdentifiableSource
>() {
1406 public int compare(IdentifiableSource o1
, IdentifiableSource o2
) {
1410 if (o1
.getCitation() == null && o2
.getCitation() != null){
1413 if (o2
.getCitation() == null && o1
.getCitation() != null){
1416 if (o1
.getCitation().equals(o2
.getCitation())){
1419 if (o1
.getCitation().getDatePublished() == null && o2
.getCitation().getDatePublished() != null){
1422 if (o1
.getCitation().getDatePublished() != null && o2
.getCitation().getDatePublished() == null){
1425 if (o1
.getCitation().getDatePublished().getYear() == null && o2
.getCitation().getDatePublished().getYear() != null){
1428 if (o1
.getCitation().getDatePublished().getYear() != null && o2
.getCitation().getDatePublished().getYear() == null){
1431 return o1
.getCitation().getDatePublished().getYear().compareTo(o2
.getCitation().getDatePublished().getYear());
1434 Collections
.sort(sources
, compareByYear
);
1435 for (IdentifiableSource source
: sources
){
1436 if (source
.getCitation()!= null){
1437 sourceString
= sourceString
.concat(source
.getCitation().getCitation());
1438 handleReference(state
, source
.getCitation());
1441 if (index
<= specimenType
.getSources().size()){
1442 sourceString
= sourceString
.concat("; ");
1446 csvLine
[table
.getIndex(CdmLightExportTable
.TYPE_INFORMATION_REF_STRING
)] = sourceString
;
1447 if (sources
.get(0).getCitation() != null ){
1448 csvLine
[table
.getIndex(CdmLightExportTable
.TYPE_INFORMATION_REF_FK
)] = getId(state
, sources
.get(0).getCitation());
1451 if (specimenType
.getDesignationSource() != null && specimenType
.getDesignationSource().getCitation() != null && !state
.getReferenceStore().contains(specimenType
.getDesignationSource().getCitation().getUuid())){
1452 handleReference(state
, specimenType
.getDesignationSource().getCitation());
1453 csvLine
[table
.getIndex(CdmLightExportTable
.TYPE_DESIGNATED_BY_REF_FK
)] = specimenType
.getDesignationSource() != null ?
getId(state
, specimenType
.getDesignationSource().getCitation()): "";
1457 Set
<TaxonName
> typifiedNames
= specimenType
.getTypifiedNames();
1459 if (typifiedNames
.size() > 1){
1460 state
.getResult().addWarning("Please check the specimen type "
1461 + cdmBaseStr(specimenType
) + " there are more then one typified name.");
1463 if (typifiedNames
.iterator().hasNext()){
1464 TaxonName name
= typifiedNames
.iterator().next();
1465 csvLine
[table
.getIndex(CdmLightExportTable
.TYPIFIED_NAME_FK
)] = getId(state
, name
);
1467 state
.getProcessor().put(table
, specimenType
, csvLine
);
1476 private String
createNameWithItalics(List
<TaggedText
> taggedName
) {
1478 String fullTitleWithHtml
= "";
1479 for (TaggedText taggedText
: taggedName
){
1480 if (taggedText
.getType().equals(TagEnum
.name
)){
1481 fullTitleWithHtml
+= "<i>" + taggedText
.getText() + "</i> ";
1482 }else if (taggedText
.getType().equals(TagEnum
.separator
)){
1483 fullTitleWithHtml
= fullTitleWithHtml
.trim() + taggedText
.getText() ;
1485 fullTitleWithHtml
+= taggedText
.getText() + " ";
1488 return fullTitleWithHtml
;
1491 private void handleNameRelationships(CdmLightExportState state
, TaxonName name
) {
1492 Set
<NameRelationship
> rels
= name
.getRelationsFromThisName();
1493 CdmLightExportTable table
= CdmLightExportTable
.NAME_RELATIONSHIP
;
1494 String
[] csvLine
= new String
[table
.getSize()];
1496 for (NameRelationship rel
: rels
) {
1497 NameRelationshipType type
= rel
.getType();
1498 TaxonName name2
= rel
.getToName();
1499 name2
= HibernateProxyHelper
.deproxy(name2
, TaxonName
.class);
1500 if (!state
.getNameStore().containsKey(name2
.getId())) {
1501 handleName(state
, name2
, null);
1504 csvLine
[table
.getIndex(CdmLightExportTable
.NAME_REL_TYPE
)] = type
.getLabel();
1505 csvLine
[table
.getIndex(CdmLightExportTable
.NAME1_FK
)] = getId(state
, name
);
1506 csvLine
[table
.getIndex(CdmLightExportTable
.NAME2_FK
)] = getId(state
, name2
);
1507 state
.getProcessor().put(table
, name
, csvLine
);
1510 rels
= name
.getRelationsToThisName();
1512 csvLine
= new String
[table
.getSize()];
1514 for (NameRelationship rel
: rels
) {
1515 NameRelationshipType type
= rel
.getType();
1516 TaxonName name2
= rel
.getFromName();
1517 name2
= HibernateProxyHelper
.deproxy(name2
, TaxonName
.class);
1518 if (!state
.getNameStore().containsKey(name2
.getId())) {
1519 handleName(state
, name2
, null);
1526 private String
createCollatation(TaxonName name
) {
1527 String collation
= "";
1528 if (name
.getNomenclaturalReference() != null) {
1529 Reference ref
= name
.getNomenclaturalReference();
1530 collation
= getVolume(ref
);
1532 if (name
.getNomenclaturalMicroReference() != null) {
1533 if (!StringUtils
.isBlank(collation
)) {
1536 collation
+= name
.getNomenclaturalMicroReference();
1542 private String
getVolume(Reference reference
) {
1543 if (reference
.getVolume() != null) {
1544 return reference
.getVolume();
1545 } else if (reference
.getInReference() != null) {
1546 if (reference
.getInReference().getVolume() != null) {
1547 return reference
.getInReference().getVolume();
1553 private void handleIdentifier(CdmLightExportState state
, CdmBase cdmBase
) {
1554 CdmLightExportTable table
= CdmLightExportTable
.IDENTIFIER
;
1557 if (cdmBase
instanceof TaxonName
){
1558 TaxonName name
= (TaxonName
)cdmBase
;
1561 List
<Identifier
> identifiers
= name
.getIdentifiers();
1563 //first check which kind of identifiers are available and then sort and create table entries
1564 Map
<DefinedTerm
, Set
<Identifier
>> identifierTypes
= new HashMap
<>();
1565 for (Identifier identifier
: identifiers
){
1566 DefinedTerm type
= identifier
.getType();
1567 if (identifierTypes
.containsKey(type
)){
1568 identifierTypes
.get(type
).add(identifier
);
1570 Set
<Identifier
> tempList
= new HashSet
<>();
1571 tempList
.add(identifier
);
1572 identifierTypes
.put(type
, tempList
);
1576 for (DefinedTerm type
:identifierTypes
.keySet()){
1577 Set
<Identifier
> identifiersByType
= identifierTypes
.get(type
);
1578 csvLine
= new String
[table
.getSize()];
1579 csvLine
[table
.getIndex(CdmLightExportTable
.FK
)] = getId(state
, name
);
1580 csvLine
[table
.getIndex(CdmLightExportTable
.REF_TABLE
)] = "ScientificName";
1581 csvLine
[table
.getIndex(CdmLightExportTable
.IDENTIFIER_TYPE
)] = type
.getLabel();
1582 csvLine
[table
.getIndex(CdmLightExportTable
.EXTERNAL_NAME_IDENTIFIER
)] = extractIdentifier(
1584 state
.getProcessor().put(table
, name
.getUuid() + ", " + type
.getLabel(), csvLine
);
1588 // Set<String> IPNIidentifiers = name.getIdentifiers(DefinedTerm.IDENTIFIER_NAME_IPNI());
1589 // Set<String> tropicosIdentifiers = name.getIdentifiers(DefinedTerm.IDENTIFIER_NAME_TROPICOS());
1590 // Set<String> WFOIdentifiers = name.getIdentifiers(DefinedTerm.uuidWfoNameIdentifier);
1591 // if (!IPNIidentifiers.isEmpty()) {
1592 // csvLine = new String[table.getSize()];
1593 // csvLine[table.getIndex(CdmLightExportTable.FK)] = getId(state, name);
1594 // csvLine[table.getIndex(CdmLightExportTable.REF_TABLE)] = "ScientificName";
1595 // csvLine[table.getIndex(CdmLightExportTable.IDENTIFIER_TYPE)] = IPNI_NAME_IDENTIFIER;
1596 // csvLine[table.getIndex(CdmLightExportTable.EXTERNAL_NAME_IDENTIFIER)] = extractIdentifier(
1597 // IPNIidentifiers);
1598 // state.getProcessor().put(table, name.getUuid() + ", " + IPNI_NAME_IDENTIFIER, csvLine);
1600 // if (!tropicosIdentifiers.isEmpty()) {
1601 // csvLine = new String[table.getSize()];
1602 // csvLine[table.getIndex(CdmLightExportTable.FK)] = getId(state, name);
1603 // csvLine[table.getIndex(CdmLightExportTable.REF_TABLE)] = "ScientificName";
1604 // csvLine[table.getIndex(CdmLightExportTable.IDENTIFIER_TYPE)] = TROPICOS_NAME_IDENTIFIER;
1605 // csvLine[table.getIndex(CdmLightExportTable.EXTERNAL_NAME_IDENTIFIER)] = extractIdentifier(
1606 // tropicosIdentifiers);
1607 // state.getProcessor().put(table, name.getUuid() + ", " + IPNI_NAME_IDENTIFIER, csvLine);
1609 // if (!WFOIdentifiers.isEmpty()) {
1610 // csvLine = new String[table.getSize()];
1611 // csvLine[table.getIndex(CdmLightExportTable.FK)] = getId(state, name);
1612 // csvLine[table.getIndex(CdmLightExportTable.REF_TABLE)] = "ScientificName";
1613 // csvLine[table.getIndex(CdmLightExportTable.IDENTIFIER_TYPE)] = WFO_NAME_IDENTIFIER;
1614 // csvLine[table.getIndex(CdmLightExportTable.EXTERNAL_NAME_IDENTIFIER)] = extractIdentifier(
1616 // state.getProcessor().put(table, name.getUuid() + ", " + WFO_NAME_IDENTIFIER, csvLine);
1618 }catch(Exception e
){
1619 state
.getResult().addWarning("Please check the identifiers for "
1620 + cdmBaseStr(cdmBase
) + " maybe there is an empty identifier");
1625 if (cdmBase
instanceof IdentifiableEntity
){
1626 IdentifiableEntity
<?
> identifiableEntity
= (IdentifiableEntity
<?
>) cdmBase
;
1627 List
<Identifier
> identifiers
= identifiableEntity
.getIdentifiers();
1628 String tableName
= null;
1629 if (cdmBase
instanceof Reference
){
1630 tableName
= "Reference";
1631 }else if (cdmBase
instanceof SpecimenOrObservationBase
){
1632 tableName
= "Specimen";
1633 }else if (cdmBase
instanceof Taxon
){
1634 tableName
= "Taxon";
1635 }else if (cdmBase
instanceof Synonym
){
1636 tableName
= "Synonym";
1637 }else if (cdmBase
instanceof TeamOrPersonBase
){
1638 tableName
= "PersonOrTeam";
1641 for (Identifier identifier
: identifiers
){
1642 if (identifier
.getType() == null && identifier
.getIdentifier() == null){
1643 state
.getResult().addWarning("Please check the identifiers for "
1644 + cdmBaseStr(cdmBase
) + " there is an empty identifier");
1648 csvLine
= new String
[table
.getSize()];
1649 csvLine
[table
.getIndex(CdmLightExportTable
.FK
)] = getId(state
, cdmBase
);
1651 if (tableName
!= null){
1652 csvLine
[table
.getIndex(CdmLightExportTable
.REF_TABLE
)] = tableName
;
1653 csvLine
[table
.getIndex(CdmLightExportTable
.IDENTIFIER_TYPE
)] = identifier
.getType() != null? identifier
.getType().getLabel():null;
1654 csvLine
[table
.getIndex(CdmLightExportTable
.EXTERNAL_NAME_IDENTIFIER
)] = identifier
.getIdentifier();
1655 state
.getProcessor().put(table
, cdmBase
.getUuid() + (identifier
.getType() != null? identifier
.getType().getLabel():null), csvLine
);
1658 if (cdmBase
instanceof Reference
){
1659 Reference ref
= (Reference
)cdmBase
;
1660 if (ref
.getDoi() != null){
1661 csvLine
= new String
[table
.getSize()];
1662 csvLine
[table
.getIndex(CdmLightExportTable
.FK
)] = getId(state
, cdmBase
);
1663 csvLine
[table
.getIndex(CdmLightExportTable
.REF_TABLE
)] = tableName
;
1664 csvLine
[table
.getIndex(CdmLightExportTable
.IDENTIFIER_TYPE
)] = "DOI";
1665 csvLine
[table
.getIndex(CdmLightExportTable
.EXTERNAL_NAME_IDENTIFIER
)] = ref
.getDoiString();
1666 state
.getProcessor().put(table
, cdmBase
.getUuid() + "DOI", csvLine
);
1670 if (cdmBase
instanceof TeamOrPersonBase
){
1671 TeamOrPersonBase
<?
> person
= HibernateProxyHelper
.deproxy(cdmBase
, TeamOrPersonBase
.class);
1672 if (person
instanceof Person
&& ((Person
)person
).getOrcid() != null){
1673 csvLine
= new String
[table
.getSize()];
1674 csvLine
[table
.getIndex(CdmLightExportTable
.FK
)] = getId(state
, cdmBase
);
1675 csvLine
[table
.getIndex(CdmLightExportTable
.REF_TABLE
)] = tableName
;
1676 csvLine
[table
.getIndex(CdmLightExportTable
.IDENTIFIER_TYPE
)] = "ORCID";
1677 csvLine
[table
.getIndex(CdmLightExportTable
.EXTERNAL_NAME_IDENTIFIER
)]= ((Person
)person
).getOrcid().asURI();
1678 state
.getProcessor().put(table
, cdmBase
.getUuid() + "ORCID", csvLine
);
1683 } catch (Exception e
) {
1684 state
.getResult().addException(e
, "An unexpected error occurred when handling identifiers for "
1685 + cdmBaseStr(cdmBase
) + ": " + e
.getMessage());
1686 e
.printStackTrace();
1690 private String
extractIdentifier(Set
<Identifier
> identifierSet
) {
1692 String identifierString
= "";
1693 for (Identifier identifier
: identifierSet
) {
1694 if (!StringUtils
.isBlank(identifierString
)) {
1695 identifierString
+= ", ";
1697 identifierString
+= identifier
.getIdentifier();
1699 return identifierString
;
1702 private String
extractProtologueURIs(CdmLightExportState state
, TaxonName name
) {
1703 if (name
.getNomenclaturalSource() != null){
1704 Set
<ExternalLink
> links
= name
.getNomenclaturalSource().getLinks();
1705 return extractLinkUris(links
.iterator());
1711 private String
extractMediaURIs(CdmLightExportState state
, Set
<?
extends DescriptionBase
<?
>> descriptionsSet
,
1714 String mediaUriString
= "";
1715 Set
<DescriptionElementBase
> elements
= new HashSet
<>();
1716 for (DescriptionBase
<?
> description
: descriptionsSet
) {
1718 if (!description
.getElements().isEmpty()) {
1719 elements
= description
.getElements();
1721 for (DescriptionElementBase element
: elements
) {
1722 Feature entityFeature
= HibernateProxyHelper
.deproxy(element
.getFeature());
1723 if (entityFeature
.equals(feature
)) {
1724 if (!element
.getMedia().isEmpty()) {
1725 List
<Media
> media
= element
.getMedia();
1726 for (Media mediaElement
: media
) {
1727 Iterator
<MediaRepresentation
> it
= mediaElement
.getRepresentations().iterator();
1728 mediaUriString
= extractMediaUris(it
);
1734 } catch (Exception e
) {
1735 state
.getResult().addException(e
, "An unexpected error occurred when extracting media URIs for "
1736 + cdmBaseStr(description
) + ": " + e
.getMessage());
1739 return mediaUriString
;
1742 private void handleAuthor(CdmLightExportState state
, TeamOrPersonBase
<?
> author
) {
1744 if (state
.getAuthorFromStore(author
.getId()) != null) {
1747 state
.addAuthorToStore(author
);
1748 handleIdentifier(state
, author
);
1749 CdmLightExportTable table
= CdmLightExportTable
.NOMENCLATURAL_AUTHOR
;
1750 String
[] csvLine
= new String
[table
.getSize()];
1751 CdmLightExportTable tableAuthorRel
= CdmLightExportTable
.NOMENCLATURAL_AUTHOR_TEAM_RELATION
;
1752 String
[] csvLineRel
= new String
[tableAuthorRel
.getSize()];
1753 String
[] csvLineMember
= new String
[table
.getSize()];
1754 csvLine
[table
.getIndex(CdmLightExportTable
.AUTHOR_ID
)] = getId(state
, author
);
1755 csvLine
[table
.getIndex(CdmLightExportTable
.ABBREV_AUTHOR
)] = author
.isProtectedTitleCache()
1756 ? author
.getTitleCache() : author
.getNomenclaturalTitleCache();
1757 csvLine
[table
.getIndex(CdmLightExportTable
.AUTHOR_TITLE
)] = author
.getTitleCache();
1758 author
= HibernateProxyHelper
.deproxy(author
);
1759 if (author
instanceof Person
) {
1760 Person authorPerson
= (Person
) author
;
1761 csvLine
[table
.getIndex(CdmLightExportTable
.AUTHOR_GIVEN_NAME
)] = authorPerson
.getGivenName();
1762 csvLine
[table
.getIndex(CdmLightExportTable
.AUTHOR_FAMILY_NAME
)] = authorPerson
.getFamilyName();
1763 csvLine
[table
.getIndex(CdmLightExportTable
.AUTHOR_PREFIX
)] = authorPerson
.getPrefix();
1764 csvLine
[table
.getIndex(CdmLightExportTable
.AUTHOR_SUFFIX
)] = authorPerson
.getSuffix();
1766 // create an entry in rel table and all members in author table,
1767 // check whether the team members already in author table
1769 Team authorTeam
= (Team
) author
;
1771 for (Person member
: authorTeam
.getTeamMembers()) {
1772 csvLineRel
= new String
[tableAuthorRel
.getSize()];
1773 csvLineRel
[tableAuthorRel
.getIndex(CdmLightExportTable
.AUTHOR_TEAM_FK
)] = getId(state
, authorTeam
);
1774 csvLineRel
[tableAuthorRel
.getIndex(CdmLightExportTable
.AUTHOR_FK
)] = getId(state
, member
);
1775 csvLineRel
[tableAuthorRel
.getIndex(CdmLightExportTable
.AUTHOR_TEAM_SEQ_NUMBER
)] = String
1777 state
.getProcessor().put(tableAuthorRel
, authorTeam
.getId() + ":" + member
.getId(), csvLineRel
);
1779 if (state
.getAuthorFromStore(member
.getId()) == null) {
1780 state
.addAuthorToStore(member
);
1781 csvLineMember
= new String
[table
.getSize()];
1782 csvLineMember
[table
.getIndex(CdmLightExportTable
.AUTHOR_ID
)] = getId(state
, member
);
1783 csvLineMember
[table
.getIndex(CdmLightExportTable
.ABBREV_AUTHOR
)] = member
1784 .isProtectedTitleCache() ? member
.getTitleCache() : member
.getNomenclaturalTitleCache();
1785 csvLineMember
[table
.getIndex(CdmLightExportTable
.AUTHOR_TITLE
)] = member
.getTitleCache();
1786 csvLineMember
[table
.getIndex(CdmLightExportTable
.AUTHOR_GIVEN_NAME
)] = member
.getGivenName();
1787 csvLineMember
[table
.getIndex(CdmLightExportTable
.AUTHOR_FAMILY_NAME
)] = member
.getFamilyName();
1788 csvLineMember
[table
.getIndex(CdmLightExportTable
.AUTHOR_PREFIX
)] = member
.getPrefix();
1789 csvLineMember
[table
.getIndex(CdmLightExportTable
.AUTHOR_SUFFIX
)] = member
.getSuffix();
1790 state
.getProcessor().put(table
, member
, csvLineMember
);
1795 state
.getProcessor().put(table
, author
, csvLine
);
1796 } catch (Exception e
) {
1797 state
.getResult().addException(e
,
1798 "An unexpected error occurred when handling author " + cdmBaseStr(author
) + ": " + e
.getMessage());
1802 private String
extractStatusString(CdmLightExportState state
, TaxonName name
, boolean abbrev
) {
1804 Set
<NomenclaturalStatus
> status
= name
.getStatus();
1805 if (status
.isEmpty()) {
1808 String statusString
= "";
1809 for (NomenclaturalStatus nameStatus
: status
) {
1810 if (nameStatus
!= null) {
1812 if (nameStatus
.getType() != null) {
1813 statusString
+= nameStatus
.getType().getIdInVocabulary();
1816 if (nameStatus
.getType() != null) {
1817 statusString
+= nameStatus
.getType().getTitleCache();
1822 if (nameStatus
.getRuleConsidered() != null
1823 && !StringUtils
.isBlank(nameStatus
.getRuleConsidered())) {
1824 statusString
+= ": " + nameStatus
.getRuleConsidered();
1826 if (nameStatus
.getCitation() != null) {
1827 String shortCitation
= OriginalSourceFormatter
.INSTANCE
.format(nameStatus
.getCitation(), null);
1828 statusString
+= " (" + shortCitation
+ ")";
1830 // if (nameStatus.getCitationMicroReference() != null
1831 // && !StringUtils.isBlank(nameStatus.getCitationMicroReference())) {
1832 // statusString += " " + nameStatus.getCitationMicroReference();
1835 statusString
+= " ";
1838 return statusString
;
1839 } catch (Exception e
) {
1840 state
.getResult().addException(e
, "An unexpected error occurred when extracting status string for "
1841 + cdmBaseStr(name
) + ": " + e
.getMessage());
1846 private void handleHomotypicalGroup(CdmLightExportState state
, HomotypicalGroup group
, Taxon acceptedTaxon
, int sortIndex
) {
1848 state
.addHomotypicalGroupToStore(group
);
1849 CdmLightExportTable table
= CdmLightExportTable
.HOMOTYPIC_GROUP
;
1850 String
[] csvLine
= new String
[table
.getSize()];
1851 csvLine
[table
.getIndex(CdmLightExportTable
.SORT_INDEX
)] = String
.valueOf(sortIndex
);
1852 csvLine
[table
.getIndex(CdmLightExportTable
.HOMOTYPIC_GROUP_ID
)] = getId(state
, group
);
1854 List
<TaxonName
> typifiedNames
= new ArrayList
<>();
1855 if (acceptedTaxon
!= null){
1856 List
<Synonym
> synonymsInGroup
= acceptedTaxon
.getSynonymsInGroup(group
);
1857 if (group
.equals(acceptedTaxon
.getHomotypicGroup())){
1858 typifiedNames
.add(acceptedTaxon
.getName());
1860 synonymsInGroup
.stream().forEach(synonym
-> typifiedNames
.add(CdmBase
.deproxy(synonym
.getName())));
1864 TaxonName firstname
= null;
1865 for (TaxonName name
: typifiedNames
){
1866 Iterator
<Taxon
> taxa
= name
.getTaxa().iterator();
1867 while(taxa
.hasNext()){
1868 Taxon taxon
= taxa
.next();
1869 if(!(taxon
.isMisapplication() || taxon
.isProparteSynonym())){
1876 // Collections.sort(typifiedNames, new HomotypicalGroupNameComparator(firstname, true));
1877 String typifiedNamesString
= "";
1878 String typifiedNamesWithSecString
= "";
1879 String typifiedNamesWithoutAccepted
= "";
1880 String typifiedNamesWithoutAcceptedWithSec
= "";
1882 for (TaxonName name
: typifiedNames
) {
1883 // Concatenated output string for homotypic group (names and
1884 // citations) + status + some name relations (e.g. “non”)
1885 // TODO: nameRelations, which and how to display
1886 Set
<TaxonBase
> taxonBases
= name
.getTaxonBases();
1887 TaxonBase
<?
> taxonBase
;
1890 String nameString
= name
.getFullTitleCache();
1891 String doubtful
= "";
1893 if (state
.getConfig().isAddHTML()){
1894 nameString
= createNameWithItalics(name
.getTaggedFullTitle()) ;
1897 Set
<NameRelationship
> related
= name
.getNameRelations();
1898 List
<NameRelationship
> relatedList
= new ArrayList
<>(related
);
1900 Collections
.sort(relatedList
, new Comparator
<NameRelationship
>() {
1902 public int compare(NameRelationship nr1
, NameRelationship nr2
) {
1903 return nr1
.getType().compareTo(nr2
.getType());
1908 List
<NameRelationship
> nonNames
= new ArrayList
<>();
1909 List
<NameRelationship
> otherRelationships
= new ArrayList
<>();
1911 for (NameRelationship rel
: relatedList
){
1912 //no inverse relations
1913 if (rel
.getFromName().equals(name
)){
1914 // alle Homonyme und inverse blocking names
1915 if (rel
.getType().equals(NameRelationshipType
.LATER_HOMONYM())
1916 || rel
.getType().equals(NameRelationshipType
.TREATED_AS_LATER_HOMONYM())
1917 || (rel
.getType().equals(NameRelationshipType
.BLOCKING_NAME_FOR()))
1918 || (rel
.getType().equals(NameRelationshipType
.UNSPECIFIC_NON()))){
1920 }else if (!rel
.getType().isBasionymRelation()){
1921 otherRelationships
.add(rel
);
1926 String nonRelNames
= "";
1927 String relNames
= "";
1929 if (nonNames
.size() > 0){
1930 nonRelNames
+= " [";
1932 for (NameRelationship relName
: nonNames
){
1933 String label
= "non ";
1934 TaxonName relatedName
= null;
1935 if (relName
.getFromName().equals(name
)){
1936 relatedName
= relName
.getToName();
1937 nonRelNames
+= label
+ relatedName
.getTitleCache() + " ";
1940 // label = relName.getType().getInverseLabel() + " ";
1941 // relatedName = relName.getFromName();
1942 // nonRelNames += label + relatedName.getTitleCache() + " ";
1948 if (nonNames
.size() > 0){
1949 nonRelNames
= StringUtils
.strip(nonRelNames
, null);
1950 nonRelNames
+= "] ";
1953 if (otherRelationships
.size() > 0){
1956 for (NameRelationship rel
: otherRelationships
){
1958 TaxonName relatedName
= null;
1959 if (rel
.getFromName().equals(name
)){
1960 label
= rel
.getType().getLabel() + " ";
1961 relatedName
= rel
.getToName();
1962 if (state
.getConfig().isAddHTML()){
1963 relNames
+= label
+ createNameWithItalics(relatedName
.getTaggedName())+ " ";
1965 relNames
+= label
+ relatedName
.getTitleCache();
1969 // label = rel.getType().getInverseLabel() + " ";
1970 // relatedName = rel.getFromName();
1975 if (otherRelationships
.size() > 0){
1976 relNames
= StringUtils
.stripEnd(relNames
, null);
1980 String synonymSign
= "";
1982 if (name
.isInvalid()){
1983 synonymSign
= "\u2212 ";
1985 synonymSign
= "\u2261 ";
1988 if (name
.isInvalid() ){
1989 synonymSign
= "\u2212 ";
1991 synonymSign
= "\u003D ";
1994 boolean isAccepted
= false;
1996 if (taxonBases
.size() == 1){
1997 taxonBase
= HibernateProxyHelper
.deproxy(taxonBases
.iterator().next());
1999 if (taxonBase
.getSec() != null){
2000 sec
= OriginalSourceFormatter
.INSTANCE_WITH_YEAR_BRACKETS
.format(taxonBase
.getSecSource());
2002 if (taxonBase
.isDoubtful()){
2007 if (taxonBase
instanceof Synonym
){
2008 if (isNotBlank(sec
)){
2009 sec
= " syn. sec. " + sec
+ " ";
2014 typifiedNamesWithoutAccepted
+= synonymSign
+ doubtful
+ nameString
+ nonRelNames
+ relNames
;
2015 typifiedNamesWithoutAcceptedWithSec
+= synonymSign
+ doubtful
+ nameString
+ sec
+ nonRelNames
+ relNames
;
2018 if (!(((Taxon
)taxonBase
).isProparteSynonym() || ((Taxon
)taxonBase
).isMisapplication())){
2021 synonymSign
= "\u003D ";
2025 if (taxonBase
.getAppendedPhrase() != null){
2026 if (state
.getConfig().isAddHTML()){
2027 String taxonString
= createNameWithItalics(taxonBase
.getTaggedTitle()) ;
2028 taxonString
= taxonString
.replace("sec "+sec
, "");
2029 String nameCacheWithItalics
= createNameWithItalics(name
.getTaggedName());
2030 nameString
= nameString
.replace(nameCacheWithItalics
, taxonString
);
2034 //there are names used more than once?
2035 for (TaxonBase
<?
> tb
: taxonBases
){
2036 if (tb
.getSec() != null){
2037 sec
= OriginalSourceFormatter
.INSTANCE_WITH_YEAR_BRACKETS
.format(tb
.getSecSource());
2039 if (tb
.isDoubtful()){
2044 if (tb
instanceof Synonym
){
2045 if (StringUtils
.isNotBlank(sec
)){
2046 sec
= " syn. sec. " + sec
+ " ";
2054 if (!(((Taxon
)tb
).isProparteSynonym() || ((Taxon
)tb
).isMisapplication())){
2058 synonymSign
= "\u003D ";
2064 typifiedNamesWithoutAccepted
+= synonymSign
+ doubtful
+ nameString
+ "; ";
2065 typifiedNamesWithoutAcceptedWithSec
+= synonymSign
+ doubtful
+ nameString
+ sec
;
2066 typifiedNamesWithoutAcceptedWithSec
= typifiedNamesWithoutAcceptedWithSec
.trim() + "; ";
2069 typifiedNamesString
+= synonymSign
+ doubtful
+ nameString
+ nonRelNames
+ relNames
;
2070 typifiedNamesWithSecString
+= synonymSign
+ doubtful
+ nameString
+ sec
+ nonRelNames
+ relNames
;
2073 csvLine
[table
.getIndex(CdmLightExportTable
.HOMOTYPIC_GROUP_STRING
)] = typifiedNamesString
.trim();
2075 csvLine
[table
.getIndex(CdmLightExportTable
.HOMOTYPIC_GROUP_WITH_SEC_STRING
)] = typifiedNamesWithSecString
.trim();
2077 if (typifiedNamesWithoutAccepted
!= null && firstname
!= null) {
2078 csvLine
[table
.getIndex(CdmLightExportTable
.HOMOTYPIC_GROUP_WITHOUT_ACCEPTED
)] = typifiedNamesWithoutAccepted
.trim();
2080 csvLine
[table
.getIndex(CdmLightExportTable
.HOMOTYPIC_GROUP_WITHOUT_ACCEPTED
)] = "";
2083 if (typifiedNamesWithoutAcceptedWithSec
!= null && firstname
!= null) {
2084 csvLine
[table
.getIndex(CdmLightExportTable
.HOMOTYPIC_GROUP_WITHOUT_ACCEPTEDWITHSEC
)] = typifiedNamesWithoutAcceptedWithSec
.trim();
2086 csvLine
[table
.getIndex(CdmLightExportTable
.HOMOTYPIC_GROUP_WITHOUT_ACCEPTEDWITHSEC
)] = "";
2091 Set
<TypeDesignationBase
<?
>> typeDesigantionSet
= group
.getTypeDesignations();
2092 List
<TypeDesignationBase
<?
>> designationList
= new ArrayList
<>();
2093 designationList
.addAll(typeDesigantionSet
);
2094 Collections
.sort(designationList
, new TypeComparator());
2096 List
<TaggedText
> list
= new ArrayList
<>();
2097 if (!designationList
.isEmpty()) {
2098 TypeDesignationSetManager manager
= new TypeDesignationSetManager(group
);
2099 list
.addAll(new TypeDesignationSetFormatter(true, false, false).toTaggedText(manager
));
2101 String typeTextDesignations
= "";
2102 //The typeDesignationManager does not handle the textual typeDesignations
2103 for (TypeDesignationBase
<?
> typeDes
: designationList
) {
2104 if (typeDes
instanceof TextualTypeDesignation
) {
2105 typeTextDesignations
= typeTextDesignations
+ ((TextualTypeDesignation
)typeDes
).getText(Language
.getDefaultLanguage());
2106 String typeDesStateRefs
= "";
2107 if (typeDes
.getDesignationSource() != null ){
2108 typeDesStateRefs
= "[";
2109 NamedSource source
= typeDes
.getDesignationSource();
2110 if (source
.getCitation() != null){
2111 typeDesStateRefs
+= "fide " + OriginalSourceFormatter
.INSTANCE
.format(source
.getCitation(), null);
2113 typeDesStateRefs
+= "]";
2114 }else if (typeDes
.getSources() != null && !typeDes
.getSources().isEmpty()){
2115 typeDesStateRefs
= "[";
2116 for (IdentifiableSource source
: typeDes
.getSources()) {
2117 if (source
.getCitation() != null){
2118 typeDesStateRefs
+= "fide " +OriginalSourceFormatter
.INSTANCE
.format(source
.getCitation(), null);
2122 typeDesStateRefs
+= "]";
2125 typeTextDesignations
= typeTextDesignations
+ typeDesStateRefs
+"; ";
2127 }else if (typeDes
instanceof SpecimenTypeDesignation
){
2128 DerivedUnit specimen
= ((SpecimenTypeDesignation
)typeDes
).getTypeSpecimen();
2129 if(specimen
!= null && !state
.getSpecimenStore().contains( specimen
.getUuid())){
2130 handleSpecimen(state
, specimen
);
2134 if (typeTextDesignations
.equals("; ")) {
2135 typeTextDesignations
= "";
2137 if (StringUtils
.isNotBlank(typeTextDesignations
)) {
2138 typeTextDesignations
= typeTextDesignations
.substring(0, typeTextDesignations
.length()-2);
2140 String specimenTypeString
= !list
.isEmpty()?
createTypeDesignationString(list
, true, typifiedNames
.get(0).isSpecies() || typifiedNames
.get(0).isInfraSpecific()):"";
2142 if (StringUtils
.isNotBlank(specimenTypeString
)) {
2143 if (!specimenTypeString
.endsWith(".")) {
2144 specimenTypeString
= specimenTypeString
+ ".";
2146 csvLine
[table
.getIndex(CdmLightExportTable
.TYPE_STRING
)] = specimenTypeString
;
2149 csvLine
[table
.getIndex(CdmLightExportTable
.TYPE_STRING
)] = "";
2151 if (StringUtils
.isNotBlank(typeTextDesignations
)) {
2152 if (!typeTextDesignations
.endsWith(".")) {
2153 typeTextDesignations
= typeTextDesignations
+ ".";
2155 csvLine
[table
.getIndex(CdmLightExportTable
.TYPE_CACHE
)] = typeTextDesignations
;
2158 csvLine
[table
.getIndex(CdmLightExportTable
.TYPE_CACHE
)] = "";
2160 state
.getProcessor().put(table
, String
.valueOf(group
.getId()), csvLine
);
2161 } catch (Exception e
) {
2162 state
.getResult().addException(e
, "An unexpected error occurred when handling homotypic group "
2163 + cdmBaseStr(group
) + ": " + e
.getMessage());
2167 private String
createTypeDesignationString(List
<TaggedText
> list
, boolean isHomotypicGroup
, boolean isSpecimenTypeDesignation
) {
2168 StringBuffer homotypicalGroupTypeDesignationString
= new StringBuffer();
2170 for (TaggedText text
: list
) {
2171 if (text
== null || text
.getText() == null){
2172 continue; //just in case
2174 if ((text
.getText().equalsIgnoreCase("Type:") //should not happen anymore
2175 || text
.getText().equalsIgnoreCase("Nametype:") //should not happen anymore
2176 || (text
.getType().equals(TagEnum
.name
) && !isHomotypicGroup
))) {
2178 }else if (text
.getType().equals(TagEnum
.reference
)) {
2179 homotypicalGroupTypeDesignationString
.append(text
.getText());
2180 }else if (text
.getType().equals(TagEnum
.name
)){
2181 if (!isSpecimenTypeDesignation
){
2182 homotypicalGroupTypeDesignationString
2183 .append("<i>"+text
.getText()+"</i> ");
2185 }else if (text
.getType().equals(TagEnum
.typeDesignation
) ) {
2186 if(isSpecimenTypeDesignation
){
2187 homotypicalGroupTypeDesignationString
2188 .append(text
.getText().replace(").", "").replace("(", "").replace(")", ""));
2190 homotypicalGroupTypeDesignationString
2191 .append(text
.getText());
2195 homotypicalGroupTypeDesignationString
.append(text
.getText());
2199 String typeDesignations
= homotypicalGroupTypeDesignationString
.toString();
2200 typeDesignations
= typeDesignations
.trim();
2202 if (typeDesignations
.endsWith(";")){
2203 typeDesignations
= typeDesignations
.substring(0, typeDesignations
.length()-1);
2205 typeDesignations
+= ".";
2206 typeDesignations
= typeDesignations
.replace("..", ".");
2207 typeDesignations
= typeDesignations
.replace(". .", ".");
2208 typeDesignations
= typeDesignations
.replace("; \u2261", " \u2261 ");
2210 if (typeDesignations
.trim().equals(".")) {
2211 typeDesignations
= null;
2214 return typeDesignations
;
2217 private String
getTropicosTitleCache(CdmLightExportState state
, TaxonName name
) {
2219 String basionymStart
= "(";
2220 String basionymEnd
= ") ";
2221 String exAuthorSeperator
= " ex ";
2222 TeamOrPersonBase
<?
> combinationAuthor
= name
.getCombinationAuthorship();
2223 TeamOrPersonBase
<?
> exCombinationAuthor
= name
.getExCombinationAuthorship();
2224 TeamOrPersonBase
<?
> basionymAuthor
= name
.getBasionymAuthorship();
2225 TeamOrPersonBase
<?
> exBasionymAuthor
= name
.getExBasionymAuthorship();
2227 String combinationAuthorString
= "";
2228 if (combinationAuthor
!= null) {
2229 combinationAuthor
= HibernateProxyHelper
.deproxy(combinationAuthor
);
2230 if (combinationAuthor
instanceof Team
) {
2231 combinationAuthorString
= createTropicosTeamTitle(combinationAuthor
);
2233 Person person
= HibernateProxyHelper
.deproxy(combinationAuthor
, Person
.class);
2234 combinationAuthorString
= createTropicosAuthorString(person
);
2237 String exCombinationAuthorString
= "";
2238 if (exCombinationAuthor
!= null) {
2239 exCombinationAuthor
= HibernateProxyHelper
.deproxy(exCombinationAuthor
);
2240 if (exCombinationAuthor
instanceof Team
) {
2241 exCombinationAuthorString
= createTropicosTeamTitle(exCombinationAuthor
);
2243 Person person
= HibernateProxyHelper
.deproxy(exCombinationAuthor
, Person
.class);
2244 exCombinationAuthorString
= createTropicosAuthorString(person
);
2248 String basionymAuthorString
= "";
2249 if (basionymAuthor
!= null) {
2250 basionymAuthor
= HibernateProxyHelper
.deproxy(basionymAuthor
);
2251 if (basionymAuthor
instanceof Team
) {
2252 basionymAuthorString
= createTropicosTeamTitle(basionymAuthor
);
2254 Person person
= HibernateProxyHelper
.deproxy(basionymAuthor
, Person
.class);
2255 basionymAuthorString
= createTropicosAuthorString(person
);
2259 String exBasionymAuthorString
= "";
2261 if (exBasionymAuthor
!= null) {
2262 exBasionymAuthor
= HibernateProxyHelper
.deproxy(exBasionymAuthor
);
2263 if (exBasionymAuthor
instanceof Team
) {
2264 exBasionymAuthorString
= createTropicosTeamTitle(exBasionymAuthor
);
2267 Person person
= HibernateProxyHelper
.deproxy(exBasionymAuthor
, Person
.class);
2268 exBasionymAuthorString
= createTropicosAuthorString(person
);
2271 String completeAuthorString
= name
.getNameCache() + " ";
2273 completeAuthorString
+= (!CdmUtils
.isBlank(exBasionymAuthorString
)
2274 || !CdmUtils
.isBlank(basionymAuthorString
)) ? basionymStart
: "";
2275 completeAuthorString
+= (!CdmUtils
.isBlank(exBasionymAuthorString
))
2276 ?
(CdmUtils
.Nz(exBasionymAuthorString
) + exAuthorSeperator
) : "";
2277 completeAuthorString
+= (!CdmUtils
.isBlank(basionymAuthorString
)) ? CdmUtils
.Nz(basionymAuthorString
) : "";
2278 completeAuthorString
+= (!CdmUtils
.isBlank(exBasionymAuthorString
)
2279 || !CdmUtils
.isBlank(basionymAuthorString
)) ? basionymEnd
: "";
2280 completeAuthorString
+= (!CdmUtils
.isBlank(exCombinationAuthorString
))
2281 ?
(CdmUtils
.Nz(exCombinationAuthorString
) + exAuthorSeperator
) : "";
2282 completeAuthorString
+= (!CdmUtils
.isBlank(combinationAuthorString
)) ? CdmUtils
.Nz(combinationAuthorString
)
2285 return completeAuthorString
;
2286 } catch (Exception e
) {
2287 state
.getResult().addException(e
, "An unexpected error occurred when handling tropicos title cache for "
2288 + cdmBaseStr(name
) + ": " + e
.getMessage());
2293 private String
createTropicosTeamTitle(TeamOrPersonBase
<?
> combinationAuthor
) {
2294 String combinationAuthorString
;
2295 Team team
= HibernateProxyHelper
.deproxy(combinationAuthor
, Team
.class);
2296 Team tempTeam
= Team
.NewInstance();
2297 for (Person teamMember
: team
.getTeamMembers()) {
2298 combinationAuthorString
= createTropicosAuthorString(teamMember
);
2299 Person tempPerson
= Person
.NewTitledInstance(combinationAuthorString
);
2300 tempTeam
.addTeamMember(tempPerson
);
2302 combinationAuthorString
= tempTeam
.generateTitle();
2303 return combinationAuthorString
;
2306 private String
createTropicosAuthorString(Person teamMember
) {
2307 String nomAuthorString
= "";
2308 String
[] splittedAuthorString
= null;
2309 if (teamMember
== null) {
2310 return nomAuthorString
;
2313 if (teamMember
.getGivenName() != null) {
2314 String givenNameString
= teamMember
.getGivenName().replaceAll("\\.", "\\. ");
2315 splittedAuthorString
= givenNameString
.split("\\s");
2316 for (String split
: splittedAuthorString
) {
2317 if (!StringUtils
.isBlank(split
)) {
2318 nomAuthorString
+= split
.substring(0, 1);
2319 nomAuthorString
+= ".";
2323 if (teamMember
.getFamilyName() != null) {
2324 String familyNameString
= teamMember
.getFamilyName().replaceAll("\\.", "\\. ");
2325 splittedAuthorString
= familyNameString
.split("\\s");
2326 for (String split
: splittedAuthorString
) {
2327 nomAuthorString
+= " " + split
;
2330 if (isBlank(nomAuthorString
.trim())) {
2331 if (teamMember
.getTitleCache() != null) {
2332 String titleCacheString
= teamMember
.getTitleCache().replaceAll("\\.", "\\. ");
2333 splittedAuthorString
= titleCacheString
.split("\\s");
2335 splittedAuthorString
= new String
[0];
2339 for (String split
: splittedAuthorString
) {
2340 if (index
< splittedAuthorString
.length
- 1 && (split
.length() == 1 || split
.endsWith("."))) {
2341 nomAuthorString
+= split
;
2343 nomAuthorString
= nomAuthorString
+ " " + split
;
2348 return nomAuthorString
.trim();
2351 private void handleReference(CdmLightExportState state
, Reference reference
) {
2353 state
.addReferenceToStore(reference
);
2354 CdmLightExportTable table
= CdmLightExportTable
.REFERENCE
;
2355 reference
= HibernateProxyHelper
.deproxy(reference
);
2357 handleIdentifier(state
, reference
);
2358 String
[] csvLine
= new String
[table
.getSize()];
2359 csvLine
[table
.getIndex(CdmLightExportTable
.REFERENCE_ID
)] = getId(state
, reference
);
2360 // TODO short citations correctly
2361 String shortCitation
= OriginalSourceFormatter
.INSTANCE_WITH_YEAR_BRACKETS
.format(reference
, null); // Should be Author(year) like in Taxon.sec
2362 csvLine
[table
.getIndex(CdmLightExportTable
.BIBLIO_SHORT_CITATION
)] = shortCitation
;
2363 // TODO get preferred title
2364 csvLine
[table
.getIndex(CdmLightExportTable
.REF_TITLE
)] = reference
.isProtectedTitleCache()
2365 ? reference
.getTitleCache() : reference
.getTitle();
2366 csvLine
[table
.getIndex(CdmLightExportTable
.ABBREV_REF_TITLE
)] = reference
.isProtectedAbbrevTitleCache()
2367 ? reference
.getAbbrevTitleCache() : reference
.getAbbrevTitle();
2368 csvLine
[table
.getIndex(CdmLightExportTable
.DATE_PUBLISHED
)] = reference
.getDatePublishedString();
2370 csvLine
[table
.getIndex(CdmLightExportTable
.EDITION
)] = reference
.getEdition();
2371 csvLine
[table
.getIndex(CdmLightExportTable
.EDITOR
)] = reference
.getEditor();
2372 csvLine
[table
.getIndex(CdmLightExportTable
.ISBN
)] = reference
.getIsbn();
2373 csvLine
[table
.getIndex(CdmLightExportTable
.ISSN
)] = reference
.getIssn();
2374 csvLine
[table
.getIndex(CdmLightExportTable
.ORGANISATION
)] = reference
.getOrganization();
2375 csvLine
[table
.getIndex(CdmLightExportTable
.PAGES
)] = reference
.getPages();
2376 csvLine
[table
.getIndex(CdmLightExportTable
.PLACE_PUBLISHED
)] = reference
.getPlacePublished();
2377 csvLine
[table
.getIndex(CdmLightExportTable
.PUBLISHER
)] = reference
.getPublisher();
2378 csvLine
[table
.getIndex(CdmLightExportTable
.REF_ABSTRACT
)] = reference
.getReferenceAbstract();
2379 csvLine
[table
.getIndex(CdmLightExportTable
.SERIES_PART
)] = reference
.getSeriesPart();
2380 csvLine
[table
.getIndex(CdmLightExportTable
.VOLUME
)] = reference
.getVolume();
2381 csvLine
[table
.getIndex(CdmLightExportTable
.YEAR
)] = reference
.getYear();
2383 if (reference
.getAuthorship() != null) {
2384 csvLine
[table
.getIndex(CdmLightExportTable
.AUTHORSHIP_TITLE
)] = createFullAuthorship(reference
);
2385 csvLine
[table
.getIndex(CdmLightExportTable
.AUTHOR_FK
)] = getId(state
, reference
.getAuthorship());
2388 csvLine
[table
.getIndex(CdmLightExportTable
.IN_REFERENCE
)] = getId(state
, reference
.getInReference());
2389 if (reference
.getInReference() != null
2390 && !state
.getReferenceStore().contains(reference
.getInReference().getUuid())) {
2391 handleReference(state
, reference
.getInReference());
2393 if (reference
.getInstitution() != null) {
2394 csvLine
[table
.getIndex(CdmLightExportTable
.INSTITUTION
)] = reference
.getInstitution().getTitleCache();
2396 if (reference
.getLsid() != null) {
2397 csvLine
[table
.getIndex(CdmLightExportTable
.LSID
)] = reference
.getLsid().getLsid();
2399 if (reference
.getSchool() != null) {
2400 csvLine
[table
.getIndex(CdmLightExportTable
.SCHOOL
)] = reference
.getSchool().getTitleCache();
2402 if (reference
.getUri() != null) {
2403 csvLine
[table
.getIndex(CdmLightExportTable
.URI
)] = reference
.getUri().toString();
2405 csvLine
[table
.getIndex(CdmLightExportTable
.REF_TYPE
)] = reference
.getType().getKey();
2407 state
.getProcessor().put(table
, reference
, csvLine
);
2408 } catch (Exception e
) {
2409 state
.getResult().addException(e
, "An unexpected error occurred when handling reference "
2410 + cdmBaseStr(reference
) + ": " + e
.getMessage());
2414 private String
createFullAuthorship(Reference reference
) {
2415 TeamOrPersonBase
<?
> authorship
= reference
.getAuthorship();
2416 String fullAuthorship
= "";
2417 if (authorship
== null) {
2420 authorship
= HibernateProxyHelper
.deproxy(authorship
);
2421 if (authorship
instanceof Person
) {
2422 fullAuthorship
= ((Person
) authorship
).getTitleCache();
2424 } else if (authorship
instanceof Team
) {
2426 Team authorTeam
= (Team
)authorship
;
2427 fullAuthorship
= authorTeam
.cacheStrategy().getTitleCache(authorTeam
);
2429 return fullAuthorship
;
2432 private void handleSpecimen(CdmLightExportState state
, SpecimenOrObservationBase
<?
> specimen
) {
2434 state
.addSpecimenToStore(specimen
);
2435 CdmLightExportTable table
= CdmLightExportTable
.SPECIMEN
;
2436 String specimenId
= getId(state
, specimen
);
2437 String
[] csvLine
= new String
[table
.getSize()];
2440 * SpecimenCitation = “El Salvador, Municipio La Libertad, San
2441 * Diego, El Amatal, 14.4.1993, González 159” [Auch ohne Punkt] ->
2442 * FieldUnit TitleCache HerbariumAbbrev = “B” [wie gehabt]
2447 csvLine
[table
.getIndex(CdmLightExportTable
.SPECIMEN_ID
)] = specimenId
;
2448 csvLine
[table
.getIndex(CdmLightExportTable
.SPECIMEN_CITATION
)] = specimen
.getTitleCache();
2449 Collection
<FieldUnit
> fieldUnits
= this.getOccurrenceService().findFieldUnits(specimen
.getUuid(), null);
2450 if (fieldUnits
.size() == 1) {
2451 Iterator
<FieldUnit
> iterator
= fieldUnits
.iterator();
2452 if (iterator
.hasNext()){
2453 FieldUnit fieldUnit
= iterator
.next();
2454 csvLine
[table
.getIndex(CdmLightExportTable
.FIELDUNIT_CITATION
)] = fieldUnit
.getTitleCache();
2457 if (specimen
.isInstanceOf(DerivedUnit
.class)){
2458 DerivedUnit derivedUnit
= (DerivedUnit
) specimen
;
2459 if (!StringUtils
.isBlank(derivedUnit
.getBarcode())){
2460 csvLine
[table
.getIndex(CdmLightExportTable
.BARCODE
)] = derivedUnit
.getBarcode();
2462 if (!StringUtils
.isBlank(derivedUnit
.getAccessionNumber())){
2463 csvLine
[table
.getIndex(CdmLightExportTable
.ACCESSION_NUMBER
)] = derivedUnit
.getAccessionNumber();
2465 if (!StringUtils
.isBlank(derivedUnit
.getCatalogNumber())){
2466 csvLine
[table
.getIndex(CdmLightExportTable
.CATALOGUE_NUMBER
)] = derivedUnit
.getCatalogNumber();
2470 csvLine
[table
.getIndex(CdmLightExportTable
.PREFERREDSTABLE_ID
)] = specimen
.getPreferredStableUri() != null? specimen
.getPreferredStableUri().toString(): null;
2471 csvLine
[table
.getIndex(CdmLightExportTable
.SPECIMEN_IMAGE_URIS
)] = extractMediaURIs(state
,
2472 specimen
.getDescriptions(), Feature
.IMAGE());
2473 if (specimen
instanceof DerivedUnit
) {
2474 DerivedUnit derivedUnit
= HibernateProxyHelper
.deproxy(specimen
, DerivedUnit
.class);
2475 if (derivedUnit
.getCollection() != null) {
2476 csvLine
[table
.getIndex(CdmLightExportTable
.HERBARIUM_ABBREV
)] = derivedUnit
.getCollection()
2480 if (specimen
instanceof MediaSpecimen
) {
2481 MediaSpecimen mediaSpecimen
= (MediaSpecimen
) specimen
;
2482 Iterator
<MediaRepresentation
> it
= mediaSpecimen
.getMediaSpecimen().getRepresentations().iterator();
2483 String mediaUris
= extractMediaUris(it
);
2484 csvLine
[table
.getIndex(CdmLightExportTable
.MEDIA_SPECIMEN_URL
)] = mediaUris
;
2488 if (derivedUnit
.getDerivedFrom() != null) {
2489 for (SpecimenOrObservationBase
<?
> original
: derivedUnit
.getDerivedFrom().getOriginals()) {
2490 // TODO: What to do if there are more then one
2492 if (original
instanceof FieldUnit
) {
2493 FieldUnit fieldUnit
= (FieldUnit
) original
;
2494 csvLine
[table
.getIndex(CdmLightExportTable
.COLLECTOR_NUMBER
)] = fieldUnit
.getFieldNumber();
2496 GatheringEvent gathering
= fieldUnit
.getGatheringEvent();
2497 if (gathering
!= null) {
2498 if (gathering
.getLocality() != null) {
2499 csvLine
[table
.getIndex(CdmLightExportTable
.LOCALITY
)] = gathering
.getLocality()
2502 if (gathering
.getCountry() != null) {
2503 csvLine
[table
.getIndex(CdmLightExportTable
.COUNTRY
)] = gathering
.getCountry()
2506 csvLine
[table
.getIndex(CdmLightExportTable
.COLLECTOR_STRING
)] = createCollectorString(
2507 state
, gathering
, fieldUnit
);
2509 if (gathering
.getGatheringDate() != null) {
2510 csvLine
[table
.getIndex(CdmLightExportTable
.COLLECTION_DATE
)] = gathering
2511 .getGatheringDate().toString();
2513 if (!gathering
.getCollectingAreas().isEmpty()) {
2515 csvLine
[table
.getIndex(CdmLightExportTable
.FURTHER_AREAS
)] = "0";
2516 for (NamedArea area
: gathering
.getCollectingAreas()) {
2518 csvLine
[table
.getIndex(CdmLightExportTable
.AREA_CATEGORY1
)] = area
.getLevel() != null?area
2519 .getLevel().getLabel():"";
2520 csvLine
[table
.getIndex(CdmLightExportTable
.AREA_NAME1
)] = area
.getLabel();
2523 csvLine
[table
.getIndex(CdmLightExportTable
.AREA_CATEGORY2
)] = area
.getLevel() != null?area
2524 .getLevel().getLabel():"";
2525 csvLine
[table
.getIndex(CdmLightExportTable
.AREA_NAME2
)] = area
.getLabel();
2528 csvLine
[table
.getIndex(CdmLightExportTable
.AREA_CATEGORY3
)] = area
.getLevel() != null?area
2529 .getLevel().getLabel():"";
2530 csvLine
[table
.getIndex(CdmLightExportTable
.AREA_NAME3
)] = area
.getLabel();
2533 csvLine
[table
.getIndex(CdmLightExportTable
.FURTHER_AREAS
)] = "1";
2543 state
.getResult().addWarning("The specimen with uuid " + specimen
.getUuid()
2544 + " is not an DerivedUnit.");
2548 state
.getProcessor().put(table
, specimen
, csvLine
);
2549 } catch (Exception e
) {
2550 state
.getResult().addException(e
, "An unexpected error occurred when handling specimen "
2551 + cdmBaseStr(specimen
) + ": " + e
.getMessage());
2555 private String
extractMediaUris(Iterator
<MediaRepresentation
> it
) {
2557 String mediaUriString
= "";
2558 boolean first
= true;
2559 while (it
.hasNext()) {
2560 MediaRepresentation rep
= it
.next();
2561 List
<MediaRepresentationPart
> parts
= rep
.getParts();
2562 for (MediaRepresentationPart part
: parts
) {
2564 if (part
.getUri() != null) {
2565 mediaUriString
+= part
.getUri().toString();
2569 if (part
.getUri() != null) {
2570 mediaUriString
+= ", " + part
.getUri().toString();
2576 return mediaUriString
;
2579 private String
extractLinkUris(Iterator
<ExternalLink
> it
) {
2581 String linkUriString
= "";
2582 boolean first
= true;
2583 while (it
.hasNext()) {
2584 ExternalLink link
= it
.next();
2586 if (link
.getUri() != null) {
2587 linkUriString
+= link
.getUri().toString();
2591 if (link
.getUri() != null) {
2592 linkUriString
+= ", " + link
.getUri().toString();
2596 return linkUriString
;
2599 private String
createCollectorString(CdmLightExportState state
, GatheringEvent gathering
, FieldUnit fieldUnit
) {
2601 String collectorString
= "";
2602 AgentBase
<?
> collectorA
= CdmBase
.deproxy(gathering
.getCollector());
2603 if (gathering
.getCollector() != null) {
2604 if (collectorA
instanceof TeamOrPersonBase
&& state
.getConfig().isHighLightPrimaryCollector()) {
2606 Person primaryCollector
= fieldUnit
.getPrimaryCollector();
2607 if (collectorA
instanceof Team
) {
2608 Team collectorTeam
= (Team
) collectorA
;
2609 boolean isFirst
= true;
2610 for (Person member
: collectorTeam
.getTeamMembers()) {
2612 collectorString
+= "; ";
2614 if (member
.equals(primaryCollector
)) {
2616 collectorString
+= "<b>" + member
.getTitleCache() + "</b>";
2618 collectorString
+= member
.getTitleCache();
2623 collectorString
= collectorA
.getTitleCache();
2626 return collectorString
;
2627 } catch (Exception e
) {
2628 state
.getResult().addException(e
, "An unexpected error occurred when creating collector string for "
2629 + cdmBaseStr(fieldUnit
) + ": " + e
.getMessage());
2635 * Returns a string representation of the {@link CdmBase cdmBase} object for
2638 private String
cdmBaseStr(CdmBase cdmBase
) {
2639 if (cdmBase
== null) {
2640 return "-no object available-";
2642 return cdmBase
.getClass().getSimpleName() + ": " + cdmBase
.getUuid();
2647 protected boolean doCheck(CdmLightExportState state
) {
2652 protected boolean isIgnore(CdmLightExportState state
) {