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 Tld
.findTld(str) .findTld(str)
.map(tld => (str.dropRight(tld.length), tld)) .map(tld => (str.dropRight(tld.length), tld))
.map({ .map({ case (names, tld) =>
case (names, tld) =>
names.split('.').toList match { names.split('.').toList match {
case Nil => Left(s"Not a domain: $str") case Nil => Left(s"Not a domain: $str")
case segs case segs

View File

@ -39,14 +39,14 @@ object DateFind {
} }
private object SimpleDate { private object SimpleDate {
val p0 = (readYear >> readMonth >> readDay).map { val p0 = (readYear >> readMonth >> readDay).map { case ((y, m), d) =>
case ((y, m), d) => SimpleDate(y, m, d) SimpleDate(y, m, d)
} }
val p1 = (readDay >> readMonth >> readYear).map { val p1 = (readDay >> readMonth >> readYear).map { case ((d, m), y) =>
case ((d, m), y) => SimpleDate(y, m, d) SimpleDate(y, m, d)
} }
val p2 = (readMonth >> readDay >> readYear).map { val p2 = (readMonth >> readDay >> readYear).map { case ((m, d), y) =>
case ((m, d), y) => SimpleDate(y, m, d) SimpleDate(y, m, d)
} }
// ymd , ydm, dmy , dym, myd, mdy // 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] = def prepend(pre: String, data: Map[String, String]): Map[String, String] =
data.toList data.toList
.map({ .map({ case (k, v) =>
case (k, v) =>
if (k.startsWith(pre)) (k, v) if (k.startsWith(pre)) (k, v)
else (pre + k, v) else (pre + k, v)
}) })

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -25,8 +25,7 @@ object ImageSizeTest extends SimpleTestSuite {
) )
test("get sizes from input-stream") { test("get sizes from input-stream") {
files.foreach { files.foreach { case (uri, expect) =>
case (uri, expect) =>
val url = uri.toJavaUrl.fold(sys.error, identity) val url = uri.toJavaUrl.fold(sys.error, identity)
Using.resource(url.openStream()) { in => Using.resource(url.openStream()) { in =>
val dim = ImageSize.get(in) val dim = ImageSize.get(in)
@ -36,8 +35,7 @@ object ImageSizeTest extends SimpleTestSuite {
} }
test("get sizes from stream") { test("get sizes from stream") {
files.foreach { files.foreach { case (uri, expect) =>
case (uri, expect) =>
val stream = uri.readURL[IO](8192, blocker) val stream = uri.readURL[IO](8192, blocker)
val dim = ImageSize.get(stream).unsafeRunSync() val dim = ImageSize.get(stream).unsafeRunSync()
assertEquals(dim, expect.some) 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))) .flatMap(f => ctx.store.bitpeace.get(f.fileMetaId.id).map(fm => (f, fm)))
.collect({ case (f, Some(fm)) if isValidFile(fm) => f }) .collect({ case (f, Some(fm)) if isValidFile(fm) => f })
.zipWithIndex .zipWithIndex
.evalMap({ .evalMap({ case (f, index) =>
case (f, index) =>
Ident Ident
.randomId[F] .randomId[F]
.map(id => .map(id =>

View File

@ -82,8 +82,7 @@ object FindProposal {
def removeDuplicates(labels: List[NerLabel]): List[NerLabel] = def removeDuplicates(labels: List[NerLabel]): List[NerLabel] =
labels labels
.sortBy(_.startPosition) .sortBy(_.startPosition)
.foldLeft((Set.empty[String], List.empty[NerLabel])) { .foldLeft((Set.empty[String], List.empty[NerLabel])) { case ((seen, result), el) =>
case ((seen, result), el) =>
if (seen.contains(el.tag.name + el.label.toLowerCase)) (seen, result) if (seen.contains(el.tag.name + el.label.toLowerCase)) (seen, result)
else (seen + (el.tag.name + el.label.toLowerCase), el :: 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] = { def apply[F[_]: Sync](): HttpRoutes[F] = {
val dsl = new Http4sDsl[F] {} val dsl = new Http4sDsl[F] {}
import dsl._ import dsl._
HttpRoutes.of[F] { HttpRoutes.of[F] { case GET -> (Root / "version") =>
case GET -> (Root / "version") =>
Ok( Ok(
VersionInfo( VersionInfo(
BuildInfo.version, BuildInfo.version,

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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