001/* 002 * (C) Copyright 2006-2012 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 */ 020package org.nuxeo.ecm.platform.audit.api.document; 021 022import java.io.Serializable; 023import java.util.HashMap; 024import java.util.List; 025 026import org.nuxeo.ecm.core.api.DocumentModel; 027import org.nuxeo.ecm.platform.audit.api.DocumentHistoryReader; 028import org.nuxeo.ecm.platform.audit.api.LogEntry; 029import org.nuxeo.ecm.platform.query.api.PageProvider; 030import org.nuxeo.ecm.platform.query.api.PageProviderService; 031import org.nuxeo.runtime.api.Framework; 032 033/** 034 * Implementation of the {@link DocumentHistoryReader} interface. This is mainly a wrapper around the 035 * {@link DocumentHistoryPageProvider} 036 * 037 * @author <a href="mailto:[email protected]">Tiry</a> 038 */ 039public class DocumentHistoryReaderImpl implements DocumentHistoryReader { 040 041 @Override 042 public List<LogEntry> getDocumentHistory(DocumentModel doc, long pageIndex, long pageSize) { 043 044 PageProvider<LogEntry> pp = getPageProvider(doc, pageIndex, pageSize); 045 return pp.getCurrentPage(); 046 } 047 048 @Override 049 @SuppressWarnings("unchecked") 050 public PageProvider<LogEntry> getPageProvider(DocumentModel doc, long pageIndex, long pageSize) { 051 052 PageProviderService pps = Framework.getService(PageProviderService.class); 053 PageProvider<LogEntry> pp = (PageProvider<LogEntry>) pps.getPageProvider("DOCUMENT_HISTORY_PROVIDER", null, 054 Long.valueOf(pageSize), Long.valueOf(pageIndex), new HashMap<String, Serializable>(), doc); 055 return pp; 056 } 057 058}