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 <[email protected]> 018 */ 019package org.nuxeo.drive.adapter.impl; 020 021import java.util.Calendar; 022 023import org.nuxeo.drive.adapter.FileItem; 024import org.nuxeo.drive.adapter.FileSystemItem; 025import org.nuxeo.drive.adapter.FolderItem; 026import org.nuxeo.drive.adapter.ScrollFileSystemItemList; 027import org.nuxeo.drive.service.impl.NuxeoDriveManagerImpl; 028import org.nuxeo.ecm.core.api.Blob; 029import org.nuxeo.ecm.core.api.NuxeoPrincipal; 030import org.nuxeo.ecm.core.api.security.SecurityConstants; 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 protected boolean canCreateChild; 040 041 protected boolean canScrollDescendants; 042 043 public AbstractVirtualFolderItem(String factoryName, NuxeoPrincipal principal, String parentId, String parentPath, 044 String folderName) { 045 super(factoryName, principal, false); 046 this.parentId = parentId; 047 name = folderName; 048 folder = true; 049 creator = SecurityConstants.SYSTEM_USERNAME; 050 lastContributor = SecurityConstants.SYSTEM_USERNAME; 051 // The Fixed Origin of (Unix) Time 052 creationDate = Calendar.getInstance(NuxeoDriveManagerImpl.UTC); 053 creationDate.set(1970, 0, 1, 0, 0, 0); 054 lastModificationDate = this.creationDate; 055 canRename = false; 056 canDelete = false; 057 canCreateChild = false; 058 canScrollDescendants = false; 059 path = FILE_SYSTEM_ITEM_PATH_SEPARATOR + getId(); 060 if (parentPath != null) { 061 path = parentPath + path; 062 } 063 } 064 065 protected AbstractVirtualFolderItem() { 066 // Needed for JSON deserialization 067 } 068 069 /*--------------------- FileSystemItem ---------------------*/ 070 @Override 071 public void rename(String name) { 072 throw new UnsupportedOperationException("Cannot rename a virtual folder item."); 073 } 074 075 @Override 076 public void delete() { 077 throw new UnsupportedOperationException("Cannot delete a virtual folder item."); 078 } 079 080 @Override 081 public boolean canMove(FolderItem dest) { 082 return false; 083 } 084 085 @Override 086 public FileSystemItem move(FolderItem dest) { 087 throw new UnsupportedOperationException("Cannot move a virtual folder item."); 088 } 089 090 /*--------------------- FolderItem -----------------*/ 091 @Override 092 public boolean getCanScrollDescendants() { 093 return canScrollDescendants; 094 } 095 096 @Override 097 public ScrollFileSystemItemList scrollDescendants(String scrollId, int batchSize, long keepAlive) { 098 throw new UnsupportedOperationException( 099 "Cannot scroll through the descendants of a virtual folder item, please call getChildren() instead."); 100 } 101 102 @Override 103 public boolean getCanCreateChild() { 104 return canCreateChild; 105 } 106 107 @Override 108 public FolderItem createFolder(String name, boolean overwrite) { 109 throw new UnsupportedOperationException("Cannot create a folder in a virtual folder item."); 110 } 111 112 @Override 113 public FileItem createFile(Blob blob, boolean overwrite) { 114 throw new UnsupportedOperationException("Cannot create a file in a virtual folder item."); 115 } 116 117 /*--------------------- Object -----------------*/ 118 // Override equals and hashCode to explicitly show that their implementation rely on the parent class and doesn't 119 // depend on the fields added to this class. 120 @Override 121 public boolean equals(Object obj) { 122 return super.equals(obj); 123 } 124 125 @Override 126 public int hashCode() { 127 return super.hashCode(); 128 } 129 130 /*---------- Needed for JSON deserialization ----------*/ 131 protected void setCanCreateChild(boolean canCreateChild) { 132 this.canCreateChild = canCreateChild; 133 } 134 135 protected void setCanScrollDescendants(boolean canScrollDescendants) { 136 this.canScrollDescendants = canScrollDescendants; 137 } 138 139}