001/* 002 * Copyright (c) 2006-2012 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the Eclipse Public License v1.0 006 * which accompanies this distribution, and is available at 007 * http://www.eclipse.org/legal/epl-v10.html 008 * 009 * Contributors: 010 * Nuxeo - initial API and implementation 011 * 012 */ 013package org.nuxeo.ecm.platform.audit.api.document; 014 015import java.io.Serializable; 016import java.util.HashMap; 017import java.util.List; 018 019import org.nuxeo.ecm.core.api.DocumentModel; 020import org.nuxeo.ecm.platform.audit.api.DocumentHistoryReader; 021import org.nuxeo.ecm.platform.audit.api.LogEntry; 022import org.nuxeo.ecm.platform.query.api.PageProvider; 023import org.nuxeo.ecm.platform.query.api.PageProviderService; 024import org.nuxeo.runtime.api.Framework; 025 026/** 027 * Implementation of the {@link DocumentHistoryReader} interface. This is mainly a wrapper around the 028 * {@link DocumentHistoryPageProvider} 029 * 030 * @author <a href="mailto:tdelprat@nuxeo.com">Tiry</a> 031 */ 032public class DocumentHistoryReaderImpl implements DocumentHistoryReader { 033 034 @Override 035 public List<LogEntry> getDocumentHistory(DocumentModel doc, long pageIndex, long pageSize) { 036 037 PageProvider<LogEntry> pp = getPageProvider(doc, pageIndex, pageSize); 038 return pp.getCurrentPage(); 039 } 040 041 @Override 042 @SuppressWarnings("unchecked") 043 public PageProvider<LogEntry> getPageProvider(DocumentModel doc, long pageIndex, long pageSize) { 044 045 PageProviderService pps = Framework.getLocalService(PageProviderService.class); 046 PageProvider<LogEntry> pp = (PageProvider<LogEntry>) pps.getPageProvider("DOCUMENT_HISTORY_PROVIDER", null, 047 Long.valueOf(pageSize), Long.valueOf(pageIndex), new HashMap<String, Serializable>(), doc); 048 return pp; 049 } 050 051}