Revision 6c5265eb
Added by Andreas Kohlbecker almost 3 years ago
cdmlib-ext/src/main/java/eu/etaxonomy/cdm/ext/occurrence/gbif/GbifJsonOccurrenceParser.java | ||
---|---|---|
24 | 24 |
import org.apache.log4j.Logger; |
25 | 25 |
|
26 | 26 |
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade; |
27 |
import eu.etaxonomy.cdm.api.service.media.MediaMetadataFileReader;
|
|
27 |
import eu.etaxonomy.cdm.api.service.media.MediaInfoFileReader;
|
|
28 | 28 |
import eu.etaxonomy.cdm.common.URI; |
29 | 29 |
import eu.etaxonomy.cdm.common.UriUtils; |
30 | 30 |
import eu.etaxonomy.cdm.common.media.CdmImageInfo; |
... | ... | |
427 | 427 |
if (mediaRecord.has("identifier")){ |
428 | 428 |
try { |
429 | 429 |
uri = new URI(mediaRecord.getString("identifier")); |
430 |
imageInf = MediaMetadataFileReader.legacyFactoryMethod(uri)
|
|
430 |
imageInf = MediaInfoFileReader.legacyFactoryMethod(uri)
|
|
431 | 431 |
.readBaseInfo() |
432 | 432 |
.getCdmImageInfo(); |
433 | 433 |
} catch (URISyntaxException |IOException | HttpException e) { |
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/media/MediaInfoFileReader.java | ||
---|---|---|
31 | 31 |
* Most code was extracted from CdmImageInfo. |
32 | 32 |
* |
33 | 33 |
*/ |
34 |
public class MediaMetadataFileReader extends AbstactMediaMetadataReader {
|
|
34 |
public class MediaInfoFileReader extends AbstactMediaMetadataReader {
|
|
35 | 35 |
|
36 |
private static Logger logger = Logger.getLogger(MediaMetadataFileReader.class);
|
|
36 |
private static Logger logger = Logger.getLogger(MediaInfoFileReader.class);
|
|
37 | 37 |
|
38 | 38 |
public static final Integer IMAGE_READ_TIMEOUT = 3000; // ms |
39 | 39 |
|
... | ... | |
48 | 48 |
* MediaMetadataService or other fast source of metadata. |
49 | 49 |
*/ |
50 | 50 |
@Deprecated |
51 |
public static MediaMetadataFileReader legacyFactoryMethod(eu.etaxonomy.cdm.common.URI uri) {
|
|
52 |
return new MediaMetadataFileReader(uri);
|
|
51 |
public static MediaInfoFileReader legacyFactoryMethod(eu.etaxonomy.cdm.common.URI uri) {
|
|
52 |
return new MediaInfoFileReader(uri);
|
|
53 | 53 |
} |
54 | 54 |
|
55 |
protected MediaMetadataFileReader(eu.etaxonomy.cdm.common.URI uri) {
|
|
55 |
protected MediaInfoFileReader(eu.etaxonomy.cdm.common.URI uri) {
|
|
56 | 56 |
super(uri, uri); |
57 | 57 |
} |
58 | 58 |
|
59 | 59 |
@Override |
60 |
public MediaMetadataFileReader read() throws IOException, HttpException {
|
|
60 |
public MediaInfoFileReader read() throws IOException, HttpException {
|
|
61 | 61 |
return readBaseInfo().readMetaData(); |
62 | 62 |
} |
63 | 63 |
|
... | ... | |
75 | 75 |
* @throws IOException |
76 | 76 |
* @throws HttpException |
77 | 77 |
*/ |
78 |
public MediaMetadataFileReader readBaseInfo() throws IOException, HttpException{
|
|
78 |
public MediaInfoFileReader readBaseInfo() throws IOException, HttpException{
|
|
79 | 79 |
readImageInfo(); |
80 | 80 |
readImageLength(); |
81 | 81 |
readSuffix(); |
... | ... | |
85 | 85 |
/** |
86 | 86 |
* Reads the image info (width, height, bitPerPixel, metadata, format, mime type) |
87 | 87 |
*/ |
88 |
public MediaMetadataFileReader readImageInfo() throws IOException, HttpException{
|
|
88 |
public MediaInfoFileReader readImageInfo() throws IOException, HttpException{
|
|
89 | 89 |
|
90 | 90 |
InputStream inputStream; |
91 | 91 |
try { |
... | ... | |
107 | 107 |
return this; |
108 | 108 |
} |
109 | 109 |
|
110 |
public MediaMetadataFileReader readMetaData() throws IOException, HttpException {
|
|
110 |
public MediaInfoFileReader readMetaData() throws IOException, HttpException {
|
|
111 | 111 |
|
112 | 112 |
ImageMetadata mediaData = null; |
113 | 113 |
try { |
... | ... | |
154 | 154 |
/** |
155 | 155 |
* Reads the size of the image defined by the {@link #imageUri} in bytes |
156 | 156 |
*/ |
157 |
public MediaMetadataFileReader readImageLength() throws ClientProtocolException, IOException, HttpException{
|
|
157 |
public MediaInfoFileReader readImageLength() throws ClientProtocolException, IOException, HttpException{
|
|
158 | 158 |
try { |
159 | 159 |
long length = UriUtils.getResourceLength(cdmImageInfo.getUri(), null); |
160 | 160 |
cdmImageInfo.setLength(length); |
... | ... | |
175 | 175 |
return this; |
176 | 176 |
} |
177 | 177 |
|
178 |
public MediaMetadataFileReader readSuffix(){
|
|
178 |
public MediaInfoFileReader readSuffix(){
|
|
179 | 179 |
String path = cdmImageInfo.getUri().getPath(); |
180 | 180 |
String suffix = path.substring(StringUtils.lastIndexOf(path, '.') + 1); |
181 | 181 |
cdmImageInfo.setSuffix(suffix); |
cdmlib-services/src/test/java/eu/etaxonomy/cdm/api/service/media/MediaInfoFileReaderTest.java | ||
---|---|---|
23 | 23 |
/** |
24 | 24 |
* @author n.hoffmann |
25 | 25 |
*/ |
26 |
public class MediaMetadataFileReaderTest {
|
|
26 |
public class MediaInfoFileReaderTest {
|
|
27 | 27 |
|
28 | 28 |
private static final String OFFLINE = "OFFLINE"; |
29 | 29 |
|
30 |
public static final Logger logger = Logger.getLogger(MediaMetadataFileReaderTest.class);
|
|
30 |
public static final Logger logger = Logger.getLogger(MediaInfoFileReaderTest.class);
|
|
31 | 31 |
|
32 | 32 |
private URI jpegUri; |
33 | 33 |
private URI tiffUri; |
... | ... | |
39 | 39 |
|
40 | 40 |
@Before |
41 | 41 |
public void setUp() throws Exception { |
42 |
URL jpegUrl = MediaMetadataFileReaderTest.class.getResource("./images/OregonScientificDS6639-DSC_0307-small.jpg");
|
|
42 |
URL jpegUrl = MediaInfoFileReaderTest.class.getResource("./images/OregonScientificDS6639-DSC_0307-small.jpg");
|
|
43 | 43 |
jpegUri = new URI(jpegUrl); |
44 | 44 |
|
45 |
URL tiffUrl = MediaMetadataFileReaderTest.class.getResource("./images/OregonScientificDS6639-DSC_0307-small.tif");
|
|
45 |
URL tiffUrl = MediaInfoFileReaderTest.class.getResource("./images/OregonScientificDS6639-DSC_0307-small.tif");
|
|
46 | 46 |
tiffUri = new URI(tiffUrl); |
47 | 47 |
|
48 | 48 |
remotePngUri = URI.create("https://dev.e-taxonomy.eu/trac_htdocs/logo_edit.png"); |
... | ... | |
51 | 51 |
@Test |
52 | 52 |
public void testNewInstanceJpeg(){ |
53 | 53 |
try { |
54 |
new MediaMetadataFileReader(jpegUri).readBaseInfo();
|
|
54 |
new MediaInfoFileReader(jpegUri).readBaseInfo();
|
|
55 | 55 |
} catch (Exception e) { |
56 | 56 |
fail("NewInstance method should not throw exceptions for existing uncorrupted images."); |
57 | 57 |
} |
... | ... | |
60 | 60 |
@Test |
61 | 61 |
public void testNewInstanceTiff() { |
62 | 62 |
try { |
63 |
new MediaMetadataFileReader(tiffUri).readBaseInfo();
|
|
63 |
new MediaInfoFileReader(tiffUri).readBaseInfo();
|
|
64 | 64 |
} catch (Exception e) { |
65 | 65 |
fail("NewInstance method should not throw exceptions for existing uncorrupted images."); |
66 | 66 |
} |
... | ... | |
70 | 70 |
public void testNewInstanceRemotePng() { |
71 | 71 |
if(UriUtils.isInternetAvailable(remotePngUri)){ |
72 | 72 |
try { |
73 |
new MediaMetadataFileReader(remotePngUri).readBaseInfo();
|
|
73 |
new MediaInfoFileReader(remotePngUri).readBaseInfo();
|
|
74 | 74 |
} catch (Exception e) { |
75 | 75 |
fail("NewInstance method should not throw exceptions for existing uncorrupted images."); |
76 | 76 |
} |
... | ... | |
83 | 83 |
public void testNewInstanceFileDoesNotExist() throws HttpException, IOException { |
84 | 84 |
URI nonExistentUri = URI.create("file:///nonExistentImage.jpg"); |
85 | 85 |
|
86 |
new MediaMetadataFileReader(nonExistentUri).readBaseInfo();
|
|
86 |
new MediaInfoFileReader(nonExistentUri).readBaseInfo();
|
|
87 | 87 |
} |
88 | 88 |
|
89 | 89 |
private CdmImageInfo getJpegInstance(){ |
90 | 90 |
if(jpegInstance == null){ |
91 | 91 |
try { |
92 |
jpegInstance = new MediaMetadataFileReader(jpegUri).readBaseInfo().getCdmImageInfo();
|
|
92 |
jpegInstance = new MediaInfoFileReader(jpegUri).readBaseInfo().getCdmImageInfo();
|
|
93 | 93 |
} catch (Exception e) { |
94 | 94 |
fail("This case should have been covered by other tests."); |
95 | 95 |
return null; |
... | ... | |
101 | 101 |
private CdmImageInfo getTifInstance(){ |
102 | 102 |
if(tifInstance == null){ |
103 | 103 |
try { |
104 |
tifInstance = new MediaMetadataFileReader(tiffUri).readBaseInfo().getCdmImageInfo();
|
|
104 |
tifInstance = new MediaInfoFileReader(tiffUri).readBaseInfo().getCdmImageInfo();
|
|
105 | 105 |
} catch (Exception e) { |
106 | 106 |
fail("This case should have been covered by other tests."); |
107 | 107 |
return null; |
... | ... | |
116 | 116 |
} |
117 | 117 |
if(pngInstance == null){ |
118 | 118 |
try { |
119 |
pngInstance = new MediaMetadataFileReader(remotePngUri).readBaseInfo().getCdmImageInfo();
|
|
119 |
pngInstance = new MediaInfoFileReader(remotePngUri).readBaseInfo().getCdmImageInfo();
|
|
120 | 120 |
} catch (Exception e) { |
121 | 121 |
fail("This case should have been covered by other tests."); |
122 | 122 |
return null; |
... | ... | |
241 | 241 |
@Test |
242 | 242 |
public void testReadMetaDataJpeg() throws IOException, HttpException{ |
243 | 243 |
|
244 |
CdmImageInfo instance = new MediaMetadataFileReader(jpegUri).readMetaData().getCdmImageInfo();
|
|
244 |
CdmImageInfo instance = new MediaInfoFileReader(jpegUri).readMetaData().getCdmImageInfo();
|
|
245 | 245 |
Map<String, String> metaData = instance.getMetaData(); |
246 | 246 |
Assert.assertEquals(52, metaData.size()); |
247 | 247 |
|
... | ... | |
255 | 255 |
|
256 | 256 |
@Test |
257 | 257 |
public void testReadMetaDataTif() throws IOException, HttpException{ |
258 |
CdmImageInfo instance = new MediaMetadataFileReader(tiffUri).readBaseInfo().readMetaData().getCdmImageInfo();
|
|
258 |
CdmImageInfo instance = new MediaInfoFileReader(tiffUri).readBaseInfo().readMetaData().getCdmImageInfo();
|
|
259 | 259 |
Map<String, String> metaData = instance.getMetaData(); |
260 | 260 |
Assert.assertEquals(15, metaData.size()); |
261 | 261 |
} |
... | ... | |
264 | 264 |
public void testReadMetaDataRemotePng() throws HttpException { |
265 | 265 |
|
266 | 266 |
try { |
267 |
CdmImageInfo instance = new MediaMetadataFileReader(remotePngUri).readMetaData().getCdmImageInfo();
|
|
267 |
CdmImageInfo instance = new MediaInfoFileReader(remotePngUri).readMetaData().getCdmImageInfo();
|
|
268 | 268 |
Map<String, String> metaData = instance.getMetaData(); |
269 | 269 |
Assert.assertEquals(1, metaData.size()); |
270 | 270 |
|
Also available in: Unified diff
ref #9607 renaming class to MediaInfoFileReader