All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.bigdime.core.config.HandlerConfigReader Maven / Gradle / Ivy

There is a newer version: 0.9.3
Show newest version
/**
 * Copyright (C) 2015 Stubhub.
 */
package io.bigdime.core.config;

import java.util.HashMap;
import java.util.Map;

import org.codehaus.jackson.JsonNode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import io.bigdime.alert.LoggerFactory;
import io.bigdime.core.AdaptorConfigurationException;
import io.bigdime.core.commons.AdaptorLogger;
import io.bigdime.core.commons.JsonHelper;
import io.bigdime.core.config.AdaptorConfigConstants.HandlerConfigConstants;

@Component
public final class HandlerConfigReader {
	private static final AdaptorLogger logger = new AdaptorLogger(LoggerFactory.getLogger(HandlerConfigReader.class));

	@Autowired
	private JsonHelper jsonHelper;

	public HandlerConfig readHandlerConfig(final JsonNode handlerNode) throws AdaptorConfigurationException {
		logger.debug("reading handler config", "reading handler config");
		final HandlerConfig handlerConfig = new HandlerConfig();

		final String name = jsonHelper.getRequiredStringProperty(handlerNode, HandlerConfigConstants.NAME);
		final String description = jsonHelper.getRequiredStringProperty(handlerNode,
				HandlerConfigConstants.DESCRIPTION);
		final String handlerClass = jsonHelper.getRequiredStringProperty(handlerNode,
				HandlerConfigConstants.HANDLER_CLASS);
		handlerConfig.setName(name);
		handlerConfig.setDescription(description);
		final Map handlerProperties = new HashMap<>();
		handlerConfig.setHandlerProperties(handlerProperties);// set a not null

		final JsonNode properties = jsonHelper.getOptionalNodeOrNull(handlerNode, HandlerConfigConstants.PROPERTIES);
		if (properties != null)
			handlerProperties.putAll(jsonHelper.getNodeTree(properties));

		logger.debug("reading handler config", "handlerProperties=\"{}\"", handlerProperties);

		handlerConfig.setHandlerClass(handlerClass);

		return handlerConfig;
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy