ref #9607 introducing IMediaInfoFactory interface
[cdmlib.git] / cdmlib-services / src / main / java / eu / etaxonomy / cdm / api / service / media / MediaInfoFactory.java
1 /**
2 * Copyright (C) 2021 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
5 *
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.
8 */
9 package eu.etaxonomy.cdm.api.service.media;
10
11 import java.io.IOException;
12 import java.util.ArrayList;
13 import java.util.List;
14
15 import org.apache.http.HttpException;
16 import org.springframework.stereotype.Component;
17
18 import eu.etaxonomy.cdm.common.URI;
19 import eu.etaxonomy.cdm.common.media.CdmImageInfo;
20
21 /**
22 * @author a.kohlbecker
23 * @since May 5, 2021
24 */
25 @Component
26 public class MediaInfoFactory implements IMediaInfoFactory {
27
28 /**
29 * TODO needs to be managed in CDM PREFERENCES
30 */
31 private List<MediaUriTransformation> uriTransformations = new ArrayList<>();
32
33
34 public MediaInfoFactory() {
35 uriTransformations.add(DefaultMediaTransformations.bgbmMediaMetadataService());
36 }
37
38 /**
39 * This method only exists due to performance issues for cases when
40 * the {@link MediaMetadataFileReader} to reduce the overhead imposed by reading
41 * the image metadata from the file itself.
42 *
43 *
44 * @param imageUri
45 * @return
46 * @throws IOException
47 * @throws HttpException
48 */
49 public CdmImageInfo cdmImageInfoWithMetaData(eu.etaxonomy.cdm.common.URI imageUri) throws IOException, HttpException {
50 return cdmImageInfoWithMetaData(imageUri.getJavaUri());
51 }
52
53 /**
54 * This method only exists due to performance issues for cases when
55 * the {@link MediaMetadataFileReader} to reduce the overhead imposed by reading
56 * the image metadata from the file itself.
57 *
58 *
59 * @param imageUri
60 * @return
61 * @throws IOException
62 * @throws HttpException
63 */
64 public CdmImageInfo cdmImageInfoWithMetaData(URI imageUri) throws IOException, HttpException {
65
66 // :-) Hooray, we can get the metadata from the web service, this is going to be snappy
67 MediaUriTransformationProcessor processor = new MediaUriTransformationProcessor();
68 processor.addAll(uriTransformations);
69 processor.applyTo(imageUri);
70
71 // :-( need to use the files reader
72 return new MediaMetadataFileReader(imageUri)
73 .readBaseInfo()
74 .readMetaData()
75 .getCdmImageInfo();
76
77 }
78
79 public CdmImageInfo cdmImageInfo(eu.etaxonomy.cdm.common.URI imageUri) throws IOException, HttpException {
80 return cdmImageInfo(imageUri.getJavaUri());
81 }
82
83 public CdmImageInfo cdmImageInfo(URI imageUri) throws IOException, HttpException {
84
85 // :-) Hooray, we can get the metadata from the web service, this is going to be snappy
86
87 // :-( need to use the files reader
88 return new MediaMetadataFileReader(imageUri)
89 .readBaseInfo()
90 .getCdmImageInfo();
91 }
92
93
94
95
96
97 }