Пример #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();
 }
  @Override
  public Representation newRepresentation(String href) {
    MutableRepresentation representation = new MutableRepresentation(this, href);

    // Add factory standard namespaces
    for (Map.Entry<String, String> entry : namespaceManager.getNamespaces().entrySet()) {
      representation.withNamespace(entry.getKey(), entry.getValue());
    }

    // Add factory standard links
    for (Link link : links) {
      representation.withLink(
          link.getRel(),
          link.getHref(),
          link.getName(),
          link.getTitle(),
          link.getHreflang(),
          link.getProfile());
    }

    return representation;
  }