001/*
002 * (C) Copyright 2006-2008 Nuxeo SAS (http://nuxeo.com/) and contributors.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the GNU Lesser General Public License
006 * (LGPL) version 2.1 which accompanies this distribution, and is available at
007 * http://www.gnu.org/licenses/lgpl.html
008 *
009 * This library is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012 * Lesser General Public License for more details.
013 *
014 * Contributors:
015 *     bstefanescu
016 *
017 * $Id$
018 */
019
020package org.nuxeo.ecm.core.rest;
021
022import java.util.List;
023
024import javax.ws.rs.GET;
025
026import org.nuxeo.ecm.core.api.DocumentModel;
027import org.nuxeo.ecm.platform.audit.api.LogEntry;
028import org.nuxeo.ecm.platform.audit.api.Logs;
029import org.nuxeo.ecm.webengine.model.View;
030import org.nuxeo.ecm.webengine.model.WebAdapter;
031import org.nuxeo.ecm.webengine.model.impl.DefaultAdapter;
032import org.nuxeo.runtime.api.Framework;
033
034/**
035 * Audit Service - manage document versions TODO not yet implemented
036 * <p>
037 * Accepts the following methods:
038 * <ul>
039 * <li>GET - get audit records
040 * </ul>
041 *
042 * @author <a href="mailto:bs@nuxeo.com">Bogdan Stefanescu</a>
043 */
044@WebAdapter(name = "audits", type = "AuditService", targetType = "Document")
045public class AuditService extends DefaultAdapter {
046
047    @GET
048    public Object doGet() {
049        return new View(getTarget(), "audits").resolve();
050    }
051
052    public List<LogEntry> getAudits() {
053        Logs logs = Framework.getService(Logs.class);
054        DocumentObject document = (DocumentObject) getTarget();
055        DocumentModel model = document.getAdapter(DocumentModel.class);
056        String id = model.getId();
057        return logs.getLogEntriesFor(id);
058    }
059
060}