Search in sources :

Example 1 with TaggedText

use of eu.etaxonomy.cdm.strategy.cache.TaggedText in project cdmlib by cybertaxonomy.

the class TaxonNodeByRankAndNameComparator method compare.

@Override
public int compare(TaxonNode node1, TaxonNode node2) {
    if (node1 == null && node2 == null) {
        return 0;
    } else if (node1 == null) {
        return 1;
    } else if (node2 == null) {
        return -1;
    }
    boolean node1Excluded = node1.isExcluded();
    boolean node2Excluded = node2.isExcluded();
    boolean node1Unplaced = node1.isUnplaced();
    boolean node2Unplaced = node2.isUnplaced();
    if (node1.getUuid().equals(node2.getUuid())) {
        return 0;
    }
    // They should both be put to the end (first unplaced then excluded)
    if (node2Excluded && !node1Excluded) {
        return -1;
    }
    if (node2Unplaced && !(node1Unplaced || node1Excluded)) {
        return -1;
    }
    if (node1Excluded && !node2Excluded) {
        return 1;
    }
    if (node1Unplaced && !(node2Unplaced || node2Excluded)) {
        return 1;
    }
    if (node1Unplaced && node2Excluded) {
        return -1;
    }
    if (node2Unplaced && node1Excluded) {
        return 1;
    }
    Integer rankTax1 = getRankOrder(node1);
    Integer rankTax2 = getRankOrder(node2);
    // first compare ranks, if ranks are equal (or both null) compare names or taxon title cache if names are null
    int rankOrder = OrderIndexComparator.instance().compare(rankTax1, rankTax2);
    if (rankOrder != 0) {
        return rankOrder;
    } else {
        List<TaggedText> taggedText1 = getTaggedText(node1);
        List<TaggedText> taggedText2 = getTaggedText(node2);
        ;
        if (taggedText1 != null && taggedText2 != null) {
            // same rank, order by name
            String sortableName1 = "";
            for (TaggedText tagged : taggedText1) {
                if (tagged.getType().equals(TagEnum.name)) {
                    sortableName1 += " " + tagged.getText();
                }
            }
            String sortableName2 = "";
            for (TaggedText tagged : taggedText2) {
                if (tagged.getType().equals(TagEnum.name)) {
                    sortableName2 += " " + tagged.getText();
                }
            }
            int result = sortableName1.compareTo(sortableName2);
            if (result == 0) {
                return node1.getUuid().compareTo(node2.getUuid());
            } else {
                return result;
            }
        } else {
            // this is maybe not 100% correct, we need to compare name cases, but it is a very rare case
            return node1.getUuid().compareTo(node2.getUuid());
        }
    }
}
Also used : TaggedText(eu.etaxonomy.cdm.strategy.cache.TaggedText)

Example 2 with TaggedText

use of eu.etaxonomy.cdm.strategy.cache.TaggedText 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 3 with TaggedText

use of eu.etaxonomy.cdm.strategy.cache.TaggedText in project cdmlib by cybertaxonomy.

the class TaxonRelationshipFormatter method getTaggedText.

public List<TaggedText> getTaggedText(TaxonRelationship taxonRelationship, boolean reverse, List<Language> languages, boolean withoutName) {
    if (taxonRelationship == null) {
        return null;
    }
    TaxonRelationshipType type = taxonRelationship.getType();
    boolean isMisapplied = type == null ? false : type.isMisappliedName() && reverse;
    boolean isSynonym = type == null ? false : type.isAnySynonym();
    Taxon relatedTaxon = reverse ? taxonRelationship.getFromTaxon() : taxonRelationship.getToTaxon();
    if (relatedTaxon == null) {
        return null;
    }
    String doubtfulTaxonStr = relatedTaxon.isDoubtful() ? DOUBTFUL_TAXON_MARKER : "";
    String doubtfulRelationStr = taxonRelationship.isDoubtful() ? "?" : "";
    TaxonName name = relatedTaxon.getName();
    TaggedTextBuilder builder = new TaggedTextBuilder();
    // rel symbol
    String symbol = doubtfulRelationStr + getSymbol(type, reverse, languages);
    builder.add(TagEnum.symbol, symbol);
    // name
    if (!withoutName) {
        if (isMisapplied) {
            // starting quote
            String startQuote = " " + doubtfulTaxonStr + QUOTE_START;
            builder.addSeparator(startQuote);
            // name cache
            List<TaggedText> nameCacheTags = getNameCacheTags(name);
            builder.addAll(nameCacheTags);
            // end quote
            String endQuote = QUOTE_END;
            builder.add(TagEnum.postSeparator, endQuote);
        } else {
            builder.addSeparator(" " + doubtfulTaxonStr);
            // name full title cache
            List<TaggedText> nameCacheTags = getNameTitleCacheTags(name);
            builder.addAll(nameCacheTags);
        }
    } else {
        if (isNotBlank(doubtfulTaxonStr)) {
            builder.addSeparator(" " + doubtfulTaxonStr);
        }
    }
    // sec/sensu (+ Separatoren?)
    if (isNotBlank(relatedTaxon.getAppendedPhrase())) {
        builder.addWhitespace();
        builder.add(TagEnum.appendedPhrase, relatedTaxon.getAppendedPhrase());
    }
    List<TaggedText> secTags = getReferenceTags(relatedTaxon.getSec(), relatedTaxon.getSecMicroReference(), /* isMisapplied,*/
    false);
    if (!secTags.isEmpty()) {
        builder.addSeparator(isMisapplied ? SENSU_SEPARATOR : SEC_SEPARATOR);
        builder.addAll(secTags);
    } else if (isBlank(relatedTaxon.getAppendedPhrase())) {
        if (isMisapplied) {
            builder.addWhitespace();
            // TODO type unclear sensuReference(?)
            builder.add(TagEnum.appendedPhrase, AUCT);
        } else {
            builder.addSeparator(SEC_SEPARATOR + UNKNOWN_SEC);
        }
    }
    // //, non author
    if (isMisapplied && name != null) {
        if (isNotBlank(name.getAuthorshipCache())) {
            builder.addSeparator(NON_SEPARATOR);
            builder.add(TagEnum.authors, name.getAuthorshipCache().trim());
        }
    }
    List<TaggedText> relSecTags = getReferenceTags(taxonRelationship.getCitation(), taxonRelationship.getCitationMicroReference(), true);
    if (!relSecTags.isEmpty()) {
        builder.addSeparator(isSynonym ? SYN_SEC : isMisapplied ? ERR_SEC : REL_SEC);
        builder.addAll(relSecTags);
    }
    return builder.getTaggedText();
}
Also used : TaxonRelationshipType(eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType) Taxon(eu.etaxonomy.cdm.model.taxon.Taxon) TaxonName(eu.etaxonomy.cdm.model.name.TaxonName) TaggedTextBuilder(eu.etaxonomy.cdm.strategy.cache.TaggedTextBuilder) TaggedText(eu.etaxonomy.cdm.strategy.cache.TaggedText)

Example 4 with TaggedText

use of eu.etaxonomy.cdm.strategy.cache.TaggedText in project cdmlib by cybertaxonomy.

the class TaxonNode2DtoBeanProcessor method processBean.

@Override
public JSONObject processBean(Object bean, JsonConfig jsonConfig) {
    TaxonNode node = (TaxonNode) bean;
    JSONObject json = new JSONObject();
    json.element("class", "TaxonNodeDto");
    json.element("uuid", node.getUuid(), jsonConfig);
    json.element("taxonomicChildrenCount", node.getCountChildren(), jsonConfig);
    // json.element("classificationUuid", node.getClassification().getUuid(), jsonConfig);
    json.element("doubtful", node.isDoubtful());
    json.element("unplaced", node.isUnplaced());
    json.element("excluded", node.isExcluded());
    if (node.getStatus() != null) {
        json.element("status", node.getStatus());
        json.element("status_symbol", node.getStatus().getSymbol());
        KeyTerm_L10n<TaxonNodeStatus> status_L10n = new KeyTerm_L10n<TaxonNodeStatus>(node.getStatus());
        json.element("status_message_L10n", status_L10n.localizedLabel());
    }
    Taxon taxon = node.getTaxon();
    if (taxon != null) {
        json.element("titleCache", taxon.getName().getTitleCache(), jsonConfig);
        List<TaggedText> taggedTitle = taxon.getName().getTaggedName();
        json.element("taggedTitle", taggedTitle, jsonConfig);
        json.element("taxonUuid", taxon.getUuid(), jsonConfig);
        // comparation made for avoiding view exceptions
        if (taxon.getSec() == null) {
            json.element("secUuid", "null");
        } else {
            json.element("secUuid", taxon.getSec().getUuid(), jsonConfig);
        }
        String ranklabel = null;
        if (taxon.getName().getRank() != null) {
            ranklabel = taxon.getName().getRank().getLabel();
        }
        json.element("rankLabel", ranklabel, jsonConfig);
    }
    return json;
}
Also used : TaxonNode(eu.etaxonomy.cdm.model.taxon.TaxonNode) JSONObject(net.sf.json.JSONObject) TaxonNodeStatus(eu.etaxonomy.cdm.model.taxon.TaxonNodeStatus) Taxon(eu.etaxonomy.cdm.model.taxon.Taxon) KeyTerm_L10n(eu.etaxonomy.cdm.api.service.l10n.KeyTerm_L10n) TaggedText(eu.etaxonomy.cdm.strategy.cache.TaggedText)

Example 5 with TaggedText

use of eu.etaxonomy.cdm.strategy.cache.TaggedText in project cdmlib by cybertaxonomy.

the class TaxonRelationshipFormatterTest method testGetTaggedTextConceptRelationsWithoutName.

@Test
public void testGetTaggedTextConceptRelationsWithoutName() {
    reverse = false;
    TaxonRelationshipType relType = TaxonRelationshipType.INCLUDES();
    final String SYMBOL = relType.getSymbol();
    taxonRel.setType(relType);
    List<TaggedText> tags = formatter.getTaggedText(taxonRel, reverse, languages, WITHOUT_NAME);
    String str = TaggedCacheHelper.createString(tags);
    Assert.assertEquals(SYMBOL + " sec. ToSecAuthor 1928, rel. sec. Cheek 1919: 123", str);
    tags = formatter.getTaggedText(taxonRel, !reverse, languages, WITHOUT_NAME);
    str = TaggedCacheHelper.createString(tags);
    Assert.assertEquals(relType.getInverseSymbol() + " sec. Macfarlane 1918, rel. sec. Cheek 1919: 123", str);
    toTaxon.setAppendedPhrase("sensu stricto");
    tags = formatter.getTaggedText(taxonRel, reverse, languages, WITHOUT_NAME);
    str = TaggedCacheHelper.createString(tags);
    Assert.assertEquals(SYMBOL + " sensu stricto sec. ToSecAuthor 1928, rel. sec. Cheek 1919: 123", str);
    toTaxon.setSec(null);
    toTaxon.setAppendedPhrase("");
    tags = formatter.getTaggedText(taxonRel, reverse, languages, WITHOUT_NAME);
    str = TaggedCacheHelper.createString(tags);
    Assert.assertEquals(SYMBOL + " sec. ???, rel. sec. Cheek 1919: 123", str);
    taxonRel.setDoubtful(true);
    toTaxon.setAppendedPhrase("");
    tags = formatter.getTaggedText(taxonRel, reverse, languages, WITHOUT_NAME);
    str = TaggedCacheHelper.createString(tags);
    Assert.assertEquals("?" + SYMBOL + " sec. ???, rel. sec. Cheek 1919: 123", str);
}
Also used : TaxonRelationshipType(eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType) TaggedText(eu.etaxonomy.cdm.strategy.cache.TaggedText) Test(org.junit.Test)

Aggregations

TaggedText (eu.etaxonomy.cdm.strategy.cache.TaggedText)36 ArrayList (java.util.ArrayList)14 TaxonName (eu.etaxonomy.cdm.model.name.TaxonName)12 Test (org.junit.Test)10 Rank (eu.etaxonomy.cdm.model.name.Rank)4 TypeDesignationBase (eu.etaxonomy.cdm.model.name.TypeDesignationBase)4 Reference (eu.etaxonomy.cdm.model.reference.Reference)4 Taxon (eu.etaxonomy.cdm.model.taxon.Taxon)4 TaxonRelationshipType (eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType)4 LanguageString (eu.etaxonomy.cdm.model.common.LanguageString)3 UnknownCdmTypeException (eu.etaxonomy.cdm.strategy.exceptions.UnknownCdmTypeException)3 List (java.util.List)3 TypeDesignationSetManager (eu.etaxonomy.cdm.api.service.name.TypeDesignationSetManager)2 Team (eu.etaxonomy.cdm.model.agent.Team)2 IdentifiableSource (eu.etaxonomy.cdm.model.common.IdentifiableSource)2 CommonTaxonName (eu.etaxonomy.cdm.model.description.CommonTaxonName)2 HybridRelationship (eu.etaxonomy.cdm.model.name.HybridRelationship)2 SpecimenTypeDesignation (eu.etaxonomy.cdm.model.name.SpecimenTypeDesignation)2 TextualTypeDesignation (eu.etaxonomy.cdm.model.name.TextualTypeDesignation)2 Synonym (eu.etaxonomy.cdm.model.taxon.Synonym)2