Skip to content

Instantly share code, notes, and snippets.

@jakob85
Created May 22, 2014 14:52
Show Gist options
  • Save jakob85/15d02170878b8d190bda to your computer and use it in GitHub Desktop.
Save jakob85/15d02170878b8d190bda to your computer and use it in GitHub Desktop.
Major Collecting stuff
AccountRepository.find().map { accounts =>
accounts.map { account =>
val eligable = reviewService.receivedReviewedInDays(account.recoInfo.recoId, millis).map {
b => {
account.recoInfo.recoId -> b
}
}.collect {
case (r, false) => r
}.map { r =>
taskService.isRecoIdEligibleForTask(r).map {
b2 => {
r -> b2
}
}.collect {
case (r, true) => r
}
}.flatMap(nested => nested)
val result = eligable.map { recoId =>
val task = Task(
None,
None,
None,
recoId = recoId,
name = account.name,
contactPersons = account.contacts,
reviewCount = account.recoInfo.reviewsNow,
latestReview = account.recoInfo.latestReviewDate,
salesPerson = account.zoho.ownerName,
stopDate = account.salesOrder.stopDate,
taskStatus = TaskStatus.NEW,
disabled = false
)
taskService.createTask(task).map { maybeInsert =>
maybeInsert.fold(
exception => Logger.error(s"Could not save task $task, exception $exception"),
success => Logger.info(s"Task created: $task")
)
}
}
result
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment