Created
May 22, 2014 14:52
-
-
Save jakob85/15d02170878b8d190bda to your computer and use it in GitHub Desktop.
Major Collecting stuff
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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