head	1.16;
access;
symbols
	TIGRIS_0_9_2_4:1.11
	TIGRIS_0_9_2_3:1.11
	HELM_PEER_PORT_BRANCH:1.15.0.2
	TURBINE_PEER:1.15
	TIGRIS_0_9_2_1:1.15
	TIGRIS_0_9_2:1.11.0.2
	TIGRIS_0_9_0:1.2.0.2;
locks; strict;
comment	@# @;


1.16
date	2001.02.21.02.17.29;	author dlr;	state dead;
branches;
next	1.15;

1.15
date	2001.01.26.18.29.00;	author edk;	state Exp;
branches
	1.15.2.1;
next	1.14;

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

1.13
date	2001.01.24.21.41.48;	author leonardr;	state Exp;
branches;
next	1.12;

1.12
date	2001.01.24.20.42.46;	author dlr;	state Exp;
branches;
next	1.11;

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

1.10
date	2001.01.12.18.55.42;	author leonardr;	state Exp;
branches;
next	1.9;

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

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

1.7
date	2001.01.08.23.25.01;	author dlr;	state Exp;
branches;
next	1.6;

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

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

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

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

1.2
date	2000.12.15.04.37.45;	author leonardr;	state Exp;
branches;
next	1.1;

1.1
date	2000.12.13.02.00.24;	author leonardr;	state Exp;
branches;
next	;

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


desc
@@


1.16
log
@Deprecated by peer port merge.
@
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.business;

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

import org.webmacro.util.*;
import org.webmacro.servlet.WebContext;

import com.workingdogs.village.*;

import org.joist.util.QuotedString;
import org.joist.database.*;

import org.tigris.helm.DoesNotExist;
import org.tigris.helm.database.*;
import org.tigris.helm.domain.*;
import org.tigris.helm.project.Project;
import org.tigris.helm.security.AccessControlList;
import org.tigris.helm.security.ACLException;
import org.tigris.helm.tool.*;
import org.tigris.helm.tool.audit.AuditLog;
import org.tigris.helm.tool.paginate.*;

public class Host extends BusinessObject
{
    private static Log log = new Log("Host", "Host Business Object");
    
    private static DomainManager domMgr;
    private static ProjectManager pMgr;
    private static RoleManager roleMgr;
    private static UserManager uMgr;
    private static UserUserGroupManager usrGrpMgr;
    private static ActionManager actMgr;
    private static ResourceManager resMgr;    

    /**
     * @@see org.tigris.helm.domain.BusinessObject#BusinessObject
     */
    public Host (Connection conn, DataManager dMgr)
    {
        super(conn, dMgr);
    }

    protected final String getTableName()
    {
        return "[None]";
    }

    public String getID() 
    {
        return "Host";
    }

    protected void createManagers ()
    {
        if (domMgr == null)
        {
            domMgr = (DomainManager)
                dMgr.getManager("org.tigris.helm.database.DomainManager");
        }

        if (pMgr == null)
        {
            pMgr = (ProjectManager)
                dMgr.getManager("org.tigris.helm.database.ProjectManager");
        }

        if (usrGrpMgr == null)
        {
            usrGrpMgr = (UserUserGroupManager)
                dMgr.getManager("org.tigris.helm.database.UserUserGroupManager");
        }

        if (actMgr == null) 
        {
            actMgr = (ActionManager)
                dMgr.getManager("org.tigris.helm.database.ActionManager");
        }

        if (resMgr == null) 
        {
            resMgr = (ResourceManager)
                dMgr.getManager("org.tigris.helm.database.ResourceManager");
        }

        if (roleMgr == null) 
        {
            roleMgr = (RoleManager)
                dMgr.getManager("org.joist.database.RoleManager");
        }
    }

    /**
     * Returns the special project which is a placeholder for the host
     * the project table (it's the group that all projects in the host are
     * members of).
     *
     * @@return The special project representing all projects on the host
     */
    public Project getSpecialProject()
        throws DataSetException, SQLException, DoesNotExist
    {
        return new Project(conn, dMgr, pMgr.getHostProjectID());
    }

    /**
     * Returns a list of all the base users on the site. 
     */
    public List getAllSiteUsers()
        throws DataSetException, JoistDatabaseException, SQLException,
               DoesNotExist
    {
        List domains = getDomains();
        List users = new ArrayList();
        for (Iterator i = domains.iterator(); i.hasNext();)
        {
            Domain d = (Domain)i.next();
            users.addAll(d.getUsers());
        }
        return users;
    }

    /**
     * Returns a list of the host users.
     */
    public List getUsers()
        throws DataSetException, JoistDatabaseException, SQLException,
               DoesNotExist
    {
        return getSpecialUser().expand();
    }

    /**
     * Returns a list of the base host users.
     */
    public List getBaseUsers()
        throws DataSetException, JoistDatabaseException, SQLException,
               DoesNotExist
    {
        List allUsers = getUsers();
        for (Iterator i = allUsers.iterator(); i.hasNext();)
        {
            User u = (User)i.next();
            if (!u.isBase()) allUsers.remove(u);
        }
        return allUsers;
    }

    /**
     * Returns the special user which is a placeholder for the host
     * users.
     *
     * @@return The special user representing all host users.
     */
    public User getSpecialUser()
        throws DataSetException, JoistDatabaseException, SQLException,
               DoesNotExist
    {
        return User.getInstance(conn, dMgr,
                                usrGrpMgr.getUserIDForHostGroup(conn));
    }

    /**
     * Returns a list of all domains, including the special host domain.
     */
    public List getDomains()
        throws DataSetException, SQLException
    {
        return Domain.listDomains(conn, dMgr);
    }

    public List getHostActions()
        throws DataSetException, SQLException, JoistDatabaseException
    {
        return getActionsForType(ActionManager.HOST_TYPE);
    }

    public List getDomainActions()
        throws DataSetException, SQLException, JoistDatabaseException
    {
        return getActionsForType(ActionManager.DOMAIN_TYPE);
    }
    
    public List getProjectActions()
        throws DataSetException, SQLException, JoistDatabaseException
    {
        return getActionsForType(ActionManager.PROJECT_TYPE);
    }
    
    private List getActionsForType(String type)
        throws DataSetException, SQLException, JoistDatabaseException
    {
        ArrayList actions = new ArrayList();
        DataSet actionSet = actMgr.getActionsForType(conn, type);
        for (int i = 0; i < actionSet.size(); i++)
        {
            try {
                actions.add(new Action(conn, dMgr, actionSet.getRecord(i)));
                //Can't happen with records.
            } catch (DoesNotExist ignore) {}
        }
        return actions;
    }

    public List getResources()
        throws DataSetException, SQLException, JoistDatabaseException
    {
        ArrayList resources = new ArrayList();
        DataSet resourceSet = resMgr.listResources(conn);
        for (int i = 0; i < resourceSet.size(); i++)
        {
            try {
                resources.add
                    (new Resource(conn, dMgr, resourceSet.getRecord(i)));
                //Can't happen with records.
            } catch (DoesNotExist ignore) {}
        }
        return resources;
    }

    public List getRoles()
        throws DataSetException, SQLException, JoistDatabaseException,
               DoesNotExist
    {
        ArrayList roles = new ArrayList();
        DataSet roleSet = roleMgr.listRoles(conn);
        for (int i = 0; i < roleSet.size(); i++)
        {
            roles.add(new Role(conn, dMgr, roleSet.getRecord(i)));
        }        
        return roles;
    }

    public List getHostRoles()
        throws DataSetException, SQLException, JoistDatabaseException
    {
        return getTypedRoles("host");
    }

    public List getDomainRoles()
        throws DataSetException, SQLException, JoistDatabaseException
    {
        return getTypedRoles("domain");
    }

    public List getProjectRoles()
        throws DataSetException, SQLException, JoistDatabaseException
    {
        return getTypedRoles("project");
    }

    private List getTypedRoles(String type)
        throws DataSetException, SQLException, JoistDatabaseException
    {
        ArrayList roles = new ArrayList();
        DataSet roleSet = roleMgr.listRolesByType(conn, type);
        for (int i = 0; i < roleSet.size(); i++)
        {
            try {                
                roles.add(new Role(conn, dMgr, roleSet.getRecord(i)));
            } catch (DoesNotExist ignore) {
                //Can't happen for records.
            }
        }        
        return roles;
    }

    public List getRequestableProjectRoles()
        throws DataSetException, SQLException, JoistDatabaseException,
               DoesNotExist
    {
        ArrayList roles = new ArrayList();
        DataSet roleSet = roleMgr.listRolesByType(conn, "project");
        for (int i = 0; i < roleSet.size(); i++)
        {
            Role role = new Role(conn, dMgr, roleSet.getRecord(i));
            if (role.isRequestable())
            {
                roles.add(role);
            }
        }        
        return roles;
    }

    public PaginatableAuditLogEntryList getAuditLog
        (Integer itemsPerPage, Criterion criterion, AccessControlList acl, 
         Domain currentDomain)
        throws SQLException, DataSetException
    {
        return AuditLog.getLog 
            (conn, dMgr, itemsPerPage, criterion, acl, currentDomain);
    }

}
@


1.15
log
@readding all the files as part of the process of returning to the way
things were as of tuesday
@
text
@@


1.15.2.1
log
@Porting to the Turbine Peer system.  -dlr and leonardr
@
text
@@


1.14
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
@d58 1
a58 4

import org.joist.database.Criterion;
import org.joist.database.DataManager;
import org.joist.database.JoistDatabaseException;
d135 1
a135 1
                dMgr.getManager("org.tigris.helm.database.RoleManager");
d147 1
a147 1
        throws DoesNotExist, DBException
d156 2
a157 1
        throws DoesNotExist, DBException
d173 2
a174 1
        throws DoesNotExist, DBException
d183 2
a184 1
        throws DoesNotExist, DBException
d202 2
a203 1
        throws DoesNotExist, DBException
d213 1
a213 1
        throws DBException
d219 1
a219 1
        throws DBException
d225 1
a225 1
        throws DBException
d231 1
a231 1
        throws DBException
d237 1
a237 1
        throws DBException
d240 1
a240 1
        DataSet actionSet = actMgr.getActionsForType(type);
d243 1
a243 2
            try
            {
d246 1
a246 5
            }
            catch (DataSetException e)
            {
                throw new DBException(e);
            }
d252 1
a252 1
        throws DBException
d262 1
a262 9
            }
            catch (DoesNotExist ignored)
            {
                // Can't happen when we already have a Record object.
            }
            catch (DataSetException e)
            {
                throw new DBException(e);
            }
d268 2
a269 1
        throws DoesNotExist, DBException
d272 2
a273 14
        DataSet roleSet = null;
        try
        {
            roleSet = roleMgr.listRoles(conn);
            for (int i = 0; i < roleSet.size(); i++)
            {
                roles.add(new Role(conn, dMgr, roleSet.getRecord(i)));
            }        
        }
        catch (DataSetException e)
        {
            throw new DBException(e);
        }
        catch (SQLException e)
d275 2
a276 6
            throw new DBException(e);
        }
        finally
        {
            dMgr.registerToClose(roleSet);
        }
d281 1
a281 1
        throws DBException
d287 1
a287 1
        throws DBException
d293 1
a293 1
        throws DBException
d299 1
a299 1
        throws DBException
d302 2
a303 2
        DataSet roleSet = null;
        try
d305 4
a308 8
            roleSet = roleMgr.listRolesByType(conn, type);
            for (int i = 0; i < roleSet.size(); i++)
            {
                try {                
                    roles.add(new Role(conn, dMgr, roleSet.getRecord(i)));
                } catch (DoesNotExist ignored) {
                    //Can't happen when we have a Record object.
                }
d310 1
a310 9
        }
        catch (DataSetException e)
        {
            throw new DBException(e);
        }
        catch (SQLException e)
        {
            throw new DBException(e);
        }
d315 2
a316 1
        throws DoesNotExist, DBException
d319 2
a320 2
        DataSet roleSet = null;
        try
d322 2
a323 2
            roleSet = roleMgr.listRolesByType(conn, "project");
            for (int i = 0; i < roleSet.size(); i++)
d325 1
a325 5
                Role role = new Role(conn, dMgr, roleSet.getRecord(i));
                if (role.isRequestable())
                {
                    roles.add(role);
                }
d327 1
a327 13
        }
        catch (DataSetException e)
        {
            throw new DBException(e);
        }
        catch (SQLException e)
        {
            throw new DBException(e);
        }
        finally
        {
            dMgr.registerToClose(roleSet);
        }
@


1.13
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
@@


1.12
log
@Making use of DBException.
@
text
@d58 4
a61 1
import org.joist.database.*;
d138 1
a138 1
                dMgr.getManager("org.joist.database.RoleManager");
d239 1
a239 1
        DataSet actionSet = actMgr.getActionsForType(conn, type);
@


1.11
log
@getSiteUsers should not return groups.
@
text
@d147 1
a147 1
        throws DataSetException, SQLException, DoesNotExist
d156 1
a156 2
        throws DataSetException, JoistDatabaseException, SQLException,
               DoesNotExist
d172 1
a172 2
        throws DataSetException, JoistDatabaseException, SQLException,
               DoesNotExist
d181 1
a181 2
        throws DataSetException, JoistDatabaseException, SQLException,
               DoesNotExist
d199 1
a199 2
        throws DataSetException, JoistDatabaseException, SQLException,
               DoesNotExist
d209 1
a209 1
        throws DataSetException, SQLException
d215 1
a215 1
        throws DataSetException, SQLException, JoistDatabaseException
d221 1
a221 1
        throws DataSetException, SQLException, JoistDatabaseException
d227 1
a227 1
        throws DataSetException, SQLException, JoistDatabaseException
d233 1
a233 1
        throws DataSetException, SQLException, JoistDatabaseException
d239 2
a240 1
            try {
d243 5
a247 1
            } catch (DoesNotExist ignore) {}
d253 1
a253 1
        throws DataSetException, SQLException, JoistDatabaseException
d263 9
a271 1
            } catch (DoesNotExist ignore) {}
d277 1
a277 2
        throws DataSetException, SQLException, JoistDatabaseException,
               DoesNotExist
d280 14
a293 2
        DataSet roleSet = roleMgr.listRoles(conn);
        for (int i = 0; i < roleSet.size(); i++)
d295 6
a300 2
            roles.add(new Role(conn, dMgr, roleSet.getRecord(i)));
        }        
d305 1
a305 1
        throws DataSetException, SQLException, JoistDatabaseException
d311 1
a311 1
        throws DataSetException, SQLException, JoistDatabaseException
d317 1
a317 1
        throws DataSetException, SQLException, JoistDatabaseException
d323 1
a323 1
        throws DataSetException, SQLException, JoistDatabaseException
d326 2
a327 2
        DataSet roleSet = roleMgr.listRolesByType(conn, type);
        for (int i = 0; i < roleSet.size(); i++)
d329 8
a336 4
            try {                
                roles.add(new Role(conn, dMgr, roleSet.getRecord(i)));
            } catch (DoesNotExist ignore) {
                //Can't happen for records.
d338 9
a346 1
        }        
d351 1
a351 2
        throws DataSetException, SQLException, JoistDatabaseException,
               DoesNotExist
d354 2
a355 2
        DataSet roleSet = roleMgr.listRolesByType(conn, "project");
        for (int i = 0; i < roleSet.size(); i++)
d357 2
a358 2
            Role role = new Role(conn, dMgr, roleSet.getRecord(i));
            if (role.isRequestable())
d360 5
a364 1
                roles.add(role);
d366 13
a378 1
        }        
@


1.10
log
@Added some listing methods.
@
text
@d17 1
a17 1
 * software developed by CollabNet (http://www.Collab.Net/)."
d153 1
a153 1
     * Returns a list of all the users on the site. 
d164 1
a164 1
            users.addAll(d.getGroupsAndUsers());
@


1.9
log
@Fixes related to IssueTrackingRebuild.
@
text
@d153 17
d207 9
@


1.8
log
@New servlet and support for same: IssueTrackingRebuild
@
text
@d163 16
@


1.7
log
@Corrected a bunch of regressions to previous User instantion method.  Deprecated User's getUserID() method in favor of getID() for better conformance with BusinessObject interface and orthoginality with other business objects.  Added a guest user and interface.  Added some JavaDoc to User.
@
text
@d153 10
@


1.6
log
@Big patch bringing the smart script runner online.
@
text
@d159 2
a160 1
        throws DataSetException, JoistDatabaseException, SQLException, DoesNotExist
d162 2
a163 1
        return new User(conn, dMgr, usrGrpMgr.getUserIDForHostGroup(conn));
@


1.5
log
@Many, many pagination changes.
@
text
@d78 1
d114 6
d150 12
@


1.4
log
@Removed unnecessary getCache() implementations in BusinessObject subclasses and migrated to a factory method for User's primary database key ctor.
@
text
@d67 2
d256 9
@


1.3
log
@Propogated object cache interface.
@
text
@a129 5
    protected Dictionary getCache ()
    {
        return null;
    }

@


1.2
log
@Big patch whose main effect is to make dynamic the list of roles on UserEdit dynamic.
@
text
@d130 5
@


1.1
log
@Added Host object--this has some code which will be phased out of Domain.
@
text
@d105 6
@

