001/** 002 * 003 */ 004 005package org.nuxeo.drive.operations; 006 007import org.nuxeo.drive.service.NuxeoDriveManager; 008import org.nuxeo.ecm.automation.core.Constants; 009import org.nuxeo.ecm.automation.core.annotations.Context; 010import org.nuxeo.ecm.automation.core.annotations.Operation; 011import org.nuxeo.ecm.automation.core.annotations.OperationMethod; 012import org.nuxeo.ecm.automation.core.annotations.Param; 013import org.nuxeo.ecm.core.api.CoreSession; 014import org.nuxeo.ecm.core.api.DocumentModel; 015import org.nuxeo.runtime.api.Framework; 016 017/** 018 * If the {@code enable} parameter is {@code true}, registers the input document as a synchronization root for the 019 * currently authenticated user. Unregisters it otherwise. 020 */ 021@Operation(id = NuxeoDriveSetSynchronizationOperation.ID, category = Constants.CAT_SERVICES, label = "Nuxeo Drive: Register / Unregister Synchronization Root", description = "If the enable parameter is true, register the input document as a synchronization root for the currently authenticated user." // 022 + " Unregister it otherwise.") 023public class NuxeoDriveSetSynchronizationOperation { 024 025 public static final String ID = "NuxeoDrive.SetSynchronization"; 026 027 @Context 028 protected CoreSession session; 029 030 @Param(name = "enable", description = "Whether to register or unregister the input document as a synchronizaiton root.") 031 protected boolean enable; 032 033 @OperationMethod 034 public void run(DocumentModel doc) { 035 NuxeoDriveManager driveManager = Framework.getService(NuxeoDriveManager.class); 036 if (enable) { 037 driveManager.registerSynchronizationRoot(session.getPrincipal(), doc, session); 038 } else { 039 driveManager.unregisterSynchronizationRoot(session.getPrincipal(), doc, session); 040 } 041 } 042 043}