Search in sources :

Example 1 with PolytomousKey

use of eu.etaxonomy.cdm.model.description.PolytomousKey in project cdmlib by cybertaxonomy.

the class MarkupKeyImport method handleKey.

public void handleKey(MarkupImportState state, XMLEventReader reader, XMLEvent parentEvent) throws XMLStreamException {
    // attributes
    Map<String, Attribute> attributes = getAttributes(parentEvent);
    String isSpotcharacters = getAndRemoveAttributeValue(attributes, IS_SPOTCHARACTERS);
    if (isNotBlank(isSpotcharacters)) {
        // TODO isSpotcharacters
        String message = "Attribute isSpotcharacters not yet implemented for <key>";
        fireWarningEvent(message, parentEvent, 4);
    }
    boolean onlyNumberedTaxaExist = checkAndRemoveAttributeValue(attributes, ONLY_NUMBERED_TAXA_EXIST, "true");
    state.setOnlyNumberedTaxaExist(onlyNumberedTaxaExist);
    PolytomousKey key = PolytomousKey.NewInstance();
    key.addPrimaryTaxonomicSource(state.getConfig().getSourceReference(), null);
    key.addTaxonomicScope(state.getCurrentTaxon());
    state.setCurrentKey(key);
    boolean isFirstCouplet = true;
    while (reader.hasNext()) {
        XMLEvent next = readNoWhitespace(reader);
        if (isMyEndingElement(next, parentEvent)) {
            save(key, state);
            // reset state
            state.setCurrentKey(null);
            state.setOnlyNumberedTaxaExist(false);
            return;
        } else if (isEndingElement(next, KEYNOTES)) {
            popUnimplemented(next.asEndElement());
        } else if (isStartingElement(next, KEY_TITLE)) {
            handleKeyTitle(state, reader, next);
        } else if (isStartingElement(next, KEYNOTES)) {
            // TODO
            handleNotYetImplementedElement(next);
        } else if (isStartingElement(next, COUPLET)) {
            PolytomousKeyNode node = null;
            if (isFirstCouplet) {
                node = key.getRoot();
                isFirstCouplet = false;
            }
            handleCouplet(state, reader, next, node);
        } else {
            handleUnexpectedElement(next);
        }
    }
    throw new IllegalStateException("<key> has no closing tag");
}
Also used : Attribute(javax.xml.stream.events.Attribute) XMLEvent(javax.xml.stream.events.XMLEvent) PolytomousKeyNode(eu.etaxonomy.cdm.model.description.PolytomousKeyNode) PolytomousKey(eu.etaxonomy.cdm.model.description.PolytomousKey)

Example 2 with PolytomousKey

use of eu.etaxonomy.cdm.model.description.PolytomousKey in project cdmlib by cybertaxonomy.

the class DescriptiveDataSetService method generatePolytomousKey.

@Override
@Transactional(readOnly = false)
public UpdateResult generatePolytomousKey(UUID descriptiveDataSetUuid, UUID taxonUuid) {
    UpdateResult result = new UpdateResult();
    PolytomousKeyGeneratorConfigurator keyConfig = new PolytomousKeyGeneratorConfigurator();
    DescriptiveDataSet descriptiveDataSet = load(descriptiveDataSetUuid);
    keyConfig.setDataSet(descriptiveDataSet);
    PolytomousKey key = new PolytomousKeyGenerator().invoke(keyConfig);
    IdentifiableServiceConfiguratorImpl<PolytomousKey> serviceConfig = new IdentifiableServiceConfiguratorImpl<>();
    serviceConfig.setTitleSearchString(descriptiveDataSet.getTitleCache());
    List<PolytomousKey> list = polytomousKeyService.findByTitle(serviceConfig).getRecords();
    if (list != null) {
        list.forEach(polytomousKey -> polytomousKeyService.delete(polytomousKey));
    }
    key.setTitleCache(descriptiveDataSet.getTitleCache(), true);
    Taxon taxon = (Taxon) taxonService.load(taxonUuid);
    key.addTaxonomicScope(taxon);
    polytomousKeyService.saveOrUpdate(key);
    result.setCdmEntity(key);
    result.addUpdatedObject(taxon);
    return result;
}
Also used : DescriptiveDataSet(eu.etaxonomy.cdm.model.description.DescriptiveDataSet) PolytomousKeyGenerator(eu.etaxonomy.cdm.strategy.generate.PolytomousKeyGenerator) Taxon(eu.etaxonomy.cdm.model.taxon.Taxon) PolytomousKeyGeneratorConfigurator(eu.etaxonomy.cdm.strategy.generate.PolytomousKeyGeneratorConfigurator) IdentifiableServiceConfiguratorImpl(eu.etaxonomy.cdm.api.service.config.IdentifiableServiceConfiguratorImpl) PolytomousKey(eu.etaxonomy.cdm.model.description.PolytomousKey) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with PolytomousKey

use of eu.etaxonomy.cdm.model.description.PolytomousKey in project cdmlib by cybertaxonomy.

the class FullCoverageDataGenerator method createDescriptions.

private void createDescriptions(List<CdmBase> cdmBases) {
    TermVocabulary<AnnotationType> voc = TermVocabulary.NewInstance(TermType.AnnotationType, AnnotationType.class, "my termVoc desc", "myTerm voc", "mtv", URI.create("http://www.abc.de"));
    handleIdentifiableEntity(voc);
    cdmBases.add(voc);
    Representation rep = voc.getRepresentations().iterator().next();
    handleAnnotatableEntity(rep);
    // Representation engRep = Language.ENGLISH().getRepresentations().iterator().next();
    // handleAnnotatableEntity(engRep);
    // cdmBases.add(engRep);  //needed?
    // Categorical data
    State state = State.NewInstance("Test state", "state", "st.");
    state.addMedia(Media.NewInstance());
    cdmBases.add(state);
    CategoricalData categoricalData = CategoricalData.NewInstance(state, Feature.CONSERVATION());
    StateData stateData = categoricalData.getStateData().get(0);
    stateData.addModifier(DefinedTerm.SEX_FEMALE());
    handleAnnotatableEntity(categoricalData);
    State nextState = State.NewInstance();
    cdmBases.add(nextState);
    StateData stateData2 = StateData.NewInstance(nextState);
    stateData2.setCount(3);
    stateData2.putModifyingText(Language.ENGLISH(), "State2 modifying text");
    categoricalData.addStateData(stateData2);
    categoricalData.setOrderRelevant(true);
    // Quantitative data
    Feature leaveLength = Feature.NewInstance("Leave length description", "leave length", "l.l.");
    cdmBases.add(leaveLength);
    leaveLength.setSupportsQuantitativeData(true);
    QuantitativeData quantitativeData = QuantitativeData.NewInstance(leaveLength);
    MeasurementUnit measurementUnit = MeasurementUnit.NewInstance("Measurement Unit", "munit", null);
    cdmBases.add(measurementUnit);
    quantitativeData.setUnit(measurementUnit);
    quantitativeData.setUuid(UUID.fromString("920fce5e-4913-4a3f-89bf-1611f5081869"));
    StatisticalMeasurementValue statisticalMeasurementValue = quantitativeData.setAverage(new BigDecimal("22.9215"), null);
    handleAnnotatableEntity(quantitativeData);
    handleIdentifiableEntity(measurementUnit);
    DefinedTerm valueModifier = DefinedTerm.NewModifierInstance("about", "about", null);
    statisticalMeasurementValue.addModifier(valueModifier);
    cdmBases.add(valueModifier);
    // Feature
    TermVocabulary<DefinedTerm> recommendedModifierEnumeration = TermVocabulary.NewInstance(TermType.Modifier, DefinedTerm.class);
    leaveLength.addRecommendedModifierEnumeration(recommendedModifierEnumeration);
    cdmBases.add(recommendedModifierEnumeration);
    TermVocabulary<State> supportedCategoricalEnumeration = TermVocabulary.NewInstance(TermType.State, State.class);
    leaveLength.addSupportedCategoricalEnumeration(supportedCategoricalEnumeration);
    cdmBases.add(supportedCategoricalEnumeration);
    leaveLength.addRecommendedMeasurementUnit(measurementUnit);
    leaveLength.addRecommendedStatisticalMeasure(StatisticalMeasure.AVERAGE());
    // CommonTaxonName
    CommonTaxonName commonTaxonName = CommonTaxonName.NewInstance("common name", Language.ENGLISH(), Country.UNITEDSTATESOFAMERICA());
    handleAnnotatableEntity(commonTaxonName);
    // TextData
    TextData textData = TextData.NewInstance(Feature.DIAGNOSIS());
    Language eng = Language.ENGLISH();
    textData.putText(eng, "My text data");
    LanguageString languageString = textData.getLanguageText(eng);
    Taxon referencedTaxon = getTaxon();
    cdmBases.add(referencedTaxon);
    languageString.addIntextReference(IntextReference.NewInstance(referencedTaxon, languageString, 2, 5));
    textData.putModifyingText(eng, "nice diagnosis");
    handleAnnotatableEntity(textData);
    handleAnnotatableEntity(languageString);
    TextFormat format = TextFormat.NewInstance("format", "format", null);
    textData.setFormat(format);
    cdmBases.add(format);
    handleAnnotatableEntity(format);
    // IndividualsAssociation
    DerivedUnit specimen = DerivedUnit.NewInstance(SpecimenOrObservationType.PreservedSpecimen);
    IndividualsAssociation indAssoc = IndividualsAssociation.NewInstance(specimen);
    indAssoc.putDescription(Language.ENGLISH(), "description for individuals association");
    handleAnnotatableEntity(indAssoc);
    // TaxonInteraction
    TaxonInteraction taxonInteraction = TaxonInteraction.NewInstance(Feature.HOSTPLANT());
    taxonInteraction.putDescription(Language.ENGLISH(), "interaction description");
    handleAnnotatableEntity(taxonInteraction);
    // Distribution
    NamedArea inCountryArea = NamedArea.NewInstance("My area in a country", "my area", "ma");
    inCountryArea.addCountry(Country.TURKEYREPUBLICOF());
    cdmBases.add(inCountryArea);
    Distribution distribution = Distribution.NewInstance(inCountryArea, PresenceAbsenceTerm.CULTIVATED());
    handleAnnotatableEntity(distribution);
    // TemporalData
    Feature floweringSeason = Feature.FLOWERING_PERIOD();
    TemporalData temporalData = TemporalData.NewInstance(ExtendedTimePeriod.NewExtendedMonthInstance(5, 8, 4, 9));
    temporalData.setFeature(floweringSeason);
    temporalData.getPeriod().setFreeText("My temporal text");
    handleAnnotatableEntity(temporalData);
    temporalData.setUuid(UUID.fromString("9a1c91c0-fc58-4310-94cb-8c26115985d3"));
    Taxon taxon = getTaxon();
    TaxonDescription taxonDescription = TaxonDescription.NewInstance(taxon);
    taxonDescription.addElements(categoricalData, quantitativeData, textData, commonTaxonName, taxonInteraction, indAssoc, distribution, temporalData);
    DerivedUnit describedSpecimenOrObservation = DerivedUnit.NewInstance(SpecimenOrObservationType.DerivedUnit);
    taxonDescription.setDescribedSpecimenOrObservation(describedSpecimenOrObservation);
    taxonDescription.addScope(DefinedTerm.SEX_FEMALE());
    taxonDescription.addGeoScope(Country.GERMANY());
    handleIdentifiableEntity(taxonDescription);
    taxon.addAggregationSource(taxonDescription);
    cdmBases.add(taxon);
    // DescriptionElmenetBase  + source
    textData.addMedia(Media.NewInstance());
    textData.addModifier(DefinedTerm.SEX_HERMAPHRODITE());
    textData.putModifyingText(Language.ENGLISH(), "no modification");
    textData.setTimeperiod(TimePeriodParser.parseString("1970-1980"));
    Reference ref = ReferenceFactory.newArticle();
    DescriptionElementSource source = textData.addSource(OriginalSourceType.Import, "22", "taxon description table", ref, "detail");
    source.setNameUsedInSource(TaxonNameFactory.NewBotanicalInstance(Rank.GENUS()));
    ExternalLink link = ExternalLink.NewInstance(ExternalLinkType.WebSite, URI.create("http://wwww.abd.de"), "Somehow useful link", 445);
    source.addLink(link);
    handleAnnotatableEntity(source);
    // as long as it still exists
    taxonDescription.addDescriptionSource(ref);
    // Specimen description
    SpecimenOrObservationBase<?> describedSpecimen = getSpecimen();
    SpecimenDescription specDesc = SpecimenDescription.NewInstance(specimen);
    cdmBases.add(describedSpecimen);
    handleAnnotatableEntity(specDesc);
    // Name description
    TaxonName name = TaxonNameFactory.NewBotanicalInstance(Rank.GENUS());
    TaxonNameDescription nameDesc = TaxonNameDescription.NewInstance(name);
    cdmBases.add(name);
    handleAnnotatableEntity(nameDesc);
    // Feature Tree
    TermTree<Feature> featureTree = TermTree.NewFeatureInstance();
    // featureTree
    TermNode<Feature> descriptionTermNode = featureTree.getRoot().addChild(Feature.DESCRIPTION());
    TermNode<Feature> leaveLengthNode = descriptionTermNode.addChild(leaveLength);
    handleIdentifiableEntity(featureTree);
    State inapplicableState = State.NewInstance("inapplicableState", "inapplicableState", null);
    State applicableState = State.NewInstance("only applicable state", "only applicable state", null);
    cdmBases.add(applicableState);
    cdmBases.add(inapplicableState);
    // this is semantically not correct, should be a parent feature
    leaveLengthNode.addInapplicableState(leaveLength, inapplicableState);
    leaveLengthNode.addApplicableState(leaveLength, applicableState);
    cdmBases.add(featureTree);
    cdmBases.add(leaveLengthNode);
    // DescriptiveDataSet
    DescriptiveDataSet descriptiveDataSet = DescriptiveDataSet.NewInstance();
    descriptiveDataSet.addDescription(taxonDescription);
    descriptiveDataSet.setLabel("My Descriptive Dataset");
    descriptiveDataSet.getDescriptiveSystem();
    handleAnnotatableEntity(descriptiveDataSet);
    descriptiveDataSet.addGeoFilterArea(Country.GERMANY());
    Classification classification = Classification.NewInstance("DescriptiveDataSet subtree classification");
    Taxon subTreeTaxon = getTaxon();
    TaxonNode subtree = classification.addChildTaxon(subTreeTaxon, null, null);
    descriptiveDataSet.addTaxonSubtree(subtree);
    cdmBases.add(classification);
    cdmBases.add(subtree);
    // polytomous keys
    Taxon coveredTaxon = Taxon.NewInstance(name, null);
    PolytomousKey key = PolytomousKey.NewTitledInstance("My Polykey");
    handleIdentificationKey(key, taxon, coveredTaxon);
    key.setStartNumber(10);
    PolytomousKeyNode firstChildNode = PolytomousKeyNode.NewInstance("Green", "What is the leave length?", coveredTaxon, leaveLength);
    key.getRoot().addChild(firstChildNode);
    PolytomousKeyNode secondChildNode = PolytomousKeyNode.NewInstance("234");
    firstChildNode.addChild(secondChildNode);
    PolytomousKey subkey = PolytomousKey.NewTitledInstance("Sub-key");
    firstChildNode.setSubkey(subkey);
    PolytomousKeyNode subKeyNode = PolytomousKeyNode.NewInstance("sub key couplet");
    subkey.getRoot().addChild(subKeyNode);
    secondChildNode.setOtherNode(subKeyNode);
    secondChildNode.putModifyingText(Language.GERMAN(), "manchmal");
    cdmBases.add(key);
    cdmBases.add(subkey);
    MediaKey mediaKey = MediaKey.NewInstance();
    mediaKey.addKeyRepresentation(Representation.NewInstance("Media Key Representation", "media key", null, Language.ENGLISH()));
    handleIdentificationKey(mediaKey, taxon, coveredTaxon);
    MultiAccessKey multiAccessKey = MultiAccessKey.NewInstance();
    handleIdentificationKey(multiAccessKey, taxon, coveredTaxon);
    cdmBases.add(mediaKey);
    cdmBases.add(multiAccessKey);
}
Also used : TaxonNode(eu.etaxonomy.cdm.model.taxon.TaxonNode) TaxonDescription(eu.etaxonomy.cdm.model.description.TaxonDescription) QuantitativeData(eu.etaxonomy.cdm.model.description.QuantitativeData) Feature(eu.etaxonomy.cdm.model.description.Feature) AnnotationType(eu.etaxonomy.cdm.model.common.AnnotationType) DerivedUnit(eu.etaxonomy.cdm.model.occurrence.DerivedUnit) MediaKey(eu.etaxonomy.cdm.model.description.MediaKey) Language(eu.etaxonomy.cdm.model.common.Language) LanguageString(eu.etaxonomy.cdm.model.common.LanguageString) TextData(eu.etaxonomy.cdm.model.description.TextData) Classification(eu.etaxonomy.cdm.model.taxon.Classification) TextFormat(eu.etaxonomy.cdm.model.description.TextFormat) CommonTaxonName(eu.etaxonomy.cdm.model.description.CommonTaxonName) TaxonName(eu.etaxonomy.cdm.model.name.TaxonName) StatisticalMeasurementValue(eu.etaxonomy.cdm.model.description.StatisticalMeasurementValue) PolytomousKey(eu.etaxonomy.cdm.model.description.PolytomousKey) MeasurementUnit(eu.etaxonomy.cdm.model.description.MeasurementUnit) CommonTaxonName(eu.etaxonomy.cdm.model.description.CommonTaxonName) SpecimenDescription(eu.etaxonomy.cdm.model.description.SpecimenDescription) TaxonNameDescription(eu.etaxonomy.cdm.model.description.TaxonNameDescription) Reference(eu.etaxonomy.cdm.model.reference.Reference) IntextReference(eu.etaxonomy.cdm.model.common.IntextReference) Taxon(eu.etaxonomy.cdm.model.taxon.Taxon) TaxonInteraction(eu.etaxonomy.cdm.model.description.TaxonInteraction) MultiAccessKey(eu.etaxonomy.cdm.model.description.MultiAccessKey) Representation(eu.etaxonomy.cdm.model.term.Representation) MediaRepresentation(eu.etaxonomy.cdm.model.media.MediaRepresentation) NamedArea(eu.etaxonomy.cdm.model.location.NamedArea) StateData(eu.etaxonomy.cdm.model.description.StateData) BigDecimal(java.math.BigDecimal) ExternalLink(eu.etaxonomy.cdm.model.media.ExternalLink) DescriptiveDataSet(eu.etaxonomy.cdm.model.description.DescriptiveDataSet) State(eu.etaxonomy.cdm.model.description.State) IndividualsAssociation(eu.etaxonomy.cdm.model.description.IndividualsAssociation) CategoricalData(eu.etaxonomy.cdm.model.description.CategoricalData) Distribution(eu.etaxonomy.cdm.model.description.Distribution) TemporalData(eu.etaxonomy.cdm.model.description.TemporalData) DescriptionElementSource(eu.etaxonomy.cdm.model.description.DescriptionElementSource) PolytomousKeyNode(eu.etaxonomy.cdm.model.description.PolytomousKeyNode) DefinedTerm(eu.etaxonomy.cdm.model.term.DefinedTerm)

Example 4 with PolytomousKey

use of eu.etaxonomy.cdm.model.description.PolytomousKey in project cdmlib by cybertaxonomy.

the class PolytomousKeyNodeServiceTest method testDelete.

@Test
public final // @DataSet(value="CommonServiceImplTest.xml")
void testDelete() {
    PolytomousKey key = PolytomousKey.NewTitledInstance("TestPolytomousKey");
    UUID uuidKey = keyService.save(key).getUuid();
    PolytomousKeyNode node = PolytomousKeyNode.NewInstance("Test statement");
    key.setRoot(node);
    key.setStartNumber(0);
    PolytomousKeyNode child = PolytomousKeyNode.NewInstance("Test statement Nr 2");
    // child.setKey(key);
    node.addChild(child, 0);
    UUID uuidNode = service.save(node).getUuid();
    PolytomousKeyNode child1 = PolytomousKeyNode.NewInstance("Test statement Nr 3");
    // child.setKey(key);
    child.addChild(child1, 0);
    UUID uuidChild = service.save(child).getUuid();
    PolytomousKeyNode child2 = PolytomousKeyNode.NewInstance("Test statement Nr 4");
    // child.setKey(key);
    child1.addChild(child2, 0);
    UUID uuidChild1 = service.save(child1).getUuid();
    node = service.load(uuidChild1);
    UUID uuidChild2 = node.getChildAt(0).getUuid();
    assertNotNull(node);
    service.delete(uuidChild1, false);
    node = service.load(uuidChild1);
    assertNull(node);
    node = service.load(uuidChild2);
    assertNotNull(node);
    node = service.load(uuidChild);
    assertNotNull(node);
    service.delete(uuidChild, true);
    node = service.load(uuidChild);
    assertNull(node);
    node = service.load(uuidChild2);
    assertNull(node);
}
Also used : PolytomousKeyNode(eu.etaxonomy.cdm.model.description.PolytomousKeyNode) UUID(java.util.UUID) PolytomousKey(eu.etaxonomy.cdm.model.description.PolytomousKey) CdmIntegrationTest(eu.etaxonomy.cdm.test.integration.CdmIntegrationTest) Test(org.junit.Test)

Example 5 with PolytomousKey

use of eu.etaxonomy.cdm.model.description.PolytomousKey in project cdmlib by cybertaxonomy.

the class TaxonNodeServiceImplTest method testMakeTaxonNodeAHeterotypicSynonymOfAnotherTaxonNode.

/**
 * Test method for {@link eu.etaxonomy.cdm.api.service.TaxonNodeServiceImpl#makeTaxonNodeASynonymOfAnotherTaxonNode(eu.etaxonomy.cdm.model.taxon.TaxonNode, eu.etaxonomy.cdm.model.taxon.TaxonNode, eu.etaxonomy.cdm.model.taxon.SynonymType, eu.etaxonomy.cdm.model.reference.Reference, java.lang.String)}.
 */
@Test
@DataSet(loadStrategy = CleanSweepInsertLoadStrategy.class)
public final void testMakeTaxonNodeAHeterotypicSynonymOfAnotherTaxonNode() {
    // create data
    classification = classificationService.load(classificationUuid);
    node1 = taxonNodeService.load(node1Uuid);
    node2 = taxonNodeService.load(node2Uuid);
    reference = referenceService.load(referenceUuid);
    synonymType = CdmBase.deproxy(termService.load(SynonymType.uuidHeterotypicSynonymOf), SynonymType.class);
    referenceDetail = "test";
    // descriptions
    t1 = node1.getTaxon();
    PolytomousKey polKey = PolytomousKey.NewInstance();
    PolytomousKeyNode keyNode = PolytomousKeyNode.NewInstance("", "", t1, null);
    keyNode.setKey(polKey);
    polKeyNodeService.save(keyNode);
    polKeyService.save(polKey);
    // nameRelations
    TaxonName relatedName = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
    t1.getName().addRelationshipFromName(relatedName, NameRelationshipType.ALTERNATIVE_NAME(), null, null);
    TaxonName name1 = t1.getName();
    UUID name1UUID = name1.getUuid();
    // taxonRelations
    Taxon relatedTaxon = Taxon.NewInstance(TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES()), null);
    t1.addTaxonRelation(relatedTaxon, TaxonRelationshipType.CONGRUENT_OR_EXCLUDES(), null, null);
    Synonym t1HomotypSynonym = Synonym.NewInstance(TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES()), null);
    t1.addHomotypicSynonym(t1HomotypSynonym);
    TaxonName nameT1 = t1.getName();
    t2 = node2.getTaxon();
    assertEquals("taxon 1 must have 2 descriptions", 2, t1.getDescriptions().size());
    assertEquals("taxon 1 must have 2 synonyms", 2, t1.getSynonyms().size());
    Assert.assertTrue("taxon 2 must have no synonyms", t2.getSynonyms().isEmpty());
    Assert.assertTrue("taxon 2 must have no descriptions", t2.getDescriptions().size() == 0);
    // save
    taxonService.save(t1HomotypSynonym);
    taxonService.save(relatedTaxon);
    nameService.save(relatedName);
    // do it
    DeleteResult result = taxonNodeService.makeTaxonNodeASynonymOfAnotherTaxonNode(node1, node2, synonymType, reference, referenceDetail, null, true);
    // post conditions
    if (!result.getUpdatedObjects().iterator().hasNext()) {
        Assert.fail("Some updates must have taken place");
    }
    assertEquals(3, result.getUpdatedObjects().size());
    assertNotNull("Old taxon should not have been deleted as it is referenced by key node", taxonService.find(t1Uuid));
    assertNull("Old taxon node should not exist anymore", taxonNodeService.find(node1Uuid));
    t1HomotypSynonym = (Synonym) taxonService.find(t1HomotypSynonym.getUuid());
    assertNotNull(t1HomotypSynonym);
    keyNode.setTaxon(null);
    polKeyNodeService.saveOrUpdate(keyNode);
    t2 = HibernateProxyHelper.deproxy(t2);
    HibernateProxyHelper.deproxy(t2.getHomotypicGroup());
    t2.setName(HibernateProxyHelper.deproxy(t2.getName()));
    termService.saveOrUpdate(synonymType);
    assertFalse("taxon 2 must have a synonym now", t2.getSynonyms().isEmpty());
    assertEquals("taxon 2 must have 3 synonyms now, the old taxon 1 and it's 2 synonyms", 3, t2.getSynonyms().size());
    assertEquals("taxon 2 must have 2 descriptions now, taken form taxon 1", 2, t2.getDescriptions().size());
    result = taxonService.deleteTaxon(t1.getUuid(), null, null);
    if (result.isAbort() || result.isError()) {
        Assert.fail();
    }
    assertNull(taxonService.find(t1Uuid));
    assertNull(taxonNodeService.find(node1Uuid));
    name1 = nameService.find(name1UUID);
    assertNotNull("taxon name 1 should still exist", name1);
    assertEquals("... but being used for the new synonym only as taxon 1 is deleted", 1, name1.getTaxonBases().size());
    t1HomotypSynonym = (Synonym) taxonService.find(t1HomotypSynonym.getUuid());
    assertNotNull(t1HomotypSynonym);
    Synonym newSynonym = (Synonym) name1.getTaxonBases().iterator().next();
    Taxon newAcceptedTaxon = CdmBase.deproxy(taxonService.find(t2.getUuid()), Taxon.class);
    assertEquals("The new synonym (old accepted taxon) and it's homotypic synonym should still be homotypic", newSynonym.getHomotypicGroup(), t1HomotypSynonym.getName().getHomotypicalGroup());
    assertFalse("The new accepted taxon must not be homotypic to ", newAcceptedTaxon.getHomotypicGroup().equals(newSynonym.getName().getHomotypicalGroup()));
    assertEquals("The new accepted taxon is taxon 2", newAcceptedTaxon, t2);
    assertEquals("The new synonyms name must be the same as the old accepted taxon's name", newSynonym.getName(), nameT1);
}
Also used : SynonymType(eu.etaxonomy.cdm.model.taxon.SynonymType) Taxon(eu.etaxonomy.cdm.model.taxon.Taxon) PolytomousKeyNode(eu.etaxonomy.cdm.model.description.PolytomousKeyNode) TaxonName(eu.etaxonomy.cdm.model.name.TaxonName) Synonym(eu.etaxonomy.cdm.model.taxon.Synonym) UUID(java.util.UUID) PolytomousKey(eu.etaxonomy.cdm.model.description.PolytomousKey) CdmTransactionalIntegrationTest(eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest) Test(org.junit.Test) DataSet(org.unitils.dbunit.annotation.DataSet)

Aggregations

PolytomousKey (eu.etaxonomy.cdm.model.description.PolytomousKey)33 PolytomousKeyNode (eu.etaxonomy.cdm.model.description.PolytomousKeyNode)23 Test (org.junit.Test)14 Taxon (eu.etaxonomy.cdm.model.taxon.Taxon)7 CdmTransactionalIntegrationTest (eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest)7 UUID (java.util.UUID)7 ArrayList (java.util.ArrayList)6 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 LanguageString (eu.etaxonomy.cdm.model.common.LanguageString)3 TaxonName (eu.etaxonomy.cdm.model.name.TaxonName)3 TaxonNode (eu.etaxonomy.cdm.model.taxon.TaxonNode)3 DataSet (org.unitils.dbunit.annotation.DataSet)3 CdmBase (eu.etaxonomy.cdm.model.common.CdmBase)2 DescriptiveDataSet (eu.etaxonomy.cdm.model.description.DescriptiveDataSet)2 Feature (eu.etaxonomy.cdm.model.description.Feature)2 TaxonDescription (eu.etaxonomy.cdm.model.description.TaxonDescription)2 LinkedPolytomousKeyNodeRowDto (eu.etaxonomy.cdm.remote.dto.polytomouskey.LinkedPolytomousKeyNodeRowDto)2 ModelAndView (org.springframework.web.servlet.ModelAndView)2 IdentifiableServiceConfiguratorImpl (eu.etaxonomy.cdm.api.service.config.IdentifiableServiceConfiguratorImpl)1 ReferencedObjectUndeletableException (eu.etaxonomy.cdm.api.service.exception.ReferencedObjectUndeletableException)1