Project

General

Profile

« Previous | Next » 

Revision c2dff0ee

Added by Patrick Plitzner over 5 years ago

ref #7589 Add service method to find taxon description by marker

View differences:

cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/DescriptiveDataSetService.java
10 10
import java.util.Optional;
11 11
import java.util.Set;
12 12
import java.util.UUID;
13
import java.util.stream.Collectors;
14 13

  
15 14
import org.apache.log4j.Logger;
16 15
import org.springframework.beans.factory.annotation.Autowired;
......
81 80
    @Autowired
82 81
    private IProgressMonitorService progressMonitorService;
83 82

  
83
    //FIXME: Use actual MarkerType for default descriptions when implemented #7957
84
    private MarkerType MARKER_DEFAULT = MarkerType.TO_BE_CHECKED();
85

  
84 86
	@Override
85 87
	@Autowired
86 88
	protected void setDao(IDescriptiveDataSetDao dao) {
......
233 235
            country = fieldUnit.getGatheringEvent().getCountry();
234 236
        }
235 237
        //get default taxon description
236
        TaxonDescription defaultTaxonDescription = findDefaultTaxonDescription(descriptiveDataSet,
237
                taxonNode);
238
        TaxonDescription defaultTaxonDescription = findTaxonDescriptionByMarkerType(descriptiveDataSet.getUuid(),
239
                taxonNode.getUuid(), MARKER_DEFAULT);
238 240
        TaxonRowWrapperDTO taxonRowWrapper = defaultTaxonDescription != null
239 241
                ? createTaxonRowWrapper(defaultTaxonDescription.getUuid(), descriptiveDataSet.getUuid()) : null;
240 242
        return new SpecimenRowWrapperDTO(description, new TaxonNodeDto(taxonNode), fieldUnit, identifier, country);
......
250 252
        super.updateTitleCacheImpl(clazz, stepSize, cacheStrategy, monitor);
251 253
    }
252 254

  
253
    /**
254
     * Returns a {@link TaxonDescription} for a given taxon node with corresponding
255
     * features according to the {@link DescriptiveDataSet}.<br>
256
     * If a description is found that matches all features of the data set this description
257
     * will be returned.
258
     * @param descriptiveDataSetUuid the uuid of the dataset defining the features
259
     * @param taxonNodeUuid the uuid of the taxon node that links to the taxon
260
     * if none could be found
261
     * @return the found taxon description or <code>null</code>
262
     */
263
    private TaxonDescription findDefaultTaxonDescription(DescriptiveDataSet dataSet, TaxonNode taxonNode){
255
    @Override
256
    public TaxonDescription findTaxonDescriptionByMarkerType(UUID dataSetUuid, UUID taxonNodeUuid, MarkerType markerType){
257
        DescriptiveDataSet dataSet = load(dataSetUuid);
258
        TaxonNode taxonNode = taxonNodeService.load(taxonNodeUuid);
264 259
        Set<DescriptionBase> dataSetDescriptions = dataSet.getDescriptions();
265
        //filter out COMPUTED descriptions
266
        List<TaxonDescription> nonComputedDescriptions = taxonNode.getTaxon().getDescriptions().stream()
267
                .filter(desc -> desc.getMarkers().stream()
268
                        .noneMatch(marker -> marker.getMarkerType().equals(MarkerType.COMPUTED())))
269
                .collect(Collectors.toList());
270
        for (TaxonDescription taxonDescription : nonComputedDescriptions) {
271
            for (DescriptionBase description : dataSetDescriptions) {
272
                if(description.getUuid().equals(taxonDescription.getUuid())){
273
                    return HibernateProxyHelper.deproxy(descriptionService.load(taxonDescription.getUuid(),
274
                            Arrays.asList("taxon", "descriptionElements", "descriptionElements.feature")), TaxonDescription.class);
275
                }
276
            }
260
        //filter by DEFAULT descriptions
261
        Optional<TaxonDescription> first = taxonNode.getTaxon().getDescriptions().stream()
262
                .filter(desc -> desc.getMarkers().stream().anyMatch(marker -> marker.getMarkerType().equals(markerType)))
263
                .filter(defaultDescription->dataSetDescriptions.contains(defaultDescription))
264
                .findFirst();
265
        if(first.isPresent()){
266
            return HibernateProxyHelper.deproxy(descriptionService.load(first.get().getUuid(),
267
                  Arrays.asList("taxon", "descriptionElements", "descriptionElements.feature")), TaxonDescription.class);
277 268
        }
278 269
        return null;
279 270
    }
......
420 411
        String tag = "";
421 412
        if(markerFlag){
422 413
            //FIXME: Add specific MarkerTypes to enum (see #7957)
423
            if(markerType.equals(MarkerType.TO_BE_CHECKED())){
414
            if(markerType.equals(MARKER_DEFAULT)){
424 415
                tag = "[Default]";
425 416
            }
426 417
            else if(markerType.equals(MarkerType.IN_BIBLIOGRAPHY())){

Also available in: Unified diff