001/*
002 * (C) Copyright 2006-2009 Nuxeo SA (http://nuxeo.com/) and others.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 *
016 * Contributors:
017 *     Nuxeo - initial API and implementation
018 *
019 * $Id$
020 */
021
022package org.nuxeo.ecm.platform.audit.listener;
023
024import org.apache.commons.logging.Log;
025import org.apache.commons.logging.LogFactory;
026import org.nuxeo.ecm.core.event.Event;
027import org.nuxeo.ecm.core.event.EventBundle;
028import org.nuxeo.ecm.core.event.PostCommitFilteringEventListener;
029import org.nuxeo.ecm.platform.audit.api.AuditLogger;
030import org.nuxeo.runtime.api.Framework;
031
032/**
033 * PostCommit async listener that pushes {@link EventBundle} into the Audit log.
034 *
035 * @author tiry
036 * @deprecated since 10.10, audit event is now handled with {@link StreamAuditEventListener}
037 */
038@Deprecated
039public class AuditEventLogger implements PostCommitFilteringEventListener {
040
041    private static final Log log = LogFactory.getLog(AuditEventLogger.class);
042
043    @Override
044    public boolean acceptEvent(Event event) {
045        AuditLogger logger = Framework.getService(AuditLogger.class);
046        if (logger == null) {
047            return false;
048        }
049        return logger.getAuditableEventNames().contains(event.getName());
050    }
051
052    @Override
053    public void handleEvent(EventBundle events) {
054        AuditLogger logger = Framework.getService(AuditLogger.class);
055        if (logger != null) {
056            logger.logEvents(events);
057        } else {
058            log.error("Can not reach AuditLogger");
059        }
060    }
061
062}