import java.io.File;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import eu.etaxonomy.cdm.model.description.Distribution;
import eu.etaxonomy.cdm.model.description.Feature;
import eu.etaxonomy.cdm.model.description.IndividualsAssociation;
+import eu.etaxonomy.cdm.model.description.PresenceAbsenceTerm;
import eu.etaxonomy.cdm.model.description.QuantitativeData;
import eu.etaxonomy.cdm.model.description.TaxonDescription;
import eu.etaxonomy.cdm.model.description.TaxonInteraction;
import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;
import eu.etaxonomy.cdm.model.term.IdentifierType;
import eu.etaxonomy.cdm.model.term.TermTree;
+import eu.etaxonomy.cdm.persistence.dao.term.ITermTreeDao;
import eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto;
import eu.etaxonomy.cdm.persistence.dto.TaxonNodeDtoByRankAndNameComparator;
import eu.etaxonomy.cdm.strategy.cache.HTMLTagRules;
import eu.etaxonomy.cdm.strategy.exceptions.UnknownCdmTypeException;
/**
+ * The export exporting a classification or a taxonomic subtree into CDM light.
+ *
* @author k.luther
* @since 15.03.2017
*/
@Autowired
private IDistributionService distributionService;
+ @Autowired
+ private ITermTreeDao termTreeDao;
+
public CdmLightClassificationExport() {
this.ioName = this.getClass().getSimpleName();
}
if (state.getRootId() != null) {
List<TaxonNodeDto> childrenOfRoot = state.getNodeChildrenMap().get(state.getRootId());
- Comparator<TaxonNodeDto> comp = state.getConfig().getComparator();
+ Comparator<TaxonNodeDto> comp = state.getConfig().getTaxonNodeComparator();
if (comp == null) {
comp = new TaxonNodeDtoByRankAndNameComparator();
}
if (children == null) {
return null;
}
- Comparator<TaxonNodeDto> comp = state.getConfig().getComparator();
+ Comparator<TaxonNodeDto> comp = state.getConfig().getTaxonNodeComparator();
if (comp == null) {
comp = new TaxonNodeDtoByRankAndNameComparator();
}
if (root.hasChildNodes()) {
childNodes = new ArrayList<>();
for (TaxonNode child : root.getChildNodes()) {
- if (child != null) {
- childNodes.add(new TaxonNodeDto(child));
- }
+ if (child != null) {
+ childNodes.add(new TaxonNodeDto(child));
+ }
}
state.getNodeChildrenMap().put(root.getUuid(), childNodes);
TaxonName name = taxon.getName();
handleName(state, name, taxon, true);
- //homotypic group / synonyms
- HomotypicalGroup homotypicGroup = taxon.getHomotypicGroup();
- int index = 0;
- int homotypicGroupIndex = 0;
- handleHomotypicalGroup(state, homotypicGroup, taxon, homotypicGroupIndex);
- homotypicGroupIndex++;
- for (Synonym syn : taxon.getSynonymsInGroup(homotypicGroup)) {
- handleSynonym(state, syn, index);
- index++;
- }
- List<HomotypicalGroup> heterotypicHomotypicGroups = taxon.getHeterotypicSynonymyGroups();
- for (HomotypicalGroup group: heterotypicHomotypicGroups){
- handleHomotypicalGroup(state, group, taxon, homotypicGroupIndex);
- for (Synonym syn : taxon.getSynonymsInGroup(group)) {
+ if (state.getConfig().isDoSynonyms()) {
+
+ //homotypic group / synonyms
+ HomotypicalGroup homotypicGroup = taxon.getHomotypicGroup();
+ int index = 0;
+ int homotypicGroupIndex = 0;
+ handleHomotypicalGroup(state, homotypicGroup, taxon, homotypicGroupIndex);
+ homotypicGroupIndex++;
+ for (Synonym syn : taxon.getSynonymsInGroup(homotypicGroup)) {
handleSynonym(state, syn, index);
index++;
}
- homotypicGroupIndex++;
- }
+ List<HomotypicalGroup> heterotypicHomotypicGroups = taxon.getHeterotypicSynonymyGroups();
+ for (HomotypicalGroup group: heterotypicHomotypicGroups){
+ handleHomotypicalGroup(state, group, taxon, homotypicGroupIndex);
+ for (Synonym syn : taxon.getSynonymsInGroup(group)) {
+ handleSynonym(state, syn, index);
+ index++;
+ }
+ homotypicGroupIndex++;
+ }
- //pro parte synonyms
- index = 0;
- for (Taxon tax : taxon.getAllProParteSynonyms()) {
- handleProPartePartialMisapplied(state, tax, taxon, true, false, index);
- index++;
- }
+ //pro parte synonyms
+ index = 0;
+ for (Taxon tax : taxon.getAllProParteSynonyms()) {
+ handleProPartePartialMisapplied(state, tax, taxon, true, false, index);
+ index++;
+ }
- //misapplications
- for (Taxon tax : taxon.getAllMisappliedNames()) {
- handleProPartePartialMisapplied(state, tax, taxon, false, true, index);
- index++;
+ //misapplications
+ for (Taxon tax : taxon.getAllMisappliedNames()) {
+ handleProPartePartialMisapplied(state, tax, taxon, false, true, index);
+ index++;
+ }
}
//taxon table
}
private void handleDescriptions(CdmLightExportState state, CdmBase cdmBase) {
+ if (!state.getConfig().isDoFactualData()) {
+ return;
+ }
String titleCache = null;
try {
List<DescriptionElementBase> usageFacts = new ArrayList<>();
for (TaxonDescription description : descriptions) {
if (description.getElements() != null) {
- for (DescriptionElementBase element : description.getElements()) {
- element = CdmBase.deproxy(element);
- handleAnnotations(element);
- if (element.getFeature().equals(Feature.COMMON_NAME())) {
- commonNameFacts.add(element);
- } else if (element.getFeature().equals(Feature.DISTRIBUTION())) {
- distributionFacts.add(element);
- } else if (element instanceof IndividualsAssociation
- || isSpecimenFeature(element.getFeature())) {
- specimenFacts.add(element);
- } else if (element.getFeature().isSupportsTaxonInteraction()) {
- taxonInteractionsFacts.add(element);
- } else {
- simpleFacts.add(element);
+ if (description.isPublish() || state.getConfig().isIncludeUnpublishedFacts()){
+ for (DescriptionElementBase element : description.getElements()) {
+ element = CdmBase.deproxy(element);
+ handleAnnotations(element);
+ if (element.getFeature().equals(Feature.COMMON_NAME())) {
+ commonNameFacts.add(element);
+ } else if (element.getFeature().equals(Feature.DISTRIBUTION())) {
+ distributionFacts.add(element);
+ } else if (element instanceof IndividualsAssociation
+ || isSpecimenFeature(element.getFeature())) {
+ specimenFacts.add(element);
+ } else if (element.getFeature().isSupportsTaxonInteraction()) {
+ taxonInteractionsFacts.add(element);
+ } else {
+ simpleFacts.add(element);
+ }
}
}
}
state.getProcessor().put(table, textData, csvLine);
}
}else if (element instanceof CategoricalData) {
- //use formater
- CategoricalData categoricalData = (CategoricalData)element;
- String cache = CategoricalDataFormatter.NewInstance(null).format(categoricalData);
- csvLine = new String[table.getSize()];
+ //use formater
+ CategoricalData categoricalData = (CategoricalData)element;
+ String cache = CategoricalDataFormatter.NewInstance(null).format(categoricalData);
+ csvLine = new String[table.getSize()];
csvLine[table.getIndex(CdmLightExportTable.FACT_ID)] = getId(state, element);
if (cdmBase instanceof Taxon) {
csvLine[table.getIndex(CdmLightExportTable.TAXON_FK)] = getId(state, cdmBase);
csvLine[table.getIndex(CdmLightExportTable.FACT_CATEGORY)] = categoricalData.getFeature().getLabel();
state.getProcessor().put(table, categoricalData, csvLine);
}else if (element instanceof QuantitativeData) {
- QuantitativeData quantitativeData = (QuantitativeData) element;
- String cache = QuantitativeDataFormatter.NewInstance(null).format(quantitativeData);
- csvLine = new String[table.getSize()];
+ QuantitativeData quantitativeData = (QuantitativeData) element;
+ String cache = QuantitativeDataFormatter.NewInstance(null).format(quantitativeData);
+ csvLine = new String[table.getSize()];
csvLine[table.getIndex(CdmLightExportTable.FACT_ID)] = getId(state, element);
if (cdmBase instanceof Taxon) {
csvLine[table.getIndex(CdmLightExportTable.TAXON_FK)] = getId(state, cdmBase);
+ cdmBaseStr(element) + ": " + e.getMessage());
}
}
- if(state.getConfig().isCreateCondensedDistributionString()){
- List<Language> langs = new ArrayList<>();
- langs.add(Language.ENGLISH());
- TermTree<NamedArea> areaTree = null; //TODO
-
- CondensedDistribution conDis = distributionService.getCondensedDistribution(
- //TODO add CondensedDistributionConfiguration to export configuration
- distributions, areaTree, true, null, state.getConfig().getCondensedDistributionConfiguration(), langs);
- CdmLightExportTable tableCondensed =
- CdmLightExportTable.SIMPLE_FACT;
- String[] csvLine = new String[tableCondensed.getSize()];
- //the computed fact has no uuid, TODO: remember the uuid for later reference assignment
- UUID randomUuid = UUID.randomUUID();
- csvLine[tableCondensed.getIndex(CdmLightExportTable.FACT_ID)] =
- randomUuid.toString();
- csvLine[tableCondensed.getIndex(CdmLightExportTable.TAXON_FK)] =
- getId(state, taxon);
- csvLine[tableCondensed.getIndex(CdmLightExportTable.FACT_TEXT)] =
- conDis.toString();
- csvLine[tableCondensed.getIndex(CdmLightExportTable.LANGUAGE)] =Language.ENGLISH().toString();
-
- csvLine[tableCondensed.getIndex(CdmLightExportTable.FACT_CATEGORY)] =
- "CondensedDistribution";
-
- state.getProcessor().put(tableCondensed, taxon, csvLine);
- }
+ if(state.getConfig().isCreateCondensedDistributionString()){
+ List<Language> langs = new ArrayList<>();
+ langs.add(Language.ENGLISH());
+ TermTree<NamedArea> areaTree = null; //TODO
+ TermTree<PresenceAbsenceTerm> statusTree = getPersistentStatusTree(state.getConfig());
+
+ CondensedDistribution conDis = distributionService.getCondensedDistribution(
+ //TODO add CondensedDistributionConfiguration to export configuration
+ distributions, areaTree, statusTree, true, null,
+ state.getConfig().getCondensedDistributionConfiguration(), langs);
+ CdmLightExportTable tableCondensed =
+ CdmLightExportTable.SIMPLE_FACT;
+ String[] csvLine = new String[tableCondensed.getSize()];
+ //the computed fact has no uuid, TODO: remember the uuid for later reference assignment
+ UUID randomUuid = UUID.randomUUID();
+ csvLine[tableCondensed.getIndex(CdmLightExportTable.FACT_ID)] =
+ randomUuid.toString();
+ csvLine[tableCondensed.getIndex(CdmLightExportTable.TAXON_FK)] =
+ getId(state, taxon);
+ csvLine[tableCondensed.getIndex(CdmLightExportTable.FACT_TEXT)] =
+ conDis.toString();
+ csvLine[tableCondensed.getIndex(CdmLightExportTable.LANGUAGE)] =Language.ENGLISH().toString();
+
+ csvLine[tableCondensed.getIndex(CdmLightExportTable.FACT_CATEGORY)] =
+ "CondensedDistribution";
+
+ state.getProcessor().put(tableCondensed, taxon, csvLine);
+ }
+ }
+
+ private TermTree<PresenceAbsenceTerm> getPersistentStatusTree(CdmLightExportConfigurator config) {
+ UUID statusTreeUuid = config.getStatusTree();
+ if (statusTreeUuid == null) {
+ return null;
+ }
+ //TODO property path
+ String[] propertyPath = new String[] {};
+ @SuppressWarnings("unchecked")
+ TermTree<PresenceAbsenceTerm> statusTree = termTreeDao.load(statusTreeUuid, Arrays.asList(propertyPath));
+ return statusTree;
}
private void handleCommonNameFacts(CdmLightExportState state, Taxon taxon,
csvLine[table.getIndex(CdmLightExportTable.PUBLICATION_TYPE)] = nomRef.getType().name();
if (nomRef.getVolume() != null) {
csvLine[table.getIndex(CdmLightExportTable.VOLUME_ISSUE)] = nomRef.getVolume();
- csvLine[table.getIndex(CdmLightExportTable.COLLATION)] = createCollatation(name);
+ csvLine[table.getIndex(CdmLightExportTable.COLLATION)] = createCollation(name);
}
if (nomRef.getDatePublished() != null) {
csvLine[table.getIndex(CdmLightExportTable.DATE_PUBLISHED)] = nomRef.getTimePeriodPublishedString();
}
if (nomRef.getVolume() == null && inReference.getVolume() != null) {
csvLine[table.getIndex(CdmLightExportTable.VOLUME_ISSUE)] = inReference.getVolume();
- csvLine[table.getIndex(CdmLightExportTable.COLLATION)] = createCollatation(name);
+ csvLine[table.getIndex(CdmLightExportTable.COLLATION)] = createCollation(name);
}
if (inReference.getInReference() != null) {
inReference = inReference.getInReference();
typifiedNames.addAll(group.getTypifiedNames());
}
-
Integer seqNumber = typifiedNames.indexOf(name);
csvLine[table.getIndex(CdmLightExportTable.HOMOTYPIC_GROUP_SEQ)] = String.valueOf(seqNumber);
state.getProcessor().put(table, name, csvLine);
}
}
- private String createCollatation(TaxonName name) {
+ private String createCollation(TaxonName name) {
String collation = "";
if (name.getNomenclaturalReference() != null) {
Reference ref = name.getNomenclaturalReference();
}
}
if (state.getConfig().isShowInverseNameRelationsInHomotypicGroup()) {
- if (rel.getToName().equals(name)){
+ if (rel.getToName().equals(name)){
// alle Homonyme und inverse blocking names
// if (rel.getType().equals(NameRelationshipType.LATER_HOMONYM())
// || rel.getType().equals(NameRelationshipType.TREATED_AS_LATER_HOMONYM())
// }else if (!rel.getType().isBasionymRelation()){
otherRelationships.add(rel);
// }
- }
+ }
}
}
if (relName.getFromName().equals(name)){
relatedName = relName.getToName();
if (state.getConfig().isAddHTML()){
- nonRelNames += label + createNameWithItalics(relatedName.getTaggedName())+ " ";
+ nonRelNames += label + createNameWithItalics(relatedName.getTaggedName())+ " ";
}else{
- nonRelNames += label + relatedName.getTitleCache();
+ nonRelNames += label + relatedName.getTitleCache();
}
}
// else{
}else{
doubtful = "";
}
- if (tb instanceof Synonym){
+ if (tb instanceof Synonym ){
+ Synonym syn = CdmBase.deproxy(tb, Synonym.class);
+ Taxon acc = syn.getAcceptedTaxon();
+ if (acc == null || !acc.equals(acceptedTaxon)) {
+ continue;
+ }
if (StringUtils.isNotBlank(sec)){
sec = " syn. sec. " + sec + " ";
}else {
break;
}else{
sec = "";
- if (!(((Taxon)tb).isProparteSynonym() || ((Taxon)tb).isMisapplication())){
+ Taxon taxon = CdmBase.deproxy(tb, Taxon.class);
+ if (!(taxon.isProparteSynonym() || taxon.isMisapplication())){
isAccepted = true;
break;
}else {
String typeTextDesignations = "";
//The typeDesignationManager does not handle the textual typeDesignations
for (TypeDesignationBase<?> typeDes: designationList) {
- if (typeDes instanceof TextualTypeDesignation) {
- typeTextDesignations = typeTextDesignations + ((TextualTypeDesignation)typeDes).getText(Language.getDefaultLanguage());
- String typeDesStateRefs = "";
+ if (typeDes instanceof TextualTypeDesignation) {
+ typeTextDesignations = typeTextDesignations + ((TextualTypeDesignation)typeDes).getText(Language.getDefaultLanguage());
+ String typeDesStateRefs = "";
if (typeDes.getDesignationSource() != null ){
typeDesStateRefs = "[";
NamedSource source = typeDes.getDesignationSource();
typeDesStateRefs += "]";
}
- typeTextDesignations = typeTextDesignations + typeDesStateRefs +"; ";
+ typeTextDesignations = typeTextDesignations + typeDesStateRefs +"; ";
- }else if (typeDes instanceof SpecimenTypeDesignation){
- DerivedUnit specimen = ((SpecimenTypeDesignation)typeDes).getTypeSpecimen();
- if(specimen != null && !state.getSpecimenStore().contains( specimen.getUuid())){
- handleSpecimen(state, specimen);
- }
- }
+ }else if (typeDes instanceof SpecimenTypeDesignation){
+ DerivedUnit specimen = ((SpecimenTypeDesignation)typeDes).getTypeSpecimen();
+ if(specimen != null && !state.getSpecimenStore().contains( specimen.getUuid())){
+ handleSpecimen(state, specimen);
+ }
+ }
}
if (typeTextDesignations.equals("; ")) {
- typeTextDesignations = "";
+ typeTextDesignations = "";
}
if (StringUtils.isNotBlank(typeTextDesignations)) {
- typeTextDesignations = typeTextDesignations.substring(0, typeTextDesignations.length()-2);
+ typeTextDesignations = typeTextDesignations.substring(0, typeTextDesignations.length()-2);
}
String specimenTypeString = !list.isEmpty()? createTypeDesignationString(list, true, typifiedNames.get(0).isSpecies() || typifiedNames.get(0).isInfraSpecific()):"";
if (StringUtils.isNotBlank(specimenTypeString)) {
if (!specimenTypeString.endsWith(".")) {
- specimenTypeString = specimenTypeString + ".";
+ specimenTypeString = specimenTypeString + ".";
}
csvLine[table.getIndex(CdmLightExportTable.TYPE_STRING)] = specimenTypeString;
}
if (StringUtils.isNotBlank(typeTextDesignations)) {
if (!typeTextDesignations.endsWith(".")) {
- typeTextDesignations = typeTextDesignations + ".";
+ typeTextDesignations = typeTextDesignations + ".";
}
csvLine[table.getIndex(CdmLightExportTable.TYPE_CACHE)] = typeTextDesignations;
* Diego, El Amatal, 14.4.1993, González 159” [Auch ohne Punkt] ->
* FieldUnit TitleCache HerbariumAbbrev = “B” [wie gehabt]
* HerbariumCode
- *
*/
csvLine[table.getIndex(CdmLightExportTable.SPECIMEN_ID)] = specimenId;
Iterator<MediaRepresentation> it = mediaSpecimen.getMediaSpecimen().getRepresentations().iterator();
String mediaUris = extractMediaUris(it);
csvLine[table.getIndex(CdmLightExportTable.MEDIA_SPECIMEN_URL)] = mediaUris;
-
}
- if (derivedUnit.getDerivedFrom() != null) {
+ if (derivedUnit.getDerivedFrom() == null) {
+ state.getResult().addWarning("The specimen with uuid " + specimen.getUuid()
+ + " does not have a field unit.");
+ } else {
for (SpecimenOrObservationBase<?> original : derivedUnit.getDerivedFrom().getOriginals()) {
// TODO: What to do if there are more then one
// FieldUnit??
}
}
}
- } else {
- state.getResult().addWarning("The specimen with uuid " + specimen.getUuid()
- + " is not an DerivedUnit.");
}
}
protected boolean isIgnore(CdmLightExportState state) {
return false;
}
-
-}
+}
\ No newline at end of file