jeudi 29 septembre 2016

Design Pattern or Design for A workflow that has multiple inputs

What will be a good design or design pattern for a workflow like this. Due to time constraints I had to quickly code a workflow as seen below a few months ago. Now I am looking at refactoring it.

            SwfEventInitOutput swfEventInitOutput = EventInit(request);

            SwfAuthorisationOutput swfAuthorisationOutput = Authorisation(request, swfEventInitOutput);

            if (swfAuthorisationOutput.getResultCode() != CommonResult.SUCCESS.getResultCode()) {
                return processCCExceptionResponse(request, swfAuthorisationOutput.getResultCode(), null, false, null, swfEventInitOutput, swfAuthorisationOutput, null);
            }

            SwfLocationDetectionOutput swfLocationDetectionOutput = LocationDetection(request, swfEventInitOutput, swfAuthorisationOutput);
            if (swfLocationDetectionOutput.getResultCode() != null && swfLocationDetectionOutput.getResultCode() != 0) {
                return processCCExceptionResponse(request, swfLocationDetectionOutput.getResultCode(), null, false, null, swfEventInitOutput, swfAuthorisationOutput, swfLocationDetectionOutput);
            }





.....

   // here it prepares the input to the flow and returns the output 
   private SwfEventInitOutput EventInit(ProcessCCRequest request) {
        SwfEventInitInput eventInitInput = new SwfEventInitInput();
        eventInitInput.setTransactionId(request.getTransactionId());
        eventInitInput.setNetworkEvent(request.getNetworkEvent());
        eventInitInput.setSubscriberId(request.getSubscriberId());

        SwfEventInit eventInit = gyWorkflowFactory.getSwfEventInit();
        SwfEventInitOutput swfEventInitOutput = eventInit.execute(eventInitInput);

        return swfEventInitOutput;

    }

1) Some workflows need more than an output from two different flows for example SwfLocationDetection , or more (not shown above)

2) The chain is something like this

  • if successful (resultCode == 0) EventInit->Authorisation->LocationDetection->FlowX->FlowZ->CcaDp

and if failure(i.e resultCode !=0)

  • failure at Authorisation: EventInit->Authorisation->CcaDp
  • failure at LocationDetection:
    EventInit->Authorisation->LocationDetection->CcaDp

3) here are interfaces

public interface SwfInput {

}


public interface SwfOutput {
    Long resultCode;
}

so for example

public SwfEventInitOutput implements SwfOutput {
    Long resultCode;

}

public SwfEventInitInput implements SwfInput {

}




public interface GyWorkflow<I extends SwfInput, O extends SwfOutput> {

    public O execute(I input);

}
so 


public class SwfEventInit extends AbstractWorkflow<SwfEventInitInput, SwfEventInitOutput> {
     public SwfEventInitOutput execute (SwfEventInitInput input) {
}

Aucun commentaire:

Enregistrer un commentaire