@Test public void get_shouldThrowNotFound_whenThereAreNoFileMatchingGivenParams() throws Exception { try { medias.get("categories", 999L, "en_GB", "unknown.test"); fail("Should have thrown ex"); } catch (WebApplicationException e) { assertThat(e.getResponse().getStatus()).isEqualTo(Response.Status.NOT_FOUND.getStatusCode()); } }
@GET @Produces(MediaType.APPLICATION_OCTET_STREAM) @RolesAllowed({ADMIN, ADMIN_READONLY}) @Path("/{type}/{id}/{locale}/{filename}") public File get(@NotNull @PathParam("type") String itemType, @NotNull @PathParam("id") Long itemId, @NotNull @PathParam("locale") String locale, @NotNull @PathParam("filename") String fileName) { java.nio.file.Path filePath = getBasePath().resolve(itemType).resolve(itemId.toString()).resolve(locale).resolve(fileName); if (!Files.exists(filePath)) throw new WebApplicationException(Response.Status.NOT_FOUND); return filePath.toFile(); }
Medias { @GET @Produces(MediaType.APPLICATION_OCTET_STREAM) @RolesAllowed({ADMIN, ADMIN_READONLY}) @Path("/{type}/{id}/{locale}/{filename}") public File get(@NotNull @PathParam("type") String itemType, @NotNull @PathParam("id") Long itemId, @NotNull @PathParam("locale") String locale, @NotNull @PathParam("filename") String fileName) { java.nio.file.Path filePath = getBasePath().resolve(itemType).resolve(itemId.toString()).resolve(locale).resolve(fileName); if (!Files.exists(filePath)) throw new WebApplicationException(Response.Status.NOT_FOUND); return filePath.toFile(); } }
Medias { @GET @Produces(MediaType.APPLICATION_OCTET_STREAM) @RolesAllowed({ADMIN, ADMIN_READONLY}) @Path("/{type}/{id}/{locale}/{filename}") public File get(@NotNull @PathParam("type") String itemType, @NotNull @PathParam("id") Long itemId, @NotNull @PathParam("locale") String locale, @NotNull @PathParam("filename") String fileName) { java.nio.file.Path filePath = getBasePath().resolve(itemType).resolve(itemId.toString()).resolve(locale).resolve(fileName); if (!Files.exists(filePath)) throw new WebApplicationException(Response.Status.NOT_FOUND); return filePath.toFile(); }  }
Medias { @GET @Produces(MediaType.APPLICATION_OCTET_STREAM) @RolesAllowed({ADMIN, ADMIN_READONLY}) @Path("/{type}/{id}/{locale}/{filename}") public File get(@NotNull @PathParam("type") String itemType, @NotNull @PathParam("id") Long itemId, @NotNull @PathParam("locale") String locale, @NotNull @PathParam("filename") String fileName) { java.nio.file.Path filePath = getBasePath().resolve(itemType).resolve(itemId.toString()).resolve(locale).resolve(fileName); if (!Files.exists(filePath)) throw new WebApplicationException(Response.Status.NOT_FOUND); return filePath.toFile(); }  @POST @Consumes("multipart/form-data") @Produces(MediaType.APPLICATION_JSON) @RolesAllowed(ADMIN) @Path("/{type}/{id}/{locale}/upload") void upload(@Context HttpServletRequest request, @NotNull @PathParam("type") String itemType, @NotNull @PathParam("id") Long itemId, @NotNull @PathParam("locale") String locale); @GET @Produces(MediaType.APPLICATION_OCTET_STREAM) @RolesAllowed({ADMIN, ADMIN_READONLY}) @Path("/{type}/{id}/{locale}/{filename}") File get(@NotNull @PathParam("type") String itemType, @NotNull @PathParam("id") Long itemId,
                    @NotNull @PathParam("locale") String locale, @NotNull @PathParam("filename") String fileName); }
Medias { @GET @Produces(MediaType.APPLICATION_OCTET_STREAM) @RolesAllowed({ADMIN, ADMIN_READONLY}) @Path("/{type}/{id}/{locale}/{filename}") public File get(@NotNull @PathParam("type") String itemType, @NotNull @PathParam("id") Long itemId, @NotNull @PathParam("locale") String locale, @NotNull @PathParam("filename") String fileName) { java.nio.file.Path filePath = getBasePath().resolve(itemType).resolve(itemId.toString()).resolve(locale).resolve(fileName); if (!Files.exists(filePath)) throw new WebApplicationException(Response.Status.NOT_FOUND); return filePath.toFile(); }  @POST @Consumes("multipart/form-data") @Produces(MediaType.APPLICATION_JSON) @RolesAllowed(ADMIN) @Path("/{type}/{id}/{locale}/upload") void upload(@Context HttpServletRequest request, @NotNull @PathParam("type") String itemType, @NotNull @PathParam("id") Long itemId, @NotNull @PathParam("locale") String locale); @GET @Produces(MediaType.APPLICATION_OCTET_STREAM) @RolesAllowed({ADMIN, ADMIN_READONLY}) @Path("/{type}/{id}/{locale}/{filename}") File get(@NotNull @PathParam("type") String itemType, @NotNull @PathParam("id") Long itemId,
                    @NotNull @PathParam("locale") String locale, @NotNull @PathParam("filename") String fileName);  }