Class GroupInfo


  • public class GroupInfo
    extends java.lang.Object
    Class holding information about user groups for the server.

    The database table is created with:

     CREATE TABLE IZS.GROUPS (
      gid       BIGINT       NOT NULL PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY,
      name      VARCHAR(80)  NOT NULL,
      descr     VARCHAR(160) NOT NULL,
      disabled  BOOLEAN      NOT NULL DEFAULT FALSE,
      all_apps  BOOLEAN      NOT NULL DEFAULT FALSE,
      UNIQUE (name)
     );
     
    Author:
    Christopher Mindus
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String ADMIN_GROUP_NAME
      The group name of the Administrators group: "Administrators".
      static java.lang.String DEFAULT_GROUP_NAME
      The group name of the Default normal user group: "Default".
      long gid
      The unique group ID.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean areAllAppsAllowed()
      Returns if the group allows users to run all apps without further app checking.
      static GroupInfo createGroup​(java.lang.String name, java.lang.String descr, boolean isDisabled, boolean areAllAppsAllowed)
      Creates a new group with the specified information.
      static GroupInfo createGroup​(java.sql.Connection conn, java.lang.String name, java.lang.String descr, boolean isDisabled, boolean areAllAppsAllowed)
      Creates a new group with the specified information.
      boolean deleteGroup()
      Deletes the group from the database.
      boolean deleteGroup​(java.sql.Connection conn)
      Deletes the group from the database.
      static GroupInfo[] getAllGroups​(boolean reload)
      Gets all the groups from the database.
      static GroupInfo[] getAllGroups​(java.sql.Connection conn)
      Gets all the groups from the database.
      java.lang.String getDescription()
      Gets the description of the group.
      static GroupInfo getGroup​(java.lang.String name, boolean reload)
      Gets the group with the specified name.
      static GroupInfo[] getGroups​(long[] groupIDs, boolean reload)
      Gets the groups for the group IDs.
      static GroupInfo[] getGroups​(java.lang.String[] names, boolean reload)
      Gets the groups for the names.
      static GroupInfo[] getGroups​(java.sql.Connection conn, java.lang.String[] names)
      Gets the groups for the names from the database.
      java.lang.String getName()
      Gets the name of the group.
      boolean isDisabled()
      Returns if the group is enabled or disabled.
      static GroupInfo[] loadGroups​(java.sql.Connection conn, boolean returnGroupInfoArray)
      Loads all the groups.
      void refreshFromDB()
      Refreshes the DB information for the group.
      boolean setInformation​(java.lang.String name, java.lang.String descr, java.lang.Boolean isDisabled, java.lang.Boolean areAllAppsAllowed)
      Updates the information of the group.
      java.lang.String toString()
      Outputs a debug string.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • DEFAULT_GROUP_NAME

        public static final java.lang.String DEFAULT_GROUP_NAME
        The group name of the Default normal user group: "Default".
        See Also:
        Constant Field Values
      • ADMIN_GROUP_NAME

        public static final java.lang.String ADMIN_GROUP_NAME
        The group name of the Administrators group: "Administrators".
        See Also:
        Constant Field Values
      • gid

        public final long gid
        The unique group ID.
    • Method Detail

      • loadGroups

        public static GroupInfo[] loadGroups​(java.sql.Connection conn,
                                             boolean returnGroupInfoArray)
                                      throws java.sql.SQLException
        Loads all the groups. Previous groups are cleared.
        Parameters:
        conn - The database connection.
        returnGroupInfoArray - Flag to return the array of all groups.
        Returns:
        The array of all groups if returnGroupInfoArray is true, null otherwise.
        Throws:
        java.sql.SQLException - For SQL errors.
      • getGroup

        public static GroupInfo getGroup​(java.lang.String name,
                                         boolean reload)
                                  throws java.sql.SQLException
        Gets the group with the specified name.
        Parameters:
        name - The group name, wildcard "*" means all groups and will fail this call.
        reload - Flag to reload the group informations from the database.
        Returns:
        The group found, or null if not found.
        Throws:
        java.sql.SQLException - For SQL errors.
        NotFoundException - If the name is "*".
      • getAllGroups

        public static GroupInfo[] getAllGroups​(boolean reload)
                                        throws java.sql.SQLException
        Gets all the groups from the database.
        Parameters:
        reload - Flag to reload the group informations from the database.
        Returns:
        The array of group informations.
        Throws:
        java.sql.SQLException - For SQL errors.
      • getAllGroups

        public static GroupInfo[] getAllGroups​(java.sql.Connection conn)
                                        throws java.sql.SQLException
        Gets all the groups from the database.
        Parameters:
        conn - The JDBC connection.
        Returns:
        The array of group informations.
        Throws:
        java.sql.SQLException - For SQL errors.
      • getGroups

        public static GroupInfo[] getGroups​(java.lang.String[] names,
                                            boolean reload)
                                     throws NotFoundException,
                                            java.sql.SQLException
        Gets the groups for the names.
        Parameters:
        names - The group names to find. The wildcard "*" group name means all groups.
        reload - Flag to reload the group informations from the database.
        Returns:
        The array of group informations.
        Throws:
        NotFoundException - If a group is not found.
        java.sql.SQLException - For SQL errors.
      • getGroups

        public static GroupInfo[] getGroups​(java.sql.Connection conn,
                                            java.lang.String[] names)
                                     throws NotFoundException,
                                            java.sql.SQLException
        Gets the groups for the names from the database.
        Parameters:
        names - The group names to find. The wildcard "*" group name means all groups.
        Returns:
        The array of group informations.
        Throws:
        NotFoundException - If a group is not found.
        java.sql.SQLException - For SQL errors.
      • getGroups

        public static GroupInfo[] getGroups​(long[] groupIDs,
                                            boolean reload)
                                     throws NotFoundException,
                                            java.sql.SQLException
        Gets the groups for the group IDs.
        Parameters:
        groupIDs - The groupIDs to find.
        reload - Flag to reload the group informations from the database.
        Returns:
        The array of group informations.
        Throws:
        NotFoundException - If a group is not found.
        java.sql.SQLException - For SQL errors.
      • createGroup

        public static GroupInfo createGroup​(java.lang.String name,
                                            java.lang.String descr,
                                            boolean isDisabled,
                                            boolean areAllAppsAllowed)
                                     throws java.sql.SQLException
        Creates a new group with the specified information.

        Note that the name AND the lower case name of the group should not exist, otherwise you will get an SQLException of a duplicate entry.

        Parameters:
        name - The group name (min 3 characters, max 80 characters).
        descr - The group description (max 160 characters, cannot be null).
        isDisabled - The group is initially disabled if true, enabled if false.
        areAllAppsAllowed - Enable group to access all apps (be careful with this one, it is primarily used for Administrator groups).
        Returns:
        The GroupInfo of the new group created.
        Throws:
        java.lang.IllegalArgumentException - If name or descr lengths are invalid.
        java.sql.SQLException - For SQL errors.
        java.lang.NullPointerException - If name or descr parameters are null.
      • createGroup

        public static GroupInfo createGroup​(java.sql.Connection conn,
                                            java.lang.String name,
                                            java.lang.String descr,
                                            boolean isDisabled,
                                            boolean areAllAppsAllowed)
                                     throws java.sql.SQLException
        Creates a new group with the specified information.

        Note that the name AND the lower case name of the group should not exist, otherwise you will get an SQLException of a duplicate entry.

        Parameters:
        conn - The JDBC connection.
        name - The group name (min 3 characters, max 80 characters).
        descr - The group description (max 160 characters, cannot be null).
        isDisabled - The group is initially disabled if true, enabled if false.
        areAllAppsAllowed - Enable group to access all apps (be careful with this one, it is primarily used for Administrator groups).
        Returns:
        The GroupInfo of the new group created.
        Throws:
        java.lang.IllegalArgumentException - If name or descr lengths are invalid.
        java.sql.SQLException - For SQL errors.
        java.lang.NullPointerException - If conn, name or descr parameters are null.
      • getName

        public java.lang.String getName()
        Gets the name of the group.
        Returns:
        The user name.
      • getDescription

        public java.lang.String getDescription()
        Gets the description of the group.
        Returns:
        A descriptive text.
      • isDisabled

        public boolean isDisabled()
        Returns if the group is enabled or disabled.
        Returns:
        true if disabled, false for enabled (default).
      • areAllAppsAllowed

        public boolean areAllAppsAllowed()
        Returns if the group allows users to run all apps without further app checking.
        Returns:
        true to allow all apps (typically for administrators), false to perform default checking with the defined apps.
      • toString

        public java.lang.String toString()
        Outputs a debug string.
        Overrides:
        toString in class java.lang.Object
        Returns:
        String for debugging.
      • refreshFromDB

        public void refreshFromDB()
                           throws java.sql.SQLException
        Refreshes the DB information for the group.
        Throws:
        java.sql.SQLException - For SQL errors.
      • setInformation

        public boolean setInformation​(java.lang.String name,
                                      java.lang.String descr,
                                      java.lang.Boolean isDisabled,
                                      java.lang.Boolean areAllAppsAllowed)
                               throws NotFoundException,
                                      java.sql.SQLException
        Updates the information of the group.
        Parameters:
        name - The new name (min 3 characters, max 80 characters), null for same name.
        descr - The new description (max 160 characters), null for same description.
        isDisabled - Flag for group disabled, null for no change.
        areAllAppsAllowed - Flag for all apps are allowed, null for no change.
        Throws:
        java.lang.IllegalArgumentException - If name or descr lengths are invalid.
        NotFoundException - If the group is not found (has been removed).
        java.sql.SQLException - For SQL errors.
      • deleteGroup

        public boolean deleteGroup​(java.sql.Connection conn)
                            throws java.sql.SQLException
        Deletes the group from the database. No commit operation is done on the connection if you wish to perform multiple operations as a unit of operation.
        Parameters:
        conn - The SQL connection.
        Returns:
        true if successfully deleted, false if already deleted.
        Throws:
        java.sql.SQLException - For SQL errors.
      • deleteGroup

        public boolean deleteGroup()
                            throws java.sql.SQLException
        Deletes the group from the database. If you wish to delete multiple groups, use the deleteGroup(Connection) call instead and grab a connection from the pool.
        Returns:
        true if successfully deleted, false if already deleted.
        Throws:
        java.sql.SQLException - For SQL errors.