Skip to content

Commit

Permalink
API-5492 Upgrade to Java 11 and other repository updates (#68)
Browse files Browse the repository at this point in the history
* API-5492: Add scalafmt config

* API-5492: Scalafmt changes

* API-5492: Add scalafix config

* API-5492: Scalafix changes

* API-5492: Update scalastyle config
  • Loading branch information
johnsgp authored Jan 12, 2023
1 parent aca3f36 commit 78e8979
Show file tree
Hide file tree
Showing 49 changed files with 1,079 additions and 768 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

!.gitignore
!.scalafmt.conf
!.scalafix.conf
.cache
/.classpath
db
Expand Down
25 changes: 25 additions & 0 deletions .scalafix.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
rules = [
OrganizeImports
]

OrganizeImports {
blankLines = Manual
coalesceToWildcardImportThreshold = 5
expandRelative = true
groupExplicitlyImportedImplicitsSeparately = false
groupedImports = Merge
groups = [
"re:(javax?|scala)\\."
"---"
"*"
"---"
"play"
"uk.gov.hmrc."
"---"
"uk.gov.hmrc.apiplatformoutboundsoap."
]
importSelectorsOrder = Ascii
importsOrder = Ascii
preset = DEFAULT
removeUnused = true
}
39 changes: 39 additions & 0 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
version="3.5.3"
runner.dialect = "scala213"

maxColumn = 180

assumeStandardLibraryStripMargin = true
align.stripMargin = true

align.preset = most
align.multiline = true

indent.extendSite = 4
indent.defnSite = 4

align.arrowEnumeratorGenerator = true

align.closeParenSite = true
align.openParenCallSite = false
align.openParenDefnSite = false
align.openParenCtrlSite = false

danglingParentheses.defnSite = true
danglingParentheses.callSite = true
danglingParentheses.exclude = []

newlines.source = keep
newlines.topLevelStatements = [before]
newlines.alwaysBeforeMultilineDef = false
newlines.implicitParamListModifierPrefer = before
# newlines.implicitParamListModifierForce = [before]
newlines.avoidForSimpleOverflow = [tooLong, punct, slc]

rewrite.rules = [SortModifiers]
rewrite.rules = [SortImports]

verticalMultiline.atDefnSite = true
verticalMultiline.newlineAfterOpenParen = true

includeNoParensInSelectChains = true
8 changes: 4 additions & 4 deletions app/uk/gov/hmrc/apiplatformoutboundsoap/GlobalContext.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@

package uk.gov.hmrc.apiplatformoutboundsoap

import play.api.inject.Injector

import javax.inject.{Inject, Singleton}

import play.api.inject.Injector

@Singleton
class GlobalContext @Inject()(playBuiltinInjector: Injector) {
class GlobalContext @Inject() (playBuiltinInjector: Injector) {
GlobalContext.injectorRef = playBuiltinInjector
}

object GlobalContext {
private var injectorRef: Injector = _

def injector: Injector = injectorRef
}
}
46 changes: 23 additions & 23 deletions app/uk/gov/hmrc/apiplatformoutboundsoap/config/AppConfig.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,41 +16,41 @@

package uk.gov.hmrc.apiplatformoutboundsoap.config

import play.api.Configuration
import uk.gov.hmrc.play.bootstrap.config.ServicesConfig

import javax.inject.{Inject, Singleton}
import scala.concurrent.duration.Duration

import play.api.Configuration
import uk.gov.hmrc.play.bootstrap.config.ServicesConfig

@Singleton
class AppConfig @Inject()(config: Configuration, servicesConfig: ServicesConfig) {
class AppConfig @Inject() (config: Configuration, servicesConfig: ServicesConfig) {

val authBaseUrl: String = servicesConfig.baseUrl("auth")

val auditingEnabled: Boolean = config.get[Boolean]("auditing.enabled")
val graphiteHost: String = config.get[String]("microservice.metrics.graphite.host")
val graphiteHost: String = config.get[String]("microservice.metrics.graphite.host")

val ccn2Host: String = config.get[String]("ccn2Host")
val ccn2Port: Int = config.get[Int]("ccn2Port")
val ccn2Username: String = config.get[String]("ccn2Username")
val ccn2Password: String = config.get[String]("ccn2Password")
val ccn2Host: String = config.get[String]("ccn2Host")
val ccn2Port: Int = config.get[Int]("ccn2Port")
val ccn2Username: String = config.get[String]("ccn2Username")
val ccn2Password: String = config.get[String]("ccn2Password")
val cryptoKeystoreLocation: String = config.get[String]("cryptoKeystoreLocation")
val keystoreAlias:String = config.get[String]("keystoreAlias")
val keystorePassword: String = config.get[String]("keystorePassword")
val enableMessageSigning: Boolean = config.get[Boolean]("enableMessageSigning")

val retryInterval: Duration = Duration(config.getOptional[String]("retry.interval").getOrElse("60 sec"))
val retryDuration: Duration = Duration(config.getOptional[String]("retry.duration").getOrElse("5 min"))
val retryInitialDelay: Duration = Duration(config.getOptional[String]("retry.initial.delay").getOrElse("30 sec"))
val retryEnabled: Boolean = config.getOptional[Boolean]("retry.enabled").getOrElse(false)
val keystoreAlias: String = config.get[String]("keystoreAlias")
val keystorePassword: String = config.get[String]("keystorePassword")
val enableMessageSigning: Boolean = config.get[Boolean]("enableMessageSigning")

val retryInterval: Duration = Duration(config.getOptional[String]("retry.interval").getOrElse("60 sec"))
val retryDuration: Duration = Duration(config.getOptional[String]("retry.duration").getOrElse("5 min"))
val retryInitialDelay: Duration = Duration(config.getOptional[String]("retry.initial.delay").getOrElse("30 sec"))
val retryEnabled: Boolean = config.getOptional[Boolean]("retry.enabled").getOrElse(false)
val retryJobLockDuration: Duration = Duration(config.getOptional[String]("retry.lock.duration").getOrElse("1 hr"))
val retryMessagesTtl: Duration = Duration(config.getOptional[String]("retry.messages.ttl").getOrElse("30 day"))
val retryMessagesTtl: Duration = Duration(config.getOptional[String]("retry.messages.ttl").getOrElse("30 day"))

val parallelism: Int = config.getOptional[Int]("retry.parallelism").getOrElse(5)
val cacheDuration: Duration = Duration(config.getOptional[String]("cache.duration").getOrElse("1 day"))
val addressingFrom: String = config.getOptional[String]("addressing.from").getOrElse("")
val addressingReplyTo: String = config.getOptional[String]("addressing.replyTo").getOrElse("")
val addressingFaultTo: String = config.getOptional[String]("addressing.faultTo").getOrElse("")
val parallelism: Int = config.getOptional[Int]("retry.parallelism").getOrElse(5)
val cacheDuration: Duration = Duration(config.getOptional[String]("cache.duration").getOrElse("1 day"))
val addressingFrom: String = config.getOptional[String]("addressing.from").getOrElse("")
val addressingReplyTo: String = config.getOptional[String]("addressing.replyTo").getOrElse("")
val addressingFaultTo: String = config.getOptional[String]("addressing.faultTo").getOrElse("")
val confirmationOfDelivery: Boolean = config.getOptional[Boolean]("confirmationOfDelivery").getOrElse(false)
val proxyRequiredForThisEnvironment = config.getOptional[Boolean]("proxy.proxyRequiredForThisEnvironment").getOrElse(false)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@
package uk.gov.hmrc.apiplatformoutboundsoap.config

import com.google.inject.AbstractModule

import uk.gov.hmrc.apiplatformoutboundsoap.GlobalContext

class InjectionModule extends AbstractModule {

override def configure() = {

// Eager initialize Context singleton
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@

package uk.gov.hmrc.apiplatformoutboundsoap.connectors

import javax.inject.{Inject, Singleton}
import scala.concurrent.Future.successful
import scala.concurrent.{ExecutionContext, Future}

import play.api.Logging
import uk.gov.hmrc.apiplatformoutboundsoap.models.JsonFormats.soapMessageStatusFormatter
import uk.gov.hmrc.apiplatformoutboundsoap.models.{OutboundSoapMessage, SoapMessageStatus}
import uk.gov.hmrc.http.HttpReads.Implicits._
import uk.gov.hmrc.http.{HttpClient, _}

import javax.inject.{Inject, Singleton}
import scala.concurrent.Future.successful
import scala.concurrent.{ExecutionContext, Future}
import uk.gov.hmrc.apiplatformoutboundsoap.models.JsonFormats.soapMessageStatusFormatter
import uk.gov.hmrc.apiplatformoutboundsoap.models.{OutboundSoapMessage, SoapMessageStatus}

@Singleton
class NotificationCallbackConnector @Inject()(httpClient: HttpClient)
(implicit ec: ExecutionContext) extends HttpErrorFunctions with Logging {
class NotificationCallbackConnector @Inject() (httpClient: HttpClient)(implicit ec: ExecutionContext) extends HttpErrorFunctions with Logging {

def sendNotification(message: OutboundSoapMessage)(implicit hc: HeaderCarrier): Future[Option[Int]] = {
(message.notificationUrl map { url =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,30 @@

package uk.gov.hmrc.apiplatformoutboundsoap.connectors

import javax.inject.{Inject, Singleton}
import scala.concurrent.{ExecutionContext, Future}
import scala.util.control.NonFatal

import org.apache.http.HttpStatus

import play.api.Logging
import play.api.http.HeaderNames.CONTENT_TYPE
import uk.gov.hmrc.apiplatformoutboundsoap.config.AppConfig
import uk.gov.hmrc.apiplatformoutboundsoap.models.SoapRequest
import uk.gov.hmrc.http.HttpReads.Implicits._
import uk.gov.hmrc.http.{HttpClient, _}

import javax.inject.{Inject, Singleton}
import scala.concurrent.{ExecutionContext, Future}
import scala.util.control.NonFatal
import uk.gov.hmrc.apiplatformoutboundsoap.config.AppConfig
import uk.gov.hmrc.apiplatformoutboundsoap.models.SoapRequest

@Singleton
class OutboundConnector @Inject()(
appConfig: AppConfig,
defaultHttpClient: HttpClient,
proxiedHttpClient: ProxiedHttpClient)
(implicit ec: ExecutionContext) extends HttpErrorFunctions with Logging {
class OutboundConnector @Inject() (
appConfig: AppConfig,
defaultHttpClient: HttpClient,
proxiedHttpClient: ProxiedHttpClient
)(implicit ec: ExecutionContext
) extends HttpErrorFunctions with Logging {

lazy val httpClient: HttpClient = if (useProxy) proxiedHttpClient else defaultHttpClient
val useProxy: Boolean = useProxyForEnv()
val useProxy: Boolean = useProxyForEnv()

def postMessage(messageId: String, soapRequest: SoapRequest): Future[Int] = {
implicit val hc: HeaderCarrier = HeaderCarrier().withExtraHeaders(CONTENT_TYPE -> "application/soap+xml")
Expand All @@ -47,7 +50,7 @@ class OutboundConnector @Inject()(
case Left(UpstreamErrorResponse(_, statusCode, _, _)) =>
logger.warn(requestLogMessage(statusCode))
statusCode
case Right(response: HttpResponse) =>
case Right(response: HttpResponse) =>
response.status
}
.recoverWith {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,23 @@

package uk.gov.hmrc.apiplatformoutboundsoap.connectors

import javax.inject.{Inject, Singleton}

import akka.actor.ActorSystem

import play.api.Configuration
import play.api.libs.ws.{WSClient, WSProxyServer}
import uk.gov.hmrc.play.audit.http.HttpAuditing
import uk.gov.hmrc.play.bootstrap.http.DefaultHttpClient
import uk.gov.hmrc.play.http.ws.{WSProxy, WSProxyConfiguration}

import javax.inject.{Inject, Singleton}

@Singleton
class ProxiedHttpClient @Inject()(
config: Configuration,
httpAuditing: HttpAuditing,
wsClient: WSClient,
actorSystem: ActorSystem
) extends DefaultHttpClient(config, httpAuditing, wsClient, actorSystem) with WSProxy {
class ProxiedHttpClient @Inject() (
config: Configuration,
httpAuditing: HttpAuditing,
wsClient: WSClient,
actorSystem: ActorSystem
) extends DefaultHttpClient(config, httpAuditing, wsClient, actorSystem) with WSProxy {

override def wsProxyServer: Option[WSProxyServer] = WSProxyConfiguration.buildWsProxyServer(config)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,34 +16,36 @@

package uk.gov.hmrc.apiplatformoutboundsoap.controllers

import javax.inject.{Inject, Singleton}
import scala.concurrent.{ExecutionContext, Future}
import scala.language.postfixOps
import scala.xml.{Node, NodeSeq}

import play.api.Logging
import play.api.mvc._
import uk.gov.hmrc.play.bootstrap.backend.controller.BackendController

import uk.gov.hmrc.apiplatformoutboundsoap.controllers.actionBuilders.ValidateConfirmationTypeAction
import uk.gov.hmrc.apiplatformoutboundsoap.models.DeliveryStatus
import uk.gov.hmrc.apiplatformoutboundsoap.models.common._
import uk.gov.hmrc.apiplatformoutboundsoap.services.ConfirmationService
import uk.gov.hmrc.play.bootstrap.backend.controller.BackendController

import javax.inject.{Inject, Singleton}
import scala.concurrent.{ExecutionContext, Future}
import scala.xml.{Node, NodeSeq}
import scala.language.postfixOps

@Singleton
class ConfirmationController @Inject()(cc: ControllerComponents,
confirmationService: ConfirmationService,
validateConfirmationTypeAction: ValidateConfirmationTypeAction)
(implicit ec: ExecutionContext)
extends BackendController(cc) with Logging{
class ConfirmationController @Inject() (
cc: ControllerComponents,
confirmationService: ConfirmationService,
validateConfirmationTypeAction: ValidateConfirmationTypeAction
)(implicit ec: ExecutionContext
) extends BackendController(cc) with Logging {

def message: Action[NodeSeq] = (Action andThen validateConfirmationTypeAction).async(parse.xml) { implicit request =>
val xml: NodeSeq = request.body

def callService(deliveryStatus: DeliveryStatus, id: String): Future[Result] = {
if(id.trim.nonEmpty) {
if (id.trim.nonEmpty) {
confirmationService.processConfirmation(xml, id.trim, deliveryStatus) map {
case UpdateSuccessResult => Accepted
case _ =>
case _ =>
logger.warn(s"No message found with global ID [$id]. Request is ${xml}")
NotFound
}
Expand All @@ -57,9 +59,9 @@ class ConfirmationController @Inject()(cc: ControllerComponents,

val id: Option[Node] = (xml \\ "RelatesTo" headOption)
(confirmationType, id) match {
case (Some(DeliveryStatus.COE), Some(id)) => callService(DeliveryStatus.COE, id.text)
case (Some(DeliveryStatus.COD), Some(id)) => callService(DeliveryStatus.COD, id.text)
case _ =>
case (Some(DeliveryStatus.COE), Some(id)) => callService(DeliveryStatus.COE, id.text)
case (Some(DeliveryStatus.COD), Some(id)) => callService(DeliveryStatus.COD, id.text)
case _ =>
logger.warn(s"Unable to update message with RelatesTo of [${id}] and x-soap-action value of [${confirmationType}]. Request is ${xml}")
Future.successful(BadRequest)
}
Expand Down
Loading

0 comments on commit 78e8979

Please sign in to comment.