Revision 8e996490
Added by Andreas Kohlbecker almost 4 years ago
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/media/MediaUtils.java | ||
---|---|---|
22 | 22 |
private static final Logger logger = Logger.getLogger(MediaUtils.class); |
23 | 23 |
|
24 | 24 |
|
25 |
/** |
|
26 |
* |
|
27 |
* @param media |
|
28 |
* @param representationPartType |
|
29 |
* @param size |
|
30 |
* @param height |
|
31 |
* @param widthOrDuration |
|
32 |
* @param mimeTypes |
|
33 |
* @param missingValStrategy |
|
34 |
* @return |
|
35 |
*/ |
|
36 | 25 |
public static MediaRepresentation findBestMatchingRepresentation(Media media, |
37 | 26 |
Class<? extends MediaRepresentationPart> representationPartType, Integer size, Integer height, |
38 | 27 |
Integer widthOrDuration, String[] mimeTypes, MissingValueStrategy missingValStrategy){ |
39 | 28 |
|
40 | 29 |
// find best matching representations of each media |
30 |
Set<MediaRepresentation> representations = media.getRepresentations(); |
|
31 |
return findBestMatchingRepresentation(representations, representationPartType, size, height, widthOrDuration, |
|
32 |
mimeTypes, missingValStrategy); |
|
33 |
} |
|
34 |
|
|
35 |
public static MediaRepresentation findBestMatchingRepresentation( |
|
36 |
Set<MediaRepresentation> representations, Class<? extends MediaRepresentationPart> representationPartType, Integer size, |
|
37 |
Integer height, Integer widthOrDuration, String[] mimeTypes, |
|
38 |
MissingValueStrategy missingValStrategy) { |
|
39 |
|
|
41 | 40 |
SortedMap<Long, MediaRepresentation> prefRepresentations |
42 |
= filterAndOrderMediaRepresentations(media.getRepresentations(), representationPartType, mimeTypes,
|
|
41 |
= filterAndOrderMediaRepresentations(representations, representationPartType, mimeTypes,
|
|
43 | 42 |
size, widthOrDuration, height, missingValStrategy); |
44 | 43 |
if(prefRepresentations.size() > 0){ |
45 | 44 |
MediaRepresentation prefOne = prefRepresentations.get(prefRepresentations.firstKey()); |
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/controller/util/MediaToolbox.java | ||
---|---|---|
9 | 9 |
package eu.etaxonomy.cdm.remote.controller.util; |
10 | 10 |
|
11 | 11 |
import java.util.ArrayList; |
12 |
import java.util.HashSet; |
|
12 | 13 |
import java.util.List; |
13 | 14 |
import java.util.Map; |
15 |
import java.util.Set; |
|
14 | 16 |
|
15 | 17 |
import org.apache.log4j.Logger; |
16 | 18 |
import org.springframework.beans.factory.annotation.Autowired; |
... | ... | |
86 | 88 |
MediaUriTransformationProcessor mediaTransformationProcessor = new MediaUriTransformationProcessor(); |
87 | 89 |
mediaTransformationProcessor.addAll(readTransformations()); |
88 | 90 |
|
89 |
List<MediaRepresentation> newReprs = new ArrayList<>();
|
|
91 |
Set<MediaRepresentation> newReprs = new HashSet<>();
|
|
90 | 92 |
for (MediaRepresentation repr : media.getRepresentations()) { |
91 | 93 |
for (MediaRepresentationPart part : repr.getParts()) { |
92 | 94 |
newReprs.addAll(mediaTransformationProcessor.makeNewMediaRepresentationsFor(part)); |
93 | 95 |
} |
94 | 96 |
} |
95 |
for(MediaRepresentation r : newReprs) { |
|
96 |
media.addRepresentation(r); |
|
97 |
} |
|
98 |
|
|
99 |
return MediaUtils.findBestMatchingRepresentation(media, type, size, height, widthOrDuration, mimeTypes, |
|
100 |
missingValStrategy); |
|
97 |
newReprs.addAll(media.getRepresentations()); |
|
98 |
return MediaUtils.findBestMatchingRepresentation(newReprs, type, size, height, widthOrDuration, mimeTypes, missingValStrategy); |
|
101 | 99 |
} |
102 | 100 |
|
103 | 101 |
@Override |
... | ... | |
111 | 109 |
for (Media media : mediaRepresentationMap.keySet()) { |
112 | 110 |
media.getRepresentations().clear(); |
113 | 111 |
media.addRepresentation(mediaRepresentationMap.get(media)); |
112 |
media.setId(0); // prevent from persisting the media entity accidentally |
|
114 | 113 |
filteredMedia.add(media); |
115 | 114 |
} |
116 | 115 |
return filteredMedia; |
cdmlib-remote/src/test/resources/eu/etaxonomy/cdm/applicationContext-test.xml | ||
---|---|---|
13 | 13 |
<context:property-override location="classpath:eu/etaxonomy/cdm/override.properties"/> |
14 | 14 |
|
15 | 15 |
<!-- |
16 |
This applicationContext is not a full cdm application context. It only covers the remote compoents |
|
16 |
This applicationContext is not a full cdm application context. It only covers the remote components
|
|
17 | 17 |
without service and persistence. The cacheManager is usually provided via a Java config class in |
18 | 18 |
eu/etaxonomy/cdm/service/api/conf which cannot use in this context. Therefore we are |
19 | 19 |
using the EhCacheManagerFactoryBean here to initialize the cacheManager bean. |
Also available in: Unified diff
ref #9134 preventing persistance of volatile modified media