Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

9904 Update scala #43

Merged
merged 7 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 37 additions & 25 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,33 +1,45 @@
version=2.0.1
align = none
continuationIndent.defnSite = 2
danglingParentheses = true
docstrings = JavaDoc
version = 3.7.0
runner.dialect = scala3
maxColumn = 120
lineEndings = unix
importSelectors = singleLine

# Only format files tracked by git.
project {
excludeFilters = ["target/"]
git = true
}

align {
preset = most
tokens = [ {code = "=>", owner = "Case|Type.Arg.ByName"}, "=", "<-", "->", "%", "%%", "should", "shouldBe", "shouldEqual", "shouldNot", "must" ]
arrowEnumeratorGenerator = true
openParenCallSite = false
openParenDefnSite = false
}

binPack {
parentConstructors = false
}

continuationIndent {
callSite = 2
defnSite = 2
}

newlines {
penalizeSingleSelectMultiArgList = false
sometimesBeforeColonInMethodReturnType = true
}

rewrite {
rules = [
AvoidInfix
PreferCurlyFors
RedundantBraces
RedundantParens
SortImports
SortModifiers
]
sortModifiers.order = [
final
override
private
protected
sealed
abstract
implicit
lazy
]
rules = [RedundantBraces, RedundantParens, AsciiSortImports]
redundantBraces {
maxLines = 100
includeUnitMethods = true
stringInterpolation = true
}
}

spaces {
inImportCurlyBraces = false
beforeContextBoundColon = Never
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import uk.gov.hmrc.breathingspaceifstub.utils.ControllerSupport
import uk.gov.hmrc.play.bootstrap.backend.controller.BackendController

@Singleton()
class DebtsController @Inject()(
class DebtsController @Inject() (
cc: ControllerComponents
)(implicit val ec: ExecutionContext)
extends BackendController(cc)
Expand All @@ -44,7 +44,7 @@ class DebtsController @Inject()(
case "AS000003" => sendResponse(OK, jsonDataFromFile("multipleBsDebtsFullPopulation.json"))
case "AS000004" => sendResponse(OK, jsonDataFromFile("multipleBsDebtsPartialPopulation.json"))
case "AS000005" => sendResponse(OK, jsonDataFromFile("multipleBsDebtsMixedPopulation.json"))
case _ => sendResponse(NOT_FOUND, failures("NO_DATA_FOUND", "No records found for the given Nino"))
case _ => sendResponse(NOT_FOUND, failures("NO_DATA_FOUND", "No records found for the given Nino"))
}

def jsonDataFromFile(filename: String): JsValue = getJsonDataFromFile(s"debts/$filename")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import uk.gov.hmrc.breathingspaceifstub.utils.ControllerSupport
import uk.gov.hmrc.play.bootstrap.backend.controller.BackendController

@Singleton()
class IndividualDetailsController @Inject()(
class IndividualDetailsController @Inject() (
configuration: Configuration,
cc: ControllerComponents
)(implicit val ec: ExecutionContext)
Expand Down Expand Up @@ -62,15 +62,15 @@ class IndividualDetailsController @Inject()(
object IndividualDetailsController {

val filter = {
val Details = "details(nino,dateOfBirth)"
val NameList = "nameList(name(firstForename,secondForename,surname,nameType))"
val Details = "details(nino,dateOfBirth)"
val NameList = "nameList(name(firstForename,secondForename,surname,nameType))"
val AddressList =
"addressList(address(addressLine1,addressLine2,addressLine3,addressLine4,addressLine5,addressPostcode,countryCode,addressType))"
val Indicators = "indicators(welshOutputInd)"
val Indicators = "indicators(welshOutputInd)"

s"$Details,$NameList,$AddressList,$Indicators"
}

val fullPopulationDetails = "IndividualDetails.json"
val fullPopulationDetails = "IndividualDetails.json"
val detailsForBreathingSpace = "IndividualDetailsForBS.json"
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import javax.inject.{Inject, Singleton}
import scala.concurrent.{ExecutionContext, Future}

@Singleton()
class MemorandumController @Inject()(
class MemorandumController @Inject() (
cc: ControllerComponents
)(implicit val ec: ExecutionContext)
extends BackendController(cc)
Expand All @@ -42,7 +42,7 @@ class MemorandumController @Inject()(
case "AA000333" => sendResponse(OK, jsonDataFromFile("hasBreathingSpaceIndicator.json"))
case "AS000003" => sendResponse(UNPROCESSABLE_ENTITY, failures("UNKNOWN_DATA_ITEM"))
case "AS000004" => sendResponse(BAD_GATEWAY, failures("BAD_GATEWAY"))
case _ => sendResponse(NOT_FOUND, failures("NO_DATA_FOUND", "No records found for the given Nino"))
case _ => sendResponse(NOT_FOUND, failures("NO_DATA_FOUND", "No records found for the given Nino"))
}

def jsonDataFromFile(filename: String): JsValue = getJsonDataFromFile(s"memorandum/$filename")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import uk.gov.hmrc.breathingspaceifstub.utils.ControllerSupport
import uk.gov.hmrc.play.bootstrap.backend.controller.BackendController

@Singleton()
class PeriodsController @Inject()(
class PeriodsController @Inject() (
cc: ControllerComponents
)(implicit val ec: ExecutionContext)
extends BackendController(cc)
Expand All @@ -53,7 +53,7 @@ class PeriodsController @Inject()(
case "AS000003" => sendResponse(OK, jsonDataFromFile("multipleBsPeriodsFullPopulation.json"))
case "AS000004" => sendResponse(OK, jsonDataFromFile("multipleBsPeriodsPartialPopulation.json"))
case "AS000005" => sendResponse(OK, jsonDataFromFile("multipleBsPeriodsMixedPopulation.json"))
case _ => sendResponse(OK, Json.parse("""{"periods":[]}"""))
case _ => sendResponse(OK, Json.parse("""{"periods":[]}"""))
}

def withBodyAcceptedNinoHandler(
Expand All @@ -79,17 +79,16 @@ class PeriodsController @Inject()(

def transformRequestJsonToResponseJson(jsValue: JsValue, addPeriodIdField: Boolean): JsResult[JsObject] = {
val attrTransformer = (__ \ "periods").json.update {
__.read[JsArray].map {
case JsArray(values) =>
val updatedValues = values.map { period =>
val retainedFields = period.as[JsObject].fields.filter(_._1 != "pegaRequestTimestamp")
val additionalFields =
if (addPeriodIdField) Seq(("periodID", JsString(UUID.randomUUID().toString))) else Seq.empty
__.read[JsArray].map { case JsArray(values) =>
val updatedValues = values.map { period =>
val retainedFields = period.as[JsObject].fields.filter(_._1 != "pegaRequestTimestamp")
val additionalFields =
if (addPeriodIdField) Seq(("periodID", JsString(UUID.randomUUID().toString))) else Seq.empty

JsObject(additionalFields ++ retainedFields)
}
JsObject(additionalFields ++ retainedFields)
}

JsArray(updatedValues)
JsArray(updatedValues)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import javax.inject.{Inject, Singleton}
import scala.concurrent.{ExecutionContext, Future}

@Singleton()
class UnderpaymentsController @Inject()(cc: ControllerComponents)(implicit val ec: ExecutionContext)
class UnderpaymentsController @Inject() (cc: ControllerComponents)(implicit val ec: ExecutionContext)
extends BackendController(cc)
with ControllerSupport {

Expand All @@ -42,7 +42,7 @@ class UnderpaymentsController @Inject()(cc: ControllerComponents)(implicit val e
(nino, periodId) match {
case ("AS000001", "648ea46e-8027-11ec-b614-03845253624e") =>
sendResponse(OK, jsonDataFromFile("underpayments1.json"))
case _ => sendResponse(NOT_FOUND, failures(s"NO_DATA_FOUND", s"$nino or $periodId did not match"))
case _ => sendResponse(NOT_FOUND, failures(s"NO_DATA_FOUND", s"$nino or $periodId did not match"))
}
}
}
4 changes: 2 additions & 2 deletions app/uk/gov/hmrc/breathingspaceifstub/model/Attended.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ object Attended {
case object DA2_BS_UNATTENDED extends Attended

def withNameOption(name: String): Option[Attended] = name match {
case "DA2_BS_ATTENDED" => Some(DA2_BS_ATTENDED)
case "DA2_BS_ATTENDED" => Some(DA2_BS_ATTENDED)
case "DA2_BS_UNATTENDED" => Some(DA2_BS_UNATTENDED)
case _ => None
case _ => None
}
}
4 changes: 2 additions & 2 deletions app/uk/gov/hmrc/breathingspaceifstub/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ package object breathingspaceifstub {

object Header {
lazy val CorrelationId = "CorrelationId"
lazy val OriginatorId = "OriginatorId"
lazy val UserId = "UserId"
lazy val OriginatorId = "OriginatorId"
lazy val UserId = "UserId"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ trait ControllerSupport extends Results with Logging {
.as(MimeTypes.JSON)
}

def composeResponse(nino: String, acceptedHandler: (String) => Future[Result])(
implicit request: Request[_]
def composeResponse(nino: String, acceptedHandler: (String) => Future[Result])(implicit
request: Request[_]
): Future[Result] = {
val normalisedNino = nino.toUpperCase.take(8)
if (normalisedNino.take(2) == "BS") sendErrorResponseFromNino(normalisedNino) // a bad nino
Expand All @@ -59,7 +59,7 @@ trait ControllerSupport extends Results with Logging {
}

def getJsonDataFromFile(filename: String): JsValue = {
val in = getClass.getResourceAsStream(s"/data/$filename")
val in = getClass.getResourceAsStream(s"/data/$filename")
val raw = Source.fromInputStream(in).getLines().mkString
Json.parse(raw)
}
Expand Down
4 changes: 2 additions & 2 deletions app/uk/gov/hmrc/breathingspaceifstub/utils/Filters.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import play.api.mvc._
import uk.gov.hmrc.play.bootstrap.filters.{AuditFilter, CacheControlFilter, LoggingFilter, MDCFilter}
import uk.gov.hmrc.play.bootstrap.metrics.MetricsFilter

class Filters @Inject()(
class Filters @Inject() (
metricsFilter: MetricsFilter,
auditFilter: AuditFilter,
loggingFilter: LoggingFilter,
Expand All @@ -42,7 +42,7 @@ class Filters @Inject()(
new StubRequestLoggingFilter()
)

class StubRequestLoggingFilter @Inject()(implicit val mat: Materializer, ec: ExecutionContext) extends Filter {
class StubRequestLoggingFilter @Inject() (implicit val mat: Materializer, ec: ExecutionContext) extends Filter {

lazy val logger = LoggerFactory.getLogger(this.getClass)

Expand Down
29 changes: 15 additions & 14 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,32 +1,33 @@
import uk.gov.hmrc.DefaultBuildSettings
import uk.gov.hmrc.DefaultBuildSettings.*

val appName = "breathing-space-if-stub"

val silencerVersion = "1.7.1"

ThisBuild / majorVersion := 1
ThisBuild / scalaVersion := "2.13.12"
ThisBuild / majorVersion := 2
ThisBuild / scalaVersion := "3.3.4"
ThisBuild / scalafmtOnCompile := true

lazy val microservice = Project(appName, file("."))
.enablePlugins(play.sbt.PlayScala, SbtAutoBuildPlugin, SbtDistributablesPlugin)
.enablePlugins(play.sbt.PlayScala, SbtDistributablesPlugin)
.disablePlugins(JUnitXmlReportPlugin)
.settings(
PlayKeys.playDefaultPort := 9503,
libraryDependencies ++= Dependencies.compile ++ Dependencies.test,
scalacOptions ++= Seq(
"-Werror",
"-Wdead-code",
"-Wunused:_",
"-Wextra-implicit",
"-feature",
"-Wconf:cat=unused&src=.*Controller\\.scala:s",
"-Wconf:cat=unused&src=.*RoutesPrefix\\.scala:s",
"-Wconf:cat=unused&src=.*Routes\\.scala:s",
"-Wconf:cat=unused&src=.*ReverseRoutes\\.scala:s",
"-Wconf:cat=unused&src=.*JavaScriptReverseRoutes\\.scala:s",
"-Wconf:src=routes/.*:s")
"-Werror",
"-language:noAutoTupling",
"-language:strictEquality",
"-Wvalue-discard",
"-Xfatal-warnings",
"-Wconf:msg=unused import&src=.*views\\.html.*:s",
"-Wconf:msg=unused import&src=<empty>:s",
"-Wconf:msg=unused&src=.*RoutesPrefix\\.scala:s",
"-Wconf:msg=unused&src=.*Routes\\.scala:s",
"-Wconf:msg=unused&src=.*ReverseRoutes\\.scala:s",
"-Wconf:msg=Flag.*repeatedly:s"
)
)
.settings(
scoverageSettings,
Expand Down
13 changes: 0 additions & 13 deletions conf/application-json-logger.xml

This file was deleted.

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
Loading