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