@Test public void testCreateMediaCheckForNull() { List<Attachment> attachments = null; Response response = mediaServiceRest.createMedia(attachments); assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus()); }
@Override public Response createMedia(final List<Attachment> attachments) { LOGGER.info("createMedia {}", attachments); if (attachments == null || attachments.isEmpty()) { LOGGER.error("Expected non-empty attachments. Returning without creating Media."); return Response.status(Response.Status.BAD_REQUEST).build(); } final Map<String, String> mediaDataMap = new HashMap<>(); final Map<String, Object> mediaFileDataMap = new HashMap<>(); attachments.forEach(attachment -> { try { if (attachment.getHeaders().size() < 2) { return; } if (attachment.getHeader("Content-Type") == null) { mediaDataMap.put(attachment.getDataHandler().getName(), IOUtils.toString(attachment.getDataHandler().getInputStream(), Charset.defaultCharset())); } else { mediaFileDataMap.put("filename", attachment.getDataHandler().getName()); mediaFileDataMap.put("content", new BufferedInputStream(attachment.getDataHandler().getInputStream())); } } catch (final IOException e) { LOGGER.error("Failed to retrieve attachments!", e); Response.status(Response.Status.BAD_REQUEST).build(); } }); return ResponseBuilder.created(mediaService.create(mediaDataMap, mediaFileDataMap)); }
MediaServiceRestImpl implements MediaServiceRest { @Override public Response createMedia(final List<Attachment> attachments) { LOGGER.info("createMedia {}", attachments); if (attachments == null || attachments.isEmpty()) { LOGGER.error("Expected non-empty attachments. Returning without creating Media."); return Response.status(Response.Status.BAD_REQUEST).build(); } final Map<String, String> mediaDataMap = new HashMap<>(); final Map<String, Object> mediaFileDataMap = new HashMap<>(); attachments.forEach(attachment -> { try { if (attachment.getHeaders().size() < 2) { return; } if (attachment.getHeader("Content-Type") == null) { mediaDataMap.put(attachment.getDataHandler().getName(), IOUtils.toString(attachment.getDataHandler().getInputStream(), Charset.defaultCharset())); } else { mediaFileDataMap.put("filename", attachment.getDataHandler().getName()); mediaFileDataMap.put("content", new BufferedInputStream(attachment.getDataHandler().getInputStream())); } } catch (final IOException e) { LOGGER.error("Failed to retrieve attachments!", e); Response.status(Response.Status.BAD_REQUEST).build(); } }); return ResponseBuilder.created(mediaService.create(mediaDataMap, mediaFileDataMap)); } }
MediaServiceRestImpl implements MediaServiceRest { @Override public Response createMedia(final List<Attachment> attachments) { LOGGER.info("createMedia {}", attachments); if (attachments == null || attachments.isEmpty()) { LOGGER.error("Expected non-empty attachments. Returning without creating Media."); return Response.status(Response.Status.BAD_REQUEST).build(); } final Map<String, String> mediaDataMap = new HashMap<>(); final Map<String, Object> mediaFileDataMap = new HashMap<>(); attachments.forEach(attachment -> { try { if (attachment.getHeaders().size() < 2) { return; } if (attachment.getHeader("Content-Type") == null) { mediaDataMap.put(attachment.getDataHandler().getName(), IOUtils.toString(attachment.getDataHandler().getInputStream(), Charset.defaultCharset())); } else { mediaFileDataMap.put("filename", attachment.getDataHandler().getName()); mediaFileDataMap.put("content", new BufferedInputStream(attachment.getDataHandler().getInputStream())); } } catch (final IOException e) { LOGGER.error("Failed to retrieve attachments!", e); Response.status(Response.Status.BAD_REQUEST).build(); } }); return ResponseBuilder.created(mediaService.create(mediaDataMap, mediaFileDataMap)); }  }
MediaServiceRestImpl implements MediaServiceRest { @Override public Response createMedia(final List<Attachment> attachments) { LOGGER.info("createMedia {}", attachments); if (attachments == null || attachments.isEmpty()) { LOGGER.error("Expected non-empty attachments. Returning without creating Media."); return Response.status(Response.Status.BAD_REQUEST).build(); } final Map<String, String> mediaDataMap = new HashMap<>(); final Map<String, Object> mediaFileDataMap = new HashMap<>(); attachments.forEach(attachment -> { try { if (attachment.getHeaders().size() < 2) { return; } if (attachment.getHeader("Content-Type") == null) { mediaDataMap.put(attachment.getDataHandler().getName(), IOUtils.toString(attachment.getDataHandler().getInputStream(), Charset.defaultCharset())); } else { mediaFileDataMap.put("filename", attachment.getDataHandler().getName()); mediaFileDataMap.put("content", new BufferedInputStream(attachment.getDataHandler().getInputStream())); } } catch (final IOException e) { LOGGER.error("Failed to retrieve attachments!", e); Response.status(Response.Status.BAD_REQUEST).build(); } }); return ResponseBuilder.created(mediaService.create(mediaDataMap, mediaFileDataMap)); }  @Override Response createMedia(final List<Attachment> attachments); @Override Response updateMedia(final JpaMedia media, final AuthenticatedUser aUser); @Override Response removeMedia(final String name, String type, final AuthenticatedUser aUser); @Override Response getMedia(final Long id, final String mediaName, final AuthenticatedUser aUser); @Override Response getMediaTypes(); }
MediaServiceRestImpl implements MediaServiceRest { @Override public Response createMedia(final List<Attachment> attachments) { LOGGER.info("createMedia {}", attachments); if (attachments == null || attachments.isEmpty()) { LOGGER.error("Expected non-empty attachments. Returning without creating Media."); return Response.status(Response.Status.BAD_REQUEST).build(); } final Map<String, String> mediaDataMap = new HashMap<>(); final Map<String, Object> mediaFileDataMap = new HashMap<>(); attachments.forEach(attachment -> { try { if (attachment.getHeaders().size() < 2) { return; } if (attachment.getHeader("Content-Type") == null) { mediaDataMap.put(attachment.getDataHandler().getName(), IOUtils.toString(attachment.getDataHandler().getInputStream(), Charset.defaultCharset())); } else { mediaFileDataMap.put("filename", attachment.getDataHandler().getName()); mediaFileDataMap.put("content", new BufferedInputStream(attachment.getDataHandler().getInputStream())); } } catch (final IOException e) { LOGGER.error("Failed to retrieve attachments!", e); Response.status(Response.Status.BAD_REQUEST).build(); } }); return ResponseBuilder.created(mediaService.create(mediaDataMap, mediaFileDataMap)); }  @Override Response createMedia(final List<Attachment> attachments); @Override Response updateMedia(final JpaMedia media, final AuthenticatedUser aUser); @Override Response removeMedia(final String name, String type, final AuthenticatedUser aUser); @Override Response getMedia(final Long id, final String mediaName, final AuthenticatedUser aUser); @Override Response getMediaTypes();  }