Skip to content

Commit

Permalink
Fixes #12908: Integrate plugin-common Trait into rudder
Browse files Browse the repository at this point in the history
  • Loading branch information
VinceMacBuche committed Jul 6, 2018
1 parent eea6aed commit b5b8ddf
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 133 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -948,47 +948,47 @@ case class RestExtractorService (
}
}

def extractInt[T](key : String) (req : Req)(fun : BigInt => Box[T]) : Box[Option[T]] = {
req.json match {
case Full(json) => json \ key match {
case JInt(value) => fun(value).map(Some(_))
case JNothing => Full(None)
case x => Failure(s"Not a valid value for '${key}' parameter, current value is : ${x}")
}
case _ =>
req.params.get(key) match {
case None => Full(None)
case Some(head :: Nil) => try {
fun(head.toLong).map(Some(_))
} catch {
case e : Throwable =>
Failure(s"Parsing request parameter '${key}' as an integer failed, current value is '${head}'. Error message is: '${e.getMessage}'.")
}
case Some(list) => Failure(s"${list.size} values defined for 'id' parameter, only one needs to be defined")
}
}
}
def extractInt[T](key : String) (req : Req)(fun : BigInt => Box[T]) : Box[Option[T]] = {
req.json match {
case Full(json) => json \ key match {
case JInt(value) => fun(value).map(Some(_))
case JNothing => Full(None)
case x => Failure(s"Not a valid value for '${key}' parameter, current value is : ${x}")
}
case _ =>
req.params.get(key) match {
case None => Full(None)
case Some(head :: Nil) => try {
fun(head.toLong).map(Some(_))
} catch {
case e : Throwable =>
Failure(s"Parsing request parameter '${key}' as an integer failed, current value is '${head}'. Error message is: '${e.getMessage}'.")
}
case Some(list) => Failure(s"${list.size} values defined for 'id' parameter, only one needs to be defined")
}
}
}

def extractBoolean[T](key : String) (req : Req)(fun : Boolean => T) : Box[Option[T]] = {
req.json match {
case Full(json) => json \ key match {
case JBool(value) => Full(Some(fun(value)))
case JNothing => Full(None)
case x => Failure(s"Not a valid value for '${key}' parameter, current value is : ${x}")
}
case _ =>
req.params.get(key) match {
case None => Full(None)
case Some(head :: Nil) => try {
Full(Some(fun(head.toBoolean)))
} catch {
case e : Throwable =>
Failure(s"Parsing request parameter '${key}' as a boolean failed, current value is '${head}'. Error message is: '${e.getMessage}'.")
}
case Some(list) => Failure(s"${list.size} values defined for 'id' parameter, only one needs to be defined")
}
}
}
def extractBoolean[T](key : String) (req : Req)(fun : Boolean => T) : Box[Option[T]] = {
req.json match {
case Full(json) => json \ key match {
case JBool(value) => Full(Some(fun(value)))
case JNothing => Full(None)
case x => Failure(s"Not a valid value for '${key}' parameter, current value is : ${x}")
}
case _ =>
req.params.get(key) match {
case None => Full(None)
case Some(head :: Nil) => try {
Full(Some(fun(head.toBoolean)))
} catch {
case e : Throwable =>
Failure(s"Parsing request parameter '${key}' as a boolean failed, current value is '${head}'. Error message is: '${e.getMessage}'.")
}
case Some(list) => Failure(s"${list.size} values defined for 'id' parameter, only one needs to be defined")
}
}
}

def extractMap[T,U](key : String)(req : Req)
( keyFun : String => T
Expand Down

This file was deleted.

0 comments on commit b5b8ddf

Please sign in to comment.