package processing;

import com.bea.jpd.ProcessDefinition;

import com.bea.jpd.JpdContext;

import controls.ApplicationFileCtl;

@com.bea.wli.jpd.Process(process = 
"<process name=\"ProcessExternalApplication81\">" + 
"  <clientRequest name=\"Client Request\" method=\"clientRequest\"/>" + 
"  <parallel name=\"Process External Request\">" + 
"    <branch name=\"Branch\">" + 
"      <controlSend name=\"Retrieve Case Number\" method=\"externalToInternalGetCaseNumber\"/>" + 
"      <controlSend name=\"Record Case Number\" method=\"applicationInfoRecordCaseNumber\"/>" + 
"    </branch>" + 
"    <branch name=\"Branch\">" + 
"      <controlSend name=\"Transform to Internal Format\" method=\"externalToInternalConvertApplicationData\"/>" + 
"    </branch>" + 
"  </parallel>" + 
"  <controlSend name=\"Create the Approval Task for the Application \" method=\"appTaskControlIICreateTaskByName\"/>" + 
"  <eventChoice name=\"Manage Task\">" + 
"    <messageEvent name=\"Message Event\">" + 
"      <controlReceive name=\"Task Completed\" method=\"appTaskControlII_onTaskCompleted\"/>" + 
"      <controlSend name=\"createApplicationFile\" method=\"appFileCtlCreateApplicationFile\"/>" + 
"    </messageEvent>" + 
"    <messageEvent name=\"Message Event\">" + 
"      <controlReceive name=\"Task Overdue\" method=\"appTaskControlII_onTaskOverdue\"/>" + 
"    </messageEvent>" + 
"  </eventChoice>" + 
"  <clientCallback name=\"Successful Return\" method=\"clientResponseCallbackHandler\"/>" + 
"</process>")
public class ProcessExternalApplication81 implements ProcessDefinition {

	@org.apache.beehive.controls.api.bean.Control
	private controls.ApplicationInfo applicationInfo;

	public java.lang.String appFileReturn;

	@org.apache.beehive.controls.api.bean.Control
	private controls.AppTaskControl appTaskControlII;
	
	@org.apache.beehive.controls.api.bean.Control
	private ApplicationFileCtl appFileCtl;

	@com.bea.wli.jpd.Callback
	public Callback callback;

	public java.util.Date overdueTime;

	public org.apache.xmlbeans.XmlObject taskResponse;

	public java.lang.String taskID;

	@com.bea.wli.jpd.Transform
	private controls.ExternalToInternal externalToInternal;

	public org.openuri.temp.exampleApp.application.ExternalApplicationDocument externalApp;

	@com.bea.wli.jpd.Context
	JpdContext context;

	public java.lang.String caseNumber;

	public org.openuri.temp.exampleApp.application.InternalApplicationDocument internalApp;

	static final long serialVersionUID = 1;

	static final String PROCESS_LABEL = "Process External Applications Process";

	public void clientRequest(
			org.openuri.temp.exampleApp.application.ExternalApplicationDocument x0) {
		context.setProcessLabel(PROCESS_LABEL);
		// #START: CODE GENERATED - PROTECTED SECTION - you can safely add code
		// above this comment in this method. #//
		// input transform
		// parameter assignment
		this.externalApp = x0;
		// #END : CODE GENERATED - PROTECTED SECTION - you can safely add code
		// below this comment in this method. #//
		System.out.println("-------------81> FN: "
				+ x0.getExternalApplication().getFirstName());
		System.out.println("-------------81> LN: "
				+ x0.getExternalApplication().getLastName());
		System.out.println("-------------81> CN: "
				+ x0.getExternalApplication().getCaseNumber());
		System.out.println("-------------81> PC: "
				+ x0.getExternalApplication().getAdress().getPostalCode());
		System.out.println("-------------81> SN: "
				+ x0.getExternalApplication().getAdress().getStreetName());

	}

	public void externalToInternalGetCaseNumber() throws Exception {
		// #START: CODE GENERATED - PROTECTED SECTION - you can safely add code
		// above this comment in this method. #//
		// input transform
		// return method call
		this.caseNumber = externalToInternal.getCaseNumber(this.externalApp);
		// output transform
		// output assignments
		// #END : CODE GENERATED - PROTECTED SECTION - you can safely add code
		// below this comment in this method. #//
	}

	public void externalToInternalConvertApplicationData() throws Exception {
		// #START: CODE GENERATED - PROTECTED SECTION - you can safely add code
		// above this comment in this method. #//
		// input transform
		// return method call
		this.internalApp = externalToInternal
				.convertApplicationData(this.externalApp);
		// output transform
		// output assignments
		// #END : CODE GENERATED - PROTECTED SECTION - you can safely add code
		// below this comment in this method. #//
	}

	public void appTaskControlIICreateTaskByName() throws Exception {
        // #START: CODE GENERATED - PROTECTED SECTION - you can safely add code above this comment in this method. #//
        // input transform
        // return method call
        this.taskID = appTaskControlII.createTaskByName(this.caseNumber);
        // output transform
        // output assignments
        // #END  : CODE GENERATED - PROTECTED SECTION - you can safely add code below this comment in this method. #//
        appTaskControlII.setRequest(this.externalApp);
        appTaskControlII.setResponse(this.externalApp);
    }

	public @org.apache.beehive.controls.api.events.EventHandler(field = "appTaskControlII", eventSet = controls.AppTaskControl.Callback.class, eventName = "onTaskOverdue")
	void appTaskControlII_onTaskOverdue(java.util.Date time) {
        // #START: CODE GENERATED - PROTECTED SECTION - you can safely add code above this comment in this method. #//
        // input transform
        // parameter assignment
        this.overdueTime = time;
        // #END  : CODE GENERATED - PROTECTED SECTION - you can safely add code below this comment in this method. #//
    }


	public @org.apache.beehive.controls.api.events.EventHandler(field = "appTaskControlII", eventSet = controls.AppTaskControl.Callback.class, eventName = "onTaskCompleted")
	void appTaskControlII_onTaskCompleted(org.apache.xmlbeans.XmlObject response) {
        // #START: CODE GENERATED - PROTECTED SECTION - you can safely add code above this comment in this method. #//
        // input transform
        // parameter assignment
        this.taskResponse = response;
        // #END  : CODE GENERATED - PROTECTED SECTION - you can safely add code below this comment in this method. #//
    }





	public void applicationInfoRecordCaseNumber() throws Exception {
        // #START: CODE GENERATED - PROTECTED SECTION - you can safely add code above this comment in this method. #//
        // input transform
        // method call
        applicationInfo.recordCaseNumber(this.caseNumber);
        // output transform
        // output assignments
        // #END  : CODE GENERATED - PROTECTED SECTION - you can safely add code below this comment in this method. #//
    }

	public void appFileCtlCreateApplicationFile() throws Exception {
        // #START: CODE GENERATED - PROTECTED SECTION - you can safely add code above this comment in this method. #//
        // input transform
        // return method call
        this.appFileReturn = appFileCtl.createApplicationFile(this.caseNumber, this.internalApp);
        // output transform
        // output assignments
        // #END  : CODE GENERATED - PROTECTED SECTION - you can safely add code below this comment in this method. #//
    }

	public void clientResponseCallbackHandler() {
		if(this.appTaskControlII.getResponse() != null)
		{
			System.out.println("------------> TASK RESP: " + this.appTaskControlII.getResponse().xmlText());
		}
		else
		{
			System.out.println("------------> TASK RESP: NULL");
		}
			
	
        // #START: CODE GENERATED - PROTECTED SECTION - you can safely add code above this comment in this method. #//
        // input transform
        // method call
        callback.onSuccess();
        // output transform
        // output assignments
        // #END  : CODE GENERATED - PROTECTED SECTION - you can safely add code below this comment in this method. #//
    }


	@com.bea.wli.jpd.CallbackInterface
	public interface Callback extends com.bea.control.ServiceBrokerControl {

		public void onSuccess();
	}

}
