Search in sources :

Example 31 with TaxonNodeDto

use of eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto in project cdmlib by cybertaxonomy.

the class ClassificationController method getChildNodesAtRank.

@RequestMapping(value = { "childNodesAt/{rankUuid}" }, method = RequestMethod.GET)
public List<TaxonNodeDto> getChildNodesAtRank(@PathVariable("uuid") UUID classificationUuid, @PathVariable("rankUuid") UUID rankUuid, @RequestParam(value = "subtree", required = false) UUID subtreeUuid, @RequestParam(value = "sortMode", required = false, defaultValue = DEFAULT_TAXONNODEDTO_SORT_MODE) TaxonNodeDtoSortMode sortMode, HttpServletRequest request, HttpServletResponse response) throws IOException {
    logger.info("getChildNodesAtRank() - " + request.getRequestURI());
    Classification classification = service.find(classificationUuid);
    if (classification == null) {
        HttpStatusMessage.UUID_NOT_FOUND.send(response, "Classification not found using " + classificationUuid);
        return null;
    }
    TaxonNode subtree = getSubtreeOrError(subtreeUuid, taxonNodeService, response);
    Rank rank = findRank(rankUuid);
    boolean includeUnpublished = NO_UNPUBLISHED;
    // long start = System.currentTimeMillis();
    List<TaxonNodeDto> rootNodes = service.listRankSpecificRootNodeDtos(classification, subtree, rank, includeUnpublished, null, null, sortMode, NODE_INIT_STRATEGY());
    return rootNodes;
}
Also used : TaxonNode(eu.etaxonomy.cdm.model.taxon.TaxonNode) Classification(eu.etaxonomy.cdm.model.taxon.Classification) Rank(eu.etaxonomy.cdm.model.name.Rank) TaxonNodeDto(eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 32 with TaxonNodeDto

use of eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto in project cdmlib by cybertaxonomy.

the class TaxonNodeDtoByNameComparatorTest method testNullSave.

@Test
public void testNullSave() {
    Classification classification = Classification.NewInstance("Greuther, 1993");
    Reference sec = ReferenceFactory.newBook();
    IBotanicalName botname_1 = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
    String nameCache_1 = "Epilobium \u00D7aschersonianum Hausskn.";
    botname_1.setNameCache(nameCache_1, true);
    Taxon taxon_1 = Taxon.NewInstance(botname_1, sec);
    IBotanicalName botname_2 = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
    String nameCache_2 = "\u00D7Epilobium \u00D7angustifolium";
    botname_2.setNameCache(nameCache_2, true);
    Taxon taxon_2 = Taxon.NewInstance(botname_2, sec);
    TaxonNodeDto node1 = new TaxonNodeDto(classification.addChildTaxon(taxon_1, sec, null));
    TaxonNodeDto node2 = new TaxonNodeDto(classification.addChildTaxon(taxon_2, sec, null));
    TaxonNodeDtoByNameComparator taxonNodeByNameComparator = new TaxonNodeDtoByNameComparator();
    Assert.assertEquals(0, taxonNodeByNameComparator.compare(null, null));
    Assert.assertEquals(-1, taxonNodeByNameComparator.compare(node1, null));
    Assert.assertEquals(1, taxonNodeByNameComparator.compare(null, node1));
}
Also used : IBotanicalName(eu.etaxonomy.cdm.model.name.IBotanicalName) TaxonNodeDtoByNameComparator(eu.etaxonomy.cdm.persistence.dto.TaxonNodeDtoByNameComparator) Reference(eu.etaxonomy.cdm.model.reference.Reference) Classification(eu.etaxonomy.cdm.model.taxon.Classification) Taxon(eu.etaxonomy.cdm.model.taxon.Taxon) TaxonNodeDto(eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto) Test(org.junit.Test)

Example 33 with TaxonNodeDto

use of eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto in project cdmlib by cybertaxonomy.

the class TaxonNodeServiceImplTest method testGetUuidAndTitleCacheHierarchy.

@Test
@DataSet(loadStrategy = CleanSweepInsertLoadStrategy.class, value = "TaxonNodeServiceImplTest.testGetUuidAndTitleCacheHierarchy.xml")
public void testGetUuidAndTitleCacheHierarchy() {
    UUID classificationUuid = UUID.fromString("029b4c07-5903-4dcf-87e8-406ed0e0285f");
    UUID abiesUuid = UUID.fromString("f8306fd3-9825-41bf-94aa-a7b5790b553e");
    UUID abiesAlbaUuid = UUID.fromString("c70f76e5-2dcb-41c5-ae6f-d756e0a0fae0");
    UUID abiesAlbaSubBrotaUuid = UUID.fromString("06d58161-7707-44b5-b720-6c0eb916b37c");
    UUID abiesPalmaUuid = UUID.fromString("6dfd30dd-e589-493a-b66a-19c4cb374f92");
    UUID pinusUuid = UUID.fromString("5d8e8341-f5e9-4616-96cf-f0351dda42f4");
    // /*
    // * Checklist
    // *  - Abies
    // *   - Abies alba
    // *    - Abieas alba subs. brota
    // *   - Abies palma
    // *  -Pinus
    // */
    // Classification checklist = Classification.NewInstance("Checklist");
    // checklist.setUuid(classificationUuid);
    // 
    // BotanicalName abiesName = TaxonNameFactory.NewBotanicalInstance(Rank.GENUS());
    // abiesName.setGenusOrUninomial("Abies");
    // Taxon abies = Taxon.NewInstance(abiesName, null);
    // 
    // BotanicalName abiesAlbaName = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
    // abiesAlbaName.setGenusOrUninomial("Abies");
    // abiesAlbaName.setSpecificEpithet("alba");
    // Taxon abiesAlba = Taxon.NewInstance(abiesAlbaName, null);
    // 
    // BotanicalName abiesAlbaSubBrotaName = TaxonNameFactory.NewBotanicalInstance(Rank.SUBSPECIES());
    // abiesAlbaSubBrotaName.setGenusOrUninomial("Abies");
    // abiesAlbaSubBrotaName.setSpecificEpithet("alba");
    // abiesAlbaSubBrotaName.setInfraSpecificEpithet("brota");
    // Taxon abiesAlbaSubBrota = Taxon.NewInstance(abiesAlbaSubBrotaName, null);
    // 
    // BotanicalName abiesPalmaName = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
    // abiesPalmaName.setGenusOrUninomial("Abies");
    // abiesPalmaName.setSpecificEpithet("palma");
    // Taxon abiesPalma = Taxon.NewInstance(abiesPalmaName, null);
    // 
    // BotanicalName pinusName = TaxonNameFactory.NewBotanicalInstance(Rank.GENUS());
    // pinusName.setGenusOrUninomial("Pinus");
    // Taxon pinus = Taxon.NewInstance(pinusName, null);
    // 
    // checklist.addParentChild(null, abies, null, null);
    // checklist.addParentChild(abies, abiesAlba, null, null);
    // checklist.addParentChild(abiesAlba, abiesAlbaSubBrota, null, null);
    // checklist.addParentChild(abies, abiesPalma, null, null);
    // checklist.addParentChild(null, pinus, null, null);
    // 
    // 
    // setComplete();
    // endTransaction();
    // 
    // String fileNameAppendix = "testGetUuidAndTitleCacheHierarchy";
    // 
    // writeDbUnitDataSetFile(new String[] {
    // "TAXONBASE", "TAXONNAME",
    // "TAXONRELATIONSHIP",
    // "HOMOTYPICALGROUP",
    // "CLASSIFICATION", "TAXONNODE",
    // "HIBERNATE_SEQUENCES" // IMPORTANT!!!
    // },
    // fileNameAppendix );
    Classification classification = classificationService.load(classificationUuid);
    List<TaxonNode> expectedChildTaxonNodes = classification.getChildNodes();
    List<TaxonNodeDto> childNodesUuidAndTitleCache = taxonNodeService.listChildNodesAsTaxonNodeDto(classification.getRootNode());
    assertNotNull("child UuidAndTitleCache list is null", childNodesUuidAndTitleCache);
    compareChildren(expectedChildTaxonNodes, childNodesUuidAndTitleCache);
    // test taxon parent of sub species
    Taxon abiesAlbaSubBrota = HibernateProxyHelper.deproxy(taxonService.load(abiesAlbaSubBrotaUuid), Taxon.class);
    TaxonNode abiesAlbaSubBrotaNode = abiesAlbaSubBrota.getTaxonNodes().iterator().next();
    TaxonNode expectedTaxonParent = HibernateProxyHelper.deproxy(abiesAlbaSubBrotaNode.getParent(), TaxonNode.class);
    TaxonNodeDto taxonParent = taxonNodeService.getParentUuidAndTitleCache(abiesAlbaSubBrotaNode);
    assertEquals("Taxon Nodes do not match. ", expectedTaxonParent.getUuid(), taxonParent.getUuid());
    assertEquals("Taxon Nodes do not match. ", (Integer) expectedTaxonParent.getId(), taxonParent.getId());
    assertEquals("Taxon Nodes do not match. ", expectedTaxonParent.getTaxon().getTitleCache(), taxonParent.getTitleCache());
    assertEquals("Taxon Nodes do not match. ", expectedTaxonParent, taxonNodeService.load(taxonParent.getUuid()));
    // test classification parent
    Taxon abies = HibernateProxyHelper.deproxy(taxonService.load(abiesUuid), Taxon.class);
    TaxonNode abiesNode = abies.getTaxonNodes().iterator().next();
    TaxonNode expectedClassificationParent = HibernateProxyHelper.deproxy(abiesNode.getParent(), TaxonNode.class);
    TaxonNodeDto classificationParent = taxonNodeService.getParentUuidAndTitleCache(abiesNode);
    assertEquals("Taxon Nodes do not match. ", expectedClassificationParent.getUuid(), classificationParent.getUuid());
    assertEquals("Taxon Nodes do not match. ", (Integer) expectedClassificationParent.getId(), classificationParent.getId());
    assertEquals("Taxon Nodes do not match. ", expectedClassificationParent.getClassification().getTitleCache(), classificationParent.getTitleCache());
    assertEquals("Taxon Nodes do not match. ", expectedClassificationParent, taxonNodeService.load(classificationParent.getUuid()));
}
Also used : TaxonNode(eu.etaxonomy.cdm.model.taxon.TaxonNode) Classification(eu.etaxonomy.cdm.model.taxon.Classification) Taxon(eu.etaxonomy.cdm.model.taxon.Taxon) UUID(java.util.UUID) TaxonNodeDto(eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto) CdmTransactionalIntegrationTest(eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest) Test(org.junit.Test) DataSet(org.unitils.dbunit.annotation.DataSet)

Example 34 with TaxonNodeDto

use of eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto in project cdmlib by cybertaxonomy.

the class TaxonNodeServiceImplTest method testFindCommonParentNode.

@Test
@DataSet("TaxonNodeServiceImplTest-testFindCommonParentNode.xml")
public void testFindCommonParentNode() {
    UUID checklist2Uuid = UUID.fromString("c6e3a598-3b6c-4ef5-8b01-5bdb3de5a9fd");
    UUID campanulaNodeUuid = UUID.fromString("62fa918d-a1d8-4284-ae4b-93478bde8656");
    UUID campanulaPersicifoliaNodeUuid = UUID.fromString("dce3defa-5123-44a7-8008-0cc9b27461f6");
    UUID classificationUuid = UUID.fromString("029b4c07-5903-4dcf-87e8-406ed0e0285f");
    UUID abiesNodeUuid = UUID.fromString("f8306fd3-9825-41bf-94aa-a7b5790b553e");
    UUID abiesAlbaNodeUuid = UUID.fromString("c70f76e5-2dcb-41c5-ae6f-d756e0a0fae0");
    UUID abiesAlbaSubBrotaNodeUuid = UUID.fromString("06d58161-7707-44b5-b720-6c0eb916b37c");
    UUID abiesPalmaNodeUuid = UUID.fromString("6dfd30dd-e589-493a-b66a-19c4cb374f92");
    UUID pinusNodeUuid = UUID.fromString("5d8e8341-f5e9-4616-96cf-f0351dda42f4");
    // /*
    // * Checklist2
    // *  - Campanula
    // *   - Campanula persicifolia
    // * Checklist
    // *  - Abies
    // *   - Abies alba
    // *    - Abieas alba subs. brota
    // *   - Abies palma
    // *  -Pinus
    // */
    // Classification checklist2 = Classification.NewInstance("Checklist2");
    // checklist2.setUuid(checklist2Uuid);
    // 
    // IBotanicalName campanulaName = TaxonNameFactory.NewBotanicalInstance(Rank.GENUS());
    // campanulaName.setGenusOrUninomial("Campanula");
    // Taxon campanula = Taxon.NewInstance(campanulaName, null);
    // 
    // IBotanicalName campanulaPersicifoliaName = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
    // campanulaPersicifoliaName.setGenusOrUninomial("Campanula");
    // campanulaPersicifoliaName.setSpecificEpithet("persicifolia");
    // Taxon campanulaPersicifolia = Taxon.NewInstance(campanulaPersicifoliaName, null);
    // 
    // TaxonNode campanulaNode = checklist2.addChildTaxon(campanula, null, null);
    // campanulaNode.setUuid(campanulaNodeUuid);
    // TaxonNode campanulaPersicifoliaNode = checklist2.addParentChild(campanula, campanulaPersicifolia, null, null);
    // campanulaPersicifoliaNode.setUuid(campanulaPersicifoliaNodeUuid);
    // 
    // Classification checklist = Classification.NewInstance("Checklist");
    // checklist.setUuid(classificationUuid);
    // 
    // IBotanicalName abiesName = TaxonNameFactory.NewBotanicalInstance(Rank.GENUS());
    // abiesName.setGenusOrUninomial("Abies");
    // Taxon abies = Taxon.NewInstance(abiesName, null);
    // 
    // IBotanicalName abiesAlbaName = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
    // abiesAlbaName.setGenusOrUninomial("Abies");
    // abiesAlbaName.setSpecificEpithet("alba");
    // Taxon abiesAlba = Taxon.NewInstance(abiesAlbaName, null);
    // 
    // IBotanicalName abiesAlbaSubBrotaName = TaxonNameFactory.NewBotanicalInstance(Rank.SUBSPECIES());
    // abiesAlbaSubBrotaName.setGenusOrUninomial("Abies");
    // abiesAlbaSubBrotaName.setSpecificEpithet("alba");
    // abiesAlbaSubBrotaName.setInfraSpecificEpithet("brota");
    // Taxon abiesAlbaSubBrota = Taxon.NewInstance(abiesAlbaSubBrotaName, null);
    // 
    // IBotanicalName abiesPalmaName = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
    // abiesPalmaName.setGenusOrUninomial("Abies");
    // abiesPalmaName.setSpecificEpithet("palma");
    // Taxon abiesPalma = Taxon.NewInstance(abiesPalmaName, null);
    // 
    // IBotanicalName pinusName = TaxonNameFactory.NewBotanicalInstance(Rank.GENUS());
    // pinusName.setGenusOrUninomial("Pinus");
    // Taxon pinus = Taxon.NewInstance(pinusName, null);
    // 
    // TaxonNode abiesNode = checklist.addChildTaxon(abies, null, null);
    // abiesNode.setUuid(abiesNodeUuid);
    // TaxonNode abiesAlbaNode = checklist.addParentChild(abies, abiesAlba, null, null);
    // abiesAlbaNode.setUuid(abiesAlbaNodeUuid);
    // TaxonNode abiesAlbaSubBrotaNode = checklist.addParentChild(abiesAlba, abiesAlbaSubBrota, null, null);
    // abiesAlbaSubBrotaNode.setUuid(abiesAlbaSubBrotaNodeUuid);
    // TaxonNode abiesPalmaNode = checklist.addParentChild(abies, abiesPalma, null, null);
    // abiesPalmaNode.setUuid(abiesPalmaNodeUuid);
    // TaxonNode pinusNode = checklist.addChildTaxon(pinus, null, null);
    // pinusNode.setUuid(pinusNodeUuid);
    // 
    // taxonService.saveOrUpdate(campanula);
    // taxonService.saveOrUpdate(campanulaPersicifolia);
    // classificationService.saveOrUpdate(checklist2);
    // 
    // taxonService.saveOrUpdate(abies);
    // taxonService.saveOrUpdate(abiesAlba);
    // taxonService.saveOrUpdate(abiesAlbaSubBrota);
    // taxonService.saveOrUpdate(abiesPalma);
    // taxonService.saveOrUpdate(pinus);
    // classificationService.saveOrUpdate(checklist);
    // 
    // 
    // setComplete();
    // endTransaction();
    // 
    // String fileNameAppendix = "testFindCommonParentNode";
    // 
    // writeDbUnitDataSetFile(new String[] {
    // "TAXONBASE", "TAXONNAME",
    // "TAXONRELATIONSHIP",
    // "HOMOTYPICALGROUP",
    // "CLASSIFICATION", "TAXONNODE",
    // "LANGUAGESTRING",
    // "HIBERNATE_SEQUENCES" // IMPORTANT!!!
    // },
    // fileNameAppendix );
    Classification classification = classificationService.load(classificationUuid);
    TaxonNode campanula = taxonNodeService.load(campanulaNodeUuid);
    TaxonNode campanulaPersicifolia = taxonNodeService.load(campanulaPersicifoliaNodeUuid);
    TaxonNode abies = taxonNodeService.load(abiesNodeUuid);
    TaxonNode abiesAlba = taxonNodeService.load(abiesAlbaNodeUuid);
    TaxonNode abiesPalma = taxonNodeService.load(abiesPalmaNodeUuid);
    TaxonNode pinus = taxonNodeService.load(pinusNodeUuid);
    // check initial state
    assertTrue(campanula != null);
    assertTrue(campanulaPersicifolia != null);
    assertTrue(abies != null);
    assertTrue(abiesAlba != null);
    assertTrue(abiesPalma != null);
    assertTrue(pinus != null);
    TaxonNodeDto classificationRootNodeDto = new TaxonNodeDto(classification.getRootNode());
    TaxonNodeDto campanulaDto = new TaxonNodeDto(campanula);
    TaxonNodeDto campanulaPersicifoliaDto = new TaxonNodeDto(campanulaPersicifolia);
    TaxonNodeDto abiesDto = new TaxonNodeDto(abies);
    TaxonNodeDto abiesAlbaDto = new TaxonNodeDto(abiesAlba);
    TaxonNodeDto abiesPalmaDto = new TaxonNodeDto(abiesPalma);
    TaxonNodeDto pinusDto = new TaxonNodeDto(pinus);
    List<TaxonNodeDto> nodes = new ArrayList<>();
    nodes.add(campanulaDto);
    TaxonNodeDto commonParentNodeDto = taxonNodeService.findCommonParentDto(nodes);
    assertEquals(campanulaDto.getUuid(), commonParentNodeDto.getUuid());
    nodes = new ArrayList<>();
    nodes.add(campanulaDto);
    nodes.add(campanulaPersicifoliaDto);
    commonParentNodeDto = taxonNodeService.findCommonParentDto(nodes);
    assertEquals(campanulaDto.getUuid(), commonParentNodeDto.getUuid());
    nodes = new ArrayList<>();
    nodes.add(campanulaDto);
    nodes.add(abiesAlbaDto);
    commonParentNodeDto = taxonNodeService.findCommonParentDto(nodes);
    assertNull(commonParentNodeDto);
    nodes = new ArrayList<>();
    nodes.add(abiesAlbaDto);
    nodes.add(abiesPalmaDto);
    commonParentNodeDto = taxonNodeService.findCommonParentDto(nodes);
    assertEquals(abiesDto.getUuid(), commonParentNodeDto.getUuid());
    nodes = new ArrayList<>();
    nodes.add(abiesDto);
    nodes.add(pinusDto);
    commonParentNodeDto = taxonNodeService.findCommonParentDto(nodes);
    assertEquals(classificationRootNodeDto.getUuid(), commonParentNodeDto.getUuid());
}
Also used : TaxonNode(eu.etaxonomy.cdm.model.taxon.TaxonNode) Classification(eu.etaxonomy.cdm.model.taxon.Classification) ArrayList(java.util.ArrayList) UUID(java.util.UUID) TaxonNodeDto(eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto) CdmTransactionalIntegrationTest(eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest) Test(org.junit.Test) DataSet(org.unitils.dbunit.annotation.DataSet)

Aggregations

TaxonNodeDto (eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto)34 ArrayList (java.util.ArrayList)16 TaxonNode (eu.etaxonomy.cdm.model.taxon.TaxonNode)15 UUID (java.util.UUID)11 Query (org.hibernate.Query)10 Classification (eu.etaxonomy.cdm.model.taxon.Classification)8 Taxon (eu.etaxonomy.cdm.model.taxon.Taxon)8 SortableTaxonNodeQueryResult (eu.etaxonomy.cdm.persistence.dto.SortableTaxonNodeQueryResult)6 LanguageString (eu.etaxonomy.cdm.model.common.LanguageString)4 DescriptiveDataSetBaseDto (eu.etaxonomy.cdm.persistence.dto.DescriptiveDataSetBaseDto)4 Test (org.junit.Test)4 DescriptionBaseDto (eu.etaxonomy.cdm.api.service.dto.DescriptionBaseDto)3 Synonym (eu.etaxonomy.cdm.model.taxon.Synonym)3 CdmTransactionalIntegrationTest (eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest)3 BigInteger (java.math.BigInteger)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 DataSet (org.unitils.dbunit.annotation.DataSet)3 SpecimenRowWrapperDTO (eu.etaxonomy.cdm.api.service.dto.SpecimenRowWrapperDTO)2 TaxonRowWrapperDTO (eu.etaxonomy.cdm.api.service.dto.TaxonRowWrapperDTO)2 IProgressMonitor (eu.etaxonomy.cdm.common.monitor.IProgressMonitor)2