001/* 002 * (C) Copyright 2012 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * Antoine Taillefer <ataillefer@nuxeo.com> 018 */ 019package org.nuxeo.drive.adapter.impl; 020 021import org.nuxeo.drive.adapter.FileSystemItem; 022import org.nuxeo.drive.adapter.FolderItem; 023import org.nuxeo.drive.service.NuxeoDriveManager; 024import org.nuxeo.ecm.core.api.CoreInstance; 025import org.nuxeo.ecm.core.api.CoreSession; 026import org.nuxeo.ecm.core.api.DocumentModel; 027import org.nuxeo.runtime.api.Framework; 028 029/** 030 * Default implementation of a synchronization root {@link FolderItem}. 031 * 032 * @author Antoine Taillefer 033 */ 034public class DefaultSyncRootFolderItem extends DocumentBackedFolderItem { 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 this(factoryName, parentItem, doc, relaxSyncRootConstraint, true); 043 } 044 045 public DefaultSyncRootFolderItem(String factoryName, FolderItem parentItem, DocumentModel doc, 046 boolean relaxSyncRootConstraint, boolean getLockInfo) { 047 super(factoryName, parentItem, doc, relaxSyncRootConstraint, getLockInfo); 048 // A sync root can always be deleted since deletion is implemented as 049 // unregistration 050 this.canDelete = true; 051 } 052 053 protected DefaultSyncRootFolderItem() { 054 // Needed for JSON deserialization 055 } 056 057 @Override 058 public void delete() { 059 CoreSession session = CoreInstance.getCoreSession(repositoryName, principal); 060 DocumentModel doc = getDocument(session); 061 Framework.getService(NuxeoDriveManager.class).unregisterSynchronizationRoot(principal, doc, session); 062 } 063 064 @Override 065 public boolean canMove(FolderItem dest) { 066 return false; 067 } 068 069 @Override 070 public FileSystemItem move(FolderItem dest) { 071 throw new UnsupportedOperationException("Cannot move a synchronization root folder item."); 072 } 073 074}