001/*
002 *  Copyright 2016 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.plugins.repository.maintenance;
017
018import org.ametys.plugins.repository.provider.AmetysPersistenceManager;
019import org.ametys.runtime.config.Config;
020import org.ametys.runtime.i18n.I18nizableText;
021import org.ametys.runtime.plugin.PluginsManager;
022import org.ametys.runtime.plugin.PluginsManager.Status;
023
024/**
025 * Client side element for maintenance tasks. Checks the safe mode, the status of safe-mode and JDNI nature of repository
026 */
027public class MaintenanceTaskClientSideElement extends org.ametys.workspaces.repository.maintenance.ui.MaintenanceTaskClientSideElement
028{
029    @Override
030    protected I18nizableText getUnavailableDescription()
031    {
032        if (!PluginsManager.getInstance().isSafeMode())
033        {
034            // Maintenance tasks are only available in safe-mode
035            return new I18nizableText("plugin.repository", "PLUGINS_REPOSITORY_BUTTON_MAINTENANCE_TASK_NO_SAFE_MODE_DESC");
036        }
037        else if (PluginsManager.getInstance().getStatus() != Status.SAFE_MODE_FORCED)
038        {
039            // Maintenance tasks are not available if configuration is not complete
040            return new I18nizableText("plugin.repository", "PLUGINS_REPOSITORY_BUTTON_MAINTENANCE_TASK_SAFE_MODE_UNFORCED_DESC");
041        }
042        else
043        {
044            return super.getUnavailableDescription();
045        }
046    }
047    
048    @Override
049    protected boolean isJndi()
050    {
051        // In safe mode the repository is not started, use the configuration parameter to determine if it is JNDI 
052        return Config.getInstance().getValue(AmetysPersistenceManager.CONFIG_USE_DEFAULT) == null;
053    }
054}