Skip to content

Commit

Permalink
[PS] TAV-742 - Update to Scala 2.13 and bump dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
beyond-code-github committed Jan 8, 2023
1 parent 980d1ca commit 39080cd
Show file tree
Hide file tree
Showing 19 changed files with 34 additions and 43 deletions.
9 changes: 4 additions & 5 deletions app/Module.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import repositories._
import services.{ABPAddressRepositoryMetrics, NonABPAddressRepositoryMetrics, ReferenceData}

import javax.inject.Singleton
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.{ExecutionContext, Future}
import scala.util.Try

Expand All @@ -51,9 +50,10 @@ class Module(environment: Environment, configuration: Configuration) extends Abs
@Provides
@Singleton
def provideAbpAddressRepository(metrics: Metrics, configHelper: ConfigHelper,
rdsQueryConfig: RdsQueryConfig, executionContext: ExecutionContext,
rdsQueryConfig: RdsQueryConfig,
applicationLifecycle: ApplicationLifecycle,
inMemoryABPAddressRepository: InMemoryABPAddressRepository): ABPAddressRepository = {
inMemoryABPAddressRepository: InMemoryABPAddressRepository)
(implicit executionContext: ExecutionContext) : ABPAddressRepository = {

val dbEnabled = isDbEnabled(configHelper)
val cipPaasDbEnabled = configHelper.isCipPaasDbEnabled()
Expand All @@ -75,8 +75,7 @@ class Module(environment: Environment, configuration: Configuration) extends Abs
}

@Provides
def provideCIPPostgresConnectionTestResult(executionContext: ExecutionContext,
applicationLifecycle: ApplicationLifecycle): Try[Future[Int]] =
def provideCIPPostgresConnectionTestResult(applicationLifecycle: ApplicationLifecycle)(implicit executionContext: ExecutionContext) : Try[Future[Int]] =
Try {
val transactor = new TransactorProvider(configuration, applicationLifecycle, "cip-address-lookup-rds").get(executionContext)
new CIPPostgresABPAddressRepository(transactor).testConnection
Expand Down
2 changes: 1 addition & 1 deletion app/repositories/InMemoryAddressTestData.scala
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ object InMemoryAddressTestData {
val cannedNonUKDataFile = Environment.simple().resource(cannedNonUKData).get
val splitter = new CsvLineSplitter(Source.fromURL(cannedNonUKDataFile).bufferedReader()).asScala.toSeq
splitter.map(CSV.convertNonUKCsvLine)
}.groupBy(_._1).mapValues(_.map(_._2).toList)
}.groupBy(_._1).view.mapValues(_.map(_._2).toList).toMap

def dbsToFilterText(dbAddress: DbAddress): Set[String] =
(dbAddress.lines.mkString(" ") + " " + dbAddress.town + " " + dbAddress.administrativeArea.getOrElse("") + " " + dbAddress.poBox.getOrElse("") + " " + dbAddress.postcode).replaceAll("[\\p{Space},]+", " ").split(" ").map(_.toLowerCase).toSet
Expand Down
5 changes: 2 additions & 3 deletions app/repositories/PostgresABPAddressRepository.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,9 @@ import model.address.{Outcode, Postcode}
import model.internal.{DbAddress, SqlDbAddress}

import javax.inject.Inject
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.Future
import scala.concurrent.{ExecutionContext, Future}

class PostgresABPAddressRepository @Inject()(transactor: Transactor[IO], queryConfig: RdsQueryConfig) extends ABPAddressRepository {
class PostgresABPAddressRepository @Inject()(transactor: Transactor[IO], queryConfig: RdsQueryConfig)(implicit ec: ExecutionContext) extends ABPAddressRepository {

import PostgresABPAddressRepository._

Expand Down
6 changes: 3 additions & 3 deletions app/repositories/TransactorProvider.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package repositories

import cats.effect.{ContextShift, IO}
import cats.effect.{Blocker, ContextShift, IO}
import doobie.Transactor
import doobie.hikari.HikariTransactor
import play.api.Configuration
Expand All @@ -37,8 +37,8 @@ class TransactorProvider (configuration: Configuration, applicationLifecycle: Ap
dbConfig.get[String]("url"),
dbConfig.get[String]("username"),
dbConfig.get[String]("password"),
ExecutionContext.fromExecutor(Executors.newFixedThreadPool(10)), // waiting for connections
ExecutionContext.fromExecutor(Executors.newCachedThreadPool()) // executing db calls, bounded by hikari connection pool size
ExecutionContext.fromExecutor(Executors.newFixedThreadPool(10)),
Blocker.liftExecutorService(Executors.newCachedThreadPool()) // executing db calls, bounded by hikari connection pool size
)

val (transactor, releaseResource) = hikariTransactorResource.allocated.unsafeRunSync()
Expand Down
3 changes: 1 addition & 2 deletions app/services/ReferenceData.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package services
import com.github.tototoshi.csv.CSVReader
import model.address.ReferenceItem

import java.util.NoSuchElementException
import java.util.zip.GZIPInputStream
import scala.collection.mutable.ListBuffer
import scala.io.{Codec, Source}
Expand Down Expand Up @@ -88,7 +87,7 @@ object ReferenceData {
}

val time = System.currentTimeMillis() - start
println(s"Loading $resource took ${time}ms")
// println(s"Loading $resource took ${time}ms")

outputBuffer.toMap
}
Expand Down
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import uk.gov.hmrc.DefaultBuildSettings.{addTestReportOption, defaultSettings, scalaSettings, targetJvm}
import uk.gov.hmrc.sbtdistributables.SbtDistributablesPlugin.publishingSettings

val thisScalaVersion = "2.12.15"
val thisScalaVersion = "2.13.10"

lazy val root = Project("address-lookup", file("."))
.enablePlugins(play.sbt.PlayScala, SbtAutoBuildPlugin, SbtGitVersioning, SbtDistributablesPlugin)
Expand Down
4 changes: 2 additions & 2 deletions conf/application-json-logger.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
<encoder class="uk.gov.hmrc.play.logging.JsonEncoder"/>
</appender>

<logger name="uk.gov" level="${logger.uk.gov:-WARN}"/>
<logger name="uk.gov" level="WARN"/>

<root level="${logger.application:-WARN}">
<root level="WARN">
<appender-ref ref="STDOUT"/>
</root>

Expand Down
9 changes: 2 additions & 7 deletions conf/application.conf
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,16 @@ play.http.requestHandler = "uk.gov.hmrc.play.bootstrap.http.RequestHandler"

# Provides an implementation of AuditConnector. Use `uk.gov.hmrc.play.bootstrap.AuditModule` or create your own.
# An audit connector must be provided.
play.modules.enabled += "uk.gov.hmrc.play.bootstrap.AuditModule"
play.modules.enabled += "uk.gov.hmrc.play.audit.AuditModule"

# Provides an implementation of MetricsFilter. Use `uk.gov.hmrc.play.bootstrap.graphite.GraphiteMetricsModule` or create your own.
# A metric filter must be provided
play.modules.enabled += "uk.gov.hmrc.play.bootstrap.graphite.GraphiteMetricsModule"

# Provides an implementation and configures all filters required by a Platform backend microservice.
play.modules.enabled += "uk.gov.hmrc.play.bootstrap.MicroserviceModule"
play.modules.enabled += "uk.gov.hmrc.play.bootstrap.backend.BackendModule"

play.http.filters = "uk.gov.hmrc.play.bootstrap.filters.MicroserviceFilters"
play.http.router = app.Routes

#play 2.5 requires an application secret
play.crypto.secret: "H7dVw$PlJiD)^U,oa4TA1pa]pT:4ETLqbL&2P=n6T~p,A*}^.Y46@PQOV~9(B09Hc]t7-hsf~&@w=zH"

play.http.errorHandler = "uk.gov.hmrc.play.bootstrap.backend.http.JsonErrorHandler"

play.ws.timeout.request = 70000ms # 70 secs
Expand Down
8 changes: 4 additions & 4 deletions project/AppDependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ object AppDependencies {

private val scalaTestVersion = "3.1.4"
private val pegdownVersion = "1.6.0"
private val doobieVersion = "0.7.1"
private val doobieVersion = "0.13.4"

val compile = Seq(
ws,
"uk.gov.hmrc" %% "bootstrap-backend-play-28" % "5.16.0",
"uk.gov.hmrc" %% "bootstrap-backend-play-28" % "7.12.0",
"com.univocity" % "univocity-parsers" % "2.9.1",
"com.github.tototoshi" %% "scala-csv" % "1.3.8",
"com.github.tototoshi" %% "scala-csv" % "1.3.10",
"org.tpolecat" %% "doobie-core" % doobieVersion,
"org.tpolecat" %% "doobie-postgres" % doobieVersion,
"org.tpolecat" %% "doobie-hikari" % doobieVersion,
Expand All @@ -27,7 +27,7 @@ object AppDependencies {
"org.pegdown" % "pegdown" % pegdownVersion % "test, it",
"com.typesafe.play" %% "play-test" % PlayVersion.current % "test, it",
"org.scalatestplus.play" %% "scalatestplus-play" % "5.1.0" % "test, it",
"org.scalatestplus" %% "mockito-3-4" % "3.1.4.0" % "test, it",
"org.scalatestplus" % "mockito-4-6_2.13" % "3.2.14.0" % "test, it",
"org.jsoup" % "jsoup" % "1.14.3" % "test, it",
)

Expand Down
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=1.6.1
sbt.version=1.7.2
10 changes: 4 additions & 6 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
resolvers += Resolver.typesafeRepo("releases")
resolvers += MavenRepository("HMRC-open-artefacts-maven2", "https://open.artefacts.tax.service.gov.uk/maven2")
resolvers += Resolver.url("HMRC-open-artefacts-ivy", url("https://open.artefacts.tax.service.gov.uk/ivy2"))(Resolver.ivyStylePatterns)


addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.8.8")

addSbtPlugin("uk.gov.hmrc" % "sbt-auto-build" % "3.5.0")

addSbtPlugin("uk.gov.hmrc" % "sbt-git-versioning" % "2.4.0")
addSbtPlugin("uk.gov.hmrc" % "sbt-auto-build" % "3.8.0")

addSbtPlugin("uk.gov.hmrc" % "sbt-distributables" % "2.1.0")

addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.8.18")
2 changes: 1 addition & 1 deletion test/unit/controllers/AddressLookupIdControllerTest.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022 HM Revenue & Customs
* Copyright 2023 HM Revenue & Customs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
3 changes: 2 additions & 1 deletion test/unit/controllers/AddressSearchControllerTest.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022 HM Revenue & Customs
* Copyright 2023 HM Revenue & Customs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -43,6 +43,7 @@ import util.Utils._

import scala.concurrent.Future
import scala.concurrent.duration._
import scala.language.postfixOps

class AddressSearchControllerTest extends AnyWordSpec with Matchers with GuiceOneAppPerSuite with MockitoSugar {

Expand Down
2 changes: 1 addition & 1 deletion test/unit/model/AddressTest.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022 HM Revenue & Customs
* Copyright 2023 HM Revenue & Customs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion test/unit/model/RequestTest.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022 HM Revenue & Customs
* Copyright 2023 HM Revenue & Customs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022 HM Revenue & Customs
* Copyright 2023 HM Revenue & Customs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion test/unit/services/ABPAddressRepositoryMetricsTest.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022 HM Revenue & Customs
* Copyright 2023 HM Revenue & Customs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion test/unit/services/ResponseProcessorTest.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022 HM Revenue & Customs
* Copyright 2023 HM Revenue & Customs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion test/unit/util/utils.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022 HM Revenue & Customs
* Copyright 2023 HM Revenue & Customs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down

0 comments on commit 39080cd

Please sign in to comment.