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
.remote
.controller
;
13 import java
.io
.IOException
;
15 import java
.util
.Arrays
;
16 import java
.util
.List
;
19 import java
.util
.UUID
;
21 import javax
.servlet
.http
.HttpServletRequest
;
22 import javax
.servlet
.http
.HttpServletResponse
;
24 import org
.apache
.http
.HttpException
;
25 import org
.springframework
.beans
.factory
.annotation
.Autowired
;
26 import org
.springframework
.stereotype
.Controller
;
27 import org
.springframework
.web
.bind
.annotation
.PathVariable
;
28 import org
.springframework
.web
.bind
.annotation
.RequestMapping
;
29 import org
.springframework
.web
.servlet
.ModelAndView
;
31 import eu
.etaxonomy
.cdm
.api
.service
.IMediaService
;
32 import eu
.etaxonomy
.cdm
.common
.media
.ImageInfo
;
33 import eu
.etaxonomy
.cdm
.model
.media
.Media
;
34 import eu
.etaxonomy
.cdm
.model
.media
.MediaRepresentation
;
37 * TODO write controller documentation
39 * @author a.kohlbecker
44 @RequestMapping(value
= {"/media/{uuid}"})
45 public class MediaController
extends BaseController
<Media
, IMediaService
>
49 * @see eu.etaxonomy.cdm.remote.controller.GenericController#setService(eu.etaxonomy.cdm.api.service.IService)
53 public void setService(IMediaService service
) {
54 this.service
= service
;
56 private static final List
<String
> MEDIA_INIT_STRATEGY
= Arrays
.asList(new String
[]{
59 "representations.parts"
62 @RequestMapping(value
= {"metadata"})
63 public ModelAndView
doGetMediaMetaData(@PathVariable("uuid") UUID uuid
,
64 HttpServletRequest request
, HttpServletResponse response
) throws IOException
{
65 Map
<String
, String
> result
;
66 Media media
= getCdmBaseInstance(uuid
, response
, MEDIA_INIT_STRATEGY
);
68 Set
<MediaRepresentation
> representations
= media
.getRepresentations();
69 //get first representation and retrieve the according metadata
71 Object
[] repArray
= representations
.toArray();
72 Object mediaRep
= repArray
[0];
73 ModelAndView mv
= new ModelAndView();
76 if (mediaRep
instanceof MediaRepresentation
){
77 MediaRepresentation medRep
= (MediaRepresentation
) mediaRep
;
78 uri
= medRep
.getParts().get(0).getUri();
79 ImageInfo imageInfo
= ImageInfo
.NewInstanceWithMetaData(uri
, 3000);
80 result
= imageInfo
.getMetaData();
85 } catch (HttpException e
) {
86 HttpStatusMessage
.fromString("Reading media file from " + uri
.toString() + " failed").setStatusCode(400).send(response
);