PlaylistService extends BasicService implements OwnerAPISupport<Playlist> { @GET @Path("/playlists/{playlistId}") @Produces(MediaType.APPLICATION_JSON) public Playlist getPlaylist(@PathParam("playlistId") long playlistId, @DefaultValue("false") @QueryParam("visibleOnly") boolean visibleOnly, @DefaultValue("false") @QueryParam("expand") boolean expand, @DefaultValue("true") @QueryParam("includeMetrics") boolean includeMetrics) { Playlist existingPlaylist = getExistingPlaylist(playlistId, false); if (!existingPlaylist.isListPublicly() && !this.isAdmin() && !inAdminOwners(existingPlaylist.getOwners())) { throwUnauthorized(); } if (visibleOnly) { for (PageReference pageReference : existingPlaylist.getPageReferences()) { if (!pageReference.isVisible()) { existingPlaylist.getPageReferences().remove(pageReference); } } } if (expand) { existingPlaylist.expand(); } else { existingPlaylist.breakRecursion(); } if (!includeMetrics) { removePlaylistMetrics(existingPlaylist); } return existingPlaylist; }  @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(expected = WebApplicationException.class) public void testGetNonExistingPlaylist() throws Exception { assertNull(getPlaylist(-1)); }
@Test public void testGetPlaylist() throws Exception { Playlist db = playlistService.createPlaylist(new Playlist("d1")); assertNotNull(getPlaylist(db.getId())); assertEquals(0, getPlaylist(db.getId()).getPageReferences().size()); }