/*
 * The Gemma project.
 * 
 * Copyright (c) 2006 University of British Columbia
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */
package edu.columbia.gemma.common.auditAndSecurity;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * @see edu.columbia.gemma.common.auditAndSecurity.AuditTrailService
 * @author pavlidis
 * @version $Id$
 */
public class AuditTrailServiceImpl extends edu.columbia.gemma.common.auditAndSecurity.AuditTrailServiceBase {

    private static Log log = LogFactory.getLog( AuditTrailServiceImpl.class.getName() );

    /**
     * @see edu.columbia.gemma.common.auditAndSecurity.AuditTrailService#audit(edu.columbia.gemma.common.Describable,
     *      edu.columbia.gemma.common.auditAndSecurity.AuditEvent)
     */
    @Override
    protected void handleAudit( edu.columbia.gemma.common.Describable entity,
            edu.columbia.gemma.common.auditAndSecurity.AuditEvent auditEvent ) throws java.lang.Exception {

        if ( entity == null || entity.getId() == null ) return;

        AuditTrail at = entity.getAuditTrail();
        if ( at == null ) {
            at = AuditTrail.Factory.newInstance();
            at.start(); // uh-oh, have to update the entity. Hard to do from here.
            if ( auditEvent != null ) at.addEvent( auditEvent ); // should we do that? I guess so.
            this.getAuditTrailDao().create( at );
            log.warn( "Creating new audit trail for " + entity );
        } else {
            if ( auditEvent == null ) throw new IllegalArgumentException( "auditEvent cannot be null" );
            at.addEvent( auditEvent );
            this.getAuditTrailDao().update( at );
            log.debug( "Added event " + auditEvent.getAction() + " to " + entity );
        }
    }

    /**
     * @param auditTrail
     * @return
     */
    @Override
    protected AuditTrail handleCreate( AuditTrail auditTrail ) {
        return this.getAuditTrailDao().create( auditTrail );
    }

}
@@ -782,16 +782,61 @@
 ctory;%0A%0A
+import edu.columbia.gemma.common.Auditable;%0A%0A
 /**%0A * @
@@ -1393,65 +1393,25 @@
 it( 
-edu.columbia.gemma.common.Describable entity,%0A           
+Auditable entity,
  edu
@@ -1473,16 +1473,28 @@
 tEvent )
+%0A           
  throws 

use Auditable instead of Describable