mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-22 02:18:26 +00:00
Adopt backend to collective-id
This commit is contained in:
@ -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
|
||||
)
|
||||
|
||||
|
@ -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] =
|
||||
|
@ -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 {
|
||||
|
||||
|
@ -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]
|
||||
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
|
@ -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 {
|
||||
|
@ -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))
|
||||
}
|
||||
|
@ -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]
|
||||
)
|
||||
|
@ -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]
|
||||
|
||||
}
|
||||
|
@ -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]
|
||||
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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")
|
||||
|
@ -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]
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user