Search in sources :

Example 1 with HomotypicGroupTaxonComparator

use of eu.etaxonomy.cdm.compare.taxon.HomotypicGroupTaxonComparator in project cdmlib by cybertaxonomy.

the class CsvNameExport method createNewRecord.

private HashMap<String, String> createNewRecord(TaxonNode childNode, CsvNameExportState state) {
    HashMap<String, String> nameRecord = new HashMap<>();
    nameRecord.put("classification", childNode.getClassification().getTitleCache());
    if (!childNode.getTaxon().getName().getRank().isLower(Rank.GENUS())) {
        return null;
    }
    TaxonNode familyNode = getHigherNode(childNode, Rank.FAMILY());
    Taxon taxon;
    String nameString;
    IBotanicalName name;
    if (familyNode == null) {
        nameRecord.put("familyTaxon", null);
        nameRecord.put("familyName", null);
        nameRecord.put("descriptionsFam", null);
    } else {
        familyNode = CdmBase.deproxy(familyNode);
        familyNode.getTaxon().setProtectedTitleCache(true);
        nameRecord.put("familyTaxon", familyNode.getTaxon().getTitleCache());
        if (familyMap.get(familyNode.getTaxon().getUuid()) != null) {
            nameRecord.putAll(familyMap.get(familyNode.getTaxon().getUuid()));
        } else {
            taxon = (Taxon) getTaxonService().load(familyNode.getTaxon().getUuid());
            taxon = CdmBase.deproxy(taxon);
            name = CdmBase.deproxy(taxon.getName());
            nameRecord.put("familyName", name.getNameCache());
            extractDescriptions(nameRecord, taxon, Feature.INTRODUCTION(), "descriptionsFam", state);
            familyMap.put(familyNode.getTaxon().getUuid(), nameRecord);
        }
    }
    TaxonNode genusNode = getHigherNode(childNode, Rank.GENUS());
    if (genusNode != null) {
        genusNode = CdmBase.deproxy(genusNode);
        genusNode.getTaxon().setProtectedTitleCache(true);
        nameRecord.put("genusTaxon", genusNode.getTaxon().getTitleCache());
        if (genusMap.get(genusNode.getTaxon().getUuid()) != null) {
            nameRecord.putAll(genusMap.get(genusNode.getTaxon().getUuid()));
        } else {
            taxon = (Taxon) getTaxonService().load(genusNode.getTaxon().getUuid());
            taxon = CdmBase.deproxy(taxon);
            name = CdmBase.deproxy(taxon.getName());
            if (name.getNameCache() != null) {
                nameRecord.put("genusName", name.getNameCache());
            } else {
                nameRecord.put("genusName", name.getGenusOrUninomial());
            }
            extractDescriptions(nameRecord, taxon, getNotesFeature(state), "descriptionsGen", state);
            genusMap.put(genusNode.getTaxon().getUuid(), nameRecord);
        }
    } else {
        nameRecord.put("genusTaxon", null);
        nameRecord.put("genusName", null);
        nameRecord.put("descriptionsGen", null);
    }
    // taxon = (Taxon) getTaxonService().load(childNode.getTaxon().getUuid());
    taxon = CdmBase.deproxy(childNode.getTaxon());
    // if (taxon.isPublish()){
    INonViralName nonViralName = taxon.getName();
    nameString = createTaggedNameString(nonViralName, false);
    nameRecord.put("childTaxon", taxon.getTitleCache());
    if (taxon.getSec() != null) {
        nameRecord.put("secRef", taxon.getSec().getTitleCache());
    } else {
        nameRecord.put("secRef", null);
    }
    getTaxonRelations(nameRecord, taxon);
    name = CdmBase.deproxy(taxon.getName());
    nameRecord.put("childName", nameString);
    nameRecord.put("nameId", String.valueOf(name.getId()));
    nameRecord.put("nameCache", name.getNameCache());
    nameRecord.put("titleName", name.getTitleCache());
    if (name.getNomenclaturalReference() != null) {
        nameRecord.put("NomRefTitleCache", name.getNomenclaturalReference().getTitleCache());
    } else {
        nameRecord.put("NomRefTitleCache", null);
    }
    nameRecord.put("fullName", name.getNameCache());
    nameRecord.put("fullTitleCache", name.getFullTitleCache());
    Set<TypeDesignationBase> typeDesSet = name.getTypeDesignations();
    Iterator<TypeDesignationBase> it = typeDesSet.iterator();
    String typeNameString = NOT_DESIGNATED;
    String statusString = null;
    if (it.hasNext()) {
        TypeDesignationBase<?> typeDes = CdmBase.deproxy(it.next());
        if (typeDes instanceof NameTypeDesignation) {
            NameTypeDesignation nameTypeDes = CdmBase.deproxy(typeDes, NameTypeDesignation.class);
            IBotanicalName typeName = CdmBase.deproxy(nameTypeDes.getTypeName());
            if (typeName != null) {
                typeNameString = "<i>" + typeName.getNameCache() + "</i> " + typeName.getAuthorshipCache();
                if (nameTypeDes.getTypeStatus() != null) {
                    NameTypeDesignationStatus status = CdmBase.deproxy(nameTypeDes.getTypeStatus());
                    statusString = status.getTitleCache();
                }
            }
        }
    }
    nameRecord.put("typeName", typeNameString);
    StringBuffer homotypicalSynonyms = new StringBuffer();
    TreeMap<HomotypicalGroup, List<Synonym>> heterotypicSynonymsList = new TreeMap<>(new HomotypicalGroupComparator());
    List<Synonym> homotypicSynonymsList = new ArrayList<>();
    StringBuffer heterotypicalSynonyms = new StringBuffer();
    List<Synonym> homotypicSynonyms;
    HomotypicalGroup group;
    IBotanicalName synonymName;
    String doubtfulTitleCache;
    for (Synonym synonym : taxon.getSynonyms()) {
        synonymName = CdmBase.deproxy(synonym.getName());
        group = CdmBase.deproxy(synonymName.getHomotypicalGroup());
        synonymName.generateFullTitle();
        if (synonym.isDoubtful()) {
            if (!synonymName.getFullTitleCache().startsWith("?")) {
                doubtfulTitleCache = "?" + synonymName.getFullTitleCache();
                synonymName = synonymName.clone();
                synonymName.setFullTitleCache(doubtfulTitleCache, true);
            }
        }
        if (!group.equals(name.getHomotypicalGroup())) {
            if (heterotypicSynonymsList.containsKey(group)) {
                heterotypicSynonymsList.get(group).add(synonym);
            } else {
                homotypicSynonyms = new ArrayList<>();
                homotypicSynonyms.add(synonym);
                heterotypicSynonymsList.put(group, homotypicSynonyms);
                homotypicSynonyms = null;
            }
        } else {
            synonymName.generateFullTitle();
            homotypicSynonymsList.add(synonym);
        }
    }
    String synonymString;
    boolean first = true;
    for (List<Synonym> list : heterotypicSynonymsList.values()) {
        Collections.sort(list, new HomotypicGroupTaxonComparator(null));
        first = true;
        for (TaxonBase<?> synonym : list) {
            NomenclaturalStatus status = null;
            if (!synonym.getName().getStatus().isEmpty()) {
                status = CdmBase.deproxy(synonym.getName().getStatus().iterator().next());
                if (status.getType().isInvalid()) {
                    heterotypicalSynonyms.append(" <invalid> ");
                    synonymName = CdmBase.deproxy(synonym.getName());
                    synonymString = createSynonymNameString(synonymName, state.getConfig().isInvalidNamesQuoted());
                    heterotypicalSynonyms.append(synonymString);
                    continue;
                }
            }
            if (first) {
                heterotypicalSynonyms.append(" <heterotypic> ");
            } else {
                heterotypicalSynonyms.append(" <homonym> ");
            }
            first = false;
            synonymName = CdmBase.deproxy(synonym.getName());
            synonymString = createSynonymNameString(synonymName, false);
            heterotypicalSynonyms.append(synonymString);
        }
    }
    first = true;
    Collections.sort(homotypicSynonymsList, new HomotypicGroupTaxonComparator(null));
    NomenclaturalStatus status = null;
    for (TaxonBase<?> synonym : homotypicSynonymsList) {
        if (!synonym.getName().getStatus().isEmpty()) {
            status = CdmBase.deproxy(synonym.getName().getStatus().iterator().next());
            if (status.getType().isInvalid()) {
                homotypicalSynonyms.append(" <invalid> ");
                synonymName = CdmBase.deproxy(synonym.getName());
                synonymString = createSynonymNameString(synonymName, true);
                homotypicalSynonyms.append(synonymString);
                continue;
            } else if (!first) {
                homotypicalSynonyms.append(" <homonym> ");
            }
        } else if (!first) {
            homotypicalSynonyms.append(" <homonym> ");
        }
        first = false;
        synonymName = CdmBase.deproxy(synonym.getName());
        synonymString = createSynonymNameString(synonymName, false);
        homotypicalSynonyms.append(synonymString);
    }
    nameRecord.put("synonyms_homotypic", homotypicalSynonyms.toString());
    nameRecord.put("synonyms_heterotypic", heterotypicalSynonyms.toString());
    nameRecord.put("status", statusString);
    Set<NameRelationship> nameRelations = name.getNameRelations();
    INonViralName relatedName = null;
    String nameRelType = null;
    String relNameString = null;
    if (nameRelations.size() > 0) {
        NameRelationship nameRel = nameRelations.iterator().next();
        IBotanicalName fromName = CdmBase.deproxy(nameRel.getFromName());
        if (fromName.equals(taxon.getName())) {
            relatedName = nameRel.getToName();
        } else {
            relatedName = nameRel.getFromName();
        }
        nameRel = CdmBase.deproxy(nameRel);
        nameRelType = nameRel.getType().getTitleCache();
        relNameString = createTaggedNameString(relatedName, getStatus(relatedName));
    }
    nameRecord.put("relatedName", relNameString);
    nameRecord.put("nameRelType", nameRelType);
    extractDescriptions(nameRecord, taxon, Feature.DISTRIBUTION(), "descriptions", state);
    return nameRecord;
}
Also used : TaxonNode(eu.etaxonomy.cdm.model.taxon.TaxonNode) HashMap(java.util.HashMap) HomotypicGroupTaxonComparator(eu.etaxonomy.cdm.compare.taxon.HomotypicGroupTaxonComparator) ArrayList(java.util.ArrayList) HomotypicalGroupComparator(eu.etaxonomy.cdm.compare.name.HomotypicalGroupComparator) List(java.util.List) ArrayList(java.util.ArrayList) INonViralName(eu.etaxonomy.cdm.model.name.INonViralName) NameRelationship(eu.etaxonomy.cdm.model.name.NameRelationship) Taxon(eu.etaxonomy.cdm.model.taxon.Taxon) TypeDesignationBase(eu.etaxonomy.cdm.model.name.TypeDesignationBase) TreeMap(java.util.TreeMap) IBotanicalName(eu.etaxonomy.cdm.model.name.IBotanicalName) NameTypeDesignation(eu.etaxonomy.cdm.model.name.NameTypeDesignation) HomotypicalGroup(eu.etaxonomy.cdm.model.name.HomotypicalGroup) NomenclaturalStatus(eu.etaxonomy.cdm.model.name.NomenclaturalStatus) Synonym(eu.etaxonomy.cdm.model.taxon.Synonym) NameTypeDesignationStatus(eu.etaxonomy.cdm.model.name.NameTypeDesignationStatus)

Example 2 with HomotypicGroupTaxonComparator

use of eu.etaxonomy.cdm.compare.taxon.HomotypicGroupTaxonComparator in project cdmlib by cybertaxonomy.

the class HomotypicalGroupComparator method compare.

@Override
public int compare(HomotypicalGroup group1, HomotypicalGroup group2) {
    TaxonBase<?> firstTypified1 = null;
    TaxonBase<?> firstTypified2 = null;
    if (group1.equals(group2)) {
        return 0;
    }
    TaxonComparator taxComparator = new HomotypicGroupTaxonComparator(null);
    Set<TaxonName> typifiedNames1 = group1.getTypifiedNames();
    List<TaxonBase> taxonBasesOfTypifiedNames = new ArrayList<>();
    for (TaxonName typifiedName : typifiedNames1) {
        if (!typifiedName.getTaxonBases().isEmpty()) {
            taxonBasesOfTypifiedNames.add(typifiedName.getTaxonBases().iterator().next());
        }
    }
    Collections.sort(taxonBasesOfTypifiedNames, taxComparator);
    firstTypified1 = taxonBasesOfTypifiedNames.get(0);
    Set<TaxonName> typifiedNames2 = group2.getTypifiedNames();
    taxonBasesOfTypifiedNames = new ArrayList<>();
    for (TaxonName typifiedName : typifiedNames2) {
        if (!typifiedName.getTaxonBases().isEmpty()) {
            taxonBasesOfTypifiedNames.add(typifiedName.getTaxonBases().iterator().next());
        }
    }
    Collections.sort(taxonBasesOfTypifiedNames, taxComparator);
    firstTypified2 = taxonBasesOfTypifiedNames.get(0);
    return taxComparator.compare(firstTypified1, firstTypified2);
}
Also used : TaxonBase(eu.etaxonomy.cdm.model.taxon.TaxonBase) HomotypicGroupTaxonComparator(eu.etaxonomy.cdm.compare.taxon.HomotypicGroupTaxonComparator) HomotypicGroupTaxonComparator(eu.etaxonomy.cdm.compare.taxon.HomotypicGroupTaxonComparator) TaxonComparator(eu.etaxonomy.cdm.compare.taxon.TaxonComparator) ArrayList(java.util.ArrayList) TaxonName(eu.etaxonomy.cdm.model.name.TaxonName)

Example 3 with HomotypicGroupTaxonComparator

use of eu.etaxonomy.cdm.compare.taxon.HomotypicGroupTaxonComparator in project cdmlib by cybertaxonomy.

the class CdmLightClassificationExport method handleName.

private void handleName(CdmLightExportState state, TaxonName name, Taxon acceptedTaxon, boolean acceptedName) {
    if (name == null || state.getNameStore().containsKey(name.getId())) {
        return;
    }
    try {
        Rank rank = name.getRank();
        CdmLightExportTable table = CdmLightExportTable.SCIENTIFIC_NAME;
        name = HibernateProxyHelper.deproxy(name);
        state.getNameStore().put(name.getId(), name.getUuid());
        String[] csvLine = new String[table.getSize()];
        csvLine[table.getIndex(CdmLightExportTable.NAME_ID)] = getId(state, name);
        if (name.getLsid() != null) {
            csvLine[table.getIndex(CdmLightExportTable.LSID)] = name.getLsid().getLsid();
        } else {
            csvLine[table.getIndex(CdmLightExportTable.LSID)] = "";
        }
        handleIdentifier(state, name);
        handleDescriptions(state, name);
        csvLine[table.getIndex(CdmLightExportTable.RANK)] = getTitleCache(rank);
        if (rank != null) {
            csvLine[table.getIndex(CdmLightExportTable.RANK_SEQUENCE)] = String.valueOf(rank.getOrderIndex());
            if (rank.isInfraGeneric()) {
                try {
                    csvLine[table.getIndex(CdmLightExportTable.INFRAGENERIC_RANK)] = name.getRank().getInfraGenericMarker();
                } catch (UnknownCdmTypeException e) {
                    state.getResult().addError("Infrageneric marker expected but not available for rank " + name.getRank().getTitleCache());
                }
            }
            if (rank.isInfraSpecific()) {
                csvLine[table.getIndex(CdmLightExportTable.INFRASPECIFIC_RANK)] = name.getRank().getAbbreviation();
            }
        } else {
            csvLine[table.getIndex(CdmLightExportTable.RANK_SEQUENCE)] = "";
        }
        if (name.isProtectedTitleCache()) {
            csvLine[table.getIndex(CdmLightExportTable.FULL_NAME_WITH_AUTHORS)] = name.getTitleCache();
        } else {
            // TODO: adapt the tropicos titlecache creation
            csvLine[table.getIndex(CdmLightExportTable.FULL_NAME_WITH_AUTHORS)] = name.getTitleCache();
        }
        if (!state.getConfig().isAddHTML()) {
            csvLine[table.getIndex(CdmLightExportTable.FULL_NAME_WITH_REF)] = name.getFullTitleCache();
        } else {
            List<TaggedText> taggedFullTitleCache = name.getTaggedFullTitle();
            List<TaggedText> taggedName = name.getTaggedName();
            String fullTitleWithHtml = createNameWithItalics(taggedFullTitleCache);
            // TODO: adapt the tropicos titlecache creation
            csvLine[table.getIndex(CdmLightExportTable.FULL_NAME_WITH_REF)] = fullTitleWithHtml.trim();
        }
        csvLine[table.getIndex(CdmLightExportTable.FULL_NAME_NO_AUTHORS)] = name.getNameCache();
        csvLine[table.getIndex(CdmLightExportTable.GENUS_UNINOMIAL)] = name.getGenusOrUninomial();
        csvLine[table.getIndex(CdmLightExportTable.INFRAGENERIC_EPITHET)] = name.getInfraGenericEpithet();
        csvLine[table.getIndex(CdmLightExportTable.SPECIFIC_EPITHET)] = name.getSpecificEpithet();
        csvLine[table.getIndex(CdmLightExportTable.INFRASPECIFIC_EPITHET)] = name.getInfraSpecificEpithet();
        csvLine[table.getIndex(CdmLightExportTable.APPENDED_PHRASE)] = name.getAppendedPhrase();
        csvLine[table.getIndex(CdmLightExportTable.BAS_AUTHORTEAM_FK)] = getId(state, name.getBasionymAuthorship());
        if (name.getBasionymAuthorship() != null) {
            if (state.getAuthorFromStore(name.getBasionymAuthorship().getId()) == null) {
                handleAuthor(state, name.getBasionymAuthorship());
            }
        }
        csvLine[table.getIndex(CdmLightExportTable.BAS_EX_AUTHORTEAM_FK)] = getId(state, name.getExBasionymAuthorship());
        if (name.getExBasionymAuthorship() != null) {
            if (state.getAuthorFromStore(name.getExBasionymAuthorship().getId()) == null) {
                handleAuthor(state, name.getExBasionymAuthorship());
            }
        }
        csvLine[table.getIndex(CdmLightExportTable.COMB_AUTHORTEAM_FK)] = getId(state, name.getCombinationAuthorship());
        if (name.getCombinationAuthorship() != null) {
            if (state.getAuthorFromStore(name.getCombinationAuthorship().getId()) == null) {
                handleAuthor(state, name.getCombinationAuthorship());
            }
        }
        csvLine[table.getIndex(CdmLightExportTable.COMB_EX_AUTHORTEAM_FK)] = getId(state, name.getExCombinationAuthorship());
        if (name.getExCombinationAuthorship() != null) {
            if (state.getAuthorFromStore(name.getExCombinationAuthorship().getId()) == null) {
                handleAuthor(state, name.getExCombinationAuthorship());
            }
        }
        csvLine[table.getIndex(CdmLightExportTable.AUTHOR_TEAM_STRING)] = name.getAuthorshipCache();
        Reference nomRef = name.getNomenclaturalReference();
        NomenclaturalSource nomenclaturalSource = name.getNomenclaturalSource();
        if (nomenclaturalSource != null && nomenclaturalSource.getNameUsedInSource() != null) {
            handleName(state, nomenclaturalSource.getNameUsedInSource(), null);
            csvLine[table.getIndex(CdmLightExportTable.NAME_USED_IN_SOURCE)] = getId(state, nomenclaturalSource.getNameUsedInSource());
        }
        if (nomRef != null) {
            if (!state.getReferenceStore().contains(nomRef.getUuid())) {
                handleReference(state, nomRef);
            }
            csvLine[table.getIndex(CdmLightExportTable.REFERENCE_FK)] = getId(state, nomRef);
            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);
            }
            if (nomRef.getDatePublished() != null) {
                csvLine[table.getIndex(CdmLightExportTable.DATE_PUBLISHED)] = nomRef.getTimePeriodPublishedString();
                csvLine[table.getIndex(CdmLightExportTable.YEAR_PUBLISHED)] = nomRef.getDatePublished().getYear();
                csvLine[table.getIndex(CdmLightExportTable.VERBATIM_DATE)] = nomRef.getDatePublished().getVerbatimDate();
            }
            if (name.getNomenclaturalMicroReference() != null) {
                csvLine[table.getIndex(CdmLightExportTable.DETAIL)] = name.getNomenclaturalMicroReference();
            }
            nomRef = HibernateProxyHelper.deproxy(nomRef);
            if (nomRef.getInReference() != null) {
                Reference inReference = nomRef.getInReference();
                if (inReference.getDatePublished() != null && nomRef.getDatePublished() == null) {
                    csvLine[table.getIndex(CdmLightExportTable.DATE_PUBLISHED)] = inReference.getDatePublishedString();
                    csvLine[table.getIndex(CdmLightExportTable.YEAR_PUBLISHED)] = inReference.getDatePublished().getYear();
                }
                if (nomRef.getVolume() == null && inReference.getVolume() != null) {
                    csvLine[table.getIndex(CdmLightExportTable.VOLUME_ISSUE)] = inReference.getVolume();
                    csvLine[table.getIndex(CdmLightExportTable.COLLATION)] = createCollatation(name);
                }
                if (inReference.getInReference() != null) {
                    inReference = inReference.getInReference();
                }
                if (inReference.getAbbrevTitle() == null) {
                    csvLine[table.getIndex(CdmLightExportTable.ABBREV_TITLE)] = CdmUtils.Nz(inReference.getTitle());
                } else {
                    csvLine[table.getIndex(CdmLightExportTable.ABBREV_TITLE)] = CdmUtils.Nz(inReference.getAbbrevTitle());
                }
                if (inReference.getTitle() == null) {
                    csvLine[table.getIndex(CdmLightExportTable.FULL_TITLE)] = CdmUtils.Nz(inReference.getAbbrevTitle() != null ? inReference.getAbbrevTitle() : inReference.getTitleCache());
                } else {
                    csvLine[table.getIndex(CdmLightExportTable.FULL_TITLE)] = CdmUtils.Nz(inReference.getTitle());
                }
                TeamOrPersonBase<?> author = inReference.getAuthorship();
                if (author != null && (nomRef.isOfType(ReferenceType.BookSection) || nomRef.isOfType(ReferenceType.Section))) {
                    csvLine[table.getIndex(CdmLightExportTable.ABBREV_REF_AUTHOR)] = author.isProtectedTitleCache() ? author.getTitleCache() : CdmUtils.Nz(author.getNomenclaturalTitleCache());
                    csvLine[table.getIndex(CdmLightExportTable.FULL_REF_AUTHOR)] = CdmUtils.Nz(author.getTitleCache());
                } else {
                    csvLine[table.getIndex(CdmLightExportTable.ABBREV_REF_AUTHOR)] = "";
                    csvLine[table.getIndex(CdmLightExportTable.FULL_REF_AUTHOR)] = "";
                }
            } else {
                if (nomRef.getAbbrevTitle() == null) {
                    csvLine[table.getIndex(CdmLightExportTable.ABBREV_TITLE)] = CdmUtils.Nz(nomRef.getTitle() != null ? nomRef.getTitle() : nomRef.getAbbrevTitleCache());
                } else {
                    csvLine[table.getIndex(CdmLightExportTable.ABBREV_TITLE)] = CdmUtils.Nz(nomRef.getAbbrevTitle());
                }
                if (nomRef.getTitle() == null) {
                    csvLine[table.getIndex(CdmLightExportTable.FULL_TITLE)] = CdmUtils.Nz(nomRef.getAbbrevTitle() != null ? nomRef.getAbbrevTitle() : nomRef.getTitleCache());
                } else {
                    csvLine[table.getIndex(CdmLightExportTable.FULL_TITLE)] = CdmUtils.Nz(nomRef.getTitle());
                }
                TeamOrPersonBase<?> author = nomRef.getAuthorship();
                if (author != null) {
                    csvLine[table.getIndex(CdmLightExportTable.ABBREV_REF_AUTHOR)] = author.isProtectedTitleCache() ? author.getTitleCache() : CdmUtils.Nz(author.getNomenclaturalTitleCache());
                    csvLine[table.getIndex(CdmLightExportTable.FULL_REF_AUTHOR)] = CdmUtils.Nz(author.getTitleCache());
                } else {
                    csvLine[table.getIndex(CdmLightExportTable.ABBREV_REF_AUTHOR)] = "";
                    csvLine[table.getIndex(CdmLightExportTable.FULL_REF_AUTHOR)] = "";
                }
            }
        } else {
            csvLine[table.getIndex(CdmLightExportTable.PUBLICATION_TYPE)] = "";
        }
        /*
             * Collation
             *
             * Detail
             *
             * TitlePageYear
             */
        String protologueUriString = extractProtologueURIs(state, name);
        csvLine[table.getIndex(CdmLightExportTable.PROTOLOGUE_URI)] = protologueUriString;
        Collection<TypeDesignationBase> specimenTypeDesignations = new ArrayList<>();
        List<TextualTypeDesignation> textualTypeDesignations = new ArrayList<>();
        for (TypeDesignationBase<?> typeDesignation : name.getTypeDesignations()) {
            if (typeDesignation.isInstanceOf(TextualTypeDesignation.class)) {
                if (((TextualTypeDesignation) typeDesignation).isVerbatim()) {
                    Set<IdentifiableSource> sources = typeDesignation.getSources();
                    boolean isProtologue = false;
                    if (sources != null && !sources.isEmpty()) {
                        IdentifiableSource source = sources.iterator().next();
                        if (name.getNomenclaturalReference() != null) {
                            isProtologue = source.getCitation() != null ? source.getCitation().getUuid().equals(name.getNomenclaturalReference().getUuid()) : false;
                        }
                    }
                    if (isProtologue) {
                        csvLine[table.getIndex(CdmLightExportTable.PROTOLOGUE_TYPE_STATEMENT)] = ((TextualTypeDesignation) typeDesignation).getPreferredText(Language.DEFAULT());
                    } else {
                        textualTypeDesignations.add((TextualTypeDesignation) typeDesignation);
                    }
                } else {
                    textualTypeDesignations.add((TextualTypeDesignation) typeDesignation);
                }
            } else if (typeDesignation.isInstanceOf(SpecimenTypeDesignation.class)) {
                SpecimenTypeDesignation specimenType = HibernateProxyHelper.deproxy(typeDesignation, SpecimenTypeDesignation.class);
                specimenTypeDesignations.add(specimenType);
                handleSpecimenType(state, specimenType);
            } else if (typeDesignation instanceof NameTypeDesignation) {
                specimenTypeDesignations.add(HibernateProxyHelper.deproxy(typeDesignation, NameTypeDesignation.class));
            }
        }
        TypeDesignationSetManager manager = new TypeDesignationSetManager(specimenTypeDesignations, name);
        HTMLTagRules rules = new HTMLTagRules();
        rules.addRule(TagEnum.name, "i");
        String test = manager.print(false, false, false, rules);
        ;
        csvLine[table.getIndex(CdmLightExportTable.TYPE_SPECIMEN)] = manager.print(false, false, false, rules);
        StringBuilder stringbuilder = new StringBuilder();
        int i = 1;
        for (TextualTypeDesignation typeDesignation : textualTypeDesignations) {
            stringbuilder.append(typeDesignation.getPreferredText(Language.DEFAULT()));
            if (typeDesignation.getSources() != null && !typeDesignation.getSources().isEmpty()) {
                stringbuilder.append(" [");
                int index = 1;
                for (IdentifiableSource source : typeDesignation.getSources()) {
                    if (source.getCitation() != null) {
                        stringbuilder.append(OriginalSourceFormatter.INSTANCE.format(source));
                    }
                    if (index < typeDesignation.getSources().size()) {
                        stringbuilder.append(", ");
                    }
                    index++;
                }
                stringbuilder.append("]");
            }
            if (i < textualTypeDesignations.size()) {
                stringbuilder.append("; ");
            } else {
                stringbuilder.append(".");
            }
            i++;
        }
        csvLine[table.getIndex(CdmLightExportTable.TYPE_STATEMENT)] = stringbuilder.toString();
        if (name.getStatus() == null || name.getStatus().isEmpty()) {
            csvLine[table.getIndex(CdmLightExportTable.NOM_STATUS)] = "";
            csvLine[table.getIndex(CdmLightExportTable.NOM_STATUS_ABBREV)] = "";
        } else {
            String statusStringAbbrev = extractStatusString(state, name, true);
            String statusString = extractStatusString(state, name, false);
            csvLine[table.getIndex(CdmLightExportTable.NOM_STATUS)] = statusString.trim();
            csvLine[table.getIndex(CdmLightExportTable.NOM_STATUS_ABBREV)] = statusStringAbbrev.trim();
        }
        HomotypicalGroup group = HibernateProxyHelper.deproxy(name.getHomotypicalGroup(), HomotypicalGroup.class);
        csvLine[table.getIndex(CdmLightExportTable.HOMOTYPIC_GROUP_FK)] = getId(state, group);
        List<TaxonName> typifiedNames = new ArrayList<>();
        if (acceptedTaxon != null) {
            HomotypicGroupTaxonComparator comparator = new HomotypicGroupTaxonComparator(acceptedTaxon);
            List<Synonym> synonymsInGroup = null;
            if (group.equals(acceptedTaxon.getHomotypicGroup())) {
                synonymsInGroup = acceptedTaxon.getHomotypicSynonymsByHomotypicGroup(comparator);
                typifiedNames.add(name);
            } else {
                synonymsInGroup = acceptedTaxon.getSynonymsInGroup(group, comparator);
            }
            synonymsInGroup.stream().forEach(synonym -> typifiedNames.add(HibernateProxyHelper.deproxy(synonym.getName(), TaxonName.class)));
        } else {
            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);
        handleNameRelationships(state, name);
    } catch (Exception e) {
        state.getResult().addException(e, "An unexpected error occurred when handling the name " + cdmBaseStr(name) + ": " + name.getTitleCache() + ": " + e.getMessage());
        e.printStackTrace();
    }
}
Also used : HomotypicGroupTaxonComparator(eu.etaxonomy.cdm.compare.taxon.HomotypicGroupTaxonComparator) ArrayList(java.util.ArrayList) LanguageString(eu.etaxonomy.cdm.model.common.LanguageString) HTMLTagRules(eu.etaxonomy.cdm.strategy.cache.HTMLTagRules) UnknownCdmTypeException(eu.etaxonomy.cdm.strategy.exceptions.UnknownCdmTypeException) CommonTaxonName(eu.etaxonomy.cdm.model.description.CommonTaxonName) TaxonName(eu.etaxonomy.cdm.model.name.TaxonName) IdentifiableSource(eu.etaxonomy.cdm.model.common.IdentifiableSource) TaggedText(eu.etaxonomy.cdm.strategy.cache.TaggedText) Reference(eu.etaxonomy.cdm.model.reference.Reference) TypeDesignationBase(eu.etaxonomy.cdm.model.name.TypeDesignationBase) Rank(eu.etaxonomy.cdm.model.name.Rank) UnknownCdmTypeException(eu.etaxonomy.cdm.strategy.exceptions.UnknownCdmTypeException) NameTypeDesignation(eu.etaxonomy.cdm.model.name.NameTypeDesignation) HomotypicalGroup(eu.etaxonomy.cdm.model.name.HomotypicalGroup) NomenclaturalSource(eu.etaxonomy.cdm.model.name.NomenclaturalSource) TypeDesignationSetManager(eu.etaxonomy.cdm.api.service.name.TypeDesignationSetManager) TextualTypeDesignation(eu.etaxonomy.cdm.model.name.TextualTypeDesignation) Synonym(eu.etaxonomy.cdm.model.taxon.Synonym) SpecimenTypeDesignation(eu.etaxonomy.cdm.model.name.SpecimenTypeDesignation)

Example 4 with HomotypicGroupTaxonComparator

use of eu.etaxonomy.cdm.compare.taxon.HomotypicGroupTaxonComparator in project cdmlib by cybertaxonomy.

the class TaxonNodeServiceImpl method pageChildNodesDTOs.

@Override
public Pager<TaxonNodeDto> pageChildNodesDTOs(UUID taxonNodeUuid, boolean recursive, boolean includeUnpublished, boolean doSynonyms, TaxonNodeSortMode sortMode, Integer pageSize, Integer pageIndex) {
    TaxonNode parentNode = dao.load(taxonNodeUuid);
    List<CdmBase> allRecords = new ArrayList<>();
    // acceptedTaxa
    List<TaxonNode> childNodes = loadChildNodesOfTaxonNode(parentNode, null, recursive, includeUnpublished, sortMode);
    allRecords.addAll(childNodes);
    // add synonyms if pager is not yet full synonyms
    if (doSynonyms) {
        List<Synonym> synList = new ArrayList<>(parentNode.getTaxon().getSynonyms());
        Collections.sort(synList, new HomotypicGroupTaxonComparator(null));
        // TODO: test sorting
        allRecords.addAll(synList);
    }
    List<TaxonNodeDto> dtos = new ArrayList<>(pageSize == null ? 25 : pageSize);
    long totalCount = Long.valueOf(allRecords.size());
    TaxonName parentName = null;
    for (CdmBase item : PagerUtils.pageList(allRecords, pageIndex, pageSize)) {
        if (item.isInstanceOf(TaxonNode.class)) {
            dtos.add(new TaxonNodeDto(CdmBase.deproxy(item, TaxonNode.class)));
        } else if (item.isInstanceOf(Synonym.class)) {
            Synonym synonym = CdmBase.deproxy(item, Synonym.class);
            parentName = parentName == null ? parentNode.getTaxon().getName() : parentName;
            boolean isHomotypic = synonym.getName().isHomotypic(parentName);
            dtos.add(new TaxonNodeDto(synonym, isHomotypic));
        }
    }
    return new DefaultPagerImpl<>(pageIndex, totalCount, pageSize, dtos);
}
Also used : DefaultPagerImpl(eu.etaxonomy.cdm.api.service.pager.impl.DefaultPagerImpl) TaxonNode(eu.etaxonomy.cdm.model.taxon.TaxonNode) HomotypicGroupTaxonComparator(eu.etaxonomy.cdm.compare.taxon.HomotypicGroupTaxonComparator) ArrayList(java.util.ArrayList) CdmBase(eu.etaxonomy.cdm.model.common.CdmBase) Synonym(eu.etaxonomy.cdm.model.taxon.Synonym) TaxonName(eu.etaxonomy.cdm.model.name.TaxonName) TaxonNodeDto(eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto)

Example 5 with HomotypicGroupTaxonComparator

use of eu.etaxonomy.cdm.compare.taxon.HomotypicGroupTaxonComparator in project cdmlib by cybertaxonomy.

the class TaxonServiceImpl method getHomotypicSynonymsByHomotypicGroup.

@Override
public List<Synonym> getHomotypicSynonymsByHomotypicGroup(Taxon taxon, List<String> propertyPaths) {
    Taxon t = (Taxon) dao.load(taxon.getUuid(), propertyPaths);
    HomotypicGroupTaxonComparator comparator = new HomotypicGroupTaxonComparator(taxon);
    return t.getHomotypicSynonymsByHomotypicGroup(comparator);
}
Also used : HomotypicGroupTaxonComparator(eu.etaxonomy.cdm.compare.taxon.HomotypicGroupTaxonComparator) Taxon(eu.etaxonomy.cdm.model.taxon.Taxon)

Aggregations

HomotypicGroupTaxonComparator (eu.etaxonomy.cdm.compare.taxon.HomotypicGroupTaxonComparator)6 ArrayList (java.util.ArrayList)5 HomotypicalGroup (eu.etaxonomy.cdm.model.name.HomotypicalGroup)3 TaxonName (eu.etaxonomy.cdm.model.name.TaxonName)3 Synonym (eu.etaxonomy.cdm.model.taxon.Synonym)3 NameTypeDesignation (eu.etaxonomy.cdm.model.name.NameTypeDesignation)2 TypeDesignationBase (eu.etaxonomy.cdm.model.name.TypeDesignationBase)2 Taxon (eu.etaxonomy.cdm.model.taxon.Taxon)2 TaxonNode (eu.etaxonomy.cdm.model.taxon.TaxonNode)2 List (java.util.List)2 TypeDesignationSetManager (eu.etaxonomy.cdm.api.service.name.TypeDesignationSetManager)1 DefaultPagerImpl (eu.etaxonomy.cdm.api.service.pager.impl.DefaultPagerImpl)1 HomotypicalGroupComparator (eu.etaxonomy.cdm.compare.name.HomotypicalGroupComparator)1 TaxonComparator (eu.etaxonomy.cdm.compare.taxon.TaxonComparator)1 CdmBase (eu.etaxonomy.cdm.model.common.CdmBase)1 IdentifiableSource (eu.etaxonomy.cdm.model.common.IdentifiableSource)1 LanguageString (eu.etaxonomy.cdm.model.common.LanguageString)1 CommonTaxonName (eu.etaxonomy.cdm.model.description.CommonTaxonName)1 IBotanicalName (eu.etaxonomy.cdm.model.name.IBotanicalName)1 INonViralName (eu.etaxonomy.cdm.model.name.INonViralName)1