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

org.etlunit.feature.informatica.InformaticaFileProducer Maven / Gradle / Ivy

There is a newer version: 1.6.9
Show newest version
package org.etlunit.feature.informatica;

import org.etlunit.feature.file.FileProducer;

import javax.inject.Inject;
import java.io.File;

public class InformaticaFileProducer implements FileProducer
{
	private InformaticaConfiguration informaticaConfiguration;
	private InformaticaRuntimeSupport informaticaRuntimeSupport;

	@Inject
	public void setInformaticaRuntimeSupport(InformaticaRuntimeSupport support)
	{
		informaticaRuntimeSupport = support;
	}

	@Inject
	public void receiveInformaticaConfiguration(InformaticaConfiguration ic)
	{
		informaticaConfiguration = ic;
	}

	public String getName()
	{
		return "informatica";
	}

	public File locateFile(String reference)
	{
		return locateFileWithClassifierAndDomain(reference, null, informaticaConfiguration.getDefaultDomain());
	}

	public File locateFileWithClassifier(String reference, String classifier)
	{
		return locateFileWithClassifierAndDomain(reference, classifier, informaticaConfiguration.getDefaultDomain());
	}

	public File locateFileWithContext(String reference, String context)
	{
		return locateFileWithClassifierAndDomain(reference, null, informaticaConfiguration.getDomains().get(context));
	}

	public File locateFileWithClassifierAndContext(String reference, String classifier, String context)
	{
		return locateFileWithClassifierAndDomain(reference, classifier, informaticaConfiguration.getDomains().get(context));
	}

	private File locateFileWithClassifierAndDomain(String reference, String classifier, InformaticaDomain domain)
	{
		// grab the remote workspace root
		if (domain == null)
		{
			domain = informaticaConfiguration.getDefaultDomain();
		}

		File root = domain.getWorkingRoot();
		File subLocation = null;

		// grab the sub directory by classifier
		if (classifier == null || classifier.equals("target"))
		{
			subLocation = informaticaRuntimeSupport.getTgtFilesRemote(domain);
		}
		else if (classifier.equals("source"))
		{
			subLocation = informaticaRuntimeSupport.getSrcFilesRemote(domain);
		}
		else if (classifier.equals("lookup"))
		{
			subLocation = informaticaRuntimeSupport.getLkpFilesRemote(domain);
		}
		else
		{
			throw new IllegalArgumentException("Invalid classifier: " + classifier);
		}

		if (!subLocation.exists())
		{
			throw new IllegalStateException("Directory no longer exists: " + subLocation.getAbsolutePath());
		}

		return new File(subLocation, reference);
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy