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;
}
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);
}
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());
}
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" });
}
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();
}
}
Aggregations