/* * (non-Javadoc) * * @see * org.magnum.dataup.service.VideoService#addVideo(org.magnum.dataup.model * .Video) */ @Override public Video addVideo(Video video, String baseUrl) { videos.add(video); video.setId(videos.size() - 1); video.setDataUrl(baseUrl + "/video/" + video.getId() + "/data"); return video; }
/** {@inheritDoc} */ @Multipart @RequestMapping(value = VIDEO_DATA_PATH, method = RequestMethod.POST) @ResponseBody public VideoStatus setVideoData( @PathVariable(ID_PARAMETER) final long id, @RequestParam(DATA_PARAMETER) final MultipartFile videoData) { try { final InputStream is = videoData.getInputStream(); Video v = new Video(); v.setId(id); v.setDataUrl(VIDEO_DATA_PATH + id); boolean containsVideo = false; for (Video video : videoList) { if (video.getId() == id) { containsVideo = true; } } if (containsVideo) { VideoFileManager fileManager = VideoFileManager.get(); fileManager.saveVideoData(v, is); } else { throw new ResourceNotFoundException(); } } catch (final IOException e) { e.printStackTrace(); } final VideoStatus status = new VideoStatus(VideoState.READY); return status; }
/** {@inheritDoc} */ @RequestMapping(value = VIDEO_SVC_PATH, method = RequestMethod.POST) @ResponseBody public Video addVideo(final @RequestBody Video v) { this.videoList.add(v); v.setId(this.videoList.size()); v.setDataUrl(VIDEO_DATA_PATH + v.getId()); return v; }
private Video getVideo(long id) { Video result = null; for (Iterator<Video> iterator = videos.iterator(); iterator.hasNext() && result == null; ) { Video video = iterator.next(); if (id == video.getId()) { result = video; } } return result; }
/** {@inheritDoc} */ @RequestMapping(value = VIDEO_DATA_PATH, method = RequestMethod.GET) @ResponseBody public void getData(@PathVariable(ID_PARAMETER) final long id, HttpServletResponse response) { Video video = new Video(); video.setId(id); try { VideoFileManager fileManager = VideoFileManager.get(); if (fileManager.hasVideoData(video)) { VideoFileManager.get().copyVideoData(video, response.getOutputStream()); response.flushBuffer(); } else { throw new ResourceNotFoundException(); } } catch (IOException e) { e.printStackTrace(); } }
@Test public void test() { Video video = Video.create() .withContentType("video/mpeg") .withDuration(123) .withSubject("Mobile Cloud") .withTitle("Programming Cloud Services for ...") .build(); fail("Not yet implemented"); }