Adopt backend to collective-id

This commit is contained in:
eikek
2022-08-04 11:03:27 +02:00
parent 26d7c91266
commit 53d92c4a26
94 changed files with 1468 additions and 833 deletions

View File

@ -16,7 +16,7 @@ import io.circe.{Decoder, Encoder}
* collective is specified, it considers all attachments.
*/
case class AllPreviewsArgs(
collective: Option[Ident],
collective: Option[CollectiveId],
storeMode: MakePreviewArgs.StoreMode
)

View File

@ -10,6 +10,12 @@ import io.circe.{Decoder, Encoder}
final class CollectiveId(val value: Long) extends AnyVal {
def valueAsString: String =
value.toString
def valueAsIdent: Ident =
Ident.unsafe(valueAsString)
override def toString =
s"CollectiveId($value)"
}
@ -19,6 +25,12 @@ object CollectiveId {
def apply(n: Long): CollectiveId = new CollectiveId(n)
def fromString(str: String): Either[String, CollectiveId] =
str.trim.toLongOption.map(CollectiveId(_)).toRight(s"Invalid collective id: $str")
def unsafeFromString(str: String): CollectiveId =
fromString(str).fold(sys.error, identity)
implicit val jsonEncoder: Encoder[CollectiveId] =
Encoder.encodeLong.contramap(_.value)
implicit val jsonDecoder: Decoder[CollectiveId] =

View File

@ -16,7 +16,7 @@ import io.circe.generic.semiauto._
* submitted by this task run in the realm of the collective (and only their files are
* considered). If it is empty, it is a system task and all files are considered.
*/
case class ConvertAllPdfArgs(collective: Option[Ident])
case class ConvertAllPdfArgs(collective: Option[CollectiveId])
object ConvertAllPdfArgs {

View File

@ -18,7 +18,7 @@ import io.circe.generic.semiauto._
* with state `ItemState.Deleted`.
*/
case class EmptyTrashArgs(
collective: Ident,
collective: CollectiveId,
minAge: Duration
) {
@ -35,8 +35,8 @@ object EmptyTrashArgs {
val defaultSchedule = CalEvent.unsafe("*-*-1/7 03:00:00 UTC")
def periodicTaskId(coll: Ident): Ident =
Ident.unsafe(s"docspell") / taskName / coll
def periodicTaskId(coll: CollectiveId): Ident =
Ident.unsafe(s"docspell") / taskName / coll.value
implicit val jsonEncoder: Encoder[EmptyTrashArgs] =
deriveEncoder[EmptyTrashArgs]
@ -45,5 +45,4 @@ object EmptyTrashArgs {
def parse(str: String): Either[Throwable, EmptyTrashArgs] =
str.parseJsonAs[EmptyTrashArgs]
}

View File

@ -20,7 +20,7 @@ sealed trait FileCategory { self: Product =>
final def id: Ident =
Ident.unsafe(self.productPrefix.toLowerCase)
def toFileKey(collective: Ident, fileId: Ident): FileKey =
def toFileKey(collective: CollectiveId, fileId: Ident): FileKey =
common.FileKey(collective, this, fileId)
}

View File

@ -9,9 +9,9 @@ package docspell.common
import io.circe.generic.semiauto.{deriveDecoder, deriveEncoder}
import io.circe.{Decoder, Encoder}
final case class FileKey(collective: Ident, category: FileCategory, id: Ident) {
final case class FileKey(collective: CollectiveId, category: FileCategory, id: Ident) {
override def toString =
s"${collective.id}/${category.id.id}/${id.id}"
s"${collective.value}/${category.id.id}/${id.id}"
}
object FileKey {

View File

@ -27,6 +27,9 @@ case class Ident(id: String) {
def /(next: Ident): Ident =
new Ident(id + Ident.concatChar + next.id)
def /(next: Number): Ident =
new Ident(id + Ident.concatChar + next)
def take(n: Int): Ident =
new Ident(id.take(n))
}

View File

@ -15,7 +15,7 @@ import io.circe.{Decoder, Encoder}
* tasks that are configured for 'existing-item' are run.
*/
final case class ItemAddonTaskArgs(
collective: Ident,
collective: CollectiveId,
itemId: Ident,
addonRunConfigs: Set[Ident]
)

View File

@ -18,7 +18,7 @@ import io.circe.generic.semiauto._
* possible tags..
*/
case class LearnClassifierArgs(
collective: Ident
collectiveId: CollectiveId
) {
def makeSubject: String =
@ -37,5 +37,4 @@ object LearnClassifierArgs {
def parse(str: String): Either[Throwable, LearnClassifierArgs] =
str.parseJsonAs[LearnClassifierArgs]
}

View File

@ -17,7 +17,7 @@ import io.circe.generic.semiauto._
* This task is run for each new file to create a new item from it or to add this file as
* an attachment to an existing item.
*
* If the `itemId' is set to some value, the item is tried to load to amend with the
* If the `itemId` is set to some value, the item is tried to load to amend with the
* given files. Otherwise a new item is created.
*
* It is also re-used by the 'ReProcessItem' task.
@ -43,7 +43,7 @@ object ProcessItemArgs {
val multiUploadTaskName = Ident.unsafe("multi-upload-process")
case class ProcessMeta(
collective: Ident,
collective: CollectiveId,
itemId: Option[Ident],
language: Language,
direction: Option[Direction],
@ -73,5 +73,4 @@ object ProcessItemArgs {
def parse(str: String): Either[Throwable, ProcessItemArgs] =
str.parseJsonAs[ProcessItemArgs]
}

View File

@ -9,7 +9,7 @@ package docspell.common
import io.circe._
import io.circe.generic.semiauto._
final case class ReIndexTaskArgs(collective: Option[Ident])
final case class ReIndexTaskArgs(collective: Option[CollectiveId])
object ReIndexTaskArgs {
val taskName = Ident.unsafe("full-text-reindex")
@ -17,7 +17,7 @@ object ReIndexTaskArgs {
def tracker(args: ReIndexTaskArgs): Ident =
args.collective match {
case Some(cid) =>
cid / DocspellSystem.migrationTaskTracker
cid.valueAsIdent / DocspellSystem.migrationTaskTracker
case None =>
DocspellSystem.migrationTaskTracker
}

View File

@ -9,7 +9,7 @@ package docspell.common
import io.circe.generic.semiauto.{deriveDecoder, deriveEncoder}
import io.circe.{Decoder, Encoder}
final case class ScheduledAddonTaskArgs(collective: Ident, addonTaskId: Ident)
final case class ScheduledAddonTaskArgs(collective: CollectiveId, addonTaskId: Ident)
object ScheduledAddonTaskArgs {
val taskName: Ident = Ident.unsafe("addon-scheduled-task")

View File

@ -6,12 +6,12 @@
package docspell.common.bc
import docspell.common.Ident
import docspell.common.CollectiveId
trait BackendCommandRunner[F[_], A] {
def run(collective: Ident, cmd: BackendCommand): F[A]
def run(collective: CollectiveId, cmd: BackendCommand): F[A]
def runAll(collective: Ident, cmds: List[BackendCommand]): F[A]
def runAll(collective: CollectiveId, cmds: List[BackendCommand]): F[A]
}