I have the following issue,
I have a Seq[Future[ProcessStepTemplatesModel]]
and I want to remove the inner Future.
What I excpected to get is a Seq[ProcessStepTemplatesModel]
.
The complete code looks like this
Future.sequence {
processSteps.map { step => // This is a "for each" over a Seq[ProcessStepTemplatesModel]
val prerequisiteFuture = processStepPrerequisitesDTO.getProcessStepPrerequisiteProcessTemplateIds(step.id.get)
prerequisiteFuture.map(prereqTemplates => {
processTemplateDTO.getProessTemplatesForStepPreqrequsites(prereqTemplates).map(pres => {
step.stepPrerequisites ++Some(pres)
step
})
})
}
}
Thanks
UPDATE:
def getEditProcessTemplateData(processTemplateId: Int) = Action.async {
//Get all steps of this process templates
val stepIds: Future[Seq[Int]] = processTemplateDTO.getProcessStepTemplateIds(processTemplateId)
val process = for {
allApprovedProcessTemplates <- processTemplateDTO.getApprovedProcessTemplates //Get all approved process templates
processTemplate <- processTemplateDTO.getProcessTemplate(processTemplateId) // Get the Process Template
prerequisites <- getProcessTemplateForEdit(processPrerequisitesDTO.getProcessPrerequisiteProcessTemplateIdsByProcessTemplateId(processTemplateId))
postConditions <- getProcessTemplateForEdit(processPostConditionsDTO.getProcessPostConditionProcessTemplateIdsByProcessTemplateId(processTemplateId))
approvedProcessTemplate <- processTemplateDTO.getProcessTemplate(processTemplate.get.approveprocess)
trainedProcessTemplate <- processTemplateDTO.getProcessTemplate(processTemplate.get.trainingsprocess)
processSteps <- processTemplateDTO.getProcessStepTemplates(processTemplateId)
// Step prerequisites
processStepsPrerequisites <- getProcessStepsPrerequisites(stepIds)
processStepsPrerequisiteProcessTemplate <- getProcessStepsPrerequisiteProcessTemplate(stepIds)
processTemplatesForStepPrerequisites <- getProcessTemplateForStepPrerequisite(stepIds)
// Step post conditions
processStepsPostConditions <- getProcessStepsPostConditions(stepIds)
processStepPostConditionProcessTemplate <- getProcessStepPostConditionProcessTemplate(stepIds)
processTemplatesForStepPostConditions <- getProcessTemplateForStepPostCondition(stepIds)
// Derived processes
derivedProcesses <- getDerivedProcesses(stepIds)
processTemplatesForStepDerivedProcesses <- getProcessStepsDerivedProcesses(stepIds)
// Process to process step
processStepsTemplates_ProcessTemplates <- getProcessStepsTemplates_ProcessTemplates(stepIds)
processTemplatesForProcessTemplatesToProcessStep <- getProcessTemplateToProcessStepId(stepIds)
responsible <- raciProcessTemplateDTO.getResponsibleProcessTemplates(processTemplateId) // get all responsibles for this process template
accountable <- raciProcessTemplateDTO.getAccountableProcessTemplates(processTemplateId) // get all accountables for this process template
consulted <- raciProcessTemplateDTO.getConsultedProcessTemplates(processTemplateId) // get all consulted for this process template
informed <- raciProcessTemplateDTO.getInformedProcessTemplates(processTemplateId) // get all consulted for this process template
} yield (allApprovedProcessTemplates, processTemplate, prerequisites, postConditions, processSteps, processStepsPrerequisites,
processStepsPrerequisiteProcessTemplate, processTemplatesForStepPrerequisites, processStepsPostConditions, processStepPostConditionProcessTemplate, processTemplatesForStepPostConditions, derivedProcesses,
processTemplatesForStepDerivedProcesses, processStepsTemplates_ProcessTemplates, processTemplatesForProcessTemplatesToProcessStep, approvedProcessTemplate, trainedProcessTemplate, responsible, accountable, consulted, informed)
process.flatMap({ case (allApprovedProcessTemplates, processTemplate, prerequisites, postConditions, processSteps, processStepsPrerequisites,
processStepsPrerequisiteProcessTemplate, processTemplatesForStepPrerequisites, processStepsPostConditions, processStepPostConditionProcessTemplate, processTemplatesForStepPostConditions, derivedProcesses,
processTemplatesForStepDerivedProcesses, processStepsTemplates_ProcessTemplates, processTemplatesForProcessTemplatesToProcessStep, approvedProcessTemplate, trainedProcessTemplate, responsible, accountable, consulted, informed) =>
Future.sequence {
processSteps.map {
step =>
val prerequisiteFuture = processStepPrerequisitesDTO.getProcessStepPrerequisiteProcessTemplateIds(step.id.get)
prerequisiteFuture.map(prereqTemplates => {
processTemplateDTO.getProessTemplatesForStepPreqrequsites(prereqTemplates).map(pres => {
println("test", pres) // they are printed
step.stepPrerequisites ++Some(pres)
println("test2", step)
step
})
})
}
}.map {
stepTemplates =>
Ok(Json.obj(
"allApprovedProcessTemplates" -> allApprovedProcessTemplates,
"processTemplate" -> processTemplate,
"prerequisites" -> prerequisites,
"postConditions" -> postConditions,
"approvedProcessTemplate" -> approvedProcessTemplate,
"trainedProcessTemplate" -> trainedProcessTemplate,
// Step prerequisites
"processStepsPrerequisites" -> processStepsPrerequisites,
"processStepsPrerequisiteProcessTemplate" -> processStepsPrerequisiteProcessTemplate,
"processTemplatesForStepPrerequisites" -> processTemplatesForStepPrerequisites,
// Step post conditions
"processStepsPostConditions" -> processStepsPostConditions,
"processStepPostConditionProcessTemplate" -> processStepPostConditionProcessTemplate,
"processTemplatesForStepPostConditions" -> processTemplatesForStepPostConditions,
// Derived processes
"derivedProcesses" -> derivedProcesses,
"processTemplatesForStepDerivedProcesses" -> processTemplatesForStepDerivedProcesses,
// Process to process step
"processStepsTemplates_ProcessTemplates" -> processStepsTemplates_ProcessTemplates,
"processTemplatesForProcessTemplatesToProcessStep" -> processTemplatesForProcessTemplatesToProcessStep,
"steps" -> "stepTemplates",
"responsible" -> responsible,
"accountable" -> accountable,
"consulted" -> consulted,
"informed" -> informed
))
}
})
}