001/* 002 * Copyright (c) 2006-2011 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 * bstefanescu 011 */ 012package org.nuxeo.ecm.automation.core.operations.document; 013 014import org.nuxeo.ecm.automation.core.Constants; 015import org.nuxeo.ecm.automation.core.annotations.Context; 016import org.nuxeo.ecm.automation.core.annotations.Operation; 017import org.nuxeo.ecm.automation.core.annotations.OperationMethod; 018import org.nuxeo.ecm.automation.core.collectors.DocumentModelCollector; 019import org.nuxeo.ecm.core.api.CoreSession; 020import org.nuxeo.ecm.core.api.DocumentModel; 021import org.nuxeo.ecm.core.api.DocumentRef; 022 023/** 024 * @author <a href="mailto:bs@nuxeo.com">Bogdan Stefanescu</a> 025 */ 026@Operation(id = UnlockDocument.ID, category = Constants.CAT_DOCUMENT, label = "Unlock", description = "Unlock the input document. The unlock will be executed in the name of the current user. An user can unlock a document only if has the UNLOCK permission granted on the document or if it the same user as the one that locked the document. Return the unlocked document") 027public class UnlockDocument { 028 029 public static final String ID = "Document.Unlock"; 030 031 @Context 032 protected CoreSession session; 033 034 @OperationMethod(collector = DocumentModelCollector.class) 035 public DocumentModel run(DocumentRef doc) { 036 session.removeLock(doc); 037 return session.getDocument(doc); 038 } 039 040 @OperationMethod(collector = DocumentModelCollector.class) 041 public DocumentModel run(DocumentModel doc) { 042 session.removeLock(doc.getRef()); 043 return session.getDocument(doc.getRef()); 044 } 045 046}