Revision 7d7ffcf0
Added by Andreas Kohlbecker almost 3 years ago
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/controller/iiif/ManifestComposer.java | ||
---|---|---|
15 | 15 |
import java.util.HashMap; |
16 | 16 |
import java.util.List; |
17 | 17 |
import java.util.Map; |
18 |
import java.util.Objects; |
|
19 |
import java.util.Optional; |
|
18 | 20 |
import java.util.stream.Collectors; |
19 | 21 |
|
20 | 22 |
import org.apache.http.HttpException; |
... | ... | |
142 | 144 |
List<Canvas> canvases = null; |
143 | 145 |
try { |
144 | 146 |
canvases = entityMediaContext.getMedia().parallelStream().map(m -> { |
145 |
try { |
|
146 |
return createCanvas(onEntitiyType, onEntityUuid, m); |
|
147 |
} catch (IOException e) { |
|
148 |
throw new RuntimeException(e); |
|
149 |
} |
|
150 |
}).collect(Collectors.toList()); |
|
147 |
try { |
|
148 |
return createCanvas(onEntitiyType, onEntityUuid, m); |
|
149 |
} catch (IOException e) { |
|
150 |
throw new RuntimeException(e); |
|
151 |
} |
|
152 |
}) |
|
153 |
.filter(Optional::isPresent) |
|
154 |
.map(Optional::get) |
|
155 |
.collect(Collectors.toList()); |
|
151 | 156 |
} catch(RuntimeException re) { |
152 | 157 |
// re-throw IOException from lambda expression |
153 | 158 |
throw new IOException(re.getCause()); |
... | ... | |
175 | 180 |
return manifest; |
176 | 181 |
} |
177 | 182 |
|
178 |
public Canvas createCanvas(String onEntitiyType, String onEntityUuid, Media media) throws IOException {
|
|
183 |
public Optional<Canvas> createCanvas(String onEntitiyType, String onEntityUuid, Media media) throws IOException {
|
|
179 | 184 |
Canvas canvas; |
185 |
|
|
180 | 186 |
MediaRepresentation thumbnailRepresentation = mediaTools.processAndFindBestMatchingRepresentation(media, null, null, 100, 100, thumbnailMimetypes, MediaUtils.MissingValueStrategy.MAX); |
181 | 187 |
MediaRepresentation fullSizeRepresentation = mediaTools.processAndFindBestMatchingRepresentation(media, null, null, Integer.MAX_VALUE, Integer.MAX_VALUE, null, MediaUtils.MissingValueStrategy.MAX); |
182 | 188 |
// MediaRepresentation fullSizeRepresentation = MediaUtils.findBestMatchingRepresentation(media, null, null, Integer.MAX_VALUE, Integer.MAX_VALUE, null, MediaUtils.MissingValueStrategy.MAX); |
... | ... | |
186 | 192 |
logger.debug("thumbnailRepresentation: " + thumbnailRepresentation.getParts().get(0).getUri()); |
187 | 193 |
} |
188 | 194 |
|
195 |
List<ImageContent> thumbnailImageContents; |
|
196 |
List<ImageContent> fullSizeImageContents; |
|
189 | 197 |
// FIXME the below only makes sense if the media is an Image!!!!! |
190 |
List<ImageContent> fullSizeImageContents = representationPartsToImageContent(fullSizeRepresentation); |
|
198 |
if(fullSizeRepresentation != null) { |
|
199 |
fullSizeImageContents = representationPartsToImageContent(fullSizeRepresentation); |
|
200 |
} else { |
|
201 |
fullSizeImageContents = new ArrayList<>(0); |
|
202 |
} |
|
191 | 203 |
|
192 |
List<ImageContent> thumbnailImageContents; |
|
193 |
if(fullSizeRepresentation.equals(thumbnailRepresentation)){ |
|
204 |
if(Objects.equals(fullSizeRepresentation, thumbnailRepresentation)){ |
|
194 | 205 |
thumbnailImageContents = fullSizeImageContents; |
195 | 206 |
} else { |
196 | 207 |
thumbnailImageContents = representationPartsToImageContent(thumbnailRepresentation); |
197 | 208 |
} |
198 | 209 |
|
210 |
if(fullSizeRepresentation == null) { |
|
211 |
return Optional.empty(); |
|
212 |
} |
|
213 |
|
|
199 | 214 |
canvas = new Canvas(iiifID(onEntitiyType, onEntityUuid, Canvas.class, "media-" + media.getUuid())); |
200 | 215 |
for(Language lang : media.getAllTitles().keySet()){ |
201 | 216 |
LanguageString titleLocalized = media.getAllTitles().get(lang); |
... | ... | |
244 | 259 |
canvas = addAttributionAndLicense(media, canvas, mediaMetadata); |
245 | 260 |
orderMedatadaItems(canvas); |
246 | 261 |
canvas.addMetadata(mediaMetadata.toArray(new MetadataEntry[mediaMetadata.size()])); |
247 |
return canvas;
|
|
262 |
return Optional.of(canvas);
|
|
248 | 263 |
} |
249 | 264 |
|
250 | 265 |
/** |
Also available in: Unified diff
fix #9368 NullPointerException (NPE) in ManifestComposer