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 org.nuxeo.ecm.core.api.CoreSession; 016import org.nuxeo.ecm.core.api.DocumentModel; 017import org.nuxeo.ecm.core.api.IdRef; 018import org.nuxeo.ecm.core.api.UnrestrictedSessionRunner; 019 020/** 021 * Simple helper to fetch the target Audited document 022 * 023 * @author <a href="mailto:tdelprat@nuxeo.com">Tiry</a> 024 */ 025public class SourceDocumentResolver extends UnrestrictedSessionRunner { 026 027 public DocumentModel sourceDocument; 028 029 protected final DocumentModel document; 030 031 SourceDocumentResolver(CoreSession session, DocumentModel doc) { 032 super(session); 033 this.document = doc; 034 } 035 036 @Override 037 public void run() { 038 DocumentModel version = null; 039 if (document.isProxy()) { 040 version = session.getSourceDocument(document.getRef()); 041 } else { 042 version = document; 043 } 044 if (version != null) { 045 if (version.getSourceId() != null && session.exists(new IdRef(version.getSourceId()))) { 046 sourceDocument = session.getSourceDocument(version.getRef()); 047 } 048 } 049 } 050 051}