<commit_before>/*******************************************************************************
 * Copyright (C) 2020, exense GmbH
 *  
 * This file is part of STEP
 *  
 * STEP is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *  
 * STEP is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *  
 * You should have received a copy of the GNU Affero General Public License
 * along with STEP.  If not, see <http://www.gnu.org/licenses/>.
 ******************************************************************************/
package step.core.scheduler;

import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;

import step.core.GlobalContext;
import step.core.controller.ControllerSetting;
import step.core.controller.ControllerSettingAccessor;
import step.core.plugins.AbstractControllerPlugin;
import step.core.plugins.Plugin;
import step.plugins.screentemplating.Input;
import step.plugins.screentemplating.InputType;
import step.plugins.screentemplating.ScreenInput;
import step.plugins.screentemplating.ScreenInputAccessor;
import step.plugins.screentemplating.ScreenTemplatePlugin;

@Plugin(dependencies= {ScreenTemplatePlugin.class})
public class SchedulerPlugin extends AbstractControllerPlugin {

	private static final String SCHEDULER_TABLE = "schedulerTable";
	private static final String SCHEDULER_ENABLED = "scheduler_enabled";
	
	private ControllerSettingAccessor controllerSettingAccessor;


	@Override
	public void executionControllerStart(GlobalContext context) throws Exception {
		controllerSettingAccessor = context.require(ControllerSettingAccessor.class);
	}
	
	@Override
	public void initializeData(GlobalContext context) throws Exception {
		createScreenInputDefinitionsIfNecessary(context);
		createSchedulerSettingsIfNecessary(context);
	}
	
	protected void createSchedulerSettingsIfNecessary(GlobalContext context) {
		createSettingIfNotExisting(context, SCHEDULER_ENABLED, "true");
	}

	protected void createSettingIfNotExisting(GlobalContext context, String key, String defaultValue) {
		ControllerSetting schedulerEnabled = controllerSettingAccessor.getSettingByKey(key);
		if(schedulerEnabled == null) {
			controllerSettingAccessor.save(new ControllerSetting(key, defaultValue));<commit_msg>SED-519 Adding missing plugin dependencies to SchedulerPlugin<commit_after>/*******************************************************************************
 * Copyright (C) 2020, exense GmbH
 *  
 * This file is part of STEP
 *  
 * STEP is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *  
 * STEP is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *  
 * You should have received a copy of the GNU Affero General Public License
 * along with STEP.  If not, see <http://www.gnu.org/licenses/>.
 ******************************************************************************/
package step.core.scheduler;

import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;

import step.core.GlobalContext;
import step.core.controller.ControllerSetting;
import step.core.controller.ControllerSettingAccessor;
import step.core.controller.ControllerSettingPlugin;
import step.core.plugins.AbstractControllerPlugin;
import step.core.plugins.Plugin;
import step.plugins.screentemplating.Input;
import step.plugins.screentemplating.InputType;
import step.plugins.screentemplating.ScreenInput;
import step.plugins.screentemplating.ScreenInputAccessor;
import step.plugins.screentemplating.ScreenTemplatePlugin;

@Plugin(dependencies= {ScreenTemplatePlugin.class, ControllerSettingPlugin.class})
public class SchedulerPlugin extends AbstractControllerPlugin {

	private static final String SCHEDULER_TABLE = "schedulerTable";
	private static final String SCHEDULER_ENABLED = "scheduler_enabled";
	
	private ControllerSettingAccessor controllerSettingAccessor;


	@Override
	public void executionControllerStart(GlobalContext context) throws Exception {
		controllerSettingAccessor = context.require(ControllerSettingAccessor.class);
	}
	
	@Override
	public void initializeData(GlobalContext context) throws Exception {
		createScreenInputDefinitionsIfNecessary(context);
		createSchedulerSettingsIfNecessary(context);
	}
	
	protected void createSchedulerSettingsIfNecessary(GlobalContext context) {
		createSettingIfNotExisting(context, SCHEDULER_ENABLED, "true");
	}

	protected void createSettingIfNotExisting(GlobalContext context, String key, String defaultValue) {
		ControllerSetting schedulerEnabled = controllerSettingAccessor.getSettingByKey(key);
		if(schedulerEnabled == null) {
			controllerSettingAccessor.save(new ControllerSetting(key, defaultValue));
{'fraction_non_alphanumeric': 0.12294776119402985, 'fraction_numerical': 0.002425373134328358, 'mean_word_length': 6.435506241331484, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5111741', 'n_tokens_mistral': 1368, 'n_tokens_neox': 1287, 'n_words': 408}