From d20681376ceb44a680ba9f3c255f181e4abe7deb Mon Sep 17 00:00:00 2001 From: Alex Rimmer <31283208+AlexRimmerHMRC@users.noreply.github.com> Date: Fri, 22 Jul 2022 09:59:44 +0100 Subject: [PATCH] ITSASU-1373 - Remove simple-reactivemongo dependency --- app/repositories/LockoutMongoRepository.scala | 46 ++++++----------- app/repositories/ThrottlingRepository.scala | 50 ++++++------------- conf/application.conf | 1 - project/AppDependencies.scala | 3 -- 4 files changed, 30 insertions(+), 70 deletions(-) diff --git a/app/repositories/LockoutMongoRepository.scala b/app/repositories/LockoutMongoRepository.scala index 153ded2b..06b8f925 100644 --- a/app/repositories/LockoutMongoRepository.scala +++ b/app/repositories/LockoutMongoRepository.scala @@ -16,34 +16,34 @@ package repositories -import com.mongodb.client.model.{IndexModel, IndexOptions} +import com.mongodb.client.model.IndexOptions import config.AppConfig import models.lockout.CheckLockout import models.matching.LockoutResponse import org.bson.Document import org.mongodb.scala.bson.conversions.Bson +import org.mongodb.scala.model.IndexModel import org.mongodb.scala.result.InsertOneResult import org.mongodb.scala.{Observable, SingleObservable} import play.api.libs.json.{Format, JsObject, JsValue, Json} -import reactivemongo.bson.BSONDocument -import repositories.LockoutMongoRepository.toIndexModel import uk.gov.hmrc.mongo.MongoComponent import uk.gov.hmrc.mongo.play.json.PlayMongoRepository import java.time._ +import java.util.concurrent.TimeUnit import javax.inject.{Inject, Singleton} import scala.concurrent.{ExecutionContext, Future} import scala.language.implicitConversions @Singleton -class LockoutMongoRepositoryConfig @Inject()( - val appConfig: AppConfig) { +class LockoutMongoRepositoryConfig @Inject()(val appConfig: AppConfig) { def mongoComponent: MongoComponent = MongoComponent(appConfig.mongoUri) import repositories.LockoutMongoRepository.lockIndex - def indexes: Seq[IndexModel] = Seq(toIndexModel(lockIndex)) + def indexes: Seq[IndexModel] = Seq(lockIndex) + } @Singleton @@ -52,7 +52,8 @@ class LockoutMongoRepository @Inject()(val config: LockoutMongoRepositoryConfig) collectionName = "selfEmploymentsData", mongoComponent = config.mongoComponent, domainFormat = implicitly[Format[JsObject]], - indexes = config.indexes + indexes = config.indexes, + replaceIndexes = true ) { def insert(document: JsObject): Future[InsertOneResult] = collection.insertOne(document).toFuture @@ -100,15 +101,13 @@ class LockoutMongoRepository @Inject()(val config: LockoutMongoRepositoryConfig) object LockoutMongoRepository { - val lockIndex: Index = Index( - Seq((CheckLockout.expiry, IndexType.ascending)), - name = Some("lockExpires"), - unique = false, - // background = false, - dropDups = false, - sparse = false, - version = None, - options = BSONDocument("expireAfterSeconds" -> 0) + val lockIndex: IndexModel = IndexModel( + Json.obj(CheckLockout.expiry -> IndexType.ascending), + new IndexOptions() + .name("lockExpires") + .unique(false) + .sparse(false) + .expireAfter(0, TimeUnit.SECONDS) ) object IndexType { @@ -117,15 +116,6 @@ object LockoutMongoRepository { def descending: Int = -1 } - case class Index( - key: Seq[(String, Json.JsValueWrapper)], - name: Option[String], - unique: Boolean, - dropDups: Boolean, - sparse: Boolean, - version: Option[Any], - options: BSONDocument) - implicit def asOption(o: JsObject): Option[JsValue] = o.result.toOption.flatMap(Option(_)) implicit def toBson(doc: JsObject): Bson = Document.parse(doc.toString()) @@ -134,11 +124,5 @@ object LockoutMongoRepository { implicit def toFuture[T](observable: Observable[T]): Future[Seq[T]] = observable.toFuture() - implicit def toIndexModel(index: Index): IndexModel = new IndexModel( - Json.obj(index.key: _*), - new IndexOptions() - .name(index.name.get) - .unique(index.unique) - .sparse(index.sparse)) } diff --git a/app/repositories/ThrottlingRepository.scala b/app/repositories/ThrottlingRepository.scala index 228cf9cd..0565da3e 100644 --- a/app/repositories/ThrottlingRepository.scala +++ b/app/repositories/ThrottlingRepository.scala @@ -24,8 +24,6 @@ import org.mongodb.scala.model.IndexModel import org.mongodb.scala.result.InsertOneResult import org.mongodb.scala.{Observable, SingleObservable} import play.api.libs.json.{Format, JsObject, JsValue, Json} -import reactivemongo.bson.BSONDocument -import reactivemongo.play.json.ImplicitBSONHandlers._ import repositories.ThrottlingRepository._ import uk.gov.hmrc.mongo.MongoComponent import uk.gov.hmrc.mongo.play.json.PlayMongoRepository @@ -50,9 +48,11 @@ class ThrottlingRepositoryConfig @Inject()(val appConfig: AppConfig) { def mongoComponent: MongoComponent = MongoComponent(appConfig.mongoUri) - def indexes: Seq[IndexModel] = - Seq(ttlIndex(ttlLengthSeconds)) ++ - Seq(idTimecodeIndex).map(toIndexModel) + def indexes: Seq[IndexModel] = Seq( + ttlIndex(ttlLengthSeconds), + idTimecodeIndex + ) + } @Singleton @@ -129,16 +129,6 @@ class ThrottlingRepository @Inject()(config: ThrottlingRepositoryConfig, instant object ThrottlingRepository { - case class Index( - key: Seq[(String, Json.JsValueWrapper)], - name: Option[String], - unique: Boolean, - dropDups: Boolean, - sparse: Boolean, - version: Option[Any], - options: BSONDocument - ) - object IndexType { def ascending: Int = 1 @@ -153,32 +143,22 @@ object ThrottlingRepository { implicit def toFuture[T](observable: Observable[T]): Future[Seq[T]] = observable.toFuture() - implicit def toIndexModel(index: Index): IndexModel = new IndexModel( - Json.obj(index.key: _*), - new IndexOptions() - .name(index.name.get) - .unique(index.unique) - .sparse(index.sparse)) - val throttleIdKey = "throttleId" val timecodeKey = "timecode" val countKey = "count" val lastUpdatedTimestampKey = "lastUpdatedTimestamp" - val idTimecodeIndex: Index = - Index( - key = Seq( - throttleIdKey -> IndexType.ascending, - timecodeKey -> IndexType.ascending - ), - name = Some("idTimecodeIndex"), - unique = true, - dropDups = false, - sparse = true, - version = None, - options = BSONDocument() - ) + val idTimecodeIndex: IndexModel = IndexModel( + Json.obj( + throttleIdKey -> IndexType.ascending, + timecodeKey -> IndexType.ascending + ), + new IndexOptions() + .name("idTimecodeIndex") + .unique(true) + .sparse(true) + ) def ttlIndex(ttlLengthSeconds: Long): IndexModel = new IndexModel( Json.obj(lastUpdatedTimestampKey -> IndexType.ascending), diff --git a/conf/application.conf b/conf/application.conf index 8c36bc3f..6fdc85fd 100644 --- a/conf/application.conf +++ b/conf/application.conf @@ -31,7 +31,6 @@ play.application.loader = "uk.gov.hmrc.play.bootstrap.ApplicationLoader" play.http.requestHandler = "uk.gov.hmrc.play.bootstrap.http.RequestHandler" # Define any modules used here -play.modules.enabled += "play.modules.reactivemongo.ReactiveMongoHmrcModule" play.modules.enabled += "uk.gov.hmrc.play.bootstrap.HttpClientModule" play.modules.enabled += "uk.gov.hmrc.play.bootstrap.AuthModule" diff --git a/project/AppDependencies.scala b/project/AppDependencies.scala index fab2cd8c..ac5632cb 100644 --- a/project/AppDependencies.scala +++ b/project/AppDependencies.scala @@ -29,8 +29,6 @@ object AppDependencies { private val scalaJVersion = "2.4.2" - private val reactiveMongoVersion = "8.0.0-play-28" - private val hmrcMongoVersion = "0.64.0" private val wiremockVersion = "2.32.0" @@ -43,7 +41,6 @@ object AppDependencies { ws, "uk.gov.hmrc" %% "bootstrap-backend-play-28" % bootstrapBackendVersion, "uk.gov.hmrc" %% "domain" % domainVersion, - "uk.gov.hmrc" %% "simple-reactivemongo" % reactiveMongoVersion, "uk.gov.hmrc.mongo" %% "hmrc-mongo-play-28" % hmrcMongoVersion )