package processing;

import com.bea.jpd.ProcessDefinition;

import com.bea.jpd.JpdContext;


@com.bea.wli.jpd.Process(process = 
"<process name=\"TestProcess\">" + 
"  <onException name=\"OnException\">" + 
"    <perform name=\"Print The Exception\" method=\"printException\"/>" + 
"  </onException>" + 
"  <clientRequest name=\"Client Request\" method=\"clientRequest\"/>" + 
"  <parallel name=\"Process External Request\">" + 
"    <branch name=\"Branch\">" + 
"      <controlSend name=\"Retrieve Case Number\" method=\"externalToInternalGetCaseNumber\"/>" + 
"    </branch>" + 
"    <branch name=\"Branch\">" + 
"      <controlSend name=\"convertApplicationData\" method=\"externalToInternalConvertApplicationData\"/>" + 
"    </branch>" + 
"  </parallel>" + 
"  <controlSend name=\"Create Approval Task for the Application\" method=\"appTaskControlIINewExternalApplication\"/>" + 
"  <eventChoice name=\"Manage Task\">" + 
"    <messageEvent name=\"Message Event\">" + 
"      <controlReceive name=\"Application Accepted\" method=\"appTaskControlII_onApplicationApprovedStep\"/>" + 
"    </messageEvent>" + 
"    <messageEvent name=\"Message Event\">" + 
"      <controlReceive name=\"Application Rejected\" method=\"appTaskControlII_onApplicationRejectedStep\"/>" + 
"    </messageEvent>" + 
"  </eventChoice>" + 
"  <clientCallback name=\"Successful Return\" method=\"successfulReturnCallbackHandler\"/>" + 
"</process>")
public class ProcessExternalApplication implements ProcessDefinition {


	

	@org.apache.beehive.controls.api.bean.Control
	private controls.AppTaskControlII appTaskControlII;

	public controls.AppTaskControlII.ApplicationRejected appRejected;

	public controls.AppTaskControlII.ApplicationApproved appProved;

	public controls.AppTaskControlII.ApprovalPending appPending;

	public java.lang.String caseNumber;

	@com.bea.wli.jpd.Transform
	private controls.ExternalToInternal externalToInternal;
	
	public org.openuri.temp.exampleApp.application.ExternalApplicationDocument externalApp;

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

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

	

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

	static final long serialVersionUID = 1;
	
	static final String PROCESS_LABEL = "Process External Applications Process"; 
	
	public void successfulReturnCallbackHandler() {
        // #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. #//
        System.out.println("---------------> return call made!");
    }

	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 appTaskControlIINewExternalApplication() throws Exception {
        // #START: CODE GENERATED - PROTECTED SECTION - you can safely add code above this comment in this method. #//
        // input transform
        // return method call
        this.appPending = appTaskControlII.NewExternalApplication(this.caseNumber, this.internalApp);
        // output transform
        // output assignments
        // #END  : CODE GENERATED - PROTECTED SECTION - you can safely add code below this comment in this method. #//
        appTaskControlII.setApplicationCaseId(this.caseNumber);
    }

	public @org.apache.beehive.controls.api.events.EventHandler(field = "appTaskControlII", eventSet = controls.AppTaskControlII.CustomCallback.class, eventName = "onApplicationApprovedStep")
	void appTaskControlII_onApplicationApprovedStep(controls.AppTaskControlII.ApplicationApproved step) {
        // #START: CODE GENERATED - PROTECTED SECTION - you can safely add code above this comment in this method. #//
        // input transform
        // parameter assignment
        this.appProved = step;
        // #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.AppTaskControlII.CustomCallback.class, eventName = "onApplicationRejectedStep")
	void appTaskControlII_onApplicationRejectedStep(controls.AppTaskControlII.ApplicationRejected step) {
        // #START: CODE GENERATED - PROTECTED SECTION - you can safely add code above this comment in this method. #//
        // input transform
        // parameter assignment
        this.appRejected = step;
        // #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 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("---------------> FN: "
				+ x0.getExternalApplication().getFirstName());
		System.out.println("---------------> LN: "
				+ x0.getExternalApplication().getLastName());
		System.out.println("---------------> CN: "
				+ x0.getExternalApplication().getCaseNumber());
		System.out.println("---------------> PC: "
				+ x0.getExternalApplication().getAdress().getPostalCode());
		System.out.println("---------------> SN: "
				+ x0.getExternalApplication().getAdress().getStreetName());
		System.out.println("---------------> S#: "
				+ x0.getExternalApplication().getAdress().getStreetNumber());
	}

	@com.bea.wli.jpd.CallbackInterface
	public interface Callback extends com.bea.control.ServiceBrokerControl {
		public void onSuccess();
	}

	public void printException() throws Exception {

		this.context.getExceptionInfo().getException().printStackTrace();

    }

}
