public Notifier addNotifierInfo(Notifier notifier) { if (notifier.getId() == null) { notifier.setId(this.dao.nextId(NOTIFIER_INFO_NAMESPACE)); } if (notifier.getTimestamp() == null) { notifier.setTimestamp(System.currentTimeMillis()); } if (StringUtils.isEmpty(notifier.getName())) { throw new StorageException("Notifier name empty"); } this.dao.add(notifier); return notifier; }
@PUT @Consumes(MediaType.MULTIPART_FORM_DATA) @Path("/notifiers/{id}") @Timed public Response addOrUpdateNotifierInfo(@PathParam("id") Long id, @FormDataParam("notifierJarFile") final InputStream inputStream, @FormDataParam("notifierJarFile") final FormDataContentDisposition contentDispositionHeader, @FormDataParam("notifierConfig") final FormDataBodyPart notifierConfig, @Context SecurityContext securityContext) throws IOException { SecurityUtil.checkPermissions(authorizer, securityContext, Notifier.NAMESPACE, id, WRITE); 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); String jarFileName = uploadJar(inputStream, notifier.getName()); notifier.setJarFileName(jarFileName); Notifier newNotifier = catalogService.addOrUpdateNotifierInfo(id, notifier); return WSUtils.respondEntity(newNotifier, CREATED); }
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);