Class WidgetService

java.lang.Object
io.meeds.ide.service.WidgetService

@Service public class WidgetService extends Object
  • Field Details

  • Constructor Details

    • WidgetService

      public WidgetService()
  • Method Details

    • getWidget

      public Widget getWidget(long id) throws org.exoplatform.commons.exception.ObjectNotFoundException
      Throws:
      org.exoplatform.commons.exception.ObjectNotFoundException
    • getWidget

      public Widget getWidget(long id, String username) throws org.exoplatform.commons.exception.ObjectNotFoundException, IllegalAccessException
      The widget as a reader may see it: an unpublished copy is readable by the editors of the layout it belongs to only, so that its id is never confirmed to anyone else; any other widget is readable as today
      Parameters:
      id - the widget id
      username - the reader, null when anonymous
      Returns:
      the widget
      Throws:
      org.exoplatform.commons.exception.ObjectNotFoundException - when no widget has that id
      IllegalAccessException - when the widget is an unpublished copy the reader may not edit the layout of
    • isDraftCopy

      public boolean isDraftCopy(Widget widget)
      Parameters:
      widget - a widget
      Returns:
      whether it is a copy made for a draft window and not published yet
    • readWidgetCodeOnApplication

      public io.meeds.layout.model.ApplicationCode readWidgetCodeOnApplication(io.meeds.layout.model.ApplicationSettingsContext context)
      The code a window renders, as the layout reads describe it: the code a never-rendered window carries in its data.init preference (an empty code, three null parts, when it is blank or holds no code, as the render builds an empty widget from it), else the widget its widgetId names, else the catalog instance's widget (also for a widgetId naming a deleted widget), else none
      Parameters:
      context - the window
      Returns:
      the code; null when the window has none: no data.init, and no widgetId naming a widget and no catalog instance widget, or a widgetId naming an unpublished copy the user may not read, which stops the read with no fallback
    • updateWidgetCodeOnApplication

      public Widget updateWidgetCodeOnApplication(io.meeds.layout.model.ApplicationSettingsContext context, String liveLayoutKey, String html, String css, String js, String username) throws org.exoplatform.commons.exception.ObjectNotFoundException, IllegalAccessException
      Writes a window's widget code on the user's draft, by ownership: in place when the window's widget is a copy this window owns on this layout, otherwise into a copy the window is pointed at, so that the published layout keeps rendering the previous code until publication. The copy is created with its code, then the window's widgetId preference is set to it and its data.init cleared in one preference write; a failure of that write deletes the copy, which nothing references. Runs under the per-window lock the settings writes take.
      Parameters:
      context - the window on the user's draft, its preferences loaded
      liveLayoutKey - the live page reference or site key the draft belongs to
      html - the HTML to write, null to keep the current one
      css - the CSS to write, null to keep the current one
      js - the JavaScript to write, null to keep the current one
      username - the administrator writing
      Returns:
      the widget the window now renders
      Throws:
      org.exoplatform.commons.exception.ObjectNotFoundException - when the window no longer exists
      IllegalAccessException - when the user is not an administrator or may not edit the layout
    • publishDraftCopies

      public void publishDraftCopies(String layoutKey, org.exoplatform.portal.config.model.ModelObject publishedLayout, String publisher)
      Marks published every unpublished copy a window of the published layout references and whose owner layout is that layout; the ownership markers stay, since ownership keeps deciding copy against in-place on the next draft. Only the copies the publishing user wrote are marked published: a draft is its author's, so a copy reaches the live page through its author's publish, and a copy another editor's draft references (a forged widgetId preference) stays unpublished, readable by the layout's editors only. Called by the publication listener alone.
      Parameters:
      layoutKey - the live page reference or site key just published
      publishedLayout - the published layout's tree, read back after the save
      publisher - the user who published
    • layoutKey

      public static String layoutKey(org.exoplatform.portal.mop.SiteKey siteKey)
      Parameters:
      siteKey - a site key
      Returns:
      the key a copy's owner layout records for a site, the form the publication listener and the REST gating rebuild
    • getWidgetByPortletId

      public Widget getWidgetByPortletId(long portletInstanceId)
    • createWidget

      public Widget createWidget(Widget widget, String username) throws org.exoplatform.commons.ObjectAlreadyExistsException, IllegalAccessException
      Throws:
      org.exoplatform.commons.ObjectAlreadyExistsException
      IllegalAccessException
    • updateWidget

      public Widget updateWidget(Widget widget, String username) throws org.exoplatform.commons.exception.ObjectNotFoundException, IllegalAccessException
      Throws:
      org.exoplatform.commons.exception.ObjectNotFoundException
      IllegalAccessException
    • deleteWidget

      public void deleteWidget(long widgetId, String username) throws org.exoplatform.commons.exception.ObjectNotFoundException, IllegalAccessException
      Throws:
      org.exoplatform.commons.exception.ObjectNotFoundException
      IllegalAccessException