Skip to content

Commit

Permalink
Merge pull request #239 from hmrc/Karolina/DLS-10599/scalafmt-bobby-r…
Browse files Browse the repository at this point in the history
…ule-fix

DLS-10599: Scalafmt bobby rule fix
  • Loading branch information
karolina-zaborska authored Jun 24, 2024
2 parents 0fae783 + c597995 commit a93f237
Show file tree
Hide file tree
Showing 51 changed files with 307 additions and 261 deletions.
3 changes: 2 additions & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ style = defaultWithAlign
maxColumn = 120
lineEndings = unix
importSelectors = singleLine
docstrings = ScalaDoc
runner.dialect = scala213
version = 3.7.13

project {
git = true
Expand Down
3 changes: 2 additions & 1 deletion app/uk/gov/hmrc/cbcr/Module.scala
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ class Module(environment: Environment, configuration: Configuration) extends Abs
logger.info("Graphite metrics enabled, starting the reporter")

val graphite = new Graphite(
new InetSocketAddress(graphiteConfig.load[String]("host"), graphiteConfig.load[Int]("port")))
new InetSocketAddress(graphiteConfig.load[String]("host"), graphiteConfig.load[Int]("port"))
)

val prefix = graphiteConfig.load[String]("prefix")

Expand Down
10 changes: 5 additions & 5 deletions app/uk/gov/hmrc/cbcr/auth/CBCRAuth.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ import uk.gov.hmrc.play.bootstrap.backend.controller.BackendController
import scala.concurrent.{ExecutionContext, Future}

@Singleton
class CBCRAuth @Inject()(val microServiceAuthConnector: AuthConnector, cc: ControllerComponents)(
implicit val ec: ExecutionContext)
extends BackendController(cc) with AuthorisedFunctions {
class CBCRAuth @Inject() (val microServiceAuthConnector: AuthConnector, cc: ControllerComponents)(implicit
val ec: ExecutionContext
) extends BackendController(cc) with AuthorisedFunctions {
override def authConnector: AuthConnector = microServiceAuthConnector

private val AuthProvider: AuthProviders = AuthProviders(GovernmentGateway)
Expand All @@ -55,8 +55,8 @@ class CBCRAuth @Inject()(val microServiceAuthConnector: AuthConnector, cc: Contr
case Some(affinityG) if isAgentOrOrganisation(affinityG) => action(request)
case _ => Future.successful(Unauthorized)
}
.recover[Result] {
case e: NoActiveSession => Unauthorized(e.reason)
.recover[Result] { case e: NoActiveSession =>
Unauthorized(e.reason)
}
}
}
2 changes: 1 addition & 1 deletion app/uk/gov/hmrc/cbcr/config/ApplicationConfig.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import uk.gov.hmrc.play.bootstrap.config.ServicesConfig
import javax.inject.{Inject, Singleton}

@Singleton
class ApplicationConfig @Inject()(configuration: Configuration, servicesConfig: ServicesConfig) {
class ApplicationConfig @Inject() (configuration: Configuration, servicesConfig: ServicesConfig) {
import uk.gov.hmrc.cbcr.config.ConfigurationOps.ConfigurationOps
private val etmpHod_ = servicesConfig.baseUrl("etmp-hod")
private val docRefIdsToClear_ = configuration.load[String]("Prod.DocRefId.clear")
Expand Down
27 changes: 14 additions & 13 deletions app/uk/gov/hmrc/cbcr/connectors/DESConnector.scala
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ trait DESConnector extends RawResponseReads with HttpErrorFunctions {
logger.info(s"Lookup Request sent to DES")
withCorrelationId { implicit hc =>
http.POST[JsValue, HttpResponse](s"$serviceUrl/$orgLookupURI/utr/$utr", Json.toJson(lookupData), desHeaders)
} recover {
case e: HttpException => HttpResponse(status = e.responseCode, body = e.message)
} recover { case e: HttpException =>
HttpResponse(status = e.responseCode, body = e.message)
}
}

Expand All @@ -89,40 +89,41 @@ trait DESConnector extends RawResponseReads with HttpErrorFunctions {
logger.info(s"Create Request sent to DES")
withCorrelationId { implicit hc =>
http.POST[SubscriptionRequest, HttpResponse](s"$serviceUrl/$cbcSubscribeURI", sub, desHeaders)
} recover {
case e: HttpException => HttpResponse(status = e.responseCode, body = e.message)
} recover { case e: HttpException =>
HttpResponse(status = e.responseCode, body = e.message)
}
}

def updateSubscription(safeId: String, cor: CorrespondenceDetails)(
implicit hc: HeaderCarrier): Future[HttpResponse] = {
def updateSubscription(safeId: String, cor: CorrespondenceDetails)(implicit
hc: HeaderCarrier
): Future[HttpResponse] = {
implicit val format = CorrespondenceDetails.updateWriter
logger.info(s"Update Request sent to DES")
withCorrelationId { implicit hc =>
http.PUT[CorrespondenceDetails, HttpResponse](s"$serviceUrl/$cbcSubscribeURI/$safeId", cor, desHeaders)
} recover {
case e: HttpException => HttpResponse(status = e.responseCode, body = e.message)
} recover { case e: HttpException =>
HttpResponse(status = e.responseCode, body = e.message)
}
}

def getSubscription(safeId: String)(implicit hc: HeaderCarrier): Future[HttpResponse] = {
logger.info(s"Get Request sent to DES for safeID: $safeId")
withCorrelationId { implicit hc =>
http.GET[HttpResponse](s"$serviceUrl/$cbcSubscribeURI/$safeId", headers = desHeaders)
} recover {
case e: HttpException => HttpResponse(status = e.responseCode, body = e.message)
} recover { case e: HttpException =>
HttpResponse(status = e.responseCode, body = e.message)
}
}

}

@Singleton
class DESConnectorImpl @Inject()(
class DESConnectorImpl @Inject() (
val ec: ExecutionContext,
val auditConnector: AuditConnector,
val configuration: ApplicationConfig,
val httpClient: HttpClient)
extends DESConnector {
val httpClient: HttpClient
) extends DESConnector {
lazy val serviceUrl: String = configuration.etmpHod
lazy val orgLookupURI: String = "registration/organisation"
lazy val cbcSubscribeURI: String = "country-by-country/subscription"
Expand Down
2 changes: 1 addition & 1 deletion app/uk/gov/hmrc/cbcr/connectors/EmailConnector.scala
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ trait EmailConnector {
}

@Singleton
class EmailConnectorImpl @Inject()(config: Configuration, httpClient: HttpClient)(implicit ec: ExecutionContext)
class EmailConnectorImpl @Inject() (config: Configuration, httpClient: HttpClient)(implicit ec: ExecutionContext)
extends EmailConnector {
val http = httpClient
val conf: Config = config.underlying.getConfig("microservice.services.email")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ import uk.gov.hmrc.play.bootstrap.backend.controller.BackendController
import scala.concurrent.ExecutionContext

@Singleton
class BusinessPartnerRecordController @Inject()(connector: DESConnector, auth: CBCRAuth, cc: ControllerComponents)(
implicit val ec: ExecutionContext)
extends BackendController(cc) {
class BusinessPartnerRecordController @Inject() (connector: DESConnector, auth: CBCRAuth, cc: ControllerComponents)(
implicit val ec: ExecutionContext
) extends BackendController(cc) {

def getBusinessPartnerRecord(utr: String) = auth.authCBCR { implicit request =>
connector.lookup(utr).map {
Expand Down
10 changes: 5 additions & 5 deletions app/uk/gov/hmrc/cbcr/controllers/CBCIdController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import javax.inject._
import scala.concurrent.Future

@Singleton
class CBCIdController @Inject()(gen: SubscriptionHandler, auth: CBCRAuth, cc: ControllerComponents)
class CBCIdController @Inject() (gen: SubscriptionHandler, auth: CBCRAuth, cc: ControllerComponents)
extends BackendController(cc) {

def subscribe =
Expand All @@ -45,14 +45,13 @@ class CBCIdController @Inject()(gen: SubscriptionHandler, auth: CBCRAuth, cc: Co

def updateSubscription(safeId: String) =
auth.authCBCRWithJson(
{ implicit request =>
implicit request =>
request.body
.validate[CorrespondenceDetails]
.fold[Future[Result]](
e => Future.successful(BadRequest(e.toString)),
details => gen.updateSubscription(safeId, details)
)
},
),
parse.json
)

Expand All @@ -61,7 +60,8 @@ class CBCIdController @Inject()(gen: SubscriptionHandler, auth: CBCRAuth, cc: Co
}

@inline implicit private def subscriptionDetailsToSubscriptionRequestBody(
s: SubscriptionDetails): SubscriptionRequest =
s: SubscriptionDetails
): SubscriptionRequest =
SubscriptionRequest(
s.businessPartnerRecord.safeId,
false,
Expand Down
13 changes: 6 additions & 7 deletions app/uk/gov/hmrc/cbcr/controllers/CBCREmailController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,20 @@ import uk.gov.hmrc.play.bootstrap.backend.controller.BackendController
import scala.concurrent.{ExecutionContext, Future}

@Singleton
class CBCREmailController @Inject()(email: EmailService, auth: CBCRAuth, cc: ControllerComponents)(
implicit val ec: ExecutionContext)
extends BackendController(cc) {
class CBCREmailController @Inject() (email: EmailService, auth: CBCRAuth, cc: ControllerComponents)(implicit
val ec: ExecutionContext
) extends BackendController(cc) {

//todo have email validation?
// todo have email validation?
def sendEmail =
auth.authCBCRWithJson(
{ implicit request =>
implicit request =>
request.body
.validate[Email]
.fold[Future[Result]](
_ => Future.successful(BadRequest),
emailCBCR => email.sendEmail(emailCBCR)
)
},
),
parse.json
)
}
6 changes: 3 additions & 3 deletions app/uk/gov/hmrc/cbcr/controllers/DocRefIdController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ import javax.inject.{Inject, Singleton}
import scala.concurrent.ExecutionContext

@Singleton
class DocRefIdController @Inject()(repo: DocRefIdRepository, auth: CBCRAuth, cc: ControllerComponents)(
implicit ec: ExecutionContext)
extends BackendController(cc) {
class DocRefIdController @Inject() (repo: DocRefIdRepository, auth: CBCRAuth, cc: ControllerComponents)(implicit
ec: ExecutionContext
) extends BackendController(cc) {

def query(docRefId: DocRefId) = auth.authCBCR { _ =>
repo.query(docRefId).map {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ import javax.inject.{Inject, Singleton}
import scala.concurrent.{ExecutionContext, Future}

@Singleton
class FileUploadResponseController @Inject()(repo: FileUploadRepository, auth: CBCRAuth, cc: ControllerComponents)(
implicit val ec: ExecutionContext)
extends BackendController(cc) {
class FileUploadResponseController @Inject() (repo: FileUploadRepository, auth: CBCRAuth, cc: ControllerComponents)(
implicit val ec: ExecutionContext
) extends BackendController(cc) {

lazy val logger: Logger = Logger(this.getClass)

Expand Down
6 changes: 3 additions & 3 deletions app/uk/gov/hmrc/cbcr/controllers/MessageRefIdController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ import uk.gov.hmrc.play.bootstrap.backend.controller.BackendController
import scala.concurrent.ExecutionContext

@Singleton
class MessageRefIdController @Inject()(repo: MessageRefIdRepository, auth: CBCRAuth, cc: ControllerComponents)(
implicit ec: ExecutionContext)
extends BackendController(cc) {
class MessageRefIdController @Inject() (repo: MessageRefIdRepository, auth: CBCRAuth, cc: ControllerComponents)(implicit
ec: ExecutionContext
) extends BackendController(cc) {

def save(messageRefId: String) = auth.authCBCR { _ =>
repo.save2(MessageRefId(messageRefId)).map(_ => Ok)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ import scala.concurrent.{ExecutionContext, Future}
import scala.util.control.NonFatal

@Singleton
class ReportingEntityDataController @Inject()(repo: ReportingEntityDataRepo, auth: CBCRAuth, cc: ControllerComponents)(
implicit ec: ExecutionContext)
extends BackendController(cc) {
class ReportingEntityDataController @Inject() (repo: ReportingEntityDataRepo, auth: CBCRAuth, cc: ControllerComponents)(
implicit ec: ExecutionContext
) extends BackendController(cc) {

lazy val logger: Logger = Logger(this.getClass)

def save() =
auth.authCBCRWithJson(
{ implicit request =>
implicit request =>
request.body
.validate[ReportingEntityData]
.fold(
Expand All @@ -48,14 +48,13 @@ class ReportingEntityDataController @Inject()(repo: ReportingEntityDataRepo, aut
Future.successful(BadRequest)
},
(data: ReportingEntityData) => repo.save(data).map(_ => Ok)
)
},
),
parse.json
)

def update() =
auth.authCBCRWithJson(
{ implicit request =>
implicit request =>
request.body
.validate[PartialReportingEntityData]
.fold(
Expand All @@ -67,9 +66,8 @@ class ReportingEntityDataController @Inject()(repo: ReportingEntityDataRepo, aut
repo.update(data).map {
case true => Ok
case false => NotModified
}
)
},
}
),
parse.json
)

Expand All @@ -80,10 +78,9 @@ class ReportingEntityDataController @Inject()(repo: ReportingEntityDataRepo, aut
case None => NotFound
case Some(data) => Ok(Json.toJson(data))
}
.recover {
case NonFatal(t) =>
logger.error(s"Exception thrown trying to query for ReportingEntityData: ${t.getMessage}", t)
InternalServerError
.recover { case NonFatal(t) =>
logger.error(s"Exception thrown trying to query for ReportingEntityData: ${t.getMessage}", t)
InternalServerError
}

}
Expand All @@ -95,10 +92,9 @@ class ReportingEntityDataController @Inject()(repo: ReportingEntityDataRepo, aut
case None => NotFound
case Some(data) => Ok(Json.toJson(data))
}
.recover {
case NonFatal(t) =>
logger.error(s"Exception thrown trying to query for ReportingEntityData: ${t.getMessage}", t)
InternalServerError
.recover { case NonFatal(t) =>
logger.error(s"Exception thrown trying to query for ReportingEntityData: ${t.getMessage}", t)
InternalServerError
}

}
Expand All @@ -110,27 +106,25 @@ class ReportingEntityDataController @Inject()(repo: ReportingEntityDataRepo, aut
case None => NotFound
case Some(data) => Ok(Json.toJson(data))
}
.recover {
case NonFatal(t) =>
logger.error(s"Exception thrown trying to query for ReportingEntityData: ${t.getMessage}", t)
InternalServerError
.recover { case NonFatal(t) =>
logger.error(s"Exception thrown trying to query for ReportingEntityData: ${t.getMessage}", t)
InternalServerError
}

}

def queryTin(tin: String, reportingPeriod: String) = auth.authCBCR { _ =>
try {
try
repo
.queryTIN(tin, LocalDate.parse(reportingPeriod))
.map { reportEntityData =>
if (reportEntityData.isEmpty) NotFound else Ok(Json.toJson(reportEntityData.head))
}
.recover {
case NonFatal(t) =>
logger.error(s"Exception thrown trying to query for ReportingEntityData: ${t.getMessage}", t)
InternalServerError
.recover { case NonFatal(t) =>
logger.error(s"Exception thrown trying to query for ReportingEntityData: ${t.getMessage}", t)
InternalServerError
}
} catch {
catch {
case e: DateTimeParseException => Future.successful(BadRequest(s"Invalid reporting period ${e.getMessage}}"))
}
}
Expand All @@ -141,11 +135,10 @@ class ReportingEntityDataController @Inject()(repo: ReportingEntityDataRepo, aut
.map { result =>
if (result) Ok(Json.toJson(DatesOverlap(true))) else Ok(Json.toJson(DatesOverlap(false)))
}
.recover {
case NonFatal(t) =>
logger
.error(s"Exception thrown trying to query for ReportingEntityData for overlapping rule: ${t.getMessage}", t)
InternalServerError
.recover { case NonFatal(t) =>
logger
.error(s"Exception thrown trying to query for ReportingEntityData for overlapping rule: ${t.getMessage}", t)
InternalServerError
}
}

Expand All @@ -156,10 +149,9 @@ class ReportingEntityDataController @Inject()(repo: ReportingEntityDataRepo, aut
case None => NotFound
case Some(data) => Ok(Json.toJson(data))
}
.recover {
case NonFatal(t) =>
logger.error(s"Exception thrown trying to query for ReportingEntityData: ${t.getMessage}", t)
InternalServerError
.recover { case NonFatal(t) =>
logger.error(s"Exception thrown trying to query for ReportingEntityData: ${t.getMessage}", t)
InternalServerError
}

}
Expand Down
Loading

0 comments on commit a93f237

Please sign in to comment.