@Test public void testAddNotifier() throws Exception { final Notifier notifier = new Notifier(); notifier.setName("test"); new Expectations() { { mockCatalogService.addNotifierInfo(notifier);times=1; result = notifier; mockFormDataBodyPart.getMediaType(); result = APPLICATION_JSON_TYPE; mockFormDataBodyPart.getValueAs(Notifier.class); result = notifier; mockFileStorage.upload(mockInputStream, anyString); result = "uploadedPath"; } }; Notifier result = (Notifier) resource.addNotifier( mockInputStream, mockFormDataContentDisposition, mockFormDataBodyPart, securityContext).getEntity(); assertEquals(notifier, result); }
@POST @Consumes(MediaType.MULTIPART_FORM_DATA) @Path("/notifiers") @Timed public Response addNotifier(@FormDataParam("notifierJarFile") final InputStream inputStream, @FormDataParam("notifierJarFile") final FormDataContentDisposition contentDispositionHeader, @FormDataParam("notifierConfig") final FormDataBodyPart notifierConfig, @Context SecurityContext securityContext) throws IOException { SecurityUtil.checkRole(authorizer, securityContext, Roles.ROLE_NOTIFIER_ADMIN); MediaType mediaType = notifierConfig.getMediaType(); LOG.debug("Media type {}", mediaType); if (!mediaType.equals(MediaType.APPLICATION_JSON_TYPE)) { throw new UnsupportedMediaTypeException(mediaType.toString()); } Notifier notifier = notifierConfig.getValueAs(Notifier.class); Collection<Notifier> existing = null; existing = catalogService.listNotifierInfos(Collections.singletonList(new QueryParam(Notifier.NOTIFIER_NAME, notifier.getName()))); if (existing != null && !existing.isEmpty()) { LOG.warn("Received a post request for an already registered notifier. Not creating entity for " + notifier); return WSUtils.respondEntity(notifier, CONFLICT); } String jarFileName = uploadJar(inputStream, notifier.getName()); notifier.setJarFileName(jarFileName); Notifier createdNotifier = catalogService.addNotifierInfo(notifier); SecurityUtil.addAcl(authorizer, securityContext, Notifier.NAMESPACE, createdNotifier.getId(), EnumSet.allOf(Permission.class)); return WSUtils.respondEntity(createdNotifier, CREATED); }
NotifierInfoCatalogResource { @POST @Consumes(MediaType.MULTIPART_FORM_DATA) @Path("/notifiers") @Timed public Response addNotifier(@FormDataParam("notifierJarFile") final InputStream inputStream, @FormDataParam("notifierJarFile") final FormDataContentDisposition contentDispositionHeader, @FormDataParam("notifierConfig") final FormDataBodyPart notifierConfig, @Context SecurityContext securityContext) throws IOException { SecurityUtil.checkRole(authorizer, securityContext, Roles.ROLE_NOTIFIER_ADMIN); MediaType mediaType = notifierConfig.getMediaType(); LOG.debug("Media type {}", mediaType); if (!mediaType.equals(MediaType.APPLICATION_JSON_TYPE)) { throw new UnsupportedMediaTypeException(mediaType.toString()); } Notifier notifier = notifierConfig.getValueAs(Notifier.class); Collection<Notifier> existing = null; existing = catalogService.listNotifierInfos(Collections.singletonList(new QueryParam(Notifier.NOTIFIER_NAME, notifier.getName()))); if (existing != null && !existing.isEmpty()) { LOG.warn("Received a post request for an already registered notifier. Not creating entity for " + notifier); return WSUtils.respondEntity(notifier, CONFLICT); } String jarFileName = uploadJar(inputStream, notifier.getName()); notifier.setJarFileName(jarFileName); Notifier createdNotifier = catalogService.addNotifierInfo(notifier); SecurityUtil.addAcl(authorizer, securityContext, Notifier.NAMESPACE, createdNotifier.getId(), EnumSet.allOf(Permission.class)); return WSUtils.respondEntity(createdNotifier, CREATED); } }
NotifierInfoCatalogResource { @POST @Consumes(MediaType.MULTIPART_FORM_DATA) @Path("/notifiers") @Timed public Response addNotifier(@FormDataParam("notifierJarFile") final InputStream inputStream, @FormDataParam("notifierJarFile") final FormDataContentDisposition contentDispositionHeader, @FormDataParam("notifierConfig") final FormDataBodyPart notifierConfig, @Context SecurityContext securityContext) throws IOException { SecurityUtil.checkRole(authorizer, securityContext, Roles.ROLE_NOTIFIER_ADMIN); MediaType mediaType = notifierConfig.getMediaType(); LOG.debug("Media type {}", mediaType); if (!mediaType.equals(MediaType.APPLICATION_JSON_TYPE)) { throw new UnsupportedMediaTypeException(mediaType.toString()); } Notifier notifier = notifierConfig.getValueAs(Notifier.class); Collection<Notifier> existing = null; existing = catalogService.listNotifierInfos(Collections.singletonList(new QueryParam(Notifier.NOTIFIER_NAME, notifier.getName()))); if (existing != null && !existing.isEmpty()) { LOG.warn("Received a post request for an already registered notifier. Not creating entity for " + notifier); return WSUtils.respondEntity(notifier, CONFLICT); } String jarFileName = uploadJar(inputStream, notifier.getName()); notifier.setJarFileName(jarFileName); Notifier createdNotifier = catalogService.addNotifierInfo(notifier); SecurityUtil.addAcl(authorizer, securityContext, Notifier.NAMESPACE, createdNotifier.getId(), EnumSet.allOf(Permission.class)); return WSUtils.respondEntity(createdNotifier, CREATED); } NotifierInfoCatalogResource(StreamlineAuthorizer authorizer, StreamCatalogService catalogService, FileStorage fileStorage); }
NotifierInfoCatalogResource { @POST @Consumes(MediaType.MULTIPART_FORM_DATA) @Path("/notifiers") @Timed public Response addNotifier(@FormDataParam("notifierJarFile") final InputStream inputStream, @FormDataParam("notifierJarFile") final FormDataContentDisposition contentDispositionHeader, @FormDataParam("notifierConfig") final FormDataBodyPart notifierConfig, @Context SecurityContext securityContext) throws IOException { SecurityUtil.checkRole(authorizer, securityContext, Roles.ROLE_NOTIFIER_ADMIN); MediaType mediaType = notifierConfig.getMediaType(); LOG.debug("Media type {}", mediaType); if (!mediaType.equals(MediaType.APPLICATION_JSON_TYPE)) { throw new UnsupportedMediaTypeException(mediaType.toString()); } Notifier notifier = notifierConfig.getValueAs(Notifier.class); Collection<Notifier> existing = null; existing = catalogService.listNotifierInfos(Collections.singletonList(new QueryParam(Notifier.NOTIFIER_NAME, notifier.getName()))); if (existing != null && !existing.isEmpty()) { LOG.warn("Received a post request for an already registered notifier. Not creating entity for " + notifier); return WSUtils.respondEntity(notifier, CONFLICT); } String jarFileName = uploadJar(inputStream, notifier.getName()); notifier.setJarFileName(jarFileName); Notifier createdNotifier = catalogService.addNotifierInfo(notifier); SecurityUtil.addAcl(authorizer, securityContext, Notifier.NAMESPACE, createdNotifier.getId(), EnumSet.allOf(Permission.class)); return WSUtils.respondEntity(createdNotifier, CREATED); } NotifierInfoCatalogResource(StreamlineAuthorizer authorizer, StreamCatalogService catalogService, FileStorage fileStorage); @GET @Path("/notifiers") @Timed Response listNotifiers(@Context UriInfo uriInfo, @Context SecurityContext securityContext); @GET @Path("/notifiers/{id}") @Timed Response getNotifierById(@PathParam("id") Long id, @Context SecurityContext securityContext); @POST @Consumes(MediaType.MULTIPART_FORM_DATA) @Path("/notifiers") @Timed Response addNotifier(@FormDataParam("notifierJarFile") final InputStream inputStream,
                                @FormDataParam("notifierJarFile") final FormDataContentDisposition contentDispositionHeader,
                                @FormDataParam("notifierConfig") final FormDataBodyPart notifierConfig,
                                @Context SecurityContext securityContext); @DELETE @Path("/notifiers/{id}") @Timed Response removeNotifierInfo(@PathParam("id") Long id, @Context SecurityContext securityContext); @PUT @Consumes(MediaType.MULTIPART_FORM_DATA) @Path("/notifiers/{id}") @Timed Response addOrUpdateNotifierInfo(@PathParam("id") Long id,
                                            @FormDataParam("notifierJarFile") final InputStream inputStream,
                                            @FormDataParam("notifierJarFile") final FormDataContentDisposition contentDispositionHeader,
                                            @FormDataParam("notifierConfig") final FormDataBodyPart notifierConfig,
                                            @Context SecurityContext securityContext); @Timed @GET @Produces({"application/java-archive", "application/json"}) @Path("/notifiers/download/{notifierId}") Response downloadNotifier(@PathParam("notifierId") Long notifierId, @Context SecurityContext securityContext); }
NotifierInfoCatalogResource { @POST @Consumes(MediaType.MULTIPART_FORM_DATA) @Path("/notifiers") @Timed public Response addNotifier(@FormDataParam("notifierJarFile") final InputStream inputStream, @FormDataParam("notifierJarFile") final FormDataContentDisposition contentDispositionHeader, @FormDataParam("notifierConfig") final FormDataBodyPart notifierConfig, @Context SecurityContext securityContext) throws IOException { SecurityUtil.checkRole(authorizer, securityContext, Roles.ROLE_NOTIFIER_ADMIN); MediaType mediaType = notifierConfig.getMediaType(); LOG.debug("Media type {}", mediaType); if (!mediaType.equals(MediaType.APPLICATION_JSON_TYPE)) { throw new UnsupportedMediaTypeException(mediaType.toString()); } Notifier notifier = notifierConfig.getValueAs(Notifier.class); Collection<Notifier> existing = null; existing = catalogService.listNotifierInfos(Collections.singletonList(new QueryParam(Notifier.NOTIFIER_NAME, notifier.getName()))); if (existing != null && !existing.isEmpty()) { LOG.warn("Received a post request for an already registered notifier. Not creating entity for " + notifier); return WSUtils.respondEntity(notifier, CONFLICT); } String jarFileName = uploadJar(inputStream, notifier.getName()); notifier.setJarFileName(jarFileName); Notifier createdNotifier = catalogService.addNotifierInfo(notifier); SecurityUtil.addAcl(authorizer, securityContext, Notifier.NAMESPACE, createdNotifier.getId(), EnumSet.allOf(Permission.class)); return WSUtils.respondEntity(createdNotifier, CREATED); } NotifierInfoCatalogResource(StreamlineAuthorizer authorizer, StreamCatalogService catalogService, FileStorage fileStorage); @GET @Path("/notifiers") @Timed Response listNotifiers(@Context UriInfo uriInfo, @Context SecurityContext securityContext); @GET @Path("/notifiers/{id}") @Timed Response getNotifierById(@PathParam("id") Long id, @Context SecurityContext securityContext); @POST @Consumes(MediaType.MULTIPART_FORM_DATA) @Path("/notifiers") @Timed Response addNotifier(@FormDataParam("notifierJarFile") final InputStream inputStream,
                                @FormDataParam("notifierJarFile") final FormDataContentDisposition contentDispositionHeader,
                                @FormDataParam("notifierConfig") final FormDataBodyPart notifierConfig,
                                @Context SecurityContext securityContext); @DELETE @Path("/notifiers/{id}") @Timed Response removeNotifierInfo(@PathParam("id") Long id, @Context SecurityContext securityContext); @PUT @Consumes(MediaType.MULTIPART_FORM_DATA) @Path("/notifiers/{id}") @Timed Response addOrUpdateNotifierInfo(@PathParam("id") Long id,
                                            @FormDataParam("notifierJarFile") final InputStream inputStream,
                                            @FormDataParam("notifierJarFile") final FormDataContentDisposition contentDispositionHeader,
                                            @FormDataParam("notifierConfig") final FormDataBodyPart notifierConfig,
                                            @Context SecurityContext securityContext); @Timed @GET @Produces({"application/java-archive", "application/json"}) @Path("/notifiers/download/{notifierId}") Response downloadNotifier(@PathParam("notifierId") Long notifierId, @Context SecurityContext securityContext);  }