head	1.4;
access;
symbols;
locks; strict;
comment	@# @;


1.4
date	2000.12.13.19.07.48;	author leonardr;	state dead;
branches;
next	1.3;

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

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

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


desc
@@


1.4
log
@Moved AuditLog to its own directory, where it will be joined by servlets.
@
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.tool;

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

import org.webmacro.util.Log;

import com.workingdogs.village.*;
import org.joist.database.*;
import org.tigris.helm.business.*;
import org.tigris.helm.DoesNotExist;
import org.tigris.helm.database.AuditLogEntryManager;
import org.tigris.helm.domain.*;
import org.tigris.helm.project.Project;
import org.tigris.helm.security.AccessControlList;

public abstract class AuditLog extends Object
{
    private AuditLogEntryManager tMgr;

    public static Log log = new Log("AuditLog", "Audit Log");

    public static final boolean debug = true;

    public static List getLog(Connection conn, DataManager dMgr,
                              AccessControlList acl, Domain domain)
        throws SQLException, DataSetException
    {
        AuditLogEntryManager aleMgr = (AuditLogEntryManager)dMgr.getManager 
            ("org.tigris.helm.database.AuditLogEntryManager");
        
        ArrayList entries = new ArrayList();
        DataSet entrySet = aleMgr.getAuditLogEntriesForDomain(conn, domain.getID());
        for (int i = 0 ; i < entrySet.size() ; i++)
        {
            Record record = entrySet.getRecord(i);
            AuditLogEntry e = new AuditLogEntry(conn, dMgr, record);
            if (e.isViewable(acl))
            {
                entries.add(e);
            }
        }        
        return entries;
    }


    public static AuditLogEntry logItem
        (Connection conn, DataManager dMgr, User triggeringUser,
         BusinessObject affected, String description)
        throws SQLException, DataSetException
    {
        return logItem(conn, dMgr, triggeringUser.getID(), affected,
                       description);
    }

    public static AuditLogEntry logItem(Connection conn, DataManager dMgr,
                                        String triggeringUserID,
                                        BusinessObject affected,
                                        String description)
        throws SQLException, DataSetException
    {
        String type = AuditLogEntryManager.HOST_TYPE;
        String id = affected.getID();
        if (affected instanceof Domain)
            type = AuditLogEntryManager.DOMAIN_TYPE;
        else if (affected instanceof Project)
            type = AuditLogEntryManager.PROJECT_TYPE;
        AuditLogEntry entry = new AuditLogEntry
            (conn, dMgr, type, id, triggeringUserID, description);
        return entry;
    }
}

@


1.3
log
@Added logging to project deletion.
@
text
@@


1.2
log
@Corrected bugs in and wrote first usage of audit logging.
@
text
@d93 10
@


1.1
log
@Added support for an audit log. Actually getting the log to contain things comes next.
@
text
@d94 1
a94 1
                                        User triggeringUser, Domain domain,
d106 1
a106 1
            (conn, dMgr, type, id, triggeringUser.getID(), description);
@

