mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-22 02:18:26 +00:00
Apply scalafmt to all files
This commit is contained in:
@ -19,9 +19,9 @@ object AccountId {
|
||||
case n if n > 0 && input.length > 2 =>
|
||||
val coll = input.substring(0, n)
|
||||
val user = input.substring(n + 1)
|
||||
Ident.fromString(coll).
|
||||
flatMap(collId => Ident.fromString(user).
|
||||
map(userId => AccountId(collId, userId)))
|
||||
Ident
|
||||
.fromString(coll)
|
||||
.flatMap(collId => Ident.fromString(user).map(userId => AccountId(collId, userId)))
|
||||
case _ =>
|
||||
invalid
|
||||
}
|
||||
|
@ -12,5 +12,4 @@ object BaseJsonCodecs {
|
||||
implicit val decodeInstantEpoch: Decoder[Instant] =
|
||||
Decoder.decodeLong.map(Instant.ofEpochMilli)
|
||||
|
||||
|
||||
}
|
||||
|
@ -21,32 +21,29 @@ object CollectiveState {
|
||||
* action. */
|
||||
case object Blocked extends CollectiveState
|
||||
|
||||
|
||||
def fromString(s: String): Either[String, CollectiveState] =
|
||||
s.toLowerCase match {
|
||||
case "active" => Right(Active)
|
||||
case "active" => Right(Active)
|
||||
case "readonly" => Right(ReadOnly)
|
||||
case "closed" => Right(Closed)
|
||||
case "blocked" => Right(Blocked)
|
||||
case _ => Left(s"Unknown state: $s")
|
||||
case "closed" => Right(Closed)
|
||||
case "blocked" => Right(Blocked)
|
||||
case _ => Left(s"Unknown state: $s")
|
||||
}
|
||||
|
||||
def unsafe(str: String): CollectiveState =
|
||||
fromString(str).fold(sys.error, identity)
|
||||
|
||||
def asString(state: CollectiveState): String = state match {
|
||||
case Active => "active"
|
||||
case Blocked => "blocked"
|
||||
case Closed => "closed"
|
||||
case Active => "active"
|
||||
case Blocked => "blocked"
|
||||
case Closed => "closed"
|
||||
case ReadOnly => "readonly"
|
||||
}
|
||||
|
||||
|
||||
|
||||
implicit val collectiveStateEncoder: Encoder[CollectiveState] =
|
||||
Encoder.encodeString.contramap(CollectiveState.asString)
|
||||
|
||||
implicit val collectiveStateDecoder: Decoder[CollectiveState] =
|
||||
Decoder.decodeString.emap(CollectiveState.fromString)
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -10,22 +10,22 @@ sealed trait ContactKind { self: Product =>
|
||||
object ContactKind {
|
||||
val all = List()
|
||||
|
||||
case object Phone extends ContactKind
|
||||
case object Mobile extends ContactKind
|
||||
case object Fax extends ContactKind
|
||||
case object Email extends ContactKind
|
||||
case object Phone extends ContactKind
|
||||
case object Mobile extends ContactKind
|
||||
case object Fax extends ContactKind
|
||||
case object Email extends ContactKind
|
||||
case object Docspell extends ContactKind
|
||||
case object Website extends ContactKind
|
||||
case object Website extends ContactKind
|
||||
|
||||
def fromString(s: String): Either[String, ContactKind] =
|
||||
s.toLowerCase match {
|
||||
case "phone" => Right(Phone)
|
||||
case "mobile" => Right(Mobile)
|
||||
case "fax" => Right(Fax)
|
||||
case "email" => Right(Email)
|
||||
case "phone" => Right(Phone)
|
||||
case "mobile" => Right(Mobile)
|
||||
case "fax" => Right(Fax)
|
||||
case "email" => Right(Email)
|
||||
case "docspell" => Right(Docspell)
|
||||
case "website" => Right(Website)
|
||||
case _ => Left(s"Not a state value: $s")
|
||||
case "website" => Right(Website)
|
||||
case _ => Left(s"Not a state value: $s")
|
||||
}
|
||||
|
||||
def unsafe(str: String): ContactKind =
|
||||
@ -34,7 +34,6 @@ object ContactKind {
|
||||
def asString(s: ContactKind): String =
|
||||
s.asString.toLowerCase
|
||||
|
||||
|
||||
implicit val contactKindEncoder: Encoder[ContactKind] =
|
||||
Encoder.encodeString.contramap(_.asString)
|
||||
|
||||
|
@ -49,6 +49,6 @@ object Duration {
|
||||
def stopTime[F[_]: Sync]: F[F[Duration]] =
|
||||
for {
|
||||
now <- Timestamp.current[F]
|
||||
end = Timestamp.current[F]
|
||||
end = Timestamp.current[F]
|
||||
} yield end.map(e => Duration.millis(e.toMillis - now.toMillis))
|
||||
}
|
||||
|
@ -10,48 +10,41 @@ sealed trait JobState { self: Product =>
|
||||
object JobState {
|
||||
|
||||
/** Waiting for being executed. */
|
||||
case object Waiting extends JobState {
|
||||
}
|
||||
case object Waiting extends JobState {}
|
||||
|
||||
/** A scheduler has picked up this job and will pass it to the next
|
||||
* free slot. */
|
||||
case object Scheduled extends JobState {
|
||||
}
|
||||
case object Scheduled extends JobState {}
|
||||
|
||||
/** Is currently executing */
|
||||
case object Running extends JobState {
|
||||
}
|
||||
case object Running extends JobState {}
|
||||
|
||||
/** Finished with failure and is being retried. */
|
||||
case object Stuck extends JobState {
|
||||
}
|
||||
case object Stuck extends JobState {}
|
||||
|
||||
/** Finished finally with a failure */
|
||||
case object Failed extends JobState {
|
||||
}
|
||||
case object Failed extends JobState {}
|
||||
|
||||
/** Finished by cancellation. */
|
||||
case object Cancelled extends JobState {
|
||||
}
|
||||
case object Cancelled extends JobState {}
|
||||
|
||||
/** Finished with success */
|
||||
case object Success extends JobState {
|
||||
}
|
||||
case object Success extends JobState {}
|
||||
|
||||
val all: Set[JobState] = Set(Waiting, Scheduled, Running, Stuck, Failed, Cancelled, Success)
|
||||
val all: Set[JobState] = Set(Waiting, Scheduled, Running, Stuck, Failed, Cancelled, Success)
|
||||
val queued: Set[JobState] = Set(Waiting, Scheduled, Stuck)
|
||||
val done: Set[JobState] = Set(Failed, Cancelled, Success)
|
||||
val done: Set[JobState] = Set(Failed, Cancelled, Success)
|
||||
|
||||
def parse(str: String): Either[String, JobState] =
|
||||
str.toLowerCase match {
|
||||
case "waiting" => Right(Waiting)
|
||||
case "waiting" => Right(Waiting)
|
||||
case "scheduled" => Right(Scheduled)
|
||||
case "running" => Right(Running)
|
||||
case "stuck" => Right(Stuck)
|
||||
case "failed" => Right(Failed)
|
||||
case "running" => Right(Running)
|
||||
case "stuck" => Right(Stuck)
|
||||
case "failed" => Right(Failed)
|
||||
case "cancelled" => Right(Cancelled)
|
||||
case "success" => Right(Success)
|
||||
case _ => Left(s"Not a job state: $str")
|
||||
case "success" => Right(Success)
|
||||
case _ => Left(s"Not a job state: $str")
|
||||
}
|
||||
|
||||
def unsafe(str: String): JobState =
|
||||
@ -60,7 +53,6 @@ object JobState {
|
||||
def asString(state: JobState): String =
|
||||
state.name
|
||||
|
||||
|
||||
implicit val jobStateEncoder: Encoder[JobState] =
|
||||
Encoder.encodeString.contramap(_.name)
|
||||
|
||||
|
@ -51,8 +51,8 @@ case class LenientUri(
|
||||
def open[F[_]: Sync]: Either[String, Resource[F, HttpURLConnection]] =
|
||||
toJavaUrl.map { url =>
|
||||
Resource
|
||||
.make(Sync[F].delay(url.openConnection().asInstanceOf[HttpURLConnection]))(
|
||||
conn => Sync[F].delay(conn.disconnect())
|
||||
.make(Sync[F].delay(url.openConnection().asInstanceOf[HttpURLConnection]))(conn =>
|
||||
Sync[F].delay(conn.disconnect())
|
||||
)
|
||||
}
|
||||
|
||||
@ -61,17 +61,16 @@ case class LenientUri(
|
||||
.emit(Either.catchNonFatal(new URL(asString)))
|
||||
.covary[F]
|
||||
.rethrow
|
||||
.flatMap(
|
||||
url => fs2.io.readInputStream(Sync[F].delay(url.openStream()), chunkSize, blocker, true)
|
||||
.flatMap(url =>
|
||||
fs2.io.readInputStream(Sync[F].delay(url.openStream()), chunkSize, blocker, true)
|
||||
)
|
||||
|
||||
def host: Option[String] =
|
||||
authority.map(
|
||||
a =>
|
||||
a.indexOf(':') match {
|
||||
case -1 => a
|
||||
case n => a.substring(0, n)
|
||||
}
|
||||
authority.map(a =>
|
||||
a.indexOf(':') match {
|
||||
case -1 => a
|
||||
case n => a.substring(0, n)
|
||||
}
|
||||
)
|
||||
|
||||
def asString: String = {
|
||||
|
@ -8,13 +8,11 @@ import io.circe.generic.semiauto._
|
||||
|
||||
case class MetaProposalList private (proposals: List[MetaProposal]) {
|
||||
|
||||
def isEmpty: Boolean = proposals.isEmpty
|
||||
def isEmpty: Boolean = proposals.isEmpty
|
||||
def nonEmpty: Boolean = proposals.nonEmpty
|
||||
|
||||
def hasResults(mt: MetaProposalType, mts: MetaProposalType*): Boolean = {
|
||||
(mts :+ mt).map(mtp => proposals.exists(_.proposalType == mtp)).
|
||||
reduce(_ && _)
|
||||
}
|
||||
def hasResults(mt: MetaProposalType, mts: MetaProposalType*): Boolean =
|
||||
(mts :+ mt).map(mtp => proposals.exists(_.proposalType == mtp)).reduce(_ && _)
|
||||
|
||||
def hasResultsAll: Boolean =
|
||||
proposals.map(_.proposalType).toSet == MetaProposalType.all.toSet
|
||||
@ -23,7 +21,7 @@ case class MetaProposalList private (proposals: List[MetaProposal]) {
|
||||
proposals.foldLeft(Set.empty[MetaProposalType])(_ + _.proposalType)
|
||||
|
||||
def fillEmptyFrom(ml: MetaProposalList): MetaProposalList = {
|
||||
val list = ml.proposals.foldLeft(proposals){ (mine, mp) =>
|
||||
val list = ml.proposals.foldLeft(proposals) { (mine, mp) =>
|
||||
if (hasResults(mp.proposalType)) mine
|
||||
else mp :: mine
|
||||
}
|
||||
@ -48,21 +46,24 @@ object MetaProposalList {
|
||||
fromSeq1(mt, refs.map(ref => Candidate(ref, Set(label))))
|
||||
|
||||
def fromSeq1(mt: MetaProposalType, refs: Seq[Candidate]): MetaProposalList =
|
||||
NonEmptyList.fromList(refs.toList).
|
||||
map(nl => MetaProposalList.of(MetaProposal(mt, nl))).
|
||||
getOrElse(empty)
|
||||
NonEmptyList
|
||||
.fromList(refs.toList)
|
||||
.map(nl => MetaProposalList.of(MetaProposal(mt, nl)))
|
||||
.getOrElse(empty)
|
||||
|
||||
def fromMap(m: Map[MetaProposalType, MetaProposal]): MetaProposalList = {
|
||||
def fromMap(m: Map[MetaProposalType, MetaProposal]): MetaProposalList =
|
||||
new MetaProposalList(m.toList.map({ case (k, v) => v.copy(proposalType = k) }))
|
||||
}
|
||||
|
||||
def flatten(ml: Seq[MetaProposalList]): MetaProposalList = {
|
||||
val init: Map[MetaProposalType, MetaProposal] = Map.empty
|
||||
|
||||
def updateMap(map: Map[MetaProposalType, MetaProposal], mp: MetaProposal): Map[MetaProposalType, MetaProposal] =
|
||||
def updateMap(
|
||||
map: Map[MetaProposalType, MetaProposal],
|
||||
mp: MetaProposal
|
||||
): Map[MetaProposalType, MetaProposal] =
|
||||
map.get(mp.proposalType) match {
|
||||
case Some(mp0) => map.updated(mp.proposalType, mp0.addIdRef(mp.values.toList))
|
||||
case None => map.updated(mp.proposalType, mp)
|
||||
case None => map.updated(mp.proposalType, mp)
|
||||
}
|
||||
|
||||
val merged = ml.foldLeft(init) { (map, el) =>
|
||||
|
@ -10,25 +10,25 @@ sealed trait MetaProposalType { self: Product =>
|
||||
|
||||
object MetaProposalType {
|
||||
|
||||
case object CorrOrg extends MetaProposalType
|
||||
case object CorrOrg extends MetaProposalType
|
||||
case object CorrPerson extends MetaProposalType
|
||||
case object ConcPerson extends MetaProposalType
|
||||
case object ConcEquip extends MetaProposalType
|
||||
case object DocDate extends MetaProposalType
|
||||
case object DueDate extends MetaProposalType
|
||||
case object ConcEquip extends MetaProposalType
|
||||
case object DocDate extends MetaProposalType
|
||||
case object DueDate extends MetaProposalType
|
||||
|
||||
val all: List[MetaProposalType] =
|
||||
List(CorrOrg, CorrPerson, ConcPerson, ConcEquip)
|
||||
|
||||
def fromString(str: String): Either[String, MetaProposalType] =
|
||||
str.toLowerCase match {
|
||||
case "corrorg" => Right(CorrOrg)
|
||||
case "corrorg" => Right(CorrOrg)
|
||||
case "corrperson" => Right(CorrPerson)
|
||||
case "concperson" => Right(ConcPerson)
|
||||
case "concequip" => Right(ConcEquip)
|
||||
case "docdate" => Right(DocDate)
|
||||
case "duedate" => Right(DueDate)
|
||||
case _ => Left(s"Invalid item-proposal-type: $str")
|
||||
case "concequip" => Right(ConcEquip)
|
||||
case "docdate" => Right(DocDate)
|
||||
case "duedate" => Right(DueDate)
|
||||
case _ => Left(s"Invalid item-proposal-type: $str")
|
||||
}
|
||||
|
||||
def unsafe(str: String): MetaProposalType =
|
||||
|
@ -11,31 +11,30 @@ sealed trait NerTag { self: Product =>
|
||||
object NerTag {
|
||||
|
||||
case object Organization extends NerTag
|
||||
case object Person extends NerTag
|
||||
case object Location extends NerTag
|
||||
case object Misc extends NerTag
|
||||
case object Email extends NerTag
|
||||
case object Website extends NerTag
|
||||
case object Date extends NerTag
|
||||
case object Person extends NerTag
|
||||
case object Location extends NerTag
|
||||
case object Misc extends NerTag
|
||||
case object Email extends NerTag
|
||||
case object Website extends NerTag
|
||||
case object Date extends NerTag
|
||||
|
||||
val all: List[NerTag] = List(Organization, Person, Location)
|
||||
|
||||
def fromString(str: String): Either[String, NerTag] =
|
||||
str.toLowerCase match {
|
||||
case "organization" => Right(Organization)
|
||||
case "person" => Right(Person)
|
||||
case "location" => Right(Location)
|
||||
case "misc" => Right(Misc)
|
||||
case "email" => Right(Email)
|
||||
case "website" => Right(Website)
|
||||
case "date" => Right(Date)
|
||||
case _ => Left(s"Invalid ner tag: $str")
|
||||
case "person" => Right(Person)
|
||||
case "location" => Right(Location)
|
||||
case "misc" => Right(Misc)
|
||||
case "email" => Right(Email)
|
||||
case "website" => Right(Website)
|
||||
case "date" => Right(Date)
|
||||
case _ => Left(s"Invalid ner tag: $str")
|
||||
}
|
||||
|
||||
def unsafe(str: String): NerTag =
|
||||
fromString(str).fold(sys.error, identity)
|
||||
|
||||
|
||||
implicit val jsonDecoder: Decoder[NerTag] =
|
||||
Decoder.decodeString.emap(fromString)
|
||||
implicit val jsonEncoder: Encoder[NerTag] =
|
||||
|
@ -24,12 +24,14 @@ object Implicits {
|
||||
ConfigReader[String].emap(reason(Ident.fromString))
|
||||
|
||||
implicit val byteVectorReader: ConfigReader[ByteVector] =
|
||||
ConfigReader[String].emap(reason(str => {
|
||||
ConfigReader[String].emap(reason { str =>
|
||||
if (str.startsWith("hex:")) ByteVector.fromHex(str.drop(4)).toRight("Invalid hex value.")
|
||||
else if (str.startsWith("b64:")) ByteVector.fromBase64(str.drop(4)).toRight("Invalid Base64 string.")
|
||||
else if (str.startsWith("b64:"))
|
||||
ByteVector.fromBase64(str.drop(4)).toRight("Invalid Base64 string.")
|
||||
else ByteVector.encodeUtf8(str).left.map(ex => s"Invalid utf8 string: ${ex.getMessage}")
|
||||
}))
|
||||
})
|
||||
|
||||
def reason[A: ClassTag](f: String => Either[String, A]): String => Either[FailureReason, A] =
|
||||
in => f(in).left.map(str => CannotConvert(in, implicitly[ClassTag[A]].runtimeClass.toString, str))
|
||||
in =>
|
||||
f(in).left.map(str => CannotConvert(in, implicitly[ClassTag[A]].runtimeClass.toString, str))
|
||||
}
|
||||
|
@ -2,9 +2,6 @@ package docspell.common
|
||||
|
||||
package object syntax {
|
||||
|
||||
object all extends EitherSyntax
|
||||
with StreamSyntax
|
||||
with StringSyntax
|
||||
with LoggerSyntax
|
||||
object all extends EitherSyntax with StreamSyntax with StringSyntax with LoggerSyntax
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user