📄 jahiagroupmanagerdbservice.java
字号:
Connection dbConn = getDBConnection (2000); if (dbConn == null) { return result; } Statement statement = null; try { statement = dbConn.createStatement(); if (statement != null) { // Get the basic user data String query = "SELECT name_jahia_grps FROM jahia_grps"; ResultSet rs = ServicesRegistry.getInstance().getDBPoolService().executeQuery(statement,query); if (rs != null) { String name; while (rs.next()) { name = rs.getString ("name_jahia_grps"); if (name != null) { result.add (name); } } } } } catch (SQLException sqlEx) { // FIXME -Fulco- : Don't know yet what to do with this exception. // It should be logged somewhere ! } finally { CloseDBConnection (dbConn); CloseStatement (statement); } return result; } //------------------------------------------------------------------------- /** * Return a <code>Vector</code) of <code>String</code> representing all the * group names of a site. * * @param int the site id * @return Return a vector of strings containing all the group names. */ public Vector getGroupnameList (int siteID) { Vector result = new Vector(); // Get a database connection Connection dbConn = getDBConnection (2000); if (dbConn == null) { return result; } Statement statement = null; try { statement = dbConn.createStatement(); if (statement != null) { // Get the basic user data String query = "SELECT name_jahia_grps FROM jahia_grps where siteid_jahia_grps=" + siteID; ResultSet rs = ServicesRegistry.getInstance().getDBPoolService().executeQuery(statement,query); if (rs != null) { String name; while (rs.next()) { name = rs.getString ("name_jahia_grps"); if (name != null) { result.add (name); } } } } } catch (SQLException sqlEx) { // FIXME -Fulco- : Don't know yet what to do with this exception. // It should be logged somewhere ! } finally { CloseDBConnection (dbConn); CloseStatement (statement); } return result; } //------------------------------------------------------------------------- /** * Return a <code>Vector</code) of <code>String</code> representing all the * group keys of a site. * * @param int the site id * @return Return a vector of identifier of all groups of this site. * @auhtor NK */ public Vector getGroupList (int siteID){ Vector result = new Vector(); // Get a database connection Connection dbConn = getDBConnection (2000); if (dbConn == null) { return result; } Statement statement = null; try { statement = dbConn.createStatement(); if (statement != null) { // Get the basic user data String query = "SELECT key_jahia_grps FROM jahia_grps where siteid_jahia_grps=" + siteID; ResultSet rs = ServicesRegistry.getInstance().getDBPoolService().executeQuery(statement,query); if (rs != null) { String name; while (rs.next()) { name = rs.getString ("key_jahia_grps"); if (name != null) { result.add (name); } } } } } catch (SQLException sqlEx) { // FIXME -Fulco- : Don't know yet what to do with this exception. // It should be logged somewhere ! } finally { CloseDBConnection (dbConn); CloseStatement (statement); } return result; } //------------------------------------------------------------------------- /** * Return a <code>Vector</code) of <code>String</code> representing all the * group keys of a site. * * @param int the site id * @return Return a vector of identifier of all groups of this site. * @auhtor NK */ public Vector getGroupList (){ Vector result = new Vector(); // Get a database connection Connection dbConn = getDBConnection (2000); if (dbConn == null) { return result; } Statement statement = null; try { statement = dbConn.createStatement(); if (statement != null) { // Get the basic user data String query = "SELECT key_jahia_grps FROM jahia_grps "; ResultSet rs = ServicesRegistry.getInstance().getDBPoolService().executeQuery(statement,query); if (rs != null) { String name; while (rs.next()) { name = rs.getString ("key_jahia_grps"); if (name != null) { result.add (name); } } } } } catch (SQLException sqlEx) { // FIXME -Fulco- : Don't know yet what to do with this exception. // It should be logged somewhere ! } finally { CloseDBConnection (dbConn); CloseStatement (statement); } return result; } //------------------------------------------------------------------------- /** * Return the list of groups to which the specified user has access. * * @param user Valid reference on an existing group. * * @return Return a vector of strings holding all the group names to * which the user as access. On any error, the returned vector * might be null. */ public Vector getUserMembership (JahiaUser user) { // try to avoid a NullPointerException if (user == null) { return null; } Vector result = new Vector(); // Get a database connection Connection dbConn = getDBConnection (2001); if (dbConn == null) { return result; } Statement statement = null; try { statement = dbConn.createStatement(); if (statement != null) { StringBuffer query = new StringBuffer("SELECT id_jahia_grps FROM jahia_grp_access"); query.append (" WHERE id_jahia_member='"); query.append (((JahiaUser)user).getName()); query.append ("' AND membertype_grp_access="); query.append (mUSERTYPE); ResultSet rs = ServicesRegistry.getInstance().getDBPoolService().executeQuery(statement,query.toString()); if (rs != null) { while (rs.next()) { String name = rs.getString ("id_jahia_grps"); if (name != null) { result.add (name); } } } } } catch (SQLException ex) { // FIXME -Fulco- : Don't know yet what to do with this exception. // It should be logged somewhere ! } finally { CloseDBConnection (dbConn); CloseStatement (statement); } return result; } //------------------------------------------------------------------------- /** * */ public JahiaGroup getAdministratorGroup (int siteID) { return lookupGroup (siteID, ADMINISTRATORS_GROUPNAME); } //------------------------------------------------------------------------- /** * Get all JahiaSite objects where the user has an access. * * @param JahiaUser user, the user you want to get his access grantes sites list. * @return Return a vector containing all JahiaSite objects where the user has an access. * @author Alexandre Kraft */ public Vector getAdminGrantedSites( JahiaUser user ) throws JahiaException { Vector grantedSites = new Vector(); Enumeration sitesList = ServicesRegistry.getInstance().getJahiaSitesService().getSites(); while(sitesList.hasMoreElements()) { JahiaSite jahiaSite = (JahiaSite) sitesList.nextElement(); JahiaConsole.println("JahiaGroupManagerDBService.getAdminGrantedSites","check granted site " + jahiaSite.getServerName()); if(JahiaSiteTools.getAdminGroup(jahiaSite).isMember( user )) { JahiaConsole.println("JahiaGroupManagerDBService.getAdminGrantedSites","granted site for " + jahiaSite.getServerName()); grantedSites.add( jahiaSite ); } } return grantedSites; } // end getAdminGrantedSites //------------------------------------------------------------------------- /** * Return an instance of the users group. * * @return Return the instance of the users group. Return null on any failure */ public final JahiaGroup getUsersGroup (int siteID) { return lookupGroup (siteID, USERS_GROUPNAME); } //------------------------------------------------------------------------- /** * Return an instance of the guest group * * @return Return the instance of the guest group. Return null on any failure. */ public final JahiaGroup getGuestGroup (int siteID) { return lookupGroup (siteID, GUEST_GROUPNAME); } //-------------------------------------------------------------------------- // Executes and INSERT, UPDATE or DELETE SQL operation. This method should not // be used with and SELECT operation. This method lock the object on database // write access. private boolean makeQuery (String query) { // Get a database connection Connection dbConn = getDBConnection (2003); if (dbConn == null) { return false; } boolean result = false; Statement statement = null; try { statement = dbConn.createStatement(); if (statement != null) { synchronized (this) { ServicesRegistry.getInstance().getDBPoolService().executeUpdate (statement,query); result = true; } } } catch (SQLException sqlEx) { toConsole ("SQL Exception occured for query ["+query+"]"); // FIXME -Fulco- : Don't know yet what to do with this exception. // It should be logged somewhere ! } finally { CloseDBConnection (dbConn); CloseStatement (statement); } return result; } //-------------------------------------------------------------------------- private boolean addGroupIntoDB (int id, String groupname, String groupKey, int siteID, Properties properties) { // Get a database connection Connection dbConn = getDBConnection (1002); if (dbConn == null) { return false; } boolean result = true; String grpIDStr = Integer.toString (id); Statement statement = null; try { statement = dbConn.createStatement(); String query = "INSERT INTO jahia_grps VALUES ("+ grpIDStr+",'"+groupname+"','" + groupKey + "'," + siteID + ")"; ServicesRegistry.getInstance().getDBPoolService().executeUpdate (statement,query); // Add the grp's attributes if (properties != null) { Enumeration enum = properties.propertyNames(); String name, value; if (enum.hasMoreElements())
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -