15 |
15 |
import java.util.stream.Collectors;
|
16 |
16 |
|
17 |
17 |
import org.apache.log4j.Logger;
|
|
18 |
import org.hibernate.Query;
|
|
19 |
import org.hibernate.Session;
|
18 |
20 |
import org.springframework.beans.factory.annotation.Autowired;
|
19 |
21 |
import org.springframework.stereotype.Service;
|
20 |
22 |
import org.springframework.transaction.annotation.Transactional;
|
... | ... | |
39 |
41 |
import eu.etaxonomy.cdm.format.description.DefaultQuantitativeDescriptionBuilder;
|
40 |
42 |
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
|
41 |
43 |
import eu.etaxonomy.cdm.model.common.CdmBase;
|
|
44 |
import eu.etaxonomy.cdm.model.common.IdentifiableSource;
|
42 |
45 |
import eu.etaxonomy.cdm.model.common.Language;
|
43 |
46 |
import eu.etaxonomy.cdm.model.description.CategoricalData;
|
44 |
47 |
import eu.etaxonomy.cdm.model.description.DescriptionBase;
|
... | ... | |
58 |
61 |
import eu.etaxonomy.cdm.model.description.TaxonDescription;
|
59 |
62 |
import eu.etaxonomy.cdm.model.description.TextData;
|
60 |
63 |
import eu.etaxonomy.cdm.model.location.NamedArea;
|
61 |
|
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
|
62 |
64 |
import eu.etaxonomy.cdm.model.occurrence.FieldUnit;
|
63 |
65 |
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
|
64 |
66 |
import eu.etaxonomy.cdm.model.reference.CdmLinkSource;
|
... | ... | |
74 |
76 |
import eu.etaxonomy.cdm.persistence.dto.SpecimenNodeWrapper;
|
75 |
77 |
import eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto;
|
76 |
78 |
import eu.etaxonomy.cdm.persistence.dto.TermDto;
|
|
79 |
import eu.etaxonomy.cdm.persistence.dto.TermTreeDto;
|
77 |
80 |
import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
|
78 |
81 |
import eu.etaxonomy.cdm.strategy.cache.common.IIdentifiableEntityCacheStrategy;
|
79 |
82 |
import eu.etaxonomy.cdm.strategy.generate.PolytomousKeyGenerator;
|
... | ... | |
130 |
133 |
|
131 |
134 |
@Override
|
132 |
135 |
public List<RowWrapperDTO<?>> getRowWrapper(UUID descriptiveDataSetUuid, IProgressMonitor monitor) {
|
133 |
|
DescriptiveDataSet descriptiveDataSet = load(descriptiveDataSetUuid);
|
134 |
|
monitor.beginTask("Load row wrapper", descriptiveDataSet.getDescriptions().size());
|
|
136 |
DescriptiveDataSetBaseDto datasetDto = dao.getDescriptiveDataSetDtoByUuid(descriptiveDataSetUuid);
|
|
137 |
// DescriptiveDataSet descriptiveDataSet = load(descriptiveDataSetUuid);
|
|
138 |
monitor.beginTask("Load row wrapper", datasetDto.getDescriptionUuids().size());
|
135 |
139 |
List<RowWrapperDTO<?>> wrappers = new ArrayList<>();
|
136 |
|
Set<DescriptionBase> descriptions = descriptiveDataSet.getDescriptions();
|
137 |
|
for (DescriptionBase<?> description : descriptions) {
|
|
140 |
Set<UUID> descriptions = datasetDto.getDescriptionUuids();
|
|
141 |
for (UUID description : descriptions) {
|
138 |
142 |
if(monitor.isCanceled()){
|
139 |
143 |
return new ArrayList<>();
|
140 |
144 |
}
|
|
145 |
DescriptionBaseDto descDto = descriptionService.loadDto(description);
|
141 |
146 |
RowWrapperDTO<?> rowWrapper = null;
|
142 |
|
// only viable descriptions are aggregated, literature or default descriptions
|
143 |
|
if(description.isInstanceOf(TaxonDescription.class) &&
|
144 |
|
(description.isAggregatedStructuredDescription()
|
145 |
|
|| description.getTypes().contains(DescriptionType.DEFAULT_VALUES_FOR_AGGREGATION)
|
146 |
|
|| description.getTypes().contains(DescriptionType.SECONDARY_DATA)
|
|
147 |
if (descDto.getTaxonDto() != null &&
|
|
148 |
(descDto.getTypes().contains(DescriptionType.DEFAULT_VALUES_FOR_AGGREGATION)
|
|
149 |
|| descDto.getTypes().contains(DescriptionType.AGGREGATED_STRUC_DESC)
|
|
150 |
|| descDto.getTypes().contains(DescriptionType.SECONDARY_DATA)
|
147 |
151 |
)){
|
148 |
|
rowWrapper = createTaxonRowWrapper((TaxonDescription)description, descriptiveDataSet.getUuid());
|
|
152 |
rowWrapper = createTaxonRowWrapper(descDto, datasetDto.getUuid());
|
149 |
153 |
}
|
150 |
|
else if (description.isInstanceOf(SpecimenDescription.class)&&
|
151 |
|
!description.getTypes().contains(DescriptionType.CLONE_FOR_SOURCE)){
|
152 |
|
rowWrapper = createSpecimenRowWrapper(HibernateProxyHelper.deproxy(description, SpecimenDescription.class), descriptiveDataSetUuid);
|
|
154 |
else if (descDto.getSpecimenDto() != null && (descDto.getTypes() == null ||
|
|
155 |
!descDto.getTypes().contains(DescriptionType.CLONE_FOR_SOURCE))){
|
|
156 |
rowWrapper = createSpecimenRowWrapper(descDto, descriptiveDataSetUuid);
|
153 |
157 |
}
|
154 |
158 |
if(rowWrapper!=null){
|
155 |
159 |
wrappers.add(rowWrapper);
|
... | ... | |
193 |
197 |
}
|
194 |
198 |
|
195 |
199 |
@Override
|
196 |
|
public TaxonDescription findDefaultDescription(UUID specimenDescriptionUuid, UUID dataSetUuid){
|
197 |
|
SpecimenDescription specimenDescription = (SpecimenDescription) descriptionService.load(specimenDescriptionUuid);
|
198 |
|
DescriptiveDataSet dataSet = load(dataSetUuid);
|
199 |
|
TaxonNode node = findTaxonNodeForDescription(specimenDescription, dataSet);
|
|
200 |
public DescriptionBaseDto findDefaultDescription(UUID specimenDescriptionUuid, UUID dataSetUuid){
|
|
201 |
DescriptionBaseDto specimenDescription = descriptionService.loadDto(specimenDescriptionUuid);
|
|
202 |
DescriptiveDataSetBaseDto dataSet = dao.getDescriptiveDataSetDtoByUuid(dataSetUuid);
|
|
203 |
TaxonNodeDto node = findTaxonNodeForDescription(specimenDescription, dataSet);
|
200 |
204 |
return recurseDefaultDescription(node, dataSet);
|
201 |
205 |
}
|
202 |
206 |
|
203 |
|
private TaxonDescription recurseDefaultDescription(TaxonNode node, DescriptiveDataSet dataSet){
|
204 |
|
TaxonDescription defaultDescription = null;
|
205 |
|
if(node!=null && node.getTaxon()!=null){
|
206 |
|
defaultDescription = findTaxonDescriptionByDescriptionType(dataSet, node.getTaxon(), DescriptionType.DEFAULT_VALUES_FOR_AGGREGATION);
|
207 |
|
if(defaultDescription==null && node.getParent()!=null){
|
208 |
|
defaultDescription = recurseDefaultDescription(node.getParent(), dataSet);
|
|
207 |
private DescriptionBaseDto recurseDefaultDescription(TaxonNodeDto node, DescriptiveDataSetBaseDto dataSet){
|
|
208 |
DescriptionBaseDto defaultDescription = null;
|
|
209 |
if(node!=null && node.getTaxonUuid()!=null){
|
|
210 |
defaultDescription = getTaxonDescriptionForDescriptiveDataSetAndType(dataSet, node.getUuid(), DescriptionType.DEFAULT_VALUES_FOR_AGGREGATION);
|
|
211 |
if(defaultDescription==null && node.getParentUUID()!=null){
|
|
212 |
defaultDescription = recurseDefaultDescription(taxonNodeService.dto(node.getParentUUID()), dataSet);
|
209 |
213 |
}
|
210 |
214 |
}
|
211 |
215 |
return defaultDescription;
|
212 |
216 |
}
|
213 |
217 |
|
214 |
|
private TaxonNode findTaxonNodeForDescription(SpecimenDescription description, DescriptiveDataSet descriptiveDataSet){
|
215 |
|
SpecimenOrObservationBase<?> specimen = description.getDescribedSpecimenOrObservation();
|
|
218 |
private TaxonNodeDto findTaxonNodeForDescription(DescriptionBaseDto description, DescriptiveDataSetBaseDto descriptiveDataSet){
|
|
219 |
UuidAndTitleCache<SpecimenOrObservationBase> specimen = description.getSpecimenDto();
|
216 |
220 |
//get taxon node
|
217 |
221 |
|
218 |
|
@SuppressWarnings({ "unchecked", "cast" })
|
|
222 |
|
|
223 |
return descriptionService.findTaxonNodeDtoForIndividualAssociation(specimen.getUuid(), descriptiveDataSet.getSubTreeFilter().iterator().next().getClassificationUUID());
|
219 |
224 |
//NOTE: don't remove cast as it does not compile on some systems
|
220 |
|
Set<IndividualsAssociation> associations = (Set<IndividualsAssociation>)descriptiveDataSet.getDescriptions()
|
221 |
|
.stream()
|
222 |
|
.flatMap(desc->desc.getElements().stream())// put all description element in one stream
|
223 |
|
.filter(element->element instanceof IndividualsAssociation)
|
224 |
|
.map(ia->(IndividualsAssociation)ia)
|
225 |
|
.collect(Collectors.toSet());
|
226 |
|
Classification classification = descriptiveDataSet.getTaxonSubtreeFilter().iterator().next().getClassification();
|
227 |
|
for (IndividualsAssociation individualsAssociation : associations) {
|
228 |
|
if(individualsAssociation.getAssociatedSpecimenOrObservation().equals(specimen)){
|
229 |
|
return ((TaxonDescription) individualsAssociation.getInDescription()).getTaxon().getTaxonNode(classification);
|
230 |
|
}
|
231 |
|
}
|
232 |
|
return null;
|
|
225 |
// List<DescriptionBaseDto> descDtos = descriptionService.loadDtos(descriptiveDataSet.getDescriptionUuids());
|
|
226 |
// descriptionService.
|
|
227 |
// Set<IndividualsAssociation> associations = descDtos
|
|
228 |
// .stream()
|
|
229 |
// .flatMap(desc->desc.getElements().stream())// put all description element in one stream
|
|
230 |
// .filter(element->element.get)
|
|
231 |
// .map(ia->(IndividualsAssociation)ia)
|
|
232 |
// .collect(Collectors.toSet());
|
|
233 |
// UUID classification = descriptiveDataSet.getSubTreeFilter().iterator().next().getClassificationUUID();
|
|
234 |
// for (IndividualsAssociation individualsAssociation : associations) {
|
|
235 |
// if(individualsAssociation.getAssociatedSpecimenOrObservation().equals(specimen)){
|
|
236 |
// return ((TaxonDescription) individualsAssociation.getInDescription()).getTaxon().getTaxonNode(classification);
|
|
237 |
// }
|
|
238 |
// }
|
|
239 |
// return null;
|
233 |
240 |
}
|
234 |
241 |
|
235 |
242 |
@Override
|
236 |
|
public TaxonRowWrapperDTO createTaxonRowWrapper(TaxonDescription taxonDescription, UUID descriptiveDataSetUuid) {
|
237 |
|
Classification classification = null;
|
238 |
|
DescriptionBaseDto description = DescriptionBaseDto.fromDescription(taxonDescription);
|
239 |
|
|
240 |
|
DescriptiveDataSet descriptiveDataSet = dao.load(descriptiveDataSetUuid, null);
|
241 |
|
Optional<TaxonNode> first = descriptiveDataSet.getTaxonSubtreeFilter().stream()
|
242 |
|
.filter(node->node.getClassification()!=null).findFirst();
|
243 |
|
Optional<Classification> classificationOptional = first.map(node->node.getClassification());
|
244 |
|
Set<DescriptionBaseDto> descriptions = new HashSet<>();
|
245 |
|
TaxonNodeDto nodeDto = null;
|
246 |
|
if(classificationOptional.isPresent()){
|
247 |
|
classification = classificationOptional.get();
|
248 |
|
nodeDto = taxonNodeService.dto(description.getTaxonDto().getUuid(), classification.getUuid());
|
249 |
|
}
|
250 |
|
|
251 |
|
return new TaxonRowWrapperDTO(description, nodeDto, descriptions);
|
|
243 |
public TaxonRowWrapperDTO createTaxonRowWrapper(UUID taxonDescriptionUuid, UUID descriptiveDataSetUuid) {
|
|
244 |
DescriptionBaseDto description = descriptionService.loadDto(taxonDescriptionUuid);
|
|
245 |
return createTaxonRowWrapper(description, descriptiveDataSetUuid);
|
252 |
246 |
}
|
253 |
247 |
|
254 |
248 |
@Override
|
255 |
249 |
@Transactional(readOnly=false)
|
256 |
|
public UpdateResult addRowWrapperToDataset(Collection<SpecimenRowWrapperDTO> wrappers, UUID datasetUuid){
|
|
250 |
public UpdateResult addRowWrapperToDataset(Collection<SpecimenRowWrapperDTO> wrappers, UUID datasetUuid, boolean addDatasetSource){
|
257 |
251 |
UpdateResult result = new UpdateResult();
|
258 |
252 |
DescriptiveDataSet dataSet = load(datasetUuid);
|
259 |
253 |
result.setCdmEntity(dataSet);
|
... | ... | |
278 |
272 |
td.addType(DescriptionType.INDIVIDUALS_ASSOCIATION);
|
279 |
273 |
td.setTitleCache("Specimens used by " + dataSet.getTitleCache() + " for " + getTaxonLabel(taxon), true);
|
280 |
274 |
return td;});
|
|
275 |
IndividualsAssociation association = null;
|
|
276 |
for (DescriptionElementBase el:taxonDescription.getElements()){
|
|
277 |
if (el instanceof IndividualsAssociation){
|
|
278 |
IndividualsAssociation indAss = (IndividualsAssociation)el;
|
|
279 |
if (indAss.getAssociatedSpecimenOrObservation().getUuid().equals(specimen.getUuid())){
|
|
280 |
association = indAss;
|
|
281 |
}
|
|
282 |
}
|
|
283 |
}
|
|
284 |
|
|
285 |
if (association == null){
|
|
286 |
association = IndividualsAssociation.NewInstance(specimen);
|
|
287 |
taxonDescription.addElement(association);
|
|
288 |
taxonService.saveOrUpdate(taxon);
|
|
289 |
result.addUpdatedObject(taxon);
|
|
290 |
}
|
|
291 |
|
281 |
292 |
|
282 |
|
IndividualsAssociation association = IndividualsAssociation.NewInstance(specimen);
|
283 |
|
taxonDescription.addElement(association);
|
284 |
|
taxonService.saveOrUpdate(taxon);
|
285 |
|
result.addUpdatedObject(taxon);
|
286 |
293 |
|
287 |
294 |
UUID specimenDescriptionUuid = wrapper.getDescription().getDescriptionUuid();
|
288 |
295 |
DescriptionBaseDto descriptionDto = wrapper.getDescription();
|
... | ... | |
356 |
363 |
}
|
357 |
364 |
}
|
358 |
365 |
}
|
|
366 |
if(addDatasetSource){
|
|
367 |
for (IdentifiableSource source: dataSet.getSources()) {
|
|
368 |
try {
|
|
369 |
specimenDescription.addSource(source.clone());
|
|
370 |
} catch (CloneNotSupportedException e) {
|
|
371 |
//nothing
|
|
372 |
}
|
|
373 |
}
|
|
374 |
|
|
375 |
}
|
359 |
376 |
|
360 |
377 |
//add specimen description to data set
|
361 |
378 |
specimenDescription.addDescriptiveDataSet(dataSet);
|
... | ... | |
377 |
394 |
}
|
378 |
395 |
}
|
379 |
396 |
|
380 |
|
private SpecimenRowWrapperDTO createSpecimenRowWrapper(SpecimenDescription description, UUID taxonNodeUuid,
|
|
397 |
private SpecimenRowWrapperDTO createSpecimenRowWrapper(DescriptionBaseDto description, UUID taxonNodeUuid,
|
381 |
398 |
UUID datasetUuid) {
|
382 |
|
TaxonNode taxonNode = taxonNodeService.load(taxonNodeUuid);
|
383 |
|
DescriptiveDataSet descriptiveDataSet = load(datasetUuid);
|
384 |
|
SpecimenOrObservationBase<?> specimen = CdmBase.deproxy(description.getDescribedSpecimenOrObservation());
|
|
399 |
TaxonNodeDto taxonNode = taxonNodeService.dto(taxonNodeUuid);
|
|
400 |
DescriptiveDataSetBaseDto descriptiveDataSet = getDescriptiveDataSetDtoByUuid(datasetUuid);
|
|
401 |
// UuidAndTitleCache<SpecimenOrObservationBase> specimen = description.getSpecimenDto();
|
|
402 |
SpecimenOrObservationBase specimen = occurrenceService.find(description.getSpecimenDto().getUuid());
|
|
403 |
|
385 |
404 |
//supplemental information
|
386 |
405 |
if(taxonNode==null){
|
387 |
406 |
taxonNode = findTaxonNodeForDescription(description, descriptiveDataSet);
|
... | ... | |
410 |
429 |
}
|
411 |
430 |
}
|
412 |
431 |
//get identifier
|
413 |
|
if(specimen.isInstanceOf(DerivedUnit.class)){
|
414 |
|
identifier = occurrenceService.getMostSignificantIdentifier(HibernateProxyHelper.deproxy(specimen, DerivedUnit.class));
|
415 |
|
}
|
|
432 |
|
|
433 |
identifier = occurrenceService.getMostSignificantIdentifier(specimen.getUuid());
|
416 |
434 |
//get country
|
417 |
435 |
if(fieldUnit != null && fieldUnit.getGatheringEvent() != null){
|
418 |
436 |
country = fieldUnit.getGatheringEvent().getCountry();
|
419 |
437 |
}
|
420 |
438 |
//get default taxon description
|
421 |
439 |
// TaxonDescription defaultTaxonDescription = findDefaultDescription(description.getUuid(), descriptiveDataSet.getUuid());
|
422 |
|
TaxonDescription defaultTaxonDescription = recurseDefaultDescription(taxonNode, descriptiveDataSet);
|
|
440 |
DescriptionBaseDto defaultTaxonDescription = recurseDefaultDescription(taxonNode, descriptiveDataSet);
|
423 |
441 |
TaxonRowWrapperDTO taxonRowWrapper = defaultTaxonDescription != null
|
424 |
|
? createTaxonRowWrapper(defaultTaxonDescription, descriptiveDataSet.getUuid()) : null;
|
|
442 |
? createTaxonRowWrapper(defaultTaxonDescription.getDescriptionUuid(), descriptiveDataSet.getUuid()) : null;
|
425 |
443 |
// use description not specimen for specimenRow
|
426 |
|
SpecimenRowWrapperDTO specimenRowWrapperDTO = new SpecimenRowWrapperDTO(DescriptionBaseDto.fromDescription(description), SpecimenOrObservationDTOFactory.fromEntity(specimen), specimen.getRecordBasis(), new TaxonNodeDto(taxonNode), fieldUnit, identifier, country);
|
|
444 |
SpecimenRowWrapperDTO specimenRowWrapperDTO = new SpecimenRowWrapperDTO(description, SpecimenOrObservationDTOFactory.fromEntity(specimen), specimen.getRecordBasis(), taxonNode, fieldUnit, identifier, country);
|
427 |
445 |
specimenRowWrapperDTO.setDefaultDescription(taxonRowWrapper);
|
428 |
446 |
return specimenRowWrapperDTO;
|
429 |
447 |
}
|
430 |
448 |
|
431 |
449 |
@Override
|
432 |
|
public SpecimenRowWrapperDTO createSpecimenRowWrapper(SpecimenDescription description, UUID descriptiveDataSetUuid){
|
|
450 |
public SpecimenRowWrapperDTO createSpecimenRowWrapper(DescriptionBaseDto description, UUID descriptiveDataSetUuid){
|
433 |
451 |
return createSpecimenRowWrapper(description, null, descriptiveDataSetUuid);
|
434 |
452 |
}
|
435 |
453 |
|
... | ... | |
437 |
455 |
public SpecimenRowWrapperDTO createSpecimenRowWrapper(UUID specimenUuid, UUID taxonNodeUuid, UUID descriptiveDataSetUuid){
|
438 |
456 |
|
439 |
457 |
SpecimenOrObservationBase<?> specimen = occurrenceService.load(specimenUuid);
|
440 |
|
SpecimenDescription specimenDescription = findSpecimenDescription(descriptiveDataSetUuid, specimen, true);
|
|
458 |
DescriptionBaseDto specimenDescription = findSpecimenDescription(descriptiveDataSetUuid, specimen, true);
|
441 |
459 |
return createSpecimenRowWrapper(specimenDescription, taxonNodeUuid, descriptiveDataSetUuid);
|
442 |
460 |
}
|
443 |
461 |
|
... | ... | |
451 |
469 |
return super.updateCachesImpl(clazz, stepSize, cacheStrategy, monitor);
|
452 |
470 |
}
|
453 |
471 |
|
454 |
|
private TaxonDescription findTaxonDescriptionByDescriptionType(DescriptiveDataSet dataSet, Taxon taxon, DescriptionType descriptionType){
|
455 |
|
Optional<TaxonDescription> first = taxon.getDescriptions().stream()
|
456 |
|
.filter(desc -> desc.getTypes().stream().anyMatch(type -> type.equals(descriptionType)))
|
457 |
|
.filter(desc -> dataSet.getDescriptions().contains(desc))
|
458 |
|
.findFirst();
|
459 |
|
if(first.isPresent()){
|
460 |
|
return HibernateProxyHelper.deproxy(descriptionService.load(first.get().getUuid(),
|
461 |
|
Arrays.asList("taxon", "descriptionElements", "descriptionElements.feature")), TaxonDescription.class);
|
462 |
|
}
|
463 |
|
return null;
|
464 |
|
}
|
465 |
|
|
|
472 |
// private TaxonDescription findTaxonDescriptionByDescriptionType(DescriptiveDataSetBaseDto dataSet, UUID taxonUuid, DescriptionType descriptionType){
|
|
473 |
// descriptionService.find
|
|
474 |
// Optional<TaxonDescription> first = taxon.getDescriptions().stream()
|
|
475 |
// .filter(desc -> desc.getTypes().stream().anyMatch(type -> type.equals(descriptionType)))
|
|
476 |
// .filter(desc -> dataSet.getDescriptions().contains(desc))
|
|
477 |
// .findFirst();
|
|
478 |
// if(first.isPresent()){
|
|
479 |
// return HibernateProxyHelper.deproxy(descriptionService.load(first.get().getUuid(),
|
|
480 |
// Arrays.asList("taxon", "descriptionElements", "descriptionElements.feature")), TaxonDescription.class);
|
|
481 |
// }
|
|
482 |
// return null;
|
|
483 |
// }
|
|
484 |
//
|
|
485 |
// @Override
|
|
486 |
// public TaxonDescription findTaxonDescriptionByDescriptionType(UUID dataSetUuid, UUID taxonNodeUuid, DescriptionType descriptionType){
|
|
487 |
// DescriptiveDataSet dataSet = load(dataSetUuid);
|
|
488 |
// TaxonNode taxonNode = taxonNodeService.load(taxonNodeUuid);
|
|
489 |
// return findTaxonDescriptionByDescriptionType(dataSet, taxonNode.getTaxon(), descriptionType);
|
|
490 |
// }
|
466 |
491 |
@Override
|
467 |
|
public TaxonDescription findTaxonDescriptionByDescriptionType(UUID dataSetUuid, UUID taxonNodeUuid, DescriptionType descriptionType){
|
468 |
|
DescriptiveDataSet dataSet = load(dataSetUuid);
|
469 |
|
TaxonNode taxonNode = taxonNodeService.load(taxonNodeUuid);
|
470 |
|
return findTaxonDescriptionByDescriptionType(dataSet, taxonNode.getTaxon(), descriptionType);
|
|
492 |
public DescriptionBaseDto getTaxonDescriptionForDescriptiveDataSetAndType(DescriptiveDataSetBaseDto dataSet, UUID taxonUuid, DescriptionType descriptionType){
|
|
493 |
Session session = getSession();
|
|
494 |
String queryString = "SELECT d.uuid FROM DescriptiveDataSet a JOIN a.descriptions as d JOIN d.taxon t WHERE t.uuid = :taxonuuid AND a.uuid = :dataSetUuid and d.type = :descriptionType";
|
|
495 |
|
|
496 |
Query query;
|
|
497 |
query = session.createQuery(queryString);
|
|
498 |
query.setParameter("taxonuuid", taxonUuid);
|
|
499 |
query.setParameter("dataSetUuid", dataSet.getUuid());
|
|
500 |
query.setParameter("descriptionType", descriptionType);
|
|
501 |
|
|
502 |
@SuppressWarnings("unchecked")
|
|
503 |
List<UUID> result = query.list();
|
|
504 |
List<DescriptionBaseDto> list = new ArrayList<>();
|
|
505 |
list.addAll(descriptionService.loadDtos(new HashSet(result)));
|
|
506 |
if (list.isEmpty()){
|
|
507 |
return null;
|
|
508 |
}
|
|
509 |
return list.get(0);
|
471 |
510 |
}
|
472 |
511 |
|
473 |
512 |
@Override
|
... | ... | |
627 |
666 |
newTaxonDescription.getTypes().add(descriptionType);
|
628 |
667 |
dataSet.addDescription(newTaxonDescription);
|
629 |
668 |
saveOrUpdate(dataSet);
|
630 |
|
return createTaxonRowWrapper(newTaxonDescription, dataSet.getUuid());
|
|
669 |
return createTaxonRowWrapper(newTaxonDescription.getUuid(), dataSet.getUuid());
|
631 |
670 |
}
|
632 |
671 |
|
633 |
672 |
@Override
|
... | ... | |
637 |
676 |
|
638 |
677 |
@Override
|
639 |
678 |
@Transactional(readOnly=false)
|
640 |
|
public SpecimenDescription findSpecimenDescription(UUID descriptiveDataSetUuid, SpecimenOrObservationBase specimen, boolean addDatasetSource){
|
641 |
|
DescriptiveDataSet dataSet = load(descriptiveDataSetUuid);
|
|
679 |
public DescriptionBaseDto findSpecimenDescription(UUID descriptiveDataSetUuid, SpecimenOrObservationBase specimen, boolean addDatasetSource){
|
|
680 |
DescriptiveDataSetBaseDto dataSet = this.getDescriptiveDataSetDtoByUuid(descriptiveDataSetUuid);
|
642 |
681 |
// SpecimenOrObservationBase specimen = occurrenceService.load(specimenUuid);
|
643 |
682 |
|
644 |
|
Set<? extends Feature> datasetFeatures = dataSet.getDescriptiveSystem().getDistinctTerms();
|
|
683 |
TermTreeDto datasetFeatures = dataSet.getDescriptiveSystem();
|
645 |
684 |
List<DescriptionElementBase> matchingDescriptionElements = new ArrayList<>();
|
646 |
685 |
|
647 |
686 |
for (SpecimenDescription specimenDescription : (Set<SpecimenDescription>) specimen.getDescriptions()) {
|
648 |
687 |
specimenDescription = (SpecimenDescription) descriptionService.load(specimenDescription.getUuid());
|
649 |
688 |
|
650 |
689 |
//check if description is already added to data set
|
651 |
|
if(dataSet.getDescriptions().contains(specimenDescription) ){
|
652 |
|
return specimenDescription;
|
|
690 |
if(dataSet.getDescriptionUuids().contains(specimenDescription.getUuid()) ){
|
|
691 |
return DescriptionBaseDto.fromDescription(specimenDescription);
|
653 |
692 |
}
|
654 |
693 |
|
655 |
694 |
//gather specimen description features and check for match with dataset features
|
... | ... | |
657 |
696 |
for (DescriptionElementBase specimenDescriptionElement : specimenDescription.getElements()) {
|
658 |
697 |
Feature feature = specimenDescriptionElement.getFeature();
|
659 |
698 |
specimenDescriptionFeatures.add(feature);
|
660 |
|
if(datasetFeatures.contains(feature) && RowWrapperDTO.hasData(specimenDescriptionElement)){
|
|
699 |
boolean contains = false;
|
|
700 |
for (TermDto featureDto:datasetFeatures.getTerms()){
|
|
701 |
if (featureDto.getUuid().equals(feature.getUuid())){
|
|
702 |
contains = true;
|
|
703 |
break;
|
|
704 |
}
|
|
705 |
}
|
|
706 |
if(contains && RowWrapperDTO.hasData(specimenDescriptionElement)){
|
661 |
707 |
matchingDescriptionElements.add(specimenDescriptionElement);
|
662 |
708 |
}
|
663 |
709 |
}
|
664 |
710 |
}
|
665 |
711 |
//Create new specimen description if description has not already been added to the dataset
|
666 |
712 |
SpecimenDescription newDesription = SpecimenDescription.NewInstance(specimen);
|
667 |
|
newDesription.setTitleCache("Dataset "+dataSet.getLabel()+": "+newDesription.generateTitle(), true); //$NON-NLS-2$
|
|
713 |
newDesription.setTitleCache("Dataset "+dataSet.getTitleCache()+": "+newDesription.generateTitle(), true); //$NON-NLS-2$
|
668 |
714 |
|
669 |
715 |
//check for equals description element (same feature and same values)
|
670 |
716 |
Map<Feature, List<DescriptionElementBase>> featureToElementMap = new HashMap<>();
|
... | ... | |
720 |
766 |
}
|
721 |
767 |
|
722 |
768 |
//add sources of data set
|
723 |
|
if(addDatasetSource){
|
724 |
|
dataSet.getSources().forEach(source->{
|
725 |
|
try {
|
726 |
|
newDesription.addSource(source.clone());
|
727 |
|
} catch (CloneNotSupportedException e) {
|
728 |
|
//nothing
|
729 |
|
}
|
730 |
|
});
|
731 |
|
}
|
732 |
|
return newDesription;
|
|
769 |
// if(addDatasetSource){
|
|
770 |
// dataSet.getSources().forEach(source->{
|
|
771 |
// try {
|
|
772 |
// newDesription.addSource(source.clone());
|
|
773 |
// } catch (CloneNotSupportedException e) {
|
|
774 |
// //nothing
|
|
775 |
// }
|
|
776 |
// });
|
|
777 |
// }
|
|
778 |
return DescriptionBaseDto.fromDescription(newDesription);
|
733 |
779 |
|
734 |
780 |
}
|
735 |
781 |
|
... | ... | |
917 |
963 |
}
|
918 |
964 |
|
919 |
965 |
@Override
|
920 |
|
public TaxonRowWrapperDTO createTaxonRowWrapper(UUID taxonDescriptionUuid, UUID descriptiveDataSetUuid) {
|
|
966 |
public TaxonRowWrapperDTO createTaxonRowWrapper(DescriptionBaseDto description, UUID descriptiveDataSetUuid) {
|
921 |
967 |
Classification classification = null;
|
922 |
|
DescriptionBaseDto description = descriptionService.loadDto(taxonDescriptionUuid);
|
923 |
|
|
924 |
968 |
DescriptiveDataSet descriptiveDataSet = dao.load(descriptiveDataSetUuid, null);
|
925 |
969 |
Optional<TaxonNode> first = descriptiveDataSet.getTaxonSubtreeFilter().stream()
|
926 |
970 |
.filter(node->node.getClassification()!=null).findFirst();
|
... | ... | |
935 |
979 |
return new TaxonRowWrapperDTO(description, nodeDto, descriptions);
|
936 |
980 |
}
|
937 |
981 |
|
|
982 |
// @Override
|
|
983 |
// public DescriptionBaseDto findTaxonDescriptionByDescriptionType(UUID dataSetUuid, UUID taxonNodeUuid, DescriptionType descriptionType){
|
|
984 |
// DescriptiveDataSetBaseDto dataSet = getDescriptiveDataSetDtoByUuid(dataSetUuid);
|
|
985 |
// TaxonNode taxonNode = taxonNodeService.load(taxonNodeUuid);
|
|
986 |
// return findTaxonDescriptionByDescriptionType(dataSet, taxonNode.getTaxon(), descriptionType);
|
|
987 |
// }
|
|
988 |
|
938 |
989 |
}
|
ref #9842: first steps removing objects in dto creation