<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.plugins.parametermanager;

import java.util.AbstractMap.SimpleEntry;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentMap;
import java.util.stream.Collectors;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import step.core.accessors.AbstractOrganizableObject;
import step.core.artefacts.reports.ReportNode;
import step.core.encryption.EncryptionManager;
import step.core.encryption.EncryptionManagerException;
import step.core.execution.ExecutionContext;
import step.core.execution.ExecutionContextBindings;
import step.core.objectenricher.ObjectPredicate;
import step.core.plugins.IgnoreDuringAutoDiscovery;
import step.core.plugins.Plugin;
import step.core.plugins.exceptions.PluginCriticalException;
import step.core.variables.VariableType;
import step.core.variables.VariablesManager;
import step.engine.execution.ExecutionManager;
import step.engine.plugins.AbstractExecutionEnginePlugin;
import step.functions.Function;
import step.parameter.Parameter;
import step.parameter.ParameterManager;
import step.parameter.ParameterScope;
import step.security.SecurityManager;

@Plugin(dependencies = {})
@IgnoreDuringAutoDiscovery
public class ParameterManagerPlugin extends AbstractExecutionEnginePlugin {
	
	private static final String RESOLVER_PREFIX_PARAMETER = "parameter::";
	private static final String PARAMETER_SCOPE_VALUE_DEFAULT = "default";
	private static final String PARAMETERS_BY_SCOPE = "$parametersByScope";
	private static final String PROTECTED_PARAMETERS = "$parametersProtected";

	public static Logger logger = LoggerFactory.getLogger(ParameterManagerPlugin.class);
		
	protected final ParameterManager parameterManager;
	protected final EncryptionManager encryptionManager;
	
	public ParameterManagerPlugin(ParameterManager parameterManager, EncryptionManager encryptionManager) {
		super();
		this.parameterManager = parameterManager;
		this.encryptionManager = encryptionManager;
	}

	@Override
	public void executionStart(ExecutionContext context) {
		ReportNode rootNode = context.getReport();
		
		// Resolve the active parameters
		Map<String, Object> contextBindings = ExecutionContextBindings.get(context);
		ObjectPredicate objectPredicate = context.getObjectPredicate();
		Map<String, Parameter> allParameters = parameterManager.getAllParameters(contextBindings, objectPredicate);

		// Add all the active parameters to the execution parameter map of the Execution object
		buildExecutionParametersMapAndUpdateExecution(context, allParameters);
		
		initializeParameterResolver(context, allParameters);
		<commit_msg>SED-758 Changing parameter resolver prefix to "parameter:"<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.plugins.parametermanager;

import java.util.AbstractMap.SimpleEntry;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentMap;
import java.util.stream.Collectors;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import step.core.accessors.AbstractOrganizableObject;
import step.core.artefacts.reports.ReportNode;
import step.core.encryption.EncryptionManager;
import step.core.encryption.EncryptionManagerException;
import step.core.execution.ExecutionContext;
import step.core.execution.ExecutionContextBindings;
import step.core.objectenricher.ObjectPredicate;
import step.core.plugins.IgnoreDuringAutoDiscovery;
import step.core.plugins.Plugin;
import step.core.plugins.exceptions.PluginCriticalException;
import step.core.variables.VariableType;
import step.core.variables.VariablesManager;
import step.engine.execution.ExecutionManager;
import step.engine.plugins.AbstractExecutionEnginePlugin;
import step.functions.Function;
import step.parameter.Parameter;
import step.parameter.ParameterManager;
import step.parameter.ParameterScope;
import step.security.SecurityManager;

@Plugin(dependencies = {})
@IgnoreDuringAutoDiscovery
public class ParameterManagerPlugin extends AbstractExecutionEnginePlugin {
	
	private static final String RESOLVER_PREFIX_PARAMETER = "parameter:";
	private static final String PARAMETER_SCOPE_VALUE_DEFAULT = "default";
	private static final String PARAMETERS_BY_SCOPE = "$parametersByScope";
	private static final String PROTECTED_PARAMETERS = "$parametersProtected";

	public static Logger logger = LoggerFactory.getLogger(ParameterManagerPlugin.class);
		
	protected final ParameterManager parameterManager;
	protected final EncryptionManager encryptionManager;
	
	public ParameterManagerPlugin(ParameterManager parameterManager, EncryptionManager encryptionManager) {
		super();
		this.parameterManager = parameterManager;
		this.encryptionManager = encryptionManager;
	}

	@Override
	public void executionStart(ExecutionContext context) {
		ReportNode rootNode = context.getReport();
		
		// Resolve the active parameters
		Map<String, Object> contextBindings = ExecutionContextBindings.get(context);
		ObjectPredicate objectPredicate = context.getObjectPredicate();
		Map<String, Parameter> allParameters = parameterManager.getAllParameters(contextBindings, objectPredicate);

		// Add all the active parameters to the execution parameter map of the Execution object
		buildExecutionParametersMapAndUpdateExecution(context, allParameters);
		
		initializeParameterResolver(context, allParameters);
		
{'fraction_non_alphanumeric': 0.1128942227183924, 'fraction_numerical': 0.0023723137036003347, 'mean_word_length': 6.313265306122449, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '1122668', 'n_tokens_mistral': 1835, 'n_tokens_neox': 1747, 'n_words': 536}