001/* 002 * (C) Copyright 2012-2018 Nuxeo (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.factory; 020 021import java.util.ArrayList; 022import java.util.Arrays; 023import java.util.List; 024import java.util.Map; 025 026import org.apache.commons.lang3.StringUtils; 027import org.apache.logging.log4j.LogManager; 028import org.apache.logging.log4j.Logger; 029import org.nuxeo.drive.adapter.FolderItem; 030import org.nuxeo.drive.hierarchy.permission.adapter.PermissionTopLevelFolderItem; 031import org.nuxeo.drive.service.TopLevelFolderItemFactory; 032import org.nuxeo.drive.service.impl.AbstractVirtualFolderItemFactory; 033import org.nuxeo.ecm.core.api.NuxeoPrincipal; 034 035/** 036 * User workspace and permission based implementation of the {@link TopLevelFolderItemFactory}. 037 * 038 * @author Antoine Taillefer 039 */ 040public class PermissionTopLevelFactory extends AbstractVirtualFolderItemFactory implements TopLevelFolderItemFactory { 041 042 private static final Logger log = LogManager.getLogger(PermissionTopLevelFactory.class); 043 044 protected static final String CHILDREN_FACTORIES_PARAM = "childrenFactories"; 045 046 protected List<String> childrenFactoryNames = new ArrayList<>(); 047 048 /*---------------------- FileSystemItemFactory ---------------*/ 049 @Override 050 public void handleParameters(Map<String, String> parameters) { 051 super.handleParameters(parameters); 052 // Look for the "childrenFactories" parameter 053 String childrenFactoriesParam = parameters.get(CHILDREN_FACTORIES_PARAM); 054 if (!StringUtils.isEmpty(childrenFactoriesParam)) { 055 childrenFactoryNames.addAll(Arrays.asList(childrenFactoriesParam.split(","))); 056 } else { 057 log.warn( 058 "Factory {} has no {} parameter, please provide one in the factory contribution using a comma separated list to set the children factory names.", 059 this::getName, () -> CHILDREN_FACTORIES_PARAM); 060 } 061 } 062 063 /*---------------------- VirtualFolderItemFactory ---------------*/ 064 @Override 065 public FolderItem getVirtualFolderItem(NuxeoPrincipal principal) { 066 return getTopLevelFolderItem(principal); 067 } 068 069 /*----------------------- TopLevelFolderItemFactory ---------------------*/ 070 @Override 071 public FolderItem getTopLevelFolderItem(NuxeoPrincipal principal) { 072 return new PermissionTopLevelFolderItem(getName(), principal, getFolderName(), childrenFactoryNames); 073 } 074 075}