package com.ebmwebsourcing.easybpel.usecase.mail;

import javax.xml.namespace.QName;

import com.ebmwebsourcing.easybpel.model.bpel.api.BPELException;
import com.ebmwebsourcing.easybpel.model.bpel.api.message.BPELExternalMessage;
import com.ebmwebsourcing.easybpel.model.bpel.impl.message.BPELExternalMessageImpl;
import com.ebmwebsourcing.easyviper.core.api.CoreException;
import com.ebmwebsourcing.easyviper.environment.test.env.api.Operation;
import com.ebmwebsourcing.easyviper.environment.test.env.api.ProviderEndpoint;
import com.ebmwebsourcing.easyviper.environment.test.env.api.Service;
import com.ebmwebsourcing.easyviper.environment.test.env.impl.AbstractServiceImpl;
import com.ebmwebsourcing.easyviper.environment.test.env.impl.OperationImpl;

public class SigabaseService extends AbstractServiceImpl implements Service {


	public SigabaseService(ProviderEndpoint pep) throws BPELException {
		super(pep);
		this.setName(new QName("http://www.sigabase.service", "ServicesSigabaseService"));

		// Create operations
		insertAffectationAgreee();
		getInfoAffectation();
	}

	private void insertAffectationAgreee() throws BPELException {
		try {
			Operation insertAffectationAgreee = new OperationImpl("insertAffectationAgreee", Operation.IN_OUT, this);
			this.addOperation(insertAffectationAgreee);


			BPELExternalMessage in1 = new BPELExternalMessageImpl();
			in1.setService(this.getName());
			in1.setEndpoint(this.getProviderEndpoint().getName());
			in1.setQName(new QName("http://www.sigabase.service", "insertAffectationAgreeeRequest1"));
			in1.setMessage("" +
					"<ns:insertAffectationAgreee xmlns:ns=\"http://www.sigabase.service\">" +
					"  <nid xmlns:tns=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:type=\"tns:string\">312</nid>" +
					"</ns:insertAffectationAgreee>" 
			);
			BPELExternalMessage out1 = new BPELExternalMessageImpl();
			out1.setService(this.getName());
			out1.setEndpoint(this.getProviderEndpoint().getName());
			out1.setQName(new QName("http://www.sigabase.service", "insertAffectationAgreeeResponse1"));
			out1.setMessage("" +
					"<sig:insertAffectationAgreeeResponse1 soapenv:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:sig=\"http://www.sigabase.service\" xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\">" +
					"         <insertAffectationAgreeeReturn xsi:type=\"sig:ArrayOf_xsd_anyType\" soapenc:arrayType=\"xsd:anyType[]\"/>" +
					"</sig:insertAffectationAgreeeResponse1>" 
			);
			insertAffectationAgreee.addMessageExchangeInstances(in1, out1, null);

			BPELExternalMessage in2 = new BPELExternalMessageImpl();
			in2.setService(this.getName());
			in2.setEndpoint(this.getProviderEndpoint().getName());
			in2.setQName(new QName("http://www.sigabase.service", "insertAffectationAgreeeRequest1"));
			in2.setMessage("" +
					"<ns:insertAffectationAgreee xmlns:ns=\"http://www.sigabase.service\">" +
					"  <nid xmlns:tns=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:type=\"tns:string\">313</nid>" +
					"</ns:insertAffectationAgreee>" 
			);
			BPELExternalMessage out2 = new BPELExternalMessageImpl();
			out2.setService(this.getName());
			out2.setEndpoint(this.getProviderEndpoint().getName());
			out2.setQName(new QName("http://www.sigabase.service", "insertAffectationAgreeeResponse1"));
			out2.setMessage("" +
					"<sig:insertAffectationAgreeeResponse1 soapenv:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:sig=\"http://www.sigabase.service\" xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\">" +
					"         <insertAffectationAgreeeReturn xsi:type=\"sig:ArrayOf_xsd_anyType\" soapenc:arrayType=\"xsd:anyType[]\">" +
					"             <item xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:type=\"xsd:int\">4</item>" +
					"             <item xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:type=\"xsd:int\">5</item>" +
					"         </insertAffectationAgreeeReturn>" +
					"</sig:insertAffectationAgreeeResponse1>" 
			);
			insertAffectationAgreee.addMessageExchangeInstances(in2, out2, null);


		} catch (CoreException e) {
			throw new BPELException(e);
		}
	}


	private void getInfoAffectation() throws BPELException {
		try {
			Operation getInfoAffectation = new OperationImpl("getInfoAffectation", Operation.IN_OUT, this);
			this.addOperation(getInfoAffectation);


			BPELExternalMessage in1 = new BPELExternalMessageImpl();
			in1.setService(this.getName());
			in1.setEndpoint(this.getProviderEndpoint().getName());
			in1.setQName(new QName("http://www.sigabase.service", "getInfoAffectationRequest1"));
			in1.setMessage("" +
					"<ns:getInfoAffectation xmlns:ns=\"http://www.sigabase.service\">" +
					"  <id xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:type=\"xs:long\" />" +
					"</ns:getInfoAffectation>" 
			);
			BPELExternalMessage out1 = new BPELExternalMessageImpl();
			out1.setService(this.getName());
			out1.setEndpoint(this.getProviderEndpoint().getName());
			out1.setQName(new QName("http://www.sigabase.service", "getInfoAffectationResponse1"));
			out1.setMessage("" +
					"<ser:getInfoAffectationResponse xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ser=\"http://www.sigabase.service\" soapenv:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">" +
					"       <getInfoAffectationReturn xsi:type=\"sig:affectationIHM\" xmlns:sig=\"http://sigabase.air.defense.gouv.fr.wsnamespace\">" +
					"            <annotationAffectation xsi:type=\"soapenc:string\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">Reorganisation</annotationAffectation>" +
					"            <base xsi:type=\"soapenc:string\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">BA217 - BRETIGNY</base>" +
					"            <causeAffectation xsi:type=\"soapenc:string\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">Interne base</causeAffectation>" +
					"            <commandement xsi:type=\"soapenc:string\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">53  - Commandement du soutien des forces aeriennes</commandement>" +
					"            <dateDebut xsi:type=\"xsd:dateTime\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">2008-11-20T23:00:00.000Z</dateDebut>" +
					"            <dateFin xsi:nil=\"true\" xsi:type=\"xsd:dateTime\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"/>" +
					"            <dateRef xsi:type=\"xsd:dateTime\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">2008-11-20T23:00:00.000Z</dateRef>" +
					"            <decideurAffectation xsi:type=\"soapenc:string\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">Commandement air des systemes de surveillance, d information et de communications</decideurAffectation>" +
					"            <etat xsi:type=\"soapenc:string\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">Agreee</etat>" +
					"            <mentionAffectation xsi:type=\"soapenc:string\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">Service</mentionAffectation>" +
					"            <nia xsi:type=\"soapenc:string\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">AL21215</nia>" +
					"            <nid xsi:type=\"soapenc:string\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">04 560 30663</nid>" +
					"            <nomFamille xsi:type=\"soapenc:string\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">Collin</nomFamille>" +
					"            <nomUsage xsi:type=\"soapenc:string\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">Collin</nomUsage>" +
					"			 <poste xsi:type=\"soapenc:string\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">Sans poste</poste>" +
					"			 <prenom xsi:type=\"soapenc:string\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">Matthieu</prenom>" +
					"			 <travail xsi:nil=\"true\" xsi:type=\"soapenc:string\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"/>" +
					"			 <typeAffectation xsi:type=\"soapenc:string\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">Active</typeAffectation>" +
					"			 <unite xsi:type=\"soapenc:string\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">CSIA              - CENTRE DES SYSTEMES D'INFORMATION AIR</unite>" +
					"		</getInfoAffectationReturn>" +
					"</ser:getInfoAffectationResponse>" 
			);
			getInfoAffectation.addMessageExchangeInstances(in1, out1, null);

		} catch (CoreException e) {
			throw new BPELException(e);
		}
	}

}
