From 6386d729f55cf777dc7d147f1a50efa4925ec6ed Mon Sep 17 00:00:00 2001 From: Florian M Date: Thu, 1 Sep 2022 09:44:51 +0200 Subject: [PATCH] Remove some more return statements from scala code --- app/models/job/Job.scala | 10 ++-- app/oxalis/mail/MailchimpClient.scala | 48 +++++++++---------- .../util/requestlogging/RequestLogging.scala | 18 ++++--- 3 files changed, 37 insertions(+), 39 deletions(-) diff --git a/app/models/job/Job.scala b/app/models/job/Job.scala index 6acf384c731..6fa0d3482b3 100644 --- a/app/models/job/Job.scala +++ b/app/models/job/Job.scala @@ -275,11 +275,11 @@ class JobService @Inject()(wkConf: WkConf, with LazyLogging with Formatter { - def trackStatusChange(jobBeforeChange: Job, jobAfterChange: Job): Unit = { - if (jobBeforeChange.isEnded) return - if (jobAfterChange.state == JobState.SUCCESS) trackNewlySuccessful(jobBeforeChange, jobAfterChange) - if (jobAfterChange.state == JobState.FAILURE) trackNewlyFailed(jobBeforeChange, jobAfterChange) - } + def trackStatusChange(jobBeforeChange: Job, jobAfterChange: Job): Unit = + if (!jobBeforeChange.isEnded) { + if (jobAfterChange.state == JobState.SUCCESS) trackNewlySuccessful(jobBeforeChange, jobAfterChange) + if (jobAfterChange.state == JobState.FAILURE) trackNewlyFailed(jobBeforeChange, jobAfterChange) + } private def trackNewlyFailed(jobBeforeChange: Job, jobAfterChange: Job): Unit = { for { diff --git a/app/oxalis/mail/MailchimpClient.scala b/app/oxalis/mail/MailchimpClient.scala index 60c3555ffb9..a0d6e849bae 100644 --- a/app/oxalis/mail/MailchimpClient.scala +++ b/app/oxalis/mail/MailchimpClient.scala @@ -18,16 +18,16 @@ class MailchimpClient @Inject()(wkConf: WkConf, rpc: RPC, multiUserDAO: MultiUse private lazy val conf = wkConf.Mail.Mailchimp - def registerUser(user: User, multiUser: MultiUser, tag: MailchimpTag): Unit = { - if (conf.host.isEmpty) return - val emailMd5 = SCrypt.md5(multiUser.email) - logger.info(s"Registering user ${user._id} for Mailchimp, tag=${MailchimpTag.format(tag)}") - for { - _ <- registerUser(user.firstName, user.lastName, multiUser.email, emailMd5) - _ <- tagByEmailMd5(emailMd5, tag) - } yield () - () - } + def registerUser(user: User, multiUser: MultiUser, tag: MailchimpTag): Unit = + if (conf.host.nonEmpty) { + val emailMd5 = SCrypt.md5(multiUser.email) + logger.info(s"Registering user ${user._id} for Mailchimp, tag=${MailchimpTag.format(tag)}") + for { + _ <- registerUser(user.firstName, user.lastName, multiUser.email, emailMd5) + _ <- tagByEmailMd5(emailMd5, tag) + } yield () + () + } private def registerUser(firstName: String, lastName: String, email: String, emailMd5: String): Fox[WSResponse] = { val uri = s"${conf.host}/lists/${conf.listId}/members/$emailMd5" @@ -42,21 +42,21 @@ class MailchimpClient @Inject()(wkConf: WkConf, rpc: RPC, multiUserDAO: MultiUse rpc(uri).silent.withBasicAuth(conf.user, conf.password).put(userBody) } - def tagUser(user: User, tag: MailchimpTag): Unit = { - if (conf.host.isEmpty) return - for { - multiUser <- multiUserDAO.findOne(user._multiUser)(GlobalAccessContext) - _ = tagMultiUser(multiUser, tag) - } yield () - () - } + def tagUser(user: User, tag: MailchimpTag): Unit = + if (conf.host.nonEmpty) { + for { + multiUser <- multiUserDAO.findOne(user._multiUser)(GlobalAccessContext) + _ = tagMultiUser(multiUser, tag) + } yield () + () + } - def tagMultiUser(multiUser: MultiUser, tag: MailchimpTag): Unit = { - if (conf.host.isEmpty) return - val emailMd5 = SCrypt.md5(multiUser.email) - tagByEmailMd5(emailMd5, tag) - () - } + def tagMultiUser(multiUser: MultiUser, tag: MailchimpTag): Unit = + if (conf.host.nonEmpty) { + val emailMd5 = SCrypt.md5(multiUser.email) + tagByEmailMd5(emailMd5, tag) + () + } private def tagByEmailMd5(emailMd5: String, tag: MailchimpTag): Fox[WSResponse] = { val uri = s"${conf.host}/lists/${conf.listId}/members/$emailMd5/tags" diff --git a/util/src/main/scala/com/scalableminds/util/requestlogging/RequestLogging.scala b/util/src/main/scala/com/scalableminds/util/requestlogging/RequestLogging.scala index 11c45def8f5..935c41b7ef3 100644 --- a/util/src/main/scala/com/scalableminds/util/requestlogging/RequestLogging.scala +++ b/util/src/main/scala/com/scalableminds/util/requestlogging/RequestLogging.scala @@ -15,16 +15,14 @@ trait AbstractRequestLogging extends LazyLogging { def logRequestFormatted(request: Request[_], result: Result, notifier: Option[String => Unit], - requesterId: Option[String] = None): Unit = { - - if (Status.isSuccessful(result.header.status)) return - - val userIdMsg = requesterId.map(id => s" for user $id").getOrElse("") - val resultMsg = s": ${resultBody(result)}" - val msg = s"Answering ${result.header.status} at ${request.uri}$userIdMsg$resultMsg" - logger.warn(msg) - notifier.foreach(_(msg)) - } + requesterId: Option[String] = None): Unit = + if (!Status.isSuccessful(result.header.status)) { + val userIdMsg = requesterId.map(id => s" for user $id").getOrElse("") + val resultMsg = s": ${resultBody(result)}" + val msg = s"Answering ${result.header.status} at ${request.uri}$userIdMsg$resultMsg" + logger.warn(msg) + notifier.foreach(_(msg)) + } private def resultBody(result: Result): String = result.body match {