import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
-import eu.etaxonomy.cdm.api.service.dto.CondensedDistribution;
+import eu.etaxonomy.cdm.api.service.geo.IDistributionService;
import eu.etaxonomy.cdm.api.service.name.TypeDesignationSetComparator;
import eu.etaxonomy.cdm.api.service.name.TypeDesignationSetContainer;
import eu.etaxonomy.cdm.api.service.name.TypeDesignationSetFormatter;
import eu.etaxonomy.cdm.common.monitor.IProgressMonitor;
import eu.etaxonomy.cdm.compare.name.TypeComparator;
import eu.etaxonomy.cdm.compare.taxon.HomotypicGroupTaxonComparator;
-import eu.etaxonomy.cdm.ext.geo.IEditGeoService;
import eu.etaxonomy.cdm.filter.TaxonNodeFilter;
+import eu.etaxonomy.cdm.format.description.CategoricalDataFormatter;
+import eu.etaxonomy.cdm.format.description.QuantitativeDataFormatter;
+import eu.etaxonomy.cdm.format.description.distribution.CondensedDistribution;
import eu.etaxonomy.cdm.format.reference.OriginalSourceFormatter;
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
import eu.etaxonomy.cdm.io.common.CdmExportBase;
import eu.etaxonomy.cdm.model.common.Identifier;
import eu.etaxonomy.cdm.model.common.Language;
import eu.etaxonomy.cdm.model.common.LanguageString;
+import eu.etaxonomy.cdm.model.description.CategoricalData;
import eu.etaxonomy.cdm.model.description.CommonTaxonName;
import eu.etaxonomy.cdm.model.description.DescriptionBase;
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
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.QuantitativeData;
import eu.etaxonomy.cdm.model.description.TaxonDescription;
import eu.etaxonomy.cdm.model.description.TaxonInteraction;
import eu.etaxonomy.cdm.model.description.TaxonNameDescription;
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;
-import eu.etaxonomy.cdm.model.term.DefinedTerm;
+import eu.etaxonomy.cdm.model.term.IdentifierType;
+import eu.etaxonomy.cdm.model.term.TermTree;
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
*/
private static final long serialVersionUID = 2518643632756927053L;
@Autowired
- private IEditGeoService geoService;
+ private IDistributionService distributionService;
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();
}
}
private void handleDescriptions(CdmLightExportState state, CdmBase cdmBase) {
+ if (!state.getConfig().isDoFactualData()) {
+ return;
+ }
String titleCache = null;
try {
} else {
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()];
+ csvLine[table.getIndex(CdmLightExportTable.FACT_ID)] = getId(state, element);
+ if (cdmBase instanceof Taxon) {
+ csvLine[table.getIndex(CdmLightExportTable.TAXON_FK)] = getId(state, cdmBase);
+ } else if (cdmBase instanceof TaxonName) {
+ csvLine[table.getIndex(CdmLightExportTable.NAME_FK)] = getId(state, cdmBase);
+ }
+ csvLine[table.getIndex(CdmLightExportTable.FACT_TEXT)] = cache;
+ 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()];
+ csvLine[table.getIndex(CdmLightExportTable.FACT_ID)] = getId(state, element);
+ if (cdmBase instanceof Taxon) {
+ csvLine[table.getIndex(CdmLightExportTable.TAXON_FK)] = getId(state, cdmBase);
+ } else if (cdmBase instanceof TaxonName) {
+ csvLine[table.getIndex(CdmLightExportTable.NAME_FK)] = getId(state, cdmBase);
+ }
+ csvLine[table.getIndex(CdmLightExportTable.FACT_TEXT)] = cache;
+ csvLine[table.getIndex(CdmLightExportTable.FACT_CATEGORY)] = quantitativeData.getFeature().getLabel();
+ state.getProcessor().put(table, quantitativeData, csvLine);
}
} catch (Exception e) {
state.getResult().addException(e, "An unexpected error occurred when handling single simple fact "
}
state.getProcessor().put(table, source, csvLine);
}
-
}
} catch (Exception e) {
state.getResult().addException(e, "An unexpected error occurred when handling single source "
+ cdmBaseStr(element) + ": " + e.getMessage());
}
-
}
private void handleDistributionFacts(CdmLightExportState state, Taxon taxon,
if(state.getConfig().isCreateCondensedDistributionString()){
List<Language> langs = new ArrayList<>();
langs.add(Language.ENGLISH());
+ TermTree<NamedArea> areaTree = null; //TODO
- CondensedDistribution conDis = geoService.getCondensedDistribution(
+ CondensedDistribution conDis = distributionService.getCondensedDistribution(
//TODO add CondensedDistributionConfiguration to export configuration
- distributions, true, null, state.getConfig().getCondensedDistributionConfiguration(), langs);
+ distributions, areaTree, true, null, state.getConfig().getCondensedDistributionConfiguration(), langs);
CdmLightExportTable tableCondensed =
CdmLightExportTable.SIMPLE_FACT;
String[] csvLine = new String[tableCondensed.getSize()];
synonymsInGroup = acceptedTaxon.getSynonymsInGroup(group, comparator);
}
- synonymsInGroup.stream().forEach(synonym -> typifiedNames.add(HibernateProxyHelper.deproxy(synonym.getName(), TaxonName.class)));
+ synonymsInGroup.stream().forEach(synonym -> typifiedNames.add(HibernateProxyHelper.deproxy(synonym.getName())));
}else{
typifiedNames.addAll(group.getTypifiedNames());
}
}
- /**
- * @param specimenType
- */
private void handleSpecimenType_(CdmLightExportState state, SpecimenTypeDesignation specimenType) {
if (specimenType.getTypeSpecimen() != null){
DerivedUnit specimen = specimenType.getTypeSpecimen();
csvLine[table.getIndex(CdmLightExportTable.TYPIFIED_NAME_FK)] = getId(state, name);
}
state.getProcessor().put(table, specimenType, csvLine);
-
-
-
-
-
}
-
private String createNameWithItalics(List<TaggedText> taggedName) {
String fullTitleWithHtml = "";
if (!state.getNameStore().containsKey(name2.getId())) {
handleName(state, name2, null);
}
-
+ csvLine = new String[table.getSize()];
csvLine[table.getIndex(CdmLightExportTable.NAME_REL_TYPE)] = type.getLabel();
csvLine[table.getIndex(CdmLightExportTable.NAME1_FK)] = getId(state, name);
csvLine[table.getIndex(CdmLightExportTable.NAME2_FK)] = getId(state, name2);
- state.getProcessor().put(table, name, csvLine);
+ state.getProcessor().put(table, rel.getUuid().toString(), csvLine);
}
rels = name.getRelationsToThisName();
csvLine = new String[table.getSize()];
for (NameRelationship rel : rels) {
- NameRelationshipType type = rel.getType();
TaxonName name2 = rel.getFromName();
- name2 = HibernateProxyHelper.deproxy(name2, TaxonName.class);
+ name2 = HibernateProxyHelper.deproxy(name2);
if (!state.getNameStore().containsKey(name2.getId())) {
handleName(state, name2, null);
}
-
-
}
}
List<Identifier> identifiers = name.getIdentifiers();
//first check which kind of identifiers are available and then sort and create table entries
- Map<DefinedTerm, Set<Identifier>> identifierTypes = new HashMap<>();
+ Map<IdentifierType, Set<Identifier>> identifierTypes = new HashMap<>();
for (Identifier identifier: identifiers){
- DefinedTerm type = identifier.getType();
+ IdentifierType type = identifier.getType();
if (identifierTypes.containsKey(type)){
identifierTypes.get(type).add(identifier);
}else{
}
}
- for (DefinedTerm type:identifierTypes.keySet()){
+ for (IdentifierType type:identifierTypes.keySet()){
Set<Identifier> identifiersByType = identifierTypes.get(type);
csvLine = new String[table.getSize()];
csvLine[table.getIndex(CdmLightExportTable.FK)] = getId(state, name);
Set<NameRelationship> related = name.getNameRelations();
List<NameRelationship> relatedList = new ArrayList<>(related);
- Collections.sort(relatedList, new Comparator<NameRelationship>() {
- @Override
- public int compare(NameRelationship nr1, NameRelationship nr2) {
- return nr1.getType().compareTo(nr2.getType());
- }
-
- });
+ Collections.sort(relatedList, (nr1, nr2)-> {
+ return nr1.getType().compareTo(nr2.getType());});
List<NameRelationship> nonNames = new ArrayList<>();
List<NameRelationship> otherRelationships = new ArrayList<>();
if (rel.getType().equals(NameRelationshipType.LATER_HOMONYM())
|| rel.getType().equals(NameRelationshipType.TREATED_AS_LATER_HOMONYM())
|| (rel.getType().equals(NameRelationshipType.BLOCKING_NAME_FOR()))
- || (rel.getType().equals(NameRelationshipType.UNSPECIFIC_NON()))){
+ || (rel.getType().equals(NameRelationshipType.UNSPECIFIC_NON()))
+ || (rel.getType().equals(NameRelationshipType.AVOIDS_HOMONYM_OF()))
+ ){
nonNames.add(rel);
}else if (!rel.getType().isBasionymRelation()){
otherRelationships.add(rel);
}
}
+ if (state.getConfig().isShowInverseNameRelationsInHomotypicGroup()) {
+ 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())
+// || (rel.getType().equals(NameRelationshipType.BLOCKING_NAME_FOR()))
+// || (rel.getType().equals(NameRelationshipType.UNSPECIFIC_NON()))
+// || (rel.getType().equals(NameRelationshipType.AVOIDS_HOMONYM_OF()))
+// ){
+// nonNames.add(rel);
+// }else if (!rel.getType().isBasionymRelation()){
+ otherRelationships.add(rel);
+// }
+ }
+ }
}
String nonRelNames = "";
TaxonName relatedName = null;
if (relName.getFromName().equals(name)){
relatedName = relName.getToName();
- nonRelNames += label + relatedName.getTitleCache() + " ";
+ if (state.getConfig().isAddHTML()){
+ nonRelNames += label + createNameWithItalics(relatedName.getTaggedName())+ " ";
+ }else{
+ nonRelNames += label + relatedName.getTitleCache();
+ }
}
// else{
// label = relName.getType().getInverseLabel() + " ";
// relatedName = relName.getFromName();
// nonRelNames += label + relatedName.getTitleCache() + " ";
// }
-
-
}
- relNames.trim();
+ nonRelNames.trim();
if (nonNames.size() > 0){
nonRelNames = StringUtils.strip(nonRelNames, null);
nonRelNames += "] ";
}
+ //other relationships
if (otherRelationships.size() > 0){
relNames += " [";
}
relNames += label + relatedName.getTitleCache();
}
}
-// else {
-// label = rel.getType().getInverseLabel() + " ";
-// relatedName = rel.getFromName();
-// }
-
+ else {
+ label = rel.getType().getInverseLabel() + " ";
+ relatedName = rel.getFromName();
+ if (state.getConfig().isAddHTML()){
+ relNames += label + createNameWithItalics(relatedName.getTaggedName())+ " ";
+ }else{
+ relNames += label + relatedName.getTitleCache();
+ }
+ }
}
relNames.trim();
if (otherRelationships.size() > 0){
relNames += "] ";
}
+
String synonymSign = "";
if (index > 0){
if (name.isInvalid()){
}else{
doubtful = "";
}
- if (tb instanceof Synonym){
+ if (tb instanceof Synonym ){
+ if (!((Synonym)tb).getAcceptedTaxon().equals(acceptedTaxon)) {
+ continue;
+ }
if (StringUtils.isNotBlank(sec)){
sec = " syn. sec. " + sec + " ";
}else {
}else {
synonymSign = "\u003D ";
}
-
}
}
if (!isAccepted){