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 SendMailService extends AbstractServiceImpl implements Service {


	public SendMailService(ProviderEndpoint pep) throws BPELException {
		super(pep);
		this.setName(new QName("http://acme.fr", "SendMailDefense"));

		// Create  operation
		send();
	}

	private void send() throws BPELException {
		try {
			Operation send = new OperationImpl("send", Operation.IN_ONLY, this);
			this.addOperation(send);

			BPELExternalMessage in1 = new BPELExternalMessageImpl();
			in1.setService(this.getName());
			in1.setEndpoint(this.getProviderEndpoint().getName());
			in1.setQName(new QName("http://petals.ow2.org/components/mail/version-3.0", "sendRequest"));
			in1.setMessage("" +
					"<ns3:sendRequest xmlns:ns3=\"http://petals.ow2.org/components/mail/version-3.0\">" +
					"  <tns:mail xmlns:tns=\"http://petals.ow2.org/components/mail/version-3.0\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:type=\"tns:MailType\">" +
					"    <tns:from xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xsi:type=\"xsd:string\">no-reply@ebmwebsourcing.org</tns:from>" +
					"    <tns:reply xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xsi:type=\"xsd:string\">no-reply@ebmwebsourcing.org</tns:reply>" +
					"    <tns:to xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xsi:type=\"xsd:string\">nicolas.salatge@ebmwebsourcing.com</tns:to>" +
					"    <tns:subject xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xsi:type=\"xsd:string\">Notification Affectation: Administre</tns:subject>" +
					"    <tns:body>Affectation id: 04 560 30663</tns:body>" +
					"  </tns:mail>" +
					"</ns3:sendRequest>"
			);
			

			send.addMessageExchangeInstances(in1, null, null);

			
			BPELExternalMessage in2 = new BPELExternalMessageImpl();
			in2.setService(this.getName());
			in2.setEndpoint(this.getProviderEndpoint().getName());
			in2.setQName(new QName("http://petals.ow2.org/components/mail/version-3.0", "sendRequest"));
			in2.setMessage("" +
					"<ns3:sendRequest xmlns:ns3=\"http://petals.ow2.org/components/mail/version-3.0\">" +
					"  <tns:mail xmlns:tns=\"http://petals.ow2.org/components/mail/version-3.0\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:type=\"tns:MailType\">" +
					"    <tns:from xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xsi:type=\"xsd:string\">no-reply@ebmwebsourcing.org</tns:from>" +
					"    <tns:reply xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xsi:type=\"xsd:string\">no-reply@ebmwebsourcing.org</tns:reply>" +
					"    <tns:to xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xsi:type=\"xsd:string\">nicolas.salatge@ebmwebsourcing.com</tns:to>" +
					"    <tns:subject xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xsi:type=\"xsd:string\">Notification Affectation: Chef</tns:subject>" +
					"    <tns:body>Affectation id: 04 560 30663</tns:body>" +
					"  </tns:mail>" +
					"</ns3:sendRequest>"
			);
			

			send.addMessageExchangeInstances(in2, null, null);

			
		} catch (CoreException e) {
			throw new BPELException(e);
		}
	}
	
	

}
