Autoformat

This commit is contained in:
Eike Kettner 2020-09-09 00:29:32 +02:00
parent 570b7de43f
commit c658677032
34 changed files with 279 additions and 319 deletions

View File

@ -26,8 +26,7 @@ object Domain {
Tld
.findTld(str)
.map(tld => (str.dropRight(tld.length), tld))
.map({
case (names, tld) =>
.map({ case (names, tld) =>
names.split('.').toList match {
case Nil => Left(s"Not a domain: $str")
case segs

View File

@ -39,14 +39,14 @@ object DateFind {
}
private object SimpleDate {
val p0 = (readYear >> readMonth >> readDay).map {
case ((y, m), d) => SimpleDate(y, m, d)
val p0 = (readYear >> readMonth >> readDay).map { case ((y, m), d) =>
SimpleDate(y, m, d)
}
val p1 = (readDay >> readMonth >> readYear).map {
case ((d, m), y) => SimpleDate(y, m, d)
val p1 = (readDay >> readMonth >> readYear).map { case ((d, m), y) =>
SimpleDate(y, m, d)
}
val p2 = (readMonth >> readDay >> readYear).map {
case ((m, d), y) => SimpleDate(y, m, d)
val p2 = (readMonth >> readDay >> readYear).map { case ((m, d), y) =>
SimpleDate(y, m, d)
}
// ymd , ydm, dmy , dym, myd, mdy

View File

@ -145,8 +145,7 @@ final class StanfordTextClassifier[F[_]: Sync: ContextShift](
def prepend(pre: String, data: Map[String, String]): Map[String, String] =
data.toList
.map({
case (k, v) =>
.map({ case (k, v) =>
if (k.startsWith(pre)) (k, v)
else (pre + k, v)
})

View File

@ -29,8 +29,7 @@ object StanfordTextClassifierSuite extends SimpleTestSuite {
.repeat
.take(10)
)
.flatMap({
case (a, b) =>
.flatMap({ case (a, b) =>
Stream.emits(Seq(a, b))
})
.covary[IO]
@ -53,8 +52,7 @@ object StanfordTextClassifierSuite extends SimpleTestSuite {
} yield (dir, blocker)
things
.use {
case (dir, blocker) =>
.use { case (dir, blocker) =>
val classifier = new StanfordTextClassifier[IO](cfg, blocker)
val modelFile = dir.resolve("test.ser.gz")

View File

@ -222,8 +222,7 @@ object LenientUri {
def percentDecode(s: String): String =
if (!s.contains("%")) s
else
s.foldLeft(("", ByteVector.empty)) {
case ((acc, res), c) =>
s.foldLeft(("", ByteVector.empty)) { case ((acc, res), c) =>
if (acc.length == 2) ("", res ++ ByteVector.fromValidHex(acc.drop(1) + c))
else if (acc.startsWith("%")) (acc :+ c, res)
else if (c == '%') ("%", res)

View File

@ -20,8 +20,7 @@ object SystemCommand {
def replace(repl: Map[String, String]): Config =
mapArgs(s =>
repl.foldLeft(s) {
case (res, (k, v)) =>
repl.foldLeft(s) { case (res, (k, v)) =>
res.replace(k, v)
}
)

View File

@ -126,8 +126,7 @@ object ConversionTest extends SimpleTestSuite with FileChecks {
conversion.use { conv =>
def check(n: Long): Handler[IO, Unit] =
storePdfTxtHandler(dir.resolve(s"test-$n.pdf"), dir.resolve(s"test-$n.txt"))
.map {
case (p, t) =>
.map { case (p, t) =>
assert(p.isNonEmpty && p.isPDF)
assert(t.isNonEmpty && t.isPlainText)
}
@ -165,8 +164,7 @@ object ConversionTest extends SimpleTestSuite with FileChecks {
.emits(uris)
.covary[IO]
.zipWithIndex
.evalMap({
case (uri, index) =>
.evalMap({ case (uri, index) =>
val load = uri.readURL[IO](8192, blocker)
val dataType = DataType.filename(uri.path.segments.last)
logger.info(s"Processing file ${uri.path.asString}") *>

View File

@ -44,14 +44,14 @@ object PoiExtract {
getDocx(data)
case PoiType.msoffice =>
EitherT(getDoc[F](data))
.recoverWith({
case _ => EitherT(getXls[F](data))
.recoverWith({ case _ =>
EitherT(getXls[F](data))
})
.value
case PoiType.ooxml =>
EitherT(getDocx[F](data))
.recoverWith({
case _ => EitherT(getXlsx[F](data))
.recoverWith({ case _ =>
EitherT(getXlsx[F](data))
})
.value
case mt =>

View File

@ -14,8 +14,7 @@ object OdfExtractTest extends SimpleTestSuite {
)
test("test extract from odt") {
files.foreach {
case (file, len) =>
files.foreach { case (file, len) =>
val is = file.toJavaUrl.map(_.openStream()).fold(sys.error, identity)
val str1 = OdfExtract.get(is).fold(throw _, identity)
assertEquals(str1.length, len)

View File

@ -14,8 +14,7 @@ object PdfboxExtractTest extends SimpleTestSuite {
)
test("extract text from text PDFs by inputstream") {
textPDFs.foreach {
case (file, txt) =>
textPDFs.foreach { case (file, txt) =>
val url = file.toJavaUrl.fold(sys.error, identity)
val str = PdfboxExtract.getText(url.openStream()).fold(throw _, identity)
val received = removeFormatting(str.value)
@ -25,8 +24,7 @@ object PdfboxExtractTest extends SimpleTestSuite {
}
test("extract text from text PDFs via Stream") {
textPDFs.foreach {
case (file, txt) =>
textPDFs.foreach { case (file, txt) =>
val data = file.readURL[IO](8192, blocker)
val str = PdfboxExtract.getText(data).unsafeRunSync().fold(throw _, identity)
val received = removeFormatting(str.value)

View File

@ -17,8 +17,7 @@ object PoiExtractTest extends SimpleTestSuite {
)
test("extract text from ms office files") {
officeFiles.foreach {
case (file, len) =>
officeFiles.foreach { case (file, len) =>
val str1 = PoiExtract
.get[IO](file.readURL[IO](8192, blocker), MimeTypeHint.none)
.unsafeRunSync()

View File

@ -25,8 +25,7 @@ object ImageSizeTest extends SimpleTestSuite {
)
test("get sizes from input-stream") {
files.foreach {
case (uri, expect) =>
files.foreach { case (uri, expect) =>
val url = uri.toJavaUrl.fold(sys.error, identity)
Using.resource(url.openStream()) { in =>
val dim = ImageSize.get(in)
@ -36,8 +35,7 @@ object ImageSizeTest extends SimpleTestSuite {
}
test("get sizes from stream") {
files.foreach {
case (uri, expect) =>
files.foreach { case (uri, expect) =>
val stream = uri.readURL[IO](8192, blocker)
val dim = ImageSize.get(stream).unsafeRunSync()
assertEquals(dim, expect.some)

View File

@ -41,8 +41,7 @@ object CreateItem {
.flatMap(f => ctx.store.bitpeace.get(f.fileMetaId.id).map(fm => (f, fm)))
.collect({ case (f, Some(fm)) if isValidFile(fm) => f })
.zipWithIndex
.evalMap({
case (f, index) =>
.evalMap({ case (f, index) =>
Ident
.randomId[F]
.map(id =>

View File

@ -82,8 +82,7 @@ object FindProposal {
def removeDuplicates(labels: List[NerLabel]): List[NerLabel] =
labels
.sortBy(_.startPosition)
.foldLeft((Set.empty[String], List.empty[NerLabel])) {
case ((seen, result), el) =>
.foldLeft((Set.empty[String], List.empty[NerLabel])) { case ((seen, result), el) =>
if (seen.contains(el.tag.name + el.label.toLowerCase)) (seen, result)
else (seen + (el.tag.name + el.label.toLowerCase), el :: result)
}

View File

@ -14,8 +14,7 @@ object InfoRoutes {
def apply[F[_]: Sync](): HttpRoutes[F] = {
val dsl = new Http4sDsl[F] {}
import dsl._
HttpRoutes.of[F] {
case GET -> (Root / "version") =>
HttpRoutes.of[F] { case GET -> (Root / "version") =>
Ok(
VersionInfo(
BuildInfo.version,

View File

@ -46,8 +46,7 @@ object Config {
pattern == ip || (inet.isLoopbackAddress && pattern == "127.0.0.1") || (pattern
.split('.')
.zip(ipParts)
.foldLeft(true) {
case (r, (a, b)) =>
.foldLeft(true) { case (r, (a, b)) =>
r && (a == "*" || a == b)
})

View File

@ -99,8 +99,7 @@ object RestServer {
val dsl = new Http4sDsl[F] {}
import dsl._
HttpRoutes.of {
case GET -> Root =>
HttpRoutes.of { case GET -> Root =>
Response[F](
Status.SeeOther,
body = Stream.empty,

View File

@ -441,8 +441,7 @@ trait Conversions {
oid: Option[Ident],
pid: Option[Ident]
): F[RContact] =
timeId.map {
case (id, now) =>
timeId.map { case (id, now) =>
RContact(id, c.value, c.kind, pid, oid, now)
}
@ -460,8 +459,7 @@ trait Conversions {
)
def newUser[F[_]: Sync](u: User, cid: Ident): F[RUser] =
timeId.map {
case (id, now) =>
timeId.map { case (id, now) =>
RUser(
id,
u.login,
@ -494,8 +492,7 @@ trait Conversions {
Tag(rt.tagId, rt.name, rt.category, rt.created)
def newTag[F[_]: Sync](t: Tag, cid: Ident): F[RTag] =
timeId.map {
case (id, now) =>
timeId.map { case (id, now) =>
RTag(id, cid, t.name, t.category, now)
}
@ -517,8 +514,7 @@ trait Conversions {
)
def newSource[F[_]: Sync](s: Source, cid: Ident): F[RSource] =
timeId.map({
case (id, now) =>
timeId.map({ case (id, now) =>
RSource(id, cid, s.abbrev, s.description, 0, s.enabled, s.priority, now, s.folder)
})
@ -540,8 +536,7 @@ trait Conversions {
Equipment(re.eid, re.name, re.created)
def newEquipment[F[_]: Sync](e: Equipment, cid: Ident): F[REquipment] =
timeId.map({
case (id, now) =>
timeId.map({ case (id, now) =>
REquipment(id, cid, e.name, now, now)
})

View File

@ -18,8 +18,7 @@ object CalEventCheckRoutes {
val dsl = new Http4sDsl[F] {}
import dsl._
HttpRoutes.of {
case req @ POST -> Root =>
HttpRoutes.of { case req @ POST -> Root =>
for {
data <- req.as[CalEventCheck]
res <- testEvent(data.event)

View File

@ -20,8 +20,7 @@ object CheckFileRoutes {
val dsl = new Http4sDsl[F] with ResponseGenerator[F] {}
import dsl._
HttpRoutes.of {
case GET -> Root / checksum =>
HttpRoutes.of { case GET -> Root / checksum =>
for {
items <-
backend.itemSearch.findByFileCollective(checksum, user.account.collective)
@ -35,8 +34,7 @@ object CheckFileRoutes {
val dsl = new Http4sDsl[F] with ResponseGenerator[F] {}
import dsl._
HttpRoutes.of {
case GET -> Root / Ident(id) / checksum =>
HttpRoutes.of { case GET -> Root / Ident(id) / checksum =>
for {
items <- backend.itemSearch.findByFileSource(checksum, id)
resp <- Ok(convert(items))

View File

@ -26,12 +26,10 @@ object FullTextIndexRoutes {
val dsl = Http4sDsl[F]
import dsl._
HttpRoutes.of {
case POST -> Root / "reIndex" =>
HttpRoutes.of { case POST -> Root / "reIndex" =>
for {
res <- backend.fulltext.reindexCollective(user.account).attempt
resp <-
Ok(Conversions.basicResult(res, "Full-text index will be re-created."))
resp <- Ok(Conversions.basicResult(res, "Full-text index will be re-created."))
} yield resp
}
}
@ -42,15 +40,13 @@ object FullTextIndexRoutes {
val dsl = Http4sDsl[F]
import dsl._
HttpRoutes.of {
case POST -> Root / "reIndexAll" / Ident(id) =>
HttpRoutes.of { case POST -> Root / "reIndexAll" / Ident(id) =>
for {
res <-
if (id.nonEmpty && id == cfg.fullTextSearch.recreateKey)
backend.fulltext.reindexAll.attempt
else Left(new Exception("The provided key is invalid.")).pure[F]
resp <-
Ok(Conversions.basicResult(res, "Full-text index will be re-created."))
resp <- Ok(Conversions.basicResult(res, "Full-text index will be re-created."))
} yield resp
}
}

View File

@ -14,8 +14,7 @@ object InfoRoutes {
def apply[F[_]: Sync](): HttpRoutes[F] = {
val dsl = new Http4sDsl[F] {}
import dsl._
HttpRoutes.of[F] {
case GET -> (Root / "version") =>
HttpRoutes.of[F] { case GET -> (Root / "version") =>
Ok(
VersionInfo(
BuildInfo.version,

View File

@ -19,8 +19,7 @@ object LoginRoutes {
val dsl: Http4sDsl[F] = new Http4sDsl[F] {}
import dsl._
HttpRoutes.of[F] {
case req @ POST -> Root / "login" =>
HttpRoutes.of[F] { case req @ POST -> Root / "login" =>
for {
up <- req.as[UserPass]
res <- S.loginUserPass(cfg.auth)(Login.UserPass(up.account, up.password))

View File

@ -23,8 +23,7 @@ object MailSendRoutes {
val dsl = new Http4sDsl[F] {}
import dsl._
HttpRoutes.of {
case req @ POST -> Root / Ident(name) / Ident(id) =>
HttpRoutes.of { case req @ POST -> Root / Ident(name) / Ident(id) =>
for {
in <- req.as[SimpleMail]
mail = convertIn(id, in)

View File

@ -40,16 +40,14 @@ object TemplateRoutes {
import dsl._
new InnerRoutes[F] {
def doc =
HttpRoutes.of[F] {
case GET -> Root =>
HttpRoutes.of[F] { case GET -> Root =>
for {
templ <- docTemplate
resp <- Ok(DocData().render(templ), `Content-Type`(`text/html`))
} yield resp
}
def app =
HttpRoutes.of[F] {
case GET -> _ =>
HttpRoutes.of[F] { case GET -> _ =>
for {
templ <- indexTemplate
resp <- Ok(IndexData(cfg).render(templ), `Content-Type`(`text/html`))

View File

@ -45,8 +45,7 @@ object QOrganization {
.query[(ROrganization, Option[RContact])]
.stream
.groupAdjacentBy(_._1)
.map({
case (ro, chunk) =>
.map({ case (ro, chunk) =>
val cs = chunk.toVector.flatMap(_._2)
(ro, cs)
})
@ -71,8 +70,7 @@ object QOrganization {
.query[(ROrganization, Option[RContact])]
.stream
.groupAdjacentBy(_._1)
.map({
case (ro, chunk) =>
.map({ case (ro, chunk) =>
val cs = chunk.toVector.flatMap(_._2)
(ro, cs)
})
@ -109,8 +107,7 @@ object QOrganization {
.query[(RPerson, Option[RContact])]
.stream
.groupAdjacentBy(_._1)
.map({
case (ro, chunk) =>
.map({ case (ro, chunk) =>
val cs = chunk.toVector.flatMap(_._2)
(ro, cs)
})
@ -135,8 +132,7 @@ object QOrganization {
.query[(RPerson, Option[RContact])]
.stream
.groupAdjacentBy(_._1)
.map({
case (ro, chunk) =>
.map({ case (ro, chunk) =>
val cs = chunk.toVector.flatMap(_._2)
(ro, cs)
})