-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
28 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package org.elastic4play.models | ||
|
||
import play.api.libs.json.{ JsString, JsValue } | ||
|
||
import com.sksamuel.elastic4s.ElasticDsl.binaryField | ||
import com.sksamuel.elastic4s.mappings.BasicFieldDefinition | ||
import org.scalactic._ | ||
|
||
import org.elastic4play.controllers.{ InputValue, JsonInputValue } | ||
import org.elastic4play.{ AttributeError, InvalidFormatAttributeError } | ||
|
||
class RawAttributeFormat extends AttributeFormat[String]("raw") { | ||
override def checkJson(subNames: Seq[String], value: JsValue): Or[JsValue, One[InvalidFormatAttributeError]] = value match { | ||
case _: JsString if subNames.isEmpty ⇒ Good(value) | ||
case _ ⇒ formatError(JsonInputValue(value)) | ||
} | ||
override def fromInputValue(subNames: Seq[String], value: InputValue): String Or Every[AttributeError] = TextAttributeFormat.fromInputValue(subNames, value) match { | ||
case Bad(One(ifae: InvalidFormatAttributeError)) ⇒ Bad(One(ifae.copy(format = name))) | ||
case other ⇒ other | ||
} | ||
|
||
override def elasticType(attributeName: String): BasicFieldDefinition = binaryField(attributeName) | ||
} | ||
|
||
object RawAttributeFormat extends RawAttributeFormat |