Revision 3ed10837
Added by Katja Luther over 2 years ago
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/DescriptiveDataSetService.java | ||
---|---|---|
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; |
|
20 | 18 |
import org.springframework.beans.factory.annotation.Autowired; |
21 | 19 |
import org.springframework.stereotype.Service; |
22 | 20 |
import org.springframework.transaction.annotation.Transactional; |
... | ... | |
76 | 74 |
import eu.etaxonomy.cdm.persistence.dto.SpecimenNodeWrapper; |
77 | 75 |
import eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto; |
78 | 76 |
import eu.etaxonomy.cdm.persistence.dto.TermDto; |
79 |
import eu.etaxonomy.cdm.persistence.dto.TermTreeDto; |
|
80 | 77 |
import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache; |
81 | 78 |
import eu.etaxonomy.cdm.strategy.cache.common.IIdentifiableEntityCacheStrategy; |
82 | 79 |
import eu.etaxonomy.cdm.strategy.generate.PolytomousKeyGenerator; |
... | ... | |
246 | 243 |
public TaxonRowWrapperDTO createTaxonRowWrapper(TaxonDescription taxonDescription, UUID descriptiveDataSetUuid) { |
247 | 244 |
TaxonNode taxonNode = null; |
248 | 245 |
Classification classification = null; |
249 |
// TaxonDescription description = (TaxonDescription) descriptionService.loadDto(taxonDescriptionUuid, |
|
250 |
// Arrays.asList("taxon", "descriptionElements", "descriptionElements.feature")); |
|
251 |
// DescriptionBaseDto description = descriptionService.loadDto(taxonDescriptionUuid); |
|
252 | 246 |
DescriptionBaseDto description = DescriptionBaseDto.fromDescription(taxonDescription); |
253 | 247 |
|
254 | 248 |
DescriptiveDataSet descriptiveDataSet = dao.load(descriptiveDataSetUuid, null); |
... | ... | |
259 | 253 |
TaxonNodeDto nodeDto = null; |
260 | 254 |
if(classificationOptional.isPresent()){ |
261 | 255 |
classification = classificationOptional.get(); |
262 |
// Taxon taxon = (Taxon) taxonService.load(description.getTaxonDto().getId(), Arrays.asList("taxonNodes", "taxonNodes.classification")); |
|
263 | 256 |
nodeDto = taxonNodeService.dto(description.getTaxonDto().getUuid(), classification.getUuid()); |
264 |
// taxonNode = taxon.getTaxonNode(classification); |
|
265 |
|
|
266 |
// for (DescriptionBase desc: taxon.getDescriptions()){ |
|
267 |
// descriptions.add(DescriptionBaseDto.fromDescription(desc)); |
|
268 |
// } |
|
269 | 257 |
} |
270 |
//TODO: fix getting descriptions |
|
271 |
// descriptions = new HashSet<>(descriptionService.loadDtosForTaxon(description.getTaxonDto().getUuid())); |
|
272 | 258 |
|
273 | 259 |
return new TaxonRowWrapperDTO(description, nodeDto, descriptions); |
274 | 260 |
} |
... | ... | |
335 | 321 |
if (elementDto instanceof QuantitativeDataDto){ |
336 | 322 |
eu.etaxonomy.cdm.model.description.Character feature = DefinedTermBase.getTermByClassAndUUID(eu.etaxonomy.cdm.model.description.Character.class, elementDto.getFeatureUuid()); |
337 | 323 |
QuantitativeData data = QuantitativeData.NewInstance(feature); |
338 |
MeasurementUnit unit = DefinedTermBase.getTermByClassAndUUID(MeasurementUnit.class, ((QuantitativeDataDto) elementDto).getMeasurementUnit().getUuid()); |
|
339 |
data.setUnit(unit); |
|
324 |
if (((QuantitativeDataDto) elementDto).getMeasurementUnit() != null){ |
|
325 |
MeasurementUnit unit = DefinedTermBase.getTermByClassAndUUID(MeasurementUnit.class, ((QuantitativeDataDto) elementDto).getMeasurementUnit().getUuid()); |
|
326 |
data.setUnit(unit); |
|
327 |
} |
|
328 |
|
|
340 | 329 |
for (StatisticalMeasurementValueDto stateDto:((QuantitativeDataDto) elementDto).getValues()){ |
341 | 330 |
StatisticalMeasure statMeasure = DefinedTermBase.getTermByClassAndUUID(StatisticalMeasure.class, stateDto.getType().getUuid()); |
342 | 331 |
StatisticalMeasurementValue value = StatisticalMeasurementValue.NewInstance(statMeasure, stateDto.getValue()); |
... | ... | |
368 | 357 |
if (elementDto instanceof QuantitativeDataDto){ |
369 | 358 |
eu.etaxonomy.cdm.model.description.Character feature = DefinedTermBase.getTermByClassAndUUID(eu.etaxonomy.cdm.model.description.Character.class, elementDto.getFeatureUuid()); |
370 | 359 |
QuantitativeData data = QuantitativeData.NewInstance(feature); |
371 |
MeasurementUnit unit = DefinedTermBase.getTermByClassAndUUID(MeasurementUnit.class, ((QuantitativeDataDto) elementDto).getMeasurementUnit().getUuid()); |
|
372 |
data.setUnit(unit); |
|
360 |
if (((QuantitativeDataDto) elementDto).getMeasurementUnit() != null){ |
|
361 |
MeasurementUnit unit = DefinedTermBase.getTermByClassAndUUID(MeasurementUnit.class, ((QuantitativeDataDto) elementDto).getMeasurementUnit().getUuid()); |
|
362 |
data.setUnit(unit); |
|
363 |
} |
|
364 |
|
|
373 | 365 |
for (StatisticalMeasurementValueDto stateDto:((QuantitativeDataDto) elementDto).getValues()){ |
374 | 366 |
StatisticalMeasure statMeasure = DefinedTermBase.getTermByClassAndUUID(StatisticalMeasure.class, stateDto.getType().getUuid()); |
375 | 367 |
StatisticalMeasurementValue value = StatisticalMeasurementValue.NewInstance(statMeasure, stateDto.getValue()); |
... | ... | |
963 | 955 |
|
964 | 956 |
@Override |
965 | 957 |
public DescriptiveDataSetBaseDto getDescriptiveDataSetDtoByUuid(UUID uuid) { |
966 |
String queryString = DescriptiveDataSetBaseDto.getDescriptiveDataSetDtoSelect() |
|
967 |
+ " WHERE a.uuid = :uuid" |
|
968 |
+ " ORDER BY a.titleCache"; |
|
969 |
Query query = getSession().createQuery(queryString); |
|
970 |
query.setParameter("uuid", uuid); |
|
971 |
|
|
972 |
@SuppressWarnings("unchecked") |
|
973 |
List<Object[]> result = query.list(); |
|
974 |
|
|
975 |
List<DescriptiveDataSetBaseDto> list = DescriptiveDataSetBaseDto.descriptiveDataSetBaseDtoListFrom(result); |
|
976 |
UUID descriptiveSystemUuid = null; |
|
977 |
UUID minRankUuid = null; |
|
978 |
UUID maxRankUuid = null; |
|
979 |
if (result != null && !result.isEmpty()){ |
|
980 |
Object[] descriptiveDataSetResult = result.get(0); |
|
981 |
descriptiveSystemUuid = (UUID)descriptiveDataSetResult[4]; |
|
982 |
minRankUuid = (UUID)descriptiveDataSetResult[5]; |
|
983 |
maxRankUuid = (UUID)descriptiveDataSetResult[6]; |
|
984 |
}else{ |
|
985 |
return null; |
|
986 |
} |
|
987 |
//get descriptiveSystem |
|
988 |
DescriptiveDataSetBaseDto dto = list.get(0); |
|
989 |
if (descriptiveSystemUuid != null){ |
|
990 |
TermTreeDto treeDto = termTreeService.getTermTreeDtoByUuid(descriptiveSystemUuid); |
|
991 |
dto.setDescriptiveSystem(treeDto); |
|
992 |
} |
|
993 |
//get taxon nodes |
|
994 |
List<UUID> nodeUuids = getNodeUuidsForDescriptiveDataSet(uuid); |
|
995 |
List<TaxonNodeDto> nodeDtos = taxonNodeService.getTaxonNodeDtos(nodeUuids); |
|
996 |
Set<TaxonNodeDto> nodeSet = new HashSet<>(nodeDtos); |
|
997 |
dto.setSubTreeFilter(nodeSet); |
|
998 |
|
|
999 |
List<UUID> descriptionUuidList = getDescriptionUuidsForDescriptiveDataSet(uuid); |
|
1000 |
Set<UUID> descriptionUuids = new HashSet<>(descriptionUuidList); |
|
1001 |
dto.setDescriptionUuids(descriptionUuids); |
|
1002 |
|
|
1003 |
TermDto minRank = termDao.getTermDto(minRankUuid); |
|
1004 |
TermDto maxRank = termDao.getTermDto(maxRankUuid); |
|
1005 |
dto.setMaxRank(maxRank); |
|
1006 |
dto.setMinRank(minRank); |
|
1007 |
return dto; |
|
1008 |
} |
|
1009 |
|
|
1010 |
private List<UUID> getNodeUuidsForDescriptiveDataSet(UUID uuid) { |
|
1011 |
Session session = getSession(); |
|
1012 |
|
|
1013 |
String queryString = "SELECT t.uuid FROM DescriptiveDataSet a JOIN a.taxonSubtreeFilter as t WHERE a.uuid = :uuid"; |
|
1014 |
|
|
1015 |
|
|
1016 |
Query query; |
|
1017 |
query = session.createQuery(queryString); |
|
1018 |
query.setParameter("uuid", uuid); |
|
1019 |
|
|
1020 |
|
|
1021 |
@SuppressWarnings("unchecked") |
|
1022 |
List<UUID> result = query.list(); |
|
1023 |
List<UUID> list = new ArrayList<>(); |
|
1024 |
for(UUID object : result){ |
|
1025 |
list.add(object); |
|
1026 |
} |
|
1027 |
|
|
1028 |
return list; |
|
1029 |
} |
|
1030 |
|
|
1031 |
private List<UUID> getDescriptionUuidsForDescriptiveDataSet(UUID uuid) { |
|
1032 |
Session session = getSession(); |
|
1033 |
|
|
1034 |
String queryString = "SELECT t.uuid FROM DescriptiveDataSet a JOIN a.descriptions as t WHERE a.uuid = :uuid"; |
|
1035 |
|
|
1036 |
|
|
1037 |
Query query; |
|
1038 |
query = session.createQuery(queryString); |
|
1039 |
query.setParameter("uuid", uuid); |
|
1040 |
|
|
1041 |
|
|
1042 |
@SuppressWarnings("unchecked") |
|
1043 |
List<UUID> result = query.list(); |
|
1044 |
List<UUID> list = new ArrayList<>(); |
|
1045 |
for(UUID object : result){ |
|
1046 |
list.add(object); |
|
1047 |
} |
|
1048 |
|
|
1049 |
return list; |
|
958 |
return dao.getDescriptiveDataSetDtoByUuid(uuid); |
|
1050 | 959 |
} |
1051 | 960 |
|
1052 | 961 |
} |
Also available in: Unified diff
ref #9772: code cleaning - move hql code to persistence