001/*
002 * (C) Copyright 2006-2011 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.api;
023
024import java.util.Date;
025import java.util.List;
026import java.util.Map;
027
028/**
029 * Interface for reading data from the Audit service.
030 *
031 * @author tiry
032 */
033public interface AuditReader {
034
035    /**
036     * Returns the logs given a doc uuid.
037     *
038     * @param uuid the document uuid
039     * @return a list of log entries
040     */
041    List<LogEntry> getLogEntriesFor(String uuid);
042
043    List<LogEntry> getLogEntriesFor(String uuid, Map<String, FilterMapEntry> filterMap, boolean doDefaultSort);
044
045    /**
046     * Returns a given log entry given its id.
047     *
048     * @param id the log entry identifier
049     * @return a LogEntry instance
050     */
051    LogEntry getLogEntryByID(long id);
052
053    /**
054     * Returns the list of log entries.
055     * <p>
056     * Note we will use NXQL in the future when the search engine will index history.
057     *
058     * @see org.nuxeo.ecm.platform.audit.api.query.DateRangeQueryConstants
059     * @param eventIds the event ids.
060     * @param dateRange a preset date range.
061     * @return a list of log entries.
062     */
063    List<LogEntry> queryLogs(String[] eventIds, String dateRange);
064
065    /**
066     * Returns the batched list of log entries.
067     * <p>
068     * Note we will use NXQL in the future when the search engine will index history.
069     *
070     * @see org.nuxeo.ecm.platform.audit.api.query.DateRangeQueryConstants
071     * @param eventIds the event ids.
072     * @param dateRange a preset date range.
073     * @param category add filter on events category
074     * @param path add filter on document path
075     * @param pageNb page number (ignore if <=1)
076     * @param pageSize number of results per page
077     * @return a list of log entries.
078     */
079    List<LogEntry> queryLogsByPage(String[] eventIds, String dateRange, String category, String path, int pageNb,
080            int pageSize);
081
082    List<LogEntry> queryLogsByPage(String[] eventIds, String dateRange, String[] category, String path, int pageNb,
083            int pageSize);
084
085    /**
086     * Returns the batched list of log entries.
087     * <p>
088     * Note we will use NXQL in the future when the search engine will index history.
089     *
090     * @see org.nuxeo.ecm.platform.audit.api.query.DateRangeQueryConstants
091     * @param eventIds the event ids.
092     * @param limit filter events by date from limit to now
093     * @param category add filter on events category
094     * @param path add filter on document path
095     * @param pageNb page number (ignore if <=1)
096     * @param pageSize number of results per page
097     * @return a list of log entries.
098     */
099    List<LogEntry> queryLogsByPage(String[] eventIds, Date limit, String category, String path, int pageNb, int pageSize);
100
101    List<LogEntry> queryLogsByPage(String[] eventIds, Date limit, String[] category, String path, int pageNb,
102            int pageSize);
103
104    /**
105     * Returns a batched list of log entries. WhereClause is a native where clause for the backend: here EJBQL 3.0 must
106     * be used if implementation of audit backend is JPA (< 7.3 or audit.elasticsearch.enabled=false) and JSON if
107     * implementation is Elasticsearch.
108     */
109    List<LogEntry> nativeQueryLogs(String whereClause, int pageNb, int pageSize);
110
111    /**
112     * Returns a batched list of entries. query string is a native query clause for the backend : here EJBQL 3.0 must be
113     * used if implementation of audit backend is JPA (< 7.3 or audit.elasticsearch.enabled=false) and JSON if
114     * implementation is Elasticsearch.
115     */
116    List<?> nativeQuery(String query, int pageNb, int pageSize);
117
118    /**
119     * Returns a batched list of entries.
120     *
121     * @param query a JPA query language query if implementation of audit backend is JPA (< 7.3 or
122     *            audit.elasticsearch.enabled=false) and JSON if implementation is Elasticsearch
123     * @param params parameters for the query
124     * @param pageNb the page number (starts at 1)
125     * @param pageSize the number of results per page
126     */
127    List<?> nativeQuery(String query, Map<String, Object> params, int pageNb, int pageSize);
128
129}