head	1.14;
access;
symbols
	TIGRIS_0_9_2_4:1.9
	TIGRIS_0_9_2_3:1.9
	HELM_PEER_PORT_BRANCH:1.13.0.2
	TURBINE_PEER:1.13
	TIGRIS_0_9_2_1:1.13
	TIGRIS_0_9_2:1.9.0.2
	TIGRIS_0_9_0:1.8.0.4
	TIGRIS_0_8_4:1.8.0.2
	NEWHELM:1.1.1.1
	TIGRIS_NOV_12_2000:1.1.1
	OLDHELM:1.3.0.2
	TIGRIS_NOV_11_2000:1.3;
locks; strict;
comment	@# @;


1.14
date	2001.02.21.03.23.56;	author edk;	state dead;
branches;
next	1.13;

1.13
date	2001.01.26.18.29.00;	author edk;	state Exp;
branches
	1.13.2.1;
next	1.12;

1.12
date	2001.01.26.05.24.05;	author edk;	state dead;
branches;
next	1.11;

1.11
date	2001.01.24.21.41.48;	author leonardr;	state Exp;
branches;
next	1.10;

1.10
date	2001.01.24.20.42.46;	author dlr;	state Exp;
branches;
next	1.9;

1.9
date	2001.01.05.21.42.38;	author leonardr;	state Exp;
branches;
next	1.8;

1.8
date	2000.11.28.21.08.22;	author leonardr;	state Exp;
branches;
next	1.7;

1.7
date	2000.11.20.21.43.16;	author leonardr;	state Exp;
branches;
next	1.6;

1.6
date	2000.11.17.00.29.21;	author leonardr;	state Exp;
branches;
next	1.5;

1.5
date	2000.11.15.22.48.39;	author leonardr;	state Exp;
branches;
next	1.4;

1.4
date	2000.11.12.22.57.31;	author dlr;	state Exp;
branches;
next	1.3;

1.3
date	2000.09.29.19.57.11;	author dlr;	state Exp;
branches;
next	1.2;

1.2
date	2000.09.29.19.55.46;	author dlr;	state Exp;
branches;
next	1.1;

1.1
date	2000.09.29.01.42.45;	author dlr;	state Exp;
branches
	1.1.1.1;
next	;

1.1.1.1
date	2000.11.12.21.15.16;	author dlr;	state Exp;
branches;
next	;

1.13.2.1
date	2001.01.28.01.02.17;	author dlr;	state dead;
branches;
next	;


desc
@@


1.14
log
@delete stuff from the head which is obsolete in the branch (more changes
are still needed for a clean compile)
@
text
@/* ================================================================
 * Copyright (c) 2000 CollabNet.  All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
 * met:
 * 
 * 1. Redistributions of source code must retain the above copyright
 * notice, this list of conditions and the following disclaimer.
 * 
 * 2. Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * 
 * 3. The end-user documentation included with the redistribution, if
 * any, must include the following acknowlegement: "This product includes
 * software developed by CollabNet (http://www.collab.net/)."
 * Alternately, this acknowlegement may appear in the software itself, if
 * and wherever such third-party acknowlegements normally appear.
 * 
 * 4. The hosted project names must not be used to endorse or promote
 * products derived from this software without prior written
 * permission. For written permission, please contact info@@collab.net.
 * 
 * 5. Products derived from this software may not use the "Tigris" name
 * nor may "Tigris" appear in their names without prior written
 * permission of CollabNet.
 * 
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL COLLABNET OR ITS CONTRIBUTORS BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * ====================================================================
 * 
 * This software consists of voluntary contributions made by many
 * individuals on behalf of CollabNet.
 */


package org.tigris.helm.database;

import java.sql.*;
import java.util.*;

import com.workingdogs.village.*;

import org.joist.database.*;
import org.tigris.helm.DoesNotExist;
import org.tigris.helm.domain.User;
import org.tigris.helm.project.Project;
import org.tigris.helm.database.*;
import org.tigris.helm.tool.*;
import org.tigris.helm.security.*;

/**
 * This class associates base users with composite users (which represent
 * groups of users.)
 *
 * @@author <a href="mailto:leonardr@@collab.net">Leonard Richardson</a>
 * @@author <a href="mailto:dlr@@collab.net">Daniel Rall</a>
 * @@version $Id: UserUserGroupManager.java,v 1.13 2001/01/26 18:29:00 edk Exp $
 */
public class UserUserGroupManager extends CompositeManager
{
    /**
     * The name of the table that this class manages.
     */
    public static final String TABLE_NAME = "HELM_USER_USERGROUP";

    /**
     * A table field name.
     */
    public static final String USER_ID = "userID";

    /**
     * A table field name.
     */
    public static final String USER_GROUP_ID = "userGroupID";

    /**
     * The values which indicate that the record is a base unit.
     */
    private static final String[] BASE_VALUES = { UserType.REGULAR };

    /**
     * The values which indicate that the record is a composite.
     */
    private static final String[] COMPOSITE_VALUES = 
    {
        UserType.GROUP, 
        UserType.HOST, 
        UserType.DOMAIN
    };

    /**
     * Creates a new instance.
     *
     * @@param dataMgr The associate manager.
     */
    public UserUserGroupManager (DataManager dataMgr)
    {
        super(dataMgr, USER_ID, USER_GROUP_ID, UserManager.TABLE_NAME, 
              TABLE_NAME, UserManager.TYPE, BASE_VALUES, COMPOSITE_VALUES);
    }

    public DataSet getUsersForGroup(Connection connection, 
                                       String groupUserID)
        throws DataSetException, SQLException
    {
        return getBasesForComposite(connection, groupUserID);
    }

    /**
     * Adds a new user group.
     *
     * @@param conn        The JDBC connection to use.
     * @@param name        The maps to the loginID field.
     * @@param description The maps to the name field.
     * @@param type        The group type.
     */
    public Integer addUserGroup (Connection conn, String name, 
                                 String description, String type)
        throws DataSetException, SQLException
    {
        Integer id = null;

        DataSet users = null;
        try
        {
            users = new TableDataSet(conn, UserManager.TABLE_NAME);
            Record userGroup = users.addRecord();
            userGroup.setValue(UserManager.LOGIN_ID, name);
            userGroup.setValue(UserManager.NAME, name);
            userGroup.setValue(UserManager.TYPE, type);
            userGroup.save();
        }
        finally
        {
            if (users != null) users.close();
        }
        id = getLastInsertedID(conn);

        return id;
    }

    /**
     * Gets the database key associated with the special user that represents 
     * the user group named by <code>userGroupName</code> in the domain 
     * <code>domainID</code>.
     * This should go into UserManager.
     *
     * @@param conn          The JDBC connection to use.
     * @@param domainID      The database key of the domain to retrieve the 
     *                      user for.
     * @@param userGroupName The name of the user group.
     */
    public String getUserIDForDomainUserGroup (Connection conn, 
                                               String domainID)
        throws SQLException
    {
        String id = null;
        PreparedStatement stmt = conn.prepareStatement
            ("select userID from User where domainID=? and type=?");
        stmt.setInt(1, Integer.valueOf(domainID).intValue());
        stmt.setString(2, UserType.DOMAIN);
        ResultSet result = stmt.executeQuery();
        id = (result.next() ? result.getString(1) : "-1");
        stmt.close();
        return id;
    }

    /**
     * Gets the database key associated with the special user that represents 
     * the group of all host users.
     * This should go into UserManager.
     *
     * @@param conn          The JDBC connection to use.
     */
    public String getUserIDForHostGroup (Connection conn)
        throws SQLException
    {
        String id = null;
        PreparedStatement stmt = conn.prepareStatement
            ("select userID from User where type=?");
        stmt.setString(1, UserType.HOST);
        ResultSet result = stmt.executeQuery();
        id = (result.next() ? result.getString(1) : "-1");
        stmt.close();
        return id;
    }

    /**
     * Gets the userID for user "**Nobody" This should go into UserManager.
     *
     * @@param  connection    A JDBC database connection.
     * @@param  domainID      The domain for which to get projects.
     * @@return a DataSet
     * @@exception    SQLException
     * @@exception DataSetException 
     */
    public String getNobodyUserID (Connection conn)
        throws JoistDatabaseException, DataSetException, SQLException
    {
        UserManager uMgr = (UserManager)
            getDataManager().getManager("org.joist.database.UserManager");
	String nobodyUserID = null;
	    Record userRcd = uMgr.getUserForLoginID(conn, "**Nobody");
	    nobodyUserID = userRcd.getValue(UserManager.USER_ID).toString();

	return nobodyUserID;
    }

    /**
     * Associates a user with a user group in the database.
     */
    public void addUserToGroup(Connection connection, String baseUserID, 
                               String groupUserID)
        throws SQLException, DataSetException, JoistDatabaseException,
               DoesNotExist
    {
        DataManager dMgr = getDataManager();
        addBaseToComposite(connection, baseUserID, groupUserID);
    }

    /**
     * Associates a user with a special domain-wide group.
     */
    public void addUserToDomainGroup(Connection connection, String baseUserID,
                                     String domainID)
        throws SQLException, DataSetException, JoistDatabaseException,
               DoesNotExist
    {
        addUserToGroup(connection, baseUserID, 
                       getUserIDForDomainUserGroup(connection, domainID));
    }

    /**
     * Removes a user-group binding in the database.
     */
    public void removeUserFromGroup(Connection connection, String baseUserID, 
                                    String groupUserID)
        throws SQLException, DataSetException, JoistDatabaseException,
               DoesNotExist
    {
        removeBaseFromComposite(connection, baseUserID, groupUserID);
    }    
}
@


1.13
log
@readding all the files as part of the process of returning to the way
things were as of tuesday
@
text
@d69 1
a69 1
 * @@version $Id: UserUserGroupManager.java,v 1.9 2001/01/05 21:42:38 leonardr Exp $
@


1.13.2.1
log
@Porting to the Turbine Peer system.  -dlr and leonardr
@
text
@d69 1
a69 1
 * @@version $Id: UserUserGroupManager.java,v 1.13 2001/01/26 18:29:00 edk Exp $
@


1.12
log
@revert this stuff to its state as of 2001/01/24 12:42:00 GMT -- with
the following exceptions, which have some different modifications so
they'll work with changes which have happened in joist:

ProjectNewsEdit.java
SkinManager.java
SkinStyleElementValueManager.java
StyleElementManager.java
StyleManager.java

it compiles.  i dunno if it works, though.
@
text
@d69 1
a69 1
 * @@version $Id: UserUserGroupManager.java,v 1.11 2001/01/24 21:41:48 leonardr Exp $
d114 7
d122 64
a185 1
     * Retrieves the users who belong to a particular group.
d187 2
a188 2
    public DataSet getUsersForGroup(String groupUserID)
        throws DBException
d190 8
a197 1
        return getBasesForComposite(groupUserID);
d201 18
a218 6
     * Retrieves the groups to which a particular user belongs.
     */
    public DataSet getGroupsForUser(String userID)
        throws DBException
    {
        return getCompositesForBase(userID);
d224 4
a227 2
    public void addUserToGroup(String baseUserID, String groupUserID)
        throws DBException
d229 2
a230 1
        addBaseToComposite(baseUserID, groupUserID);
d236 4
a239 2
    public void addUserToDomainGroup(String baseUserID, String domainID)
        throws DBException
d241 2
a242 3
        UserManager uMgr = (UserManager)getDataManager().getManager
            ("org.tigris.helm.database.UserManager");            
        addUserToGroup(baseUserID, uMgr.getUserIDForDomainUserGroup(domainID));
d248 4
a251 2
    public void removeUserFromGroup(String baseUserID, String groupUserID)
        throws DBException
d253 1
a253 1
        removeBaseFromComposite(baseUserID, groupUserID);
@


1.11
log
@Ported UserManager and RoleManager to Helm. Started moving other TableManagers toward a grab-connection-on-demand model. Massive breakage ensues. dlr and I are working on it.
@
text
@d69 1
a69 1
 * @@version $Id: UserUserGroupManager.java,v 1.10 2001/01/24 20:42:46 dlr Exp $
@


1.10
log
@Making use of DBException.
@
text
@d69 1
a69 1
 * @@version $Id: UserUserGroupManager.java,v 1.9 2001/01/05 21:42:38 leonardr Exp $
a113 7
    public DataSet getUsersForGroup(Connection connection, 
                                       String groupUserID)
        throws DBException
    {
        return getBasesForComposite(connection, groupUserID);
    }

d115 1
a115 6
     * Adds a new user group.
     *
     * @@param conn        The JDBC connection to use.
     * @@param name        The maps to the loginID field.
     * @@param description The maps to the name field.
     * @@param type        The group type.
d117 1
a117 2
    public Integer addUserGroup (Connection conn, String name, 
                                 String description, String type)
d120 1
a120 19
        Integer id = null;

        DataSet users = null;
        try
        {
            users = new TableDataSet(conn, UserManager.TABLE_NAME);
            Record userGroup = users.addRecord();
            userGroup.setValue(UserManager.LOGIN_ID, name);
            userGroup.setValue(UserManager.NAME, name);
            userGroup.setValue(UserManager.TYPE, type);
            userGroup.save();
        }
        finally
        {
            if (users != null) users.close();
        }
        id = getLastInsertedID(conn);

        return id;
d124 1
a124 9
     * Gets the database key associated with the special user that represents 
     * the user group named by <code>userGroupName</code> in the domain 
     * <code>domainID</code>.
     * This should go into UserManager.
     *
     * @@param conn          The JDBC connection to use.
     * @@param domainID      The database key of the domain to retrieve the 
     *                      user for.
     * @@param userGroupName The name of the user group.
d126 1
a126 2
    public String getUserIDForDomainUserGroup (Connection conn, 
                                               String domainID)
d129 1
a129 16
        String id = null;
        try
        {
            PreparedStatement stmt = conn.prepareStatement
                ("select userID from User where domainID=? and type=?");
            stmt.setInt(1, Integer.valueOf(domainID).intValue());
            stmt.setString(2, UserType.DOMAIN);
            ResultSet result = stmt.executeQuery();
            id = (result.next() ? result.getString(1) : "-1");
            stmt.close();
        }
        catch (SQLException e)
        {
            throw new DBException(e);
        }
        return id;
d133 1
a133 5
     * Gets the database key associated with the special user that represents 
     * the group of all host users.
     * This should go into UserManager.
     *
     * @@param conn          The JDBC connection to use.
d135 1
a135 1
    public String getUserIDForHostGroup (Connection conn)
d138 1
a138 15
        String id = null;
        try
        {
            PreparedStatement stmt = conn.prepareStatement
                ("select userID from User where type=?");
            stmt.setString(1, UserType.HOST);
            ResultSet result = stmt.executeQuery();
            id = (result.next() ? result.getString(1) : "-1");
            stmt.close();
        }
        catch (SQLException e)
        {
            throw new DBException(e);
        }
        return id;
d142 1
a142 5
     * Gets the userID for user "**Nobody" This should go into UserManager.
     *
     * @@param  connection    A JDBC database connection.
     * @@param  domainID      The domain for which to get projects.
     * @@return a DataSet
d144 1
a144 1
    public String getNobodyUserID (Connection conn)
d147 3
a149 29
        UserManager uMgr = (UserManager)
            getDataManager().getManager("org.joist.database.UserManager");
	String nobodyUserID = null;
	    Record userRcd = uMgr.getUserForLoginID(conn, "**Nobody");
	    nobodyUserID = userRcd.getValue(UserManager.USER_ID).toString();

	return nobodyUserID;
    }

    /**
     * Associates a user with a user group in the database.
     */
    public void addUserToGroup(Connection connection, String baseUserID, 
                               String groupUserID)
        throws DoesNotExist, DBException
    {
        DataManager dMgr = getDataManager();
        addBaseToComposite(connection, baseUserID, groupUserID);
    }

    /**
     * Associates a user with a special domain-wide group.
     */
    public void addUserToDomainGroup(Connection connection, String baseUserID,
                                     String domainID)
        throws DoesNotExist, DBException
    {
        addUserToGroup(connection, baseUserID, 
                       getUserIDForDomainUserGroup(connection, domainID));
d155 2
a156 3
    public void removeUserFromGroup(Connection connection, String baseUserID, 
                                    String groupUserID)
        throws DoesNotExist, DBException
d158 1
a158 1
        removeBaseFromComposite(connection, baseUserID, groupUserID);
@


1.9
log
@Big patch bringing the smart script runner online.
@
text
@d69 1
a69 1
 * @@version $Id: UserUserGroupManager.java,v 1.8 2000/11/28 21:08:22 leonardr Exp $
d116 1
a116 1
        throws DataSetException, SQLException
d131 1
a131 1
        throws DataSetException, SQLException
d167 1
a167 1
        throws SQLException
d170 14
a183 7
        PreparedStatement stmt = conn.prepareStatement
            ("select userID from User where domainID=? and type=?");
        stmt.setInt(1, Integer.valueOf(domainID).intValue());
        stmt.setString(2, UserType.DOMAIN);
        ResultSet result = stmt.executeQuery();
        id = (result.next() ? result.getString(1) : "-1");
        stmt.close();
d195 1
a195 1
        throws SQLException
d198 13
a210 6
        PreparedStatement stmt = conn.prepareStatement
            ("select userID from User where type=?");
        stmt.setString(1, UserType.HOST);
        ResultSet result = stmt.executeQuery();
        id = (result.next() ? result.getString(1) : "-1");
        stmt.close();
a219 2
     * @@exception    SQLException
     * @@exception DataSetException 
d222 1
a222 1
        throws JoistDatabaseException, DataSetException, SQLException
d238 1
a238 2
        throws SQLException, DataSetException, JoistDatabaseException,
               DoesNotExist
d249 1
a249 2
        throws SQLException, DataSetException, JoistDatabaseException,
               DoesNotExist
d260 1
a260 2
        throws SQLException, DataSetException, JoistDatabaseException,
               DoesNotExist
@


1.8
log
@Mega patch providing more user group admin functionality.
@
text
@d69 1
a69 1
 * @@version $Id: UserUserGroupManager.java,v 1.7 2000/11/20 21:43:16 leonardr Exp $
d174 20
@


1.7
log
@Added user group business object.
@
text
@d69 1
a69 1
 * @@version $Id: UserUserGroupManager.java,v 1.6 2000/11/17 00:29:21 leonardr Exp $
d202 1
a202 2
     * Associates a user with a user group, and makes sure the people who have 
     * roles in that user group get Issuezilla accounts in the user group.
a210 23
        AccessControlList.buildUserGroups(connection, dMgr);
        
        ArrayList affectedUsers = new ArrayList();
        ArrayList affectedProjects = new ArrayList();
        
        UserManager uMgr = (UserManager)
            dMgr.getManager("org.joist.database.UserManager");
        UserRoleProjectManager urpMgr = (UserRoleProjectManager)
            dMgr.getManager("org.tigris.helm.database.UserRoleProjectManager");
        
        //All projects this usergroup has a role in are affected
        DataSet projects = urpMgr.getProjectsForUser(connection, groupUserID);
        String domainName = null;
        for (int i = 0; i < projects.size(); i++)
        {
            Project project = new Project 
                (connection, dMgr, projects.getRecord(i));
            affectedProjects.add(project);
        }
        
        //Only one user -- the new one -- is affected by this change.
        affectedUsers.add(new User(connection, dMgr, baseUserID));
        TigrisUpdate.findNewMembers(affectedUsers, affectedProjects);
d226 1
a226 2
     * Removes a user from a group, deleting all the Issuezilla accounts
     * they got by virtue of belonging to that group.
a232 1
        DataManager dMgr = getDataManager();
a233 4
        AccessControlList.buildUserGroups(connection, dMgr);
        
        runScriptsForUserUserGroup(connection, baseUserID, groupUserID, 
                                   "Delete");
a234 43

    /**
     * Runs scripts to reflect a user's group membership after a
     * change. This method name does not very well describe what goes on.
     */
    public void runScriptsForUserUserGroup(Connection connection, 
                                           String baseUserID, 
                                           String groupUserID,
                                           String mode)
        throws SQLException, DataSetException, JoistDatabaseException,
               DoesNotExist
    {
        DataManager dMgr = getDataManager();
        ArrayList affectedUsers = new ArrayList();
        ArrayList affectedProjects = new ArrayList();
        
        UserManager uMgr = (UserManager)
            dMgr.getManager("org.joist.database.UserManager");
        UserRoleProjectManager urpMgr = (UserRoleProjectManager)
            dMgr.getManager("org.tigris.helm.database.UserRoleProjectManager");
        
        //All projects this usergroup has a role in are affected
        DataSet projects = urpMgr.getProjectsForUser(connection, groupUserID);
        for (int i = 0; i < projects.size(); i++)
        {
            Project project = new Project
                (connection, dMgr, projects.getRecord(i));
            affectedProjects.add(project);
        }
        
        //Only one user -- the base user -- is affected by this change.
        affectedUsers.add(new User(connection, dMgr, baseUserID));
        if (affectedUsers.size() > 0 && affectedProjects.size() > 0)
        {
            if (mode.equals("Add"))
            {
                TigrisUpdate.findNewMembers(affectedUsers, affectedProjects);
            } else {
                TigrisUpdate.findExMembers(affectedUsers, affectedProjects);
            }
        }
    }

@


1.6
log
@Made the TigrisUpdate stuff saner with the use of business objects.
@
text
@d69 1
a69 1
 * @@version $Id: UserUserGroupManager.java,v 1.5 2000/11/15 22:48:39 leonardr Exp $
d114 7
d235 12
@


1.5
log
@Got rid of more superfluous UpdateException throwage.
@
text
@d56 3
d69 1
a69 1
 * @@version $Id: UserUserGroupManager.java,v 1.4 2000/11/12 22:57:31 dlr Exp $
d200 2
a201 1
        throws SQLException, DataSetException, JoistDatabaseException
d220 3
a222 4
            ArrayList projectInfo = TigrisUpdate.getProjectInfo
                (dMgr, connection, projects.getRecord(i), domainName);
            domainName = (String)projectInfo.get(0);
            affectedProjects.add(projectInfo);
d226 1
a226 3
        affectedUsers.add
            (TigrisUpdate.getUserInfo(dMgr, connection, baseUserID));
        
d236 2
a237 1
        throws SQLException, DataSetException, JoistDatabaseException
d255 2
a256 1
        throws SQLException, DataSetException, JoistDatabaseException
a268 1
        String domainName = null;
d271 3
a273 4
            ArrayList projectInfo = TigrisUpdate.getProjectInfo
                (dMgr, connection, projects.getRecord(i), domainName);
            domainName = (String)projectInfo.get(0);
            affectedProjects.add(projectInfo);
d277 1
a277 3
        affectedUsers.add
            (TigrisUpdate.getUserInfo(dMgr, connection, baseUserID));

@


1.4
log
@Resolved merge conflicts.
@
text
@d66 1
a66 1
 * @@version $Id: UserUserGroupManager.java,v 1.1.1.1 2000/11/12 21:15:16 dlr Exp $
d197 1
a197 2
        throws SQLException, DataSetException, JoistDatabaseException,
               UpdateException
d235 1
a235 2
        throws SQLException, DataSetException, JoistDatabaseException,
               UpdateException
d253 1
a253 2
        throws SQLException, DataSetException, JoistDatabaseException,
               UpdateException
@


1.3
log
@Corrected log id.
@
text
@d17 1
a17 1
 * software developed by Collab.Net (http://www.Collab.Net/)."
d27 1
a27 1
 * permission of Collab.Net.
d32 1
a32 1
 * IN NO EVENT SHALL COLLAB.NET OR ITS CONTRIBUTORS BE LIABLE FOR ANY
d44 1
a44 1
 * individuals on behalf of Collab.Net.
d47 1
d50 1
a51 4
import java.sql.*;

import org.webmacro.util.*;
import org.webmacro.servlet.*;
d56 3
a58 1
import org.joist.util.*;
d61 2
a62 1
 * Manages one or more database table.
d64 1
d66 1
a66 3
 * @@version $Id: UserUserGroupManager.java,v 1.2 2000/09/29 19:55:46 dlr Exp $
 *
 * Copyright (c) 2000 CollabNet, Inc.
d68 72
d141 28
a168 4
public class UserUserGroupManager extends TableManager
{
    private static Log log = new Log("uugMgr", "UserUserGroupManager");
    private static boolean debug = true;
d171 1
a171 1
     * Instantiates a new instance.
d173 5
a177 1
     * @@param	dataMgr  A variable of type DataManager
d179 2
a180 1
    public UserUserGroupManager(DataManager dataMgr)
d182 7
a188 1
        super(dataMgr);
d190 103
@


1.2
log
@Collab.Net --> CollabNet in copyright.
@
text
@d64 1
a64 1
 * @@version $Id: UserUserGroupManager.java,v 1.1 2000/09/29 01:42:45 dlr Exp $
d71 1
a71 1
    private static Log log = new Log("rpsmMgr", "UserUserGroupManager");
@


1.1
log
@Table manager stubs for the new Helm permission system.
@
text
@d2 1
a2 1
 * Copyright (c) 2000 Collab.Net.  All rights reserved.
d64 1
a64 1
 * @@version $Id: $
d66 1
a66 1
 * Copyright (c) 2000 Collab.Net, Inc.
@


1.1.1.1
log
@Merging newhelm tree into helm, as per IZ issue #557.  Previous major version of helm is tagged TIGRIS_NOV_11_2000.
@
text
@d2 1
a2 1
 * Copyright (c) 2000 CollabNet.  All rights reserved.
d17 1
a17 1
 * software developed by CollabNet (http://www.collab.net/)."
d27 1
a27 1
 * permission of CollabNet.
d32 1
a32 1
 * IN NO EVENT SHALL COLLABNET OR ITS CONTRIBUTORS BE LIABLE FOR ANY
d44 1
a44 1
 * individuals on behalf of CollabNet.
a46 1

d49 1
d51 3
a53 1
import java.util.*;
d58 1
a58 3
import org.tigris.helm.database.*;
import org.tigris.helm.tool.*;
import org.tigris.helm.security.*;
d61 1
a61 2
 * This class associates base users with composite users (which represent
 * groups of users.)
a62 1
 * @@author <a href="mailto:leonardr@@collab.net">Leonard Richardson</a>
d64 3
a66 1
 * @@version $Id: UserUserGroupManager.java,v 1.39 2000/11/11 04:46:46 dlr Exp $
d68 2
a69 1
public class UserUserGroupManager extends CompositeManager
d71 2
a72 73
    /**
     * The name of the table that this class manages.
     */
    public static final String TABLE_NAME = "HELM_USER_USERGROUP";

    /**
     * A table field name.
     */
    public static final String USER_ID = "userID";

    /**
     * A table field name.
     */
    public static final String USER_GROUP_ID = "userGroupID";

    /**
     * The values which indicate that the record is a base unit.
     */
    private static final String[] BASE_VALUES = { UserType.REGULAR };

    /**
     * The values which indicate that the record is a composite.
     */
    private static final String[] COMPOSITE_VALUES = 
    {
        UserType.GROUP, 
        UserType.HOST, 
        UserType.DOMAIN
    };

    /**
     * Creates a new instance.
     *
     * @@param dataMgr The associate manager.
     */
    public UserUserGroupManager (DataManager dataMgr)
    {
        super(dataMgr, USER_ID, USER_GROUP_ID, UserManager.TABLE_NAME, 
              TABLE_NAME, UserManager.TYPE, BASE_VALUES, COMPOSITE_VALUES);
    }

    /**
     * Adds a new user group.
     *
     * @@param conn        The JDBC connection to use.
     * @@param name        The maps to the loginID field.
     * @@param description The maps to the name field.
     * @@param type        The group type.
     */
    public Integer addUserGroup (Connection conn, String name, 
                                 String description, String type)
        throws DataSetException, SQLException
    {
        Integer id = null;

        DataSet users = null;
        try
        {
            users = new TableDataSet(conn, UserManager.TABLE_NAME);
            Record userGroup = users.addRecord();
            userGroup.setValue(UserManager.LOGIN_ID, name);
            userGroup.setValue(UserManager.NAME, name);
            userGroup.setValue(UserManager.TYPE, type);
            userGroup.save();
        }
        finally
        {
            if (users != null) users.close();
        }
        id = getLastInsertedID(conn);

        return id;
    }
d75 1
a75 4
     * Gets the database key associated with the special user that represents 
     * the user group named by <code>userGroupName</code> in the domain 
     * <code>domainID</code>.
     * This should go into UserManager.
d77 1
a77 4
     * @@param conn          The JDBC connection to use.
     * @@param domainID      The database key of the domain to retrieve the 
     *                      user for.
     * @@param userGroupName The name of the user group.
d79 1
a79 3
    public String getUserIDForDomainUserGroup (Connection conn, 
                                               String domainID)
        throws SQLException
d81 1
a81 9
        String id = null;
        PreparedStatement stmt = conn.prepareStatement
            ("select userID from User where domainID=? and type=?");
        stmt.setInt(1, Integer.valueOf(domainID).intValue());
        stmt.setString(2, UserType.DOMAIN);
        ResultSet result = stmt.executeQuery();
        id = (result.next() ? result.getString(1) : "-1");
        stmt.close();
        return id;
a82 124

    /**
     * Gets the userID for user "**Nobody" This should go into UserManager.
     *
     * @@param  connection    A JDBC database connection.
     * @@param  domainID      The domain for which to get projects.
     * @@return a DataSet
     * @@exception    SQLException
     * @@exception DataSetException 
     */
    public String getNobodyUserID (Connection conn)
        throws JoistDatabaseException, DataSetException, SQLException
    {
        UserManager uMgr = (UserManager)
            getDataManager().getManager("org.joist.database.UserManager");
	String nobodyUserID = null;
	    Record userRcd = uMgr.getUserForLoginID(conn, "**Nobody");
	    nobodyUserID = userRcd.getValue(UserManager.USER_ID).toString();

	return nobodyUserID;
    }

    /**
     * Associates a user with a user group, and makes sure the people who have 
     * roles in that user group get Issuezilla accounts in the user group.
     */
    public void addUserToGroup(Connection connection, String baseUserID, 
                               String groupUserID)
        throws SQLException, DataSetException, JoistDatabaseException,
               UpdateException
    {
        DataManager dMgr = getDataManager();
        addBaseToComposite(connection, baseUserID, groupUserID);
        AccessControlList.buildUserGroups(connection, dMgr);
        
        ArrayList affectedUsers = new ArrayList();
        ArrayList affectedProjects = new ArrayList();
        
        UserManager uMgr = (UserManager)
            dMgr.getManager("org.joist.database.UserManager");
        UserRoleProjectManager urpMgr = (UserRoleProjectManager)
            dMgr.getManager("org.tigris.helm.database.UserRoleProjectManager");
        
        //All projects this usergroup has a role in are affected
        DataSet projects = urpMgr.getProjectsForUser(connection, groupUserID);
        String domainName = null;
        for (int i = 0; i < projects.size(); i++)
        {
            ArrayList projectInfo = TigrisUpdate.getProjectInfo
                (dMgr, connection, projects.getRecord(i), domainName);
            domainName = (String)projectInfo.get(0);
            affectedProjects.add(projectInfo);
        }
        
        //Only one user -- the new one -- is affected by this change.
        affectedUsers.add
            (TigrisUpdate.getUserInfo(dMgr, connection, baseUserID));
        
        TigrisUpdate.findNewMembers(affectedUsers, affectedProjects);
    }

    /**
     * Removes a user from a group, deleting all the Issuezilla accounts
     * they got by virtue of belonging to that group.
     */
    public void removeUserFromGroup(Connection connection, String baseUserID, 
                                    String groupUserID)
        throws SQLException, DataSetException, JoistDatabaseException,
               UpdateException
    {
        DataManager dMgr = getDataManager();
        removeBaseFromComposite(connection, baseUserID, groupUserID);
        AccessControlList.buildUserGroups(connection, dMgr);
        
        runScriptsForUserUserGroup(connection, baseUserID, groupUserID, 
                                   "Delete");
    }    

    /**
     * Runs scripts to reflect a user's group membership after a
     * change. This method name does not very well describe what goes on.
     */
    public void runScriptsForUserUserGroup(Connection connection, 
                                           String baseUserID, 
                                           String groupUserID,
                                           String mode)
        throws SQLException, DataSetException, JoistDatabaseException,
               UpdateException
    {
        DataManager dMgr = getDataManager();
        ArrayList affectedUsers = new ArrayList();
        ArrayList affectedProjects = new ArrayList();
        
        UserManager uMgr = (UserManager)
            dMgr.getManager("org.joist.database.UserManager");
        UserRoleProjectManager urpMgr = (UserRoleProjectManager)
            dMgr.getManager("org.tigris.helm.database.UserRoleProjectManager");
        
        //All projects this usergroup has a role in are affected
        DataSet projects = urpMgr.getProjectsForUser(connection, groupUserID);
        String domainName = null;
        for (int i = 0; i < projects.size(); i++)
        {
            ArrayList projectInfo = TigrisUpdate.getProjectInfo
                (dMgr, connection, projects.getRecord(i), domainName);
            domainName = (String)projectInfo.get(0);
            affectedProjects.add(projectInfo);
        }
        
        //Only one user -- the base user -- is affected by this change.
        affectedUsers.add
            (TigrisUpdate.getUserInfo(dMgr, connection, baseUserID));

        if (affectedUsers.size() > 0 && affectedProjects.size() > 0)
        {
            if (mode.equals("Add"))
            {
                TigrisUpdate.findNewMembers(affectedUsers, affectedProjects);
            } else {
                TigrisUpdate.findExMembers(affectedUsers, affectedProjects);
            }
        }
    }

@


