Search in sources :

Example 6 with PolytomousKey

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

the class PolytomousKeyDaoImpl method delete.

@Override
public UUID delete(PolytomousKey key) {
    key = this.load(key.getUuid());
    key = HibernateProxyHelper.deproxy(key, PolytomousKey.class);
    if (key.getRoot() != null) {
        PolytomousKeyNode root = HibernateProxyHelper.deproxy(key.getRoot(), PolytomousKeyNode.class);
        key.setRoot(null);
        nodeDao.delete(root);
    }
    getSession().delete(key);
    return key.getUuid();
}
Also used : PolytomousKeyNode(eu.etaxonomy.cdm.model.description.PolytomousKeyNode) PolytomousKey(eu.etaxonomy.cdm.model.description.PolytomousKey)

Example 7 with PolytomousKey

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

the class IkeyPlusImportTest method testDoInvoke.

@Test
@DataSets({ @DataSet(/*loadStrategy=CleanSweepInsertLoadStrategy.class,*/
value = "/eu/etaxonomy/cdm/database/ClearDB_with_Terms_DataSet.xml"), @DataSet(value = "/eu/etaxonomy/cdm/database/TermsDataSet-with_auditing_info.xml") })
public void testDoInvoke() {
    UUID newKeyUuid = null;
    try {
        ikeyPlusImport.getKey(sddUri, null);
        newKeyUuid = ikeyPlusImport.getCdmKey().getUuid();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    commitAndStartNewTransaction(null);
    PolytomousKey pk = polytomousKeyService.find(newKeyUuid);
    Assert.assertNotNull(pk);
// assertEquals("Number of TaxonNames should be 1", 1, nameService.count(null));
}
Also used : UUID(java.util.UUID) URISyntaxException(java.net.URISyntaxException) FileNotFoundException(java.io.FileNotFoundException) PolytomousKey(eu.etaxonomy.cdm.model.description.PolytomousKey) CdmTransactionalIntegrationTest(eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest) Test(org.junit.Test) DataSets(org.unitils.dbunit.annotation.DataSets)

Example 8 with PolytomousKey

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

the class PolytomousKeyGeneratorTest method testInvokeWithoutDependencies.

/**
 * With dependencies is difficult to check because it only changes the performance
 * if data is clean. So in this test we first check some dirty data with
 * dependency check and then without.
 * In the first run it correctly removes the length of wings check at the end
 * as length of wings is not applicable if presence of wings = no.
 * In the second run it does the length of wings check as it does not
 * use dependency check.
 */
@Test
public void testInvokeWithoutDependencies() {
    generator = new PolytomousKeyGenerator();
    PolytomousKeyGeneratorConfigurator configurator = createDefaultConfig();
    configurator.setMerge(true);
    configurator.setUseDependencies(true);
    catd27.getStateData().get(0).setState(no);
    td8.addElement(qtd38);
    PolytomousKey result = generator.invoke(configurator);
    result.setTitleCache("Merge Key with dependency", true);
    assertNotNull("Key should exist (dependency on)", result);
    if (debug) {
        result.print(System.out);
    }
    // Assertions
    assertNotNull("Key should exist.", result);
    PolytomousKeyNode root = result.getRoot();
    Assert.assertEquals(featureShape, root.getFeature());
    // circular
    PolytomousKeyNode circularNode = root.getChildAt(1);
    assertInnerNode(circularNode, circular, featurePresence);
    // no
    assertIsTaxonList(circularNode.getChildAt(0), no, taxon8, taxon7);
    // yes
    assertIsTaxonList(circularNode.getChildAt(1), yes, taxon5, taxon6);
    // and now without dependency check
    configurator.setUseDependencies(false);
    result = generator.invoke(configurator);
    result.setTitleCache("Merge Key without dependency", true);
    assertNotNull("Key should exist (dependency off)", result);
    if (debug) {
        result.print(System.out);
    }
    // Assertions
    assertNotNull("Key should exist.", result);
    root = result.getRoot();
    Assert.assertEquals(featureShape, root.getFeature());
    // circular
    circularNode = root.getChildAt(1);
    assertInnerNode(circularNode, circular, featurePresence);
    // no
    PolytomousKeyNode noNode = assertInnerNode(circularNode.getChildAt(0), no, featureLength);
    // as dependency check is switched off we distinguish length, though length should be inapplicable here
    assertSingleTaxon(noNode.getChildAt(0), taxon8, LESS_3);
    assertSingleTaxon(noNode.getChildAt(1), taxon7, GT_3);
    // yes
    assertIsTaxonList(circularNode.getChildAt(1), yes, taxon5, taxon6);
}
Also used : PolytomousKeyNode(eu.etaxonomy.cdm.model.description.PolytomousKeyNode) PolytomousKey(eu.etaxonomy.cdm.model.description.PolytomousKey) Test(org.junit.Test)

Example 9 with PolytomousKey

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

the class PolytomousKeyGeneratorTest method testInvokeMergeModeOff.

// *************************** TESTS *********************** /
@Test
public void testInvokeMergeModeOff() {
    PolytomousKeyGeneratorConfigurator configurator = createDefaultConfig();
    configurator.setMerge(false);
    PolytomousKey result = generator.invoke(configurator);
    result.setTitleCache("No Merge Key", true);
    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());
    // circular
    PolytomousKeyNode circularNode = root.getChildAt(0);
    assertInnerNode(circularNode, circular, featurePresence);
    // yes
    PolytomousKeyNode yesNode = circularNode.getChildAt(0);
    assertInnerNode(yesNode, yes, featureLength);
    // <3
    PolytomousKeyNode less3Node = yesNode.getChildAt(0);
    assertIsTaxonList(less3Node, LESS_3, taxon5, taxon6);
    // >3
    assertSingleTaxon(yesNode.getChildAt(1), taxon7, GT_3);
    // no
    assertSingleTaxon(circularNode.getChildAt(1), taxon8, no);
    // triangular
    PolytomousKeyNode triangularNode = root.getChildAt(1);
    assertInnerNode(triangularNode, triangular, featureLength);
    // <3
    less3Node = triangularNode.getChildAt(0);
    // blue
    assertSingleTaxon(less3Node.getChildAt(0), taxon1, blue);
    // yellow
    assertSingleTaxon(less3Node.getChildAt(1), taxon2, yellow);
    // >3
    PolytomousKeyNode gt3Node = triangularNode.getChildAt(1);
    assertInnerNode(gt3Node, GT_3, featureColour);
    // blue
    assertSingleTaxon(gt3Node.getChildAt(0), taxon3, blue);
    // yellow
    assertSingleTaxon(gt3Node.getChildAt(1), taxon4, yellow);
    // oval
    assertSingleTaxon(root.getChildAt(2), taxon1, oval);
}
Also used : PolytomousKeyNode(eu.etaxonomy.cdm.model.description.PolytomousKeyNode) PolytomousKey(eu.etaxonomy.cdm.model.description.PolytomousKey) Test(org.junit.Test)

Example 10 with PolytomousKey

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

the class PostMergeEntityListener method removeNullFromCollections.

private static void removeNullFromCollections(Object entity) {
    if (entity != null) {
        Class<?> entityClazz = entity.getClass();
        if (TaxonNode.class.isAssignableFrom(entityClazz)) {
            TaxonNode node = (TaxonNode) entity;
            node.removeNullValueFromChildren();
        } else if (PolytomousKeyNode.class.isAssignableFrom(entityClazz)) {
            PolytomousKeyNode node = (PolytomousKeyNode) entity;
            if (node.getChildren() != null && Hibernate.isInitialized(node.getChildren())) {
                node.removeNullValueFromChildren();
                for (PolytomousKeyNode childNode : node.getChildren()) {
                    removeNullFromCollections(childNode);
                }
            }
        } else if (PolytomousKey.class.isAssignableFrom(entityClazz)) {
            PolytomousKey key = (PolytomousKey) entity;
            PolytomousKeyNode node = key.getRoot();
            if (node != null && node.getChildren() != null && Hibernate.isInitialized(node.getChildren())) {
                node.removeNullValueFromChildren();
                for (PolytomousKeyNode childNode : node.getChildren()) {
                    removeNullFromCollections(childNode);
                }
            }
        } else if (TermTree.class.isAssignableFrom(entityClazz)) {
            TermTree<?> tree = (TermTree<?>) entity;
            tree.removeNullValueFromChildren();
            try {
                for (TermNode<?> node : tree.getRootChildren()) {
                    node.removeNullValueFromChildren();
                    if (node.getChildNodes() != null) {
                        for (TermNode<?> childNode : node.getChildNodes()) {
                            removeNullFromCollections(childNode);
                        }
                    }
                }
            } catch (LazyInitializationException e) {
                logger.warn("Cannot clean up uninitialized children without a session, skipping.");
            }
        } else if (TermNode.class.isAssignableFrom(entityClazz)) {
            TermNode<?> node = (TermNode<?>) entity;
            if (Hibernate.isInitialized(node.getChildNodes())) {
                node.removeNullValueFromChildren();
            }
        }
    }
}
Also used : TermTree(eu.etaxonomy.cdm.model.term.TermTree) TaxonNode(eu.etaxonomy.cdm.model.taxon.TaxonNode) LazyInitializationException(org.hibernate.LazyInitializationException) PolytomousKeyNode(eu.etaxonomy.cdm.model.description.PolytomousKeyNode) TermNode(eu.etaxonomy.cdm.model.term.TermNode) PolytomousKey(eu.etaxonomy.cdm.model.description.PolytomousKey)

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