Update state and proposals only on invalid items

Invalid items are those that are not ready, and not shown to the user.
When changing metadata, it should only be changed, if the item was not
already shown to the user.
This commit is contained in:
Eike Kettner
2020-05-23 15:46:24 +02:00
parent 855d4eefa8
commit 25d089da6c
6 changed files with 48 additions and 23 deletions

View File

@ -1,11 +1,18 @@
package docspell.common
import io.circe.{Decoder, Encoder}
import cats.data.NonEmptyList
sealed trait ItemState { self: Product =>
final def name: String =
productPrefix.toLowerCase
def isValid: Boolean =
ItemState.validStates.exists(_ == this)
def isInvalid: Boolean =
ItemState.invalidStates.exists(_ == this)
}
object ItemState {
@ -24,8 +31,11 @@ object ItemState {
case _ => Left(s"Invalid item state: $str")
}
val validStates: Seq[ItemState] =
Seq(Created, Confirmed)
val validStates: NonEmptyList[ItemState] =
NonEmptyList.of(Created, Confirmed)
val invalidStates: NonEmptyList[ItemState] =
NonEmptyList.of(Premature, Processing)
def unsafe(str: String): ItemState =
fromString(str).fold(sys.error, identity)