Project

General

Profile

« Previous | Next » 

Revision 3baaf1b2

Added by Andreas Müller 5 months ago

ref #9607 remove redundant method in IMediaInfoFactory

View differences:

cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/common/CdmImportBase.java
1435 1435
        try {
1436 1436
        	if (readMediaData){
1437 1437
        		logger.info("Read media data from: " + uri);
1438
        		cdmImageInfo = getMediaInfoFactory().cdmImageInfo(uri);
1438
        		cdmImageInfo = getMediaInfoFactory().cdmImageInfo(uri, false);
1439 1439
        	}
1440 1440
        } catch (Exception e) {
1441 1441
        	String message = "An error occurred when trying to read image meta data for " + uri.toString() + ": " +  e.getMessage();
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/media/in/MediaExcelImport.java
223 223
            CdmImageInfo cdmImageInfo = null;
224 224
            try {
225 225
                if (state.getConfig().isReadMediaData()){
226
                    cdmImageInfo = getMediaInfoFactory().cdmImageInfo(uri);
226
                    cdmImageInfo = getMediaInfoFactory().cdmImageInfo(uri, false);
227 227
                }
228 228
            } catch (Exception e) {
229 229
                String message = "An error occurred when trying to read image meta data for %s. Image was created but without metadata.";
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/sdd/in/SDDImport.java
1599 1599
							try{
1600 1600
								URL url = new URL(href);
1601 1601

  
1602
								imageMetaData = getMediaInfoFactory().cdmImageInfo(URI.fromUrl(url));
1602
								imageMetaData = getMediaInfoFactory().cdmImageInfo(URI.fromUrl(url), false);
1603 1603
								image = ImageFile.NewInstance(URI.fromUrl(url), null, imageMetaData);
1604 1604
							} catch (MalformedURLException e) {
1605 1605
								logger.error("Malformed URL", e);
......
1612 1612
							File parent = f.getParentFile();
1613 1613
							String fi = parent.toString() + File.separator + href;
1614 1614
							File file = new File(fi);
1615
							imageMetaData = getMediaInfoFactory().cdmImageInfo(new URI(fi)); //file
1615
							imageMetaData = getMediaInfoFactory().cdmImageInfo(new URI(fi), false); //file
1616 1616
							image = ImageFile.NewInstance(URI.fromFile(file), null, imageMetaData);
1617 1617
						}
1618 1618
						MediaRepresentation representation = MediaRepresentation.NewInstance(imageMetaData.getMimeType(), null);
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/controller/MediaController.java
90 90
                   result = service.readResourceMetadataFiltered(mediaRepresentation);
91 91
                } else {
92 92
                    uri = mediaRepresentation.getParts().get(0).getUri();
93
                    CdmImageInfo cdmImageInfo = mediaInfoFactory.cdmImageInfoWithMetaData(uri);
93
                    CdmImageInfo cdmImageInfo = mediaInfoFactory.cdmImageInfo(uri, true);
94 94
                    result = cdmImageInfo.getMetaData();
95 95
                }
96 96
            } catch (IOException | HttpException e) {
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/controller/iiif/ManifestComposer.java
421 421
            }
422 422
            if (part.getUri() != null) {
423 423
                try {
424
                    CdmImageInfo cdmImageInfo = mediaInfoFactory.cdmImageInfoWithMetaData(part.getUri());
424
                    CdmImageInfo cdmImageInfo = mediaInfoFactory.cdmImageInfo(part.getUri(), true);
425 425
                    Map<String, String> result = cdmImageInfo.getMetaData();
426 426
                    if(result != null){
427 427
                        for (String key : result.keySet()) {
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/MediaServiceImpl.java
295 295
        Map<String, String> metadata = new HashMap<>();
296 296

  
297 297
        for(MediaRepresentationPart part : representation.getParts()) {
298
            CdmImageInfo iInfo =  mediaInfoFactory.cdmImageInfoWithMetaData(part.getUri());
298
            CdmImageInfo iInfo =  mediaInfoFactory.cdmImageInfo(part.getUri(), true);
299 299
            if(iInfo.getMetaData() != null) {
300 300
                metadata.putAll(iInfo.getMetaData());
301 301
            }
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/media/IMediaInfoFactory.java
22 22
public interface IMediaInfoFactory {
23 23

  
24 24
    /**
25
     * This method only exists due to performance issues for cases when
26
     * the {@link MediaInfoFileReader} to reduce the overhead imposed by reading
27
     * the image metadata from the file itself.
25
     * Reads the image metadata by first trying to read it first from a metadata service.
26
     * If this is not possible it reads it by downloading the file.
27
     *
28
     * @param imageUri the image uri
29
     * @param forceMetaData if true reading metadata additional metadata reading is forced even if not performant
28 30
     */
29
    public CdmImageInfo cdmImageInfoWithMetaData(URI imageUri) throws IOException, HttpException;
30

  
31
    public CdmImageInfo cdmImageInfo(URI imageUri) throws IOException, HttpException;
31
    public CdmImageInfo cdmImageInfo(URI imageUri, boolean forceMetaData) throws IOException, HttpException;
32 32

  
33 33
}
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/media/MediaInfoFactory.java
42 42
     * the image metadata from the file itself.
43 43
     */
44 44
    @Override
45
    public CdmImageInfo cdmImageInfoWithMetaData(URI imageUri) throws IOException, HttpException {
45
    public CdmImageInfo cdmImageInfo(URI imageUri, boolean forceMetaData) throws IOException, HttpException {
46 46

  
47 47
        List<URI> metadataServiceURIs = applyURITransformations(imageUri);
48 48
        if(!metadataServiceURIs.isEmpty()) {
......
52 52
                    .getCdmImageInfo();
53 53
        } else {
54 54
            // :-( need to use the files reader
55
            return new MediaInfoFileReader(imageUri)
56
                   .readBaseInfo()
57
                   .readMetaData()
58
                   .getCdmImageInfo();
55
            MediaInfoFileReader mediaReader = new MediaInfoFileReader(imageUri)
56
                   .readBaseInfo();
57
            AbstactMediaMetadataReader reader = forceMetaData ? mediaReader.readMetaData() : mediaReader;
58
            return reader.getCdmImageInfo();
59 59
        }
60 60
    }
61 61

  
......
65 65
        List<URI> metadataServiceURIs = processor.applyTo(imageUri);
66 66
        return metadataServiceURIs;
67 67
    }
68

  
69
    @Override
70
    public CdmImageInfo cdmImageInfo(URI imageUri) throws IOException, HttpException {
71

  
72
        List<URI> metadataServiceURIs = applyURITransformations(imageUri);
73
        // :-) Hooray, we can get the metadata from the web service, this is going to be snappy
74
        if(!metadataServiceURIs.isEmpty()) {
75
            return new MediaInfoServiceReader(imageUri, metadataServiceURIs.get(0))
76
                    .read()
77
                    .getCdmImageInfo();
78
        } else {
79
            // :-( need to use the files reader
80
            return new MediaInfoFileReader(imageUri)
81
                   .readBaseInfo()
82
                   .getCdmImageInfo();
83
        }
84
    }
85 68
}
cdmlib-services/src/test/java/eu/etaxonomy/cdm/api/service/media/MediaInfoFactoryTest.java
51 51
    @Test
52 52
    public void readMediaInfoViaFileReader() throws IOException, HttpException {
53 53
        assertTrue(((MediaInfoFactory)mediaInfoFactory).applyURITransformations(notTransformableURI).isEmpty());
54
        CdmImageInfo cdmImageInfo = mediaInfoFactory.cdmImageInfoWithMetaData(notTransformableURI);
54
        CdmImageInfo cdmImageInfo = mediaInfoFactory.cdmImageInfo(notTransformableURI, true);
55 55
        assertNotNull(cdmImageInfo);
56 56
        assertEquals(225, cdmImageInfo.getHeight());
57 57
        assertEquals(300, cdmImageInfo.getWidth());
......
61 61
    public void readMediaInfoViaServiceReaderScalerAPI() throws IOException, HttpException, URISyntaxException {
62 62
        assertEquals(1, ((MediaInfoFactory)mediaInfoFactory).applyURITransformations(transformableURI_ScalerAPI).size());
63 63
        if(UriUtils.isInternetAvailable(new URI("https://image.bgbm.org/"))){
64
            CdmImageInfo cdmImageInfo = mediaInfoFactory.cdmImageInfoWithMetaData(transformableURI_ScalerAPI);
64
            CdmImageInfo cdmImageInfo = mediaInfoFactory.cdmImageInfo(transformableURI_ScalerAPI, true);
65 65
            assertNotNull(cdmImageInfo);
66 66
            assertEquals(954, cdmImageInfo.getHeight());
67 67
            assertEquals(1400, cdmImageInfo.getWidth());
......
85 85
    public void readMediaInfoViaServiceReaderIIIF_API() throws IOException, HttpException, URISyntaxException {
86 86
        assertEquals(1, ((MediaInfoFactory)mediaInfoFactory).applyURITransformations(transformableURI_IIIF_API).size());
87 87
        if(UriUtils.isInternetAvailable(new URI("https://image.bgbm.org/"))){
88
            CdmImageInfo cdmImageInfo = mediaInfoFactory.cdmImageInfoWithMetaData(transformableURI_IIIF_API);
88
            CdmImageInfo cdmImageInfo = mediaInfoFactory.cdmImageInfo(transformableURI_IIIF_API, true);
89 89
            assertNotNull(cdmImageInfo);
90 90
            assertEquals(2592, cdmImageInfo.getHeight());
91 91
            assertEquals(3456, cdmImageInfo.getWidth());

Also available in: Unified diff