Skip to content

Commit

Permalink
DL-15127 : play3.0 upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
kannanEkambaram committed Dec 24, 2024
1 parent 327d74a commit 5aa4192
Show file tree
Hide file tree
Showing 20 changed files with 107 additions and 148 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ The list of software providers is loaded from the `SoftwareProviders.json` file.
### Running the service locally

#### Using Service Manager
To run all the dependent services and start software choices frontend, you can either use `sm --start SOFTWARE_CHOICES_ALL -r` or `sm2 --start SOFTWARE_CHOICES_ALL -r` if you are using sm2.
To run all the dependent services and start software choices frontend, use `sm2 --start SOFTWARE_CHOICES_ALL`.

Alternatively, if you want to start the service individually, you can either use `sm --start SOFTWARE_CHOICES_FRONTEND -r` or `sm2 --start SOFTWARE_CHOICES_FRONTEND -r` if you are using sm2.
Alternatively, if you want to start the service individually, use `sm2 --start SOFTWARE_CHOICES_FRONTEND`.

Prior to starting the service locally, make sure the instance running in service manager is stopped. This can be done by running either `sm --stop SOFTWARE_CHOICES_FRONTEND`, or `sm2 --stop SOFTWARE_CHOICES_FRONTEND` if you are using sm2.
Prior to starting the service locally, make sure the instance running in service manager is stopped.
This can be done by running either `sm2 --stop SOFTWARE_CHOICES_FRONTEND`.

### From source code on your local machine
1. Clone this repository into the development environment on your machine.
Expand Down
14 changes: 11 additions & 3 deletions app/config/ErrorHandler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,21 @@ package config

import javax.inject.{Inject, Singleton}
import play.api.i18n.MessagesApi
import play.api.mvc.Request
import play.api.mvc.{Request, RequestHeader}
import play.twirl.api.Html
import uk.gov.hmrc.play.bootstrap.frontend.http.FrontendErrorHandler
import views.html.templates.error_template

import scala.language.implicitConversions


@Singleton
class ErrorHandler @Inject()(val messagesApi: MessagesApi,view : error_template, implicit val appConfig: AppConfig) extends FrontendErrorHandler {
override def standardErrorTemplate(pageTitle: String, heading: String, message: String)(implicit request: Request[_]): Html =
class ErrorHandler @Inject()(val messagesApi: MessagesApi,
view : error_template,
implicit val appConfig: AppConfig) extends FrontendErrorHandler {

implicit def rhToRequest(rh: RequestHeader): Request[_] = Request(rh, "")

override def standardErrorTemplate(pageTitle: String, heading: String, message: String)(implicit rh: Request[_]): Html =
view(pageTitle, heading, message)
}
1 change: 0 additions & 1 deletion app/controllers/LanguageSwitchController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import utils.LoggingUtil

import javax.inject.Inject


class LanguageSwitchController @Inject()(cc: MessagesControllerComponents)
extends FrontendController(cc)
with I18nSupport
Expand Down
20 changes: 14 additions & 6 deletions app/utils/LoggingUtil.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,23 @@ import uk.gov.hmrc.http.{HeaderNames, HttpResponse, SessionKeys}

trait LoggingUtil extends LoggerLike {

lazy val trueClientIp: Request[_] => Option[String] = request => request.headers.get(HeaderNames.trueClientIp).map(trueClientIp => s"trueClientIp: $trueClientIp ")
lazy val trueClientIp: Request[_] => Option[String] =
request => request.headers.get(HeaderNames.trueClientIp).map(trueClientIp => s"trueClientIp: $trueClientIp ")

lazy val sessionId: Request[_] => Option[String] = request => request.session.get(SessionKeys.sessionId).map(sessionId => s"sessionId: $sessionId ")
lazy val sessionId: Request[_] => Option[String] =
request => request.session.get(SessionKeys.sessionId).map(sessionId => s"sessionId: $sessionId ")

lazy val identifiers: Request[_] => String = request => Seq(trueClientIp(request), sessionId(request)).flatten.foldLeft("")(_ + _)
lazy val identifiers: Request[_] => String =
request => Seq(trueClientIp(request), sessionId(request)).flatten.foldLeft("")(_ + _)

lazy val trueClientIpFromHttpResponse: HttpResponse => Option[String] = httpResponse => httpResponse.headers.get(HeaderNames.trueClientIp).map(trueClientIp => s"trueClientIp: $trueClientIp")
lazy val sessionIdFromHttpResponse: HttpResponse => Option[String] = httpResponse => httpResponse.headers.get(HeaderNames.xSessionId).map(sessionId => s"sessionId: $sessionId")
lazy val identifiersFromHttpResponse: HttpResponse => String = request => Seq(trueClientIpFromHttpResponse(request), sessionIdFromHttpResponse(request)).flatten.foldLeft("")(_ + _)
lazy val trueClientIpFromHttpResponse: HttpResponse => Option[String] =
httpResponse => httpResponse.headers.get(HeaderNames.trueClientIp).map(trueClientIp => s"trueClientIp: $trueClientIp")

lazy val sessionIdFromHttpResponse: HttpResponse => Option[String] =
httpResponse => httpResponse.headers.get(HeaderNames.xSessionId).map(sessionId => s"sessionId: $sessionId")

lazy val identifiersFromHttpResponse: HttpResponse => String =
request => Seq(trueClientIpFromHttpResponse(request), sessionIdFromHttpResponse(request)).flatten.foldLeft("")(_ + _)

lazy val logger: Logger = LoggerFactory.getLogger(getClass)

Expand Down
34 changes: 16 additions & 18 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import sbt.Keys.scalacOptions
import uk.gov.hmrc.DefaultBuildSettings.integrationTestSettings
import uk.gov.hmrc.sbtdistributables.SbtDistributablesPlugin.publishingSettings
import sbt.*

val appName = "software-choices-frontend"
val silencerVersion = "1.7.19"

val silencerVersion = "1.7.0"

lazy val coverageSettings: Seq[Setting[_]] = {
import scoverage.ScoverageKeys
lazy val coverageSettings: Seq[Def.Setting[?]] = {
import scoverage.*

val excludedPackages = Seq(
"<empty>",
Expand All @@ -24,23 +21,24 @@ lazy val coverageSettings: Seq[Setting[_]] = {

Seq(
ScoverageKeys.coverageExcludedPackages := excludedPackages.mkString(";"),
ScoverageKeys.coverageMinimum := 90,
ScoverageKeys.coverageFailOnMinimum := false,
ScoverageKeys.coverageHighlighting := true
ScoverageKeys.coverageMinimumStmtTotal := 90,
ScoverageKeys.coverageFailOnMinimum := false,
ScoverageKeys.coverageHighlighting := true
)
}

lazy val microservice = Project(appName, file("."))
.enablePlugins(play.sbt.PlayScala, SbtAutoBuildPlugin, SbtGitVersioning, SbtDistributablesPlugin)
.settings(coverageSettings: _*)
lazy val microservice: Project = Project(appName, file("."))
.enablePlugins(play.sbt.PlayScala, SbtDistributablesPlugin)
.disablePlugins(JUnitXmlReportPlugin)

.settings(coverageSettings *)
.settings(
majorVersion := 0,
libraryDependencies ++= AppDependencies.compile ++ AppDependencies.test
)
.settings(publishingSettings: _*)
.settings(scalaVersion := "2.13.14")
.configs(IntegrationTest)
.settings(integrationTestSettings(): _*)
.settings(scalaVersion := "2.12.12")
.settings(inConfig(IntegrationTest)(Defaults.itSettings): _*)
.settings(
TwirlKeys.templateImports ++= Seq(
"uk.gov.hmrc.hmrcfrontend.views.html.helpers._",
Expand All @@ -53,7 +51,7 @@ lazy val microservice = Project(appName, file("."))
// You may turn it on for `views` too to suppress warnings from unused imports in compiled twirl templates, but this will hide other warnings.
scalacOptions += "-P:silencer:pathFilters=views;routes",
libraryDependencies ++= Seq(
compilerPlugin("com.github.ghik" % "silencer-plugin" % silencerVersion cross CrossVersion.full),
"com.github.ghik" % "silencer-lib" % silencerVersion % Provided cross CrossVersion.full
compilerPlugin("com.github.ghik" % "silencer-plugin" % silencerVersion cross CrossVersion.full),
"com.github.ghik" % "silencer-lib" % silencerVersion % Provided cross CrossVersion.full
)
)
2 changes: 1 addition & 1 deletion conf/SoftwareProviders.json
Original file line number Diff line number Diff line change
Expand Up @@ -5210,7 +5210,7 @@
"agent": false,
"accounting": true,
"spreadsheets": false,
"viewReturn": true,
"viewReturn": false,
"viewLiabilities": false,
"viewPayments": false,
"cognitive": false,
Expand Down
38 changes: 0 additions & 38 deletions conf/application.conf
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
# limitations under the License.

include "frontend.conf"

appName="software-choices-frontend"

accessibility-statement.service-path = "/software-choices"
Expand All @@ -26,23 +25,6 @@ play.http.router=prod.Routes

play.i18n.langs = [ "en", "cy" ]

# An ApplicationLoader that uses Guice to bootstrap the application.
play.application.loader = "uk.gov.hmrc.play.bootstrap.ApplicationLoader"

# Primary entry point for all HTTP requests on Play applications
play.http.requestHandler = "uk.gov.hmrc.play.bootstrap.http.RequestHandler"

# Provides an implementation of AuditConnector. Use `uk.gov.hmrc.play.audit.AuditModule` or create your own.
# An audit connector must be provided.
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 frontend microservice.
play.modules.enabled += "uk.gov.hmrc.play.bootstrap.frontend.FrontendModule"

# Custom error handler
play.http.errorHandler = "config.ErrorHandler"

Expand Down Expand Up @@ -104,26 +86,6 @@ microservice {
}
}

metrics {
name = ${appName}
rateUnit = SECONDS
durationUnit = SECONDS
showSamples = true
jvm = true
enabled = false
}

auditing {
enabled=false
traceRequests=false
consumer {
baseUri {
host = localhost
port = 8100
}
}
}

contact-frontend {
host = "http://localhost:9250"
}
Expand Down
22 changes: 0 additions & 22 deletions conf/logback.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,35 +14,13 @@
</encoder>
</appender>

<appender name="STDOUT_IGNORE_NETTY" class="ch.qos.logback.core.ConsoleAppender">
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<pattern>%date{ISO8601} level=[%level] logger=[%logger] thread=[%thread] rid=[not-available] user=[not-available] message=[%message] %replace(exception=[%xException]){'^exception=\[\]$',''}%n</pattern>
</encoder>
</appender>

<appender name="ACCESS_LOG_FILE" class="ch.qos.logback.core.FileAppender">
<file>logs/access.log</file>
<encoder>
<pattern>%message%n</pattern>
</encoder>
</appender>

<appender name="CONNECTOR_LOG_FILE" class="ch.qos.logback.core.FileAppender">
<file>logs/connector.log</file>
<encoder>
<pattern>%message%n</pattern>
</encoder>
</appender>


<logger name="accesslog" level="INFO" additivity="false">
<appender-ref ref="ACCESS_LOG_FILE" />
</logger>

<logger name="com.ning.http.client.providers.netty" additivity="false">
<appender-ref ref="STDOUT_IGNORE_NETTY" />
</logger>

<logger name="com.google.inject" level="INFO"/>

<logger name="uk.gov" level="INFO"/>
Expand Down
2 changes: 0 additions & 2 deletions conf/prod.routes
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# Add all the application routes to the app.routes file
-> /making-tax-digital-software app.Routes
-> / health.Routes

GET /admin/metrics com.kenshoo.play.metrics.MetricsController.metrics
29 changes: 15 additions & 14 deletions project/AppDependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,29 @@
*/

import play.core.PlayVersion.current
import sbt._
import sbt.*

object AppDependencies {

val playUiVersion = "9.11.0-play-28"
val jsoupVersion = "1.15.3"
val bootstrapVersion = "7.12.0"
val scalaTestPlusVersion = "5.0.0"
val scalaMockVersion = "3.6.0"
val jsoupVersion = "1.15.3"
val bootstrapVersion = "8.6.0"
val scalaTestPlusVersion = "7.0.1"
val scalaMockVersion = "5.1.0"

val compile: Seq[ModuleID] = Seq(
"uk.gov.hmrc" %% "bootstrap-frontend-play-28" % bootstrapVersion,
"uk.gov.hmrc" %% "play-frontend-hmrc-play-28" % "8.5.0",
"org.webjars" % "jquery" % "3.6.3"
"uk.gov.hmrc" %% "bootstrap-frontend-play-30" % bootstrapVersion,
"uk.gov.hmrc" %% "play-frontend-hmrc-play-30" % "8.5.0",
"org.webjars" % "jquery" % "3.7.1"
)

val test: Seq[ModuleID] = Seq(
"org.jsoup" % "jsoup" % jsoupVersion % "test",
"com.typesafe.play" %% "play-test" % current % "test",
"org.scalatestplus.play" %% "scalatestplus-play" % scalaTestPlusVersion % "test",
"org.scalamock" %% "scalamock-scalatest-support" % scalaMockVersion % "test",
"org.pegdown" % "pegdown" % "1.6.0" % "test"
"org.jsoup" % "jsoup" % jsoupVersion % "test",
"org.playframework" %% "play-test" % current % "test",
"org.scalatestplus.play" %% "scalatestplus-play" % scalaTestPlusVersion % "test",
"org.scalamock" %% "scalamock" % scalaMockVersion % "test",
"org.pegdown" % "pegdown" % "1.6.0" % "test",
"com.vladsch.flexmark" % "flexmark-all" % "0.64.8" % "test"
)

def apply(): Seq[sbt.ModuleID] = compile ++ test
}
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=1.7.2
sbt.version=1.9.9
14 changes: 7 additions & 7 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
resolvers += "HMRC-open-artefacts-maven" at "https://open.artefacts.tax.service.gov.uk/maven2"
resolvers += "HMRC-open-artefacts-maven2" at "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("uk.gov.hmrc" %% "sbt-auto-build" % "3.16.0")
addSbtPlugin("uk.gov.hmrc" %% "sbt-auto-build" % "3.24.0")

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

addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.8.18")
addSbtPlugin("org.playframework" % "sbt-plugin" % "3.0.3")

addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.9.3")
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "2.2.1")

addSbtPlugin("org.scalastyle" %% "scalastyle-sbt-plugin" % "1.0.0")
addSbtPlugin("org.scalastyle" %% "scalastyle-sbt-plugin" % "1.0.0" exclude("org.scala-lang.modules", "scala-xml_2.12"))

addSbtPlugin("org.irundaia.sbt" % "sbt-sassify" % "1.4.11")
addSbtPlugin("io.github.irundaia" % "sbt-sassify" % "1.5.2")
2 changes: 2 additions & 0 deletions run-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/usr/bin/env bash
sbt clean compile coverage test coverageReport
Loading

0 comments on commit 5aa4192

Please sign in to comment.