Project

General

Profile

« Previous | Next » 

Revision ec49a23d

Added by Patrick Plitzner over 4 years ago

ref #8450 Add service method to find default description

View differences:

cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/DescriptiveDataSetService.java
166 166
        return taxonNodeService.load(findFilteredTaxonNodes(descriptiveDataSet), propertyPaths);
167 167
    }
168 168

  
169
    @Override
170
    public TaxonDescription findDefaultDescription(UUID specimenDescriptionUuid, UUID dataSetUuid){
171
        SpecimenDescription specimenDescription = (SpecimenDescription) descriptionService.load(specimenDescriptionUuid);
172
        DescriptiveDataSet dataSet = load(dataSetUuid);
173
        TaxonNode node = findTaxonNodeForDescription(specimenDescription, dataSet);
174
        return recurseDefaultDescription(node, dataSet);
175
    }
176

  
177
    private TaxonDescription recurseDefaultDescription(TaxonNode node, DescriptiveDataSet dataSet){
178
        TaxonDescription defaultDescription = findTaxonDescriptionByDescriptionType(dataSet, node.getTaxon(), DescriptionType.DEFAULT_VALUES_FOR_AGGREGATION);
179
        if(defaultDescription==null && node.getParent()!=null){
180
            defaultDescription = recurseDefaultDescription(node.getParent(), dataSet);
181
        }
182
        return defaultDescription;
183
    }
184

  
169 185
    private TaxonNode findTaxonNodeForDescription(SpecimenDescription description, DescriptiveDataSet descriptiveDataSet){
170 186
        SpecimenOrObservationBase specimen = description.getDescribedSpecimenOrObservation();
171 187
        TaxonNode taxonNode = null;
......
186 202
        return null;
187 203
    }
188 204

  
189
    private TaxonNode findTaxonNodeForSpecimen(TaxonNode taxonNode, SpecimenOrObservationBase<?> specimen){
190
        Collection<SpecimenNodeWrapper> nodeWrapper = occurrenceService.listUuidAndTitleCacheByAssociatedTaxon(Arrays.asList(taxonNode.getUuid()), null, null);
191
        for (SpecimenNodeWrapper specimenNodeWrapper : nodeWrapper) {
192
            if(specimenNodeWrapper.getUuidAndTitleCache().getId().equals(specimen.getId())){
193
                return taxonNode;
194
            }
195
        }
196
        return null;
197
    }
198

  
199 205
    @Override
200 206
    public TaxonRowWrapperDTO createTaxonRowWrapper(UUID taxonDescriptionUuid, UUID descriptiveDataSetUuid) {
201 207
        TaxonNode taxonNode = null;
......
326 332
    }
327 333

  
328 334
    private TaxonDescription findTaxonDescriptionByDescriptionType(DescriptiveDataSet dataSet, Taxon taxon, DescriptionType descriptionType){
329
        Set<DescriptionBase> dataSetDescriptions = dataSet.getDescriptions();
330
        //filter by DEFAULT descriptions
331 335
        Optional<TaxonDescription> first = taxon.getDescriptions().stream()
332 336
                .filter(desc -> desc.getTypes().stream().anyMatch(type -> type.equals(descriptionType)))
333
                .filter(defaultDescription->dataSetDescriptions.contains(defaultDescription))
337
                .filter(desc -> dataSet.getDescriptions().contains(desc))
334 338
                .findFirst();
335 339
        if(first.isPresent()){
336 340
            return HibernateProxyHelper.deproxy(descriptionService.load(first.get().getUuid(),
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/IDescriptiveDataSetService.java
184 184
     */
185 185
    UpdateResult generatePolytomousKey(UUID descriptiveDataSetUuid, UUID taxonUuid);
186 186

  
187
    /**
188
     * Returns the first {@link TaxonDescription} with {@link DescriptionType#DEFAULT_VALUES_FOR_AGGREGATION}
189
     * found in the taxon node hierarchy of the associated taxon
190
     * @param specimenDescriptionUuid the specimen description
191
     * @param dataSetUuid the data set
192
     * @return the first found default description or <code>null</code>
193
     */
194
    public TaxonDescription findDefaultDescription(UUID specimenDescriptionUuid, UUID dataSetUuid);
195

  
187 196
}

Also available in: Unified diff