001/*
002 *  Copyright 2015 Anyware Services
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 */
016package org.ametys.workspaces.repository;
017
018import java.io.IOException;
019
020import org.apache.avalon.framework.service.ServiceException;
021import org.apache.avalon.framework.service.ServiceManager;
022import org.apache.excalibur.source.Source;
023
024import org.ametys.core.ui.ribbonconfiguration.RibbonConfigurationSource;
025import org.ametys.core.util.SystemStatus;
026import org.ametys.runtime.plugin.PluginsManager;
027import org.ametys.workspaces.repository.maintenance.MaintenanceTaskManager;
028
029/**
030 * Repository workspace handling maintenance tasks in safe mode.
031 */
032public class RepositoryWorkspaceGenerator extends org.ametys.plugins.core.ui.WorkspaceGenerator
033{
034    /** System status provider */
035    protected SystemStatus _systemStatus;
036    
037    @Override
038    protected RibbonConfigurationSource getRibbonConfiguration() throws IOException
039    {
040        if (PluginsManager.getInstance().isSafeMode())
041        {
042            return RibbonConfigurationSource.createFromUri("resource://org/ametys/workspaces/repository/repository-safe-ribbon.xml", _resolver);
043        }
044        
045        return super.getRibbonConfiguration();
046    }
047    
048    @Override
049    public void service(ServiceManager sm) throws ServiceException
050    {
051        super.service(sm);
052        _systemStatus = (SystemStatus) sm.lookup(SystemStatus.ROLE);
053    }
054    
055    @Override
056    protected Source getUIToolsConfiguration() throws IOException
057    {
058        if (PluginsManager.getInstance().isSafeMode())
059        {
060            boolean safeModeForced = PluginsManager.Status.SAFE_MODE_FORCED.equals(PluginsManager.getInstance().getStatus());
061            if (safeModeForced && _systemStatus.getStatus().contains(MaintenanceTaskManager.REPOSITORY_UNAVAILABLE))
062            {
063                return _resolver.resolveURI("resource://org/ametys/workspaces/repository/repository-maintenance-uitools.xml");
064            }
065        }
066        
067        return super.getUIToolsConfiguration();
068    }
069}