Revision e5fafd55
Added by Katja Luther over 1 year ago
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/OccurrenceServiceImpl.java | ||
---|---|---|
213 | 213 |
); |
214 | 214 |
return new DefaultPagerImpl<>(pageNumber, numberOfResults, pageSize, mediaDTOs); |
215 | 215 |
} |
216 |
|
|
216 |
@Override |
|
217 |
public Pager<Media> getMediaInHierarchy(SpecimenOrObservationBase<?> rootOccurence, boolean collectOriginalMedia, boolean collectDerivateMedia, Integer pageSize, |
|
218 |
Integer pageNumber, List<String> propertyPaths) { |
|
219 |
List<Media> media = new ArrayList<>(); |
|
220 |
//media specimens |
|
221 |
if(rootOccurence.isInstanceOf(MediaSpecimen.class)){ |
|
222 |
MediaSpecimen mediaSpecimen = HibernateProxyHelper.deproxy(rootOccurence, MediaSpecimen.class); |
|
223 |
media.add(mediaSpecimen.getMediaSpecimen()); |
|
224 |
} |
|
225 |
// pherograms & gelPhotos |
|
226 |
if (rootOccurence.isInstanceOf(DnaSample.class)) { |
|
227 |
DnaSample dnaSample = CdmBase.deproxy(rootOccurence, DnaSample.class); |
|
228 |
Set<Sequence> sequences = dnaSample.getSequences(); |
|
229 |
//we do show only those gelPhotos which lead to a consensus sequence |
|
230 |
for (Sequence sequence : sequences) { |
|
231 |
Set<Media> dnaRelatedMedia = new HashSet<>(); |
|
232 |
for (SingleRead singleRead : sequence.getSingleReads()){ |
|
233 |
AmplificationResult amplification = singleRead.getAmplificationResult(); |
|
234 |
dnaRelatedMedia.add(amplification.getGelPhoto()); |
|
235 |
dnaRelatedMedia.add(singleRead.getPherogram()); |
|
236 |
dnaRelatedMedia.remove(null); |
|
237 |
} |
|
238 |
media.addAll(dnaRelatedMedia); |
|
239 |
} |
|
240 |
} |
|
241 |
if(rootOccurence.isInstanceOf(DerivedUnit.class)){ |
|
242 |
DerivedUnit derivedUnit = HibernateProxyHelper.deproxy(rootOccurence, DerivedUnit.class); |
|
243 |
if (collectDerivateMedia) { |
|
244 |
for (DerivationEvent derivationEvent : derivedUnit.getDerivationEvents()) { |
|
245 |
for (DerivedUnit childDerivative : derivationEvent.getDerivatives()) { |
|
246 |
//collectOriginalMedia should only called for the first derived unit |
|
247 |
media.addAll(getMediaInHierarchy(childDerivative, false, true, pageSize, pageNumber, propertyPaths).getRecords()); |
|
248 |
} |
|
249 |
} |
|
250 |
} |
|
251 |
if (collectOriginalMedia) { |
|
252 |
for (SpecimenOrObservationBase original : derivedUnit.getOriginals()) { |
|
253 |
//collect media to the top of the tree |
|
254 |
media.addAll(getMediaInHierarchy(original, true, false, pageSize, pageNumber, propertyPaths).getRecords()); |
|
255 |
} |
|
256 |
} |
|
257 |
} |
|
258 |
|
|
259 |
|
|
260 |
return new DefaultPagerImpl<>(pageNumber, Long.valueOf(media.size()), pageSize, media); |
|
261 |
} |
|
262 |
|
|
263 |
|
|
217 | 264 |
@Override |
218 | 265 |
public Pager<Media> getMediaInHierarchy(SpecimenOrObservationBase<?> rootOccurence, Integer pageSize, |
219 | 266 |
Integer pageNumber, List<String> propertyPaths) { |
220 |
|
|
221 |
List<Media> media = new ArrayList<>(); |
|
222 |
//media specimens |
|
223 |
if(rootOccurence.isInstanceOf(MediaSpecimen.class)){ |
|
224 |
MediaSpecimen mediaSpecimen = HibernateProxyHelper.deproxy(rootOccurence, MediaSpecimen.class); |
|
225 |
media.add(mediaSpecimen.getMediaSpecimen()); |
|
226 |
} |
|
227 |
// pherograms & gelPhotos |
|
228 |
if (rootOccurence.isInstanceOf(DnaSample.class)) { |
|
229 |
DnaSample dnaSample = CdmBase.deproxy(rootOccurence, DnaSample.class); |
|
230 |
Set<Sequence> sequences = dnaSample.getSequences(); |
|
231 |
//we do show only those gelPhotos which lead to a consensus sequence |
|
232 |
for (Sequence sequence : sequences) { |
|
233 |
Set<Media> dnaRelatedMedia = new HashSet<>(); |
|
234 |
for (SingleRead singleRead : sequence.getSingleReads()){ |
|
235 |
AmplificationResult amplification = singleRead.getAmplificationResult(); |
|
236 |
dnaRelatedMedia.add(amplification.getGelPhoto()); |
|
237 |
dnaRelatedMedia.add(singleRead.getPherogram()); |
|
238 |
dnaRelatedMedia.remove(null); |
|
239 |
} |
|
240 |
media.addAll(dnaRelatedMedia); |
|
241 |
} |
|
242 |
} |
|
243 |
if(rootOccurence.isInstanceOf(DerivedUnit.class)){ |
|
244 |
DerivedUnit derivedUnit = HibernateProxyHelper.deproxy(rootOccurence, DerivedUnit.class); |
|
245 |
for (DerivationEvent derivationEvent : derivedUnit.getDerivationEvents()) { |
|
246 |
for (DerivedUnit childDerivative : derivationEvent.getDerivatives()) { |
|
247 |
media.addAll(getMediaInHierarchy(childDerivative, pageSize, pageNumber, propertyPaths).getRecords()); |
|
248 |
} |
|
249 |
} |
|
250 |
} |
|
251 |
return new DefaultPagerImpl<>(pageNumber, Long.valueOf(media.size()), pageSize, media); |
|
267 |
return getMediaInHierarchy(rootOccurence, false, true, pageSize, |
|
268 |
pageNumber, propertyPaths); |
|
269 |
|
|
252 | 270 |
} |
253 | 271 |
|
254 | 272 |
@Override |
Also available in: Unified diff
ref #10156: add parameter for collecting original media