Project

General

Profile

Download (2.43 KB) Statistics
| Branch: | Tag: | Revision:
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 per service and version.
30
     *
31
     * ./MediaInfoService/1.0/ --> MediaUriTransformation
32
     */
33
    private List<MediaUriTransformation> mediaInfoService_1_0_Transformations = new ArrayList<>();
34

    
35
    public MediaInfoFactory() {
36
        mediaInfoService_1_0_Transformations.addAll(DefaultMediaTransformations.bgbmMediaMetadataService());
37
    }
38

    
39
    /**
40
     * This method only exists due to performance issues for cases when
41
     * the {@link MediaInfoFileReader} to reduce the overhead imposed by reading
42
     * the image metadata from the file itself.
43
     */
44
    @Override
45
    public CdmImageInfo cdmImageInfo(URI imageUri, boolean forceMetaData) throws IOException, HttpException {
46

    
47
        List<URI> metadataServiceURIs = applyURITransformations(imageUri);
48
        if(!metadataServiceURIs.isEmpty()) {
49
            // :-) Hooray, we can get the metadata from the web service, this is going to be snappy
50
            return new MediaInfoServiceReader(imageUri, metadataServiceURIs.get(0))
51
                    .read()
52
                    .getCdmImageInfo();
53
        } else {
54
            // :-( need to use the files reader
55
            MediaInfoFileReader mediaReader = new MediaInfoFileReader(imageUri)
56
                   .readBaseInfo();
57
            AbstactMediaMetadataReader reader = forceMetaData ? mediaReader.readMetaData() : mediaReader;
58
            return reader.getCdmImageInfo();
59
        }
60
    }
61

    
62
    protected List<URI> applyURITransformations(URI imageUri) {
63
        MediaUriTransformationProcessor processor = new MediaUriTransformationProcessor();
64
        processor.addAll(mediaInfoService_1_0_Transformations);
65
        List<URI> metadataServiceURIs = processor.applyTo(imageUri);
66
        return metadataServiceURIs;
67
    }
68
}
(4-4/9)