diff options
author | Kseniya Tomskikh <ktomskih@datamonsters.co> | 2017-10-20 16:25:04 +0700 |
---|---|---|
committer | Kseniya Tomskikh <ktomskih@datamonsters.co> | 2017-10-20 16:25:04 +0700 |
commit | 54b15dae509212f6661dc1f1bc4ca248cb487443 (patch) | |
tree | 85b1ceafd9a56da511513797bd263977f52b556c /src/main/scala/xyz/driver/pdsuidomain/formats/json/extracteddata | |
parent | 6d6e732368e97e319653f00e498189afceeb4671 (diff) | |
download | rest-query-54b15dae509212f6661dc1f1bc4ca248cb487443.tar.gz rest-query-54b15dae509212f6661dc1f1bc4ca248cb487443.tar.bz2 rest-query-54b15dae509212f6661dc1f1bc4ca248cb487443.zip |
PDSUI-2336 Deleted api classes of play format, userhistory and message services
Diffstat (limited to 'src/main/scala/xyz/driver/pdsuidomain/formats/json/extracteddata')
2 files changed, 0 insertions, 144 deletions
diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/extracteddata/ApiExtractedData.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/extracteddata/ApiExtractedData.scala deleted file mode 100644 index 4182c8d..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/extracteddata/ApiExtractedData.scala +++ /dev/null @@ -1,64 +0,0 @@ -package xyz.driver.pdsuidomain.formats.json.extracteddata - -import xyz.driver.pdsuicommon.domain.{LongId, TextJson} -import xyz.driver.pdsuidomain.entities.ExtractedData -import xyz.driver.pdsuidomain.formats.json.label.ApiExtractedDataLabel -import play.api.libs.json._ -import play.api.data.validation._ -import play.api.libs.functional.syntax._ -import xyz.driver.pdsuicommon.json.JsonSerializer -import xyz.driver.pdsuidomain.services.ExtractedDataService.RichExtractedData - -// The specification: https://driverinc.atlassian.net/wiki/pages/viewpage.action?pageId=33423387 -// Note, that there is "Extracted data object or Temporary extracted data object" in specification -// ApiExtractedData represents both types -final case class ApiExtractedData(id: Long, - documentId: Long, - keywordId: Option[Long], - evidence: Option[String], - meta: Option[String], - // An empty list and no-existent list are different cases - labels: Option[List[ApiExtractedDataLabel]]) { - - def toDomain = RichExtractedData( - extractedData = ExtractedData( - id = LongId(this.id), - documentId = LongId(this.documentId), - keywordId = this.keywordId.map(LongId(_)), - evidenceText = this.evidence, - meta = this.meta.map(x => TextJson(JsonSerializer.deserialize[ExtractedData.Meta](x))) - ), - labels = labels.getOrElse(List.empty).map(_.toDomain()) - ) - -} - -object ApiExtractedData { - - implicit val format: Format[ApiExtractedData] = ( - (JsPath \ "id").format[Long] and - (JsPath \ "documentId").format[Long] and - (JsPath \ "keywordId").formatNullable[Long] and - (JsPath \ "evidence").formatNullable[String] and - (JsPath \ "meta").formatNullable[String] and - (JsPath \ "labels").formatNullable[List[ApiExtractedDataLabel]]( - Format( - Reads - .of[List[ApiExtractedDataLabel]] - .filter(ValidationError("empty labels"))({ - case x if x.nonEmpty => true - case _ => false - }), - Writes.of[List[ApiExtractedDataLabel]] - )) - )(ApiExtractedData.apply, unlift(ApiExtractedData.unapply)) - - def fromDomain(extractedDataWithLabels: RichExtractedData) = ApiExtractedData( - id = extractedDataWithLabels.extractedData.id.id, - documentId = extractedDataWithLabels.extractedData.documentId.id, - keywordId = extractedDataWithLabels.extractedData.keywordId.map(_.id), - evidence = extractedDataWithLabels.extractedData.evidenceText, - meta = extractedDataWithLabels.extractedData.meta.map(x => JsonSerializer.serialize(x.content)), - labels = Option(extractedDataWithLabels.labels.map(ApiExtractedDataLabel.fromDomain)) - ) -} diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/extracteddata/ApiPartialExtractedData.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/extracteddata/ApiPartialExtractedData.scala deleted file mode 100644 index cfd55fd..0000000 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/extracteddata/ApiPartialExtractedData.scala +++ /dev/null @@ -1,80 +0,0 @@ -package xyz.driver.pdsuidomain.formats.json.extracteddata - -import xyz.driver.pdsuicommon.domain.{LongId, TextJson} -import xyz.driver.pdsuidomain.entities.ExtractedData.Meta -import xyz.driver.pdsuidomain.entities._ -import org.davidbild.tristate.Tristate -import org.davidbild.tristate.contrib.play.ToJsPathOpsFromJsPath -import play.api.data.validation._ -import play.api.libs.functional.syntax._ -import play.api.libs.json._ -import xyz.driver.pdsuicommon.json.{JsonSerializer, JsonValidationException} -import xyz.driver.pdsuicommon.validation.{AdditionalConstraints, JsonValidationErrors} -import xyz.driver.pdsuidomain.formats.json.label.ApiExtractedDataLabel -import xyz.driver.pdsuidomain.services.ExtractedDataService.RichExtractedData - -import scala.collection._ - -final case class ApiPartialExtractedData(documentId: Option[Long], - keywordId: Option[Long], - evidence: Tristate[String], - meta: Tristate[String], - labels: Tristate[List[ApiExtractedDataLabel]]) { - - def applyTo(orig: RichExtractedData): RichExtractedData = RichExtractedData( - extractedData = applyTo(orig.extractedData), - labels = labels.cata(_.map(_.toDomain(orig.extractedData.id)), List.empty, orig.labels) - ) - - private def applyTo(orig: ExtractedData): ExtractedData = ExtractedData( - id = orig.id, - documentId = orig.documentId, - keywordId = keywordId.map(LongId[Keyword]).orElse(orig.keywordId), - evidenceText = evidence.cata(Some(_), None, orig.evidenceText), - meta = meta.map(x => TextJson(JsonSerializer.deserialize[Meta](x))).cata(Some(_), None, orig.meta) - ) - - def toDomain: RichExtractedData = { - val validation = Map( - JsPath \ "documentId" -> AdditionalConstraints.optionNonEmptyConstraint(documentId) - ) - - val validationErrors: JsonValidationErrors = validation.collect({ - case (fieldName, e: Invalid) => (fieldName, e.errors) - })(breakOut) - - if (validationErrors.isEmpty) { - val extractedData = ExtractedData( - documentId = documentId.map(LongId[Document]).get, - keywordId = keywordId.map(LongId[Keyword]), - evidenceText = evidence.toOption, - meta = meta.map(x => TextJson(JsonSerializer.deserialize[Meta](x))).toOption - ) - val labelList = labels.map(_.map(_.toDomain())) - RichExtractedData(extractedData, labelList.getOrElse(List.empty)) - } else { - throw new JsonValidationException(validationErrors) - } - } -} - -object ApiPartialExtractedData { - - private val reads: Reads[ApiPartialExtractedData] = ( - (JsPath \ "documentId").readNullable[Long] and - (JsPath \ "keywordId").readNullable[Long] and - (JsPath \ "evidence").readTristate[String] and - (JsPath \ "meta").readTristate[String] and - (JsPath \ "labels").readTristate[List[ApiExtractedDataLabel]] - )(ApiPartialExtractedData.apply _) - - private val writes: Writes[ApiPartialExtractedData] = ( - (JsPath \ "documentId").writeNullable[Long] and - (JsPath \ "keywordId").writeNullable[Long] and - (JsPath \ "evidence").writeTristate[String] and - (JsPath \ "meta").writeTristate[String] and - (JsPath \ "labels").writeTristate[List[ApiExtractedDataLabel]] - )(unlift(ApiPartialExtractedData.unapply)) - - implicit val format: Format[ApiPartialExtractedData] = Format(reads, writes) -} |