-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #451 from NDLANO/concept-index
search-api: Index concepts from concept-api
- Loading branch information
Showing
92 changed files
with
1,748 additions
and
687 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
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
44 changes: 44 additions & 0 deletions
44
common/src/main/scala/no/ndla/common/model/domain/concept/Concept.scala
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,44 @@ | ||
/* | ||
* Part of NDLA common | ||
* Copyright (C) 2024 NDLA | ||
* | ||
* See LICENSE | ||
*/ | ||
|
||
package no.ndla.common.model.domain.concept | ||
|
||
import io.circe.generic.semiauto.{deriveDecoder, deriveEncoder} | ||
import io.circe.{Decoder, Encoder} | ||
import no.ndla.common.model.NDLADate | ||
import no.ndla.common.model.domain.draft.DraftCopyright | ||
import no.ndla.common.model.domain.{Content, Responsible, Tag, Title} | ||
import no.ndla.language.Language.getSupportedLanguages | ||
|
||
case class Concept( | ||
id: Option[Long], | ||
revision: Option[Int], | ||
title: Seq[Title], | ||
content: Seq[ConceptContent], | ||
copyright: Option[DraftCopyright], | ||
created: NDLADate, | ||
updated: NDLADate, | ||
updatedBy: Seq[String], | ||
metaImage: Seq[ConceptMetaImage], | ||
tags: Seq[Tag], | ||
subjectIds: Set[String], | ||
articleIds: Seq[Long], | ||
status: Status, | ||
visualElement: Seq[VisualElement], | ||
responsible: Option[Responsible], | ||
conceptType: ConceptType, | ||
glossData: Option[GlossData], | ||
editorNotes: Seq[ConceptEditorNote] | ||
) extends Content { | ||
def supportedLanguages: Set[String] = | ||
getSupportedLanguages(title, content, tags, visualElement, metaImage).toSet | ||
} | ||
|
||
object Concept { | ||
implicit val encoder: Encoder[Concept] = deriveEncoder | ||
implicit val decoder: Decoder[Concept] = deriveDecoder | ||
} |
8 changes: 4 additions & 4 deletions
8
...ceptapi/model/domain/ConceptContent.scala → ...model/domain/concept/ConceptContent.scala
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
25 changes: 25 additions & 0 deletions
25
common/src/main/scala/no/ndla/common/model/domain/concept/ConceptEditorNote.scala
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 @@ | ||
/* | ||
* Part of NDLA common. | ||
* Copyright (C) 2024 NDLA | ||
* | ||
* See LICENSE | ||
* | ||
*/ | ||
|
||
package no.ndla.common.model.domain.concept | ||
|
||
import no.ndla.common.model.NDLADate | ||
import io.circe.{Encoder, Decoder} | ||
import io.circe.generic.semiauto.{deriveDecoder, deriveEncoder} | ||
|
||
case class ConceptEditorNote( | ||
note: String, | ||
user: String, | ||
status: Status, | ||
timestamp: NDLADate | ||
) | ||
|
||
object ConceptEditorNote { | ||
implicit val encoder: Encoder[ConceptEditorNote] = deriveEncoder | ||
implicit val decoder: Decoder[ConceptEditorNote] = deriveDecoder | ||
} |
6 changes: 3 additions & 3 deletions
6
...ptapi/model/domain/ConceptMetaImage.scala → ...del/domain/concept/ConceptMetaImage.scala
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
50 changes: 50 additions & 0 deletions
50
common/src/main/scala/no/ndla/common/model/domain/concept/ConceptStatus.scala
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,50 @@ | ||
/* | ||
* Part of NDLA common | ||
* Copyright (C) 2024 NDLA | ||
* | ||
* See LICENSE | ||
*/ | ||
|
||
package no.ndla.common.model.domain.concept | ||
|
||
import enumeratum.* | ||
import no.ndla.common.errors.ValidationException | ||
|
||
import scala.util.{Failure, Success, Try} | ||
|
||
sealed trait ConceptStatus extends EnumEntry {} | ||
object ConceptStatus extends Enum[ConceptStatus] with CirceEnum[ConceptStatus] { | ||
case object IN_PROGRESS extends ConceptStatus | ||
case object EXTERNAL_REVIEW extends ConceptStatus | ||
case object INTERNAL_REVIEW extends ConceptStatus | ||
case object QUALITY_ASSURANCE extends ConceptStatus | ||
case object LANGUAGE extends ConceptStatus | ||
case object FOR_APPROVAL extends ConceptStatus | ||
case object END_CONTROL extends ConceptStatus | ||
case object PUBLISHED extends ConceptStatus | ||
case object UNPUBLISHED extends ConceptStatus | ||
case object ARCHIVED extends ConceptStatus | ||
|
||
val values: IndexedSeq[ConceptStatus] = findValues | ||
|
||
def valueOfOrError(s: String): Try[ConceptStatus] = | ||
valueOf(s) match { | ||
case Some(st) => Success(st) | ||
case None => | ||
val validStatuses = values.map(_.toString).mkString(", ") | ||
Failure( | ||
ValidationException( | ||
"status", | ||
s"'$s' is not a valid concept status. Must be one of $validStatuses" | ||
) | ||
) | ||
} | ||
|
||
def valueOf(s: String): Option[ConceptStatus] = values.find(_.toString == s.toUpperCase) | ||
|
||
val thatDoesNotRequireResponsible: Seq[ConceptStatus] = Seq(PUBLISHED, UNPUBLISHED, ARCHIVED) | ||
val thatRequiresResponsible: Set[ConceptStatus] = this.values.filterNot(thatDoesNotRequireResponsible.contains).toSet | ||
|
||
implicit def ordering[A <: ConceptStatus]: Ordering[ConceptStatus] = | ||
(x: ConceptStatus, y: ConceptStatus) => indexOf(x) - indexOf(y) | ||
} |
37 changes: 37 additions & 0 deletions
37
common/src/main/scala/no/ndla/common/model/domain/concept/ConceptType.scala
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,37 @@ | ||
/* | ||
* Part of NDLA common | ||
* Copyright (C) 2024 NDLA | ||
* | ||
* See LICENSE | ||
*/ | ||
|
||
package no.ndla.common.model.domain.concept | ||
|
||
import enumeratum.* | ||
import no.ndla.common.CirceUtil.CirceEnumWithErrors | ||
import no.ndla.common.errors.InvalidStatusException | ||
|
||
import scala.util.{Failure, Success, Try} | ||
|
||
sealed abstract class ConceptType(override val entryName: String) extends EnumEntry { | ||
override def toString: String = entryName | ||
} | ||
|
||
object ConceptType extends Enum[ConceptType] with CirceEnumWithErrors[ConceptType] { | ||
case object CONCEPT extends ConceptType("concept") | ||
case object GLOSS extends ConceptType("gloss") | ||
|
||
def all: Seq[String] = ConceptType.values.map(_.toString) | ||
def valueOf(s: String): Option[ConceptType] = ConceptType.values.find(_.toString == s) | ||
def valueOf(s: Option[String]): Option[ConceptType] = s.flatMap(valueOf) | ||
|
||
def valueOfOrError(s: String): Try[ConceptType] = { | ||
valueOf(s) match { | ||
case None => | ||
Failure(InvalidStatusException(s"'$s' is not a valid concept type. Valid options are ${all.mkString(", ")}.")) | ||
case Some(conceptType) => Success(conceptType) | ||
} | ||
} | ||
|
||
override def values: IndexedSeq[ConceptType] = findValues | ||
} |
6 changes: 3 additions & 3 deletions
6
.../conceptapi/model/domain/EditorNote.scala → ...mon/model/domain/concept/EditorNote.scala
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
31 changes: 31 additions & 0 deletions
31
common/src/main/scala/no/ndla/common/model/domain/concept/Gloss.scala
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,31 @@ | ||
/* | ||
* Part of NDLA common | ||
* Copyright (C) 2024 NDLA | ||
* | ||
* See LICENSE | ||
*/ | ||
|
||
package no.ndla.common.model.domain.concept | ||
|
||
import io.circe.generic.semiauto.{deriveDecoder, deriveEncoder} | ||
import io.circe.{Decoder, Encoder} | ||
|
||
case class GlossExample(example: String, language: String, transcriptions: Map[String, String]) | ||
|
||
object GlossExample { | ||
implicit val encoder: Encoder[GlossExample] = deriveEncoder | ||
implicit val decoder: Decoder[GlossExample] = deriveDecoder | ||
} | ||
|
||
case class GlossData( | ||
gloss: String, | ||
wordClass: WordClass, | ||
originalLanguage: String, | ||
transcriptions: Map[String, String], | ||
examples: List[List[GlossExample]] | ||
) | ||
|
||
object GlossData { | ||
implicit val encoder: Encoder[GlossData] = deriveEncoder | ||
implicit val decoder: Decoder[GlossData] = deriveDecoder | ||
} |
6 changes: 3 additions & 3 deletions
6
...ndla/conceptapi/model/domain/Status.scala → .../common/model/domain/concept/Status.scala
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
6 changes: 3 additions & 3 deletions
6
...nceptapi/model/domain/VisualElement.scala → .../model/domain/concept/VisualElement.scala
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
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
Oops, something went wrong.