use of eu.etaxonomy.cdm.api.service.dto.MarkedEntityDTO in project cdmlib by cybertaxonomy.
the class ClassificationServiceImpl method handleAncestorsForMarkersRecursive.
private void handleAncestorsForMarkersRecursive(TaxonInContextDTO result, List<MarkerType> markerTypes, TaxonNode node) {
for (MarkerType type : markerTypes) {
Taxon taxon = node.getTaxon();
if (taxon != null && taxon.hasMarker(type, true)) {
String label = taxon.getName() == null ? taxon.getTitleCache() : taxon.getName().getTitleCache();
MarkedEntityDTO<Taxon> dto = new MarkedEntityDTO<>(type, true, taxon.getUuid(), label);
result.addMarkedAncestor(dto);
}
}
TaxonNode parentNode = node.getParent();
if (parentNode != null) {
handleAncestorsForMarkersRecursive(result, markerTypes, parentNode);
}
}
use of eu.etaxonomy.cdm.api.service.dto.MarkedEntityDTO in project cdmlib by cybertaxonomy.
the class IdentifiableServiceBaseTest method testFindByMarker.
@Test
@DataSet(value = "IdentifiableServiceBaseTest.testFindByIdentifierOrMarker.xml")
public final void testFindByMarker() {
// classification Filter
Classification classification = classificationService.find(5000);
TaxonNode rootNode = classification.getRootNode();
Boolean markerValue = true;
UUID uuidMarkerTypeCompleted = MarkerType.uuidComplete;
UUID uuidMarkerTypeDoubtful = UUID.fromString("b51325c8-05fe-421a-832b-d86fc249ef6e");
MarkerType markerType1 = (MarkerType) termService.find(uuidMarkerTypeCompleted);
MarkerType noMarkerType = null;
MarkerType markerType2 = (MarkerType) termService.find(uuidMarkerTypeDoubtful);
Assert.assertNotNull(markerType2);
TaxonTitleType titleType = TaxonTitleType.TAXON;
MarkerType markerType = markerType1;
Pager<MarkedEntityDTO<Taxon>> taxonPager = taxonService.findByMarker(Taxon.class, markerType, markerValue, rootNode, true, titleType, null, null, null);
Assert.assertEquals("Result size for 'marker1=true' should be 1", Long.valueOf(1), taxonPager.getCount());
Assert.assertEquals("Result size for 'marker1=true' should be 1", 1, taxonPager.getRecords().size());
MarkedEntityDTO<Taxon> dto = taxonPager.getRecords().get(0);
MarkedEntityDTO<Taxon>.Marker marker = dto.getMarker();
Assert.assertTrue("Flag must be true", marker.getFlag());
Assert.assertEquals("Flag must be true", uuidMarkerTypeCompleted, marker.getTypeUuid());
Assert.assertNotNull("the CDM entity in the dto must not be empty if includeEntity=true", dto.getCdmEntity().getEntity());
Assert.assertEquals(5000, dto.getCdmEntity().getEntity().getId());
markerValue = false;
taxonPager = taxonService.findByMarker(Taxon.class, markerType, markerValue, rootNode, false, titleType, null, null, null);
Assert.assertEquals("Result size for 'marker1=false' should be 0", Long.valueOf(0), taxonPager.getCount());
markerValue = true;
markerType = noMarkerType;
taxonPager = taxonService.findByMarker(Taxon.class, markerType, markerValue, rootNode, false, titleType, null, null, null);
Assert.assertEquals("Result size for not existing marker type should be 0", Long.valueOf(0), taxonPager.getCount());
markerType = markerType2;
taxonPager = taxonService.findByMarker(Taxon.class, markerType, markerValue, rootNode, false, titleType, null, null, null);
Assert.assertEquals("Result size for markerType2 should be 0", Long.valueOf(0), taxonPager.getCount());
rootNode = null;
markerType = markerType1;
taxonPager = taxonService.findByMarker(Taxon.class, markerType, markerValue, rootNode, false, titleType, null, null, null);
Assert.assertEquals("Result size for no subtree should be 2", Long.valueOf(2), taxonPager.getCount());
Pager<MarkedEntityDTO<TaxonBase>> taxonBasePager = taxonService.findByMarker(TaxonBase.class, markerType, markerValue, rootNode, false, titleType, null, null, null);
Assert.assertEquals("Result size for taxa and synonyms without subtree filter with flag = true should be 3", Long.valueOf(3), taxonBasePager.getCount());
markerValue = null;
taxonBasePager = taxonService.findByMarker(TaxonBase.class, markerType, markerValue, rootNode, false, titleType, null, null, null);
Assert.assertEquals("Result size for taxa and synonyms without subtree filter with any flag value should be 4", Long.valueOf(4), taxonBasePager.getCount());
markerValue = true;
Pager<MarkedEntityDTO<TaxonName>> namePager = nameService.findByMarker(TaxonName.class, markerType, markerValue, false, null, null, null);
Assert.assertEquals("Result size for names with flag = true should be 1", Long.valueOf(1), namePager.getCount());
}
use of eu.etaxonomy.cdm.api.service.dto.MarkedEntityDTO in project cdmlib by cybertaxonomy.
the class AbstractIdentifiableListController method doFindByMarker.
/**
* List identifiable entities by markers
*
* @param type
* @param markerType
* @param value
* @param pageIndex
* @param pageSize
* @param request
* @param response
* @return
* @see AbstractIdentifiableListController#doFindByIdentifier(Class, String, String, Integer, Integer, MatchMode, Boolean, HttpServletRequest, HttpServletResponse)
* @throws IOException
*/
@RequestMapping(method = RequestMethod.GET, value = { "findByMarker" })
public Pager<MarkedEntityDTO<T>> doFindByMarker(@RequestParam(value = "class", required = false) Class<T> type, @RequestParam(value = "markerType", required = true) UUID markerTypeUuid, @RequestParam(value = "value", required = false) Boolean value, @RequestParam(value = "pageIndex", required = false) Integer pageIndex, @RequestParam(value = "pageSize", required = false) Integer pageSize, @RequestParam(value = "includeEntity", required = false, defaultValue = "false") Boolean includeEntity, HttpServletRequest request, HttpServletResponse response) throws IOException {
MarkerType markerType = null;
if (markerTypeUuid != null) {
DefinedTermBase<?> term = CdmBase.deproxy(termService.find(markerTypeUuid), MarkerType.class);
if (term != null && term.isInstanceOf(MarkerType.class)) {
markerType = CdmBase.deproxy(term, MarkerType.class);
}
}
logger.info("doFindByMarker() " + requestPathAndQuery(request));
PagerParameters pagerParams = new PagerParameters(pageSize, pageIndex).normalizeAndValidate(response);
Pager<MarkedEntityDTO<T>> result = service.findByMarker(type, markerType, value, includeEntity, pagerParams.getPageSize(), pagerParams.getPageIndex(), initializationStrategy);
return result;
}
Aggregations