@Test public void testUpdateRequestedOwner() throws Exception { Screen screen = screenService.getScreenByKey("key1", false, false, true, null); doReturn(true).when(screenService).isAdmin(); Screen screenUpdate = new Screen(); screenUpdate.setRequestedOwner("newowner"); screen = screenService.updateRequestedOwner(screen.getId(), screenUpdate); assertEquals("newowner", screen.getRequestedOwner()); screen = screenService.onboardScreen(screenService.getOnboardings().get(0).getId()); assertEquals("newowner", screen.getOwners().get(0).getUser().getUserId()); }
@PUT @Path("/screens/{id}/requestedOwner") @Produces(MediaType.APPLICATION_JSON) public Screen updateRequestedOwner(@PathParam("id") long screenId, Screen screenData) { if (!isAdmin()) { throwUnauthorized(); } Screen existingScreen = new ScreenDAO().getById(screenId); if (!existingScreen.getOwners().isEmpty()) { throwBadRequest(); } existingScreen.setRequestedOwner(screenData.getRequestedOwner()); existingScreen = ScreenDAO.save(existingScreen); if (existingScreen.getPlaylist() != null) { existingScreen.getPlaylist().expand(); } return existingScreen; }
ScreenService extends BasicService implements OwnerAPISupport<Screen> { @PUT @Path("/screens/{id}/requestedOwner") @Produces(MediaType.APPLICATION_JSON) public Screen updateRequestedOwner(@PathParam("id") long screenId, Screen screenData) { if (!isAdmin()) { throwUnauthorized(); } Screen existingScreen = new ScreenDAO().getById(screenId); if (!existingScreen.getOwners().isEmpty()) { throwBadRequest(); } existingScreen.setRequestedOwner(screenData.getRequestedOwner()); existingScreen = ScreenDAO.save(existingScreen); if (existingScreen.getPlaylist() != null) { existingScreen.getPlaylist().expand(); } return existingScreen; } }
ScreenService extends BasicService implements OwnerAPISupport<Screen> { @PUT @Path("/screens/{id}/requestedOwner") @Produces(MediaType.APPLICATION_JSON) public Screen updateRequestedOwner(@PathParam("id") long screenId, Screen screenData) { if (!isAdmin()) { throwUnauthorized(); } Screen existingScreen = new ScreenDAO().getById(screenId); if (!existingScreen.getOwners().isEmpty()) { throwBadRequest(); } existingScreen.setRequestedOwner(screenData.getRequestedOwner()); existingScreen = ScreenDAO.save(existingScreen); if (existingScreen.getPlaylist() != null) { existingScreen.getPlaylist().expand(); } return existingScreen; }  }
ScreenService extends BasicService implements OwnerAPISupport<Screen> { @PUT @Path("/screens/{id}/requestedOwner") @Produces(MediaType.APPLICATION_JSON) public Screen updateRequestedOwner(@PathParam("id") long screenId, Screen screenData) { if (!isAdmin()) { throwUnauthorized(); } Screen existingScreen = new ScreenDAO().getById(screenId); if (!existingScreen.getOwners().isEmpty()) { throwBadRequest(); } existingScreen.setRequestedOwner(screenData.getRequestedOwner()); existingScreen = ScreenDAO.save(existingScreen); if (existingScreen.getPlaylist() != null) { existingScreen.getPlaylist().expand(); } return existingScreen; }  @GET @Path("/screens") @Produces(MediaType.APPLICATION_JSON) List<Screen> getScreens(@QueryParam("userId") String userId); @GET @Path("/onboardings") @Produces(MediaType.APPLICATION_JSON) List<Screen> getOnboardings(); @GET @Path("/screens/{id}") @Produces(MediaType.APPLICATION_JSON) Screen getScreen(@PathParam("id") long screenId,
			@DefaultValue("true") @QueryParam("includeMetrics") boolean includeMetrics,
			@DefaultValue("false") @QueryParam("live") boolean live); @GET @Path("/screens/bykey/{key}") @Produces(MediaType.APPLICATION_JSON) Screen getScreenByKey(@PathParam("key") String key,
			@DefaultValue("true") @QueryParam("includeMetrics") boolean includeMetrics,
			@DefaultValue("false") @QueryParam("live") boolean live,
			@DefaultValue("false") @QueryParam("autoOnboard") boolean doOnboarding,
			@QueryParam("owner") String requestedOwner); @POST @Path("/screens") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) Screen createScreen(Screen screen); @PUT @Path("/screens/{id}") @Produces(MediaType.APPLICATION_JSON) Screen updateScreen(@PathParam("id") long screenId, Screen screenData); @PUT @Path("/screens/{id}/statistics") @Produces(MediaType.APPLICATION_JSON) Screen updateScreenStatstics(@PathParam("id") long screenId, Screen screenData); @GET @Path("/screens/{id}/health") @Produces(MediaType.APPLICATION_JSON) Screen.AliveState getScreenHealth(@PathParam("id") long screenId); @GET @Path("/screens/{id}/events") @Produces(MediaType.APPLICATION_JSON) List<EventHistory> getScreenEvents(@PathParam("id") long screenId); @GET @Path("/screens/{id}/eventsperhour") @Produces(MediaType.APPLICATION_JSON) List<BasicNameValuePair> getScreenEventsPerHour(@PathParam("id") long screenId); @GET @Path("/screens/{id}/control") @Produces(MediaType.APPLICATION_JSON) Integer getRemoteKey(@PathParam("id") long screenId); @PUT @Path("/screens/{id}/control/{key}") @Produces(MediaType.APPLICATION_JSON) Screen remoteControlScreen(@PathParam("id") long screenId, Screen screenData, @PathParam("key") int key); @POST @Path("/screens/{id}/copy") @Consumes(MediaType.APPLICATION_JSON) Screen copyScreen(@PathParam("id") long screenId, Screen newScreen); @PUT @Path("/screens/{id}/requestedOwner") @Produces(MediaType.APPLICATION_JSON) Screen updateRequestedOwner(@PathParam("id") long screenId, Screen screenData); @POST @Path("/screens/{id}/onboard") @Produces(MediaType.APPLICATION_JSON) Screen onboardScreen(@PathParam("id") long screenId); @POST @Path("/claim/{key}") @Produces(MediaType.APPLICATION_JSON) Screen claimScreen(@PathParam("key") String key, @DefaultValue("0") @QueryParam("screenId") long screenId); @DELETE @Path("/screens/{screenId}") Response deleteScreen(@PathParam("screenId") long screenId); @Override @POST @Path("/screens/{screenId}/owners") @Consumes(MediaType.APPLICATION_JSON) Screen addOwners(@PathParam("screenId") long screenId, Owner[] ownerData); @Override @DELETE @Path("/screens/{screenId}/owners/{ownerId}") @Produces(MediaType.APPLICATION_JSON) Screen deleteOwner(@PathParam("screenId") long screenId, @PathParam("ownerId") long ownerId); @POST @Path("/screenkey/{key}/appliancestart") @Consumes(MediaType.APPLICATION_JSON) Response registerApplianceStart(@PathParam("key") String key, ApplianceInfo logContent); }
ScreenService extends BasicService implements OwnerAPISupport<Screen> { @PUT @Path("/screens/{id}/requestedOwner") @Produces(MediaType.APPLICATION_JSON) public Screen updateRequestedOwner(@PathParam("id") long screenId, Screen screenData) { if (!isAdmin()) { throwUnauthorized(); } Screen existingScreen = new ScreenDAO().getById(screenId); if (!existingScreen.getOwners().isEmpty()) { throwBadRequest(); } existingScreen.setRequestedOwner(screenData.getRequestedOwner()); existingScreen = ScreenDAO.save(existingScreen); if (existingScreen.getPlaylist() != null) { existingScreen.getPlaylist().expand(); } return existingScreen; }  @GET @Path("/screens") @Produces(MediaType.APPLICATION_JSON) List<Screen> getScreens(@QueryParam("userId") String userId); @GET @Path("/onboardings") @Produces(MediaType.APPLICATION_JSON) List<Screen> getOnboardings(); @GET @Path("/screens/{id}") @Produces(MediaType.APPLICATION_JSON) Screen getScreen(@PathParam("id") long screenId,
			@DefaultValue("true") @QueryParam("includeMetrics") boolean includeMetrics,
			@DefaultValue("false") @QueryParam("live") boolean live); @GET @Path("/screens/bykey/{key}") @Produces(MediaType.APPLICATION_JSON) Screen getScreenByKey(@PathParam("key") String key,
			@DefaultValue("true") @QueryParam("includeMetrics") boolean includeMetrics,
			@DefaultValue("false") @QueryParam("live") boolean live,
			@DefaultValue("false") @QueryParam("autoOnboard") boolean doOnboarding,
			@QueryParam("owner") String requestedOwner); @POST @Path("/screens") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) Screen createScreen(Screen screen); @PUT @Path("/screens/{id}") @Produces(MediaType.APPLICATION_JSON) Screen updateScreen(@PathParam("id") long screenId, Screen screenData); @PUT @Path("/screens/{id}/statistics") @Produces(MediaType.APPLICATION_JSON) Screen updateScreenStatstics(@PathParam("id") long screenId, Screen screenData); @GET @Path("/screens/{id}/health") @Produces(MediaType.APPLICATION_JSON) Screen.AliveState getScreenHealth(@PathParam("id") long screenId); @GET @Path("/screens/{id}/events") @Produces(MediaType.APPLICATION_JSON) List<EventHistory> getScreenEvents(@PathParam("id") long screenId); @GET @Path("/screens/{id}/eventsperhour") @Produces(MediaType.APPLICATION_JSON) List<BasicNameValuePair> getScreenEventsPerHour(@PathParam("id") long screenId); @GET @Path("/screens/{id}/control") @Produces(MediaType.APPLICATION_JSON) Integer getRemoteKey(@PathParam("id") long screenId); @PUT @Path("/screens/{id}/control/{key}") @Produces(MediaType.APPLICATION_JSON) Screen remoteControlScreen(@PathParam("id") long screenId, Screen screenData, @PathParam("key") int key); @POST @Path("/screens/{id}/copy") @Consumes(MediaType.APPLICATION_JSON) Screen copyScreen(@PathParam("id") long screenId, Screen newScreen); @PUT @Path("/screens/{id}/requestedOwner") @Produces(MediaType.APPLICATION_JSON) Screen updateRequestedOwner(@PathParam("id") long screenId, Screen screenData); @POST @Path("/screens/{id}/onboard") @Produces(MediaType.APPLICATION_JSON) Screen onboardScreen(@PathParam("id") long screenId); @POST @Path("/claim/{key}") @Produces(MediaType.APPLICATION_JSON) Screen claimScreen(@PathParam("key") String key, @DefaultValue("0") @QueryParam("screenId") long screenId); @DELETE @Path("/screens/{screenId}") Response deleteScreen(@PathParam("screenId") long screenId); @Override @POST @Path("/screens/{screenId}/owners") @Consumes(MediaType.APPLICATION_JSON) Screen addOwners(@PathParam("screenId") long screenId, Owner[] ownerData); @Override @DELETE @Path("/screens/{screenId}/owners/{ownerId}") @Produces(MediaType.APPLICATION_JSON) Screen deleteOwner(@PathParam("screenId") long screenId, @PathParam("ownerId") long ownerId); @POST @Path("/screenkey/{key}/appliancestart") @Consumes(MediaType.APPLICATION_JSON) Response registerApplianceStart(@PathParam("key") String key, ApplianceInfo logContent);  }