Class UserPortalViewHelper


  • public final class UserPortalViewHelper
    extends Object
    Helper functions for various UI related operations on user portals. This package contains several other helper classes that are all package-private and should not be used directly. This class is the public entry point for those helper functions, delegating to the package-private helper classes as required.
    Since:
    8.2.0
    Author:
    XIMA MEDIA GmbH
    • Method Detail

      • addKeyToCustomLocalizations

        public static void addKeyToCustomLocalizations​(UserPortalViewModel model,
                                                       ELocalizationsType type)
        Adds a new key to the custom messages or files of the selected portal related entity of the given type. Uses the configured new key from the model. This is usually called when the user adds a new key in the UI.
        Parameters:
        model - User portal view model to add the key to.
      • addNewLocaleToPortal

        public static void addNewLocaleToPortal​(IEntityContext ec,
                                                Locale locale,
                                                UserPortalViewModel model)
                                         throws IOException
        Adds a new locale to the portal. This is usually called when the user adds a new locale in the UI.
        Parameters:
        ec - Entity context for accessing the database.
        locale - Locale to add.
        model - User portal view model to add the locale to.
        Throws:
        IOException - When a temporary file (from an upload) stored on the file system could not be read.
      • addTagToUserPortal

        public static void addTagToUserPortal​(UserPortalViewModel model,
                                              String newTagName)
        Adds a new tag to the user portal. This is usually called when the user adds a new tag in the UI.
        Parameters:
        model - User portal view model to add the tag to.
        newTagName - Requested mame of the new tag.
      • addUploadedFileToSelectedPortal

        public static void addUploadedFileToSelectedPortal​(org.primefaces.model.file.UploadedFile file,
                                                           String fileKey,
                                                           UserPortalViewModel model)
                                                    throws IOException
        Adjusts the model by adding an uploaded file to the list of localized portal files. This is usually called when the user uploads a file in the UI.
        Parameters:
        file - Uploaded file to add.
        fileKey - Key that identifies the file.
        model - View model to add the file to.
        Throws:
        IOException - When the file could not be read.
      • addUploadedFileToSelectedProject

        public static void addUploadedFileToSelectedProject​(org.primefaces.model.file.UploadedFile file,
                                                            String fileKey,
                                                            UserPortalViewModel model)
                                                     throws IOException
        Adjusts the model by adding an uploaded file to the list of files of the currently selected project. This is usually called when the user uploads a file in the UI.
        Parameters:
        file - Uploaded file to add.
        fileKey - Key that identifies the file.
        model - View model to add the file to.
        Throws:
        IOException - When the file could not be read.
      • applySelectionFromPreviousPortalViewModel

        public static void applySelectionFromPreviousPortalViewModel​(IEntityContext ec,
                                                                     UserPortalViewModel previousModel,
                                                                     UserPortalViewModel model)
                                                              throws IOException
        Applies the selection from the previous view model to the new view model.
        Parameters:
        ec - Entity context for accessing the database.
        previousModel - Previous view model to copy the selection from.
        model - New view model to copy the selection to.
        Throws:
        IOException
      • cleanupPortalViewModel

        public static void cleanupPortalViewModel​(UserPortalViewModel model)
        Cleans up an existing portal view model, releasing resource such as temporary files. Should be called only once the model is not needed anymore.
        Parameters:
        model - Model to clean up.
      • createTextContentView

        public static Map<String,​String> createTextContentView​(Supplier<UserPortalLocalizationsViewModelWithFiles> localizationsSupplier,
                                                                     Map<String,​UserPortalFileMeta> metaData,
                                                                     ETextContentViewEmptyMode emptyMode)
        Creates a map representing a view of the files for the given localizations. The map key is the file key, the value is the file content as a string. The map is writable. Writing to the map will set files in the model.
        Parameters:
        localizationsSupplier - Supplier for the localizations to create the view for.
        metaData - A map with the metadata of the files to include in the view. The key is the file key.
        emptyMode - How to treat empty or blank strings.
        Returns:
        A map representing a plain text content view of the given files.
      • findCustomLocalizationsKeys

        public static List<String> findCustomLocalizationsKeys​(UserPortalViewModel model,
                                                               ELocalizationsType type)
        Finds all custom keys that can be configured for the given type of portal related entity.
        Parameters:
        model - User portal view model to find the keys for.
        type - Type of the localizations to find the keys for.
        Returns:
        A list of custom keys that can be configured on the advanced tab.
      • findLanguagesToAddMatchingQuery

        public static List<String> findLanguagesToAddMatchingQuery​(String query,
                                                                   Locale locale,
                                                                   UserPortalViewModel model)
        Finds all languages that match the given query and are not yet added to the user portal. The query is matched against the language tag and the display name of the locale.
        Parameters:
        query - Query to match against the language tags and display names.
        locale - Locale to use for sorting the languages based on their display name.
        model - User portal view model to find the languages for.
        Returns:
        A list of language tags that match the query and are not yet added to the user portal.
      • newUserPortalViewModel

        public static UserPortalViewModel newUserPortalViewModel​(IEntityContext ec,
                                                                 Locale locale,
                                                                 WorkspaceScope workspace,
                                                                 IUserPermissionCheck userPermissionCheck,
                                                                 UserPortal portal)
        Creates a new view model for editing a single user portal. This is usually called when a user portal was selected in the UI or when the selected portal needs to be refreshed.
        Parameters:
        ec - Entity context for accessing the database.
        locale - UI locale to use for the view model, used e.g. to sort locales based on their display name.
        workspace - Workspace scope where the user portal is being edited (system or client).
        userPermissionCheck - Permission checker for the current user.
        portal - User portal to create the view model for.
        Returns:
        A new view model for editing the user portal.
      • openPortalFileInputStream

        public static InputStream openPortalFileInputStream​(Class<? extends ALocalizedScopedFileMetaEntity<?,​?>> type,
                                                            UserPortalDynamicFileResourceParams params)
        Opens an input stream for the contents of a file in the user portal. The file is identified by the given parameters.
        Parameters:
        type - Type of the file entity.
        params - Parameters to identify the file.
        Returns:
        An input stream for the file contents.
      • persistUserPortalViewModel

        public static UserPortalPersistResult persistUserPortalViewModel​(IEntityContext ec,
                                                                         UserPortal portal,
                                                                         UserPortalViewModel model)
                                                                  throws IOException
        Given a view model with data, persists that data in the database. Uses the given user portal entity, which may refer to a transient or already persisted entity. Updates the entity with the data from the view model, and saves it back to the database.

        This is usually called just after the user clicked the save button in the UI.

        Parameters:
        ec - Entity context for accessing the database.
        portal - User portal entity to update with the data from the view model.
        model - View model with the data to apply to the user portal.
        Throws:
        IOException - When a temporary file (from an upload) stored on the file system could not be read.
      • prepareSelectedProjectForEditing

        public static void prepareSelectedProjectForEditing​(IEntityContext ec,
                                                            UserPortalViewModel model)
        Prepares the model so that the given project's portal configuration can be edited. This is usually called when the user clicks on a project in the UI to edit its configuration.
        Parameters:
        ec - Entity context for accessing the database.
        model - View model to adjust.
      • prepareUserPortalViewForUpdatedLocale

        public static void prepareUserPortalViewForUpdatedLocale​(IEntityContext ec,
                                                                 UserPortalViewModel model)
                                                          throws IOException
        Prepares the model for the given locale so that the portal configuration for that locale can be edited. This is usually called when the user changes the locale in the UI.
        Parameters:
        model - View model to adjust.
        Throws:
        IOException
      • removeFileFromSelectedPortal

        public static void removeFileFromSelectedPortal​(String fileKey,
                                                        UserPortalViewModel model)
        Adjusts the model by removing the file with the given key from the currently selected portal, if present. This is usually called when the user removes a file in the UI.
        Parameters:
        fileKey - Key that identifies the file.
      • removeFileFromSelectedProject

        public static void removeFileFromSelectedProject​(String fileKey,
                                                         UserPortalViewModel model)
        Adjusts the model by removing the file with the given key from the currently selected project, if present. This is usually called when the user removes a file in the UI.
        Parameters:
        fileKey - Key that identifies the file.
      • removeKeyFromCustomLocalizations

        public static void removeKeyFromCustomLocalizations​(UserPortalViewModel model,
                                                            ELocalizationsType type,
                                                            String key)
        Removes a custom key from all messages or files of the selected portal related entity of the given type. This is usually called when the user removes a key in the UI.
        Parameters:
        model - User portal view model to remove the key from.
        type - Type of the localizations to remove the key from.
        key - Key to remove.
      • removeTagFromUserPortal

        public static void removeTagFromUserPortal​(UserPortalViewModel model,
                                                   UserPortalProjectTagViewModel tag)
        Removes a tag from the user portal. This is usually called when the user removes a tag in the UI.
        Parameters:
        model - User portal view model to remove the tag from.
        tag - Tag to remove.
      • reorderInputAuthenticators

        public static void reorderInputAuthenticators​(int fromIndex,
                                                      int toIndex,
                                                      UserPortalViewModel model)
        Updates the model and moves an input login service at a given position to another position.
        Parameters:
        fromIndex - The index of the input login service to move.
        toIndex - The index to move the input login service to.
        model - The model to update.
      • reorderRedirectAuthenticators

        public static void reorderRedirectAuthenticators​(int fromIndex,
                                                         int toIndex,
                                                         UserPortalViewModel model)
        Updates the model and moves a redirect login service at a given position to another position.
        Parameters:
        fromIndex - The index of the input login service to move.
        toIndex - The index to move the input login service to.
        model - The model to update.
      • resolveTagMessage

        public static String resolveTagMessage​(UserPortalProjectTagViewModel tag,
                                               UserPortalViewModel model,
                                               String messageKey,
                                               Supplier<String> defaultSupplier)
        Resolves the value of a localized tag message for a given tag.
         Uses the currently selected language first, falling back to the default language. When no value is found, the
         given default value is used.
        Parameters:
        tag - Tag to resolve the message for.
        Returns:
        Resolved message for the tag.