Search in sources :

Example 1 with TextualTypeDesignation

use of eu.etaxonomy.cdm.model.name.TextualTypeDesignation 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 2 with TextualTypeDesignation

use of eu.etaxonomy.cdm.model.name.TextualTypeDesignation in project cdmlib by cybertaxonomy.

the class TypeDesignationBaseBeanProcessor method processBeanSecondStep.

@Override
public JSONObject processBeanSecondStep(TypeDesignationBase bean, JSONObject json, JsonConfig jsonConfig) {
    json.element("typeStatus", bean.getTypeStatus(), jsonConfig);
    if (bean.getClass().isAssignableFrom(SpecimenTypeDesignation.class)) {
        json.element("typeSpecimen", ((SpecimenTypeDesignation) bean).getTypeSpecimen(), jsonConfig);
        json.element("designationSource", ((SpecimenTypeDesignation) bean).getDesignationSource(), jsonConfig);
    } else if (bean.getClass().isAssignableFrom(NameTypeDesignation.class)) {
        json.element("typeName", ((NameTypeDesignation) bean).getTypeName(), jsonConfig);
        json.element("designationSource", ((NameTypeDesignation) bean).getDesignationSource(), jsonConfig);
    }
    if (bean instanceof TextualTypeDesignation) {
        List<Language> languages = LocaleContext.getLanguages();
        TextualTypeDesignation textualTypeDesignation = (TextualTypeDesignation) bean;
        LanguageString languageString;
        if (Hibernate.isInitialized(textualTypeDesignation.getText())) {
            languageString = MultilanguageTextHelper.getPreferredLanguageString(textualTypeDesignation.getText(), languages);
            if (languageString != null) {
                json.element("text_L10n", languageString, jsonConfig);
            }
            if (!isReplaceMultilanguageText()) {
                json.element("text", textualTypeDesignation.getText().values(), jsonConfig);
            }
        }
    }
    return json;
}
Also used : NameTypeDesignation(eu.etaxonomy.cdm.model.name.NameTypeDesignation) Language(eu.etaxonomy.cdm.model.common.Language) LanguageString(eu.etaxonomy.cdm.model.common.LanguageString) TextualTypeDesignation(eu.etaxonomy.cdm.model.name.TextualTypeDesignation)

Example 3 with TextualTypeDesignation

use of eu.etaxonomy.cdm.model.name.TextualTypeDesignation in project cdmlib by cybertaxonomy.

the class CdmLightClassificationExport method handleHomotypicalGroup.

private void handleHomotypicalGroup(CdmLightExportState state, HomotypicalGroup group, Taxon acceptedTaxon, int sortIndex) {
    try {
        state.addHomotypicalGroupToStore(group);
        CdmLightExportTable table = CdmLightExportTable.HOMOTYPIC_GROUP;
        String[] csvLine = new String[table.getSize()];
        csvLine[table.getIndex(CdmLightExportTable.SORT_INDEX)] = String.valueOf(sortIndex);
        csvLine[table.getIndex(CdmLightExportTable.HOMOTYPIC_GROUP_ID)] = getId(state, group);
        List<TaxonName> typifiedNames = new ArrayList<>();
        if (acceptedTaxon != null) {
            List<Synonym> synonymsInGroup = acceptedTaxon.getSynonymsInGroup(group);
            if (group.equals(acceptedTaxon.getHomotypicGroup())) {
                typifiedNames.add(acceptedTaxon.getName());
            }
            synonymsInGroup.stream().forEach(synonym -> typifiedNames.add(CdmBase.deproxy(synonym.getName())));
        }
        TaxonName firstname = null;
        for (TaxonName name : typifiedNames) {
            Iterator<Taxon> taxa = name.getTaxa().iterator();
            while (taxa.hasNext()) {
                Taxon taxon = taxa.next();
                if (!(taxon.isMisapplication() || taxon.isProparteSynonym())) {
                    firstname = name;
                    break;
                }
            }
        }
        // Collections.sort(typifiedNames, new HomotypicalGroupNameComparator(firstname, true));
        String typifiedNamesString = "";
        String typifiedNamesWithSecString = "";
        String typifiedNamesWithoutAccepted = "";
        String typifiedNamesWithoutAcceptedWithSec = "";
        int index = 0;
        for (TaxonName name : typifiedNames) {
            // Concatenated output string for homotypic group (names and
            // citations) + status + some name relations (e.g. “non”)
            // TODO: nameRelations, which and how to display
            Set<TaxonBase> taxonBases = name.getTaxonBases();
            TaxonBase<?> taxonBase;
            String sec = "";
            String nameString = name.getFullTitleCache();
            String doubtful = "";
            if (state.getConfig().isAddHTML()) {
                nameString = createNameWithItalics(name.getTaggedFullTitle());
            }
            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());
                }
            });
            List<NameRelationship> nonNames = new ArrayList<>();
            List<NameRelationship> otherRelationships = new ArrayList<>();
            for (NameRelationship rel : relatedList) {
                // no inverse relations
                if (rel.getFromName().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()))) {
                        nonNames.add(rel);
                    } else if (!rel.getType().isBasionymRelation()) {
                        otherRelationships.add(rel);
                    }
                }
            }
            String nonRelNames = "";
            String relNames = "";
            if (nonNames.size() > 0) {
                nonRelNames += " [";
            }
            for (NameRelationship relName : nonNames) {
                String label = "non ";
                TaxonName relatedName = null;
                if (relName.getFromName().equals(name)) {
                    relatedName = relName.getToName();
                    nonRelNames += label + relatedName.getTitleCache() + " ";
                }
            // else{
            // label = relName.getType().getInverseLabel() + " ";
            // relatedName = relName.getFromName();
            // nonRelNames += label + relatedName.getTitleCache() + " ";
            // }
            }
            relNames.trim();
            if (nonNames.size() > 0) {
                nonRelNames = StringUtils.strip(nonRelNames, null);
                nonRelNames += "] ";
            }
            if (otherRelationships.size() > 0) {
                relNames += " [";
            }
            for (NameRelationship rel : otherRelationships) {
                String label = "";
                TaxonName relatedName = null;
                if (rel.getFromName().equals(name)) {
                    label = rel.getType().getLabel() + " ";
                    relatedName = rel.getToName();
                    if (state.getConfig().isAddHTML()) {
                        relNames += label + createNameWithItalics(relatedName.getTaggedName()) + " ";
                    } else {
                        relNames += label + relatedName.getTitleCache();
                    }
                }
            // else {
            // label = rel.getType().getInverseLabel() + " ";
            // relatedName = rel.getFromName();
            // }
            }
            relNames.trim();
            if (otherRelationships.size() > 0) {
                relNames = StringUtils.stripEnd(relNames, null);
                relNames += "] ";
            }
            String synonymSign = "";
            if (index > 0) {
                if (name.isInvalid()) {
                    synonymSign = "\u2212 ";
                } else {
                    synonymSign = "\u2261 ";
                }
            } else {
                if (name.isInvalid()) {
                    synonymSign = "\u2212 ";
                } else {
                    synonymSign = "\u003D ";
                }
            }
            boolean isAccepted = false;
            if (taxonBases.size() == 1) {
                taxonBase = HibernateProxyHelper.deproxy(taxonBases.iterator().next());
                if (taxonBase.getSec() != null) {
                    sec = OriginalSourceFormatter.INSTANCE_WITH_YEAR_BRACKETS.format(taxonBase.getSecSource());
                }
                if (taxonBase.isDoubtful()) {
                    doubtful = "?";
                } else {
                    doubtful = "";
                }
                if (taxonBase instanceof Synonym) {
                    if (isNotBlank(sec)) {
                        sec = " syn. sec. " + sec + " ";
                    } else {
                        sec = "";
                    }
                    typifiedNamesWithoutAccepted += synonymSign + doubtful + nameString + nonRelNames + relNames;
                    typifiedNamesWithoutAcceptedWithSec += synonymSign + doubtful + nameString + sec + nonRelNames + relNames;
                } else {
                    // sec = "";
                    if (!(((Taxon) taxonBase).isProparteSynonym() || ((Taxon) taxonBase).isMisapplication())) {
                        isAccepted = true;
                    } else {
                        synonymSign = "\u003D ";
                    }
                }
                if (taxonBase.getAppendedPhrase() != null) {
                    if (state.getConfig().isAddHTML()) {
                        String taxonString = createNameWithItalics(taxonBase.getTaggedTitle());
                        taxonString = taxonString.replace("sec " + sec, "");
                        String nameCacheWithItalics = createNameWithItalics(name.getTaggedName());
                        nameString = nameString.replace(nameCacheWithItalics, taxonString);
                    }
                }
            } else {
                // there are names used more than once?
                for (TaxonBase<?> tb : taxonBases) {
                    if (tb.getSec() != null) {
                        sec = OriginalSourceFormatter.INSTANCE_WITH_YEAR_BRACKETS.format(tb.getSecSource());
                    }
                    if (tb.isDoubtful()) {
                        doubtful = "?";
                    } else {
                        doubtful = "";
                    }
                    if (tb instanceof Synonym) {
                        if (StringUtils.isNotBlank(sec)) {
                            sec = " syn. sec. " + sec + " ";
                        } else {
                            sec = "";
                        }
                        break;
                    } else {
                        sec = "";
                        if (!(((Taxon) tb).isProparteSynonym() || ((Taxon) tb).isMisapplication())) {
                            isAccepted = true;
                            break;
                        } else {
                            synonymSign = "\u003D ";
                        }
                    }
                }
                if (!isAccepted) {
                    typifiedNamesWithoutAccepted += synonymSign + doubtful + nameString + "; ";
                    typifiedNamesWithoutAcceptedWithSec += synonymSign + doubtful + nameString + sec;
                    typifiedNamesWithoutAcceptedWithSec = typifiedNamesWithoutAcceptedWithSec.trim() + "; ";
                }
            }
            typifiedNamesString += synonymSign + doubtful + nameString + nonRelNames + relNames;
            typifiedNamesWithSecString += synonymSign + doubtful + nameString + sec + nonRelNames + relNames;
            csvLine[table.getIndex(CdmLightExportTable.HOMOTYPIC_GROUP_STRING)] = typifiedNamesString.trim();
            csvLine[table.getIndex(CdmLightExportTable.HOMOTYPIC_GROUP_WITH_SEC_STRING)] = typifiedNamesWithSecString.trim();
            if (typifiedNamesWithoutAccepted != null && firstname != null) {
                csvLine[table.getIndex(CdmLightExportTable.HOMOTYPIC_GROUP_WITHOUT_ACCEPTED)] = typifiedNamesWithoutAccepted.trim();
            } else {
                csvLine[table.getIndex(CdmLightExportTable.HOMOTYPIC_GROUP_WITHOUT_ACCEPTED)] = "";
            }
            if (typifiedNamesWithoutAcceptedWithSec != null && firstname != null) {
                csvLine[table.getIndex(CdmLightExportTable.HOMOTYPIC_GROUP_WITHOUT_ACCEPTEDWITHSEC)] = typifiedNamesWithoutAcceptedWithSec.trim();
            } else {
                csvLine[table.getIndex(CdmLightExportTable.HOMOTYPIC_GROUP_WITHOUT_ACCEPTEDWITHSEC)] = "";
            }
            index++;
        }
        Set<TypeDesignationBase<?>> typeDesigantionSet = group.getTypeDesignations();
        List<TypeDesignationBase<?>> designationList = new ArrayList<>();
        designationList.addAll(typeDesigantionSet);
        Collections.sort(designationList, new TypeComparator());
        List<TaggedText> list = new ArrayList<>();
        if (!designationList.isEmpty()) {
            TypeDesignationSetManager manager = new TypeDesignationSetManager(group);
            list.addAll(new TypeDesignationSetFormatter(true, false, false).toTaggedText(manager));
        }
        String typeTextDesignations = "";
        // The typeDesignationManager does not handle the textual typeDesignations
        for (TypeDesignationBase<?> typeDes : designationList) {
            if (typeDes instanceof TextualTypeDesignation) {
                typeTextDesignations = typeTextDesignations + ((TextualTypeDesignation) typeDes).getText(Language.getDefaultLanguage());
                String typeDesStateRefs = "";
                if (typeDes.getDesignationSource() != null) {
                    typeDesStateRefs = "[";
                    NamedSource source = typeDes.getDesignationSource();
                    if (source.getCitation() != null) {
                        typeDesStateRefs += "fide " + OriginalSourceFormatter.INSTANCE.format(source.getCitation(), null);
                    }
                    typeDesStateRefs += "]";
                } else if (typeDes.getSources() != null && !typeDes.getSources().isEmpty()) {
                    typeDesStateRefs = "[";
                    for (IdentifiableSource source : typeDes.getSources()) {
                        if (source.getCitation() != null) {
                            typeDesStateRefs += "fide " + OriginalSourceFormatter.INSTANCE.format(source.getCitation(), null);
                        }
                    }
                    typeDesStateRefs += "]";
                }
                typeTextDesignations = typeTextDesignations + typeDesStateRefs + "; ";
            } else if (typeDes instanceof SpecimenTypeDesignation) {
                DerivedUnit specimen = ((SpecimenTypeDesignation) typeDes).getTypeSpecimen();
                if (specimen != null && !state.getSpecimenStore().contains(specimen.getUuid())) {
                    handleSpecimen(state, specimen);
                }
            }
        }
        if (typeTextDesignations.equals("; ")) {
            typeTextDesignations = "";
        }
        if (StringUtils.isNotBlank(typeTextDesignations)) {
            typeTextDesignations = typeTextDesignations.substring(0, typeTextDesignations.length() - 2);
        }
        String specimenTypeString = !list.isEmpty() ? createTypeDesignationString(list, true, typifiedNames.get(0).isSpecies() || typifiedNames.get(0).isInfraSpecific()) : "";
        if (StringUtils.isNotBlank(specimenTypeString)) {
            if (!specimenTypeString.endsWith(".")) {
                specimenTypeString = specimenTypeString + ".";
            }
            csvLine[table.getIndex(CdmLightExportTable.TYPE_STRING)] = specimenTypeString;
        } else {
            csvLine[table.getIndex(CdmLightExportTable.TYPE_STRING)] = "";
        }
        if (StringUtils.isNotBlank(typeTextDesignations)) {
            if (!typeTextDesignations.endsWith(".")) {
                typeTextDesignations = typeTextDesignations + ".";
            }
            csvLine[table.getIndex(CdmLightExportTable.TYPE_CACHE)] = typeTextDesignations;
        } else {
            csvLine[table.getIndex(CdmLightExportTable.TYPE_CACHE)] = "";
        }
        state.getProcessor().put(table, String.valueOf(group.getId()), csvLine);
    } catch (Exception e) {
        state.getResult().addException(e, "An unexpected error occurred when handling homotypic group " + cdmBaseStr(group) + ": " + e.getMessage());
    }
}
Also used : ArrayList(java.util.ArrayList) LanguageString(eu.etaxonomy.cdm.model.common.LanguageString) DerivedUnit(eu.etaxonomy.cdm.model.occurrence.DerivedUnit) TaxonBase(eu.etaxonomy.cdm.model.taxon.TaxonBase) 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) TypeDesignationSetFormatter(eu.etaxonomy.cdm.api.service.name.TypeDesignationSetFormatter) NameRelationship(eu.etaxonomy.cdm.model.name.NameRelationship) Taxon(eu.etaxonomy.cdm.model.taxon.Taxon) TypeDesignationBase(eu.etaxonomy.cdm.model.name.TypeDesignationBase) UnknownCdmTypeException(eu.etaxonomy.cdm.strategy.exceptions.UnknownCdmTypeException) TypeComparator(eu.etaxonomy.cdm.compare.name.TypeComparator) NamedSource(eu.etaxonomy.cdm.model.reference.NamedSource) TypeDesignationSetManager(eu.etaxonomy.cdm.api.service.name.TypeDesignationSetManager) Synonym(eu.etaxonomy.cdm.model.taxon.Synonym) TextualTypeDesignation(eu.etaxonomy.cdm.model.name.TextualTypeDesignation) SpecimenTypeDesignation(eu.etaxonomy.cdm.model.name.SpecimenTypeDesignation)

Aggregations

LanguageString (eu.etaxonomy.cdm.model.common.LanguageString)3 TextualTypeDesignation (eu.etaxonomy.cdm.model.name.TextualTypeDesignation)3 TypeDesignationSetManager (eu.etaxonomy.cdm.api.service.name.TypeDesignationSetManager)2 IdentifiableSource (eu.etaxonomy.cdm.model.common.IdentifiableSource)2 CommonTaxonName (eu.etaxonomy.cdm.model.description.CommonTaxonName)2 NameTypeDesignation (eu.etaxonomy.cdm.model.name.NameTypeDesignation)2 SpecimenTypeDesignation (eu.etaxonomy.cdm.model.name.SpecimenTypeDesignation)2 TaxonName (eu.etaxonomy.cdm.model.name.TaxonName)2 TypeDesignationBase (eu.etaxonomy.cdm.model.name.TypeDesignationBase)2 Synonym (eu.etaxonomy.cdm.model.taxon.Synonym)2 TaggedText (eu.etaxonomy.cdm.strategy.cache.TaggedText)2 UnknownCdmTypeException (eu.etaxonomy.cdm.strategy.exceptions.UnknownCdmTypeException)2 ArrayList (java.util.ArrayList)2 TypeDesignationSetFormatter (eu.etaxonomy.cdm.api.service.name.TypeDesignationSetFormatter)1 TypeComparator (eu.etaxonomy.cdm.compare.name.TypeComparator)1 HomotypicGroupTaxonComparator (eu.etaxonomy.cdm.compare.taxon.HomotypicGroupTaxonComparator)1 Language (eu.etaxonomy.cdm.model.common.Language)1 HomotypicalGroup (eu.etaxonomy.cdm.model.name.HomotypicalGroup)1 NameRelationship (eu.etaxonomy.cdm.model.name.NameRelationship)1 NomenclaturalSource (eu.etaxonomy.cdm.model.name.NomenclaturalSource)1