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.hierarchy.permission.adapter; 020 021import java.util.ArrayList; 022import java.util.List; 023 024import org.nuxeo.drive.adapter.FileSystemItem; 025import org.nuxeo.drive.adapter.FolderItem; 026import org.nuxeo.drive.adapter.impl.AbstractVirtualFolderItem; 027import org.nuxeo.drive.service.VirtualFolderItemFactory; 028import org.nuxeo.ecm.core.api.NuxeoPrincipal; 029 030/** 031 * User workspace and permission based implementation of the top level {@link FolderItem}. 032 * <p> 033 * Implements the following tree: 034 * 035 * <pre> 036 * Nuxeo Drive 037 * |-- My Docs (= user workspace if synchronized else user synchronization roots) 038 * | |-- Folder 1 039 * | |-- Folder 2 040 * | |-- ... 041 * |-- Other Docs (= user's shared synchronized roots with ReadWrite permission) 042 * | |-- Other folder 1 043 * | |-- Other folder 2 044 * | |-- ... 045 * </pre> 046 * 047 * @author Antoine Taillefer 048 */ 049public class PermissionTopLevelFolderItem extends AbstractVirtualFolderItem { 050 051 protected List<String> childrenFactoryNames; 052 053 public PermissionTopLevelFolderItem(String factoryName, NuxeoPrincipal principal, String folderName, 054 List<String> childrenFactoryNames) { 055 super(factoryName, principal, null, null, folderName); 056 this.childrenFactoryNames = childrenFactoryNames; 057 } 058 059 protected PermissionTopLevelFolderItem() { 060 // Needed for JSON deserialization 061 } 062 063 @Override 064 public List<FileSystemItem> getChildren() { 065 066 List<FileSystemItem> children = new ArrayList<>(); 067 for (String childFactoryName : childrenFactoryNames) { 068 VirtualFolderItemFactory factory = getFileSystemItemAdapterService().getVirtualFolderItemFactory( 069 childFactoryName); 070 FolderItem child = factory.getVirtualFolderItem(principal); 071 if (child != null) { 072 children.add(child); 073 } 074 } 075 return children; 076 } 077 078 // Override equals and hashCode to explicitly show that their implementation rely on the parent class and doesn't 079 // depend on the fields added to this class. 080 @Override 081 public boolean equals(Object obj) { 082 return super.equals(obj); 083 } 084 085 @Override 086 public int hashCode() { 087 return super.hashCode(); 088 } 089 090}