Class PluginTransactions


  • public final class PluginTransactions
    extends Object
    Utility methods for performing database-related operations of client or system plugins.
    Since:
    8.0.0
    Author:
    XIMA MEDIA GmbH
    • Method Detail

      • create

        public static <E extends APluginEntity<?,​?,​?>> E create​(IEntityContext ec,
                                                                            E entity)
        Creates the given system or client plugin entity.
        Type Parameters:
        E - Type of the plugin entity.
        Parameters:
        ec - Entity context for accessing the database.
        entity - Plugin to create.
        Returns:
        The created plugin.
        Throws:
        de.xima.cmn.dao.exceptions.AbstractDaoRuntimeException - When the data could not saved to the database.
      • delete

        public static void delete​(IEntityContext ec,
                                  APluginEntity<?,​?,​?> entity)
        Deletes the given system or client plugin entity.
        Parameters:
        ec - Entity context for accessing the database.
        entity - Plugin to delete.
        Throws:
        de.xima.cmn.dao.exceptions.AbstractDaoRuntimeException - When the data could not saved to the database.
      • existsPluginWithPluginKey

        public static boolean existsPluginWithPluginKey​(IEntityContext ec,
                                                        WorkspaceScope scope,
                                                        String pluginKey)
        Checks if a plugin with the given key exists within the given system or client scope.
        Parameters:
        ec - Entity context for accessing the database.
        scope - Scope to check for plugins.
        pluginKey - The plugin key to check for.
        Returns:
        true if at least one plugin with the given key exists, false otherwise.
      • existsPluginWithPluginKey

        public static boolean existsPluginWithPluginKey​(Supplier<IEntityContext> entityContextFactory,
                                                        WorkspaceScope scope,
                                                        String pluginKey)
        Checks if a plugin with the given key exists within the given system or client scope.
        Parameters:
        entityContextFactory - Entity context factory for accessing the database.
        scope - Scope to check for plugins.
        pluginKey - The plugin key to check for.
        Returns:
        true if at least one plugin with the given key exists, false otherwise.
      • newPluginEntityForJarFile

        public static APluginEntity<?,​?,​?> newPluginEntityForJarFile​(WorkspaceScope scope,
                                                                                 IUser user,
                                                                                 Path jarFile,
                                                                                 PluginID pluginId)
                                                                          throws Exception
        Creates a new plugin entity with the data from the given JAR file. Reads the meta data from the JAR file and sets it on the entity. Also sets the file entity to the data of the given JAR file. The active flag is set to false, set it to true if you do want the plugin to be active.
        Parameters:
        scope - Scope where the plugin is installed.
        user - User who uploaded or installed the plugin.
        jarFile - JAR file of the plugin.
        pluginId - Plugin ID, if known, for dealing with legacy plugins without a plugin ID in their manifest files.
        Returns:
        A new plugin entity for the given scope, with the meta data from the JAR file.
        Throws:
        Exception - When the JAR file could not be analyzed for its meta data.
      • pluginDao

        public static IGenericDao<? extends APluginEntity<?,​?,​?>> pluginDao​(WorkspaceScope scope)
        Gets the plugin DAO for plugins of the given scope, either the client plugin DAO or the system plugin DAO.
        Parameters:
        scope - Scope for which to get the DAO.
        Returns:
        The DAO for the given scope.
      • read

        public static <E extends APluginEntity<?,​?,​?>> E read​(IEntityContext ec,
                                                                          E entity)
        Re-reads a plugin with the given ID from the given scope.
        Type Parameters:
        E - Type of the plugin entity to re-read.
        Parameters:
        ec - Entity context for accessing the database.
        entity - Plugin entity to re-read.
        Returns:
        The re-read plugin from the database.
        Throws:
        de.xima.cmn.dao.exceptions.AbstractDaoRuntimeException - When the data could not be read from the database.
      • readAllPluginMeta

        public static Set<PluginGroupMeta> readAllPluginMeta​(IEntityContext ec,
                                                             WorkspaceScope scope)
        Reads all plugins from the given scope, and returns the relevant meta data with the key and ID.
        Parameters:
        ec - Entity context for accessing the database.
        scope - Scope for which to read the plugins.
        Returns:
        A list with all meta data of the plugins from the given scope.
        Throws:
        de.xima.cmn.dao.exceptions.AbstractDaoRuntimeException - When the data could not be read from the database.
      • readAllPluginMeta

        public static Set<PluginGroupMeta> readAllPluginMeta​(Supplier<IEntityContext> entityContextFactory,
                                                             WorkspaceScope scope)
        Reads all plugins from the given scope, and returns the relevant meta data with the key and ID.
        Parameters:
        entityContextFactory - Entity context factory for accessing the database.
        scope - Scope for which to read the plugins.
        Returns:
        A list with all meta data of the plugins from the given scope.
        Throws:
        de.xima.cmn.dao.exceptions.AbstractDaoRuntimeException - When the data could not be read from the database.
      • readAllPluginMetaWithVersions

        public static List<VersionedPluginGroupMeta> readAllPluginMetaWithVersions​(IEntityContext ec,
                                                                                   WorkspaceScope scope)
                                                                            throws IOException
        Reads all plugins from a given scope, including the version for each plugin, and returns a map from the plugin group to the set of all versions for that plugin group.
        Parameters:
        ec - Entity context for accessing the database.
        scope - Scope for which to read the plugins.
        Returns:
        A list with all meta data of the plugins from the given scope, including the plugin's version.
        Throws:
        IOException - When the versions could not be read.
        de.xima.cmn.dao.exceptions.AbstractDaoRuntimeException - When the data could not be read from the database.
      • readAllPluginMetaWithVersions

        public static List<VersionedPluginGroupMeta> readAllPluginMetaWithVersions​(Supplier<IEntityContext> entityContextFactory,
                                                                                   WorkspaceScope scope)
                                                                            throws IOException
        Reads all plugins from a given scope, including the version for each plugin, and returns a map from the plugin group to the set of all versions for that plugin group.
        Parameters:
        entityContextFactory - Entity context supplier for accessing the database.
        scope - Scope for which to read the plugins.
        Returns:
        A list with all meta data of the plugins from the given scope, including the plugin's version.
        Throws:
        IOException - When the versions could not be read.
        de.xima.cmn.dao.exceptions.AbstractDaoRuntimeException - When the data could not be read from the database.
      • readAllPluginsWithPluginKey

        public static List<APluginEntity<?,​?,​?>> readAllPluginsWithPluginKey​(IEntityContext ec,
                                                                                         WorkspaceScope scope,
                                                                                         String pluginKey)
        Reads all plugins with a given plugin key.
        Parameters:
        ec - Entity context for accessing the database.
        scope - Scope in which to look for plugins.
        pluginKey - Key to look for.
        Returns:
        All plugins with the given key and from the given scope.
      • readById

        public static APluginEntity<?,​?,​?> readById​(IEntityContext ec,
                                                                WorkspaceScope scope,
                                                                long id)
        Reads a plugin with the given ID from the given scope.
        Parameters:
        ec - Entity context for accessing the database.
        scope - Scope where the plugin is located.
        id - Database ID of the plugin.
        Returns:
        The plugin, if found, or null otherwise.
        Throws:
        de.xima.cmn.dao.exceptions.AbstractDaoRuntimeException - When the data could not be read from the database.
      • readOverloadedPlugins

        public static Set<PluginID> readOverloadedPlugins​(IEntityContext ec,
                                                          WorkspaceScope scope)
        Gets a set of all plugin IDs that exists in the given scope and overload a plugin from another scope.
        Parameters:
        ec - Entity context for accessing the database.
        scope - Scope to check.
        Returns:
        A set of all plugins in the given scope overloading a plugin from another scope.
      • readOverloadedPlugins

        public static Set<PluginID> readOverloadedPlugins​(Supplier<IEntityContext> entityContextFactory,
                                                          WorkspaceScope scope)
        Gets a set of all plugin IDs that exists in the given scope and overload a plugin from another scope.
        Parameters:
        entityContextFactory - Entity context factory for accessing the database.
        scope - Scope to check.
        Returns:
        A set of all plugins in the given scope overloading a plugin from another scope.
      • readPluginManifest

        public static PluginManifest readPluginManifest​(IEntityContext ec,
                                                        APluginEntity<? extends IPluginFileEntity<?,​?,​?>,​? extends IFileDataEntity<?>,​?> plugin)
                                                 throws IOException
        Reads and parses the manifest of a given plugin entity.
        Parameters:
        ec - Entity context for accessing the database.
        plugin - Plugin entity for which to get the manifest.
        Returns:
        The manifest of the given plugin entity.
        Throws:
        IOException - When the plugin could not be read.
      • setNewPluginData

        public static void setNewPluginData​(APluginEntity<?,​?,​?> plugin,
                                            IUser user,
                                            Path jarFile)
                                     throws IOException
        Sets a new JAR file for a given plugin. Also updates the modification time and the user who made the modification.
        Parameters:
        plugin - Plugin to update.
        user - User who uploaded or installed the plugin.
        jarFile - JAR file of the plugin.
        Throws:
        IOException - When the JAR file data could not be read.
      • update

        public static <E extends APluginEntity<?,​?,​?>> E update​(IEntityContext ec,
                                                                            E entity)
        Updates the given system or client plugin entity.
        Type Parameters:
        E - Type of the plugin entity.
        Parameters:
        ec - Entity context for accessing the database.
        entity - Plugin to update.
        Returns:
        The updated plugin.
        Throws:
        de.xima.cmn.dao.exceptions.AbstractDaoRuntimeException - When the data could not saved to the database.