Class MyApplicationsSettingsService

java.lang.Object
io.meeds.appcenter.service.MyApplicationsSettingsService

@Service public class MyApplicationsSettingsService extends Object
Settings of the Shortcuts portlet (AppCenterMyApplicationsPortlet): who may change them, which preferences a settings write may store, and the header title keyed on the portlet's CMS setting name.
  • Field Details

  • Constructor Details

    • MyApplicationsSettingsService

      public MyApplicationsSettingsService()
  • Method Details

    • canEditSettings

      public boolean canEditSettings(String settingName, String username)
      Whether a user may change the settings of a Shortcuts portlet window, header title included: the page-content right of the window's page, in the space owning that page's site, whatever space its setting recorded, the site edit right for a site-layout window, administrators only for a shared-layout window, whose context is the platform's whatever space its setting recorded, and for a window whose setting was recorded on a section-template draft page, whatever its name. A shared-layout window is told by its generated name, or, for a window of a configured shared layout, which has no storage id, so no generated name, by the SHARED_LAYOUT_REFERENCE its setting records; such a window whose setting was recorded before keeps the right of the page that first rendered it.
      Parameters:
      settingName - the window's CMS setting name
      username - the user, null or anonymous for a guest
      Returns:
      true when the user may write the window's settings
    • canEditLegacyHeaderTitle

      public boolean canEditLegacyHeaderTitle(String username)
      Whether a user may change a header title stored under a legacy numeric object id, the random applicationId the portlet used before the title was keyed on the setting name: administrators only.
      Parameters:
      username - the user, null or anonymous for a guest
      Returns:
      true when the user is an administrator
    • getSettingsToStore

      public Map<String,String> getSettingsToStore(String settingName, String username, Map<String,String> parameters) throws IllegalAccessException
      Decides a settings write of a Shortcuts portlet window: refuses a user who may not edit the window's settings, before reading any parameter, then keeps only the preferences the portlet owns, each with a valid value.
      Parameters:
      settingName - the window's CMS setting name, read from its stored preferences, never from the request
      username - the user, null or anonymous for a guest
      parameters - posted parameters
      Returns:
      the preferences to store, by name
      Throws:
      IllegalAccessException - when the user may not edit the settings
      IllegalArgumentException - when the write selects the SELECTED listing mode with no application to list
    • getWritableSettings

      public Map<String,String> getWritableSettings(String settingName, Map<String,String> parameters)
      Filters the parameters of a settings write down to the preferences the Shortcuts portlet owns, each with a valid value. Any other name, among which name, applicationId, data.init, canEdit and settingName, and any invalid value is dropped, and so is the id of an application that no longer exists or that another Shortcuts portlet window created, and of a category that no longer exists. The selection mode, the application ids and the category ids are stored only with a listing mode, both lists whatever the selection mode, so that switching modes keeps the other list. A write selecting the SELECTED listing mode is refused as a whole unless it selects the MANUAL mode with at least one application, or the CATEGORY mode with at least one category: a SELECTED listing is never stored empty.
      Parameters:
      settingName - the window's CMS setting name
      parameters - posted parameters
      Returns:
      the preferences to store, by name
      Throws:
      IllegalArgumentException - when the write selects the SELECTED listing mode with nothing to list
    • getListingMode

      public static String getListingMode(String storedValue)
      Reads a stored listing mode: FAVORITES or SELECTED, FAVORITES for any other value or none.
      Parameters:
      storedValue - the listingMode preference
      Returns:
      the listing mode to render
    • getSelectionMode

      public static String getSelectionMode(String storedValue)
      Reads a stored selection mode: MANUAL or CATEGORY, MANUAL for any other value or none.
      Parameters:
      storedValue - the selectionMode preference
      Returns:
      the selection mode to render
    • getApplicationIds

      public static List<Long> getApplicationIds(String storedValue)
      Reads stored application ids: the ordered ids, without duplicates, empty for a value that is not a list of at most ApplicationCenterService.MAX_LISTED_APPLICATIONS ids.
      Parameters:
      storedValue - the applicationIds preference, comma-separated
      Returns:
      the ids to render, never null
    • getCategoryIds

      public static List<Long> getCategoryIds(String storedValue)
      Reads stored category ids: the ordered ids, without duplicates, empty for a value that is not a list of at most MAX_LISTED_CATEGORIES ids.
      Parameters:
      storedValue - the categoryIds preference, comma-separated
      Returns:
      the ids to render, never null
    • getTemplate

      public static String getTemplate(String storedValue)
      Reads a stored template: ROW, CARDS or COLUMN, null for any other value or none, which renders the legacy layout.
      Parameters:
      storedValue - the template preference
      Returns:
      the template to render, or null
    • getDisplayFlag

      public static Boolean getDisplayFlag(String storedValue)
      Reads a stored display flag: showSeeMore, listInRow, showIcon, showName or outlined.
      Parameters:
      storedValue - the preference
      Returns:
      true or false, null for any other value or none, which the template's default replaces
    • getIconSize

      public static Integer getIconSize(String storedValue)
      Reads a stored icon size.
      Parameters:
      storedValue - the iconSize preference
      Returns:
      the size, from MIN_ICON_SIZE to MAX_ICON_SIZE, null for any other value or none, which the template's default replaces
    • getColor

      public static String getColor(String storedValue)
      Reads a stored color: #RRGGBB or #RRGGBBAA.
      Parameters:
      storedValue - the color preference
      Returns:
      the color, empty for any other value or none: no color
    • getAlignment

      public static String getAlignment(String storedValue)
      Reads a stored alignment, horizontal or vertical: START, CENTER or END, START being the left in a left-to-right page and the top vertically.
      Parameters:
      storedValue - the hAlign or vAlign preference
      Returns:
      the alignment, null for any other value or none, which the template's default replaces
    • copyHeaderTitle

      public void copyHeaderTitle(String sourceKey, String settingName)
      Copies the header title, every language, from one key to another when the latter holds none: from the legacy applicationId key to the setting name, or from the setting name a window gave up to the one it got. Reads and writes go through the ACL-free translation API: the copy runs at render, for any viewer.
      Parameters:
      sourceKey - the key the header title is stored under
      settingName - the window's CMS setting name
    • generateSettingName

      public String generateSettingName(String storageId, WindowKind windowKind)
      Generates the setting name of a window: Untitled-STORAGEID-UUID for a page window, with a site- or shared- marker before the UUID for a site-layout or a shared-layout window, so that its name tells which right and which context apply to it.
      Parameters:
      storageId - the window's storage id
      windowKind - where the window is placed
      Returns:
      a new setting name
    • generateSectionTemplateDraftSettingName

      public String generateSectionTemplateDraftSettingName(String storageId, long templateId)
      Generates the setting name of a window of a section-template draft page: Untitled-STORAGEID-sdraft-TEMPLATEID-UUID, so that the applications of the template's earlier editing sessions, and those to delete with the template, are told by their owner's name.
      Parameters:
      storageId - the window's storage id
      templateId - the section template id
      Returns:
      a new setting name
    • getSectionTemplateId

      public long getSectionTemplateId(String pageReference)
      Parameters:
      pageReference - a page reference
      Returns:
      the id of the section template whose draft page the reference names, section_draft_TEMPLATE_USER in the global site, 0 for any other page
    • isSectionTemplateDraftName

      public boolean isSectionTemplateDraftName(String settingName)
      Parameters:
      settingName - a Shortcuts portlet window's CMS setting name
      Returns:
      true when the name was generated for a window of a section-template draft page
    • getSectionTemplateDraftStorageId

      public String getSectionTemplateDraftStorageId(String settingName, long templateId)
      Parameters:
      settingName - a Shortcuts portlet window's CMS setting name
      templateId - a section template id
      Returns:
      the storage id of the window of that template's draft page the name was generated for, null for any other name
    • getSectionTemplateDraftNamePattern

      public String getSectionTemplateDraftNamePattern(long templateId)
      Parameters:
      templateId - a section template id
      Returns:
      a LIKE pattern matching at least the setting names generated for the windows of that template's draft pages, to check one by one with getSectionTemplateDraftStorageId(String, long)
    • getContextSpaceId

      public long getContextSpaceId(String settingName, String pageReference)
      Decides the space a window's setting records: the space owning the site of the recorded page reference, for a page window as for a site-layout window, whose recorded page is on the site whose layout holds it, whatever site's navigation rendered the page; none for a shared-layout window, which a configured layout renders on every page of the sites it serves.
      Parameters:
      settingName - the window's CMS setting name
      pageReference - the page reference the window's setting records, see getSettingPageReference(String, String, SiteKey)
      Returns:
      the space id to record, 0 for the platform context
    • isContextDeleted

      public boolean isContextDeleted(String settingName, String pageReference)
      Whether a window's context no longer exists: the page its setting records is on a space's group site, or on a space's public site, and that space is gone, or on a portal site that was removed. A space's public site is removed with its space, after which nothing tells it from another removed site. A shared-layout window's context is the platform's.
      Parameters:
      settingName - the window's CMS setting name
      pageReference - the page reference the window's setting records
      Returns:
      true when the window's space or portal site was deleted
    • getSettingPageReference

      public String getSettingPageReference(String settingName, String pageReference, org.exoplatform.portal.mop.SiteKey layoutSite)
      Decides the page reference a window's setting records and is compared with: for a site-layout window, the rendered page's name on the site whose layout holds the window, whatever page and site render it, so that its context, its right and the check of its name follow that site; the rendered page otherwise. A site renders the pages of other sites, and a displayed site renders the meta portal's layout.
      Parameters:
      settingName - the window's CMS setting name
      pageReference - the page the window is rendered on
      layoutSite - the site whose layout holds a site-layout window
      Returns:
      the page reference to record and compare
    • keepsSettingName

      public boolean keepsSettingName(String settingName, String storageId, WindowKind windowKind, String pageReference, Supplier<Collection<String>> otherWindowNames)
      Whether a window keeps the setting name its preferences carry. A layout copy carries the preferences of its source, the setting name included, and a page editor may rewrite it: such a window would act in the context of another window's setting. It keeps its name when the name was generated for it: its storage id and the marker of its kind of window. Otherwise, a page window keeps an unmarked name recorded on this page that no other window of the page carries, as after a same-page publish, and a site-layout window keeps a site-marked name recorded on this site that no other window of the site carries, whatever space their setting recorded, since the space is read from the recorded page (getContextSpaceId(String, String)). Every other name is given up, a shared-layout window's and a section-template draft window's included. The decision on a name generated for another storage id is memoised per window.
      Parameters:
      settingName - the name the window's preferences carry, not blank
      storageId - the window's storage id, not blank
      windowKind - where the window is placed
      pageReference - the page reference the window's setting records, see getSettingPageReference(String, String, SiteKey)
      otherWindowNames - reads the setting names of the other windows of the page, or of the site for a site-layout window
      Returns:
      true when the window keeps its setting name
    • hasSetting

      public boolean hasSetting(String settingName)
      Parameters:
      settingName - a Shortcuts portlet window's CMS setting name
      Returns:
      true when the window's setting exists
    • getSetting

      public io.meeds.social.cms.model.CMSSetting getSetting(String settingName)
      Parameters:
      settingName - a Shortcuts portlet window's CMS setting name
      Returns:
      the window's setting, recorded server-side when the window was first rendered, null when it does not exist