Class UserPortalContentSelectionHelper


  • public final class UserPortalContentSelectionHelper
    extends Object
    Helper for resolving entity selections and select item metadata for user portal content.
    Since:
    8.6.0
    Author:
    XIMA MEDIA GmbH
    • Method Detail

      • getCurrentSelectionExtractor

        public static Function<UserPortalContentViewModel,​UUID> getCurrentSelectionExtractor​(EUserPortalContentConfigType contentType)
        Returns the UUID extractor for the linked entity of the given content type.
        Parameters:
        contentType - the content type
        Returns:
        extractor for the selected entity UUID, or null when the type does not support a linked entity
      • getRestorableSelectedContentEntityUuid

        public static UUID getRestorableSelectedContentEntityUuid​(UserPortalContentViewModel previousSelectedContent,
                                                                  EUserPortalContentConfigType contentType,
                                                                  Function<UserPortalContentViewModel,​UUID> currentSelectionExtractor,
                                                                  UUID selectedTenantUuid)
        Resolves the previously selected entity UUID that can be restored for the current tenant.
        Parameters:
        previousSelectedContent - the previously selected content
        contentType - the current content type
        currentSelectionExtractor - extractor for the entity UUID
        selectedTenantUuid - the currently selected tenant UUID
        Returns:
        the restorable entity UUID, or null when none is available
      • getSelectableCurrentContentEntityUuid

        public static UUID getSelectableCurrentContentEntityUuid​(UserPortalContentViewModel selectedContent,
                                                                 Function<UserPortalContentViewModel,​UUID> currentSelectionExtractor,
                                                                 UUID restorableSelectedUuid,
                                                                 UUID temporaryDisplaySelectionUuid)
        Resolves the UUID that should currently be treated as selectable in the entity dropdown.
        Parameters:
        selectedContent - the currently selected content
        currentSelectionExtractor - extractor for the entity UUID
        restorableSelectedUuid - a restorable UUID from a previous selection
        temporaryDisplaySelectionUuid - a temporary UUID used only for dropdown display
        Returns:
        the UUID that should be treated as selected in the dropdown, or null
      • createAvailableSelectItems

        public static List<javax.faces.model.SelectItem> createAvailableSelectItems​(Map<UUID,​String> availableContent,
                                                                                    UUID selectableCurrentUuid,
                                                                                    Predicate<UUID> isExistingContent,
                                                                                    Predicate<UUID> hasDisplayNameOverride,
                                                                                    Function<UUID,​String> resolveSelectedContentDisplayLabel,
                                                                                    Function<UUID,​String> resolveTemporarySelectedContentDisplayName,
                                                                                    String existingLabel)
        Creates select items for the available content entities of a content type.
        Parameters:
        availableContent - available entities mapped by UUID
        selectableCurrentUuid - UUID that should remain selectable although already assigned
        isExistingContent - predicate that indicates whether an entity is already used by another content
        hasDisplayNameOverride - predicate that indicates whether an entity has a temporary display name override
        resolveSelectedContentDisplayLabel - resolves the display name for an available content entity, taking into account possible overrides and the current selection
        resolveTemporarySelectedContentDisplayName - resolves the display name for a temporary create-new selection
        existingLabel - localized suffix for already assigned content
        Returns:
        select items for the dropdown
      • buildPortalContentSelectItemLabel

        public static String buildPortalContentSelectItemLabel​(String name,
                                                               boolean showExistingLabel,
                                                               String existingLabel)
        Returns the display label for a select item.
        Parameters:
        name - base display name
        showExistingLabel - whether the existing-content suffix should be appended
        existingLabel - localized suffix for already assigned content
        Returns:
        the rendered label
      • getFirstEnabledSelectItemValue

        public static UUID getFirstEnabledSelectItemValue​(List<javax.faces.model.SelectItem> items)
        Returns the first enabled UUID value from the given select items.
        Parameters:
        items - select items to inspect
        Returns:
        the first enabled UUID value, or null
      • getCurrentSelectionDisplayName

        public static String getCurrentSelectionDisplayName​(UserPortalContentViewModel selectedContent,
                                                            EUserPortalContentConfigType contentType,
                                                            UUID contentUuid,
                                                            Function<UserPortalContentViewModel,​UUID> currentSelectionExtractor)
        Returns the display name override for the current selected content when the entity UUID matches.
        Parameters:
        selectedContent - the currently selected content
        contentType - the content type
        contentUuid - the entity UUID to inspect
        currentSelectionExtractor - extractor for the entity UUID
        Returns:
        trimmed display name of the current selection, or null
      • getTemporaryCreateNewSelectionName

        public static String getTemporaryCreateNewSelectionName​(EUserPortalContentConfigType contentType,
                                                                UUID contentUuid,
                                                                UserPortalContentViewModel selectedContent,
                                                                UserPortalContentViewModel previousSelectedContent,
                                                                Function<UserPortalContentViewModel,​UUID> currentSelectionExtractor,
                                                                UUID restorableSelectedUuid)
        Returns the display name of the temporary create-new selection that can replace the previous entity.
        Parameters:
        contentType - the content type
        contentUuid - UUID to resolve
        selectedContent - the current content
        previousSelectedContent - the previously selected content
        currentSelectionExtractor - extractor for the entity UUID
        restorableSelectedUuid - restorable UUID from the previous selection
        Returns:
        the temporary display name, or null
      • resolveAvailableContentDisplayName

        public static String resolveAvailableContentDisplayName​(UUID contentUuid,
                                                                String displayNameOverride,
                                                                String currentSelectionName,
                                                                String temporaryCreateNewName,
                                                                Map<UUID,​String> availableContent)
        Resolves the display name for an available content entity.
        Parameters:
        contentUuid - the entity UUID
        displayNameOverride - display name override from dialog edits
        currentSelectionName - display name of the current selection
        temporaryCreateNewName - display name of a temporary create-new selection
        availableContent - available content mapped by UUID
        Returns:
        the best matching display name, or null
      • formatSelectedResourceFileSize

        public static String formatSelectedResourceFileSize​(Long fileSize)
      • resolveTemporarySelectedContentDisplayName

        public static String resolveTemporarySelectedContentDisplayName​(EUserPortalContentConfigType contentType,
                                                                        UUID contentUuid,
                                                                        UserPortalContentViewModel selectedContent)
        Resolves the display name for a temporary content entity that only exists in the current dialog state.
        Parameters:
        contentType - the content type
        contentUuid - the entity UUID
        selectedContent - the currently selected content
        Returns:
        the temporary display name, or null
      • getTemporarySelectedContentInfo

        public static UserPortalTenantContentLoader.TenantContentSelectItemInfo getTemporarySelectedContentInfo​(EUserPortalContentConfigType contentType,
                                                                                                                UserPortalContentViewModel selectedContent,
                                                                                                                Map<UUID,​String> availableContent,
                                                                                                                String displayName)
        Creates a temporary content info entry for the current create-new selection when it is not part of the available content map yet.
        Parameters:
        contentType - the content type
        selectedContent - the currently selected content
        availableContent - available content mapped by UUID
        displayName - resolved display name of the temporary selection
        Returns:
        a temporary select-item info entry, or null
      • shouldShowExistingLabel

        public static boolean shouldShowExistingLabel​(UUID contentUuid,
                                                      boolean isExistingContent,
                                                      boolean selectableCurrent)
        Returns whether an existing-content label should be shown for a select item.
        Parameters:
        contentUuid - the entity UUID
        isExistingContent - whether the entity is already used by another content
        selectableCurrent - whether the entity should still be selectable for the current content
        Returns:
        true when the label should be shown
      • getSelectedContentEntityUuid

        public static UUID getSelectedContentEntityUuid​(EUserPortalContentConfigType contentType,
                                                        UserPortalContentViewModel selectedContent,
                                                        Function<UserPortalContentViewModel,​UUID> currentSelectionExtractor,
                                                        Map<UUID,​String> availableContent,
                                                        UUID restorableSelectedUuid,
                                                        UUID temporaryDisplaySelectionUuid)
        Resolves the entity UUID that should be exposed as selected for the given content type. When
        Parameters:
        contentType - the content type
        selectedContent - the currently selected content
        currentSelectionExtractor - extractor for the entity UUID
        availableContent - available content mapped by UUID
        restorableSelectedUuid - restorable UUID from a previous selection
        temporaryDisplaySelectionUuid - temporary UUID used only for dropdown display
        Returns:
        the selected entity UUID, or null