3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
11 package eu
.etaxonomy
.cdm
.api
.service
;
13 import java
.io
.IOException
;
14 import java
.net
.HttpURLConnection
;
15 import java
.net
.MalformedURLException
;
18 import java
.util
.ArrayList
;
19 import java
.util
.List
;
23 import org
.apache
.http
.HttpException
;
24 import org
.springframework
.beans
.factory
.annotation
.Autowired
;
25 import org
.springframework
.stereotype
.Service
;
26 import org
.springframework
.transaction
.annotation
.Propagation
;
27 import org
.springframework
.transaction
.annotation
.Transactional
;
29 import eu
.etaxonomy
.cdm
.api
.service
.pager
.Pager
;
30 import eu
.etaxonomy
.cdm
.api
.service
.pager
.impl
.DefaultPagerImpl
;
31 import eu
.etaxonomy
.cdm
.common
.IProgressMonitor
;
32 import eu
.etaxonomy
.cdm
.common
.mediaMetaData
.ImageMetaData
;
33 import eu
.etaxonomy
.cdm
.model
.description
.MediaKey
;
34 import eu
.etaxonomy
.cdm
.model
.location
.NamedArea
;
35 import eu
.etaxonomy
.cdm
.model
.media
.Media
;
36 import eu
.etaxonomy
.cdm
.model
.media
.Rights
;
37 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameBase
;
38 import eu
.etaxonomy
.cdm
.model
.taxon
.Classification
;
39 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
40 import eu
.etaxonomy
.cdm
.persistence
.dao
.media
.IMediaDao
;
41 import eu
.etaxonomy
.cdm
.strategy
.cache
.common
.IIdentifiableEntityCacheStrategy
;
42 import eu
.etaxonomy
.cdm
.strategy
.cache
.media
.MediaDefaultCacheStrategy
;
45 @Transactional(readOnly
=true, propagation
= Propagation
.SUPPORTS
)
46 public class MediaServiceImpl
extends IdentifiableServiceBase
<Media
,IMediaDao
> implements IMediaService
{
49 protected void setDao(IMediaDao dao
) {
53 public Pager
<MediaKey
> getMediaKeys(Set
<Taxon
> taxonomicScope
, Set
<NamedArea
> geoScopes
, Integer pageSize
, Integer pageNumber
, List
<String
> propertyPaths
) {
54 Integer numberOfResults
= dao
.countMediaKeys(taxonomicScope
, geoScopes
);
56 List
<MediaKey
> results
= new ArrayList
<MediaKey
>();
57 if(numberOfResults
> 0) { // no point checking again //TODO use AbstractPagerImpl.hasResultsInRange(numberOfResults, pageNumber, pageSize)
58 results
= dao
.getMediaKeys(taxonomicScope
, geoScopes
, pageSize
, pageNumber
, propertyPaths
);
61 return new DefaultPagerImpl
<MediaKey
>(pageNumber
, numberOfResults
, pageSize
, results
);
64 public Pager
<Rights
> getRights(Media t
, Integer pageSize
, Integer pageNumber
, List
<String
> propertyPaths
) {
65 Integer numberOfResults
= dao
.countRights(t
);
67 List
<Rights
> results
= new ArrayList
<Rights
>();
68 if(numberOfResults
> 0) { // no point checking again //TODO use AbstractPagerImpl.hasResultsInRange(numberOfResults, pageNumber, pageSize)
69 results
= dao
.getRights(t
, pageSize
, pageNumber
,propertyPaths
);
72 return new DefaultPagerImpl
<Rights
>(pageNumber
, numberOfResults
, pageSize
, results
);
76 public ImageMetaData
getImageInfo(URI imageUri
, Integer timeOut
) throws IOException
, HttpException
{
77 ImageMetaData imageMetaData
= ImageMetaData
.newInstance();
78 imageMetaData
.readImageInfo(imageUri
, timeOut
);
79 imageMetaData
.readMetaData(imageUri
, timeOut
);
84 public Map
<String
,String
> getImageMetaData(URI imageUri
, Integer timeOut
) throws IOException
, HttpException
{
86 ImageMetaData imageMetaData
= ImageMetaData
.newInstance();
87 imageMetaData
.readMetaData(imageUri
, timeOut
);
90 return imageMetaData
.getMetaData();
95 * @see eu.etaxonomy.cdm.api.service.IMediaService#getImageSize(java.net.URI, java.lang.Integer)
97 public Integer
getImageSize(URI imageUri
, Integer timeOut
) {
99 URL url
= imageUri
.toURL();
100 HttpURLConnection
.setFollowRedirects(false);
102 HttpURLConnection connection
= (HttpURLConnection
) url
.openConnection();
104 return connection
.getContentLength();
106 } catch (MalformedURLException e
) {
107 logger
.trace("MalformedURLException when trying to get filesize for: " +imageUri
);
108 } catch (IOException e
) {
109 logger
.trace("IOException when trying to get filesize for: " +imageUri
);
116 * @see eu.etaxonomy.cdm.api.service.IIdentifiableEntityService#updateTitleCache(java.lang.Integer, eu.etaxonomy.cdm.strategy.cache.common.IIdentifiableEntityCacheStrategy)
119 public void updateTitleCache(Class
<?
extends Media
> clazz
, Integer stepSize
, IIdentifiableEntityCacheStrategy
<Media
> cacheStrategy
, IProgressMonitor monitor
) {
120 //IIdentifiableEntityCacheStrategy<Media> cacheStrategy = MediaDefaultCacheStrategy();
124 super.updateTitleCacheImpl(clazz
, stepSize
, cacheStrategy
, monitor
);