예제 #1
0
 /* (non-Javadoc)
  * @see au.com.twobit.yosane.service.resource.impl.ImagesResource#getImageDetails(java.lang.String)
  */
 @GET
 @Path("/{imageId}")
 @Relation(relation = "image", method = METHOD_GET_IMAGE_DETAILS)
 public Response getImageDetails(@PathParam("imageId") String imageIdentifier) throws Exception {
   ImageStatus status = storage.getImageStatus(imageIdentifier);
   Image image =
       new Image(
           imageIdentifier,
           ImageFormat.png.name(),
           status,
           storage.getImageLastModifiedDate(imageIdentifier));
   String pathbase =
       String.format("%s/%s", getClass().getAnnotation(Path.class).value(), imageIdentifier);
   Link home = createLink(HomeResource.class);
   Link scanners = createLink(ScannersResource.class);
   Representation response =
       hal.newRepresentation(pathbase)
           .withLink(home.getRel(), home.getHref())
           .withLink(scanners.getRel(), scanners.getHref());
   if (status == ImageStatus.MISSING) {
     return ResourceHelper.generateErrorResponse(
         response, ERROR_IMAGE_MISSING, "Image is no longer available");
   }
   response
       .withLink("imageRotate", String.format("%s/rotate", pathbase))
       .withLink("imageDownload", String.format("%s/file", pathbase))
       .withLink("imageDownloadThumb", String.format("%s/file/thumb", pathbase))
       .withBean(image);
   return Response.ok(response.toString(RepresentationFactory.HAL_JSON)).build();
 }
예제 #2
0
 /* (non-Javadoc)
  * @see au.com.twobit.yosane.service.resource.impl.ImagesResource#getImageThumb(java.lang.String)
  */
 @GET
 @Path("/{imageId}/file/thumb")
 @Produces("image/png")
 @Relation(relation = "imageDownloadThumb", method = METHOD_GET_IMAGE_THUMB)
 public Response getImageThumb(@PathParam("imageId") String imageIdentifier) {
   try {
     storage.assertImageStatus(imageIdentifier, ImageStatus.READY);
     BufferedImage image = storage.loadImageThumbnail(imageIdentifier);
     return Response.ok().entity(createByteArrayFromImage(image, png.name())).build();
   } catch (Exception x) {
     return Response.serverError().build();
   }
 }
예제 #3
0
 /* (non-Javadoc)
  * @see au.com.twobit.yosane.service.resource.impl.ImagesResource#getImageFile(java.lang.String)
  */
 @GET
 @Path("/{imageId}/file")
 @Produces("image/png")
 @CacheControl(maxAge = 1, maxAgeUnit = TimeUnit.MINUTES)
 @Relation(relation = "imageDownload", method = METHOD_GET_IMAGE_FILE)
 public Response getImageFile(@PathParam("imageId") String imageIdentifier) {
   try {
     storage.assertImageStatus(imageIdentifier, ImageStatus.READY);
     BufferedImage image = storage.loadImage(imageIdentifier);
     return Response.ok().entity(createByteArrayFromImage(image, png.name())).build();
   } catch (Exception x) {
     return Response.serverError().build();
   }
 }
예제 #4
0
 /* (non-Javadoc)
  * @see au.com.twobit.yosane.service.resource.impl.ImagesResource#rotateImageFile(java.lang.String, java.lang.String)
  */
 @POST
 @Path("/{imageId}/rotate")
 @Produces(MediaType.APPLICATION_JSON)
 public Response rotateImageFile(
     @PathParam("imageId") String imageIdentifier, @QueryParam("direction") String rotation) {
   try {
     RotateDirection direction = RotateDirection.UNKNOWN;
     storage.assertImageStatus(imageIdentifier, ImageStatus.READY);
     direction = RotateDirection.valueOf(rotation.toUpperCase());
     if (direction == RotateDirection.UNKNOWN) {
       throw new Exception();
     }
     executorService.execute(new ImageRotation(storage, imageIdentifier, direction));
     return Response.ok().build();
   } catch (Exception x) {
     x.printStackTrace();
   }
   return Response.serverError().build();
 }