/* ----------------------------------------
 * Origin  : GFI INFORMATIQUE 
 * Project : CDPP Propagation Tool 
 * ----------------------------------------
 * History 
 * Version : 01/05/2015 : SCA : V2.1
 * ----------------------------------------
 */
package fr.tlse.irap.server.frontServices;

import java.util.Date;

import javax.jws.WebMethod;
import javax.jws.WebService;

import org.apache.log4j.Logger;

import fr.tlse.irap.fit.FitCatalog;
import fr.tlse.irap.fit.FitImages;
import fr.tlse.irap.fit.IFit;
import fr.tlse.irap.server.serviceDAO.IAsciiDAO;
import fr.tlse.irap.server.serviceDAO.IImageDAO;
import fr.tlse.irap.tool.radial.CMEType;

@WebService(endpointInterface = "fr.tlse.irap.fit.IFit")
public class FitImpl implements IFit {
	private static final Logger logger = Logger.getLogger(FitImpl.class);

	private IAsciiDAO asciiDAO;
	private IImageDAO imageDAO;

	@WebMethod
	public FitCatalog fetchFitsCME(Date t1, Date t2, boolean fromLinkcat, CMEType cmeType, String sourceName) {

		logger.info("getFits : t1=" + t1 + " t2=" + t2 + " CME Type=" + cmeType + " sourceName=" + sourceName);

		FitCatalog fitCatalog = null;
		try {
			if (fromLinkcat) {
				fitCatalog = new FitCatalog(asciiDAO.loadLinkcatFitsCME(t1, t2, cmeType, sourceName));
			}
			else {
				fitCatalog = new FitCatalog(asciiDAO.loadFitsCME(t1, t2, cmeType, sourceName));
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return fitCatalog;
	}

	@WebMethod
	public FitCatalog fetchFitsCIR(Date t1, Date t2, String sourceName) {

		logger.info("getFits : t1=" + t1 + " t2=" + t2 + " sourceName=" + sourceName);

		FitCatalog fitCatalog = null;
		try {
			fitCatalog = new FitCatalog(asciiDAO.loadFitsCIR(t1, t2, sourceName));
		} catch (Exception e) {
			e.printStackTrace();
		}
		return fitCatalog;
	}

	@Override
	public FitImages fetchImagesCIR(Date initialTime, String probeName) {

		logger.info("getFits : initialTime=" + initialTime);
		
		FitImages fitImages = null;
		try {
			fitImages = new FitImages(imageDAO.loadPlotCIR(initialTime, probeName), imageDAO.loadErrorPlotCIR(initialTime, probeName));
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return fitImages;
	}

	@Override
	public FitImages fetchImagesCME(Date initialTime, String probeName) {

		logger.info("getFits : initialTime=" + initialTime);
		
		FitImages fitImages = null;
		try {
			fitImages = new FitImages(imageDAO.loadPlotCME(initialTime, probeName), imageDAO.loadErrorPlotCME(initialTime, probeName));
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return fitImages;
	}

	public IAsciiDAO getAsciiDAO() {
		return asciiDAO;
	}

	public void setAsciiDAO(IAsciiDAO asciiDAO) {
		this.asciiDAO = asciiDAO;
	}

	public IImageDAO getImageDAO() {
		return imageDAO;
	}

	public void setImageDAO(IImageDAO imageDAO) {
		this.imageDAO = imageDAO;
	}

}
