PlaylistService extends BasicService implements OwnerAPISupport<Playlist> { @POST @Path("/playlists/{playlistId}/copy") @Consumes(MediaType.APPLICATION_JSON) public Playlist copyPlaylist(@PathParam("playlistId") long playlistId, Playlist newPlaylist) { Playlist existingPlaylist = getExistingPlaylist(playlistId, false); Playlist copiedPlaylist = new Playlist(existingPlaylist); copiedPlaylist.setName(newPlaylist.getName()); copiedPlaylist = createPlaylist(copiedPlaylist); for (PageReference ref : existingPlaylist.getPageReferences()) { copiedPlaylist = addPage(copiedPlaylist.getId(), ref.getPage()); updatePageReference( copiedPlaylist.getPageReferences().get(copiedPlaylist.getPageReferences().size() - 1).getId(), ref); } return copiedPlaylist; }  @GET @Path("/playlists") @Produces(MediaType.APPLICATION_JSON) List<Playlist> getPlaylists(@DefaultValue("false") @QueryParam("expand") boolean expand,
			@QueryParam("userId") String userId); @GET @Path("/catalog") @Produces(MediaType.APPLICATION_JSON) List<Playlist> getPlaylistCatalog(@DefaultValue("0") @QueryParam("exclude") long excludeId); @GET @Path("/playlists/{playlistId}") @Produces(MediaType.APPLICATION_JSON) Playlist getPlaylist(@PathParam("playlistId") long playlistId,
			@DefaultValue("false") @QueryParam("visibleOnly") boolean visibleOnly,
			@DefaultValue("false") @QueryParam("expand") boolean expand,
			@DefaultValue("true") @QueryParam("includeMetrics") boolean includeMetrics); @PUT @Path("/playlists/{playlistId}") @Produces(MediaType.APPLICATION_JSON) Playlist updatePlaylist(@PathParam("playlistId") long playlistId, Playlist playlistData); @POST @Path("/playlists") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) Playlist createPlaylist(Playlist playlist); @POST @Path("/playlists/{playlistId}/pages") @Consumes(MediaType.APPLICATION_JSON) Playlist addPage(@PathParam("playlistId") long playlistId, Page page); @POST @Path("/playlists/{playlistId}/playlists") @Consumes(MediaType.APPLICATION_JSON) Playlist addPlaylist(@PathParam("playlistId") long playlistId, Playlist playlist); @POST @Path("/playlists/{playlistId}/files") @Consumes(MediaType.APPLICATION_JSON) Playlist addFile(@PathParam("playlistId") long playlistId, File file); @PUT @Path("/playlists/{playlistId}/pagereferences/{pageRefId}") @Produces(MediaType.APPLICATION_JSON) PageReference updatePageReference(@PathParam("pageRefId") long pageRefId, PageReference pageRef); @POST @Path("/playlists/{playlistId}/copy") @Consumes(MediaType.APPLICATION_JSON) Playlist copyPlaylist(@PathParam("playlistId") long playlistId, Playlist newPlaylist); @DELETE @Path("/playlists/{playlistId}") Response deletePlaylist(@PathParam("playlistId") long playlistId); @DELETE @Path("/playlists/{playlistId}/pagereferences/{pageReferenceId}") @Produces(MediaType.APPLICATION_JSON) Playlist deletePage(@PathParam("playlistId") long playlistId,
			@PathParam("pageReferenceId") long pageReferenceId); @POST @Path("/playlists/{playlistId}/pagereferences/{pageReferenceId}/moveto/{idx}") @Produces(MediaType.APPLICATION_JSON) Playlist movePage(@PathParam("playlistId") long playlistId,
			@PathParam("pageReferenceId") long pageReferenceId, @PathParam("idx") int newPosition); @GET @Path("/playlists/{playlistId}/references") @Produces(MediaType.APPLICATION_JSON) PlaylistReferences getReferences(@PathParam("playlistId") long playlistId); @Override @POST @Path("/playlists/{playlistId}/owners") @Consumes(MediaType.APPLICATION_JSON) Playlist addOwners(@PathParam("playlistId") long playlistId, Owner[] ownerData); @Override @DELETE @Path("/playlists/{playlistId}/owners/{ownerId}") @Produces(MediaType.APPLICATION_JSON) Playlist deleteOwner(@PathParam("playlistId") long playlistId, @PathParam("ownerId") long ownerId);  }
@Test public void testCopyPlaylist() throws Exception { Page page1 = pageService.createPage(new Page("p1")); Page page2 = pageService.createPage(new Page("p2")); Playlist playlist = new Playlist("d1"); playlist.addPageReference(new PageReference(page1)); playlist.addPageReference(new PageReference(page2)); playlist = playlistService.createPlaylist(playlist); PageReference pageUpdate = new PageReference(); pageUpdate.setPageDisplayDurationOverride(99); playlistService.updatePageReference(getPlaylist(playlist.getId()).getPageReferences().get(0).getId(), pageUpdate); Playlist copy = playlistService.copyPlaylist(playlist.getId(), new Playlist("d2")); List<Playlist> playlists = getPlaylists(false); assertEquals(2, playlists.size()); assertEquals("d2", playlists.get(1).getName()); assertEquals(copy.getId(), playlists.get(1).getId()); assertEquals(2, playlists.get(1).getPageReferences().size()); assertEquals(99, playlists.get(1).getPageReferences().get(0).getPageDisplayDurationOverride()); }
@Test(expected = WebApplicationException.class) public void testCopyNonExistentPlaylist() throws Exception { playlistService.copyPlaylist(-1, new Playlist()); }