Reformat with scalafmt 3.0.0

This commit is contained in:
Scala Steward
2021-08-19 08:50:30 +02:00
parent 5a2a0295ef
commit e4fecefaea
127 changed files with 558 additions and 658 deletions

View File

@ -22,12 +22,12 @@ import io.circe.{Decoder, Encoder}
trait DoobieMeta extends EmilDoobieMeta {
implicit val sqlLogging = LogHandler({
implicit val sqlLogging = LogHandler {
case e @ Success(_, _, _, _) =>
DoobieMeta.logger.trace("SQL " + e)
case e =>
DoobieMeta.logger.error(s"SQL Failure: $e")
})
}
def jsonMeta[A](implicit d: Decoder[A], e: Encoder[A]): Meta[A] =
Meta[String].imap(str => str.parseJsonAs[A].fold(ex => throw ex, identity))(a =>

View File

@ -22,7 +22,7 @@ object FlywayMigrate {
logger.info("Running db migrations...")
val locations = jdbc.dbmsName match {
case Some(dbtype) =>
List(s"classpath:db/migration/${dbtype}")
List(s"classpath:db/migration/$dbtype")
case None =>
logger.warn(
s"Cannot read database name from jdbc url: ${jdbc.url}. Go with H2"

View File

@ -22,13 +22,12 @@ sealed trait FromExpr {
def leftJoin(sel: Select, alias: String, on: Condition): Joined =
leftJoin(Relation.SubSelect(sel, alias), on)
/** Prepends the given from expression to existing joins. It will
* replace the current [[FromExpr.From]] value.
/** Prepends the given from expression to existing joins. It will replace the current
* [[FromExpr.From]] value.
*
* If this is a [[FromExpr.From]], it is replaced by the given
* expression. If this is a [[FromExpr.Joined]] then the given
* expression replaces the current `From` and the joins are
* prepended to the existing joins.
* If this is a [[FromExpr.From]], it is replaced by the given expression. If this is a
* [[FromExpr.Joined]] then the given expression replaces the current `From` and the
* joins are prepended to the existing joins.
*/
def prepend(fe: FromExpr): FromExpr
}

View File

@ -46,9 +46,8 @@ object QAttachment {
.foldMonoid
}
/** Deletes an attachment, its related source and meta data records.
* It will only delete an related archive file, if this is the last
* attachment in that archive.
/** Deletes an attachment, its related source and meta data records. It will only delete
* an related archive file, if this is the last attachment in that archive.
*/
def deleteSingleAttachment[F[_]: Sync](
store: Store[F]
@ -77,9 +76,9 @@ object QAttachment {
} yield n + k + f
}
/** This deletes the attachment and *all* its related files. This used
* when deleting an item and should not be used to delete a
* *single* attachment where the item should stay.
/** This deletes the attachment and *all* its related files. This used when deleting an
* item and should not be used to delete a *single* attachment where the item should
* stay.
*/
private def deleteAttachment[F[_]: Sync](store: Store[F])(ra: RAttachment): F[Int] =
for {

View File

@ -368,8 +368,8 @@ object QItem {
from.query[ListItem].stream
}
/** Same as `findItems` but resolves the tags for each item. Note that
* this is implemented by running an additional query per item.
/** Same as `findItems` but resolves the tags for each item. Note that this is
* implemented by running an additional query per item.
*/
def findItemsWithTags(
collective: Ident,

View File

@ -43,14 +43,14 @@ object QJob {
else ().pure[F]
}
.find(_.isRight)
.flatMap({
.flatMap {
case Right(job) =>
Stream.emit(job)
case Left(_) =>
Stream
.eval(logger.fwarn[F]("Cannot mark job, even after retrying. Give up."))
.map(_ => None)
})
}
.compile
.last
.map(_.flatten)

View File

@ -43,10 +43,10 @@ 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)
})
}
}
def getOrgAndContact(
@ -63,10 +63,10 @@ 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)
})
}
.compile
.last
}
@ -91,11 +91,11 @@ object QOrganization {
.query[(RPerson, Option[ROrganization], Option[RContact])]
.stream
.groupAdjacentBy(_._1)
.map({ case (rp, chunk) =>
.map { case (rp, chunk) =>
val cs = chunk.toVector.flatMap(_._3)
val ro = chunk.map(_._2).head.flatten
(rp, ro, cs)
})
}
}
def getPersonAndContact(
@ -115,11 +115,11 @@ object QOrganization {
.query[(RPerson, Option[ROrganization], Option[RContact])]
.stream
.groupAdjacentBy(_._1)
.map({ case (rp, chunk) =>
.map { case (rp, chunk) =>
val cs = chunk.toVector.flatMap(_._3)
val ro = chunk.map(_._2).head.flatten
(rp, ro, cs)
})
}
.compile
.last
}

View File

@ -31,5 +31,5 @@ object QueryWildcard {
def addAtEnd(s: String): String =
if (s.endsWith("*")) atEnd(s)
else s"${s}%"
else s"$s%"
}

View File

@ -19,14 +19,13 @@ import org.log4s._
trait JobQueue[F[_]] {
/** Inserts the job into the queue to get picked up as soon as
* possible. The job must have a new unique id.
/** Inserts the job into the queue to get picked up as soon as possible. The job must
* have a new unique id.
*/
def insert(job: RJob): F[Unit]
/** Inserts the job into the queue only, if there is no job with the
* same tracker-id running at the moment. The job id must be a new
* unique id.
/** Inserts the job into the queue only, if there is no job with the same tracker-id
* running at the moment. The job id must be a new unique id.
*
* If the job has no tracker defined, it is simply inserted.
*/

View File

@ -19,12 +19,10 @@ import org.log4s.getLogger
trait PeriodicTaskStore[F[_]] {
/** Get the free periodic task due next and reserve it to the given
* worker.
/** Get the free periodic task due next and reserve it to the given worker.
*
* If found, the task is returned and resource finalization takes
* care of unmarking the task after use and updating `nextRun` with
* the next timestamp.
* If found, the task is returned and resource finalization takes care of unmarking the
* task after use and updating `nextRun` with the next timestamp.
*/
def takeNext(
worker: Ident,
@ -69,10 +67,10 @@ object PeriodicTaskStore {
Marked.notFound.pure[F]
}
Resource.make(chooseNext)({
Resource.make(chooseNext) {
case Marked.Found(pj) => unmark(pj)
case _ => ().pure[F]
})
}
}
def getNext(excl: Option[Ident]): F[Option[RPeriodicTask]] =

View File

@ -17,8 +17,8 @@ import bitpeace.FileMeta
import doobie._
import doobie.implicits._
/** The archive file of some attachment. The `id` is shared with the
* attachment, to create a 0..1-1 relationship.
/** The archive file of some attachment. The `id` is shared with the attachment, to create
* a 0..1-1 relationship.
*/
case class RAttachmentArchive(
id: Ident, //same as RAttachment.id
@ -113,9 +113,8 @@ object RAttachmentArchive {
).orderBy(b.position.asc).build.query[(RAttachmentArchive, FileMeta)].to[Vector]
}
/** If the given attachment id has an associated archive, this returns
* the number of all associated attachments. Returns 0 if there is
* no archive for the given attachment.
/** If the given attachment id has an associated archive, this returns the number of all
* associated attachments. Returns 0 if there is no archive for the given attachment.
*/
def countEntries(attachId: Ident): ConnectionIO[Int] =
Select(

View File

@ -16,8 +16,8 @@ import bitpeace.FileMeta
import doobie._
import doobie.implicits._
/** A preview image of an attachment. The `id` is shared with the
* attachment, to create a 1-1 (or 0..1-1) relationship.
/** A preview image of an attachment. The `id` is shared with the attachment, to create a
* 1-1 (or 0..1-1) relationship.
*/
case class RAttachmentPreview(
id: Ident, //same as RAttachment.id

View File

@ -16,8 +16,8 @@ import bitpeace.FileMeta
import doobie._
import doobie.implicits._
/** The origin file of an attachment. The `id` is shared with the
* attachment, to create a 1-1 (or 0..1-1) relationship.
/** The origin file of an attachment. The `id` is shared with the attachment, to create a
* 1-1 (or 0..1-1) relationship.
*/
case class RAttachmentSource(
id: Ident, //same as RAttachment.id

View File

@ -87,10 +87,9 @@ object RClassifierSetting {
def delete(coll: Ident): ConnectionIO[Int] =
DML.delete(T, T.cid === coll)
/** Finds tag categories that exist and match the classifier setting.
* If the setting contains a black list, they are removed from the
* existing categories. If it is a whitelist, the intersection is
* returned.
/** Finds tag categories that exist and match the classifier setting. If the setting
* contains a black list, they are removed from the existing categories. If it is a
* whitelist, the intersection is returned.
*/
def getActiveCategories(coll: Ident): ConnectionIO[List[String]] =
(for {
@ -104,7 +103,9 @@ object RClassifierSetting {
}
} yield res).getOrElse(Nil)
/** Checks the json array of tag categories and removes those that are not present anymore. */
/** Checks the json array of tag categories and removes those that are not present
* anymore.
*/
def fixCategoryList(coll: Ident): ConnectionIO[Int] =
(for {
sett <- OptionT(findById(coll))

View File

@ -35,7 +35,7 @@ object RContact {
val personId = Column[Ident]("pid", this)
val orgId = Column[Ident]("oid", this)
val created = Column[Timestamp]("created", this)
val all = NonEmptyList.of[Column[_]](contactId, value, kind, personId, orgId, created)
val all = NonEmptyList.of[Column[_]](contactId, value, kind, personId, orgId, created)
}
private val T = Table(None)

View File

@ -88,7 +88,7 @@ object RFolder {
case Some(id) => id.pure[ConnectionIO]
case None =>
Sync[ConnectionIO].raiseError(
new Exception(s"No folder found for: id=${folderId.id} or name=${name}")
new Exception(s"No folder found for: id=${folderId.id} or name=$name")
)
}
}

View File

@ -30,7 +30,7 @@ object RItemProposal {
val classifyProposals = Column[MetaProposalList]("classifier_proposals", this)
val classifyTags = Column[List[IdRef]]("classifier_tags", this)
val created = Column[Timestamp]("created", this)
val all = NonEmptyList.of[Column[_]](itemId, classifyProposals, classifyTags, created)
val all = NonEmptyList.of[Column[_]](itemId, classifyProposals, classifyTags, created)
}
val T = Table(None)

View File

@ -40,7 +40,7 @@ object RNode {
val updated = Column[Timestamp]("updated", this)
val created = Column[Timestamp]("created", this)
val notFound = Column[Int]("not_found", this)
val all = NonEmptyList.of[Column[_]](id, nodeType, url, updated, created, notFound)
val all = NonEmptyList.of[Column[_]](id, nodeType, url, updated, created, notFound)
}
def as(alias: String): Table =

View File

@ -20,9 +20,8 @@ import doobie._
import doobie.implicits._
import io.circe.Encoder
/** A periodic task is a special job description, that shares a few
* properties of a `RJob`. It must provide all information to create
* a `RJob` value eventually.
/** A periodic task is a special job description, that shares a few properties of a
* `RJob`. It must provide all information to create a `RJob` value eventually.
*/
case class RPeriodicTask(
id: Ident,

View File

@ -12,8 +12,8 @@ import docspell.common._
import docspell.store.qb.DSL._
import docspell.store.qb.{Condition, Select}
/** A helper class combining information from `RTag` and `RTagItem`.
* This is not a "record", there is no corresponding table.
/** A helper class combining information from `RTag` and `RTagItem`. This is not a
* "record", there is no corresponding table.
*/
case class TagItemName(
tagId: Ident,

View File

@ -17,8 +17,8 @@ sealed trait UserTaskScope { self: Product =>
def fold[A](fa: AccountId => A, fb: Ident => A): A
/** Maps to the account or uses the collective for both parts if the
* scope is collective wide.
/** Maps to the account or uses the collective for both parts if the scope is collective
* wide.
*/
private[usertask] def toAccountId: AccountId =
AccountId(collective, fold(_.user, identity))

View File

@ -17,21 +17,18 @@ import docspell.store.{AddResult, Store}
import io.circe._
/** User tasks are `RPeriodicTask`s that can be managed by the user.
* The user can change arguments, enable/disable it or run it just
* once.
/** User tasks are `RPeriodicTask`s that can be managed by the user. The user can change
* arguments, enable/disable it or run it just once.
*
* This class defines methods at a higher level, dealing with
* `UserTask` and `UserTaskScope` instead of directly using
* `RPeriodicTask`. A user task is associated to a specific user (not
* just the collective). But it can be associated to the whole
* collective by using the collective as submitter, too. This is
* abstracted in `UserTaskScope`.
* This class defines methods at a higher level, dealing with `UserTask` and
* `UserTaskScope` instead of directly using `RPeriodicTask`. A user task is associated
* to a specific user (not just the collective). But it can be associated to the whole
* collective by using the collective as submitter, too. This is abstracted in
* `UserTaskScope`.
*
* implNote: The mapping is as follows: The collective is the task
* group. The submitter property contains the username. Once a task
* is saved to the database, it can only be referenced uniquely by its
* id. A user may submit multiple same tasks (with different
* implNote: The mapping is as follows: The collective is the task group. The submitter
* property contains the username. Once a task is saved to the database, it can only be
* referenced uniquely by its id. A user may submit multiple same tasks (with different
* properties).
*/
trait UserTaskStore[F[_]] {
@ -40,13 +37,13 @@ trait UserTaskStore[F[_]] {
*/
def getAll(scope: UserTaskScope): Stream[F, UserTask[String]]
/** Return all tasks of the given name and user. The task's arguments
* are returned as stored in the database.
/** Return all tasks of the given name and user. The task's arguments are returned as
* stored in the database.
*/
def getByNameRaw(scope: UserTaskScope, name: Ident): Stream[F, UserTask[String]]
/** Return all tasks of the given name and user. The task's arguments
* are decoded using the given json decoder.
/** Return all tasks of the given name and user. The task's arguments are decoded using
* the given json decoder.
*/
def getByName[A](scope: UserTaskScope, name: Ident)(implicit
D: Decoder[A]
@ -57,9 +54,8 @@ trait UserTaskStore[F[_]] {
/** Updates or inserts the given task.
*
* The task is identified by its id. If no task with this id
* exists, a new one is created. Otherwise the existing task is
* updated.
* The task is identified by its id. If no task with this id exists, a new one is
* created. Otherwise the existing task is updated.
*/
def updateTask[A](scope: UserTaskScope, subject: Option[String], ut: UserTask[A])(
implicit E: Encoder[A]
@ -69,15 +65,13 @@ trait UserTaskStore[F[_]] {
*/
def deleteTask(scope: UserTaskScope, id: Ident): F[Int]
/** Return the task of the given user and name. If multiple exists, an
* error is returned. The task's arguments are returned as stored
* in the database.
/** Return the task of the given user and name. If multiple exists, an error is
* returned. The task's arguments are returned as stored in the database.
*/
def getOneByNameRaw(scope: UserTaskScope, name: Ident): OptionT[F, UserTask[String]]
/** Return the task of the given user and name. If multiple exists, an
* error is returned. The task's arguments are decoded using the
* given json decoder.
/** Return the task of the given user and name. If multiple exists, an error is
* returned. The task's arguments are decoded using the given json decoder.
*/
def getOneByName[A](scope: UserTaskScope, name: Ident)(implicit
D: Decoder[A]
@ -85,14 +79,12 @@ trait UserTaskStore[F[_]] {
/** Updates or inserts the given task.
*
* Unlike `updateTask`, this ensures that there is at most one task
* of some name in the db. Multiple same tasks (task with same
* name) may not be allowed to run, depending on what they do.
* This is not ensured by the database, though.
* Unlike `updateTask`, this ensures that there is at most one task of some name in the
* db. Multiple same tasks (task with same name) may not be allowed to run, depending
* on what they do. This is not ensured by the database, though.
*
* If there are currently multiple tasks with same name as `ut` for
* the user `account`, they will all be removed and the given task
* inserted!
* If there are currently multiple tasks with same name as `ut` for the user `account`,
* they will all be removed and the given task inserted!
*/
def updateOneTask[A](scope: UserTaskScope, subject: Option[String], ut: UserTask[A])(
implicit E: Encoder[A]
@ -155,7 +147,7 @@ object UserTaskStore {
.flatMap {
case Nil => (None: Option[UserTask[String]]).pure[F]
case ut :: Nil => ut.some.pure[F]
case _ => Async[F].raiseError(new Exception("More than one result found"))
case _ => Async[F].raiseError(new Exception("More than one result found"))
}
)