Search in sources :

Example 1 with MarkedEntityDTO

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);
    }
}
Also used : TaxonNode(eu.etaxonomy.cdm.model.taxon.TaxonNode) Taxon(eu.etaxonomy.cdm.model.taxon.Taxon) MarkerType(eu.etaxonomy.cdm.model.common.MarkerType) MarkedEntityDTO(eu.etaxonomy.cdm.api.service.dto.MarkedEntityDTO)

Example 2 with MarkedEntityDTO

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());
}
Also used : TaxonNode(eu.etaxonomy.cdm.model.taxon.TaxonNode) TaxonTitleType(eu.etaxonomy.cdm.persistence.query.TaxonTitleType) Taxon(eu.etaxonomy.cdm.model.taxon.Taxon) MarkedEntityDTO(eu.etaxonomy.cdm.api.service.dto.MarkedEntityDTO) TaxonBase(eu.etaxonomy.cdm.model.taxon.TaxonBase) Classification(eu.etaxonomy.cdm.model.taxon.Classification) MarkerType(eu.etaxonomy.cdm.model.common.MarkerType) UUID(java.util.UUID) CdmTransactionalIntegrationTest(eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest) Test(org.junit.Test) ExpectedDataSet(org.unitils.dbunit.annotation.ExpectedDataSet) DataSet(org.unitils.dbunit.annotation.DataSet)

Example 3 with MarkedEntityDTO

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;
}
Also used : PagerParameters(eu.etaxonomy.cdm.remote.controller.util.PagerParameters) MarkerType(eu.etaxonomy.cdm.model.common.MarkerType) MarkedEntityDTO(eu.etaxonomy.cdm.api.service.dto.MarkedEntityDTO) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

MarkedEntityDTO (eu.etaxonomy.cdm.api.service.dto.MarkedEntityDTO)3 MarkerType (eu.etaxonomy.cdm.model.common.MarkerType)3 Taxon (eu.etaxonomy.cdm.model.taxon.Taxon)2 TaxonNode (eu.etaxonomy.cdm.model.taxon.TaxonNode)2 Classification (eu.etaxonomy.cdm.model.taxon.Classification)1 TaxonBase (eu.etaxonomy.cdm.model.taxon.TaxonBase)1 TaxonTitleType (eu.etaxonomy.cdm.persistence.query.TaxonTitleType)1 PagerParameters (eu.etaxonomy.cdm.remote.controller.util.PagerParameters)1 CdmTransactionalIntegrationTest (eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest)1 UUID (java.util.UUID)1 Test (org.junit.Test)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 DataSet (org.unitils.dbunit.annotation.DataSet)1 ExpectedDataSet (org.unitils.dbunit.annotation.ExpectedDataSet)1