Search in sources :

Example 1 with IBotanicalName

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

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

the class StatisticsDaoHibernateImplTest method createDataSet.

private void createDataSet() {
    // create NO_OF_CLASSIFICATIONS classifications
    classifications = new ArrayList<Classification>();
    for (int i = 1; i <= NO_OF_CLASSIFICATIONS; i++) {
        Classification classification = Classification.NewInstance("European Abies" + i);
        classifications.add(classification);
        classificationDao.save(classification);
    }
    // create all taxa, references and synonyms and attach them to one or
    // more classifications
    // variables: flags
    int remainder = NO_OF_ACCEPTED_TAXA;
    Reference sec = ReferenceFactory.newBook();
    boolean secondClassificationForTaxonFlag = false;
    boolean synonymFlag = false;
    boolean tNomRefFlag = false;
    boolean sNomRefFlag = false;
    boolean tDescrSourceRefFlag = false;
    boolean sDescrSourceRefFlag = false;
    // variables: counter (pre-loop)
    int descriptiveElementsPerTaxon = (NO_OF_DESCRIPTIVE_SOURCE_REFERENCES / NO_OF_ACCEPTED_TAXA) + 1;
    int taxaInClass;
    int classiCounter = 0, sharedClassification = 0, synonymCounter = 0, nomRefCounter = 0;
    // iterate over classifications and add taxa
    for (; /* see above */
    remainder > 0 && classiCounter < NO_OF_CLASSIFICATIONS; ) /* see below */
    {
        // compute no of taxa to be created in this classification
        if (classiCounter >= NO_OF_CLASSIFICATIONS - 1) {
            // last classification
            // gets all left taxa
            taxaInClass = remainder;
        } else {
            // take half of left taxa for this class:
            taxaInClass = remainder / 2;
        }
        // iterate over amount of taxa meant to be in this classification
        for (int taxonCounter = 1; taxonCounter <= taxaInClass; taxonCounter++) {
            // create a String for the Name
            RandomStringUtils.randomAlphabetic(10);
            String randomName = RandomStringUtils.randomAlphabetic(5) + " " + RandomStringUtils.randomAlphabetic(10);
            // create a name for the taxon
            IBotanicalName name = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
            name.setNameCache(randomName, true);
            // create nomenclatural reference for taxon name (if left)
            if (nomRefCounter < NO_OF_NOMENCLATURAL_REFERENCES) {
                // we remember this taxon has a nomenclatural reference:
                tNomRefFlag = true;
                Reference nomRef = ReferenceFactory.newBook();
                name.setNomenclaturalReference(nomRef);
                referenceDao.save(nomRef);
                nomRefCounter++;
            }
            // create a new sec for every other taxon
            if (taxonCounter % 2 != 0) {
                sec = createSecReference(classiCounter, taxonCounter);
            }
            // create the taxon
            Taxon taxon = Taxon.NewInstance(name, sec);
            if (no_of_descriptive_source_references < NO_OF_DESCRIPTIVE_SOURCE_REFERENCES) {
                tDescrSourceRefFlag = true;
                // create a description and 2 description elements with
                // references for taxon name
                TaxonNameDescription nameDescr = TaxonNameDescription.NewInstance();
                CommonTaxonName nameElement = CommonTaxonName.NewInstance("Veilchen" + taxonCounter, Language.GERMAN());
                TextData textElement = new TextData();
                Reference nameElementRef = ReferenceFactory.newArticle();
                Reference textElementRef = ReferenceFactory.newBookSection();
                nameElement.addSource(OriginalSourceType.PrimaryTaxonomicSource, null, null, nameElementRef, "name: ");
                textElement.addSource(OriginalSourceType.PrimaryTaxonomicSource, null, null, textElementRef, "text: ");
                nameDescr.addElement(nameElement);
                nameDescr.addElement(textElement);
                name.addDescription(nameDescr);
                // taxon.getName().addDescription(nameDescr);
                referenceDao.save(nameElementRef);
                referenceDao.save(textElementRef);
                descriptionDao.save(nameDescr);
                // create descriptions, description sources and their
                // references
                // for taxon
                TaxonDescription taxonDescription = new TaxonDescription();
                for (int i = 0; i < descriptiveElementsPerTaxon; i++) {
                    DescriptionElementBase descriptionElement = new TextData();
                    DescriptionElementSource descriptionElementSource = DescriptionElementSource.NewInstance(OriginalSourceType.PrimaryTaxonomicSource);
                    Reference article = ReferenceFactory.newArticle();
                    descriptionElementSource.setCitation(article);
                    descriptionElement.addSource(descriptionElementSource);
                    taxonDescription.addElement(descriptionElement);
                    referenceDao.save(article);
                    descriptionElementDao.save(descriptionElement);
                }
                descriptionDao.save(taxonDescription);
                taxon.addDescription(taxonDescription);
                // create a Specimen for taxon with description, descr.
                // element and referece
                // 
                // Specimen specimen = Specimen.NewInstance();
                // SpecimenDescription specimenDescription =
                // SpecimenDescription.NewInstance(specimen);
                // DescriptionElementBase descrElement = new TextData();
                // Reference specimenRef = ReferenceFactory.newArticle();
                // descrElement.addSource(null, null, specimenRef, null);
                // 
                // 
                // descriptionService.save(specimenDescription);
                // taxon.add(specimen);
                no_of_descriptive_source_references += descriptiveElementsPerTaxon + 2 + 1;
            }
            // add taxon to classification
            classifications.get(classiCounter).addChildTaxon(taxon, null, null);
            // now if there are any left, we create a synonym for the taxon
            if (synonymCounter < NO_OF_SYNONYMS) {
                synonymFlag = true;
                randomName = RandomStringUtils.randomAlphabetic(5) + " " + RandomStringUtils.randomAlphabetic(10);
                // name for synonym
                name = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
                name.setNameCache(randomName, true);
                // create nomenclatural reference for synonym name (if left)
                if (nomRefCounter < NO_OF_NOMENCLATURAL_REFERENCES) {
                    sNomRefFlag = true;
                    Reference nomRef = ReferenceFactory.newBook();
                    name.setNomenclaturalReference(nomRef);
                    referenceDao.save(nomRef);
                    nomRefCounter++;
                }
                if (no_of_descriptive_source_references < NO_OF_DESCRIPTIVE_SOURCE_REFERENCES) {
                    sDescrSourceRefFlag = true;
                    // create a description and 2 description elements with
                    // references for synonym name
                    TaxonNameDescription nameDescr = TaxonNameDescription.NewInstance();
                    CommonTaxonName nameElement = CommonTaxonName.NewInstance("anderes Veilchen" + taxonCounter, Language.GERMAN());
                    TextData textElement = new TextData();
                    Reference nameElementRef = ReferenceFactory.newArticle();
                    Reference textElementRef = ReferenceFactory.newBookSection();
                    nameElement.addSource(OriginalSourceType.PrimaryTaxonomicSource, null, null, nameElementRef, "name: ");
                    textElement.addSource(OriginalSourceType.PrimaryTaxonomicSource, null, null, textElementRef, "text: ");
                    nameDescr.addElement(nameElement);
                    nameDescr.addElement(textElement);
                    name.addDescription(nameDescr);
                    // taxon.getName().addDescription(nameDescr);
                    referenceDao.save(nameElementRef);
                    referenceDao.save(textElementRef);
                    descriptionDao.save(nameDescr);
                    no_of_descriptive_source_references += 2;
                }
                // create a new reference for every other synonym:
                if (taxonCounter % 2 != 0) {
                    sec = createSecReference(classiCounter, taxonCounter);
                }
                Synonym synonym = Synonym.NewInstance(name, sec);
                taxonDao.save(synonym);
                taxon.addSynonym(synonym, SynonymType.SYNONYM_OF());
                synonymCounter++;
            }
            // we add the taxon to the next class in the list too.
            if (classiCounter < NO_OF_CLASSIFICATIONS && sharedClassification < NO_OF_SHARED_TAXA) {
                classifications.get(classiCounter + 1).addChildTaxon(taxon, null, null);
                // we remember that this taxon is attached to 2
                // classifications:
                secondClassificationForTaxonFlag = true;
                sharedClassification++;
                classificationDao.saveOrUpdate(classifications.get(classiCounter + 1));
            }
            taxonDao.save(taxon);
            classificationDao.saveOrUpdate(classifications.get(classiCounter));
            // count the data created with this taxon:
            int c = classiCounter;
            if (secondClassificationForTaxonFlag) {
                c++;
            }
            // twice, if it is attached to 2 classifications
            for (int i = classiCounter; i <= c; i++) {
                // count everything just created for this taxon:
                increment(no_of_accepted_taxa_c, i);
                increment(no_of_taxon_names_c, i);
                if (tNomRefFlag) {
                    increment(no_of_nomenclatural_references_c, i);
                }
                if (sNomRefFlag) {
                    increment(no_of_nomenclatural_references_c, i);
                }
                if (synonymFlag) {
                    increment(no_of_synonyms_c, i);
                    increment(no_of_taxon_names_c, i);
                }
                if (taxonCounter % 2 != 0) {
                    increment(no_of_all_references_c, i);
                    if (synonymFlag) {
                        increment(no_of_all_references_c, i);
                    }
                }
                if (tDescrSourceRefFlag) {
                    increment(no_of_descriptive_source_references_c, i, descriptiveElementsPerTaxon + 2);
                }
                if (sDescrSourceRefFlag) {
                    increment(no_of_descriptive_source_references_c, i, 2);
                }
            }
            // put flags back:
            secondClassificationForTaxonFlag = false;
            tNomRefFlag = false;
            sNomRefFlag = false;
            synonymFlag = false;
            tDescrSourceRefFlag = false;
            sDescrSourceRefFlag = false;
        }
        // modify variables (post-loop)
        classiCounter++;
        remainder -= taxaInClass;
    }
    merge(no_of_accepted_taxa_c, no_of_synonyms_c, no_of_all_taxa_c);
    merge(no_of_all_references_c, no_of_nomenclatural_references_c, no_of_all_references_c);
}
Also used : CommonTaxonName(eu.etaxonomy.cdm.model.description.CommonTaxonName) TaxonNameDescription(eu.etaxonomy.cdm.model.description.TaxonNameDescription) Reference(eu.etaxonomy.cdm.model.reference.Reference) Taxon(eu.etaxonomy.cdm.model.taxon.Taxon) TaxonDescription(eu.etaxonomy.cdm.model.description.TaxonDescription) DescriptionElementBase(eu.etaxonomy.cdm.model.description.DescriptionElementBase) IBotanicalName(eu.etaxonomy.cdm.model.name.IBotanicalName) Classification(eu.etaxonomy.cdm.model.taxon.Classification) TextData(eu.etaxonomy.cdm.model.description.TextData) DescriptionElementSource(eu.etaxonomy.cdm.model.description.DescriptionElementSource) Synonym(eu.etaxonomy.cdm.model.taxon.Synonym)

Example 3 with IBotanicalName

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

the class TaxonServiceSearchTest method testFindByDescriptionElementFullText_modify_Taxon.

@SuppressWarnings("rawtypes")
@Test
@DataSet(loadStrategy = CleanSweepInsertLoadStrategy.class)
public final void testFindByDescriptionElementFullText_modify_Taxon() throws IOException, LuceneParseException {
    refreshLuceneIndex();
    TaxonNode subtree = null;
    Taxon t_abies_balsamea = (Taxon) taxonService.find(ABIES_BALSAMEA_UUID);
    TaxonDescription d_abies_balsamea = (TaxonDescription) descriptionService.find(DESC_ABIES_BALSAMEA_UUID);
    Pager<SearchResult<TaxonBase>> pager = taxonService.findByDescriptionElementFullText(TextData.class, "Balsam-Tanne", null, subtree, null, Arrays.asList(new Language[] { Language.GERMAN() }), false, null, null, null, null);
    Assert.assertEquals("expecting to find the GERMAN 'Balsam-Tanne'", 1, pager.getCount().intValue());
    // exchange the Taxon with another one via the Taxon object
    // 1.) remove existing description:
    t_abies_balsamea.removeDescription(d_abies_balsamea);
    taxonService.saveOrUpdate(t_abies_balsamea);
    commitAndStartNewTransaction(null);
    t_abies_balsamea = (Taxon) taxonService.find(t_abies_balsamea.getUuid());
    pager = taxonService.findByDescriptionElementFullText(TextData.class, "Balsam-Tanne", null, subtree, null, Arrays.asList(new Language[] { Language.GERMAN() }), false, null, null, null, null);
    Assert.assertEquals("'Balsam-Tanne' should no longer be found", 0, pager.getCount().intValue());
    // 2.) create new description and add to taxon:
    TaxonDescription d_abies_balsamea_new = TaxonDescription.NewInstance();
    d_abies_balsamea_new.addElement(TextData.NewInstance("Die Balsamtanne ist mit bis zu 30 m Höhe ein mittelgro" + UTF8.SHARP_S + "er Baum und kann bis zu 200 Jahre alt werden", Language.GERMAN(), null));
    t_abies_balsamea.addDescription(d_abies_balsamea_new);
    // set authorshipCache to null to avoid validation exception,
    // this is maybe not needed in future,  see ticket #3344
    IBotanicalName abies_balsamea = CdmBase.deproxy(t_abies_balsamea.getName(), TaxonName.class);
    abies_balsamea.setAuthorshipCache(null);
    printDataSet(System.err, new String[] { "LANGUAGESTRING_AUD" });
    taxonService.saveOrUpdate(t_abies_balsamea);
    commitAndStartNewTransaction(null);
    // printDataSet(System.out, new String[] {
    // "DESCRIPTIONBASE"
    // });
    pager = taxonService.findByDescriptionElementFullText(TextData.class, "mittelgro" + UTF8.SHARP_S + "er Baum", null, subtree, null, Arrays.asList(new Language[] { Language.GERMAN() }), false, null, null, null, null);
    Assert.assertEquals("the taxon should be found via the new Description", 1, pager.getCount().intValue());
}
Also used : IBotanicalName(eu.etaxonomy.cdm.model.name.IBotanicalName) TaxonNode(eu.etaxonomy.cdm.model.taxon.TaxonNode) Language(eu.etaxonomy.cdm.model.common.Language) Taxon(eu.etaxonomy.cdm.model.taxon.Taxon) TextData(eu.etaxonomy.cdm.model.description.TextData) TaxonDescription(eu.etaxonomy.cdm.model.description.TaxonDescription) SearchResult(eu.etaxonomy.cdm.api.service.search.SearchResult) CdmTransactionalIntegrationTest(eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest) Test(org.junit.Test) DataSet(org.unitils.dbunit.annotation.DataSet)

Example 4 with IBotanicalName

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

the class DistributionAggregationTest method createTestDataSet.

// @Test //  uncomment to create test data file//
@Override
public void createTestDataSet() throws FileNotFoundException {
    // --- References --- //
    Reference sec = ReferenceFactory.newDatabase();
    sec.setTitleCache("Test", true);
    Reference nomRef = ReferenceFactory.newBook();
    sec.setTitleCache("Sp.Pl.", true);
    referenceService.save(sec);
    referenceService.save(nomRef);
    // --- Taxa --- //
    // Lapsana
    // L. communis
    // L. communis subsp. communis
    // L. communis subsp. adenophora
    // L. communis subsp. alpina
    // Sonchella
    // S. dentata
    // S. stenoma
    IBotanicalName n_lapsana = TaxonNameFactory.NewBotanicalInstance(Rank.GENUS());
    n_lapsana.setTitleCache("Lapsana", true);
    Taxon t_lapsana = Taxon.NewInstance(n_lapsana, sec);
    t_lapsana.setUuid(T_LAPSANA_UUID);
    taxonService.saveOrUpdate(t_lapsana);
    IBotanicalName n_lapsana_communis = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
    n_lapsana_communis.setTitleCache("L. communis", true);
    Taxon t_lapsana_communis = Taxon.NewInstance(n_lapsana_communis, sec);
    t_lapsana_communis.setUuid(T_LAPSANA_COMMUNIS_UUID);
    taxonService.saveOrUpdate(t_lapsana_communis);
    IBotanicalName n_lapsana_communis_communis = TaxonNameFactory.NewBotanicalInstance(Rank.SUBSPECIES());
    n_lapsana_communis_communis.setTitleCache("L. communis subsp. communis", true);
    Taxon t_lapsana_communis_communis = Taxon.NewInstance(n_lapsana_communis_communis, sec);
    t_lapsana_communis_communis.setUuid(T_LAPSANA_COMMUNIS_COMMUNIS_UUID);
    taxonService.saveOrUpdate(t_lapsana_communis_communis);
    IBotanicalName n_lapsana_communis_adenophora = TaxonNameFactory.NewBotanicalInstance(Rank.SUBSPECIES());
    n_lapsana_communis_adenophora.setTitleCache("L. communis subsp. adenophora", true);
    Taxon t_lapsana_communis_adenophora = Taxon.NewInstance(n_lapsana_communis_adenophora, sec);
    t_lapsana_communis_adenophora.setUuid(T_LAPSANA_COMMUNIS_ADENOPHORA_UUID);
    taxonService.saveOrUpdate(t_lapsana_communis_adenophora);
    IBotanicalName n_lapsana_communis_alpina = TaxonNameFactory.NewBotanicalInstance(Rank.SUBSPECIES());
    n_lapsana_communis_alpina.setTitleCache("L. communis subsp. alpina", true);
    Taxon t_lapsana_communis_alpina = Taxon.NewInstance(n_lapsana_communis_alpina, sec);
    t_lapsana_communis_alpina.setUuid(T_LAPSANA_COMMUNIS_ALPINA_UUID);
    taxonService.saveOrUpdate(t_lapsana_communis_alpina);
    // --- Classification --- //
    Classification classification = Classification.NewInstance("TestClassification");
    classification.setUuid(CLASSIFICATION_UUID);
    classificationService.save(classification);
    TaxonNode node_lapsana = classification.addChildTaxon(t_lapsana, sec, null);
    TaxonNode node_lapsana_communis = node_lapsana.addChildTaxon(t_lapsana_communis, sec, null);
    node_lapsana_communis.addChildTaxon(t_lapsana_communis_communis, sec, null);
    node_lapsana_communis.addChildTaxon(t_lapsana_communis_adenophora, sec, null);
    node_lapsana_communis.addChildTaxon(t_lapsana_communis_alpina, sec, null);
    classificationService.saveOrUpdate(classification);
    // --- Distributions --- //
    // tdwg3 level YUG :  Yugoslavia
    // contains tdwg4 level areas :
    // YUG-BH	Bosnia-Herzegovina
    // YUG-CR	Croatia
    // YUG-KO	Kosovo
    // YUG-MA	Macedonia
    // YUG-MN	Montenegro
    // assigning distribution information to taxa
    // expectations regarding the aggregation can be found in the comments below
    // TaxonDescription d_lapsana_communis_communis = TaxonDescription.NewInstance(t_lapsana_communis_communis);
    // d_lapsana_communis_communis.addElement(Distribution.NewInstance(
    // TdwgArea.getAreaByTdwgAbbreviation("YUG-MN"),
    // PresenceTerm.ENDEMIC_FOR_THE_RELEVANT_AREA() // should be ignored
    // );
    commitAndStartNewTransaction(null);
    writeDbUnitDataSetFile(new String[] { "TAXONBASE", "TAXONNAME", "REFERENCE", "DESCRIPTIONELEMENTBASE", "DESCRIPTIONBASE", "AGENTBASE", "CLASSIFICATION", "TAXONNODE", "HOMOTYPICALGROUP", "LANGUAGESTRING", "HIBERNATE_SEQUENCES" });
}
Also used : IBotanicalName(eu.etaxonomy.cdm.model.name.IBotanicalName) TaxonNode(eu.etaxonomy.cdm.model.taxon.TaxonNode) Reference(eu.etaxonomy.cdm.model.reference.Reference) Taxon(eu.etaxonomy.cdm.model.taxon.Taxon) Classification(eu.etaxonomy.cdm.model.taxon.Classification)

Example 5 with IBotanicalName

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

the class TaxonServiceImplTest method testDeleteTaxonWithAnnotations.

@Test
@DataSet(value = "../../database/ClearDBDataSet.xml")
public final void testDeleteTaxonWithAnnotations() {
    // create a small classification
    Taxon testTaxon = getTestTaxon();
    service.save(testTaxon).getUuid();
    Taxon speciesTaxon = (Taxon) service.find(SPECIES1_UUID);
    Iterator<TaxonDescription> descriptionIterator = speciesTaxon.getDescriptions().iterator();
    UUID descrUUID = null;
    UUID descrElementUUID = null;
    if (descriptionIterator.hasNext()) {
        TaxonDescription descr = descriptionIterator.next();
        descrUUID = descr.getUuid();
        descrElementUUID = descr.getElements().iterator().next().getUuid();
    }
    IBotanicalName taxonName = nameService.find(SPECIES1_NAME_UUID);
    assertNotNull(taxonName);
    TaxonDeletionConfigurator config = new TaxonDeletionConfigurator();
    config.setDeleteNameIfPossible(false);
    Annotation annotation = Annotation.NewDefaultLanguageInstance("test");
    speciesTaxon.addAnnotation(annotation);
    DeleteResult result = service.deleteTaxon(speciesTaxon.getUuid(), config, speciesTaxon.getTaxonNodes().iterator().next().getClassification().getUuid());
    if (!result.isOk()) {
        Assert.fail();
    }
    commitAndStartNewTransaction(null);
    taxonName = nameService.find(SPECIES1_NAME_UUID);
    Taxon taxon = (Taxon) service.find(SPECIES1_UUID);
    // descriptionService.find(descrUUID);
    assertNull(descriptionService.find(descrUUID));
    assertNull(descriptionElementService.find(descrElementUUID));
    // assertNull(synName);
    assertNotNull(taxonName);
    assertNull(taxon);
    config.setDeleteNameIfPossible(true);
    Taxon newTaxon = Taxon.NewInstance(TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES()), null);
    service.save(newTaxon);
    result = service.deleteTaxon(newTaxon.getUuid(), config, null);
    if (!result.isOk()) {
        Assert.fail();
    }
}
Also used : IBotanicalName(eu.etaxonomy.cdm.model.name.IBotanicalName) TaxonDeletionConfigurator(eu.etaxonomy.cdm.api.service.config.TaxonDeletionConfigurator) Taxon(eu.etaxonomy.cdm.model.taxon.Taxon) TaxonDescription(eu.etaxonomy.cdm.model.description.TaxonDescription) UUID(java.util.UUID) Annotation(eu.etaxonomy.cdm.model.common.Annotation) CdmTransactionalIntegrationTest(eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest) Test(org.junit.Test) DataSet(org.unitils.dbunit.annotation.DataSet)

Aggregations

IBotanicalName (eu.etaxonomy.cdm.model.name.IBotanicalName)70 Test (org.junit.Test)48 Taxon (eu.etaxonomy.cdm.model.taxon.Taxon)44 Reference (eu.etaxonomy.cdm.model.reference.Reference)30 Classification (eu.etaxonomy.cdm.model.taxon.Classification)22 CdmTransactionalIntegrationTest (eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest)19 TaxonNode (eu.etaxonomy.cdm.model.taxon.TaxonNode)16 DataSet (org.unitils.dbunit.annotation.DataSet)16 TaxonDescription (eu.etaxonomy.cdm.model.description.TaxonDescription)15 TaxonName (eu.etaxonomy.cdm.model.name.TaxonName)11 UUID (java.util.UUID)10 ArrayList (java.util.ArrayList)9 Person (eu.etaxonomy.cdm.model.agent.Person)8 CommonTaxonName (eu.etaxonomy.cdm.model.description.CommonTaxonName)8 Synonym (eu.etaxonomy.cdm.model.taxon.Synonym)8 Team (eu.etaxonomy.cdm.model.agent.Team)7 CdmIntegrationTest (eu.etaxonomy.cdm.test.integration.CdmIntegrationTest)6 TaxonDeletionConfigurator (eu.etaxonomy.cdm.api.service.config.TaxonDeletionConfigurator)5 TextData (eu.etaxonomy.cdm.model.description.TextData)5 INonViralName (eu.etaxonomy.cdm.model.name.INonViralName)5