Search in sources :

Example 1 with TaggedTextBuilder

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

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

the class TaxonNameDefaultCacheStrategy method getCultivarTaggedNameCache.

// ***************************** PRIVATES ***************************************/
private List<TaggedText> getCultivarTaggedNameCache(TaxonName taxonName) {
    List<TaggedText> scientificNameTags;
    TaggedTextBuilder builder = TaggedTextBuilder.NewInstance();
    if (isNotBlank(taxonName.getInfraSpecificEpithet())) {
        scientificNameTags = getInfraSpeciesTaggedNameCache(taxonName, false, false);
    } else if (isNotBlank(taxonName.getSpecificEpithet())) {
        scientificNameTags = getSpeciesTaggedNameCache(taxonName, false);
    } else if (isNotBlank(taxonName.getInfraGenericEpithet())) {
        scientificNameTags = getInfraGenusTaggedNameCache(taxonName, false);
    } else /*if (isNotBlank(taxonName.getGenusOrUninomial())) */
    {
        scientificNameTags = getGenusOrUninomialTaggedNameCache(taxonName, false);
    }
    UUID rankUuid = taxonName.getRank().getUuid();
    boolean rankIsHandled = true;
    String cultivarStr = null;
    String groupStr = taxonName.getCultivarGroupEpithet();
    if (rankUuid.equals(Rank.uuidCultivar)) {
        cultivarStr = surroundedCultivarEpithet(taxonName.getCultivarEpithet());
        if (isNotBlank(cultivarStr) && isNotBlank(groupStr)) {
            groupStr = surroundGroupWithBracket(groupStr);
        }
        cultivarStr = CdmUtils.concat(" ", groupStr, cultivarStr);
    } else if (rankUuid.equals(Rank.uuidCultivarGroup)) {
        cultivarStr = CdmUtils.concat(" ", groupStr, checkHasGroupEpithet(groupStr) ? null : "Group");
    } else if (rankUuid.equals(Rank.uuidGrexICNCP)) {
        cultivarStr = CdmUtils.concat(" ", groupStr, checkHasGrexEpithet(groupStr) ? null : "grex");
    } else {
        rankIsHandled = false;
    }
    if (rankIsHandled) {
        builder.addAll(scientificNameTags);
    } else if (rankUuid.equals(Rank.uuidGraftChimaera)) {
        // TODO not yet fully implemented
        cultivarStr = "+ " + CdmUtils.concat(" ", taxonName.getGenusOrUninomial(), surroundedCultivarEpithet(taxonName.getCultivarEpithet()));
    } else if (rankUuid.equals(Rank.uuidDenominationClass)) {
        // TODO dummy implementation
        cultivarStr = CdmUtils.concat(" ", taxonName.getGenusOrUninomial(), surroundedCultivarEpithet(taxonName.getCultivarEpithet()));
    } else {
        // (!rankIsHandled)
        throw new IllegalStateException("Unsupported rank " + taxonName.getRank().getTitleCache() + " for cultivar.");
    }
    if (isNotBlank(cultivarStr)) {
        builder.add(TagEnum.cultivar, cultivarStr);
    }
    List<TaggedText> tags = builder.getTaggedText();
    addAppendedTaggedPhrase(tags, taxonName, true);
    return tags;
}
Also used : TaggedTextBuilder(eu.etaxonomy.cdm.strategy.cache.TaggedTextBuilder) UUID(java.util.UUID) TaggedText(eu.etaxonomy.cdm.strategy.cache.TaggedText)

Example 3 with TaggedTextBuilder

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

the class TypeDesignationSetManager method mapTypeDesignation.

private void mapTypeDesignation(Map<TypedEntityReference<? extends VersionableEntity>, TypeDesignationWorkingSet> byBaseEntityByTypeStatus, TypeDesignationBase<?> td) {
    td = HibernateProxyHelper.deproxy(td);
    TypeDesignationStatusBase<?> status = td.getTypeStatus();
    try {
        final VersionableEntity baseEntity = baseEntity(td);
        final TypedEntityReference<? extends VersionableEntity> baseEntityReference = makeEntityReference(baseEntity);
        TaggedTextBuilder workingsetBuilder = new TaggedTextBuilder();
        boolean withCitation = true;
        TypeDesignationSetFormatter.buildTaggedTextForSingleType(td, withCitation, workingsetBuilder, 0);
        @SuppressWarnings({ "unchecked", "rawtypes" }) TypeDesignationDTO<?> typeDesignationDTO = new TypeDesignationDTO(td.getClass(), td.getUuid(), workingsetBuilder.getTaggedText(), getTypeUuid(td));
        if (!byBaseEntityByTypeStatus.containsKey(baseEntityReference)) {
            byBaseEntityByTypeStatus.put(baseEntityReference, new TypeDesignationWorkingSet(baseEntity, baseEntityReference));
        }
        byBaseEntityByTypeStatus.get(baseEntityReference).insert(status, typeDesignationDTO);
    } catch (DataIntegrityException e) {
        problems.add(e.getMessage());
    }
}
Also used : TaggedTextBuilder(eu.etaxonomy.cdm.strategy.cache.TaggedTextBuilder) VersionableEntity(eu.etaxonomy.cdm.model.common.VersionableEntity)

Example 4 with TaggedTextBuilder

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

the class TypeDesignationSetFormatter method buildTaggedText.

private List<TaggedText> buildTaggedText(TypeDesignationSetManager manager) {
    // still unclear if this should become a parameter or should be always true
    boolean withBrackets = true;
    TaggedTextBuilder finalBuilder = new TaggedTextBuilder();
    if (withNameIfAvailable && manager.getTypifiedNameCache() != null) {
        finalBuilder.add(TagEnum.name, manager.getTypifiedNameCache(), TypedEntityReference.fromEntity(manager.getTypifiedName(), false));
        finalBuilder.addPostSeparator(POST_NAME_SEPARTOR);
    }
    int typeSetCount = 0;
    LinkedHashMap<TypedEntityReference<? extends VersionableEntity>, TypeDesignationWorkingSet> orderedByTypesByBaseEntity = manager.getOrderedTypeDesignationWorkingSets();
    TypeDesignationWorkingSetType lastWsType = null;
    if (orderedByTypesByBaseEntity != null) {
        for (TypedEntityReference<?> baseEntityRef : orderedByTypesByBaseEntity.keySet()) {
            buildTaggedTextForSingleTypeSet(manager, withBrackets, finalBuilder, typeSetCount, baseEntityRef, lastWsType);
            lastWsType = orderedByTypesByBaseEntity.get(baseEntityRef).getWorkingsetType();
            typeSetCount++;
        }
    }
    return finalBuilder.getTaggedText();
}
Also used : TypeDesignationWorkingSetType(eu.etaxonomy.cdm.api.service.name.TypeDesignationWorkingSet.TypeDesignationWorkingSetType) TaggedTextBuilder(eu.etaxonomy.cdm.strategy.cache.TaggedTextBuilder) TypedEntityReference(eu.etaxonomy.cdm.ref.TypedEntityReference) VersionableEntity(eu.etaxonomy.cdm.model.common.VersionableEntity)

Example 5 with TaggedTextBuilder

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

the class TypeDesignationSetFormatter method buildTaggedTextForSingleTypeSet.

private void buildTaggedTextForSingleTypeSet(TypeDesignationSetManager manager, boolean withBrackets, TaggedTextBuilder finalBuilder, int typeSetCount, TypedEntityReference<?> baseEntityRef, TypeDesignationWorkingSetType lastWsType) {
    LinkedHashMap<TypedEntityReference<? extends VersionableEntity>, TypeDesignationWorkingSet> orderedByTypesByBaseEntity = manager.getOrderedTypeDesignationWorkingSets();
    TypeDesignationWorkingSet typeDesignationWorkingSet = orderedByTypesByBaseEntity.get(baseEntityRef);
    TaggedTextBuilder workingsetBuilder = new TaggedTextBuilder();
    if (typeSetCount > 0) {
        workingsetBuilder.add(TagEnum.separator, TYPE_SEPARATOR);
    } else if (withStartingTypeLabel) {
        // TODO this is not really exact as we may want to handle specimen types and
        // name types separately, but this is such a rare case (if at all) and
        // increases complexity so it is not yet implemented
        boolean isPlural = hasMultipleTypes(orderedByTypesByBaseEntity);
        if (typeDesignationWorkingSet.getWorkingsetType().isSpecimenType()) {
            workingsetBuilder.add(TagEnum.label, (isPlural ? "Types:" : "Type:"));
        } else if (typeDesignationWorkingSet.getWorkingsetType().isNameType()) {
            workingsetBuilder.add(TagEnum.label, (isPlural ? "Nametypes:" : "Nametype:"));
        } else {
        // do nothing for now
        }
    }
    boolean hasExplicitBaseEntity = hasExplicitBaseEntity(baseEntityRef, typeDesignationWorkingSet);
    if (hasExplicitBaseEntity && !baseEntityRef.getLabel().isEmpty()) {
        workingsetBuilder.add(TagEnum.specimenOrObservation, baseEntityRef.getLabel(), baseEntityRef);
    }
    int typeStatusCount = 0;
    if (withBrackets && hasExplicitBaseEntity) {
        workingsetBuilder.add(TagEnum.separator, TYPE_STATUS_PARENTHESIS_LEFT);
    }
    for (TypeDesignationStatusBase<?> typeStatus : typeDesignationWorkingSet.keySet()) {
        typeStatusCount = buildTaggedTextForSingleTypeStatus(manager, workingsetBuilder, typeDesignationWorkingSet, typeStatusCount, typeStatus, lastWsType, typeSetCount);
    }
    if (withBrackets && hasExplicitBaseEntity) {
        workingsetBuilder.add(TagEnum.separator, TYPE_STATUS_PARENTHESIS_RIGHT);
    }
    typeDesignationWorkingSet.setRepresentation(workingsetBuilder.toString());
    finalBuilder.addAll(workingsetBuilder);
    return;
}
Also used : TypedEntityReference(eu.etaxonomy.cdm.ref.TypedEntityReference) TaggedTextBuilder(eu.etaxonomy.cdm.strategy.cache.TaggedTextBuilder) VersionableEntity(eu.etaxonomy.cdm.model.common.VersionableEntity)

Aggregations

TaggedTextBuilder (eu.etaxonomy.cdm.strategy.cache.TaggedTextBuilder)5 VersionableEntity (eu.etaxonomy.cdm.model.common.VersionableEntity)3 TypedEntityReference (eu.etaxonomy.cdm.ref.TypedEntityReference)2 TaggedText (eu.etaxonomy.cdm.strategy.cache.TaggedText)2 TypeDesignationWorkingSetType (eu.etaxonomy.cdm.api.service.name.TypeDesignationWorkingSet.TypeDesignationWorkingSetType)1 TaxonName (eu.etaxonomy.cdm.model.name.TaxonName)1 Taxon (eu.etaxonomy.cdm.model.taxon.Taxon)1 TaxonRelationshipType (eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType)1 UUID (java.util.UUID)1