Skip to content

Commit bceb3fb

Browse files
committed
custom release settings
1 parent eff4f59 commit bceb3fb

33 files changed

+279
-223
lines changed

build.sbt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ releaseProcess := Seq[ReleaseStep](
108108
pushChanges // : ReleaseStep, also checks that an upstream branch is properly configured
109109
)
110110

111+
scalafmtOnCompile := false
112+
111113
coverageMinimum := 60
112114

113115
coverageFailOnMinimum := true

src/main/scala/com/sfxcode/nosql/mongo/Aggregate.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ trait Aggregate extends Field with Filter with Sort {
1111
def compositeProjection(resultFieldName: String, keys: List[String]): Bson =
1212
computed(
1313
resultFieldName,
14-
Map[String, Any]("$concat" -> keys.map(key => Map[String, Any]("$substr" -> List("$" + key, 0, 99999)))))
14+
Map[String, Any]("$concat" -> keys.map(key => Map[String, Any]("$substr" -> List("$" + key, 0, 99999))))
15+
)
1516

1617
def divideProjection(resultFieldName: String, dividendFieldName: String, divisorFieldName: String): Bson =
1718
computed(resultFieldName, Map[String, Any]("$divide" -> List("$" + dividendFieldName, "$" + divisorFieldName)))

src/main/scala/com/sfxcode/nosql/mongo/Field.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ trait Field {
4141
val list = fieldnames.map { name =>
4242
if (name.startsWith("$")) {
4343
name
44-
} else {
44+
}
45+
else {
4546
"$" + name
4647
}
4748
}.toList

src/main/scala/com/sfxcode/nosql/mongo/Filter.scala

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,14 @@ trait Filter {
3030
def dateInRangeFilter(dateFieldKey: String, dateFrom: Date = null, dateUntil: Date = null): Bson =
3131
if (dateFrom != null && dateUntil != null) {
3232
and(gte(dateFieldKey, dateFrom), lte(dateFieldKey, dateUntil))
33-
} else if (dateUntil != null) {
33+
}
34+
else if (dateUntil != null) {
3435
lte(dateFieldKey, dateUntil)
35-
} else if (dateFrom != null) {
36+
}
37+
else if (dateFrom != null) {
3638
gte(dateFieldKey, dateFrom)
37-
} else {
39+
}
40+
else {
3841
Map()
3942
}
4043

src/main/scala/com/sfxcode/nosql/mongo/GridFSDAO.scala

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
package com.sfxcode.nosql.mongo
22

3-
import com.sfxcode.nosql.mongo.database.{ ChangeObserver, CollectionStats, DatabaseProvider }
3+
import com.sfxcode.nosql.mongo.database.{ChangeObserver, CollectionStats, DatabaseProvider}
44
import com.sfxcode.nosql.mongo.gridfs.Metadata
55
import org.bson.types.ObjectId
66
import org.mongodb.scala.bson.conversions.Bson
7-
import org.mongodb.scala.gridfs.{ GridFSBucket, GridFSFile }
7+
import org.mongodb.scala.gridfs.{GridFSBucket, GridFSFile}
88
import org.mongodb.scala.model.CountOptions
9-
import org.mongodb.scala.{ Document, Observable, ReadConcern, ReadPreference, SingleObservable, WriteConcern }
9+
import org.mongodb.scala.{Document, Observable, ReadConcern, ReadPreference, SingleObservable, WriteConcern}
1010

1111
abstract class GridFSDAO(provider: DatabaseProvider, bucketName: String) extends Metadata(provider, bucketName) {
1212

1313
var bucket: GridFSBucket = {
1414
if (bucketName.contains(DatabaseProvider.CollectionSeparator)) {
1515
val newDatabaseName = bucketName.substring(0, bucketName.indexOf(DatabaseProvider.CollectionSeparator))
16-
val newBucketName = bucketName.substring(bucketName.indexOf(DatabaseProvider.CollectionSeparator) + 1)
16+
val newBucketName = bucketName.substring(bucketName.indexOf(DatabaseProvider.CollectionSeparator) + 1)
1717
GridFSBucket(provider.database(newDatabaseName), newBucketName)
18-
} else {
18+
}
19+
else {
1920
GridFSBucket(provider.database(), bucketName)
2021
}
2122
}

src/main/scala/com/sfxcode/nosql/mongo/MongoDAO.scala

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,27 @@ import java.nio.charset.Charset
44

55
import better.files.File
66
import com.sfxcode.nosql.mongo.bson.DocumentHelper
7-
import com.sfxcode.nosql.mongo.database.{ ChangeObserver, CollectionStats, DatabaseProvider }
7+
import com.sfxcode.nosql.mongo.database.{ChangeObserver, CollectionStats, DatabaseProvider}
88
import com.sfxcode.nosql.mongo.operation.Crud
99
import org.bson.json.JsonParseException
10-
import org.mongodb.scala.{ BulkWriteResult, Document, MongoCollection, Observable, SingleObservable }
10+
import org.mongodb.scala.{BulkWriteResult, Document, MongoCollection, Observable, SingleObservable}
1111

1212
import scala.collection.mutable.ArrayBuffer
1313
import scala.reflect.ClassTag
1414

1515
/**
16-
* Created by tom on 20.01.17.
17-
*/
16+
* Created by tom on 20.01.17.
17+
*/
1818
abstract class MongoDAO[A](provider: DatabaseProvider, collectionName: String)(implicit ct: ClassTag[A])
19-
extends Crud[A] {
19+
extends Crud[A] {
2020

2121
val collection: MongoCollection[A] = {
2222
if (collectionName.contains(DatabaseProvider.CollectionSeparator)) {
23-
val newDatabaseName = collectionName.substring(0, collectionName.indexOf(DatabaseProvider.CollectionSeparator))
23+
val newDatabaseName = collectionName.substring(0, collectionName.indexOf(DatabaseProvider.CollectionSeparator))
2424
val newCollectionName = collectionName.substring(collectionName.indexOf(DatabaseProvider.CollectionSeparator) + 1)
2525
provider.database(newDatabaseName).getCollection[A](newCollectionName)
26-
} else {
26+
}
27+
else {
2728
provider.database().getCollection[A](collectionName)
2829
}
2930
}
@@ -48,7 +49,8 @@ abstract class MongoDAO[A](provider: DatabaseProvider, collectionName: String)(i
4849
val iterator = file.lineIterator(Charset.forName("UTF-8"))
4950
iterator.foreach(line => docs.+=(DocumentHelper.documentFromJsonString(line).get))
5051
}
51-
} catch {
52+
}
53+
catch {
5254
case e: JsonParseException =>
5355
logger.error(e.getMessage, e)
5456
}

src/main/scala/com/sfxcode/nosql/mongo/Sort.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.sfxcode.nosql.mongo
22

33
import org.bson.conversions.Bson
4-
import org.mongodb.scala.model.Sorts.{ ascending, descending, orderBy }
4+
import org.mongodb.scala.model.Sorts.{ascending, descending, orderBy}
55

66
object Sort extends Sort
77

@@ -10,7 +10,8 @@ trait Sort {
1010
def sortByKey(key: String, sortAscending: Boolean = true): Bson =
1111
if (sortAscending) {
1212
orderBy(ascending(key))
13-
} else {
13+
}
14+
else {
1415
orderBy(descending(key))
1516
}
1617

src/main/scala/com/sfxcode/nosql/mongo/bson/BsonConverter.scala

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.sfxcode.nosql.mongo.bson
22

33
import java.math.BigInteger
4-
import java.time.{ LocalDate, LocalDateTime, ZoneId }
4+
import java.time.{LocalDate, LocalDateTime, ZoneId}
55
import java.util.Date
66

77
import org.mongodb.scala.Document
@@ -22,31 +22,32 @@ object BsonConverter {
2222
case option: Option[Any] =>
2323
if (option.isDefined) {
2424
toBson(option.get)
25-
} else {
25+
}
26+
else {
2627
BsonNull()
2728
}
2829
case v: Any if converterPlugin.hasCustomClass(v) =>
2930
converterPlugin.toBson(v)
30-
case b: Boolean => BsonBoolean(b)
31-
case s: String => BsonString(s)
32-
case c: Char => BsonString(c.toString)
31+
case b: Boolean => BsonBoolean(b)
32+
case s: String => BsonString(s)
33+
case c: Char => BsonString(c.toString)
3334
case bytes: Array[Byte] => BsonBinary(bytes)
34-
case r: Regex => BsonRegularExpression(r)
35-
case d: Date => BsonDateTime(d)
35+
case r: Regex => BsonRegularExpression(r)
36+
case d: Date => BsonDateTime(d)
3637
case ld: LocalDate =>
3738
BsonDateTime(Date.from(ld.atStartOfDay(ZoneId.systemDefault()).toInstant))
3839
case ldt: LocalDateTime =>
3940
BsonDateTime(Date.from(ldt.atZone(ZoneId.systemDefault()).toInstant))
40-
case oid: ObjectId => BsonObjectId(oid)
41-
case i: Int => BsonInt32(i)
42-
case l: Long => BsonInt64(l)
43-
case bi: BigInt => BsonInt64(bi.toLong)
44-
case bi: BigInteger => BsonInt64(bi.longValue())
45-
case d: Double => BsonDouble(d)
46-
case f: Float => BsonDouble(f)
47-
case bd: BigDecimal => BsonDecimal128.apply(bd)
41+
case oid: ObjectId => BsonObjectId(oid)
42+
case i: Int => BsonInt32(i)
43+
case l: Long => BsonInt64(l)
44+
case bi: BigInt => BsonInt64(bi.toLong)
45+
case bi: BigInteger => BsonInt64(bi.longValue())
46+
case d: Double => BsonDouble(d)
47+
case f: Float => BsonDouble(f)
48+
case bd: BigDecimal => BsonDecimal128.apply(bd)
4849
case bd: java.math.BigDecimal => BsonDecimal128.apply(bd)
49-
case doc: Document => BsonDocument(doc)
50+
case doc: Document => BsonDocument(doc)
5051
case map: scala.collection.Map[_, _] =>
5152
var doc = Document()
5253
map.keys.foreach { key =>
@@ -76,22 +77,22 @@ object BsonConverter {
7677
def fromBson(value: BsonValue): Any =
7778
value match {
7879

79-
case b: BsonBoolean => b.getValue
80-
case s: BsonString => s.getValue
81-
case bytes: BsonBinary => bytes.getData
80+
case b: BsonBoolean => b.getValue
81+
case s: BsonString => s.getValue
82+
case bytes: BsonBinary => bytes.getData
8283
case r: BsonRegularExpression => r.getPattern
83-
case d: BsonDateTime => new Date(d.getValue)
84-
case d: BsonTimestamp => new Date(d.getTime)
85-
case oid: BsonObjectId => oid.getValue
86-
case i: BsonInt32 => i.getValue
87-
case l: BsonInt64 => l.getValue
88-
case d: BsonDouble => d.doubleValue()
89-
case d: BsonDecimal128 => d.getValue.bigDecimalValue()
90-
case doc: BsonDocument => Document(doc)
84+
case d: BsonDateTime => new Date(d.getValue)
85+
case d: BsonTimestamp => new Date(d.getTime)
86+
case oid: BsonObjectId => oid.getValue
87+
case i: BsonInt32 => i.getValue
88+
case l: BsonInt64 => l.getValue
89+
case d: BsonDouble => d.doubleValue()
90+
case d: BsonDecimal128 => d.getValue.bigDecimalValue()
91+
case doc: BsonDocument => Document(doc)
9192
case array: BsonArray =>
9293
array.getValues.asScala.toList.map(v => fromBson(v))
9394
case n: BsonNull => null
94-
case _ => value
95+
case _ => value
9596
}
9697

9798
def asMap(document: Document): Map[String, Any] = {

src/main/scala/com/sfxcode/nosql/mongo/bson/ConverterPlugin.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ object ClassUtil {
5151
result.+=(name -> value)
5252
}
5353

54-
} else {
54+
}
55+
else {
5556
val fields = classRegistry(clazz)
5657
fields.keys.foreach { name =>
5758
val value = fields(name).get(v)

src/main/scala/com/sfxcode/nosql/mongo/bson/DocumentHelper.scala

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.sfxcode.nosql.mongo.bson
22

3-
import better.files.{ Scanner, StringSplitter }
3+
import better.files.{Scanner, StringSplitter}
44
import com.typesafe.scalalogging.LazyLogging
55
import org.mongodb.scala.Document
66

@@ -14,11 +14,12 @@ object DocumentHelper extends LazyLogging {
1414

1515
try {
1616
result = Some(Document(json))
17-
} catch {
17+
}
18+
catch {
1819
case e: Exception if e.getMessage.contains("parse string as a date") => {
1920
logger.debug("parse error - try to replace iso date")
20-
val scanner = Scanner(json, splitter = StringSplitter.on(SplitterDelimeter))
21-
var i = 0
21+
val scanner = Scanner(json, splitter = StringSplitter.on(SplitterDelimeter))
22+
var i = 0
2223
var datePosition = 0
2324
val resultBuffer = new StringBuffer()
2425

@@ -32,10 +33,12 @@ object DocumentHelper extends LazyLogging {
3233
resultBuffer.append(s.substring(0, 27))
3334
resultBuffer.append(":")
3435
resultBuffer.append(s.substring(27))
35-
} else {
36+
}
37+
else {
3638
resultBuffer.append(s)
3739
}
38-
} else {
40+
}
41+
else {
3942
resultBuffer.append(s)
4043
}
4144
resultBuffer.append(SplitterDelimeter)

0 commit comments

Comments
 (0)