Search in sources :

Example 21 with TaggedText

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

the class TaxonRelationshipFormatter method getReferenceTags.

private List<TaggedText> getReferenceTags(Reference ref, String detail, /*boolean isSensu,*/
boolean isRelation) {
    List<TaggedText> result = new ArrayList<>();
    String secRef;
    if (ref != null) {
        TeamOrPersonBase<?> author = CdmBase.deproxy(ref.getAuthorship());
        // 
        if (ref.isProtectedTitleCache() == false && author != null && isNotBlank(author.getTitleCache())) {
            if (author.isInstanceOf(Person.class)) {
                secRef = PersonDefaultCacheStrategy.INSTANCE().getFamilyTitle((Person) author);
            } else {
                // #9624
                secRef = TeamDefaultCacheStrategy.INSTANCE_ET_AL_2().getFamilyTitle((Team) author);
            }
            if (isNotBlank(ref.getYear())) {
                secRef += " " + ref.getYear();
            }
        } else {
            secRef = ref.getTitleCache();
        }
        TagEnum secType = /*isSensu? TagEnum.sensuReference : */
        isRelation ? TagEnum.relSecReference : TagEnum.secReference;
        TaggedText refTag = TaggedText.NewInstance(secType, secRef);
        refTag.setEntityReference(new TypedEntityReference<>(CdmBase.deproxy(ref).getClass(), ref.getUuid()));
        result.add(refTag);
    }
    if (isNotBlank(detail)) {
        result.add(TaggedText.NewSeparatorInstance(DETAIL_SEPARATOR));
        TagEnum detailType = /*isSensu? TagEnum.sensuMicroReference : */
        isRelation ? TagEnum.relSecMicroReference : TagEnum.secMicroReference;
        TaggedText microTag = TaggedText.NewInstance(detailType, detail);
        result.add(microTag);
    }
    return result;
}
Also used : TagEnum(eu.etaxonomy.cdm.strategy.cache.TagEnum) ArrayList(java.util.ArrayList) Team(eu.etaxonomy.cdm.model.agent.Team) TaggedText(eu.etaxonomy.cdm.strategy.cache.TaggedText) Person(eu.etaxonomy.cdm.model.agent.Person)

Example 22 with TaggedText

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

the class NameCacheStrategyBase method addOriginalSpelling.

protected void addOriginalSpelling(List<TaggedText> tags, TaxonName currentName) {
    currentName = CdmBase.deproxy(currentName);
    // Hibernate.initialize(currentName.getRelationsToThisName());
    TaxonName originalName = currentName.getOriginalSpelling();
    if (originalName != null) {
        String originalNameString;
        tags.add(TaggedText.NewSeparatorInstance(" [as \""));
        if (!originalName.isNonViral()) {
            originalNameString = originalName.getTitleCache();
            tags.add(new TaggedText(TagEnum.name, originalNameString));
        } else {
            INonViralName originalNvName = CdmBase.deproxy(originalName);
            originalNameString = makeOriginalNameString(originalNvName, tags);
            for (String split : originalNameString.split(" ")) {
                if (split.matches(NonViralNameParserImplRegExBase.infraSpeciesMarker) || split.matches(NonViralNameParserImplRegExBase.oldInfraSpeciesMarker)) {
                    tags.add(new TaggedText(TagEnum.rank, split));
                } else {
                    tags.add(new TaggedText(TagEnum.name, split));
                }
            }
        }
        tags.add(TaggedText.NewSeparatorInstance("\"]"));
    } else {
        return;
    }
}
Also used : INonViralName(eu.etaxonomy.cdm.model.name.INonViralName) TaxonName(eu.etaxonomy.cdm.model.name.TaxonName) TaggedText(eu.etaxonomy.cdm.strategy.cache.TaggedText)

Example 23 with TaggedText

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

the class NameCacheStrategyBase method getNomStatusTags.

@Override
public List<TaggedText> getNomStatusTags(TaxonName taxonName, boolean includeSeparatorBefore, boolean includeSeparatorAfter) {
    Set<NomenclaturalStatus> ncStati = taxonName.getStatus();
    Iterator<NomenclaturalStatus> iterator = ncStati.iterator();
    List<TaggedText> nomStatusTags = new ArrayList<>();
    while (iterator.hasNext()) {
        NomenclaturalStatus ncStatus = iterator.next();
        // since the NewInstance method of nomencatural status allows null as parameter
        // we have to check for null values here
        String nomStatusStr = "not defined";
        if (ncStatus.getType() != null) {
            NomenclaturalStatusType statusType = ncStatus.getType();
            List<Language> prefLangs = Arrays.asList(new Language[] { Language.LATIN(), Language.DEFAULT() });
            Representation repr = statusType.getPreferredRepresentation(prefLangs);
            if (repr != null) {
                if (!Language.LATIN().equals(repr.getLanguage())) {
                    String message = "No latin representation available for nom. status. " + statusType.getTitleCache();
                    logger.info(message);
                }
                nomStatusStr = repr.getAbbreviatedLabel();
            } else {
                String message = "No representation available for nom. status. " + statusType.getTitleCache();
                logger.warn(message);
                nomStatusStr = statusType.getTitleCache();
            }
        } else if (isNotBlank(ncStatus.getRuleConsidered())) {
            nomStatusStr = ncStatus.getRuleConsidered();
        }
        String statusSeparator = ", ";
        if (includeSeparatorBefore) {
            nomStatusTags.add(new TaggedText(TagEnum.separator, statusSeparator));
        }
        nomStatusTags.add(new TaggedText(TagEnum.nomStatus, nomStatusStr, new TypedEntityReference<>(ncStatus.getClass(), ncStatus.getUuid())));
        if (includeSeparatorAfter) {
            nomStatusTags.add(new TaggedText(TagEnum.postSeparator, ","));
        }
    }
    return nomStatusTags;
}
Also used : Language(eu.etaxonomy.cdm.model.common.Language) NomenclaturalStatus(eu.etaxonomy.cdm.model.name.NomenclaturalStatus) ArrayList(java.util.ArrayList) Representation(eu.etaxonomy.cdm.model.term.Representation) TypedEntityReference(eu.etaxonomy.cdm.ref.TypedEntityReference) NomenclaturalStatusType(eu.etaxonomy.cdm.model.name.NomenclaturalStatusType) TaggedText(eu.etaxonomy.cdm.strategy.cache.TaggedText)

Example 24 with TaggedText

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

the class NameCacheStrategyBase method getTaggedTitle.

@Override
public List<TaggedText> getTaggedTitle(TaxonName taxonName) {
    if (taxonName == null) {
        return null;
    }
    if (taxonName.isProtectedTitleCache()) {
        // protected title cache
        List<TaggedText> tags = new ArrayList<>();
        tags.add(new TaggedText(TagEnum.name, taxonName.getTitleCache()));
        return tags;
    } else {
        return doGetTaggedTitle(taxonName);
    }
}
Also used : ArrayList(java.util.ArrayList) TaggedText(eu.etaxonomy.cdm.strategy.cache.TaggedText)

Example 25 with TaggedText

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

the class TaxonNameDefaultCacheStrategy method getInfraGenusTaggedNameCache.

/**
 * Returns the tag list for an infrageneric taxon (including species aggregates).
 *
 * @see #getSpeciesAggregateTaggedCache(NonViralName)
 * @param nonViralName
 * @return
 */
protected List<TaggedText> getInfraGenusTaggedNameCache(INonViralName nonViralName, boolean addAppended) {
    Rank rank = nonViralName.getRank();
    if (rank != null && rank.isSpeciesAggregate() && isBlank(nonViralName.getAuthorshipCache())) {
        return getSpeciesAggregateTaggedCache(nonViralName, addAppended);
    }
    // genus
    List<TaggedText> tags = getUninomialTaggedPart(nonViralName);
    // marker
    String infraGenericMarker;
    if (rank != null) {
        try {
            infraGenericMarker = rank.getInfraGenericMarker();
            if (rank.equals(Rank.SECTION_BOTANY()) || rank.equals(Rank.SUBSECTION_BOTANY())) {
                infraGenericMarker = infraGenericMarker.replace("(bot.)", "");
            }
        } catch (UnknownCdmTypeException e) {
            infraGenericMarker = "'unhandled infrageneric rank'";
        }
    } else {
        infraGenericMarker = "'undefined infrageneric rank'";
    }
    String infraGenEpi = CdmUtils.Nz(nonViralName.getInfraGenericEpithet()).trim();
    if (nonViralName.isBinomHybrid()) {
        infraGenericMarker = CdmUtils.concat("", NOTHO, infraGenericMarker);
    }
    addInfraGenericPart(nonViralName, tags, infraGenericMarker, infraGenEpi);
    addAppendedTaggedPhrase(tags, nonViralName, addAppended);
    return tags;
}
Also used : UnknownCdmTypeException(eu.etaxonomy.cdm.strategy.exceptions.UnknownCdmTypeException) Rank(eu.etaxonomy.cdm.model.name.Rank) TaggedText(eu.etaxonomy.cdm.strategy.cache.TaggedText)

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