diff --git a/bson/src/main/scala/dao/BsonDao.scala b/bson/src/main/scala/dao/BsonDao.scala index 3643560..c2a6f31 100644 --- a/bson/src/main/scala/dao/BsonDao.scala +++ b/bson/src/main/scala/dao/BsonDao.scala @@ -16,25 +16,26 @@ package reactivemongo.extensions.dao -import akka.stream.Materializer -import akka.stream.scaladsl.Sink -import play.api.libs.json.{ JsObject, Json } - -import scala.util.Random +import scala.concurrent.duration._ import scala.concurrent.Await import scala.concurrent.ExecutionContext import scala.concurrent.Future -import scala.concurrent.duration._ -import reactivemongo.api.bson._ +import scala.util.Random + +import akka.stream.scaladsl.Sink +import akka.stream.Materializer +import play.api.libs.json.{ JsObject, Json } +import reactivemongo.akkastream.cursorProducer import reactivemongo.api.{ Collation, Cursor, DB, ReadConcern, WriteConcern } -import reactivemongo.api.indexes.Index +import reactivemongo.api.bson._ +import reactivemongo.api.bson.collection.BSONCollection import reactivemongo.api.commands.WriteResult -import reactivemongo.extensions.dsl.BsonDsl._ +import reactivemongo.api.indexes.Index import reactivemongo.api.Cursor.FailOnError -import reactivemongo.api.bson.collection.BSONCollection -import reactivemongo.akkastream.cursorProducer +import reactivemongo.extensions.dsl.BsonDsl._ -/** A DAO implementation operates on BSONCollection using BSONDocument. +/** + * A DAO implementation operates on BSONCollection using BSONDocument. * * To create a DAO for a concrete model extend this class. * @@ -120,8 +121,7 @@ abstract class BsonDao[Model, ID](db: => Future[DB], collectionName: String)( )(implicit ec: ExecutionContext): Future[List[Model]] = { val from = page * pageSize collection.flatMap( - _ - .find(selector) + _.find(selector) .sort(sort) .skip(from) .cursor[Model]() @@ -146,8 +146,7 @@ abstract class BsonDao[Model, ID](db: => Future[DB], collectionName: String)( ): Future[List[Model]] = { val from = page * pageSize collection.flatMap( - _ - .find(selector) + _.find(selector) .collation(collation) .sort(sort) .skip(from) @@ -226,10 +225,9 @@ abstract class BsonDao[Model, ID](db: => Future[DB], collectionName: String)( _id <- Future(doc.getAsTry[ID]("_id").get) res <- { val mappedModel = lifeCycle.prePersist(model) - collection.flatMap(_.update.one($id(_id), mappedModel, upsert = true).map { - result => - lifeCycle.postPersist(mappedModel) - result + collection.flatMap(_.update.one($id(_id), mappedModel, upsert = true).map { result => + lifeCycle.postPersist(mappedModel) + result }) } } yield res diff --git a/bson/src/main/scala/dao/BsonDaoBuilder.scala b/bson/src/main/scala/dao/BsonDaoBuilder.scala index ab33e6b..748cada 100644 --- a/bson/src/main/scala/dao/BsonDaoBuilder.scala +++ b/bson/src/main/scala/dao/BsonDaoBuilder.scala @@ -16,12 +16,12 @@ package reactivemongo.extensions.dao -import reactivemongo.api.DB -import reactivemongo.api.bson._ - import scala.concurrent.ExecutionContext import scala.concurrent.Future +import reactivemongo.api.bson._ +import reactivemongo.api.DB + class BsonDaoBuilder[Model, ID](db: => Future[DB]) { def apply(collectionName: String)( implicit modelReader: BSONDocumentReader[Model], diff --git a/bson/src/main/scala/dsl/BsonDsl.scala b/bson/src/main/scala/dsl/BsonDsl.scala index 9bbe98f..19acddf 100644 --- a/bson/src/main/scala/dsl/BsonDsl.scala +++ b/bson/src/main/scala/dsl/BsonDsl.scala @@ -16,18 +16,18 @@ package reactivemongo.extensions.dsl +import scala.reflect.runtime.universe.TypeTag + import reactivemongo.api.bson._ import reactivemongo.extensions.BsonTypes -import scala.reflect.runtime.universe.TypeTag - trait BsonDsl { implicit def bsonDocumentToPretty(document: BSONDocument): String = { BSONDocument.pretty(document) } - //**********************************************************************************************// + // **********************************************************************************************// // Helpers def $empty: BSONDocument = BSONDocument.empty @@ -42,9 +42,9 @@ trait BsonDsl { def $id[T](id: T)(implicit writer: BSONWriter[T]): BSONDocument = BSONDocument("_id" -> id) // End of Helpers - //**********************************************************************************************// + // **********************************************************************************************// - //**********************************************************************************************// + // **********************************************************************************************// // Top Level Logical Operators def $or(expressions: BSONDocument*): BSONDocument = { BSONDocument("$or" -> expressions) @@ -58,9 +58,9 @@ trait BsonDsl { BSONDocument("$nor" -> expressions) } // End of Top Level Logical Operators - //**********************************************************************************************// + // **********************************************************************************************// - //**********************************************************************************************// + // **********************************************************************************************// // Top Level Evaluation Operators def $text(search: String): BSONDocument = { BSONDocument("$text" -> BSONDocument("$search" -> search)) @@ -74,9 +74,9 @@ trait BsonDsl { BSONDocument("$where" -> expression) } // End of Top Level Evaluation Operators - //**********************************************************************************************// + // **********************************************************************************************// - //**********************************************************************************************// + // **********************************************************************************************// // Top Level Field Update Operators def $inc(item: ElementProducer, items: ElementProducer*): BSONDocument = { BSONDocument("$inc" -> BSONDocument((Seq(item) ++ items): _*)) @@ -133,9 +133,9 @@ trait BsonDsl { BSONDocument("$currentDate" -> BSONDocument(items.map(item => item._1 -> item._2.produce))) } // End of Top Level Field Update Operators - //**********************************************************************************************// + // **********************************************************************************************// - //**********************************************************************************************// + // **********************************************************************************************// // Top Level Array Update Operators def $addToSet(item: ElementProducer, items: ElementProducer*): BSONDocument = { BSONDocument("$addToSet" -> BSONDocument((Seq(item) ++ items): _*)) @@ -160,9 +160,10 @@ trait BsonDsl { BSONDocument("$pull" -> BSONDocument(item)) } // End ofTop Level Array Update Operators - //**********************************************************************************************// + // **********************************************************************************************// - /** Represents the inital state of the expression which has only the name of the field. + /** + * Represents the inital state of the expression which has only the name of the field. * It does not know the value of the expression. */ trait ElementBuilder { @@ -178,24 +179,24 @@ trait BsonDsl { /* * This type of expressions cannot be cascaded. Examples: * - * {{{ + * {{{ * "price" $eq 10 * "price" $ne 1000 * "size" $in ("S", "M", "L") * "size" $nin ("S", "XXL") * }}} * - */ + */ case class SimpleExpression[V <: BSONValue](field: String, value: V) extends Expression[V] - /** Expressions of this type can be cascaded. Examples: + /** + * Expressions of this type can be cascaded. Examples: * - * {{{ + * {{{ * "age" $gt 50 $lt 60 * "age" $gte 50 $lte 60 * }}} - * - */ + */ case class CompositeExpression(field: String, value: BSONDocument) extends Expression[BSONDocument] with ComparisonOperators { @@ -221,7 +222,7 @@ trait BsonDsl { CompositeExpression(field, append(BSONDocument("$gte" -> value))) } - /** Matches any of the values that exist in an array specified in the query.*/ + /** Matches any of the values that exist in an array specified in the query. */ def $in[T](values: T*)(implicit writer: BSONWriter[T]): SimpleExpression[BSONDocument] = { SimpleExpression(field, BSONDocument("$in" -> values)) } diff --git a/bson/src/main/scala/dsl/criteria/Expression.scala b/bson/src/main/scala/dsl/criteria/Expression.scala index 48c9bf0..9555a36 100644 --- a/bson/src/main/scala/dsl/criteria/Expression.scala +++ b/bson/src/main/scala/dsl/criteria/Expression.scala @@ -17,11 +17,12 @@ package reactivemongo.extensions.dsl.criteria import scala.language.dynamics import scala.language.implicitConversions -import reactivemongo.api.bson._ - import scala.util.Try -/** The '''Expression''' type defines a recursive propositional abstract +import reactivemongo.api.bson._ + +/** + * The '''Expression''' type defines a recursive propositional abstract * syntax tree central to the MongoDB embedded domain-specific language (EDSL). * It is the main abstraction used to provide the EDSL and results in being * able to write: @@ -30,45 +31,45 @@ import scala.util.Try * import Untyped._ * * val edslQuery = criteria.first < 10 && ( - * criteria.second >= 20.0 || criteria.second.in (0.0, 1.0) - * ); + * criteria.second >= 20.0 || criteria.second.in (0.0, 1.0) + * ); * }}} * * And have that equivalent to this filter: * * {{{ * val bsonQuery = BSONDocument ( - * "$and" -> - * BSONArray ( - * BSONDocument ( - * "first" -> BSONDocument ("$lt" -> BSONInteger (10)) - * ), - * BSONDocument ( - * "$or" -> - * BSONArray ( - * BSONDocument ( - * "second" -> BSONDocument ("$gte" -> BSONDouble (20.0)) - * ), - * BSONDocument ( - * "second" -> - * BSONDocument ( - * "$in" -> BSONArray (BSONDouble (0.0), BSONDouble (1.0)) - * ) - * ) - * ) - * ) - * ) - * ); + * "$and" -> + * BSONArray ( + * BSONDocument ( + * "first" -> BSONDocument ("$lt" -> BSONInteger (10)) + * ), + * BSONDocument ( + * "$or" -> + * BSONArray ( + * BSONDocument ( + * "second" -> BSONDocument ("$gte" -> BSONDouble (20.0)) + * ), + * BSONDocument ( + * "second" -> + * BSONDocument ( + * "$in" -> BSONArray (BSONDouble (0.0), BSONDouble (1.0)) + * ) + * ) + * ) + * ) + * ) + * ); * }}} * * @author svickers - * */ case class Expression(name: Option[String], element: BSONElement) { /// Class Imports import Expression._ - /** The logical negation operator attempts to invert this '''Expression''' + /** + * The logical negation operator attempts to invert this '''Expression''' * by using complimentary operators if possible, falling back to the * general-case wrapping in a `$not` operator. */ @@ -102,19 +103,23 @@ case class Expression(name: Option[String], element: BSONElement) { Expression(Some("$not"), el) } - /** Conjunction: ''AND''. + /** + * Conjunction: ''AND''. */ def &&(rhs: Expression): Expression = combine("$and", rhs) - /** Negation of conjunction: ''NOR''. + /** + * Negation of conjunction: ''NOR''. */ def !&&(rhs: Expression): Expression = combine("$nor", rhs) - /** Disjunction: ''OR''. + /** + * Disjunction: ''OR''. */ def ||(rhs: Expression): Expression = combine("$or", rhs) - /** The isEmpty method reports as to whether or not this '''Expression''' + /** + * The isEmpty method reports as to whether or not this '''Expression''' * has neither a `name` nor an assigned value. */ def isEmpty: Boolean = name.isEmpty && element.name.isEmpty @@ -137,12 +142,14 @@ case class Expression(name: Option[String], element: BSONElement) { object Expression { - /** The empty property is provided so that ''monoid'' definitions for + /** + * The empty property is provided so that ''monoid'' definitions for * '''Expression''' can be easily provided. */ val empty = new Expression(None, "" -> BSONDocument.empty) - /** The apply method provides functional-style creation syntax for + /** + * The apply method provides functional-style creation syntax for * [[reactivemongo.extensions.dsl.criteria.Expression]] instances. */ def apply(name: String, element: BSONElement): Expression = new Expression(Some(name), element) diff --git a/bson/src/main/scala/dsl/criteria/Term.scala b/bson/src/main/scala/dsl/criteria/Term.scala index 43775a8..8f4bd74 100644 --- a/bson/src/main/scala/dsl/criteria/Term.scala +++ b/bson/src/main/scala/dsl/criteria/Term.scala @@ -19,71 +19,83 @@ import scala.language.dynamics import reactivemongo.api.bson._ -/** A '''Term'' instance reifies the use of a MongoDB document field, both +/** + * A '''Term'' instance reifies the use of a MongoDB document field, both * top-level or nested. Operators common to all ''T'' types are defined here * with type-specific ones provided in the companion object below. * * @author svickers - * */ case class Term[T](`_term$name`: String) extends Dynamic { - /** Logical equality. + /** + * Logical equality. */ def ===[U <: T: ValueBuilder](rhs: U): Expression = Expression(`_term$name`, `_term$name` -> implicitly[ValueBuilder[U]].bson(rhs)); - /** Logical equality. + /** + * Logical equality. */ def @==[U <: T: ValueBuilder](rhs: U): Expression = ===[U](rhs); - /** Logical inequality: '''$ne'''. + /** + * Logical inequality: '''$ne'''. */ def <>[U <: T: ValueBuilder](rhs: U): Expression = Expression(`_term$name`, "$ne" -> implicitly[ValueBuilder[U]].bson(rhs)); - /** Logical inequality: '''$ne'''. + /** + * Logical inequality: '''$ne'''. */ def =/=[U <: T: ValueBuilder](rhs: U): Expression = <>[U](rhs); - /** Logical inequality: '''$ne'''. + /** + * Logical inequality: '''$ne'''. */ def !==[U <: T: ValueBuilder](rhs: U): Expression = <>[U](rhs); - /** Less-than comparison: '''$lt'''. + /** + * Less-than comparison: '''$lt'''. */ def <[U <: T: ValueBuilder](rhs: U): Expression = Expression(`_term$name`, "$lt" -> implicitly[ValueBuilder[U]].bson(rhs)); - /** Less-than or equal comparison: '''$lte'''. + /** + * Less-than or equal comparison: '''$lte'''. */ def <=[U <: T: ValueBuilder](rhs: U): Expression = Expression(`_term$name`, "$lte" -> implicitly[ValueBuilder[U]].bson(rhs)); - /** Greater-than comparison: '''$gt'''. + /** + * Greater-than comparison: '''$gt'''. */ def >[U <: T: ValueBuilder](rhs: U): Expression = Expression(`_term$name`, "$gt" -> implicitly[ValueBuilder[U]].bson(rhs)); - /** Greater-than or equal comparison: '''$gte'''. + /** + * Greater-than or equal comparison: '''$gte'''. */ def >=[U <: T: ValueBuilder](rhs: U): Expression = Expression(`_term$name`, "$gte" -> implicitly[ValueBuilder[U]].bson(rhs)); - /** Field existence: '''$exists'''. + /** + * Field existence: '''$exists'''. */ def exists: Expression = Expression(`_term$name`, "$exists" -> BSONBoolean(true)); - /** Field value equals one of the '''values''': '''$in'''. + /** + * Field value equals one of the '''values''': '''$in'''. */ def in[U <: T: ValueBuilder](values: Iterable[U])(implicit B: ValueBuilder[U]): Expression = Expression(`_term$name`, "$in" -> BSONArray(values.map(B.bson))); - /** Field value equals either '''head''' or one of the (optional) '''tail''' values: '''$in'''. + /** + * Field value equals either '''head''' or one of the (optional) '''tail''' values: '''$in'''. */ def in[U <: T: ValueBuilder](head: U, tail: U*)(implicit B: ValueBuilder[U]): Expression = Expression(`_term$name`, "$in" -> BSONArray(Seq(B.bson(head)) ++ tail.map(B.bson))); @@ -94,7 +106,8 @@ case class Term[T](`_term$name`: String) extends Dynamic { object Term { /// Class Types - /** The '''CollectionTermOps''' `implicit` provides EDSL functionality to + /** + * The '''CollectionTermOps''' `implicit` provides EDSL functionality to * `Seq` [[reactivemongo.extensions.dsl.criteria.Term]]s only. */ implicit class CollectionTermOps[T](val term: Term[Seq[T]]) extends AnyVal { @@ -102,7 +115,8 @@ object Term { Expression(term.`_term$name`, "$all" -> BSONArray(values.map(B.bson))); } - /** The '''StringTermOps''' `implicit` enriches + /** + * The '''StringTermOps''' `implicit` enriches * [[reactivemongo.extensions.dsl.criteria.Term]]s for `String`-only operations. */ implicit class StringTermOps[T >: String](val term: Term[T]) extends AnyVal { diff --git a/bson/src/main/scala/dsl/criteria/Typed.scala b/bson/src/main/scala/dsl/criteria/Typed.scala index cccf4d4..0bb1026 100644 --- a/bson/src/main/scala/dsl/criteria/Typed.scala +++ b/bson/src/main/scala/dsl/criteria/Typed.scala @@ -22,13 +22,12 @@ import scala.language.experimental.macros import scala.reflect.macros.whitebox.Context import scala.reflect.runtime.universe._ -/** The '''Typed''' `object` provides the ability to ''lift'' an arbitrary type +/** + * The '''Typed''' `object` provides the ability to ''lift'' an arbitrary type * `T` into the [[reactivemongo.extensions.dsl.criteria]] world. Each property * is represented as a [[reactivemongo.extensions.dsl.criteria.Term]]. * - * * @author svickers - * */ object Typed { /// Class Types @@ -64,7 +63,8 @@ object Typed { } } - /** The criteria method produces a type which enforces the existence of + /** + * The criteria method produces a type which enforces the existence of * property names within ''T''. */ def criteria[T] = new PropertyAccess[T] diff --git a/bson/src/main/scala/dsl/criteria/Untyped.scala b/bson/src/main/scala/dsl/criteria/Untyped.scala index 745037a..0d26c17 100644 --- a/bson/src/main/scala/dsl/criteria/Untyped.scala +++ b/bson/src/main/scala/dsl/criteria/Untyped.scala @@ -17,7 +17,8 @@ package reactivemongo.extensions.dsl.criteria import scala.language.dynamics -/** The '''Untyped''' type defines the behaviour expected of queries where the +/** + * The '''Untyped''' type defines the behaviour expected of queries where the * MongoDB document may not correspond to a Scala type known to the system * using this abstraction. */ @@ -28,7 +29,8 @@ sealed trait Untyped extends Dynamic { object Untyped { - /** The criteria property is a ''factory'' of '''Untyped''' instances. + /** + * The criteria property is a ''factory'' of '''Untyped''' instances. */ val criteria = new Untyped {}; @@ -68,14 +70,35 @@ object Untyped { def where( block: ( - Untyped, Untyped, Untyped, Untyped, Untyped, Untyped, Untyped, Untyped, Untyped, Untyped, Untyped + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped ) => Expression ): Expression = block(criteria, criteria, criteria, criteria, criteria, criteria, criteria, criteria, criteria, criteria, criteria); def where( block: ( - Untyped, Untyped, Untyped, Untyped, Untyped, Untyped, Untyped, Untyped, Untyped, Untyped, Untyped, Untyped + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped ) => Expression ): Expression = block( @@ -95,7 +118,18 @@ object Untyped { def where( block: ( - Untyped, Untyped, Untyped, Untyped, Untyped, Untyped, Untyped, Untyped, Untyped, Untyped, Untyped, Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, Untyped ) => Expression ): Expression = @@ -117,8 +151,20 @@ object Untyped { def where( block: ( - Untyped, Untyped, Untyped, Untyped, Untyped, Untyped, Untyped, Untyped, Untyped, Untyped, Untyped, Untyped, - Untyped, Untyped + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped ) => Expression ): Expression = block( @@ -140,8 +186,21 @@ object Untyped { def where( block: ( - Untyped, Untyped, Untyped, Untyped, Untyped, Untyped, Untyped, Untyped, Untyped, Untyped, Untyped, Untyped, - Untyped, Untyped, Untyped + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped ) => Expression ): Expression = block( @@ -164,8 +223,22 @@ object Untyped { def where( block: ( - Untyped, Untyped, Untyped, Untyped, Untyped, Untyped, Untyped, Untyped, Untyped, Untyped, Untyped, Untyped, - Untyped, Untyped, Untyped, Untyped + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped ) => Expression ): Expression = block( @@ -189,8 +262,23 @@ object Untyped { def where( block: ( - Untyped, Untyped, Untyped, Untyped, Untyped, Untyped, Untyped, Untyped, Untyped, Untyped, Untyped, Untyped, - Untyped, Untyped, Untyped, Untyped, Untyped + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped ) => Expression ): Expression = block( @@ -215,8 +303,24 @@ object Untyped { def where( block: ( - Untyped, Untyped, Untyped, Untyped, Untyped, Untyped, Untyped, Untyped, Untyped, Untyped, Untyped, Untyped, - Untyped, Untyped, Untyped, Untyped, Untyped, Untyped + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped ) => Expression ): Expression = block( @@ -242,8 +346,25 @@ object Untyped { def where( block: ( - Untyped, Untyped, Untyped, Untyped, Untyped, Untyped, Untyped, Untyped, Untyped, Untyped, Untyped, Untyped, - Untyped, Untyped, Untyped, Untyped, Untyped, Untyped, Untyped + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped ) => Expression ): Expression = block( @@ -270,8 +391,26 @@ object Untyped { def where( block: ( - Untyped, Untyped, Untyped, Untyped, Untyped, Untyped, Untyped, Untyped, Untyped, Untyped, Untyped, Untyped, - Untyped, Untyped, Untyped, Untyped, Untyped, Untyped, Untyped, Untyped + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped ) => Expression ): Expression = block( @@ -299,8 +438,27 @@ object Untyped { def where( block: ( - Untyped, Untyped, Untyped, Untyped, Untyped, Untyped, Untyped, Untyped, Untyped, Untyped, Untyped, Untyped, - Untyped, Untyped, Untyped, Untyped, Untyped, Untyped, Untyped, Untyped, Untyped + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped ) => Expression ): Expression = block( @@ -329,8 +487,28 @@ object Untyped { def where( block: ( - Untyped, Untyped, Untyped, Untyped, Untyped, Untyped, Untyped, Untyped, Untyped, Untyped, Untyped, Untyped, - Untyped, Untyped, Untyped, Untyped, Untyped, Untyped, Untyped, Untyped, Untyped, Untyped + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped, + Untyped ) => Expression ): Expression = block( diff --git a/bson/src/main/scala/dsl/criteria/ValueBuilder.scala b/bson/src/main/scala/dsl/criteria/ValueBuilder.scala index 40a67d2..ab39768 100644 --- a/bson/src/main/scala/dsl/criteria/ValueBuilder.scala +++ b/bson/src/main/scala/dsl/criteria/ValueBuilder.scala @@ -19,17 +19,18 @@ import scala.language.implicitConversions import reactivemongo.api.bson._ -/** The '''ValueBuilder'' type is a model of the ''type class'' pattern used to +/** + * The '''ValueBuilder'' type is a model of the ''type class'' pattern used to * produce a ''T''-specific [[reactivemongo.bson.BSONValue]] instance. * * @author svickers - * */ trait ValueBuilder[T] { def bson(v: T): BSONValue; } -/** The '''ValueBuilder''' companion object defines common +/** + * The '''ValueBuilder''' companion object defines common * [[reactivemongo.extensions.dsl.criteria.ValueBuilder]] ''type classes'' * available for any project. Types not known to the library can define * [[reactivemongo.extensions.dsl.criteria.ValueBuilder]] instances as needed diff --git a/bson/src/main/scala/fixtures/BsonFixtures.scala b/bson/src/main/scala/fixtures/BsonFixtures.scala index be161db..321371a 100644 --- a/bson/src/main/scala/fixtures/BsonFixtures.scala +++ b/bson/src/main/scala/fixtures/BsonFixtures.scala @@ -16,15 +16,15 @@ package reactivemongo.extensions.fixtures +import scala.concurrent.{ ExecutionContext, Future } + import play.api.libs.json.JsObject -import reactivemongo.api.DB -import reactivemongo.api.bson.BSONDocument import reactivemongo.api.bson.collection.BSONCollection +import reactivemongo.api.bson.BSONDocument import reactivemongo.api.commands.WriteResult +import reactivemongo.api.DB import reactivemongo.play.json.compat.ExtendedJsonConverters -import scala.concurrent.{ ExecutionContext, Future } - class BsonFixtures(db: => Future[DB])(implicit ec: ExecutionContext) extends Fixtures[BSONDocument] { def map(document: JsObject): BSONDocument = ExtendedJsonConverters.toDocument(document) diff --git a/bson/src/test/scala/dao/CustomIdBsonDao.scala b/bson/src/test/scala/dao/CustomIdBsonDao.scala index 7a70d3c..c3b55c0 100644 --- a/bson/src/test/scala/dao/CustomIdBsonDao.scala +++ b/bson/src/test/scala/dao/CustomIdBsonDao.scala @@ -17,10 +17,11 @@ package reactivemongo.extensions.dao import scala.concurrent.ExecutionContext.Implicits.global -import reactivemongo.extensions.model.CustomIdModel -import reactivemongo.extensions.model.CustomIdModel.customIdModelHandler + import reactivemongo.api.bson._ import reactivemongo.api.indexes.IndexType +import reactivemongo.extensions.model.CustomIdModel +import reactivemongo.extensions.model.CustomIdModel.customIdModelHandler import reactivemongo.extensions.util.Misc.UUID class CustomIdBsonDao extends BsonDao[CustomIdModel, String](MongoContext.db, "customId-" + UUID()) { diff --git a/bson/src/test/scala/dao/CustomIdBsonDaoSpec.scala b/bson/src/test/scala/dao/CustomIdBsonDaoSpec.scala index bab315f..dbed182 100644 --- a/bson/src/test/scala/dao/CustomIdBsonDaoSpec.scala +++ b/bson/src/test/scala/dao/CustomIdBsonDaoSpec.scala @@ -16,15 +16,16 @@ package reactivemongo.extensions.dao +import scala.concurrent.ExecutionContext.Implicits.global + import org.scalatest._ import org.scalatest.concurrent._ +import org.scalatest.flatspec.AnyFlatSpec +import org.scalatest.matchers.should.Matchers import org.scalatest.time.SpanSugar._ import reactivemongo.api.bson._ -import reactivemongo.extensions.model.CustomIdModel import reactivemongo.extensions.dsl.BsonDsl._ -import scala.concurrent.ExecutionContext.Implicits.global -import org.scalatest.flatspec.AnyFlatSpec -import org.scalatest.matchers.should.Matchers +import reactivemongo.extensions.model.CustomIdModel class CustomIdBsonDaoSpec extends AnyFlatSpec diff --git a/bson/src/test/scala/dao/DummyBsonDao.scala b/bson/src/test/scala/dao/DummyBsonDao.scala index 6a82fc9..20ba068 100644 --- a/bson/src/test/scala/dao/DummyBsonDao.scala +++ b/bson/src/test/scala/dao/DummyBsonDao.scala @@ -17,9 +17,10 @@ package reactivemongo.extensions.dao import scala.concurrent.ExecutionContext.Implicits.global -import reactivemongo.extensions.model.DummyModel -import reactivemongo.api.indexes.IndexType + import reactivemongo.api.bson._ +import reactivemongo.api.indexes.IndexType +import reactivemongo.extensions.model.DummyModel import reactivemongo.extensions.util.Misc.UUID class DummyBsonDao extends BsonDao[DummyModel, BSONObjectID](MongoContext.db, "dummy-" + UUID()) { diff --git a/bson/src/test/scala/dao/DummyBsonDaoSpec.scala b/bson/src/test/scala/dao/DummyBsonDaoSpec.scala index 8ca614e..c4a539b 100644 --- a/bson/src/test/scala/dao/DummyBsonDaoSpec.scala +++ b/bson/src/test/scala/dao/DummyBsonDaoSpec.scala @@ -16,10 +16,14 @@ package reactivemongo.extensions.dao +import scala.concurrent.ExecutionContext.Implicits.global + import akka.actor.ActorSystem import akka.stream.ActorMaterializer import org.scalatest._ import org.scalatest.concurrent._ +import org.scalatest.flatspec.AnyFlatSpec +import org.scalatest.matchers.should.Matchers import org.scalatest.time.SpanSugar._ import reactivemongo.api.bson._ import reactivemongo.extensions.dsl.BsonDsl._ @@ -27,10 +31,6 @@ import reactivemongo.extensions.model.DummyModel import reactivemongo.extensions.util.Logger import reactivemongo.extensions.Implicits._ -import scala.concurrent.ExecutionContext.Implicits.global -import org.scalatest.flatspec.AnyFlatSpec -import org.scalatest.matchers.should.Matchers - class DummyBsonDaoSpec extends AnyFlatSpec with Matchers with ScalaFutures with BeforeAndAfter with OneInstancePerTest { implicit override def patienceConfig = PatienceConfig(timeout = 20 seconds, interval = 1 seconds) diff --git a/bson/src/test/scala/dao/DynamicBsonDaoSpec.scala b/bson/src/test/scala/dao/DynamicBsonDaoSpec.scala index 76f4548..80e1a46 100644 --- a/bson/src/test/scala/dao/DynamicBsonDaoSpec.scala +++ b/bson/src/test/scala/dao/DynamicBsonDaoSpec.scala @@ -16,17 +16,18 @@ package reactivemongo.extensions.dao +import scala.concurrent.Await +import scala.concurrent.ExecutionContext.Implicits.global + import org.scalatest._ import org.scalatest.concurrent.ScalaFutures -import org.scalatest.time.Span +import org.scalatest.flatspec.AnyFlatSpec +import org.scalatest.matchers.should.Matchers import org.scalatest.time.Seconds +import org.scalatest.time.Span import reactivemongo.api.bson._ import reactivemongo.extensions.dsl.BsonDsl._ import reactivemongo.extensions.Implicits._ -import scala.concurrent.Await -import scala.concurrent.ExecutionContext.Implicits.global -import org.scalatest.flatspec.AnyFlatSpec -import org.scalatest.matchers.should.Matchers class DynamicBsonDaoSpec extends AnyFlatSpec diff --git a/bson/src/test/scala/dao/EventBsonDao.scala b/bson/src/test/scala/dao/EventBsonDao.scala index b10d4d1..e3c6d32 100644 --- a/bson/src/test/scala/dao/EventBsonDao.scala +++ b/bson/src/test/scala/dao/EventBsonDao.scala @@ -16,13 +16,14 @@ package reactivemongo.extensions.dao -import scala.concurrent.Future -import scala.concurrent.Await import scala.concurrent.duration._ +import scala.concurrent.Await import scala.concurrent.ExecutionContext.Implicits.global -import reactivemongo.extensions.model.Event +import scala.concurrent.Future + import reactivemongo.api.DB import reactivemongo.extensions.dsl.BsonDsl +import reactivemongo.extensions.model.Event class EventBsonDao(_db: Future[DB]) extends BsonDao[Event, String](_db, "events") with BsonDsl { diff --git a/bson/src/test/scala/dao/MapModelBsonDao.scala b/bson/src/test/scala/dao/MapModelBsonDao.scala index 8ecb08a..0cc7589 100644 --- a/bson/src/test/scala/dao/MapModelBsonDao.scala +++ b/bson/src/test/scala/dao/MapModelBsonDao.scala @@ -17,9 +17,10 @@ package reactivemongo.extensions.dao import scala.concurrent.ExecutionContext.Implicits.global -import reactivemongo.extensions.model.MapModel + import reactivemongo.api.bson.BSONObjectID import reactivemongo.api.WriteConcern +import reactivemongo.extensions.model.MapModel import reactivemongo.extensions.util.Misc.UUID class MapModelBsonDao extends BsonDao[MapModel, BSONObjectID](MongoContext.db, "dummy-" + UUID()) { diff --git a/bson/src/test/scala/dao/MapModelBsonDaoSpec.scala b/bson/src/test/scala/dao/MapModelBsonDaoSpec.scala index d9f1448..9e9f2b0 100644 --- a/bson/src/test/scala/dao/MapModelBsonDaoSpec.scala +++ b/bson/src/test/scala/dao/MapModelBsonDaoSpec.scala @@ -16,16 +16,17 @@ package reactivemongo.extensions.dao +import scala.concurrent.ExecutionContext.Implicits.global + import org.scalatest._ import org.scalatest.concurrent._ +import org.scalatest.flatspec.AnyFlatSpec +import org.scalatest.matchers.should.Matchers import org.scalatest.time.SpanSugar._ import reactivemongo.api.bson._ import reactivemongo.extensions.dsl.BsonDsl._ import reactivemongo.extensions.model.MapModel import reactivemongo.extensions.Implicits._ -import scala.concurrent.ExecutionContext.Implicits.global -import org.scalatest.flatspec.AnyFlatSpec -import org.scalatest.matchers.should.Matchers class MapModelBsonDaoSpec extends AnyFlatSpec diff --git a/bson/src/test/scala/dao/PersonBsonDao.scala b/bson/src/test/scala/dao/PersonBsonDao.scala index f81c463..942d72d 100644 --- a/bson/src/test/scala/dao/PersonBsonDao.scala +++ b/bson/src/test/scala/dao/PersonBsonDao.scala @@ -16,14 +16,14 @@ package reactivemongo.extensions.dao -import scala.concurrent.Future -import scala.concurrent.Await import scala.concurrent.duration._ +import scala.concurrent.Await import scala.concurrent.ExecutionContext.Implicits.global +import scala.concurrent.Future -import reactivemongo.extensions.model.Person import reactivemongo.api.DB import reactivemongo.extensions.dsl.BsonDsl +import reactivemongo.extensions.model.Person class PersonBsonDao(_db: Future[DB]) extends BsonDao[Person, String](_db, "persons") with BsonDsl { diff --git a/bson/src/test/scala/dao/TemporalModelDao.scala b/bson/src/test/scala/dao/TemporalModelDao.scala index 4d5017a..b8b1e25 100644 --- a/bson/src/test/scala/dao/TemporalModelDao.scala +++ b/bson/src/test/scala/dao/TemporalModelDao.scala @@ -17,8 +17,9 @@ package reactivemongo.extensions.dao import scala.concurrent.ExecutionContext.Implicits.global -import reactivemongo.extensions.model.TemporalModel + import reactivemongo.api.bson.BSONObjectID +import reactivemongo.extensions.model.TemporalModel import reactivemongo.extensions.util.Misc.UUID class TemporalModelDao extends BsonDao[TemporalModel, BSONObjectID](MongoContext.db, "temporal_model_" + UUID()) diff --git a/bson/src/test/scala/dao/TemporalModelDaoSpec.scala b/bson/src/test/scala/dao/TemporalModelDaoSpec.scala index ff4b773..280cad7 100644 --- a/bson/src/test/scala/dao/TemporalModelDaoSpec.scala +++ b/bson/src/test/scala/dao/TemporalModelDaoSpec.scala @@ -16,13 +16,14 @@ package reactivemongo.extensions.dao +import scala.concurrent.ExecutionContext.Implicits.global + import org.scalatest._ import org.scalatest.concurrent._ -import org.scalatest.time.SpanSugar._ -import reactivemongo.extensions.model.TemporalModel -import scala.concurrent.ExecutionContext.Implicits.global import org.scalatest.flatspec.AnyFlatSpec import org.scalatest.matchers.should.Matchers +import org.scalatest.time.SpanSugar._ +import reactivemongo.extensions.model.TemporalModel class TemporalModelDaoSpec extends AnyFlatSpec diff --git a/bson/src/test/scala/dsl/BsonDslSpec.scala b/bson/src/test/scala/dsl/BsonDslSpec.scala index f09bbcd..0148308 100644 --- a/bson/src/test/scala/dsl/BsonDslSpec.scala +++ b/bson/src/test/scala/dsl/BsonDslSpec.scala @@ -16,12 +16,12 @@ package reactivemongo.extensions.dsl -import reactivemongo.api.bson._ -import reactivemongo.extensions.util.Logger -import BsonDsl._ import org.joda.time.DateTime import org.scalatest.flatspec.AnyFlatSpec import org.scalatest.matchers.should.Matchers +import reactivemongo.api.bson._ +import reactivemongo.extensions.util.Logger +import BsonDsl._ object BsonDslSpec extends AnyFlatSpec with Matchers { import reactivemongo.extensions.dao.Handlers._ @@ -60,7 +60,7 @@ object BsonDslSpec extends AnyFlatSpec with Matchers { document shouldBe expected } - //**********************************************************************************************// + // **********************************************************************************************// // Comparison Operators it should "create complex document 2" in { val dsl: BSONDocument = "age".$gte(50).$lte(60) @@ -114,9 +114,9 @@ object BsonDslSpec extends AnyFlatSpec with Matchers { dsl shouldBe expected } // End of Comparison Operators - //**********************************************************************************************// + // **********************************************************************************************// - //**********************************************************************************************// + // **********************************************************************************************// // Logical Operators it should "create $or" in { val dsl = $or("qty".$lt(20).$gte(10), "sale".$eq(true)) @@ -156,9 +156,9 @@ object BsonDslSpec extends AnyFlatSpec with Matchers { dsl shouldBe expected } // End of logical operators - //**********************************************************************************************// + // **********************************************************************************************// - //**********************************************************************************************// + // **********************************************************************************************// // Element Operators it should "create $exists" in { val dsl1: BSONDocument = "qty".$exists(true) @@ -180,9 +180,9 @@ object BsonDslSpec extends AnyFlatSpec with Matchers { dsl2 shouldBe expected2 } // End of Element Operators - //**********************************************************************************************// + // **********************************************************************************************// - //**********************************************************************************************// + // **********************************************************************************************// // Evaluation Operators it should "create $mod" in { val dsl: BSONDocument = "qty".$mod(5, 0) @@ -213,9 +213,9 @@ object BsonDslSpec extends AnyFlatSpec with Matchers { dsl shouldBe expected } // End of Evaluation Operators - //**********************************************************************************************// + // **********************************************************************************************// - //**********************************************************************************************// + // **********************************************************************************************// // Array Operators it should "create $all" in { val dsl: BSONDocument = "size".$all("S", "M", "L") @@ -237,9 +237,9 @@ object BsonDslSpec extends AnyFlatSpec with Matchers { dsl shouldBe expected } // End of Array Operators - //**********************************************************************************************// + // **********************************************************************************************// - //**********************************************************************************************// + // **********************************************************************************************// // Top Level Field Update Operators it should "create $inc" in { val dsl = $inc("sold" -> 1, "stock" -> -1) @@ -324,9 +324,9 @@ object BsonDslSpec extends AnyFlatSpec with Matchers { } should have).message("illegal") } // End of Top Level Field Update Operators - //**********************************************************************************************// + // **********************************************************************************************// - //**********************************************************************************************// + // **********************************************************************************************// // Top Level Array Update Operators it should "create $addToSet" in { val dsl = $addToSet("sizes" -> "L", "colours" -> "Blue") @@ -371,6 +371,6 @@ object BsonDslSpec extends AnyFlatSpec with Matchers { dsl shouldBe expected } // End ofTop Level Array Update Operators - //**********************************************************************************************// + // **********************************************************************************************// } diff --git a/bson/src/test/scala/dsl/criteria/UntypedCriteriaSpec.scala b/bson/src/test/scala/dsl/criteria/UntypedCriteriaSpec.scala index a74ad7d..3b81989 100644 --- a/bson/src/test/scala/dsl/criteria/UntypedCriteriaSpec.scala +++ b/bson/src/test/scala/dsl/criteria/UntypedCriteriaSpec.scala @@ -18,19 +18,18 @@ package reactivemongo.extensions.dsl.criteria import org.scalatest._ -import org.scalatest.matchers._ - -import reactivemongo.api.bson._ import org.scalatest.flatspec.AnyFlatSpec +import org.scalatest.matchers._ import org.scalatest.matchers.should.Matchers +import reactivemongo.api.bson._ -/** The '''UntypedCriteriaSpec''' type unit tests the +/** + * The '''UntypedCriteriaSpec''' type unit tests the * [[reactivemongo.extensions.dsl.criteria.Untyped]] EDSL functionality and * serves both to verify fitness as well as an exemplar to how the * [[reactivemongo.extensions.dsl.criteria.Untyped]] functionality can be used. * * @author svickers - * */ class UntypedCriteriaSpec extends AnyFlatSpec with Matchers { /// Class Imports diff --git a/bson/src/test/scala/dsl/criteria/UntypedWhereSpec.scala b/bson/src/test/scala/dsl/criteria/UntypedWhereSpec.scala index 921aa64..f623c91 100644 --- a/bson/src/test/scala/dsl/criteria/UntypedWhereSpec.scala +++ b/bson/src/test/scala/dsl/criteria/UntypedWhereSpec.scala @@ -18,18 +18,17 @@ package reactivemongo.extensions.dsl.criteria import org.scalatest._ -import org.scalatest.matchers._ - -import reactivemongo.api.bson._ import org.scalatest.flatspec.AnyFlatSpec +import org.scalatest.matchers._ import org.scalatest.matchers.should.Matchers +import reactivemongo.api.bson._ -/** The '''UntypedWhereSpec''' type verifies the behaviour expected of the +/** + * The '''UntypedWhereSpec''' type verifies the behaviour expected of the * `where` method in the [[reactivemongo.extensions.dsl.criteria.Untyped]] * `type`. * * @author svickers - * */ class UntypedWhereSpec extends AnyFlatSpec with Matchers { /// Class Imports @@ -83,27 +82,27 @@ class UntypedWhereSpec extends AnyFlatSpec with Matchers { it should "support 22 placeholders" in { val q = where { _.p === 0 && - _.p === 0 && - _.p === 0 && - _.p === 0 && - _.p === 0 && - _.p === 0 && - _.p === 0 && - _.p === 0 && - _.p === 0 && - _.p === 0 && - _.p === 0 && - _.p === 0 && - _.p === 0 && - _.p === 0 && - _.p === 0 && - _.p === 0 && - _.p === 0 && - _.p === 0 && - _.p === 0 && - _.p === 0 && - _.p === 0 && - _.p === 0 + _.p === 0 && + _.p === 0 && + _.p === 0 && + _.p === 0 && + _.p === 0 && + _.p === 0 && + _.p === 0 && + _.p === 0 && + _.p === 0 && + _.p === 0 && + _.p === 0 && + _.p === 0 && + _.p === 0 && + _.p === 0 && + _.p === 0 && + _.p === 0 && + _.p === 0 && + _.p === 0 && + _.p === 0 && + _.p === 0 && + _.p === 0 } BSONDocument.pretty(q) shouldBe ( diff --git a/bson/src/test/scala/fixtures/BsonFixturesSpec.scala b/bson/src/test/scala/fixtures/BsonFixturesSpec.scala index 32738e7..dbf9420 100644 --- a/bson/src/test/scala/fixtures/BsonFixturesSpec.scala +++ b/bson/src/test/scala/fixtures/BsonFixturesSpec.scala @@ -16,19 +16,20 @@ package reactivemongo.extensions.fixtures +import scala.concurrent.ExecutionContext.Implicits.global + import org.scalatest._ import org.scalatest.concurrent._ -import org.scalatest.time.Span +import org.scalatest.flatspec.AnyFlatSpec +import org.scalatest.matchers.should.Matchers import org.scalatest.time.Seconds -import reactivemongo.extensions.dao.MongoContext -import reactivemongo.extensions.dao.PersonBsonDao +import org.scalatest.time.Span import reactivemongo.extensions.dao.EventBsonDao import reactivemongo.extensions.dao.Handlers -import Handlers._ // extension BSON handler +import reactivemongo.extensions.dao.MongoContext +import reactivemongo.extensions.dao.PersonBsonDao import reactivemongo.extensions.Implicits.FutureOption // ~ -import scala.concurrent.ExecutionContext.Implicits.global -import org.scalatest.flatspec.AnyFlatSpec -import org.scalatest.matchers.should.Matchers +import Handlers._ // extension BSON handler class BsonFixturesSpec extends AnyFlatSpec with Matchers with ScalaFutures with BeforeAndAfter { diff --git a/bson/src/test/scala/model/TemporalModel.scala b/bson/src/test/scala/model/TemporalModel.scala index 4a594bd..502f531 100644 --- a/bson/src/test/scala/model/TemporalModel.scala +++ b/bson/src/test/scala/model/TemporalModel.scala @@ -16,11 +16,11 @@ package reactivemongo.extensions.model +import org.joda.time.DateTime import reactivemongo.api.bson._ -import reactivemongo.extensions.dao.LifeCycle import reactivemongo.extensions.dao.Handlers.BSONDateTimeHandler +import reactivemongo.extensions.dao.LifeCycle import reactivemongo.extensions.util.Logger -import org.joda.time.DateTime case class TemporalModel( _id: BSONObjectID = BSONObjectID.generate, diff --git a/core/src/main/scala/bson.scala b/core/src/main/scala/bson.scala index 8fe685b..a2f75ae 100644 --- a/core/src/main/scala/bson.scala +++ b/core/src/main/scala/bson.scala @@ -1,8 +1,8 @@ package reactivemongo.extensions -import reactivemongo.api.bson._ +import scala.reflect.runtime.universe.{ typeOf, TypeTag } -import scala.reflect.runtime.universe.{ TypeTag, typeOf } +import reactivemongo.api.bson._ object BsonTypes { diff --git a/core/src/main/scala/dao/Dao.scala b/core/src/main/scala/dao/Dao.scala index 376ba77..dadee0f 100644 --- a/core/src/main/scala/dao/Dao.scala +++ b/core/src/main/scala/dao/Dao.scala @@ -16,18 +16,19 @@ package reactivemongo.extensions.dao +import scala.concurrent.{ ExecutionContext, Future } +import scala.concurrent.duration.Duration +import scala.concurrent.ExecutionContext.Implicits.global + import akka.stream.Materializer -import reactivemongo.api.bson.BSONDocument import reactivemongo.api.{ Collation, Collection, CollectionProducer, DB, WriteConcern } import reactivemongo.api.bson.collection.BSONSerializationPack +import reactivemongo.api.bson.BSONDocument import reactivemongo.api.commands.WriteResult import reactivemongo.api.indexes.{ Index, IndexType } -import scala.concurrent.ExecutionContext.Implicits.global -import scala.concurrent.{ ExecutionContext, Future } -import scala.concurrent.duration.Duration - -/** Base class for all DAO implementations. This class defines the API for all DAOs. +/** + * Base class for all DAO implementations. This class defines the API for all DAOs. * * A DAO defines how to work with a specific collection. * @@ -44,14 +45,15 @@ abstract class Dao[C <: Collection: CollectionProducer, Structure, Model, ID, Wr collectionName: String ) { - /** The list of indexes to be ensured on DAO load. + /** + * The list of indexes to be ensured on DAO load. * - * Because of Scala initialization order there are exactly 2 ways + * Because of Scala initialization order there are exactly 2 ways * of defining auto indexes. * - * First way is to use an '''early definition''': + * First way is to use an '''early definition''': * - * {{{ + * {{{ * object PersonDao extends { * override val autoIndexes = Seq( * Index(Seq("name" -> IndexType.Ascending), unique = true, background = true), @@ -59,12 +61,12 @@ abstract class Dao[C <: Collection: CollectionProducer, Structure, Model, ID, Wr * } with BsonDao[Person, BSONObjectID](MongoContext.db, "persons") * }}} * - * Second way is to '''override def'''. Be careful __not to change declaration to `val` instead of `def`__. + * Second way is to '''override def'''. Be careful __not to change declaration to `val` instead of `def`__. * - * {{{ + * {{{ * object PersonDao extends BsonDao[Person, BSONObjectID](MongoContext.db, "persons") { * - * override def autoIndexes = Seq( + * override def autoIndexes = Seq( * Index(Seq("name" -> IndexType.Ascending), unique = true, background = true), * Index(Seq("age" -> IndexType.Ascending), background = true)) * } @@ -102,9 +104,10 @@ abstract class Dao[C <: Collection: CollectionProducer, Structure, Model, ID, Wr options = BSONDocument.empty ) - /** Bulk inserts multiple models. + /** + * Bulk inserts multiple models. * - * @param models A [[scala.collection.TraversableOnce]] of models. + * @param models A [[scala.collection.TraversableOnce]] of models. * @return The number of successful insertions. */ def bulkInsert(models: Iterable[Model])(implicit ec: ExecutionContext): Future[Int] @@ -112,22 +115,25 @@ abstract class Dao[C <: Collection: CollectionProducer, Structure, Model, ID, Wr /** Reference to the collection this DAO operates on. */ def collection: Future[C] = database.map(_.collection[C](collectionName)) - /** Returns the number of documents in this collection matching the given selector. + /** + * Returns the number of documents in this collection matching the given selector. * - * @param selector Selector document which may be empty. + * @param selector Selector document which may be empty. */ def count(selector: Structure)(implicit ec: ExecutionContext): Future[Int] - /** Defines the default write concern for this Dao which defaults to `GetLastError()`. + /** + * Defines the default write concern for this Dao which defaults to `GetLastError()`. * - * Related API functions should allow overriding this value. + * Related API functions should allow overriding this value. */ def defaultWriteConcern: WriteConcern = WriteConcern.Default /** Drops this collection */ def drop()(implicit ec: ExecutionContext): Future[Boolean] - /** Drops this collection and awaits until it has been dropped or a timeout has occured. + /** + * Drops this collection and awaits until it has been dropped or a timeout has occured. * @param timeout Maximum amount of time to await until this collection has been dropped. * @return true if the collection has been successfully dropped, otherwise false. */ @@ -136,9 +142,10 @@ abstract class Dao[C <: Collection: CollectionProducer, Structure, Model, ID, Wr /** Ensures indexes defined by `autoIndexes`. */ def ensureIndexes()(implicit ec: ExecutionContext): Future[Iterable[Boolean]] - /** Retrieves models by page matching the given selector. + /** + * Retrieves models by page matching the given selector. * - * @param selector Selector document. + * @param selector Selector document. * @param sort Sorting document. * @param page 1 based page number. * @param pageSize Maximum number of elements in each page. @@ -153,16 +160,18 @@ abstract class Dao[C <: Collection: CollectionProducer, Structure, Model, ID, Wr implicit ec: ExecutionContext ): Future[List[Model]] - /** Retrieves all models matching the given selector. + /** + * Retrieves all models matching the given selector. * - * @param selector Selector document. + * @param selector Selector document. * @param sort Sorting document. */ def findAll(selector: Structure, sort: Structure)(implicit ec: ExecutionContext): Future[List[Model]] - /** Updates and returns a single model. It returns the old document by default. + /** + * Updates and returns a single model. It returns the old document by default. * - * @param query The selection criteria for the update. + * @param query The selection criteria for the update. * @param update Performs an update of the selected model. * @param sort Determines which model the operation updates if the query selects multiple models. * findAndUpdate() updates the first model in the sort order specified by this argument. @@ -173,9 +182,10 @@ abstract class Dao[C <: Collection: CollectionProducer, Structure, Model, ID, Wr implicit ec: ExecutionContext ): Future[Option[Model]] - /** Removes and returns a single model. + /** + * Removes and returns a single model. * - * @param query The selection criteria for the remove. + * @param query The selection criteria for the remove. * @param sort Determines which model the operation removes if the query selects multiple models. * findAndRemove() removes the first model in the sort order specified by this argument. */ @@ -190,15 +200,17 @@ abstract class Dao[C <: Collection: CollectionProducer, Structure, Model, ID, Wr /** Retrieves at most one model matching the given selector. */ def findOne(selector: Structure)(implicit ec: ExecutionContext): Future[Option[Model]] - /** Retrieves a random model matching the given selector. + /** + * Retrieves a random model matching the given selector. * - * This API may require more than one query. + * This API may require more than one query. */ def findRandom(selector: Structure)(implicit ec: ExecutionContext): Future[Option[Model]] - /** Folds the documents matching the given selector by applying the function `f`. + /** + * Folds the documents matching the given selector by applying the function `f`. * - * @param selector Selector document. + * @param selector Selector document. * @param sort Sorting document. * @param state Initial state for the fold operation. * @param f Folding function. @@ -206,9 +218,10 @@ abstract class Dao[C <: Collection: CollectionProducer, Structure, Model, ID, Wr */ def fold[A](selector: Structure, sort: Structure, state: A)(f: (A, Model) => A)(implicit m: Materializer): Future[A] - /** Iterates over the documents matching the given selector and applies the function `f`. + /** + * Iterates over the documents matching the given selector and applies the function `f`. * - * @param selector Selector document. + * @param selector Selector document. * @param sort Sorting document. * @param f function to be applied. */ @@ -217,17 +230,19 @@ abstract class Dao[C <: Collection: CollectionProducer, Structure, Model, ID, Wr /** Inserts the given model. */ def insert(model: Model, writeConcern: WriteConcern)(implicit ec: ExecutionContext): Future[WriteResult] - /** Lists indexes that are currently ensured in this collection. + /** + * Lists indexes that are currently ensured in this collection. * - * This list may not be equal to `autoIndexes` in case of index creation failure. + * This list may not be equal to `autoIndexes` in case of index creation failure. */ def listIndexes()(implicit ec: ExecutionContext): Future[List[Index]] - /** Removes model(s) matching the given selector. + /** + * Removes model(s) matching the given selector. * - * In order to remove multiple documents `firstMatchOnly` has to be `false`. + * In order to remove multiple documents `firstMatchOnly` has to be `false`. * - * @param selector Selector document. + * @param selector Selector document. * @param limit Num of documents to be removed. */ def remove(selector: Structure, limit: Option[Int])(implicit ec: ExecutionContext): Future[WriteResult] @@ -238,17 +253,19 @@ abstract class Dao[C <: Collection: CollectionProducer, Structure, Model, ID, Wr /** Removes the document with the given ID. */ def removeById(id: ID)(implicit ec: ExecutionContext): Future[WriteResult] - /** Inserts the document, or updates it if it already exists in the collection. + /** + * Inserts the document, or updates it if it already exists in the collection. * - * @param model The model to save. + * @param model The model to save. * @param writeConcern the command message to send in order to control * how the document is inserted. Defaults to defaultWriteConcern. */ def save(id: ID, model: Model, writeConcern: WriteConcern)(implicit ec: ExecutionContext): Future[WriteResult] - /** Updates the documents matching the given selector. + /** + * Updates the documents matching the given selector. * - * @param selector Selector query. + * @param selector Selector query. * @param update Update query. * @param writeConcern Write concern which defaults to defaultWriteConcern. * @param upsert Create the document if it does not exist. @@ -259,9 +276,10 @@ abstract class Dao[C <: Collection: CollectionProducer, Structure, Model, ID, Wr implicit ec: ExecutionContext ): Future[WriteResult] - /** Updates the document with the given `id`. + /** + * Updates the document with the given `id`. * - * @param id ID of the document that will be updated. + * @param id ID of the document that will be updated. * @param update Update query. * @param writeConcern Write concern which defaults to defaultWriteConcern. * @tparam U Type of the update query. diff --git a/core/src/main/scala/dao/Handlers.scala b/core/src/main/scala/dao/Handlers.scala index 8078ade..d507d0d 100644 --- a/core/src/main/scala/dao/Handlers.scala +++ b/core/src/main/scala/dao/Handlers.scala @@ -16,11 +16,11 @@ package reactivemongo.extensions.dao +import scala.util.Success + import org.joda.time.DateTime import reactivemongo.api.bson._ -import scala.util.Success - object Handlers { implicit object BSONDateTimeHandler extends BSONReader[DateTime] with BSONWriter[DateTime] { diff --git a/core/src/main/scala/dao/LifeCycle.scala b/core/src/main/scala/dao/LifeCycle.scala index 5dc69a2..15625aa 100644 --- a/core/src/main/scala/dao/LifeCycle.scala +++ b/core/src/main/scala/dao/LifeCycle.scala @@ -16,7 +16,8 @@ package reactivemongo.extensions.dao -/** Type class to work with the life cycle of a model. +/** + * Type class to work with the life cycle of a model. * * By defining a life cycle object, one can preprocess all models before being persisted or perform specific actions * after life cycle events. @@ -74,14 +75,15 @@ trait LifeCycle[Model, ID] { def ensuredIndexes(): Unit } -/** This is the default life cycle for all models. +/** + * This is the default life cycle for all models. * * Basically it does not perform any actions after life cyle events nor does any transformations to model instances. */ class ReflexiveLifeCycle[Model, ID] extends LifeCycle[Model, ID] { def prePersist(model: Model): Model = model def postPersist(model: Model): Unit = {} - def preRemove(id: ID): Unit = {} - def postRemove(id: ID): Unit = {} - def ensuredIndexes(): Unit = {} + def preRemove(id: ID): Unit = {} + def postRemove(id: ID): Unit = {} + def ensuredIndexes(): Unit = {} } diff --git a/core/src/main/scala/fixtures/Fixtures.scala b/core/src/main/scala/fixtures/Fixtures.scala index 6fc07f9..eb30403 100644 --- a/core/src/main/scala/fixtures/Fixtures.scala +++ b/core/src/main/scala/fixtures/Fixtures.scala @@ -16,15 +16,15 @@ package reactivemongo.extensions.fixtures +import scala.concurrent.ExecutionContext.Implicits.global +import scala.concurrent.Future +import scala.jdk.CollectionConverters._ + import com.typesafe.config.{ Config, ConfigFactory, ConfigRenderOptions, ConfigResolveOptions } import play.api.libs.json.{ JsObject, Json } import reactivemongo.api.commands.WriteResult import reactivemongo.extensions.util.Logger -import scala.concurrent.ExecutionContext.Implicits.global -import scala.concurrent.Future -import scala.jdk.CollectionConverters._ - trait Fixtures[T] { protected lazy val renderOptions = ConfigRenderOptions.concise.setJson(true).setFormatted(true) @@ -43,17 +43,21 @@ trait Fixtures[T] { Json.parse(toString(config)).as[JsObject] protected def resolveConfig(config: Config): Config = { - val resolvedConfig = config.root.keySet.asScala.diff(reserved).foldLeft(config) { (config, collectionName) => - val collectionConfig = config.getConfig(collectionName) - - val resolvedCollectionConfig = collectionConfig.root.keySet.asScala.foldLeft(collectionConfig) { - (_collectionConfig, documentName) => - val documentConfig = _collectionConfig.getConfig(documentName).resolve(resolveOptions) - _collectionConfig.withValue(documentName, documentConfig.root) - }.resolve(resolveOptions) - - config.withValue(collectionName, resolvedCollectionConfig.root) - }.resolve + val resolvedConfig = config.root.keySet.asScala + .diff(reserved) + .foldLeft(config) { (config, collectionName) => + val collectionConfig = config.getConfig(collectionName) + + val resolvedCollectionConfig = collectionConfig.root.keySet.asScala + .foldLeft(collectionConfig) { (_collectionConfig, documentName) => + val documentConfig = _collectionConfig.getConfig(documentName).resolve(resolveOptions) + _collectionConfig.withValue(documentName, documentConfig.root) + } + .resolve(resolveOptions) + + config.withValue(collectionName, resolvedCollectionConfig.root) + } + .resolve Logger.debug("Resolved Config =>\n" + toString(resolvedConfig)) resolvedConfig diff --git a/core/src/main/scala/util/Logger.scala b/core/src/main/scala/util/Logger.scala index e38453d..b89dd65 100644 --- a/core/src/main/scala/util/Logger.scala +++ b/core/src/main/scala/util/Logger.scala @@ -16,115 +16,132 @@ package reactivemongo.extensions.util -import org.slf4j.{ LoggerFactory, Logger => Slf4jLogger } +import org.slf4j.{ Logger => Slf4jLogger, LoggerFactory } -/** Typical logger interface. +/** + * Typical logger interface. */ trait LoggerLike { - /** The underlying SLF4J Logger. + /** + * The underlying SLF4J Logger. */ def logger: Slf4jLogger - /** `true` if the logger instance is enabled for the `TRACE` level. + /** + * `true` if the logger instance is enabled for the `TRACE` level. */ def isTraceEnabled = logger.isTraceEnabled - /** `true` if the logger instance is enabled for the `DEBUG` level. + /** + * `true` if the logger instance is enabled for the `DEBUG` level. */ def isDebugEnabled = logger.isDebugEnabled - /** `true` if the logger instance is enabled for the `INFO` level. + /** + * `true` if the logger instance is enabled for the `INFO` level. */ def isInfoEnabled = logger.isInfoEnabled - /** `true` if the logger instance is enabled for the `WARN` level. + /** + * `true` if the logger instance is enabled for the `WARN` level. */ def isWarnEnabled = logger.isWarnEnabled - /** `true` if the logger instance is enabled for the `ERROR` level. + /** + * `true` if the logger instance is enabled for the `ERROR` level. */ def isErrorEnabled = logger.isErrorEnabled - /** Logs a message with the `TRACE` level. + /** + * Logs a message with the `TRACE` level. * - * @param message the message to log + * @param message the message to log */ def trace(message: => String) = { if (logger.isTraceEnabled) logger.trace(message) } - /** Logs a message with the `TRACE` level. + /** + * Logs a message with the `TRACE` level. * - * @param message the message to log + * @param message the message to log * @param error the associated exception */ def trace(message: => String, error: => Throwable) = { if (logger.isTraceEnabled) logger.trace(message, error) } - /** Logs a message with the `DEBUG` level. + /** + * Logs a message with the `DEBUG` level. * - * @param message the message to log + * @param message the message to log */ def debug(message: => String) = { if (logger.isDebugEnabled) logger.debug(message) } - /** Logs a message with the `DEBUG` level. + /** + * Logs a message with the `DEBUG` level. * - * @param message the message to log + * @param message the message to log * @param error the associated exception */ def debug(message: => String, error: => Throwable) = { if (logger.isDebugEnabled) logger.debug(message, error) } - /** Logs a message with the `INFO` level. + /** + * Logs a message with the `INFO` level. * - * @param message the message to log + * @param message the message to log */ def info(message: => String) = { if (logger.isInfoEnabled) logger.info(message) } - /** Logs a message with the `INFO` level. + /** + * Logs a message with the `INFO` level. * - * @param message the message to log + * @param message the message to log * @param error the associated exception */ def info(message: => String, error: => Throwable) = { if (logger.isInfoEnabled) logger.info(message, error) } - /** Logs a message with the `WARN` level. + /** + * Logs a message with the `WARN` level. * - * @param message the message to log + * @param message the message to log */ def warn(message: => String) = { if (logger.isWarnEnabled) logger.warn(message) } - /** Logs a message with the `WARN` level. + /** + * Logs a message with the `WARN` level. * - * @param message the message to log + * @param message the message to log * @param error the associated exception */ def warn(message: => String, error: => Throwable) = { if (logger.isWarnEnabled) logger.warn(message, error) } - /** Logs a message with the `ERROR` level. + /** + * Logs a message with the `ERROR` level. * - * @param message the message to log + * @param message the message to log */ def error(message: => String) = { if (logger.isErrorEnabled) logger.error(message) } - /** Logs a message with the `ERROR` level. + /** + * Logs a message with the `ERROR` level. * - * @param message the message to log + * @param message the message to log * @param error the associated exception */ def error(message: => String, error: => Throwable) = { @@ -133,13 +150,15 @@ trait LoggerLike { } -/** A Play logger. +/** + * A Play logger. * * @param logger the underlying SL4FJ logger */ class Logger(val logger: Slf4jLogger) extends LoggerLike -/** High-level API for logging operations. +/** + * High-level API for logging operations. * * For example, logging with the default application logger: * {{{ @@ -150,24 +169,26 @@ class Logger(val logger: Slf4jLogger) extends LoggerLike * {{{ * Logger("my.logger").info("Hello!") * }}} - * */ object Logger extends LoggerLike { - /** The 'application' logger. + /** + * The 'application' logger. */ lazy val logger = LoggerFactory.getLogger("reactivemongo.extensions") - /** Obtains a logger instance. + /** + * Obtains a logger instance. * - * @param name the name of the logger + * @param name the name of the logger * @return a logger */ def apply(name: String): Logger = new Logger(LoggerFactory.getLogger(name)) - /** Obtains a logger instance. + /** + * Obtains a logger instance. * - * @param clazz a class whose name will be used as logger name + * @param clazz a class whose name will be used as logger name * @return a logger */ def apply[T](clazz: Class[T]): Logger = new Logger(LoggerFactory.getLogger(clazz)) diff --git a/core/src/test/scala/dao/MongoContext.scala b/core/src/test/scala/dao/MongoContext.scala index c349c2d..573a896 100644 --- a/core/src/test/scala/dao/MongoContext.scala +++ b/core/src/test/scala/dao/MongoContext.scala @@ -16,19 +16,19 @@ package reactivemongo.extensions.dao -import reactivemongo.api.DB -import reactivemongo.api.AsyncDriver -import reactivemongo.extensions.util.Misc.UUID - -import scala.concurrent.ExecutionContext.Implicits.global +import scala.concurrent.duration._ import scala.concurrent.Await +import scala.concurrent.ExecutionContext.Implicits.global import scala.concurrent.Future -import scala.concurrent.duration._ + +import reactivemongo.api.AsyncDriver +import reactivemongo.api.DB +import reactivemongo.extensions.util.Misc.UUID object MongoContext { - val driver = new AsyncDriver - val connection = driver.connect(List("localhost")) + val driver = new AsyncDriver + val connection = driver.connect(List("localhost")) def db: Future[DB] = connection.flatMap(_.database("test-reactivemongo-extensions")) def randomDb: Future[DB] = connection.flatMap(_.database(UUID())) - def syncDb = Await.result(connection.flatMap(_.database("test-reactivemongo-extensions")), 10.seconds) + def syncDb = Await.result(connection.flatMap(_.database("test-reactivemongo-extensions")), 10.seconds) } diff --git a/core/src/test/scala/util/ColoredLevel.scala b/core/src/test/scala/util/ColoredLevel.scala index 6e1a8ff..ccb1d88 100644 --- a/core/src/test/scala/util/ColoredLevel.scala +++ b/core/src/test/scala/util/ColoredLevel.scala @@ -16,11 +16,12 @@ package reactivemongo.extensions.util -import ch.qos.logback.classic.Level -import ch.qos.logback.classic.spi.ILoggingEvent import ch.qos.logback.classic.pattern.ClassicConverter +import ch.qos.logback.classic.spi.ILoggingEvent +import ch.qos.logback.classic.Level -/** A logback converter generating colored, lower-case level names. +/** + * A logback converter generating colored, lower-case level names. * * Used for example as: * {{{ diff --git a/core/src/test/scala/util/Colors.scala b/core/src/test/scala/util/Colors.scala index be3209f..9f44733 100644 --- a/core/src/test/scala/util/Colors.scala +++ b/core/src/test/scala/util/Colors.scala @@ -8,21 +8,24 @@ object Colors { import scala.Console._ lazy val isANSISupported = { - Option(System.getProperty("sbt.log.noformat")).map(_ != "true").orElse { - Option(System.getProperty("os.name")) - .map(_.toLowerCase) - .filter(_.contains("windows")) - .map(_ => false) - }.getOrElse(true) + Option(System.getProperty("sbt.log.noformat")) + .map(_ != "true") + .orElse { + Option(System.getProperty("os.name")) + .map(_.toLowerCase) + .filter(_.contains("windows")) + .map(_ => false) + } + .getOrElse(true) } - def red(str: String): String = if (isANSISupported) (RED + str + RESET) else str - def blue(str: String): String = if (isANSISupported) (BLUE + str + RESET) else str - def cyan(str: String): String = if (isANSISupported) (CYAN + str + RESET) else str - def green(str: String): String = if (isANSISupported) (GREEN + str + RESET) else str - def magenta(str: String): String = if (isANSISupported) (MAGENTA + str + RESET) else str - def white(str: String): String = if (isANSISupported) (WHITE + str + RESET) else str - def black(str: String): String = if (isANSISupported) (BLACK + str + RESET) else str - def yellow(str: String): String = if (isANSISupported) (YELLOW + str + RESET) else str + def red(str: String): String = if (isANSISupported) RED + str + RESET else str + def blue(str: String): String = if (isANSISupported) BLUE + str + RESET else str + def cyan(str: String): String = if (isANSISupported) CYAN + str + RESET else str + def green(str: String): String = if (isANSISupported) GREEN + str + RESET else str + def magenta(str: String): String = if (isANSISupported) MAGENTA + str + RESET else str + def white(str: String): String = if (isANSISupported) WHITE + str + RESET else str + def black(str: String): String = if (isANSISupported) BLACK + str + RESET else str + def yellow(str: String): String = if (isANSISupported) YELLOW + str + RESET else str } diff --git a/json/src/main/scala/dao/JsonDao.scala b/json/src/main/scala/dao/JsonDao.scala index fe238a0..469329e 100644 --- a/json/src/main/scala/dao/JsonDao.scala +++ b/json/src/main/scala/dao/JsonDao.scala @@ -16,24 +16,25 @@ package reactivemongo.extensions.json.dao +import scala.concurrent.{ Await, ExecutionContext, Future } +import scala.concurrent.duration._ +import scala.util.Random // Required import + import akka.stream.Materializer import play.api.libs.json._ import reactivemongo.akkastream.cursorProducer -import reactivemongo.api.Cursor.FailOnError -import reactivemongo.api.bson._ import reactivemongo.api.{ Collation, Cursor, DB, ReadConcern, WriteConcern } +import reactivemongo.api.bson._ import reactivemongo.api.bson.collection.BSONCollection import reactivemongo.api.commands.WriteResult import reactivemongo.api.indexes.Index +import reactivemongo.api.Cursor.FailOnError import reactivemongo.extensions.dao.{ Dao, LifeCycle, ReflexiveLifeCycle } import reactivemongo.extensions.json.dsl.JsonDsl._ import reactivemongo.play.json.compat._ -import scala.concurrent.{ Await, ExecutionContext, Future } -import scala.concurrent.duration._ -import scala.util.Random // Required import - -/** A DAO implementation that operates on JSONCollection using JsObject. +/** + * A DAO implementation that operates on JSONCollection using JsObject. * * To create a DAO for a concrete model extend this class. * @@ -64,7 +65,6 @@ import scala.util.Random // Required import * import reactivemongo.extensions.json.dao.JsonDao * import scala.concurrent.ExecutionContext.Implicits.global * - * * object MongoContext { * val driver = new MongoDriver * val connection = driver.connection(List("localhost")) @@ -115,8 +115,7 @@ abstract class JsonDao[Model, ID: Writes](database: => Future[DB], collectionNam ): Future[List[Model]] = { val from = page * pageSize collection.flatMap( - _ - .find(selector) + _.find(selector) .sort(sort) .skip(from) .cursor[Model]() @@ -139,8 +138,7 @@ abstract class JsonDao[Model, ID: Writes](database: => Future[DB], collectionNam ): Future[List[Model]] = { val from = page * pageSize collection.flatMap( - _ - .find(selector) + _.find(selector) .collation(collation) .sort(sort) .skip(from) diff --git a/json/src/main/scala/dao/JsonDaoBuilder.scala b/json/src/main/scala/dao/JsonDaoBuilder.scala index 539ecaa..c7a2e3f 100644 --- a/json/src/main/scala/dao/JsonDaoBuilder.scala +++ b/json/src/main/scala/dao/JsonDaoBuilder.scala @@ -16,16 +16,16 @@ package reactivemongo.extensions.json.dao +import scala.concurrent.ExecutionContext +import scala.concurrent.Future + import play.api.libs.json.OFormat import play.api.libs.json.Writes -import reactivemongo.api.DB import reactivemongo.api.bson.{ BSONDocumentReader, BSONDocumentWriter } +import reactivemongo.api.DB import reactivemongo.extensions.dao.LifeCycle import reactivemongo.extensions.dao.ReflexiveLifeCycle -import scala.concurrent.ExecutionContext -import scala.concurrent.Future - class JsonDaoBuilder[Model, ID: Writes](db: => Future[DB]) { def apply(collectionName: String)( implicit fmt: OFormat[Model], diff --git a/json/src/main/scala/dsl/JsonDsl.scala b/json/src/main/scala/dsl/JsonDsl.scala index 4f958a9..2ef6fbd 100644 --- a/json/src/main/scala/dsl/JsonDsl.scala +++ b/json/src/main/scala/dsl/JsonDsl.scala @@ -16,12 +16,13 @@ package reactivemongo.extensions.json.dsl +import scala.reflect.runtime.universe.TypeTag + import play.api.libs.json._ -import play.api.libs.json.Json.JsValueWrapper import play.api.libs.json.Json.toJsFieldJsValueWrapper +import play.api.libs.json.Json.JsValueWrapper import reactivemongo.api.bson._ import reactivemongo.extensions.BsonTypes -import scala.reflect.runtime.universe.TypeTag trait JsonDsl { @@ -31,7 +32,7 @@ trait JsonDsl { type Element = (Field, Value) - //**********************************************************************************************// + // **********************************************************************************************// // Helpers def $empty: JsObject = Json.obj() @@ -47,9 +48,9 @@ trait JsonDsl { Json.obj("_id" -> id) } // End of Helpers - //**********************************************************************************************// + // **********************************************************************************************// - //**********************************************************************************************// + // **********************************************************************************************// // Top Level Logical Operators def $or(expressions: JsObject*): JsObject = { Json.obj("$or" -> expressions) @@ -63,9 +64,9 @@ trait JsonDsl { Json.obj("$nor" -> expressions) } // End of Top Level Logical Operators - //**********************************************************************************************// + // **********************************************************************************************// - //**********************************************************************************************// + // **********************************************************************************************// // Top Level Evaluation Operators def $text(search: String): JsObject = { Json.obj("$text" -> Json.obj("$search" -> search)) @@ -79,9 +80,9 @@ trait JsonDsl { Json.obj("$where" -> expression) } // End of Top Level Evaluation Operators - //**********************************************************************************************// + // **********************************************************************************************// - //**********************************************************************************************// + // **********************************************************************************************// // Top Level Field Update Operators def $inc(element: Element, elements: Element*): JsObject = { Json.obj("$inc" -> Json.obj((Seq(element) ++ elements): _*)) @@ -141,9 +142,9 @@ trait JsonDsl { Json.obj("$currentDate" -> Json.obj(items.map(item => item._1 -> item._2.produce): _*)) } // End of Top Level Field Update Operators - //**********************************************************************************************// + // **********************************************************************************************// - //**********************************************************************************************// + // **********************************************************************************************// // Top Level Array Update Operators def $addToSet(element: Element, elements: Element*): JsObject = { Json.obj("$addToSet" -> Json.obj((Seq(element) ++ elements): _*)) @@ -168,9 +169,10 @@ trait JsonDsl { Json.obj("$pull" -> Json.obj(element)) } // End ofTop Level Array Update Operators - //**********************************************************************************************// + // **********************************************************************************************// - /** Represents the inital state of the expression which has only the name of the field. + /** + * Represents the inital state of the expression which has only the name of the field. * It does not know the value of the expression. */ trait ElementBuilder { @@ -186,24 +188,24 @@ trait JsonDsl { /* * This type of expressions cannot be cascaded. Examples: * - * {{{ + * {{{ * "price" $eq 10 * "price" $ne 1000 * "size" $in ("S", "M", "L") * "size" $nin ("S", "XXL") * }}} * - */ + */ case class SimpleExpression[V <: JsValue](field: String, value: V) extends Expression[V] - /** Expressions of this type can be cascaded. Examples: + /** + * Expressions of this type can be cascaded. Examples: * - * {{{ + * {{{ * "age" $gt 50 $lt 60 * "age" $gte 50 $lte 60 * }}} - * - */ + */ case class CompositeExpression(field: String, value: JsObject) extends Expression[JsObject] with ComparisonOperators { override def append(value: JsObject): JsObject = { this.value ++ value @@ -227,7 +229,7 @@ trait JsonDsl { CompositeExpression(field, append(Json.obj("$gte" -> value))) } - /** Matches any of the values that exist in an array specified in the query.*/ + /** Matches any of the values that exist in an array specified in the query. */ def $in[T](values: T*)(implicit writer: Writes[T]): SimpleExpression[JsObject] = { SimpleExpression(field, Json.obj("$in" -> values)) } diff --git a/json/src/main/scala/fixtures/JsonFixtures.scala b/json/src/main/scala/fixtures/JsonFixtures.scala index 805e1ee..6dab388 100644 --- a/json/src/main/scala/fixtures/JsonFixtures.scala +++ b/json/src/main/scala/fixtures/JsonFixtures.scala @@ -16,16 +16,16 @@ package reactivemongo.extensions.json.fixtures +import scala.concurrent.{ ExecutionContext, Future } + import play.api.libs.json.{ JsObject, Json } -import reactivemongo.api.DB import reactivemongo.api.bson.collection.BSONCollection import reactivemongo.api.commands.WriteResult +import reactivemongo.api.DB import reactivemongo.extensions.fixtures.Fixtures import reactivemongo.play.json.compat._ import reactivemongo.play.json.compat.json2bson._ -import scala.concurrent.{ ExecutionContext, Future } - class JsonFixtures(db: => Future[DB])(implicit ec: ExecutionContext) extends Fixtures[JsObject] { def map(document: JsObject): JsObject = document diff --git a/json/src/main/scala/joda/JodaReads.scala b/json/src/main/scala/joda/JodaReads.scala index 0602f69..988e495 100644 --- a/json/src/main/scala/joda/JodaReads.scala +++ b/json/src/main/scala/joda/JodaReads.scala @@ -8,9 +8,10 @@ object JodaReads extends JodaReads trait JodaReads { - /** Reads for the `org.joda.time.DateTime` type. + /** + * Reads for the `org.joda.time.DateTime` type. * - * @param pattern a date pattern, as specified in `org.joda.time.format.DateTimeFormat`, or "" to use ISO format. + * @param pattern a date pattern, as specified in `org.joda.time.format.DateTimeFormat`, or "" to use ISO format. * @param corrector a simple string transformation function that can be used to transform input String before parsing. * Useful when standards are not respected and require a few tweaks. Defaults to identity function. */ @@ -34,17 +35,20 @@ trait JodaReads { } - /** The default implicit JodaDate reads, using yyyy-MM-dd format + /** + * The default implicit JodaDate reads, using yyyy-MM-dd format */ val JodaDateReads = jodaDateReads("yyyy-MM-dd") - /** The default implicit JodaDate reads, using ISO-8601 format + /** + * The default implicit JodaDate reads, using ISO-8601 format */ implicit val DefaultJodaDateTimeReads = jodaDateReads("") - /** Reads for the `org.joda.time.LocalDate` type. + /** + * Reads for the `org.joda.time.LocalDate` type. * - * @param pattern a date pattern, as specified in `org.joda.time.format.DateTimeFormat`, or "" to use ISO format. + * @param pattern a date pattern, as specified in `org.joda.time.format.DateTimeFormat`, or "" to use ISO format. * @param corrector string transformation function (See jodaDateReads). Defaults to identity function. */ def jodaLocalDateReads(pattern: String, corrector: String => String = identity): Reads[org.joda.time.LocalDate] = @@ -65,13 +69,15 @@ trait JodaReads { scala.util.control.Exception.nonFatalCatch[LocalDate].opt(LocalDate.parse(input, df)) } - /** The default implicit joda.time.LocalDate reads, using ISO-8601 format. + /** + * The default implicit joda.time.LocalDate reads, using ISO-8601 format. */ implicit val DefaultJodaLocalDateReads = jodaLocalDateReads("") - /** Reads for the `org.joda.time.LocalTime` type. + /** + * Reads for the `org.joda.time.LocalTime` type. * - * @param pattern a date pattern, as specified in `org.joda.time.format.DateTimeFormat`, or "" to use ISO format. + * @param pattern a date pattern, as specified in `org.joda.time.format.DateTimeFormat`, or "" to use ISO format. * @param corrector string transformation function (See jodaTimeReads). Defaults to identity function. */ def jodaLocalTimeReads(pattern: String, corrector: String => String = identity): Reads[LocalTime] = @@ -93,7 +99,8 @@ trait JodaReads { scala.util.control.Exception.nonFatalCatch[LocalTime].opt(LocalTime.parse(input, df)) } - /** the default implicit joda.time.LocalTime reads + /** + * the default implicit joda.time.LocalTime reads */ implicit val DefaultJodaLocalTimeReads = jodaLocalTimeReads("") } diff --git a/json/src/main/scala/joda/JodaWrites.scala b/json/src/main/scala/joda/JodaWrites.scala index e072d5d..6bd69f6 100644 --- a/json/src/main/scala/joda/JodaWrites.scala +++ b/json/src/main/scala/joda/JodaWrites.scala @@ -10,7 +10,8 @@ object JodaWrites extends JodaWrites trait JodaWrites { - /** Serializer for DateTime + /** + * Serializer for DateTime * @param pattern the pattern used by org.joda.time.format.DateTimeFormat */ def jodaDateWrites(pattern: String): Writes[DateTime] = new Writes[DateTime] { @@ -18,19 +19,22 @@ trait JodaWrites { def writes(d: DateTime): JsValue = JsString(d.toString(df)) } - /** Serializer DateTime -> JsNumber(d.getMillis (number of milliseconds since the Epoch)) + /** + * Serializer DateTime -> JsNumber(d.getMillis (number of milliseconds since the Epoch)) */ implicit object JodaDateTimeNumberWrites extends Writes[DateTime] { def writes(d: DateTime): JsValue = JsNumber(d.getMillis) } - /** Default Serializer LocalDate -> JsString(ISO8601 format (yyyy-MM-dd)) + /** + * Default Serializer LocalDate -> JsString(ISO8601 format (yyyy-MM-dd)) */ object JodaDateTimeWrites extends Writes[DateTime] { def writes(d: DateTime): JsValue = JsString(d.toString) } - /** Serializer for LocalDate + /** + * Serializer for LocalDate * @param pattern the pattern used by org.joda.time.format.DateTimeFormat */ def jodaLocalDateWrites(pattern: String): Writes[LocalDate] = { @@ -38,19 +42,22 @@ trait JodaWrites { Writes[LocalDate] { d => JsString(d.toString(df)) } } - /** Default Serializer LocalDate -> JsString(ISO8601 format (yyyy-MM-dd)) + /** + * Default Serializer LocalDate -> JsString(ISO8601 format (yyyy-MM-dd)) */ implicit object DefaultJodaLocalDateWrites extends Writes[LocalDate] { def writes(d: LocalDate): JsValue = JsString(d.toString) } - /** Serializer for LocalTime + /** + * Serializer for LocalTime * @param pattern the pattern used by org.joda.time.format.DateTimeFormat */ def jodaLocalTimeWrites(pattern: String): Writes[LocalTime] = Writes[LocalTime] { d => JsString(d.toString(pattern)) } - /** Default Serializer LocalDate -> JsString(ISO8601 format (HH:mm:ss.SSS)) + /** + * Default Serializer LocalDate -> JsString(ISO8601 format (HH:mm:ss.SSS)) */ implicit object DefaultJodaLocalTimeWrites extends Writes[LocalTime] { def writes(d: LocalTime): JsValue = JsString(d.toString) diff --git a/json/src/test/scala/dao/CustomIdJsonDao.scala b/json/src/test/scala/dao/CustomIdJsonDao.scala index f02bfb5..8d47e48 100644 --- a/json/src/test/scala/dao/CustomIdJsonDao.scala +++ b/json/src/test/scala/dao/CustomIdJsonDao.scala @@ -17,10 +17,11 @@ package reactivemongo.extensions.json.dao import scala.concurrent.ExecutionContext.Implicits.global + +import reactivemongo.api.indexes.IndexType +import reactivemongo.extensions.dao.MongoContext import reactivemongo.extensions.json.model.CustomIdModel import reactivemongo.extensions.json.model.CustomIdModel.customIdModelFormat -import reactivemongo.extensions.dao.MongoContext -import reactivemongo.api.indexes.IndexType import reactivemongo.extensions.util.Misc.UUID class CustomIdJsonDao extends JsonDao[CustomIdModel, String](MongoContext.db, "dummy-" + UUID()) { diff --git a/json/src/test/scala/dao/CustomIdJsonDaoSpec.scala b/json/src/test/scala/dao/CustomIdJsonDaoSpec.scala index 0c5f03d..effb653 100644 --- a/json/src/test/scala/dao/CustomIdJsonDaoSpec.scala +++ b/json/src/test/scala/dao/CustomIdJsonDaoSpec.scala @@ -16,15 +16,16 @@ package reactivemongo.extensions.json.dao +import scala.concurrent.ExecutionContext.Implicits.global + import org.scalatest._ import org.scalatest.concurrent._ -import org.scalatest.time.SpanSugar._ -import reactivemongo.play.json._ -import reactivemongo.extensions.json.model.CustomIdModel -import reactivemongo.extensions.json.dsl.JsonDsl._ -import scala.concurrent.ExecutionContext.Implicits.global import org.scalatest.flatspec.AnyFlatSpec import org.scalatest.matchers.should.Matchers +import org.scalatest.time.SpanSugar._ +import reactivemongo.extensions.json.dsl.JsonDsl._ +import reactivemongo.extensions.json.model.CustomIdModel +import reactivemongo.play.json._ class CustomIdJsonDaoSpec extends AnyFlatSpec diff --git a/json/src/test/scala/dao/DummyJsonDao.scala b/json/src/test/scala/dao/DummyJsonDao.scala index 9c4faae..855718a 100644 --- a/json/src/test/scala/dao/DummyJsonDao.scala +++ b/json/src/test/scala/dao/DummyJsonDao.scala @@ -17,10 +17,11 @@ package reactivemongo.extensions.json.dao import scala.concurrent.ExecutionContext.Implicits.global -import reactivemongo.extensions.json.model.DummyModel -import reactivemongo.extensions.dao.MongoContext -import reactivemongo.api.indexes.IndexType + import reactivemongo.api.bson.BSONObjectID +import reactivemongo.api.indexes.IndexType +import reactivemongo.extensions.dao.MongoContext +import reactivemongo.extensions.json.model.DummyModel import reactivemongo.extensions.util.Misc.UUID import reactivemongo.play.json.compat.bson2json._ diff --git a/json/src/test/scala/dao/DummyJsonDaoSpec.scala b/json/src/test/scala/dao/DummyJsonDaoSpec.scala index 029975f..51c9008 100644 --- a/json/src/test/scala/dao/DummyJsonDaoSpec.scala +++ b/json/src/test/scala/dao/DummyJsonDaoSpec.scala @@ -16,17 +16,18 @@ package reactivemongo.extensions.json.dao +import scala.concurrent.ExecutionContext.Implicits.global + import org.scalatest._ import org.scalatest.concurrent._ +import org.scalatest.flatspec.AnyFlatSpec +import org.scalatest.matchers.should.Matchers import org.scalatest.time.SpanSugar._ -import reactivemongo.play.json.compat._ -import reactivemongo.extensions.json.model.DummyModel import reactivemongo.extensions.json.dsl.JsonDsl._ +import reactivemongo.extensions.json.model.DummyModel import reactivemongo.extensions.util.Logger import reactivemongo.extensions.Implicits._ -import scala.concurrent.ExecutionContext.Implicits.global -import org.scalatest.flatspec.AnyFlatSpec -import org.scalatest.matchers.should.Matchers +import reactivemongo.play.json.compat._ class DummyJsonDaoSpec extends AnyFlatSpec with Matchers with ScalaFutures with BeforeAndAfter with OneInstancePerTest { diff --git a/json/src/test/scala/dao/DynamicJsonDaoSpec.scala b/json/src/test/scala/dao/DynamicJsonDaoSpec.scala index 77f164f..b673266 100644 --- a/json/src/test/scala/dao/DynamicJsonDaoSpec.scala +++ b/json/src/test/scala/dao/DynamicJsonDaoSpec.scala @@ -16,30 +16,30 @@ package reactivemongo.extensions.json.dao +import scala.concurrent.Await +import scala.concurrent.ExecutionContext.Implicits.global +import scala.concurrent.Future + import org.scalatest._ import org.scalatest.concurrent.ScalaFutures -import org.scalatest.time.Span +import org.scalatest.flatspec.AnyFlatSpec +import org.scalatest.matchers.should.Matchers import org.scalatest.time.Seconds -import play.api.libs.json.OFormat +import org.scalatest.time.Span import play.api.libs.json.JsError -import play.api.libs.json.Json import play.api.libs.json.JsObject import play.api.libs.json.JsResult import play.api.libs.json.JsSuccess import play.api.libs.json.JsValue +import play.api.libs.json.Json +import play.api.libs.json.OFormat import reactivemongo.api.bson.BSONObjectID import reactivemongo.extensions.dao.MongoContext import reactivemongo.extensions.json.dsl.JsonDsl._ import reactivemongo.extensions.util.Logger import reactivemongo.extensions.Implicits._ - -import scala.concurrent.Future -import scala.concurrent.Await -import scala.concurrent.ExecutionContext.Implicits.global -import org.scalatest.flatspec.AnyFlatSpec -import org.scalatest.matchers.should.Matchers import reactivemongo.play.json.compat.bson2json.fromWriter -import reactivemongo.play.json.compat.json2bson.{toDocumentReader, toDocumentWriter} +import reactivemongo.play.json.compat.json2bson.{ toDocumentReader, toDocumentWriter } class DynamicJsonDaoSpec extends AnyFlatSpec diff --git a/json/src/test/scala/dao/EventJsonDao.scala b/json/src/test/scala/dao/EventJsonDao.scala index fb422ed..97a83d4 100644 --- a/json/src/test/scala/dao/EventJsonDao.scala +++ b/json/src/test/scala/dao/EventJsonDao.scala @@ -16,11 +16,12 @@ package reactivemongo.extensions.json.dao -import scala.concurrent.Future import scala.concurrent.ExecutionContext.Implicits.global -import reactivemongo.extensions.json.model.Event -import reactivemongo.extensions.json.dsl.JsonDsl +import scala.concurrent.Future + import reactivemongo.api.DB +import reactivemongo.extensions.json.dsl.JsonDsl +import reactivemongo.extensions.json.model.Event class EventJsonDao(_db: Future[DB]) extends JsonDao[Event, String](_db, "events") with JsonDsl { diff --git a/json/src/test/scala/dao/PersonJsonDao.scala b/json/src/test/scala/dao/PersonJsonDao.scala index 0c75375..aca5238 100644 --- a/json/src/test/scala/dao/PersonJsonDao.scala +++ b/json/src/test/scala/dao/PersonJsonDao.scala @@ -17,11 +17,11 @@ package reactivemongo.extensions.json.dao import scala.concurrent.ExecutionContext.Implicits.global -import reactivemongo.extensions.json.model.Person -import reactivemongo.api.DB - import scala.concurrent.Future + +import reactivemongo.api.DB import reactivemongo.extensions.json.dsl.JsonDsl +import reactivemongo.extensions.json.model.Person class PersonJsonDao(_db: Future[DB]) extends JsonDao[Person, String](_db, "persons") with JsonDsl { diff --git a/json/src/test/scala/dao/TemporalModelJsonDao.scala b/json/src/test/scala/dao/TemporalModelJsonDao.scala index 13a83fc..4b93d86 100644 --- a/json/src/test/scala/dao/TemporalModelJsonDao.scala +++ b/json/src/test/scala/dao/TemporalModelJsonDao.scala @@ -17,10 +17,11 @@ package reactivemongo.extensions.json.dao import scala.concurrent.ExecutionContext.Implicits.global + +import reactivemongo.api.bson.BSONObjectID import reactivemongo.extensions.dao.MongoContext import reactivemongo.extensions.json.model.TemporalModel import reactivemongo.extensions.util.Misc.UUID -import reactivemongo.api.bson.BSONObjectID import reactivemongo.play.json.compat.bson2json._ class TemporalModelJsonDao extends JsonDao[TemporalModel, BSONObjectID](MongoContext.db, "temporal_model_" + UUID()) diff --git a/json/src/test/scala/dao/TemporalModelJsonDaoSpec.scala b/json/src/test/scala/dao/TemporalModelJsonDaoSpec.scala index 49565b3..b80bf27 100644 --- a/json/src/test/scala/dao/TemporalModelJsonDaoSpec.scala +++ b/json/src/test/scala/dao/TemporalModelJsonDaoSpec.scala @@ -16,17 +16,17 @@ package reactivemongo.extensions.json.dao +import scala.concurrent.ExecutionContext.Implicits.global + import org.joda.time.DateTime import org.scalatest._ import org.scalatest.concurrent._ +import org.scalatest.flatspec.AnyFlatSpec +import org.scalatest.matchers.should.Matchers import org.scalatest.time.SpanSugar._ import reactivemongo.extensions.json.model.TemporalModel import reactivemongo.extensions.json.model.TemporalModel._ -import scala.concurrent.ExecutionContext.Implicits.global -import org.scalatest.flatspec.AnyFlatSpec -import org.scalatest.matchers.should.Matchers - class TemporalModelJsonDaoSpec extends AnyFlatSpec with Matchers diff --git a/json/src/test/scala/dsl/JsonDslSpec.scala b/json/src/test/scala/dsl/JsonDslSpec.scala index dd18cf2..5c72b96 100644 --- a/json/src/test/scala/dsl/JsonDslSpec.scala +++ b/json/src/test/scala/dsl/JsonDslSpec.scala @@ -16,15 +16,15 @@ package reactivemongo.extensions.json.dsl -import reactivemongo.extensions.util.Logger -import reactivemongo.api.bson._ -import play.api.libs.json._ -import reactivemongo.play.json.compat.bson2json._ -import JsonDsl._ import org.joda.time.DateTime -import reactivemongo.extensions.json.joda.JodaFormats._ import org.scalatest.flatspec.AnyFlatSpec import org.scalatest.matchers.should.Matchers +import play.api.libs.json._ +import reactivemongo.api.bson._ +import reactivemongo.extensions.json.joda.JodaFormats._ +import reactivemongo.extensions.util.Logger +import reactivemongo.play.json.compat.bson2json._ +import JsonDsl._ class JsonDslSpec extends AnyFlatSpec with Matchers { @@ -71,7 +71,7 @@ class JsonDslSpec extends AnyFlatSpec with Matchers { dsl shouldBe expected } - //**********************************************************************************************// + // **********************************************************************************************// // Comparison Operators it should "create complex document 1" in { val dsl: JsObject = "age".$gt(50).$lt(60) @@ -136,9 +136,9 @@ class JsonDslSpec extends AnyFlatSpec with Matchers { dsl shouldBe expected } // End of Comparison Operators - //**********************************************************************************************// + // **********************************************************************************************// - //**********************************************************************************************// + // **********************************************************************************************// // Logical Operators it should "create $or" in { val dsl = $or("qty".$lt(20).$gte(10), "sale".$eq(true)) @@ -172,9 +172,9 @@ class JsonDslSpec extends AnyFlatSpec with Matchers { dsl shouldBe expected } // End of logical operators - //**********************************************************************************************// + // **********************************************************************************************// - //**********************************************************************************************// + // **********************************************************************************************// // Element Operators it should "create $exists" in { val dsl1: JsObject = "qty".$exists(true) @@ -196,9 +196,9 @@ class JsonDslSpec extends AnyFlatSpec with Matchers { dsl2 shouldBe expected2 } // End of Element Operators - //**********************************************************************************************// + // **********************************************************************************************// - //**********************************************************************************************// + // **********************************************************************************************// // Evaluation Operators it should "create $mod" in { val dsl: JsObject = "qty".$mod(5, 0) @@ -229,9 +229,9 @@ class JsonDslSpec extends AnyFlatSpec with Matchers { dsl shouldBe expected } // End of Evaluation Operators - //**********************************************************************************************// + // **********************************************************************************************// - //**********************************************************************************************// + // **********************************************************************************************// // Array Operators it should "create $all" in { val dsl: JsObject = "size".$all("S", "M", "L") @@ -252,9 +252,9 @@ class JsonDslSpec extends AnyFlatSpec with Matchers { dsl shouldBe expected } // End of Array Operators - //**********************************************************************************************// + // **********************************************************************************************// - //**********************************************************************************************// + // **********************************************************************************************// // Top Level Field Update Operators it should "create $inc" in { val dsl = $inc("sold" -> 1, "stock" -> -1) @@ -335,9 +335,9 @@ class JsonDslSpec extends AnyFlatSpec with Matchers { } should have).message("illegal") } // End of Top Level Field Update Operators - //**********************************************************************************************// + // **********************************************************************************************// - //**********************************************************************************************// + // **********************************************************************************************// // Top Level Array Update Operators it should "create $addToSet" in { val dsl = $addToSet("sizes" -> "L", "colours" -> "Blue") @@ -379,6 +379,6 @@ class JsonDslSpec extends AnyFlatSpec with Matchers { dsl shouldBe expected } // End ofTop Level Array Update Operators - //**********************************************************************************************// + // **********************************************************************************************// } diff --git a/json/src/test/scala/fixtures/JsonFixturesSpec.scala b/json/src/test/scala/fixtures/JsonFixturesSpec.scala index 34d2eab..bb9631b 100644 --- a/json/src/test/scala/fixtures/JsonFixturesSpec.scala +++ b/json/src/test/scala/fixtures/JsonFixturesSpec.scala @@ -16,18 +16,19 @@ package reactivemongo.extensions.json.fixtures +import scala.concurrent.ExecutionContext.Implicits.global + import org.scalatest._ import org.scalatest.concurrent._ -import org.scalatest.time.Span +import org.scalatest.flatspec.AnyFlatSpec +import org.scalatest.matchers.should.Matchers import org.scalatest.time.Seconds -import reactivemongo.extensions.util.Logger +import org.scalatest.time.Span import reactivemongo.extensions.dao.MongoContext -import reactivemongo.extensions.json.dao.PersonJsonDao import reactivemongo.extensions.json.dao.EventJsonDao +import reactivemongo.extensions.json.dao.PersonJsonDao +import reactivemongo.extensions.util.Logger import reactivemongo.extensions.Implicits._ -import scala.concurrent.ExecutionContext.Implicits.global -import org.scalatest.flatspec.AnyFlatSpec -import org.scalatest.matchers.should.Matchers class JsonFixturesSpec extends AnyFlatSpec with Matchers with ScalaFutures with BeforeAndAfter { diff --git a/json/src/test/scala/model/CustomIdModel.scala b/json/src/test/scala/model/CustomIdModel.scala index 55f04b5..5352395 100644 --- a/json/src/test/scala/model/CustomIdModel.scala +++ b/json/src/test/scala/model/CustomIdModel.scala @@ -23,7 +23,7 @@ import reactivemongo.extensions.util.Misc.UUID case class CustomIdModel(_id: String = UUID(), name: String, surname: String, age: Int) object CustomIdModel { - implicit val customIdModelFormat = Json.format[CustomIdModel] + implicit val customIdModelFormat = Json.format[CustomIdModel] implicit val customIdModelHandler = Macros.handler[CustomIdModel] def random(n: Int): Seq[CustomIdModel] = (1 to n).map { index => diff --git a/json/src/test/scala/model/DummyModel.scala b/json/src/test/scala/model/DummyModel.scala index 662c28a..a0cbdce 100644 --- a/json/src/test/scala/model/DummyModel.scala +++ b/json/src/test/scala/model/DummyModel.scala @@ -16,14 +16,14 @@ package reactivemongo.extensions.json.model +import play.api.libs.json.Json import reactivemongo.api.bson._ import reactivemongo.play.json.compat.bson2json._ -import play.api.libs.json.Json case class DummyModel(_id: BSONObjectID = BSONObjectID.generate, name: String, surname: String, age: Int) object DummyModel { - implicit val dummyModelFormat = Json.format[DummyModel] + implicit val dummyModelFormat = Json.format[DummyModel] implicit val dummyModelHandler = Macros.handler[DummyModel] def random(n: Int): Seq[DummyModel] = (1 to n).map { index => diff --git a/json/src/test/scala/model/MapModel.scala b/json/src/test/scala/model/MapModel.scala index ef8b831..038f585 100644 --- a/json/src/test/scala/model/MapModel.scala +++ b/json/src/test/scala/model/MapModel.scala @@ -16,14 +16,14 @@ package reactivemongo.extensions.json.model +import play.api.libs.json.Json import reactivemongo.api.bson._ import reactivemongo.play.json.compat.bson2json._ -import play.api.libs.json.Json case class MapModel(_id: BSONObjectID = BSONObjectID.generate, data: Map[String, Int]) object MapModel { - implicit val mapModelFormat = Json.format[MapModel] + implicit val mapModelFormat = Json.format[MapModel] implicit val MapModelHandler = Macros.handler[MapModel] def random(n: Int): Seq[MapModel] = (1 to n).map { index => MapModel(data = Map("count" -> n)) } diff --git a/json/src/test/scala/model/Person.scala b/json/src/test/scala/model/Person.scala index bf587cd..d7afb28 100644 --- a/json/src/test/scala/model/Person.scala +++ b/json/src/test/scala/model/Person.scala @@ -22,7 +22,7 @@ import reactivemongo.api.bson.Macros case class Person(_id: String, name: String, surname: String, fullname: String, age: Int, country: String) object Person { - implicit val personFormat = Json.format[Person] + implicit val personFormat = Json.format[Person] implicit val PersonHandler = Macros.handler[Person] } diff --git a/json/src/test/scala/model/TemporalModel.scala b/json/src/test/scala/model/TemporalModel.scala index 6ddec68..8840fcd 100644 --- a/json/src/test/scala/model/TemporalModel.scala +++ b/json/src/test/scala/model/TemporalModel.scala @@ -16,14 +16,14 @@ package reactivemongo.extensions.json.model -import reactivemongo.api.bson.{BSONObjectID, BSONReader, Macros} +import org.joda.time.DateTime +import play.api.libs.json.Json +import reactivemongo.api.bson.{ BSONObjectID, BSONReader, Macros } import reactivemongo.extensions.dao.LifeCycle +import reactivemongo.extensions.json.joda.JodaFormats._ import reactivemongo.extensions.util.Logger -import play.api.libs.json.Json -import org.joda.time.DateTime import reactivemongo.play.json.compat.bson2json._ import reactivemongo.play.json.compat.json2bson._ -import reactivemongo.extensions.json.joda.JodaFormats._ case class TemporalModel( _id: BSONObjectID = BSONObjectID.generate(), diff --git a/project/Common.scala b/project/Common.scala index a0faca8..d79d295 100644 --- a/project/Common.scala +++ b/project/Common.scala @@ -1,4 +1,5 @@ import sbt._ + import Keys._ object Common { diff --git a/project/Travis.scala b/project/Travis.scala deleted file mode 100644 index 03a2a52..0000000 --- a/project/Travis.scala +++ /dev/null @@ -1,50 +0,0 @@ -import sbt._ -import Keys._ - -object Travis { - val travisSnapshotBranches = SettingKey[Seq[String]]("branches that can be published on sonatype") - - val travisCommand = Command.command("publishSnapshotsFromTravis") { state => - val extracted = Project.extract(state) - import extracted._ - - val thisRef = extracted.get(thisProjectRef) - - val isSnapshot = getOpt(version).exists(_.endsWith("SNAPSHOT")) - val isTravisEnabled = sys.env.get("TRAVIS").exists(_ == "true") - val isNotPR = sys.env.get("TRAVIS_PULL_REQUEST").exists(_ == "false") - val isBranchAcceptable = - sys.env.get("TRAVIS_BRANCH").exists(branch => getOpt(travisSnapshotBranches).exists(_.contains(branch))) - - if (isSnapshot && isTravisEnabled && isNotPR && isBranchAcceptable) { - - println(s"publishing $thisRef from travis...") - - val newState = - appendWithSession( - Seq( - publishTo := Some("Sonatype Snapshots".at("https://oss.sonatype.org/content/repositories/snapshots/")), - credentials := Seq( - Credentials( - "Sonatype Nexus Repository Manager", - "oss.sonatype.org", - sys.env.get("SONATYPE_USER").getOrElse(throw new RuntimeException("no SONATYPE_USER defined")), - sys.env.get("SONATYPE_PASSWORD").getOrElse(throw new RuntimeException("no SONATYPE_PASSWORD defined")) - ) - ) - ), - state - ) - - runTask(publish in thisRef, newState) - - println(s"published $thisRef from travis") - } else { - println( - s"not publishing $thisRef to Sonatype : isSnapshot=$isSnapshot, isTravisEnabled=$isTravisEnabled, isNotPR=$isNotPR, isBranchAcceptable=$isBranchAcceptable" - ) - } - - state - } -} diff --git a/samples/src/test/scala/dsl/criteria/TypedCriteriaSpec.scala b/samples/src/test/scala/dsl/criteria/TypedCriteriaSpec.scala index 173f781..2d87d0c 100644 --- a/samples/src/test/scala/dsl/criteria/TypedCriteriaSpec.scala +++ b/samples/src/test/scala/dsl/criteria/TypedCriteriaSpec.scala @@ -18,11 +18,10 @@ package reactivemongo.extensions.samples.dsl.criteria import org.scalatest._ - -import reactivemongo.api.bson._ -import reactivemongo.extensions.dsl.criteria._ import org.scalatest.flatspec.AnyFlatSpec import org.scalatest.matchers.should.Matchers +import reactivemongo.api.bson._ +import reactivemongo.extensions.dsl.criteria._ trait Company { val name: String; @@ -31,11 +30,11 @@ trait Company { case class Person(val firstName: String, val lastName: String, age: Int) -/** The '''TypedCriteriaSpec''' type verifies the expected behaviour of the +/** + * The '''TypedCriteriaSpec''' type verifies the expected behaviour of the * [[reactivemongo.extensions.dsl.criteria.Typed]] Criteria DSL. * * @author svickers - * */ class TypedCriteriaSpec extends AnyFlatSpec with Matchers { /// Class Imports @@ -52,7 +51,7 @@ class TypedCriteriaSpec extends AnyFlatSpec with Matchers { t match { case Term(propertyName) => - propertyName shouldBe ("lastName"); + propertyName shouldBe "lastName"; } }