Class UserPortalContentSelectionHelper
- java.lang.Object
-
- de.xima.fc.gui.helper.user_portal.content.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 Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static StringbuildPortalContentSelectItemLabel(String name, boolean showExistingLabel, String existingLabel)Returns the display label for a select item.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.static StringformatSelectedResourceFileSize(Long fileSize)static StringgetCurrentSelectionDisplayName(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.static Function<UserPortalContentViewModel,UUID>getCurrentSelectionExtractor(EUserPortalContentConfigType contentType)Returns the UUID extractor for the linked entity of the given content type.static UUIDgetFirstEnabledSelectItemValue(List<javax.faces.model.SelectItem> items)Returns the first enabled UUID value from the given select items.static UUIDgetRestorableSelectedContentEntityUuid(UserPortalContentViewModel previousSelectedContent, EUserPortalContentConfigType contentType, Function<UserPortalContentViewModel,UUID> currentSelectionExtractor, UUID selectedTenantUuid)Resolves the previously selected entity UUID that can be restored for the current tenant.static UUIDgetSelectableCurrentContentEntityUuid(UserPortalContentViewModel selectedContent, Function<UserPortalContentViewModel,UUID> currentSelectionExtractor, UUID restorableSelectedUuid, UUID temporaryDisplaySelectionUuid)Resolves the UUID that should currently be treated as selectable in the entity dropdown.static UUIDgetSelectedContentEntityUuid(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.static StringgetTemporaryCreateNewSelectionName(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.static UserPortalTenantContentLoader.TenantContentSelectItemInfogetTemporarySelectedContentInfo(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.static Map<UUID,UserPortalTenantContentLoader.TenantContentSelectItemInfo>mergeTemporarySelectedContentInfo(Map<UUID,UserPortalTenantContentLoader.TenantContentSelectItemInfo> availableContentInfos, UserPortalTenantContentLoader.TenantContentSelectItemInfo temporarySelectedContentInfo)Merges a temporary selected-content info entry into the available content infos.static StringresolveAvailableContentDisplayName(UUID contentUuid, String displayNameOverride, String currentSelectionName, String temporaryCreateNewName, Map<UUID,String> availableContent)Resolves the display name for an available content entity.static StringresolveTemporarySelectedContentDisplayName(EUserPortalContentConfigType contentType, UUID contentUuid, UserPortalContentViewModel selectedContent)Resolves the display name for a temporary content entity that only exists in the current dialog state.static booleanshouldShowExistingLabel(UUID contentUuid, boolean isExistingContent, boolean selectableCurrent)Returns whether an existing-content label should be shown for a select item.
-
-
-
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
nullwhen 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 contentcontentType- the current content typecurrentSelectionExtractor- extractor for the entity UUIDselectedTenantUuid- the currently selected tenant UUID- Returns:
- the restorable entity UUID, or
nullwhen 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 contentcurrentSelectionExtractor- extractor for the entity UUIDrestorableSelectedUuid- a restorable UUID from a previous selectiontemporaryDisplaySelectionUuid- 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 UUIDselectableCurrentUuid- UUID that should remain selectable although already assignedisExistingContent- predicate that indicates whether an entity is already used by another contenthasDisplayNameOverride- predicate that indicates whether an entity has a temporary display name overrideresolveSelectedContentDisplayLabel- resolves the display name for an available content entity, taking into account possible overrides and the current selectionresolveTemporarySelectedContentDisplayName- resolves the display name for a temporary create-new selectionexistingLabel- 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 nameshowExistingLabel- whether the existing-content suffix should be appendedexistingLabel- 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 contentcontentType- the content typecontentUuid- the entity UUID to inspectcurrentSelectionExtractor- 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 typecontentUuid- UUID to resolveselectedContent- the current contentpreviousSelectedContent- the previously selected contentcurrentSelectionExtractor- extractor for the entity UUIDrestorableSelectedUuid- 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 UUIDdisplayNameOverride- display name override from dialog editscurrentSelectionName- display name of the current selectiontemporaryCreateNewName- display name of a temporary create-new selectionavailableContent- available content mapped by UUID- Returns:
- the best matching display name, or
null
-
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 typecontentUuid- the entity UUIDselectedContent- 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 typeselectedContent- the currently selected contentavailableContent- available content mapped by UUIDdisplayName- 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 UUIDisExistingContent- whether the entity is already used by another contentselectableCurrent- whether the entity should still be selectable for the current content- Returns:
truewhen the label should be shown
-
mergeTemporarySelectedContentInfo
public static Map<UUID,UserPortalTenantContentLoader.TenantContentSelectItemInfo> mergeTemporarySelectedContentInfo(Map<UUID,UserPortalTenantContentLoader.TenantContentSelectItemInfo> availableContentInfos, UserPortalTenantContentLoader.TenantContentSelectItemInfo temporarySelectedContentInfo)
Merges a temporary selected-content info entry into the available content infos.- Parameters:
availableContentInfos- currently available content infostemporarySelectedContentInfo- temporary content info to merge- Returns:
- original or merged content info map
-
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 typeselectedContent- the currently selected contentcurrentSelectionExtractor- extractor for the entity UUIDavailableContent- available content mapped by UUIDrestorableSelectedUuid- restorable UUID from a previous selectiontemporaryDisplaySelectionUuid- temporary UUID used only for dropdown display- Returns:
- the selected entity UUID, or
null
-
-