# Select Question, Write Test, Issue Regret Letter Tasks

  • Edit DlFlow.kflow and change insert the below content to change the DrivingLicence flow.
role-ref RTO("rto"), Applicant("applicant")

flow DrivingLicence {
document(applicantId:String, firstName:String,lastName:String,  age:Int, reviewOkay:Boolean = `false`,
    first:Int?, ^second:Int?, result:Int?) 

task ReviewApplication {
  input(firstName, lastName, age) display-id("${document.firstName} ${document.lastName}")
  output(reviewOkay)
  realizer manual(RTO) distribution(system)
}
task SelectQuestion {
  output(first!,^second!)
  realizer auto
}

task WriteTest {
  input(applicantId, first!,^second!) display-id("${document.firstName} ${document.lastName}")
  output(result!)
    realizer manual(Applicant) distribution(custom)
} 

task IssueRegretLetter {
    input(firstName)
    realizer auto
}
  
net DL {
  init-document(applicantId,firstName,lastName, age)
  START out (ReviewApplication)
  connector C1 in(ReviewApplication) out select {
    case  applicationFine => `reviewOkay` => SelectQuestion
    case default => IssueRegretLetter
  }
  connector C2 in(SelectQuestion) out(WriteTest)
  END in any(IssueRegretLetter,WriteTest)
}

}
  • SelectQuestion, IssueRegretLetter are 'auto' tasks, SelectQuestionTaskCode, IssueRegretLetterTaskCode gets generated, we need to write code so that they will get executed automatically.
  • SelectQuestionTaskCode sets the question with addition of two random number first and second.
  • Edit SelectQuestionTaskCode in idea, and replace execute method with the following,
def execute(taskId:Id, input:Input): Output = {
  import scala.util.Random
  Output(first = Random.nextInt(5), second = Random.nextInt(10))

}
  • Edit IssueRegretLetterTaskCode in idea, and replace execute method with the following,
def execute(taskId:Id, input:Input): Output = {
  println(s"Issue Regret Letter to ${input.firstName}")
  Output()
}
  • WriteTest task has distribution custom, so we need to let it know how the custom allocation done
  • Edit WriteTestTaskAllocationCode and replace allocate method with the following,
def allocate(taskId: Id, input: WriteTestTask.Input): Option[String] =  input.applicantId.option 
  • $compile.
  • $run.

# Execute Flow

Lets execute phase II task added to the flow

  • Go to the browser, and localhost:9000/monitorview.
  • Enter username and password rto/rtorto (rto user can create the flow).
  • Go to Team tab and click on + button next to the team name.
  • In Create Flow page select the net DL, application Id as johndoe,and First name as Steve ,Last name as Martin and age as 24.
  • Submit will create the flow, and a review Application task (notice the task is allocated to rto).
  • Go to localhost:9000/benchview to see the task allocated to rto.
  • Click on the task display as Steve Martin.
  • Start the task by clicking on START button, check output Review Okay as true, and COMPLETE.
  • If you check output Review Okay as false,then as a result of the Connector C1, IssueRegretLetter Task will get executed and End the flow, since the flow ends in any of the task IssueregretLetter or WriteTest.
  • Now browse localhost:9000/monitorview, notice SelectQuestion auto task got completed automatically, and WriteTest task is assigned to johndoe.
  • Go to localhost:9000/benchview but we need to login as johndoe to complete the task,so logout, and login again in benchview as johndoe/johndoe(may use a different browser).
  • WriteTest task is listed, start the task. Add the numbers First and Second and enter the Result. Click on Save and Complete.
  • Logout and login as rto/rto (If a different browser is used then come back to the previous one).
  • Go to http://localhost:9000/reportview#/flow/search and select Flow Name as DrivingLicence from the dropdown.
  • Click on search result, and see the details of the flow just got completed along with all the completed tasks.

That concludes the step two which has a flow with auto task and manual task with custom allocation. Also connector is conditional, and flow can end in any of the task completion.