diff --git a/modules/backend/src/main/scala/docspell/backend/ops/OItem.scala b/modules/backend/src/main/scala/docspell/backend/ops/OItem.scala index ff27b29a..65c00771 100644 --- a/modules/backend/src/main/scala/docspell/backend/ops/OItem.scala +++ b/modules/backend/src/main/scala/docspell/backend/ops/OItem.scala @@ -152,6 +152,12 @@ trait OItem[F[_]] { notifyJoex: Boolean ): F[UpdateResult] + def reprocessAll( + items: NonEmptyList[Ident], + account: AccountId, + notifyJoex: Boolean + ): F[UpdateResult] + /** Submits a task that finds all non-converted pdfs and triggers * converting them using ocrmypdf. Each file is converted by a * separate task. @@ -587,6 +593,20 @@ object OItem { _ <- OptionT.liftF(if (notifyJoex) joex.notifyAllNodes else ().pure[F]) } yield UpdateResult.success).getOrElse(UpdateResult.notFound) + def reprocessAll( + items: NonEmptyList[Ident], + account: AccountId, + notifyJoex: Boolean + ): F[UpdateResult] = + UpdateResult.fromUpdate(for { + items <- store.transact(RItem.filterItems(items, account.collective)) + jobs <- items + .map(item => ReProcessItemArgs(item, Nil)) + .traverse(arg => JobFactory.reprocessItem[F](arg, account, Priority.Low)) + _ <- queue.insertAllIfNew(jobs) + _ <- if (notifyJoex) joex.notifyAllNodes else ().pure[F] + } yield items.size) + def convertAllPdf( collective: Option[Ident], account: AccountId, diff --git a/modules/restapi/src/main/resources/docspell-openapi.yml b/modules/restapi/src/main/resources/docspell-openapi.yml index 9a051e7e..2eabe73f 100644 --- a/modules/restapi/src/main/resources/docspell-openapi.yml +++ b/modules/restapi/src/main/resources/docspell-openapi.yml @@ -2225,6 +2225,31 @@ paths: schema: $ref: "#/components/schemas/BasicResult" + /sec/items/reprocess: + post: + tags: + - Item (Multi Edit) + summary: Submit multiple items to re-processing + description: | + Given a list of item-ids, submits all these items for + reprocessing. All attachments of these items will be + reprocessed. Item metadata is not changed. + security: + - authTokenHeader: [] + requestBody: + content: + application/json: + schema: + $ref: "#/components/schemas/IdList" + + responses: + 200: + description: Ok + content: + application/json: + schema: + $ref: "#/components/schemas/BasicResult" + /sec/attachment/{id}: delete: diff --git a/modules/restserver/src/main/scala/docspell/restserver/routes/ItemMultiRoutes.scala b/modules/restserver/src/main/scala/docspell/restserver/routes/ItemMultiRoutes.scala index 860db77d..9865e71f 100644 --- a/modules/restserver/src/main/scala/docspell/restserver/routes/ItemMultiRoutes.scala +++ b/modules/restserver/src/main/scala/docspell/restserver/routes/ItemMultiRoutes.scala @@ -149,14 +149,13 @@ object ItemMultiRoutes { resp <- Ok(Conversions.basicResult(res, "Concerned equipment updated")) } yield resp - // case req @ POST -> Root / "reprocess" => - // for { - // data <- req.as[IdList] - // ids = data.ids.flatMap(s => Ident.fromString(s).toOption) - // _ <- logger.fdebug(s"Re-process item ${id.id}") - // res <- backend.item.reprocess(id, ids, user.account, true) - // resp <- Ok(Conversions.basicResult(res, "Re-process task submitted.")) - // } yield resp + case req @ POST -> Root / "reprocess" => + for { + json <- req.as[IdList] + items <- readIds[F](json.ids) + res <- backend.item.reprocessAll(items, user.account, true) + resp <- Ok(Conversions.basicResult(res, "Re-process task(s) submitted.")) + } yield resp // case POST -> Root / "deleteAll" => // for { diff --git a/modules/webapp/src/main/elm/Comp/ItemDetail/FormChange.elm b/modules/webapp/src/main/elm/Comp/ItemDetail/FormChange.elm index c6dc36dc..7d9c1c85 100644 --- a/modules/webapp/src/main/elm/Comp/ItemDetail/FormChange.elm +++ b/modules/webapp/src/main/elm/Comp/ItemDetail/FormChange.elm @@ -114,5 +114,5 @@ multiUpdate flags ids change receive = in Api.setConcEquipmentMultiple flags data receive - _ -> + NoFormChange -> Cmd.none