Skip to content

Commit b3346fe

Browse files
API-6255 - Upgrade to Java 11 and other repository updates (#71)
* API-6255 - Update copyright date time * API-6255 - Update build settings * API-6255 - Java 11 build changes * API-6255 - scalafmt changes * API-6255 - scalafmt formatted changes * API-6255 - scalafix formatted changes * API-6255 - No such setting/task it:test issue fixed
1 parent 4620123 commit b3346fe

28 files changed

+256
-183
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
.*
22
!.gitignore
33
!.scalafix.conf
4+
!.scalafmt.conf
45
logs
56
project/project
67
project/target

.scalafmt.conf

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
version="3.5.3"
2+
runner.dialect = "scala213"
3+
4+
maxColumn = 180
5+
6+
assumeStandardLibraryStripMargin = true
7+
align.stripMargin = true
8+
9+
align.preset = most
10+
align.multiline = true
11+
12+
indent.extendSite = 4
13+
indent.defnSite = 4
14+
15+
align.arrowEnumeratorGenerator = true
16+
17+
align.closeParenSite = true
18+
align.openParenCallSite = false
19+
align.openParenDefnSite = false
20+
align.openParenCtrlSite = false
21+
22+
danglingParentheses.defnSite = true
23+
danglingParentheses.callSite = true
24+
danglingParentheses.exclude = []
25+
26+
newlines.source = keep
27+
newlines.topLevelStatements = [before]
28+
newlines.alwaysBeforeMultilineDef = false
29+
newlines.implicitParamListModifierPrefer = before
30+
# newlines.implicitParamListModifierForce = [before]
31+
newlines.avoidForSimpleOverflow = [tooLong, punct, slc]
32+
33+
rewrite.rules = [SortModifiers]
34+
rewrite.rules = [SortImports]
35+
36+
verticalMultiline.atDefnSite = true
37+
verticalMultiline.newlineAfterOpenParen = true
38+
39+
includeNoParensInSelectChains = true

app/uk/gov/hmrc/apiscope/controllers/ScopeController.scala

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,55 +18,59 @@ package uk.gov.hmrc.apiscope.controllers
1818

1919
import javax.inject.{Inject, Singleton}
2020
import scala.concurrent.{ExecutionContext, Future}
21+
2122
import util.ApplicationLogger
23+
2224
import play.api.libs.json._
2325
import play.api.mvc._
26+
import uk.gov.hmrc.play.bootstrap.backend.controller.BackendController
27+
2428
import uk.gov.hmrc.apiscope.models.ErrorCode._
29+
import uk.gov.hmrc.apiscope.models.ResponseFormatters._
2530
import uk.gov.hmrc.apiscope.models.{Scope, ScopeData}
2631
import uk.gov.hmrc.apiscope.services.ScopeService
27-
import uk.gov.hmrc.play.bootstrap.backend.controller.BackendController
28-
import uk.gov.hmrc.apiscope.models.ResponseFormatters._
2932

3033
@Singleton
31-
class ScopeController @Inject()(scopeService: ScopeService, cc: ControllerComponents, playBodyParsers: PlayBodyParsers)(implicit val ec: ExecutionContext)
32-
extends BackendController(cc) with ApplicationLogger {
34+
class ScopeController @Inject() (scopeService: ScopeService, cc: ControllerComponents, playBodyParsers: PlayBodyParsers)(implicit val ec: ExecutionContext)
35+
extends BackendController(cc) with ApplicationLogger {
3336

3437
def createOrUpdateScope(): Action[JsValue] = Action.async(playBodyParsers.json) { implicit request =>
3538
handleRequest[Seq[ScopeData]](request) {
36-
scopeRequest => {
37-
logger.info(s"Creating api-scope from request: $request")
38-
val scopes = scopeRequest.map {
39-
scopeData => Scope(scopeData.key, scopeData.name, scopeData.description, scopeData.confidenceLevel)
39+
scopeRequest =>
40+
{
41+
logger.info(s"Creating api-scope from request: $request")
42+
val scopes = scopeRequest.map {
43+
scopeData => Scope(scopeData.key, scopeData.name, scopeData.description, scopeData.confidenceLevel)
44+
}
45+
scopeService.saveScopes(scopes).map {
46+
scopes =>
47+
logger.info(s"api-scope successfully created: $scopes")
48+
Ok(Json.toJson(scopes))
49+
} recover recovery
4050
}
41-
scopeService.saveScopes(scopes).map {
42-
scopes =>
43-
logger.info(s"api-scope successfully created: $scopes")
44-
Ok(Json.toJson(scopes))
45-
} recover recovery
46-
}
4751
}
4852
}
4953

5054
def fetchScope(key: String): Action[AnyContent] = Action.async {
5155
scopeService.fetchScope(key).map {
5256
case Some(scope) => Ok(Json.toJson(scope))
53-
case None => NotFound(error(SCOPE_NOT_FOUND, s"Scope not found with key: $key"))
57+
case None => NotFound(error(SCOPE_NOT_FOUND, s"Scope not found with key: $key"))
5458
} recover recovery
5559
}
5660

5761
def fetchScopes(scopes: String): Action[AnyContent] = Action.async {
5862
logger.info(s"Fetching scopes: $scopes")
5963
val future: Future[Seq[Scope]] = scopes match {
60-
case "*" => scopeService.fetchAll
64+
case "*" => scopeService.fetchAll
6165
case spaceSeparatedScopes =>
6266
scopeService.fetchScopes(spaceSeparatedScopes.split("\\s+").toSet)
6367
}
6468

65-
future map(scopes => Ok(Json.toJson(scopes))) recover recovery
69+
future map (scopes => Ok(Json.toJson(scopes))) recover recovery
6670
}
6771

6872
def validate: Action[JsValue] = Action.async(playBodyParsers.json) { implicit request =>
69-
handleRequest[Seq[ScopeData]](request) (_ => Future.successful(NoContent))
73+
handleRequest[Seq[ScopeData]](request)(_ => Future.successful(NoContent))
7074
}
7175

7276
private def recovery: PartialFunction[Throwable, Result] = {
@@ -75,4 +79,4 @@ class ScopeController @Inject()(scopeService: ScopeService, cc: ControllerCompon
7579
InternalServerError(error(UNKNOWN_ERROR, "An unexpected error occurred"))
7680
}
7781

78-
}
82+
}

app/uk/gov/hmrc/apiscope/controllers/package.scala

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,22 @@
1616

1717
package uk.gov.hmrc.apiscope
1818

19+
import scala.concurrent.Future
20+
1921
import util.ApplicationLogger
2022

21-
import scala.concurrent.Future
2223
import play.api.libs.json.Json.toJson
2324
import play.api.libs.json._
2425
import play.api.mvc.Results._
2526
import play.api.mvc.{Request, Result}
2627
import uk.gov.hmrc.http.NotFoundException
28+
2729
import uk.gov.hmrc.apiscope.models.ErrorCode.{API_INVALID_JSON, SCOPE_NOT_FOUND}
2830
import uk.gov.hmrc.apiscope.models.{ErrorCode, ErrorDescription, ErrorResponse}
2931

3032
package object controllers extends ApplicationLogger {
3133

32-
33-
private def validate[T](request:Request[JsValue])(implicit tjs: Reads[T]): Either[Result, JsResult[T]] = {
34+
private def validate[T](request: Request[JsValue])(implicit tjs: Reads[T]): Either[Result, JsResult[T]] = {
3435
try {
3536
Right(request.body.validate[T])
3637
} catch {
@@ -42,21 +43,25 @@ package object controllers extends ApplicationLogger {
4243

4344
val either: Either[Result, JsResult[T]] = validate(request)
4445

45-
either.fold(Future.successful, {
46-
result => result.fold(
47-
errors => Future.successful(UnprocessableEntity(validationResult(errors))),
48-
entity => f(entity)
49-
)
50-
})
46+
either.fold(
47+
Future.successful,
48+
{
49+
result =>
50+
result.fold(
51+
errors => Future.successful(UnprocessableEntity(validationResult(errors))),
52+
entity => f(entity)
53+
)
54+
}
55+
)
5156
}
5257

53-
def validationResult(errors : Seq[(JsPath, Seq[JsonValidationError])]): JsValue = {
58+
def validationResult(errors: Seq[(JsPath, Seq[JsonValidationError])]): JsValue = {
5459

5560
val errs: Seq[ErrorDescription] = errors flatMap { case (jsPath, seqValidationError) =>
5661
seqValidationError map {
5762
validationError =>
5863
val isMissingPath = validationError.message == "error.path.missing"
59-
val message = if (isMissingPath) "element is missing" else validationError.message
64+
val message = if (isMissingPath) "element is missing" else validationError.message
6065
ErrorDescription(jsPath.toString, message)
6166
}
6267
}
@@ -66,7 +71,7 @@ package object controllers extends ApplicationLogger {
6671

6772
def recovery: PartialFunction[Throwable, Result] = {
6873
case nfe: NotFoundException => NotFound(error(SCOPE_NOT_FOUND, nfe.getMessage))
69-
case e =>
74+
case e =>
7075
logger.error(s"An unexpected error occurred: ${e.getMessage}", e)
7176
InternalServerError(error(ErrorCode.UNKNOWN_ERROR, "An unexpected error occurred"))
7277
}

app/uk/gov/hmrc/apiscope/models/ConfidenceLevel.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,16 @@
1616

1717
package uk.gov.hmrc.apiscope.models
1818

19-
import enumeratum.values.{IntEnum, IntEnumEntry, IntPlayJsonValueEnum}
20-
2119
import scala.collection.immutable
2220

21+
import enumeratum.values.{IntEnum, IntEnumEntry, IntPlayJsonValueEnum}
22+
2323
sealed abstract class ConfidenceLevel(val value: Int) extends IntEnumEntry
2424

2525
object ConfidenceLevel extends IntEnum[ConfidenceLevel] with IntPlayJsonValueEnum[ConfidenceLevel] {
2626
val values: immutable.IndexedSeq[ConfidenceLevel] = findValues
2727

28-
case object L50 extends ConfidenceLevel(50)
28+
case object L50 extends ConfidenceLevel(50)
2929
case object L200 extends ConfidenceLevel(200)
3030
case object L250 extends ConfidenceLevel(250)
3131
case object L500 extends ConfidenceLevel(500)

app/uk/gov/hmrc/apiscope/models/EnumJson.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import play.api.libs.json._
2121
object EnumJson {
2222

2323
def enumReads[E <: Enumeration](enum: E): Reads[E#Value] = new Reads[E#Value] {
24+
2425
def reads(json: JsValue): JsResult[E#Value] = json match {
2526
case JsString(s) =>
2627
try {
@@ -29,7 +30,7 @@ object EnumJson {
2930
case _: NoSuchElementException =>
3031
JsError(s"Enumeration expected of type: '${enum.getClass}', but it does not contain '$s'")
3132
}
32-
case _ => JsError("String value expected")
33+
case _ => JsError("String value expected")
3334
}
3435
}
3536

@@ -41,4 +42,4 @@ object EnumJson {
4142
Format(enumReads(enum), enumWrites)
4243
}
4344

44-
}
45+
}

app/uk/gov/hmrc/apiscope/models/ErrorCode.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ object ErrorCode extends Enumeration {
2424

2525
type ErrorCode = Value
2626

27-
val SCOPE_NOT_FOUND = Value("SCOPE_NOT_FOUND")
28-
val INVALID_REQUEST_PAYLOAD = Value("INVALID_REQUEST_PAYLOAD")
29-
val UNKNOWN_ERROR = Value("UNKNOWN_ERROR")
30-
val API_INVALID_JSON = Value("API_INVALID_JSON")
27+
val SCOPE_NOT_FOUND = Value("SCOPE_NOT_FOUND")
28+
val INVALID_REQUEST_PAYLOAD = Value("INVALID_REQUEST_PAYLOAD")
29+
val UNKNOWN_ERROR = Value("UNKNOWN_ERROR")
30+
val API_INVALID_JSON = Value("API_INVALID_JSON")
3131
val API_SCOPE_ALREADY_IN_USE = Value("API_SCOPE_ALREADY_IN_USE")
3232
}
3333

app/uk/gov/hmrc/apiscope/models/Scope.scala

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,4 @@
1616

1717
package uk.gov.hmrc.apiscope.models
1818

19-
2019
case class Scope(key: String, name: String, description: String, confidenceLevel: Option[ConfidenceLevel] = None)
21-
22-
23-

app/uk/gov/hmrc/apiscope/models/ScopeRequest.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package uk.gov.hmrc.apiscope.models
1818

1919
import play.api.libs.json.Json
2020

21-
2221
case class ScopeData(key: String, name: String, description: String, confidenceLevel: Option[ConfidenceLevel] = None) {
2322
require(key.trim.nonEmpty, s"scope key is required")
2423
require(name.trim.nonEmpty, s"scope name is required")

app/uk/gov/hmrc/apiscope/module/ScopeJsonFileReaderModule.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package uk.gov.hmrc.apiscope.module
1818

1919
import com.google.inject.AbstractModule
20+
2021
import uk.gov.hmrc.apiscope.services.ScopeJsonFileService
2122

2223
class ScopeJsonFileReaderModule extends AbstractModule {

0 commit comments

Comments
 (0)