Class ApplicationSettingsService

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

@Service public class ApplicationSettingsService extends Object
The registry of the application settings plugins and the rules every configuration of placed applications follows: an application without a plugin is not configurable, every application is validated before the first one is applied, each one is applied through its plugin while its window is locked on this node, and a failure after the first apply names the applications already applied, nothing being undone.
  • Field Details

  • Constructor Details

    • ApplicationSettingsService

      public ApplicationSettingsService()
  • Method Details

    • addPlugin

      public void addPlugin(ApplicationSettingsPlugin plugin)
      Registers a plugin, replacing the one registered for the same portlet
    • removePlugin

      public void removePlugin(String portletName)
    • isConfigurable

      public boolean isConfigurable(String contentId, boolean siteContainer)
      Parameters:
      contentId - the application content id, app/portlet
      siteContainer - whether the window sits in a site container
      Returns:
      whether a plugin configures the application there
    • getSettingsSchema

      public Map<String,Object> getSettingsSchema(String contentId)
      Parameters:
      contentId - the application content id, app/portlet
      Returns:
      the JSON schema of its settings, null when no plugin configures it
    • newContext

      public ApplicationSettingsContext newContext(org.exoplatform.portal.config.model.Application window, org.exoplatform.portal.mop.page.PageKey pageKey, org.exoplatform.portal.mop.SiteKey siteKey, org.exoplatform.portal.mop.SiteKey liveSiteKey, String pageReference, boolean draft, String username)
      Parameters:
      window - a window of the stored tree
      pageKey - the page holding it, null in a site container
      siteKey - the site holding it
      liveSiteKey - the live site, whose space the setting belongs to
      pageReference - the live page reference: the page's for a page window, the live site's home page for a site-container window, which the caller reads once per site (getSiteHomePageReference(SiteKey)), null while that site has none
      draft - whether the window is the user's draft
      username - the acting user
      Returns:
      the plugins' context of the window
    • getSiteHomePageReference

      public String getSiteHomePageReference(org.exoplatform.portal.mop.SiteKey siteKey)
      The page a setting of a site-container window hangs on: the page of the first navigation item of the site, in tree order, that references a page and is displayed, or scheduled and within its publication window, whatever that page's own access permissions. Its editors may change the window's setting, and whoever may access that page may read the setting, so a first page restricted to a group keeps the setting from the site's other viewers, as a window the site layout editor placed takes the right of the page the site first rendered it on.
      Parameters:
      siteKey - the live site
      Returns:
      the page reference, null while no such item of the site references a page
    • readSettings

      public Map<String,Object> readSettings(ApplicationSettingsContext context)
      Returns:
      the settings of a configurable window as its plugin reads them for the context's user, null when it has none, when the user may not read them or when the plugin fails
    • validate

      public void validate(List<ApplicationSettingsContext> contexts, List<Map<String,Object>> settings, List<String> requestedIds) throws IllegalAccessException, org.exoplatform.commons.exception.ObjectNotFoundException
      Checks every application before anything is written: a plugin configures it where it sits, and its plugin accepts the settings for the context's user
      Parameters:
      contexts - the windows, in the order of the call
      settings - their settings, null-valued entries already dropped
      requestedIds - the ids the call named, for the refusals
      Throws:
      IllegalAccessException - when an application's own rule refuses the user
      org.exoplatform.commons.exception.ObjectNotFoundException - when a referenced object does not exist
      IllegalArgumentException - when no plugin configures an application where it sits, when a list holds a null item, or when a plugin refuses a value, with its fixed text
      IllegalStateException - when a plugin answers a fixed state refusal, or fails without a fixed text, answered as the application not saved
    • apply

      public void apply(List<ApplicationSettingsContext> contexts, List<Map<String,Object>> settings, List<String> requestedIds) throws IllegalAccessException, org.exoplatform.commons.exception.ObjectNotFoundException
      Applies validated settings application after application, each window locked on this node while its plugin writes. A failure of the first application is answered as is; a later one names the applications already applied, which stay applied.
      Parameters:
      contexts - the windows, as validate(List, List, List) checked them, possibly re-pointed at the draft's copies
      settings - their validated settings
      requestedIds - the ids the call named
      Throws:
      IllegalAccessException - when the first application is refused
      org.exoplatform.commons.exception.ObjectNotFoundException - when the first application's object disappeared
    • isOwner

      public boolean isOwner(ApplicationSettingsContext context)
      Returns:
      whether the window carries the ownership marker naming itself: the keys it carries were created for it on this layout version
    • markOwner

      public void markOwner(ApplicationSettingsContext context, Map<String,String> keys) throws IllegalAccessException, org.exoplatform.commons.exception.ObjectNotFoundException
      Stores the keys a plugin created for the window with the ownership marker naming the window, every other preference kept
      Throws:
      IllegalAccessException
      org.exoplatform.commons.exception.ObjectNotFoundException
    • updatePreferences

      public void updatePreferences(ApplicationSettingsContext context, Map<String,String> preferences) throws IllegalAccessException, org.exoplatform.commons.exception.ObjectNotFoundException
      Sets the given preferences of the window, every other preference kept, through the page or the site writer, which check the user's edit right on the layout holding the window
      Throws:
      IllegalAccessException
      org.exoplatform.commons.exception.ObjectNotFoundException
    • dropNullEntries

      public Map<String,Object> dropNullEntries(Map<String,Object> settings)
      Returns:
      a copy of the settings without their null-valued entries, at every depth of the maps they hold: a null asks for nothing
    • pathOf

      public List<Integer> pathOf(org.exoplatform.portal.config.model.ModelObject root, String storageId)
      Returns:
      the child indexes leading from the root to the window, null when the root does not hold it
    • atPath

      public org.exoplatform.portal.config.model.Application atPath(org.exoplatform.portal.config.model.ModelObject root, List<Integer> path)
      Returns:
      the window at the given child indexes, null when the tree holds no window there
    • runLocked

      public <T> T runLocked(String layoutKey, long applicationId, LayoutWrite<T> write) throws org.exoplatform.commons.exception.ObjectNotFoundException, IllegalAccessException
      Runs a write on one window under the node-local lock every tool write on that window takes (a settings write, a widget code write): a lock not obtained within the timeout refuses the write with LAYOUT_BUSY and writes nothing
      Type Parameters:
      T - what the write returns
      Parameters:
      layoutKey - the page reference or the site key the window belongs to
      applicationId - the window's storage id
      write - the write
      Returns:
      what the write returns
      Throws:
      org.exoplatform.commons.exception.ObjectNotFoundException - from the write
      IllegalAccessException - from the write