2 * Copyright (C) 2021 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
9 package eu
.etaxonomy
.cdm
.api
.service
.media
;
11 import java
.io
.IOException
;
12 import java
.util
.ArrayList
;
13 import java
.util
.List
;
15 import org
.apache
.http
.HttpException
;
16 import org
.apache
.logging
.log4j
.LogManager
;import org
.apache
.logging
.log4j
.Logger
;
17 import org
.springframework
.stereotype
.Component
;
19 import eu
.etaxonomy
.cdm
.common
.URI
;
20 import eu
.etaxonomy
.cdm
.common
.media
.CdmImageInfo
;
23 * @author a.kohlbecker
27 public class MediaInfoFactory
implements IMediaInfoFactory
{
29 private static final Logger logger
= LogManager
.getLogger(MediaInfoFactory
.class);
32 * TODO needs to be managed in CDM PREFERENCES per service and version.
34 * ./MediaInfoService/1.0/ --> MediaUriTransformation
36 private List
<MediaUriTransformation
> mediaInfoService_1_0_Transformations
= new ArrayList
<>();
38 public MediaInfoFactory() {
39 mediaInfoService_1_0_Transformations
.addAll(DefaultMediaTransformations
.bgbmMediaMetadataService());
43 * This method only exists due to performance issues for cases when
44 * the {@link MediaInfoFileReader} to reduce the overhead imposed by reading
45 * the image metadata from the file itself.
48 public CdmImageInfo
cdmImageInfo(URI imageUri
, boolean forceMetaData
) throws IOException
, HttpException
{
50 List
<URI
> metadataServiceURIs
= applyURITransformations(imageUri
);
51 if(!metadataServiceURIs
.isEmpty()) {
52 // :-) Hooray, we can get the metadata from the web service, this is going to be snappy
54 return new MediaInfoServiceReader(imageUri
, metadataServiceURIs
.get(0))
57 } catch (Exception e
) {
58 logger
.warn("Meta data could not be read from meta data service ("+e
.getMessage()+"): " + imageUri
.toString());
59 //if an exception occurs read data from original file
63 // :-( need to use the files reader
64 MediaInfoFileReader mediaReader
= new MediaInfoFileReader(imageUri
).readBaseInfo();
65 AbstactMediaMetadataReader reader
= forceMetaData ? mediaReader
.readMetaData() : mediaReader
;
66 return reader
.getCdmImageInfo();
70 protected List
<URI
> applyURITransformations(URI imageUri
) {
71 MediaUriTransformationProcessor processor
= new MediaUriTransformationProcessor();
72 processor
.addAll(mediaInfoService_1_0_Transformations
);
73 List
<URI
> metadataServiceURIs
= processor
.applyTo(imageUri
);
74 return metadataServiceURIs
;