001/* 002 * (C) Copyright 2012 Nuxeo SA (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 * Antoine Taillefer <ataillefer@nuxeo.com> 016 */ 017package org.nuxeo.drive.adapter.impl; 018 019import org.nuxeo.drive.adapter.FileSystemItem; 020import org.nuxeo.drive.adapter.FolderItem; 021import org.nuxeo.drive.service.NuxeoDriveManager; 022import org.nuxeo.ecm.core.api.CoreInstance; 023import org.nuxeo.ecm.core.api.CoreSession; 024import org.nuxeo.ecm.core.api.DocumentModel; 025import org.nuxeo.runtime.api.Framework; 026 027/** 028 * Default implementation of a synchronization root {@link FolderItem}. 029 * 030 * @author Antoine Taillefer 031 */ 032public class DefaultSyncRootFolderItem extends DocumentBackedFolderItem implements FolderItem { 033 034 private static final long serialVersionUID = 1L; 035 036 public DefaultSyncRootFolderItem(String factoryName, FolderItem parentItem, DocumentModel doc) { 037 this(factoryName, parentItem, doc, false); 038 } 039 040 public DefaultSyncRootFolderItem(String factoryName, FolderItem parentItem, DocumentModel doc, 041 boolean relaxSyncRootConstraint) { 042 super(factoryName, parentItem, doc, relaxSyncRootConstraint); 043 // A sync root can always be deleted since deletion is implemented as 044 // unregistration 045 this.canDelete = true; 046 } 047 048 protected DefaultSyncRootFolderItem() { 049 // Needed for JSON deserialization 050 } 051 052 @Override 053 public void delete() { 054 try (CoreSession session = CoreInstance.openCoreSession(repositoryName, principal)) { 055 DocumentModel doc = getDocument(session); 056 Framework.getLocalService(NuxeoDriveManager.class).unregisterSynchronizationRoot(principal, doc, session); 057 } 058 } 059 060 @Override 061 public boolean canMove(FolderItem dest) { 062 return false; 063 } 064 065 @Override 066 public FileSystemItem move(FolderItem dest) { 067 throw new UnsupportedOperationException("Cannot move a synchronization root folder item."); 068 } 069 070}