Class LayoutImageService

java.lang.Object
io.meeds.layout.service.LayoutImageService

@Service public class LayoutImageService extends Object
The images a layout write consumes, as the editor's background inputs save them: each upload id of the call is resolved while the description is applied and before any write, then saved as an attachment of its background keyed on the live page or site, as the user, through the attachment service's edit check; the attachment URL replaces the placeholder in the layout before the draft is written; the upload resources are released whether the write succeeds or fails, and the attachments created are deleted when the write that follows them fails.
  • Field Details

    • IMAGE_NOT_SAVED

      public static final String IMAGE_NOT_SAVED
      See Also:
    • ATTACHMENT_URL

      public static final String ATTACHMENT_URL
      See Also:
    • IMAGE_TYPES

      public static final Set<String> IMAGE_TYPES
      The image types upload_layout_image stages, the only ones a consuming call takes: a resource another door staged with another type is refused
  • Constructor Details

    • LayoutImageService

      public LayoutImageService()
  • Method Details

    • consumption

      public ImageConsumption consumption(String keyPrefix, String username)
      Parameters:
      keyPrefix - the live page's or site's storage id, page_<id> or site_<id>, the first segment of every attachment key the call creates
      username - the user consuming the ids
      Returns:
      the consumption the call's writers claim their upload ids on: a staged resource the user may consume, owner-less or their own, and of an image type the upload tool stages
    • isConsumable

      public boolean isConsumable(String uploadId, String username)
      Parameters:
      uploadId - an upload id a call carries
      username - the user consuming it
      Returns:
      whether a consuming call takes it: a staged resource, owner-less or the user's own, of an image type the upload tool stages
    • attach

      public void attach(ImageConsumption images, String username) throws org.exoplatform.commons.exception.ObjectNotFoundException, IllegalAccessException
      Saves each claimed image as an attachment of its target, as the user, and records its URL on the consumption
      Parameters:
      images - the call's consumption
      username - the user writing the layout
      Throws:
      org.exoplatform.commons.exception.ObjectNotFoundException - when a target no longer exists
      IllegalAccessException - when the user may not edit a target
    • substitute

      public void substitute(LayoutModel root, ImageConsumption images)
      Replaces every placeholder of the layout tree with the URL of the attachment saved for it
      Parameters:
      root - the layout to write
      images - the call's consumption, its attachments saved
    • compensate

      public void compensate(ImageConsumption images)
      Deletes the attachments the call created, when the layout write that followed them failed
      Parameters:
      images - the call's consumption
    • release

      public void release(ImageConsumption images)
      Releases every upload resource the call claimed: a consumed one is already gone, an unconsumed one goes with the failed call
      Parameters:
      images - the call's consumption