Project

General

Profile

Download (2.91 KB) Statistics
| Branch: | Tag: | Revision:
1
// $Id$
2
/**
3
* Copyright (C) 2007 EDIT
4
* European Distributed Institute of Taxonomy 
5
* http://www.e-taxonomy.eu
6
* 
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.
9
*/
10

    
11
package eu.etaxonomy.cdm.remote.controller;
12

    
13
import java.io.IOException;
14
import java.net.URI;
15
import java.net.URISyntaxException;
16
import java.util.Arrays;
17
import java.util.List;
18
import java.util.Map;
19
import java.util.Set;
20
import java.util.UUID;
21

    
22
import javax.servlet.http.HttpServletRequest;
23
import javax.servlet.http.HttpServletResponse;
24

    
25
import org.apache.http.HttpException;
26
import org.springframework.beans.factory.annotation.Autowired;
27
import org.springframework.stereotype.Controller;
28
import org.springframework.web.bind.annotation.PathVariable;
29
import org.springframework.web.bind.annotation.RequestMapping;
30
import org.springframework.web.servlet.ModelAndView;
31

    
32
import eu.etaxonomy.cdm.api.service.IMediaService;
33
import eu.etaxonomy.cdm.common.mediaMetaData.MediaMetaData;
34
import eu.etaxonomy.cdm.model.common.Representation;
35
import eu.etaxonomy.cdm.model.media.Media;
36
import eu.etaxonomy.cdm.model.media.MediaRepresentation;
37

    
38
/**
39
 * TODO write controller documentation
40
 * 
41
 * @author a.kohlbecker
42
 * @date 24.03.2009
43
 */
44

    
45
@Controller
46
@RequestMapping(value = {"/media/{uuid}"})
47
public class MediaController extends AnnotatableController<Media, IMediaService>
48
{
49
	
50
	/* (non-Javadoc)
51
	 * @see eu.etaxonomy.cdm.remote.controller.GenericController#setService(eu.etaxonomy.cdm.api.service.IService)
52
	 */
53
	@Autowired
54
	@Override
55
	public void setService(IMediaService service) {
56
		this.service = service;
57
	}
58
	private static final List<String> MEDIA_INIT_STRATEGY = Arrays.asList(new String []{
59
			"*",
60
			"representations",
61
			"representations.parts"
62
	});
63
	
64
	@RequestMapping(value = {"metadata"})
65
	public ModelAndView doGetMediaMetaData(@PathVariable("uuid") UUID uuid,
66
			HttpServletRequest request, HttpServletResponse response) throws IOException {
67
		Map<String, String> result;
68
		Media media = getCdmBaseInstance(uuid, response, MEDIA_INIT_STRATEGY);
69
		
70
		Set<MediaRepresentation> representations = media.getRepresentations();
71
		//get first representation and retrieve the according metadata
72

    
73
		Object[] repArray = representations.toArray();
74
		Object mediaRep = repArray[0];
75
		ModelAndView mv = new ModelAndView();
76
		try {
77
			if (mediaRep instanceof MediaRepresentation){
78
				MediaRepresentation medRep = (MediaRepresentation) mediaRep;
79
				String uriString = medRep.getParts().get(0).getUri();
80
				result = service.getImageMetaData(new URI(uriString), 3000);
81
				mv.addObject(result);
82
			}
83
		} catch (URISyntaxException e) {
84
			// TODO Auto-generated catch block
85
			e.printStackTrace();
86
		} catch (HttpException e) {
87
			// TODO Auto-generated catch block
88
			e.printStackTrace();
89
		}
90
		return mv;
91
		
92
	}
93

    
94
}
(23-23/43)