<commit_before>package com.truemarkit.newrelic.oracle;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.truemarkit.newrelic.oracle.model.Metric;
import com.newrelic.metrics.publish.Agent;
import com.newrelic.metrics.publish.AgentFactory;
import com.newrelic.metrics.publish.configuration.ConfigurationException;
import lombok.extern.slf4j.Slf4j;

import java.io.File;
import java.util.*;

/**
 * @author <NAME>
 */
@Slf4j
public class OracleAgentFactory extends AgentFactory {

	@Override
	public Agent createConfiguredAgent(Map<String, Object> properties) throws ConfigurationException {
		String name = (String) properties.get("name");
		String host = (String) properties.get("host");
		String port = (String) properties.get("port");
		String serviceName = (String) properties.get("service_name");
		String sid = (String) properties.get("sid");
		String username = (String) properties.get("username");
		String password = (String) properties.get("password");
		if (name == null || host == null || username == null || password == null || port == null || serviceName == null) {
			throw new ConfigurationException("'name', 'host', 'user' and 'password' cannot be null.");
		}

		return new OracleAgent(name, host, port, sid, serviceName, username, password, readMetrics());
	}

	public List<Metric> readMetrics() {
		List<Metric> metrics = new ArrayList<>();
		ObjectMapper objectMapper = new ObjectMapper();<commit_msg>Adding better error handling for plugin configuration<commit_after>package com.truemarkit.newrelic.oracle;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.netradius.commons.lang.StringHelper;
import com.truemarkit.newrelic.oracle.model.Metric;
import com.newrelic.metrics.publish.Agent;
import com.newrelic.metrics.publish.AgentFactory;
import com.newrelic.metrics.publish.configuration.ConfigurationException;
import lombok.extern.slf4j.Slf4j;

import java.io.File;
import java.util.*;

/**
 * @author <NAME>
 */
@Slf4j
public class OracleAgentFactory extends AgentFactory {

	@Override
	public Agent createConfiguredAgent(Map<String, Object> properties) throws ConfigurationException {
		String name = (String) properties.get("name");
		if (StringHelper.isEmpty(name)) {
			throw new ConfigurationException("name may not be empty");
		}
		String host = (String) properties.get("host");
		if (StringHelper.isEmpty(host)) {
			throw new ConfigurationException("host may not be empty");
		}
		String port = (String) properties.get("port");
		if (StringHelper.isEmpty(port)) {
			throw new ConfigurationException("port may not be empty");
		}
		String serviceName = (String) properties.get("service_name");
		String sid = (String) properties.get("sid");
		if (StringHelper.isEmpty(serviceName) && StringHelper.isEmpty(sid)) {
			throw new ConfigurationException("service_name or sid must have a value");
		}
		String username = (String) properties.get("username");
		if (StringHelper.isEmpty(username)) {
			throw new ConfigurationException("username may not be empty");
		}
		String password = (String) properties.get("password");
		if (StringHelper.isEmpty(password)) {
			throw new ConfigurationException("password may not be empty");
		}
		return new OracleAgent(name, host, port, sid, serviceName, username, password, readMetrics());
	}

	public List<Metric> readMetrics() {
		List<Metric> metrics = new ArrayList<>();
		ObjectMapper objectMapper = new ObjectMapper();
{'fraction_non_alphanumeric': 0.12691218130311616, 'fraction_numerical': 0.0016997167138810198, 'mean_word_length': 5.649717514124294, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, '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': '6744507', 'n_tokens_mistral': 1063, 'n_tokens_neox': 990, 'n_words': 258}