Project

General

Profile

« Previous | Next » 

Revision 71559ffe

Added by Katja Luther over 2 years ago

ref #9710: switch to dtos for descriptive data set and descriptions for character matrix

View differences:

cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/DescriptiveDataSetService.java
23 23
import eu.etaxonomy.cdm.api.service.config.DeleteDescriptiveDataSetConfigurator;
24 24
import eu.etaxonomy.cdm.api.service.config.IdentifiableServiceConfiguratorImpl;
25 25
import eu.etaxonomy.cdm.api.service.config.RemoveDescriptionsFromDescriptiveDataSetConfigurator;
26
import eu.etaxonomy.cdm.api.service.dto.CategoricalDataDto;
26 27
import eu.etaxonomy.cdm.api.service.dto.DescriptionBaseDto;
28
import eu.etaxonomy.cdm.api.service.dto.DescriptionElementDto;
29
import eu.etaxonomy.cdm.api.service.dto.QuantitativeDataDto;
27 30
import eu.etaxonomy.cdm.api.service.dto.RowWrapperDTO;
31
import eu.etaxonomy.cdm.api.service.dto.SpecimenOrObservationDTOFactory;
28 32
import eu.etaxonomy.cdm.api.service.dto.SpecimenRowWrapperDTO;
33
import eu.etaxonomy.cdm.api.service.dto.StateDataDto;
34
import eu.etaxonomy.cdm.api.service.dto.StatisticalMeasurementValueDto;
29 35
import eu.etaxonomy.cdm.api.service.dto.TaxonRowWrapperDTO;
30 36
import eu.etaxonomy.cdm.common.monitor.IProgressMonitor;
31 37
import eu.etaxonomy.cdm.filter.TaxonNodeFilter;
......
45 51
import eu.etaxonomy.cdm.model.description.PolytomousKey;
46 52
import eu.etaxonomy.cdm.model.description.QuantitativeData;
47 53
import eu.etaxonomy.cdm.model.description.SpecimenDescription;
54
import eu.etaxonomy.cdm.model.description.State;
48 55
import eu.etaxonomy.cdm.model.description.StatisticalMeasure;
56
import eu.etaxonomy.cdm.model.description.StatisticalMeasurementValue;
49 57
import eu.etaxonomy.cdm.model.description.TaxonDescription;
50 58
import eu.etaxonomy.cdm.model.description.TextData;
51 59
import eu.etaxonomy.cdm.model.location.NamedArea;
......
57 65
import eu.etaxonomy.cdm.model.taxon.Taxon;
58 66
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
59 67
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
68
import eu.etaxonomy.cdm.model.term.DefinedTermBase;
60 69
import eu.etaxonomy.cdm.persistence.dao.description.IDescriptiveDataSetDao;
61 70
import eu.etaxonomy.cdm.persistence.dao.term.IDefinedTermDao;
71
import eu.etaxonomy.cdm.persistence.dto.DescriptiveDataSetBaseDto;
62 72
import eu.etaxonomy.cdm.persistence.dto.MergeResult;
63 73
import eu.etaxonomy.cdm.persistence.dto.SpecimenNodeWrapper;
64 74
import eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto;
......
117 127
        return dao.getDescriptiveDataSetUuidAndTitleCache( limitOfInitialElements, pattern);
118 128
    }
119 129

  
130
	@Override
131
    public DescriptiveDataSetBaseDto getDescriptiveDataSetDtoByUuid(UUID uuid) {
132
        return dao.getDescriptiveDataSetDtoByUuid(uuid);
133
    }
134

  
135

  
120 136
	@Override
121 137
	public ArrayList<RowWrapperDTO> getRowWrapper(UUID descriptiveDataSetUuid, IProgressMonitor monitor) {
122 138
	    DescriptiveDataSet descriptiveDataSet = load(descriptiveDataSetUuid);
......
223 239
    public TaxonRowWrapperDTO createTaxonRowWrapper(UUID taxonDescriptionUuid, UUID descriptiveDataSetUuid) {
224 240
        TaxonNode taxonNode = null;
225 241
        Classification classification = null;
226
        TaxonDescription description = (TaxonDescription) descriptionService.load(taxonDescriptionUuid,
227
                Arrays.asList("taxon", "descriptionElements", "descriptionElements.feature"));
242
//        TaxonDescription description = (TaxonDescription) descriptionService.loadDto(taxonDescriptionUuid,
243
//                Arrays.asList("taxon", "descriptionElements", "descriptionElements.feature"));
244
        DescriptionBaseDto description = descriptionService.loadDto(taxonDescriptionUuid);
245

  
228 246
        DescriptiveDataSet descriptiveDataSet = dao.load(descriptiveDataSetUuid, null);
229 247
        Optional<TaxonNode> first = descriptiveDataSet.getTaxonSubtreeFilter().stream()
230 248
                .filter(node->node.getClassification()!=null).findFirst();
231 249
        Optional<Classification> classificationOptional = first.map(node->node.getClassification());
232 250
        Set<DescriptionBaseDto> descriptions = new HashSet<>();
251
        TaxonNodeDto nodeDto = null;
233 252
        if(classificationOptional.isPresent()){
234 253
            classification = classificationOptional.get();
235
            Taxon taxon = (Taxon) taxonService.load(description.getTaxon().getId(), Arrays.asList("taxonNodes", "taxonNodes.classification"));
236
            taxonNode = taxon.getTaxonNode(classification);
237
            for (DescriptionBase desc: taxon.getDescriptions()){
238
                descriptions.add(new DescriptionBaseDto(desc));
239
            }
240
        }
254
//            Taxon taxon = (Taxon) taxonService.load(description.getTaxonDto().getId(), Arrays.asList("taxonNodes", "taxonNodes.classification"));
255
            nodeDto = taxonNodeService.dto(description.getTaxonDto().getUuid(), classification.getUuid());
256
//            taxonNode = taxon.getTaxonNode(classification);
241 257

  
258
//            for (DescriptionBase desc: taxon.getDescriptions()){
259
//                descriptions.add(DescriptionBaseDto.fromDescription(desc));
260
//            }
261
        }
262
        descriptions = new HashSet<>(descriptionService.loadDtosForTaxon(description.getTaxonDto().getUuid()));
242 263

  
243
        return new TaxonRowWrapperDTO(new DescriptionBaseDto(description), new TaxonNodeDto(taxonNode), descriptions);
264
        return new TaxonRowWrapperDTO(description, nodeDto, descriptions);
244 265
    }
245 266

  
246 267
    @Override
......
283 304
                taxonService.saveOrUpdate(taxon);
284 305
                result.addUpdatedObject(taxon);
285 306
            }
286
            DescriptionBase<?> specimenDescription = wrapper.getDescription().getDescription();
287
            if (specimenDescription.isPersited()){
288
                specimenDescription = descriptionService.load(specimenDescription.getUuid());
307
            UUID specimenDescriptionUuid = wrapper.getDescription().getDescriptionUuid();
308
            DescriptionBaseDto descriptionDto = wrapper.getDescription();
309
            DescriptionBase<?> specimenDescription =  descriptionService.load(specimenDescriptionUuid);
310
            //if description already exist use the loaded one and add changed data otherwise create a new one and add to specimen
311
            if (specimenDescription == null){
312
                specimenDescription = SpecimenDescription.NewInstance(specimen);
313
                List<DescriptionElementDto> elementDtos = descriptionDto.getElements();
314
                List<DescriptionElementBase> elements = new ArrayList<>();
315
                for (DescriptionElementDto elementDto: elementDtos){
316
                    if (elementDto instanceof CategoricalDataDto){
317
                        eu.etaxonomy.cdm.model.description.Character feature = DefinedTermBase.getTermByClassAndUUID(eu.etaxonomy.cdm.model.description.Character.class, elementDto.getFeatureUuid());
318
                        CategoricalData data = CategoricalData.NewInstance(feature);
319
                        for (StateDataDto stateDto:((CategoricalDataDto) elementDto).getStates()){
320
                            State state = DefinedTermBase.getTermByClassAndUUID(State.class, stateDto.getState().getUuid());
321
                            data.addStateData(state);
322
                            specimenDescription.addElement(data);
323
                        }
324
                    }
325
                    if (elementDto instanceof QuantitativeDataDto){
326
                        eu.etaxonomy.cdm.model.description.Character feature = DefinedTermBase.getTermByClassAndUUID(eu.etaxonomy.cdm.model.description.Character.class, elementDto.getFeatureUuid());
327
                        QuantitativeData data = QuantitativeData.NewInstance(feature);
328
                        for (StatisticalMeasurementValueDto stateDto:((QuantitativeDataDto) elementDto).getValues()){
329
                            StatisticalMeasure statMeasure = DefinedTermBase.getTermByClassAndUUID(StatisticalMeasure.class, stateDto.getType().getUuid());
330
                            StatisticalMeasurementValue value = StatisticalMeasurementValue.NewInstance(statMeasure, stateDto.getValue());
331
                            data.addStatisticalValue(value);
332
                            specimenDescription.addElement(data);
333
                        }
334
                    }
335
                }
336

  
289 337
            }else {
290
                specimen.addDescription(specimenDescription);
338
                List<DescriptionElementDto> elementDtos = descriptionDto.getElements();
339
                for (DescriptionElementDto elementDto: elementDtos){
340
                    if (elementDto instanceof CategoricalDataDto){
341
                        eu.etaxonomy.cdm.model.description.Character feature = DefinedTermBase.getTermByClassAndUUID(eu.etaxonomy.cdm.model.description.Character.class, elementDto.getFeatureUuid());
342
                        List<DescriptionElementBase> uniqueElementList = specimenDescription.getElements().stream().filter(element -> element.getUuid().equals(elementDto.getElementUuid())).collect(Collectors.toList());
343
                        List<State> allStates = new ArrayList<>();
344
                        CategoricalData element = null;
345
                        if (uniqueElementList.size() == 1){
346
                            element = HibernateProxyHelper.deproxy(uniqueElementList.get(0), CategoricalData.class);
347
                        }else{
348
                            element = CategoricalData.NewInstance(feature);
349
                        }
350
                        for (StateDataDto stateDto:((CategoricalDataDto) elementDto).getStates()){
351
                            State state = DefinedTermBase.getTermByClassAndUUID(State.class, stateDto.getState().getUuid());
352
                            allStates.add(state);
353
                        }
354
                        element.setStateDataOnly(allStates);
355
                    }
356
                }
291 357
            }
292 358
//            SpecimenRowWrapperDTO rowWrapper = createSpecimenRowWrapper(specimenDescription, wrapper.getTaxonNode().getUuid(), datasetUuid);
293 359
            if(wrapper==null){
294
                result.addException(new IllegalArgumentException("Could not create wrapper for "+wrapper.getDescription().getDescription()));
360
                result.addException(new IllegalArgumentException("Could not create wrapper for "+wrapper.getDescription()));
295 361
                continue;
296 362
            }
297 363
            //add specimen description to data set
......
356 422
        TaxonRowWrapperDTO taxonRowWrapper = defaultTaxonDescription != null
357 423
                ? createTaxonRowWrapper(defaultTaxonDescription.getUuid(), descriptiveDataSet.getUuid()) : null;
358 424
//                use description not specimen for specimenRow
359
        SpecimenRowWrapperDTO specimenRowWrapperDTO = new SpecimenRowWrapperDTO(new DescriptionBaseDto(description), specimen.getRecordBasis(), new TaxonNodeDto(taxonNode), fieldUnit, identifier, country);
425
        SpecimenRowWrapperDTO specimenRowWrapperDTO = new SpecimenRowWrapperDTO(DescriptionBaseDto.fromDescription(description), SpecimenOrObservationDTOFactory.fromEntity(specimen), specimen.getRecordBasis(), new TaxonNodeDto(taxonNode), fieldUnit, identifier, country);
360 426
        specimenRowWrapperDTO.setDefaultDescription(taxonRowWrapper);
361 427
        return specimenRowWrapperDTO;
362 428
    }
......
584 650
    }
585 651

  
586 652
    @Override
587
    public List<TermDto> getSupportedStatesForFeature(UUID featureUuid){
588
        return termDao.getSupportedStatesForFeature(featureUuid);
653
    public Map<UUID, List<TermDto>> getSupportedStatesForFeature(Set<UUID> featureUuids){
654
        return termDao.getSupportedStatesForFeature(featureUuids);
589 655
    }
590 656

  
591 657
    @Override

Also available in: Unified diff