001/* 002 * (C) Copyright 2013 Nuxeo SA (http://nuxeo.com/) and contributors. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the GNU Lesser General Public License 006 * (LGPL) version 2.1 which accompanies this distribution, and is available at 007 * http://www.gnu.org/licenses/lgpl-2.1.html 008 * 009 * This library is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 012 * Lesser General Public License for more details. 013 * 014 * Contributors: 015 * Antoine Taillefer <ataillefer@nuxeo.com> 016 */ 017package org.nuxeo.drive.operations.test; 018 019import java.net.URL; 020 021import org.apache.commons.logging.Log; 022import org.apache.commons.logging.LogFactory; 023import org.nuxeo.drive.adapter.FileSystemItem; 024import org.nuxeo.ecm.automation.core.Constants; 025import org.nuxeo.ecm.automation.core.annotations.Operation; 026import org.nuxeo.ecm.automation.core.annotations.OperationMethod; 027import org.nuxeo.ecm.automation.core.annotations.Param; 028import org.nuxeo.runtime.api.Framework; 029import org.nuxeo.runtime.reload.ReloadService; 030 031/** 032 * Activates / deactivates the {@link FileSystemItem} factories of the given profile. 033 * 034 * @author Antoine Taillefer 035 */ 036@Operation(id = NuxeoDriveSetActiveFactories.ID, category = Constants.CAT_SERVICES, label = "Nuxeo Drive: Activate or deactivate file system item factories") 037public class NuxeoDriveSetActiveFactories { 038 039 public static final String ID = "NuxeoDrive.SetActiveFactories"; 040 041 private static final Log log = LogFactory.getLog(NuxeoDriveSetActiveFactories.class); 042 043 @Param(name = "profile") 044 protected String profile; 045 046 @Param(name = "enable", required = false) 047 protected boolean enable = true; 048 049 @OperationMethod 050 public boolean run() throws Exception { 051 NuxeoDriveIntegrationTestsHelper.checkOperationAllowed(); 052 String contrib = null; 053 if ("userworkspace".equals(profile)) { 054 contrib = "/OSGI-INF/nuxeodrive-hierarchy-userworkspace-contrib.xml"; 055 } else if ("permission".equals(profile)) { 056 contrib = "/OSGI-INF/nuxeodrive-hierarchy-permission-contrib.xml"; 057 } else { 058 log.warn(String.format("No active file system item factory contribution for profile '%s'.", profile)); 059 return false; 060 } 061 URL url = NuxeoDriveSetActiveFactories.class.getResource(contrib); 062 if (enable) { 063 Framework.getRuntime().getContext().deploy(url); 064 } else { 065 Framework.getRuntime().getContext().undeploy(url); 066 } 067 Framework.getLocalService(ReloadService.class).reload(); 068 return true; 069 } 070 071}