head	1.13;
access;
symbols
	TIGRIS_0_9_2_4:1.7
	TIGRIS_0_9_2_3:1.7
	HELM_PEER_PORT_BRANCH:1.12.0.2
	TURBINE_PEER:1.12
	TIGRIS_0_9_2_1:1.12
	TIGRIS_0_9_2:1.7.0.2
	TIGRIS_0_9_0:1.5.0.2;
locks; strict;
comment	@# @;


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

1.12
date	2001.01.26.18.29.00;	author edk;	state Exp;
branches
	1.12.2.1;
next	1.11;

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

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

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

1.8
date	2001.01.24.20.42.46;	author dlr;	state Exp;
branches;
next	1.7;

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

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

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

1.4
date	2000.12.13.22.44.23;	author leonardr;	state Exp;
branches;
next	1.3;

1.3
date	2000.12.13.22.05.13;	author leonardr;	state Exp;
branches;
next	1.2;

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

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

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


desc
@@


1.13
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.apache.turbine.services.db.TurbineDB;
import org.apache.turbine.util.db.pool.DBConnection;

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

import com.workingdogs.village.*;

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

/**
 * Manages the entry table.
 *
 * @@author <a href="mailto:leonardr@@collab.net">Leonard Richardson</a>
 * @@version $Id: AuditLogEntryManager.java,v 1.12 2001/01/26 18:29:00 edk Exp $
 *
 * Copyright (c) 2000 CollabNet, Inc.  
 */

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

    public static final String HOST_TYPE = "Host";   
    public static final String DOMAIN_TYPE = "Domain";   
    public static final String PROJECT_TYPE = "Project";   

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

    /**
     * The time at which the entry was put into the database.
     */
    public static final String TIMESTAMP = "TIMESTAMP";   

    /**
     * Type of the Helm component affected by this log entry.
     */
    public static final String AFFECTED_TYPE = "AFFECTED_TYPE";   

    /**
     * ID of the Helm component affected by this log entry.
     */
    public static final String AFFECTED_OBJECT_ID  = "AFFECTED_ID";   

    /**
     * UserID of the user who triggered this log entry.
     */
    public static final String INITIATING_USER = "INITIATING_USER";   

    /**
     * What happened.
     */
    public static final String DESCRIPTION = "DESCRIPTION";   

    /**
     * Explanation of why the action was triggered.
     */
    public static final String RATIONALE = "RATIONALE";   

    /**
     * The logger instance for all instances of this class.
     */
    private static Log log = new Log("AuditLog", "AuditLogEntryManager");
    
    /**
     * Whether we want debugging information.
     */
    private static boolean debug = true;
    
    /**
     * Creates a new instance.
     *
     * @@param dataMgr The manager of this instance.
     */
    public AuditLogEntryManager(DataManager dataMgr)
    {
        super(dataMgr);
    }    

    /**
     * Logs a new audit log entry.
     *
     * @@param connection    The JDBC database connection to use
     * @@param      The ID for the list's project
     * @@param name          The name for the list
     * @@param description   A short description of the list
     * @@param type          The type of the list
     *
     * @@exception SQLException
     * @@exception DataSetException
     */
    public Record addAuditLogEntry(Connection connection, String affectedType, 
                                   String affectedObjectID,
                                   String initiatingUser, String description)
        throws DataSetException, SQLException
    {
        String action = "Logging entry";
        log.info(action + ": " + description);
        TableDataSet entries = null;
        Record entry = null;
        try {            
            entries = new TableDataSet(connection, TABLE_NAME, 
                                       new KeyDef().addAttrib(ENTRY_ID));
            entry = entries.addRecord();
            if (affectedType != null) 
                entry.setValue (AFFECTED_TYPE, affectedType);

            if (affectedObjectID != null) 
                entry.setValue (AFFECTED_OBJECT_ID,affectedObjectID);

            if (initiatingUser != null) 
                entry.setValue(INITIATING_USER, initiatingUser);

            if (description != null) 
                entry.setValue(DESCRIPTION, description);

            entry.setValue(RATIONALE, "");
            
            entry.save();
            // NOTE: There is no way to refresh a Village Record which has
            // been created using TableDataSet.addRecord().
            String entryID = getLastInsertedID(connection).toString();
            entry.setValue(ENTRY_ID, entryID);
        } catch (DataSetException e) {
            log.exception(e);
            if (debug) log.debug(action + ": " + e.getMessage());
            throw e;
        } catch (SQLException e) {
            log.exception(e);
            if (debug) log.debug(action + ": " + e.getMessage());
            throw e;
        } finally {
            registerToClose(entries);
        }
        
        return entry;
    }

    /**
     * Adds to the rationale field of the given entry.
     *
     * @@param connection    The JDBC database connection to use
     * @@param entryID       The entry to whose rationale we are appending.
     * @@param rationale     The new addition to the rationale field.
     *
     * @@return The revised Record for the entry.
     *
     * @@exception SQLException
     * @@exception DataSetException
     */
    public Record appendToRationale(Connection connection, String entryID,
                                    String newRationale)
        throws DataSetException, SQLException
    {
        Record entry = getEntry(connection, entryID);
        String oldRationale = entry.getValue(RATIONALE).asString();
        if (oldRationale==null) oldRationale = "";
        StringBuffer rationale = new StringBuffer(oldRationale);
        if (!oldRationale.equals(""))
        {
            rationale.append("\n<hr>\n");
        }
        rationale.append(newRationale);
        entry.setValue(RATIONALE, rationale.toString());
        entry.save();
        return entry;
    }

    public String getAuditLogEntriesQuery()
    {
        return "SELECT * FROM " + TABLE_NAME;
    }

    /**
     * Returns a particular entry.
     *
     * @@param	connection    A JDBC database connection
     * @@param   entryID       The log entry to get.
     * @@return	a Record for the log entry
     * @@exception	SQLException
     * @@exception	DataSetException
     */
    public Record getEntry(Connection connection, String entryID)
	throws SQLException, DataSetException
    {        
        DataSet entries =
            getAuditLogEntries(connection, entryID, null, null, null, null);
        if (!(entries.size() > 0))
        {
            throw new DataSetException("No such log entry " + entryID);
        }
        return entries.getRecord(0);
    }

    /**
     * Returns the full log.
     *
     * @@param	connection    A JDBC database connection
     * @@return	a DataSet containing the log
     * @@exception	SQLException
     * @@exception	DataSetException
     */
    public DataSet getAuditLogEntries(Connection connection)
	throws SQLException, DataSetException
    {        
        return getAuditLogEntries(connection, null, null, null, null, null);
    }

    /**
     * Returns the log for the host.
     *
     * @@param	connection    A JDBC database connection
     * @@return	a DataSet containing the log
     * @@exception	SQLException
     * @@exception	DataSetException
     */
    public DataSet getAuditLogEntriesForHost(Connection connection)
	throws SQLException, DataSetException
    {        
        return getAuditLogEntries(connection, null, HOST_TYPE, null, null, null);
    }

    /**
     * Returns the log for a particular domain.
     *
     * @@param	connection    A JDBC database connection
     * @@param	domainID      ID of the domain to get entries for
     * @@return	a DataSet containing the log
     * @@exception	SQLException
     * @@exception	DataSetException
     */
    public DataSet getAuditLogEntriesForDomain
        (Connection connection, String domainID)
	throws SQLException, DataSetException
    {        
        return getAuditLogEntries(connection, null, DOMAIN_TYPE, domainID, 
                                  null, null);
    }

    /**
     * Gets a entry by ID.
     *
     * @@param	connection    A JDBC database connection
     * @@param	entryID     The ID to get a record for
     * @@return	 a String
     * @@exception	SQLException
     * @@exception	DataSetException
     */
    public Record getAuditLogEntryByID (Connection connection, String entryID)
	throws SQLException, DataSetException
    {        
        DataSet entries = getAuditLogEntries(connection, entryID, 
                                             null, null, null, null);        
        if (entries.size() == 0)
        {
            throw new DataSetException("No such entry " + entryID);
        }
        return entries.getRecord(0);
    }

    /**
     * Retrieves entries by any of the relevant fields.
     *
     * @@param	connection       A JDBC database connection
     * @@param   entryID          An entry ID
     * @@param   type             Type of object affected.
     * @@param   affectedObjectID ID of object affected.
     * @@param   description      Partial description of entries to retrieve. 
     *                           This will be used in an SQL LIKE clause.
     * @@return	 a DataSet
     * @@exception	SQLException
     * @@exception	DataSetException
     */
    private TableDataSet getAuditLogEntries 
        (Connection connection, String entryID, String type, 
         String affectedObjectID, String initiatingUser, String description)
        throws SQLException, DataSetException
    {
        TableDataSet entries = null;
        try {
            entries = new TableDataSet(connection, TABLE_NAME,
                                       new KeyDef().addAttrib(ENTRY_ID));
            entries.where(buildWhereClause(entryID, type, affectedObjectID,
                                           initiatingUser, description));
            entries.order(TIMESTAMP + " DESC, " + ENTRY_ID + " DESC");
            entries.fetchRecords();
	}
	catch (DataSetException e)
	{
	    log.exception(e);
	    throw e;
	}
	catch (SQLException e)
	{
	    log.exception(e);
	    throw e;
	}
	finally
	{
	    registerToClose(entries);
	}
        return entries;
    }

    /**
     * Creates a SQL <code>where</code> clause.
     */
    protected static String buildWhereClause 
        (String entryID, String type, String affectedObjectID, 
         String initiatingUser, String description)
    {
        StringBuffer whereClause = new StringBuffer();
        boolean firstClause = true;

        if (entryID != null)
        {
            whereClause.append(ENTRY_ID).append('=').append(entryID);
            firstClause = false;
        }

        if (type != null)
        {
            if (!firstClause)
            {
                whereClause.append(" AND ");
            }
            whereClause.append(AFFECTED_TYPE).append('=')
                .append(escapeAndQuoteSQL(type));
            firstClause = false;
        }

        if (affectedObjectID != null)
        {
            if (!firstClause)
            {
                whereClause.append(" AND ");
            }
            whereClause.append(affectedObjectID).append('=')
                .append(affectedObjectID);
            firstClause = false;
        }
        
        if (initiatingUser != null)
        {
            if (!firstClause)
            {
                whereClause.append(" AND ");
            }
            whereClause.append(INITIATING_USER).append('=')
                .append(initiatingUser);
            firstClause = false;
        }

        if (description != null)
        {
            if (!firstClause)
            {
                whereClause.append(" AND ");
            }
            whereClause.append(DESCRIPTION).append(" LIKE ")
                .append("%" + escapeAndQuoteSQL(description) + "%");
            firstClause = false;
        }

        return whereClause.toString();
    }

}
@


1.12
log
@readding all the files as part of the process of returning to the way
things were as of tuesday
@
text
@d66 1
a66 1
 * @@version $Id: AuditLogEntryManager.java,v 1.7 2001/01/05 01:10:55 dlr Exp $
@


1.12.2.1
log
@Porting to the Turbine Peer system.  -dlr and leonardr
@
text
@d66 1
a66 1
 * @@version $Id: AuditLogEntryManager.java,v 1.12 2001/01/26 18:29:00 edk Exp $
@


1.11
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
d59 1
a59 3
import org.joist.database.Criterion;
import org.joist.database.DataManager;
import org.joist.database.TableManager;
a61 2
import org.tigris.helm.DoesNotExist;

d63 1
a63 1
 * Manages the audit log entry table.
d66 1
a66 1
 * @@version $Id: AuditLogEntryManager.java,v 1.10 2001/01/24 22:24:36 leonardr Exp $
d68 1
a68 1
 * Copyright (c) 2000-2001 CollabNet, Inc.  
a118 7
     * The default ordering of records from this table.
     */
    public static final String DEFAULT_ORDER_BY  =  
        TABLE_NAME + "." + TIMESTAMP + " DESC, " + TABLE_NAME + "." 
        + ENTRY_ID + " DESC";

    /**
d135 1
a135 1
        super(dataMgr, new KeyDef().addAttrib(ENTRY_ID));
d139 66
a204 1
     * Returns a SQL query which selectes from this table.
d206 2
a207 1
     * @@exception DBException
d209 18
a231 4
    ////////////////////////////////////////////////////////////////
    // Accessor methods.
    ////////////////////////////////////////////////////////////////

d233 1
a233 1
     * Gets a entry by ID.
d235 5
a239 4
     * @@param	entryID     The ID to get a record for
     * @@return	 a String
     * @@exception	DBException if a database error occurs.
     * @@exception	DoesNotExist if the entryID is invalid.
d241 6
a246 5
    public Record getEntry(String entryID)
	throws DBException, DoesNotExist
    {                
        Record entry = getFirstMatchingEntry(new Criterion(ENTRY_ID, entryID));
        if (entry == null)
d248 1
a248 1
            throw new DoesNotExist("Entry with ID " + entryID);
d250 1
a250 1
        return entry;
d256 1
d258 2
a259 1
     * @@exception	DBException if a database error occurs.
d261 2
a262 2
    public DataSet getAuditLogEntries()
	throws DBException
d264 1
a264 1
        return getAuditLogEntries(null);
d270 1
d272 2
a273 2
     *
     * @@exception	DBException if a database error occurs.
d275 2
a276 2
    public DataSet getAuditLogEntriesForHost()
	throws DBException
d278 1
a278 1
        return getAuditLogEntries(new Criterion(AFFECTED_TYPE, HOST_TYPE));
d284 1
d287 2
a288 1
     * @@exception	DBException if a database error occurs.
d290 3
a292 2
    public DataSet getAuditLogEntriesForDomain(String domainID)
	throws DBException
d294 2
a295 3
        Criterion c = new Criterion(AFFECTED_TYPE, DOMAIN_TYPE);
        c.and(new Criterion(AFFECTED_OBJECT_ID, domainID));
        return getAuditLogEntries(c);
d299 1
a299 1
     * Returns the first log entry matching a given Criterion. 
d301 5
a305 5
     * @@param criterion Criterion to use in select.
     *
     * @@exception DBException if a database error occurs.
     *
     * @@return Null if no matching entry, first entry in recordset otherwise.
d307 8
a314 12
    private Record getFirstMatchingEntry(Criterion criterion)
        throws DBException
    {
        Record entry = null;
        try {
            DataSet entries = getAuditLogEntries(criterion);
            if (entries != null && entries.containsRecord(0))
            {
                entry = entries.getRecord(0);
            }
        } catch (DataSetException e) {
            throw new DBException(e);
d316 1
a316 1
        return entry;
d320 1
a320 1
     * Retrieves entries that match a given Criterion
d322 14
a335 6
     * @@param	criterion  The Criterion to use for matching.
     * @@return	           a DataSet containing all matching entries
     * @@exception	   DBException if a database error occurs.
     */
    private DataSet getAuditLogEntries (Criterion criterion)
        throws DBException
d337 1
a337 1
        DataSet s = null;
d339 22
a360 5
            s = runSelect(TABLE_NAME, criterion, DEFAULT_ORDER_BY);
        } catch (Exception e) {
            throw new DBException(e);
        }
        return s;
a362 4
    ////////////////////////////////////////////////////////////////
    // Mutator methods.
    ////////////////////////////////////////////////////////////////

d364 1
a364 8
     * Logs a new audit log entry.
     *
     * @@param affectedType   Type of object affected
     * @@param affectedType   ID of object affected
     * @@param initiatingUser User who caused this item to be logged
     * @@param description    Description of what occured
     *
     * @@exception DBException if a database error occurs.
d366 2
a367 2
    public Record addAuditLogEntry
        (String affectedType, String affectedObjectID,
a368 1
        throws DBException
d370 2
a371 3
        DBConnection dbConn = null;
        Record entry = null;
        TableDataSet entries = null;
d373 1
a373 1
        try
d375 3
a377 2
            dbConn = TurbineDB.getConnection();
            Connection connection = dbConn.getConnection();           
d379 10
a388 2
            entries = new TableDataSet(connection, TABLE_NAME, keydef);
            entry = entries.addRecord();
d390 5
a394 28
            if (affectedType != null) 
                entry.setValue (AFFECTED_TYPE, affectedType);
            
            if (affectedObjectID != null) 
                entry.setValue (AFFECTED_OBJECT_ID,affectedObjectID);

            if (initiatingUser != null) 
                entry.setValue(INITIATING_USER, initiatingUser);

            if (description != null) 
                entry.setValue(DESCRIPTION, description);

            entry.setValue(RATIONALE, "");
            
            entry.save();

            // NOTE: There is no way to refresh a Village Record which has
            // been created using TableDataSet.addRecord().
            String entryID = getLastInsertedID(connection).toString();
            entry.setValue(ENTRY_ID, entryID);

        } catch (Exception e) {
            throw new DBException(e);
        } finally {
            try {
                TurbineDB.releaseConnection(dbConn);
            } catch (Exception e) {
                throw new DBException(e);
d396 3
a398 1
            registerToClose(entries);
d401 10
a410 2
        return entry;
    }
d412 3
a414 20
    /**
     * Adds to the rationale field of the given entry.
     *
     * @@param connection    The JDBC database connection to use
     * @@param entryID       The entry to whose rationale we are appending.
     * @@param rationale     The new addition to the rationale field.
     *
     * @@return The revised Record for the entry.
     *
     * @@exception DBException if a database error occurs.
     */
    public Record appendToRationale(String entryID, String newRationale)
        throws DBException, DoesNotExist
    {
        Record entry = getEntry(entryID);
        try {
            String oldRationale = entry.getValue(RATIONALE).asString();
            if (oldRationale==null) oldRationale = "";
            StringBuffer rationale = new StringBuffer(oldRationale);
            if (!oldRationale.equals(""))
d416 1
a416 1
                rationale.append("\n<hr>\n");
d418 3
a420 7
            rationale.append(newRationale);
            entry.setValue(RATIONALE, rationale.toString());
            entry.save();
        } catch (DataSetException e) {
            throw new DBException(e);
        } catch (SQLException e) {
            throw new DBException(e);
d422 2
a423 1
        return entry;
d425 1
@


1.10
log
@Moved TableManagers to new keydef constructor and keydef-less runSelect.
@
text
@d70 1
a70 1
 * @@version $Id: AuditLogEntryManager.java,v 1.9 2001/01/24 21:41:48 leonardr Exp $
@


1.9
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
@d70 1
a70 1
 * @@version $Id: AuditLogEntryManager.java,v 1.8 2001/01/24 20:42:46 dlr Exp $
d146 1
a146 1
        super(dataMgr);
a149 5
     * The KeyDef object appropriate for this table.
     */
    private KeyDef keydef = new KeyDef().addAttrib(ENTRY_ID);

    /**
d259 1
a259 1
            s = runSelect(TABLE_NAME, keydef, criterion, DEFAULT_ORDER_BY);
d294 1
a294 1
            entries = new TableDataSet(connection, TABLE_NAME, keydef());
@


1.8
log
@Making use of DBException.
@
text
@d32 1
a32 1
 * IN NO EVENT SHALL COLLAB.NET OR ITS CONTRIBUTORS BE LIABLE FOR ANY
d59 3
a61 1
import org.joist.database.*;
d64 2
d67 1
a67 1
 * Manages the entry table.
d70 1
a70 1
 * @@version $Id: AuditLogEntryManager.java,v 1.7 2001/01/05 01:10:55 dlr Exp $
d72 1
a72 1
 * Copyright (c) 2000 CollabNet, Inc.  
d123 7
d150 1
a150 9
     * Logs a new audit log entry.
     *
     * @@param connection    The JDBC database connection to use
     * @@param      The ID for the list's project
     * @@param name          The name for the list
     * @@param description   A short description of the list
     * @@param type          The type of the list
     *
     * @@exception DBException
d152 1
a152 42
    public Record addAuditLogEntry(Connection connection, String affectedType, 
                                   String affectedObjectID,
                                   String initiatingUser, String description)
        throws DBException
    {
        String action = "Logging entry";
        log.info(action + ": " + description);
        TableDataSet entries = null;
        Record entry = null;
        try {            
            entries = new TableDataSet(connection, TABLE_NAME, 
                                       new KeyDef().addAttrib(ENTRY_ID));
            entry = entries.addRecord();
            if (affectedType != null) 
                entry.setValue (AFFECTED_TYPE, affectedType);

            if (affectedObjectID != null) 
                entry.setValue (AFFECTED_OBJECT_ID,affectedObjectID);

            if (initiatingUser != null) 
                entry.setValue(INITIATING_USER, initiatingUser);

            if (description != null) 
                entry.setValue(DESCRIPTION, description);

            entry.setValue(RATIONALE, "");
            
            entry.save();
            // NOTE: There is no way to refresh a Village Record which has
            // been created using TableDataSet.addRecord().
            String entryID = getLastInsertedID(connection).toString();
            entry.setValue(ENTRY_ID, entryID);
        } catch (DataSetException e) {
            throw new DBException(e);
        } catch (SQLException e) {
            throw new DBException(e);
        } finally {
            registerToClose(entries);
        }
        
        return entry;
    }
d155 1
a155 7
     * Adds to the rationale field of the given entry.
     *
     * @@param connection    The JDBC database connection to use
     * @@param entryID       The entry to whose rationale we are appending.
     * @@param rationale     The new addition to the rationale field.
     *
     * @@return The revised Record for the entry.
a158 32
    public Record appendToRationale(Connection connection, String entryID,
                                    String newRationale)
        throws DBException
    {
        Record entry = getEntry(connection, entryID);
        try
        {
            String oldRationale = entry.getValue(RATIONALE).asString();
            if (oldRationale==null) oldRationale = "";
            StringBuffer rationale = new StringBuffer(oldRationale);
            if (!oldRationale.equals(""))
            {
                rationale.append("\n<hr>\n");
            }
            rationale.append(newRationale);
            entry.setValue(RATIONALE, rationale.toString());
            entry.save();
        }
        catch (DataSetException e)
        {
            throw new DBException(e);
        }
        catch (SQLException e)
        {
            throw new DBException(e);
        }
        return entry;
    }

    /**
     * HELP: Why on earth is this public?
     */
d164 4
d169 1
a169 1
     * Returns a particular entry.
d171 4
a174 5
     * @@param	connection    A JDBC database connection
     * @@param   entryID       The log entry to get.
     * @@return	a Record for the log entry
     *
     * @@exception DBException
d176 5
a180 7
    public Record getEntry(Connection connection, String entryID)
	throws DBException
    {        
        Record entry = null;
        DataSet entries =
            getAuditLogEntries(connection, entryID, null, null, null, null);
        if (entries.size() > 0)
d182 1
a182 8
            try
            {
                entry = entries.getRecord(0);
            }
            catch (DataSetException e)
            {
                throw new DBException(e);
            }
a189 1
     * @@param	connection    A JDBC database connection
d191 1
a191 2
     *
     * @@exception DBException
d193 1
a193 1
    public DataSet getAuditLogEntries(Connection connection)
d196 1
a196 1
        return getAuditLogEntries(connection, null, null, null, null, null);
a201 1
     * @@param	connection    A JDBC database connection
d204 1
a204 1
     * @@exception DBException
d206 1
a206 1
    public DataSet getAuditLogEntriesForHost(Connection connection)
d209 1
a209 2
        return getAuditLogEntries(connection, null, HOST_TYPE, null, null,
                                  null);
a214 1
     * @@param	connection    A JDBC database connection
d217 1
a217 2
     *
     * @@exception DBException
d219 1
a219 2
    public DataSet getAuditLogEntriesForDomain
        (Connection connection, String domainID)
d222 3
a224 2
        return getAuditLogEntries(connection, null, DOMAIN_TYPE, domainID, 
                                  null, null);
d228 3
a230 1
     * Gets a entry by ID.
d232 1
a232 3
     * @@param	connection    A JDBC database connection
     * @@param	entryID     The ID to get a record for
     * @@return	 a String
d234 1
a234 1
     * @@exception DBException
d236 7
a242 9
    public Record getAuditLogEntryByID (Connection connection, String entryID)
	throws DBException
    {        
        Record r = null;
        DataSet entries = getAuditLogEntries(connection, entryID, 
                                             null, null, null, null);        
        if (entries.size() > 0)
        {
            try
d244 1
a244 5
                r = entries.getRecord(0);
            }
            catch (DataSetException e)
            {
                throw new DBException(e);
d246 2
d249 1
a249 1
        return r;
d253 1
a253 9
     * Retrieves entries by any of the relevant fields.
     *
     * @@param	connection       A JDBC database connection
     * @@param   entryID          An entry ID
     * @@param   type             Type of object affected.
     * @@param   affectedObjectID ID of object affected.
     * @@param   description      Partial description of entries to retrieve. 
     *                           This will be used in an SQL LIKE clause.
     * @@return	 a DataSet
d255 3
a257 1
     * @@exception DBException
d259 1
a259 3
    private TableDataSet getAuditLogEntries 
        (Connection connection, String entryID, String type, 
         String affectedObjectID, String initiatingUser, String description)
d262 1
a262 1
        TableDataSet entries = null;
d264 2
a265 9
            entries = new TableDataSet(connection, TABLE_NAME,
                                       new KeyDef().addAttrib(ENTRY_ID));
            entries.where(buildWhereClause(entryID, type, affectedObjectID,
                                           initiatingUser, description));
            entries.order(TIMESTAMP + " DESC, " + ENTRY_ID + " DESC");
            entries.fetchRecords();
	}
	catch (DataSetException e)
	{
d267 2
a268 10
	}
	catch (SQLException e)
	{
            throw new DBException(e);
	}
	finally
	{
	    registerToClose(entries);
	}
        return entries;
d271 4
d276 8
a283 1
     * Creates a SQL <code>where</code> clause.
d285 2
a286 2
    protected static String buildWhereClause 
        (String entryID, String type, String affectedObjectID, 
d288 1
d290 3
a292 2
        StringBuffer whereClause = new StringBuffer();
        boolean firstClause = true;
d294 1
a294 1
        if (entryID != null)
d296 21
a316 3
            whereClause.append(ENTRY_ID).append('=').append(entryID);
            firstClause = false;
        }
d318 4
a321 10
        if (type != null)
        {
            if (!firstClause)
            {
                whereClause.append(" AND ");
            }
            whereClause.append(AFFECTED_TYPE).append('=')
                .append(escapeAndQuoteSQL(type));
            firstClause = false;
        }
d323 7
a329 5
        if (affectedObjectID != null)
        {
            if (!firstClause)
            {
                whereClause.append(" AND ");
d331 1
a331 3
            whereClause.append(affectedObjectID).append('=')
                .append(affectedObjectID);
            firstClause = false;
d334 2
a335 10
        if (initiatingUser != null)
        {
            if (!firstClause)
            {
                whereClause.append(" AND ");
            }
            whereClause.append(INITIATING_USER).append('=')
                .append(initiatingUser);
            firstClause = false;
        }
d337 20
a356 3
        if (description != null)
        {
            if (!firstClause)
d358 1
a358 1
                whereClause.append(" AND ");
d360 7
a366 3
            whereClause.append(DESCRIPTION).append(" LIKE ")
                .append("%" + escapeAndQuoteSQL(description) + "%");
            firstClause = false;
d368 1
a368 2

        return whereClause.toString();
@


1.7
log
@Migrated to latest Turbine CVS to avoid connection release bug (fixed long ago in Turbine CVS--we just had a bunk version).
@
text
@d66 1
a66 1
 * @@version $Id: AuditLogEntryManager.java,v 1.6 2000/12/29 17:11:52 leonardr Exp $
d147 1
a147 2
     * @@exception SQLException
     * @@exception DataSetException
d152 1
a152 1
        throws DataSetException, SQLException
d182 1
a182 3
            log.exception(e);
            if (debug) log.debug(action + ": " + e.getMessage());
            throw e;
d184 1
a184 3
            log.exception(e);
            if (debug) log.debug(action + ": " + e.getMessage());
            throw e;
d201 1
a201 2
     * @@exception SQLException
     * @@exception DataSetException
d205 1
a205 1
        throws DataSetException, SQLException
d208 1
a208 4
        String oldRationale = entry.getValue(RATIONALE).asString();
        if (oldRationale==null) oldRationale = "";
        StringBuffer rationale = new StringBuffer(oldRationale);
        if (!oldRationale.equals(""))
d210 18
a227 1
            rationale.append("\n<hr>\n");
a228 3
        rationale.append(newRationale);
        entry.setValue(RATIONALE, rationale.toString());
        entry.save();
d232 3
d246 2
a247 2
     * @@exception	SQLException
     * @@exception	DataSetException
d250 1
a250 1
	throws SQLException, DataSetException
d252 1
d255 1
a255 1
        if (!(entries.size() > 0))
d257 8
a264 1
            throw new DataSetException("No such log entry " + entryID);
d266 1
a266 1
        return entries.getRecord(0);
d274 2
a275 2
     * @@exception	SQLException
     * @@exception	DataSetException
d278 1
a278 1
	throws SQLException, DataSetException
d288 2
a289 2
     * @@exception	SQLException
     * @@exception	DataSetException
d292 1
a292 1
	throws SQLException, DataSetException
d294 2
a295 1
        return getAuditLogEntries(connection, null, HOST_TYPE, null, null, null);
d304 2
a305 2
     * @@exception	SQLException
     * @@exception	DataSetException
d309 1
a309 1
	throws SQLException, DataSetException
d321 2
a322 2
     * @@exception	SQLException
     * @@exception	DataSetException
d325 1
a325 1
	throws SQLException, DataSetException
d327 1
d330 1
a330 1
        if (entries.size() == 0)
d332 8
a339 1
            throw new DataSetException("No such entry " + entryID);
d341 1
a341 1
        return entries.getRecord(0);
d354 2
a355 2
     * @@exception	SQLException
     * @@exception	DataSetException
d360 1
a360 1
        throws SQLException, DataSetException
d373 1
a373 2
	    log.exception(e);
	    throw e;
d377 1
a377 2
	    log.exception(e);
	    throw e;
a447 1

@


1.6
log
@Many, many pagination changes.
@
text
@d51 1
a51 1
import org.apache.turbine.services.db.PoolBrokerService;
d66 1
a66 1
 * @@version $Id: AuditLogEntryManager.java,v 1.5 2000/12/14 02:28:42 leonardr Exp $
@


1.5
log
@New servlet: AuditLogList
@
text
@d66 1
a66 1
 * @@version $Id: AuditLogEntryManager.java,v 1.4 2000/12/13 22:44:23 leonardr Exp $
d225 5
@


1.4
log
@Rationale append works now.
@
text
@d66 1
a66 1
 * @@version $Id: AuditLogEntryManager.java,v 1.3 2000/12/13 22:05:13 leonardr Exp $
d338 1
a338 1
            entries.order(TIMESTAMP + " ASC, " + ENTRY_ID + " ASC");
@


1.3
log
@More work on AuditEventDetail.
@
text
@d66 1
a66 1
 * @@version $Id: AuditLogEntryManager.java,v 1.2 2000/12/13 02:57:36 leonardr Exp $
d217 5
a221 1
        rationale.append("\n<hr>\n").append(newRationale);
d223 1
@


1.2
log
@Corrected bugs in and wrote first usage of audit logging.
@
text
@d66 1
a66 1
 * @@version $Id: AuditLogEntryManager.java,v 1.1 2000/12/13 02:01:05 leonardr Exp $
d174 2
d214 3
a216 2
        StringBuffer rationale = new StringBuffer
            (entry.getValue(RATIONALE).asString());
@


1.1
log
@Added support for an audit log. Actually getting the log to contain things comes next.
@
text
@d66 1
a66 1
 * @@version $Id: AuditLogEntryManager.java,v 1.4 2000/12/02 01:45:41 leonardr Exp $
d77 1
a77 1
    public static final String TABLE_NAME = "HELM_ENTRY";
d101 1
a101 1
    public static final String AFFECTED_OBJECT_ID  = "AFFECTED_OBJECT_ID";   
@

