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 java.security.Principal; 022import java.util.Calendar; 023import java.util.List; 024 025import org.nuxeo.drive.adapter.FileItem; 026import org.nuxeo.drive.adapter.FileSystemItem; 027import org.nuxeo.drive.adapter.FolderItem; 028import org.nuxeo.drive.adapter.ScrollFileSystemItemList; 029import org.nuxeo.drive.service.impl.NuxeoDriveManagerImpl; 030import org.nuxeo.ecm.core.api.Blob; 031 032/** 033 * Base implementation of a virtual {@link FolderItem}. 034 * 035 * @author Antoine Taillefer 036 */ 037public abstract class AbstractVirtualFolderItem extends AbstractFileSystemItem implements FolderItem { 038 039 private static final long serialVersionUID = 1L; 040 041 protected boolean canCreateChild; 042 043 protected boolean canScrollDescendants; 044 045 public AbstractVirtualFolderItem(String factoryName, Principal principal, String parentId, String parentPath, 046 String folderName) { 047 super(factoryName, principal, false); 048 this.parentId = parentId; 049 name = folderName; 050 folder = true; 051 creator = "system"; 052 lastContributor = "system"; 053 // The Fixed Origin of (Unix) Time 054 creationDate = Calendar.getInstance(NuxeoDriveManagerImpl.UTC); 055 creationDate.set(1970, 0, 1, 0, 0, 0); 056 lastModificationDate = this.creationDate; 057 canRename = false; 058 canDelete = false; 059 canCreateChild = false; 060 canScrollDescendants = false; 061 path = "/" + getId(); 062 if (parentPath != null) { 063 path = parentPath + path; 064 } 065 } 066 067 protected AbstractVirtualFolderItem() { 068 // Needed for JSON deserialization 069 } 070 071 /*----------------------- FolderItem -----------------------*/ 072 @Override 073 public abstract List<FileSystemItem> getChildren(); 074 075 /*--------------------- FileSystemItem ---------------------*/ 076 @Override 077 public void rename(String name) { 078 throw new UnsupportedOperationException("Cannot rename a virtual folder item."); 079 } 080 081 @Override 082 public void delete() { 083 throw new UnsupportedOperationException("Cannot delete a virtual folder item."); 084 } 085 086 @Override 087 public boolean canMove(FolderItem dest) { 088 return false; 089 } 090 091 @Override 092 public FileSystemItem move(FolderItem dest) { 093 throw new UnsupportedOperationException("Cannot move a virtual folder item."); 094 } 095 096 /*--------------------- FolderItem -----------------*/ 097 @Override 098 public boolean getCanScrollDescendants() { 099 return canScrollDescendants; 100 } 101 102 @Override 103 public ScrollFileSystemItemList scrollDescendants(String scrollId, int batchSize, long keepAlive) { 104 throw new UnsupportedOperationException( 105 "Cannot scroll through the descendants of a virtual folder item, please call getChildren() instead."); 106 } 107 108 @Override 109 public boolean getCanCreateChild() { 110 return canCreateChild; 111 } 112 113 @Override 114 public FolderItem createFolder(String name, boolean overwrite) { 115 throw new UnsupportedOperationException("Cannot create a folder in a virtual folder item."); 116 } 117 118 @Override 119 public FileItem createFile(Blob blob, boolean overwrite) { 120 throw new UnsupportedOperationException("Cannot create a file in a virtual folder item."); 121 } 122 123 /*---------- Needed for JSON deserialization ----------*/ 124 protected void setCanCreateChild(boolean canCreateChild) { 125 this.canCreateChild = canCreateChild; 126 } 127 128 protected void setCanScrollDescendants(boolean canScrollDescendants) { 129 this.canScrollDescendants = canScrollDescendants; 130 } 131 132}