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

com.botronsoft.cmj.spitools.impl.transformation.SingleValueArgumentProcessor Maven / Gradle / Ivy

There is a newer version: 1.3.1
Show newest version
package com.botronsoft.cmj.spitools.impl.transformation;

import java.util.Optional;

import org.apache.log4j.Logger;

import com.botronsoft.cmj.spi.configuration.ExportContext;
import com.botronsoft.cmj.spi.configuration.ImportContext;
import com.botronsoft.cmj.spitools.impl.transformation.configuration.Configuration;
import com.botronsoft.cmj.spitools.impl.transformation.parsers.SingleValueArgumentParser;
import com.botronsoft.cmj.spitools.impl.transformation.transformers.ArgumentTransformer;

class SingleValueArgumentProcessor implements ArgumentProcessor {

	private static final Logger log = Logger.getLogger(SingleValueArgumentProcessor.class);

	private final Configuration configuration;
	private final SingleValueArgumentParser singleValueParser;
	private final ArgumentTransformer transformer;

	SingleValueArgumentProcessor(Configuration configuration, SingleValueArgumentParser singleValueParser,
			ArgumentTransformer transformer) {
		this.configuration = configuration;
		this.singleValueParser = singleValueParser;
		this.transformer = transformer;
	}

	@Override
	public String processArgumentForExport(String value, ExportContext exportContext) {
		Optional valueOptional = singleValueParser.parse(value, configuration);
		if (!valueOptional.isPresent()) {
			log.debug(String.format("Ignoring value for argument '%s': '%s'", configuration.getArgumentName(), value));
			return value;
		}

		return transformer.transformArgumentForExport(value, configuration, exportContext.getReferenceCollector());
	}

	@Override
	public String processArgumentForImport(String value, ImportContext importContext) {
		Optional valueOptional = singleValueParser.parse(value, configuration);
		if (!valueOptional.isPresent()) {
			log.debug(String.format("Ignoring value for argument '%s': '%s'", configuration.getArgumentName(), value));
			return value;
		}

		return transformer.transformArgumentForImport(value, configuration, importContext.getReferenceLookup());
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy