Search in sources :

Example 21 with PolytomousKey

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

the class PolytomousKeyNodeServiceImpl method delete.

@Override
public DeleteResult delete(UUID nodeUUID, boolean deleteChildren) {
    DeleteResult result = new DeleteResult();
    PolytomousKeyNode node = dao.findByUuid(nodeUUID);
    node = HibernateProxyHelper.deproxy(node);
    if (node == null) {
        // result.addException(new Exception("The polytomouskey node was already deleted."));;
        return result;
    }
    List<PolytomousKeyNode> children = new ArrayList<PolytomousKeyNode>();
    node.removeNullValueFromChildren();
    for (PolytomousKeyNode child : node.getChildren()) {
        children.add(child);
    }
    PolytomousKeyNode parent = node.getParent();
    parent = HibernateProxyHelper.deproxy(parent, PolytomousKeyNode.class);
    PolytomousKey key = null;
    if (parent == null) {
        key = node.getKey();
        key = HibernateProxyHelper.deproxy(key, PolytomousKey.class);
    }
    if (!deleteChildren) {
        for (PolytomousKeyNode child : children) {
            if (!child.equals(node)) {
                parent.addChild(child);
                dao.saveOrUpdate(child);
                result.addUpdatedObject(child);
            }
        }
        dao.saveOrUpdate(node);
        result.addUpdatedObject(node);
    }
    if (parent != null) {
        if (parent.getChildren().contains(null)) {
            List<PolytomousKeyNode> parentChildren = parent.getChildren();
            HHH_9751_Util.removeAllNull(parentChildren);
        }
        parent.removeChild(node);
        dao.saveOrUpdate(parent);
    }
    if (node.getKey() != null && key != null) {
        key.setRoot(null);
    }
    if (node.getTaxon() != null) {
        node.removeTaxon();
    }
    if (dao.delete(node) == null) {
        result.setAbort();
    } else {
        result.addDeletedObject(node);
    }
    if (parent != null) {
        dao.saveOrUpdate(parent);
        result.addUpdatedObject(parent);
    } else {
        keyDao.saveOrUpdate(key);
        result.addUpdatedObject(key);
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) PolytomousKeyNode(eu.etaxonomy.cdm.model.description.PolytomousKeyNode) PolytomousKey(eu.etaxonomy.cdm.model.description.PolytomousKey)

Example 22 with PolytomousKey

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

the class PolytomousKeyServiceImplTest method testCount.

// ************************* TESTS ********************************************/
/**
 * Test method for {@link eu.etaxonomy.cdm.api.service.ServiceBase#count(java.lang.Class)}.
 */
@Test
public void testCount() {
    PolytomousKey key = PolytomousKey.NewTitledInstance("My test key");
    service.save(key);
    Taxon taxon = Taxon.NewInstance(null, null);
    key.addTaxonomicScope(taxon);
    // Annotation annotation = Annotation.NewInstance("Any annotation", Language.DEFAULT());
    // key.addAnnotation(annotation);
    PolytomousKeyNode child = PolytomousKeyNode.NewInstance();
    Taxon taxon2 = Taxon.NewInstance(null, null);
    child.setTaxon(taxon2);
    key.getRoot().addChild(child);
    service.save(key);
    setComplete();
    endTransaction();
    System.out.println("Count");
    printDataSet(System.out, new String[] { "PolytomousKey", "POLYTOMOUSKEYNODE", "POLYTOMOUSKEYNODE_LANGUAGESTRING", "POLYTOMOUSKEY_ANNOTATION", "POLYTOMOUSKEY_CREDIT", "POLYTOMOUSKEY_EXTENSION", "POLYTOMOUSKEY_MARKER", "POLYTOMOUSKEY_NAMEDAREA", "POLYTOMOUSKEY_ORIGINALSOURCEBASE", "POLYTOMOUSKEY_RIGHTS", "POLYTOMOUSKEY_SCOPE", "POLYTOMOUSKEY_TAXON", "POLYTOMOUSKEY_TAXONBASE", "ANNOTATION", "TAXONBASE" });
// printDataSet(System.out);
}
Also used : Taxon(eu.etaxonomy.cdm.model.taxon.Taxon) PolytomousKeyNode(eu.etaxonomy.cdm.model.description.PolytomousKeyNode) PolytomousKey(eu.etaxonomy.cdm.model.description.PolytomousKey) CdmTransactionalIntegrationTest(eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest) Test(org.junit.Test)

Example 23 with PolytomousKey

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

the class PolytomousKeyServiceImplTest method testDelete.

/**
 * Test method for {@link eu.etaxonomy.cdm.api.service.ServiceBase#delete(eu.etaxonomy.cdm.model.common.CdmBase)}.
 */
@Test
@DataSet
public void testDelete() {
    System.out.println("Delete start");
    printDataSet(System.out, new String[] { "PolytomousKey", "POLYTOMOUSKEYNODE", "POLYTOMOUSKEYNODE_LANGUAGESTRING", "POLYTOMOUSKEY_ANNOTATION", "POLYTOMOUSKEY_CREDIT", "POLYTOMOUSKEY_EXTENSION", "POLYTOMOUSKEY_MARKER", "POLYTOMOUSKEY_NAMEDAREA", "POLYTOMOUSKEY_ORIGINALSOURCEBASE", "POLYTOMOUSKEY_RIGHTS", "POLYTOMOUSKEY_SCOPE", "POLYTOMOUSKEY_TAXON", "POLYTOMOUSKEY_TAXONBASE", "ANNOTATION", "TAXONBASE" });
    UUID uuid = UUID.fromString("0a709940-4f2e-43c1-8db1-f4745f2a4889");
    PolytomousKey key = service.find(uuid);
    PolytomousKeyNode someChild = key.getRoot().getChildren().iterator().next();
    // service.delete(key);
    key.getRoot().removeChild(someChild);
    nodeService.delete(someChild);
    setComplete();
    endTransaction();
    System.out.println("Delete End");
    printDataSet(System.out, new String[] { "PolytomousKey", "POLYTOMOUSKEYNODE", "POLYTOMOUSKEYNODE_LANGUAGESTRING", "POLYTOMOUSKEY_ANNOTATION", "POLYTOMOUSKEY_CREDIT", "POLYTOMOUSKEY_EXTENSION", "POLYTOMOUSKEY_MARKER", "POLYTOMOUSKEY_NAMEDAREA", "POLYTOMOUSKEY_ORIGINALSOURCEBASE", "POLYTOMOUSKEY_RIGHTS", "POLYTOMOUSKEY_SCOPE", "POLYTOMOUSKEY_TAXON", "POLYTOMOUSKEY_TAXONBASE" });
}
Also used : PolytomousKeyNode(eu.etaxonomy.cdm.model.description.PolytomousKeyNode) 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)

Example 24 with PolytomousKey

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

the class PolytomousKeyGeneratorTest method testDependencyScore.

@Test
public void testDependencyScore() {
    generator = new PolytomousKeyGenerator();
    // new PolytomousKeyGeneratorConfigurator();
    PolytomousKeyGeneratorConfigurator configurator = createDefaultConfig();
    // remove shape feature
    configurator.getDataSet().getDescriptiveSystem().getRoot().removeChild(0);
    configurator.setMerge(true);
    configurator.setUseDependencies(true);
    PolytomousKey result = generator.invoke(configurator);
    result.setTitleCache("Test Dependency Score Key", true);
    if (debug) {
        result.print(System.out);
    }
    // Assertions
    assertNotNull("Key should exist.", result);
    PolytomousKeyNode root = result.getRoot();
    Assert.assertEquals("Root feature should be 'presence' as it inherits score from 'length of wings'", featurePresence, root.getFeature());
// ...otherwise it would be color, both have a score of 12.0 but presence comes first in list
}
Also used : PolytomousKeyNode(eu.etaxonomy.cdm.model.description.PolytomousKeyNode) PolytomousKey(eu.etaxonomy.cdm.model.description.PolytomousKey) Test(org.junit.Test)

Example 25 with PolytomousKey

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

the class PolytomousKeyGeneratorTest method testTaxonomicHierarchy.

@Test
public void testTaxonomicHierarchy() {
    tdGenus.getElements().clear();
    tdGenus.addElements(mergeTaxDescriptions(td1, td2, td3, td4));
    TaxonNode genus1Node = classification.getRootNode().getChildNodes().iterator().next();
    removeTaxon5_8(genus1Node);
    UUID uuidTdGenus2 = UUID.fromString("3eed217a-fd40-4a38-997f-1f4360133d0d");
    Taxon taxonGenus2 = getTaxon(10);
    TaxonDescription tdGenus2 = createTaxonDescription(taxonGenus2, "tdGenus2", uuidTdGenus2);
    taxa.add(tdGenus2);
    TaxonNode genus2Node = classification.getRootNode().addChildTaxon(taxonGenus2, null, null);
    genus2Node.addChildTaxon(taxon5, null, null);
    genus2Node.addChildTaxon(taxon6, null, null);
    genus2Node.addChildTaxon(taxon7, null, null);
    genus2Node.addChildTaxon(taxon8, null, null);
    tdGenus2.addElements(mergeTaxDescriptions(td5, td6, td7, td8));
    PolytomousKeyGeneratorConfigurator configurator = createDefaultConfig();
    PolytomousKey result = generator.invoke(configurator);
    result.setTitleCache("Merge Key", true);
    assertNotNull("Key should exist (merge mode ON).", result);
    if (debug) {
        result.print(System.out);
    }
    // Assertions
    assertNotNull("Key should exist.", result);
    PolytomousKeyNode root = result.getRoot();
    Assert.assertEquals(featureShape, root.getFeature());
    Assert.assertNull(root.getTaxon());
    // triangular or oval
    PolytomousKeyNode triangularNode = root.getChildAt(0);
    assertInnerNodeWithTaxon(triangularNode, "Oval or Triangular", featureLength, taxonGenus);
    // <3
    PolytomousKeyNode lessNode = triangularNode.getChildAt(0);
    assertInnerNode(lessNode, LESS_3, featureColour);
    // blue
    assertSingleTaxon(lessNode.getChildAt(0), taxon1, blue);
    // yellow
    assertSingleTaxon(lessNode.getChildAt(1), taxon2, yellow);
    // >3
    PolytomousKeyNode gtNode = triangularNode.getChildAt(1);
    assertInnerNode(gtNode, GT_3, featureColour);
    // blue
    assertSingleTaxon(gtNode.getChildAt(0), taxon3, blue);
    // yellow
    assertSingleTaxon(gtNode.getChildAt(1), taxon4, yellow);
    // circular
    PolytomousKeyNode circularNode = root.getChildAt(1);
    assertInnerNodeWithTaxon(circularNode, circular, featurePresence, taxonGenus2);
    // yes
    PolytomousKeyNode yesNode = circularNode.getChildAt(0);
    assertInnerNode(yesNode, yes, featureLength);
    // <3
    assertIsTaxonList(yesNode.getChildAt(0), LESS_3, taxon5, taxon6);
    // >3
    assertSingleTaxon(yesNode.getChildAt(1), taxon7, GT_3);
    // no
    assertSingleTaxon(circularNode.getChildAt(1), taxon8, no);
}
Also used : TaxonNode(eu.etaxonomy.cdm.model.taxon.TaxonNode) Taxon(eu.etaxonomy.cdm.model.taxon.Taxon) TaxonDescription(eu.etaxonomy.cdm.model.description.TaxonDescription) PolytomousKeyNode(eu.etaxonomy.cdm.model.description.PolytomousKeyNode) UUID(java.util.UUID) PolytomousKey(eu.etaxonomy.cdm.model.description.PolytomousKey) Test(org.junit.Test)

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