/* ----------------------------------------
 * Origin  : GFI INFORMATIQUE 
 * Project : CDPP Propagation Tool 
 * ----------------------------------------
 * History 
 * Version : 01/05/2015 : SCA : V2.1
 * Version : 15/09/2016 : SCA : V2.2 (PSWS-H2020)
 *  Set a default J-map image if not exists
 * ----------------------------------------
 */
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.server.serviceDAO.IAsciiDAO;
import fr.tlse.irap.server.serviceTool.ICorotationTool;
import fr.tlse.irap.server.serviceTool.IRadialTool;
import fr.tlse.irap.server.serviceTool.ISepTool;
import fr.tlse.irap.spaceElement.SpaceElement;
import fr.tlse.irap.tool.ITool;
import fr.tlse.irap.tool.corotation.Corotation;
import fr.tlse.irap.tool.corotation.CorotationCatalog;
import fr.tlse.irap.tool.corotation.CorotationEnd;
import fr.tlse.irap.tool.radial.CMEType;
import fr.tlse.irap.tool.radial.Radial;
import fr.tlse.irap.tool.radial.RadialCatalog;
import fr.tlse.irap.tool.radial.RadialEnd;
import fr.tlse.irap.tool.sep.Sep;
import fr.tlse.irap.tool.sep.SepEnd;

@WebService(endpointInterface = "fr.tlse.irap.tool.ITool")
public class ToolImpl implements ITool {
	private static final Logger logger = Logger.getLogger(ToolImpl.class);
	
	private IRadialTool radialTool;
	private ICorotationTool corotationTool;
	private ISepTool sepTool;
	private IAsciiDAO asciiDAO;

	public ToolImpl() {
	}
	
	@WebMethod
	public RadialEnd computeRadial(Radial radial, SpaceElement endElement) {
		RadialEnd radialEnd = null;
		try {
			radialEnd = radialTool.computeRadial(radial, endElement);
		} catch (Exception e) {
			return radialEnd;
		}
		logger.info("Stop computing Radial ");
		return radialEnd;
	}

	@WebMethod
	public CorotationEnd computeCorotation(Corotation corotation, SpaceElement endElement) {
		CorotationEnd corotEnd = null;
		try {
			corotEnd = corotationTool.computeCorotation(corotation, endElement);
		} catch (Exception e) {
			e.printStackTrace();
			return corotEnd;
		}
		//logger.info("Stop computing Corotation ");
		return corotEnd;
	}

	@WebMethod
	public SepEnd computeSep(Sep sep, SpaceElement endElement) {
		SepEnd sepEnd = null;
		try {
			sepEnd = sepTool.computeSep(sep, endElement);
		} catch (Exception e) {
			e.printStackTrace();
			return sepEnd;
		}
		//logger.info("Stop computing SEP ");
		return sepEnd;
	}

	@WebMethod
	public RadialCatalog getRadialCatalog(Date t1, Date t2, int targetId, CMEType cmeType, String observer, double extent) {

		RadialCatalog radialCatalog = null;
		try {
			radialCatalog = new RadialCatalog(asciiDAO.loadRadialCMEs(t1, t2, targetId, cmeType, observer, extent));
		} catch (Exception e) {
			e.printStackTrace();
		}
		return radialCatalog;
	}

	@WebMethod
	public RadialCatalog getLinkcatCatalog(Date t1, Date t2, CMEType cmeType, String observer, double extent) {

		RadialCatalog radialCatalog = null;
		try {
			radialCatalog = new RadialCatalog(asciiDAO.loadLinkcatCMEs(t1, t2, cmeType, observer, extent));
		} catch (Exception e) {
			e.printStackTrace();
		}
		return radialCatalog;
	}

	@WebMethod
	public CorotationCatalog getCorotationCatalog(Date t1, Date t2, int targetId, String observer, double spread) {
		CorotationCatalog corotationCatalog = null;
		try {
			corotationCatalog = new CorotationCatalog(asciiDAO.loadCorotationCIRs(t1, t2, targetId, observer, spread));
		} catch (Exception e) {
			e.printStackTrace();
		}
		return corotationCatalog;
	}

	// getters/setters for SPRING instanciation
	public IRadialTool getRadialTool() {
		return radialTool;
	}
	public void setRadialTool(IRadialTool radialTool) {
		this.radialTool = radialTool;
	}
	public ICorotationTool getCorotationTool() {
		return corotationTool;
	}
	public void setCorotationTool(ICorotationTool corotationTool) {
		this.corotationTool = corotationTool;
	}
	public ISepTool getSepTool() {
		return sepTool;
	}
	public void setSepTool(ISepTool sepTool) {
		this.sepTool = sepTool;
	}
	public IAsciiDAO getAsciiDAO() {
		return asciiDAO;
	}
	public void setAsciiDAO(IAsciiDAO asciiDAO) {
		this.asciiDAO = asciiDAO;
	}

}
