head	1.9;
access;
symbols
	TIGRIS_0_9_2_4:1.3
	TIGRIS_0_9_2_3:1.3
	HELM_PEER_PORT_BRANCH:1.8.0.2
	TURBINE_PEER:1.8
	TIGRIS_0_9_2_1:1.8
	TIGRIS_0_9_2:1.3.0.4
	TIGRIS_0_9_0:1.3.0.2
	TIGRIS_0_8_4:1.2.0.2;
locks; strict;
comment	@# @;


1.9
date	2001.02.21.03.23.56;	author edk;	state dead;
branches;
next	1.8;

1.8
date	2001.01.26.18.29.00;	author edk;	state Exp;
branches
	1.8.2.1;
next	1.7;

1.7
date	2001.01.26.05.24.05;	author edk;	state dead;
branches;
next	1.6;

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

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

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

1.3
date	2000.12.12.08.55.12;	author edk;	state Exp;
branches;
next	1.2;

1.2
date	2000.11.22.01.51.08;	author edk;	state Exp;
branches;
next	1.1;

1.1
date	2000.11.13.21.16.52;	author edk;	state Exp;
branches;
next	;

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


desc
@@


1.9
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 COLLAB.NET 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.util.*;
import java.sql.*;

import org.webmacro.util.Log;

import com.workingdogs.village.*;

import org.joist.database.*;
import org.tigris.helm.DoesNotExist;

/**
 * Manages the invitation table (for projects)
 *
 * @@author <a href="mailto:edk@@collab.net">Ed Korthof</a>
 * @@version $Id: InvitationManager.java,v 1.8 2001/01/26 18:29:00 edk Exp $
 *
 * Copyright (c) 2000 CollabNet, Inc.
 */

public class InvitationManager extends TableManager
{
    /**
     * The name of the database table that this <code>TableManager</code> 
     * manages.
     */
    public static final String TABLE_NAME = "HELM_INVITATION";

    /**
     * The primary database key field.
     */
    public static final String ID = "INVITATION_ID";

    /**
     * The field which contains the invitation itself.
     */
    public static final String TICKET = "TICKET";

    /**
     * The field which contains the project ID
     */
    public static final String PROJECT_ID = "PROJECT_ID";

    /**
     * The logger instance for all instances of this class.
     */
    private static Log log = new Log("invtMgr", "InvitationManager");

    /**
     * Whether we want debugging information.
     */
    private static boolean debug = true;

    /**
     * Creates a new instance.
     *
     * @@param dataMgr The manager of this instance.
     */
    public InvitationManager(DataManager dataMgr)
    {
        super(dataMgr);
    }

    public Record createRecord(Connection conn) 
        throws DataSetException, SQLException
    {
        TableDataSet invitations = null;
        try {
            invitations = new TableDataSet(conn, TABLE_NAME,
                    new KeyDef().addAttrib(ID));
            return invitations.addRecord();
        } finally {  // even if we catch the exceptions, we can't add much info
            registerToClose(invitations);
        }
    }

    /**
     * Adds a new invitation to the database
     *
     * @@param connection  The JDBC database connection to use.
     * @@param invitation  A village Record containing the invitation to add
     *
     * @@exception	JoistDatabaseException
     */
    public void addInvitation (Connection connection, Record invitation)
	throws JoistDatabaseException
    {
        try
        {
            invitation.save();
            invitation.setValue(ID,
                    getLastInsertedID(connection).toString());
        }
	catch (DataSetException e)
	{
	    log.exception(e);
	    String message = "Adding  " + e.getMessage();
	    if (debug) log.debug(message);
	    throw new JoistDatabaseException("unable to add new Invitation");
	}
	catch (SQLException e)
	{
	    log.exception(e);
	    String message = "Adding  " + e.getMessage();
	    if (debug) log.debug(message);
	    throw new JoistDatabaseException("unable to add new Invitation");
	}
    }

    public Record getInvitation(Connection connection, String ticket) 
        throws DoesNotExist
    {
        Record invitation = null;
        if (ticket == null || ticket.equals(""))
            throw new DoesNotExist("no ticket provided");

        TableDataSet invitations = null;
	try
	{
	    invitations = new TableDataSet(connection, TABLE_NAME, 
                    new KeyDef().addAttrib(ID));
            StringBuffer whereClause = new StringBuffer();
            whereClause.append(TICKET).append("='").append(ticket).append('\'');
            invitations.where(whereClause.toString());

            // Do update.
            invitations.fetchRecords();
	    if (invitations.containsRecord(0)) 
	    {
                return invitations.getRecord(0);
            }
            if (debug) log.info("unable to find invite");
            throw new DoesNotExist("no invitation found");
        }
        catch (DoesNotExist e)
        {
            throw e;
        }
        catch (Exception e) 
        {
            log.exception(e);
            if (debug) log.info("unable to find invite: " + e.getMessage());
            throw new DoesNotExist("unable to find invite: " + e.getMessage());
        }

	finally
	{
	    if (invitations != null) registerToClose(invitations);
	}
    }

    /**
     * Deletes an existing invitation from the database
     *
     * @@param	  connection    The JDBC database connection
     * @@param	  invitation    A village Record with the invitation to delete
     * @@exception SQLException
     */
    public void  deleteInvitation (Connection connection, Record invitation)
	throws JoistDatabaseException
    {
	try
	{
            invitation.markToBeDeleted();
            invitation.save();
	}
	catch (DataSetException e)
	{
	    log.exception(e);
	    if (debug) log.debug("Deleting Invitation: " + e.getMessage());
	    throw new JoistDatabaseException("unable to delete invitation: " +
                    e.getMessage());
	}
	catch (SQLException e)
	{
	    log.exception(e);
	    if (debug) log.debug("Deleting Invitation: " + e.getMessage());
	    throw new JoistDatabaseException("unable to delete invitation: " +
                    e.getMessage());
	}
    }
}


@


1.8
log
@readding all the files as part of the process of returning to the way
things were as of tuesday
@
text
@d62 1
a62 1
 * @@version $Id: InvitationManager.java,v 1.3 2000/12/12 08:55:12 edk Exp $
@


1.8.2.1
log
@Porting to the Turbine Peer system.  -dlr and leonardr
@
text
@d62 1
a62 1
 * @@version $Id: InvitationManager.java,v 1.8 2001/01/26 18:29:00 edk Exp $
@


1.7
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
@d32 1
a32 1
 * IN NO EVENT SHALL COLLABNET OR ITS CONTRIBUTORS BE LIABLE FOR ANY
d55 1
a55 7
import org.apache.turbine.services.db.TurbineDB;
import org.apache.turbine.util.db.pool.DBConnection;

import org.joist.database.Criterion;
import org.joist.database.DataManager;
import org.joist.database.TableManager;

d62 1
a62 1
 * @@version $Id: InvitationManager.java,v 1.6 2001/01/24 22:24:36 leonardr Exp $
d99 1
a99 1
    
d107 1
a107 1
        super(dataMgr, new KeyDef().addAttrib(ID));
d110 2
a111 13
    ////////////////////////////////////////////////////////////////
    // Accessor methods
    ////////////////////////////////////////////////////////////////

    /**
     * Retrieves an invitation by ticket string.
     *
     * @@return The new record.
     * @@exception	DBException if a problem with the database occurs.
     * @@exception	DoesNotExist if the ticket is invalid.
     */
    public Record getInvitation(String ticket) 
        throws DBException, DoesNotExist
a112 41
        if (ticket == null || ticket.equals(""))
            throw new DBException("No ticket provided.");

        DataSet invitations = null;
        Record invitation = null;

        Criterion criterion = new Criterion(TICKET, ticket);
        try {
            invitations = runSelect(TABLE_NAME, criterion);
        } catch (Exception e) {
            throw new DBException(e);
        }

        if (invitations != null && invitations.containsRecord(0))
        {
            try {
                invitation  = invitations.getRecord(0);
            } catch (DataSetException e) {
                throw new DBException(e);
            }
        } else {
            throw new DoesNotExist("Invitation with ticket " + ticket);
        }

        return invitation;
    }

    ////////////////////////////////////////////////////////////////
    // Mutator methods.
    ////////////////////////////////////////////////////////////////

    /**
     * Creates and returns a new record in the invitation table.
     *
     * @@return The new record.
     * @@exception	DBException if a problem with the database occurs.
     */
    public Record createRecord() 
        throws DBException
    {
        DBConnection dbConn = null;
a113 1
        Record r = null;
d115 4
a118 12
            dbConn = TurbineDB.getConnection();
            Connection connection = dbConn.getConnection();           
            invitations = new TableDataSet(connection, TABLE_NAME, keydef);
            r = invitations.addRecord();
        } catch (Exception e) {
            throw new DBException(e);
        } finally {
            try {
                TurbineDB.releaseConnection(dbConn);
            } catch (Exception e) {
                throw new DBException(e);
            }
a120 1
        return r;
d124 1
a124 1
     * Saves a new invitation record to the database
d126 2
a127 1
     * @@param invitation  A village Record containing the invitation to save
d129 1
a129 1
     * @@exception	DBException if a problem with the database occurs.
d132 1
a132 1
	throws DBException
d137 58
a194 5
            invitation.setValue(ID, getLastInsertedID(connection).toString());
        } catch (DataSetException e) {
	    throw new DBException(e);
	} catch (SQLException e) {
	    throw new DBException(e);
d201 1
d203 1
a203 1
     * @@exception	DBException if a problem with the database occurs.
d205 2
a206 2
    public void  deleteInvitation (Record invitation)
	throws DBException
d212 14
a225 4
	} catch (DataSetException e) {
            throw new DBException(e);
	} catch (SQLException e) {
            throw new DBException(e);
d229 2
@


1.6
log
@Moved TableManagers to new keydef constructor and keydef-less runSelect.
@
text
@d68 1
a68 1
 * @@version $Id: InvitationManager.java,v 1.5 2001/01/24 21:41:48 leonardr Exp $
@


1.5
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
@d68 1
a68 1
 * @@version $Id: InvitationManager.java,v 1.4 2001/01/24 20:42:46 dlr Exp $
a96 5
     * A KeyDef object appropriate for this table.
     */
    public static KeyDef keydef = new KeyDef().addAttrib(ID);    

    /**
d113 1
a113 1
        super(dataMgr);
d138 1
a138 1
            invitations = runSelect(TABLE_NAME, keydef, criterion);
@


1.4
log
@Making use of DBException.
@
text
@d32 1
a32 1
 * IN NO EVENT SHALL COLLAB.NET OR ITS CONTRIBUTORS BE LIABLE FOR ANY
d55 7
a61 1
import org.joist.database.*;
d68 1
a68 1
 * @@version $Id: InvitationManager.java,v 1.3 2000/12/12 08:55:12 edk Exp $
d97 5
d110 1
a110 1

d121 52
a172 1
    public Record createRecord(Connection conn) 
d175 1
d177 1
d179 5
a183 5
            invitations = new TableDataSet(conn, TABLE_NAME,
                    new KeyDef().addAttrib(ID));
            return invitations.addRecord();
        }
        catch (DataSetException e) {
d185 6
a190 2
        }
        finally {
d193 1
d197 1
a197 1
     * Adds a new invitation to the database
d199 1
a199 2
     * @@param connection  The JDBC database connection to use.
     * @@param invitation  A village Record containing the invitation to add
d201 1
a201 1
     * @@exception	JoistDatabaseException
d209 5
a213 52
            invitation.setValue(ID,
                    getLastInsertedID(connection).toString());
        }
	catch (DataSetException e)
	{
	    throw new DBException("unable to add new Invitation", e);
	}
	catch (SQLException e)
	{
	    throw new DBException("unable to add new Invitation", e);
	}
    }

    public Record getInvitation(Connection connection, String ticket) 
        throws DoesNotExist
    {
        Record invitation = null;
        if (ticket == null || ticket.equals(""))
            throw new DoesNotExist("no ticket provided");

        TableDataSet invitations = null;
	try
	{
	    invitations = new TableDataSet(connection, TABLE_NAME, 
                    new KeyDef().addAttrib(ID));
            StringBuffer whereClause = new StringBuffer();
            whereClause.append(TICKET).append("='").append(ticket).append('\'');
            invitations.where(whereClause.toString());

            // Do update.
            invitations.fetchRecords();
	    if (invitations.containsRecord(0)) 
	    {
                return invitations.getRecord(0);
            }
            if (debug) log.info("unable to find invite");
            throw new DoesNotExist("no invitation found");
        }
        catch (DoesNotExist e)
        {
            throw e;
        }
        catch (Exception e) 
        {
            log.exception(e);
            if (debug) log.info("unable to find invite: " + e.getMessage());
            throw new DoesNotExist("unable to find invite: " + e.getMessage());
        }

	finally
	{
	    if (invitations != null) registerToClose(invitations);
a219 1
     * @@param	  connection    The JDBC database connection
d221 1
a221 1
     * @@exception SQLException
d223 1
a223 1
    public void  deleteInvitation (Connection connection, Record invitation)
d230 4
a233 8
	}
	catch (DataSetException e)
	{
	    throw new DBException("unable to delete invitation", e);
	}
	catch (SQLException e)
	{
	    throw new DBException("unable to delete invitation", e);
@


1.3
log
@quote ticket value explicitly
@
text
@d62 1
a62 1
 * @@version $Id: InvitationManager.java,v 1.2 2000/11/22 01:51:08 edk Exp $
d111 1
a111 1
        throws DataSetException, SQLException
d118 5
a122 1
        } finally {  // even if we catch the exceptions, we can't add much info
d136 1
a136 1
	throws JoistDatabaseException
d146 1
a146 4
	    log.exception(e);
	    String message = "Adding  " + e.getMessage();
	    if (debug) log.debug(message);
	    throw new JoistDatabaseException("unable to add new Invitation");
d150 1
a150 4
	    log.exception(e);
	    String message = "Adding  " + e.getMessage();
	    if (debug) log.debug(message);
	    throw new JoistDatabaseException("unable to add new Invitation");
d204 1
a204 1
	throws JoistDatabaseException
d213 1
a213 4
	    log.exception(e);
	    if (debug) log.debug("Deleting Invitation: " + e.getMessage());
	    throw new JoistDatabaseException("unable to delete invitation: " +
                    e.getMessage());
d217 1
a217 4
	    log.exception(e);
	    if (debug) log.debug("Deleting Invitation: " + e.getMessage());
	    throw new JoistDatabaseException("unable to delete invitation: " +
                    e.getMessage());
a220 2


@


1.2
log
@new invitations stuff : if you have a valid ticket, you can request
roles, even if the project is private and you have none so far.
@
text
@d62 1
a62 1
 * @@version $Id: InvitationManager.java,v 1.1 2000/11/13 21:16:52 edk Exp $
d169 1
a169 1
            whereClause.append(TICKET).append('=').append(ticket);
@


1.1
log
@send out invitations with nonces during SSPAS2 (soon to be renamed)
@
text
@a51 1
//import org.webmacro.servlet.*;
d56 1
a56 1
//import org.joist.util.*;
d62 1
a62 1
 * @@version $Id: InvitationManager.java,v 1.1 2000/11/13 16:47:09 edk Exp $
d83 1
a83 1
    public static final String NONCE = "NONCE";
d156 2
a157 2
    public boolean checkInvitation (Connection connection, String nonce,
            String projectID) throws SQLException, DataSetException
d159 3
a161 2
	Record invitation = null;
        if (nonce == null || nonce.equals("")) return false;
d166 2
a167 2
            // Prep for update.
	    invitations = new TableDataSet(connection, TABLE_NAME);
d169 1
a169 6
            whereClause.append(NONCE).append('=').append(nonce);
            if (projectID != null)
            {
                whereClause.append(" and ").append(PROJECT_ID).
                    append('=').append(projectID);
            }
d176 1
a176 1
                return true;
d178 6
a183 1
            return false;
d185 7
@

