-
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 #545 from NDLANO/new-learningpath-status
New learningpath status `READY_FOR_PUBLISHING`
- Loading branch information
Showing
50 changed files
with
820 additions
and
780 deletions.
There are no files selected for viewing
6 changes: 3 additions & 3 deletions
6
...ingpathapi/model/domain/Description.scala → ...del/domain/learningpath/Description.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
56 changes: 56 additions & 0 deletions
56
common/src/main/scala/no/ndla/common/model/domain/learningpath/LearningPath.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,56 @@ | ||
/* | ||
* Part of NDLA common | ||
* Copyright (C) 2024 NDLA | ||
* | ||
* See LICENSE | ||
* | ||
*/ | ||
|
||
package no.ndla.common.model.domain.learningpath | ||
|
||
import io.circe.generic.semiauto.{deriveDecoder, deriveEncoder} | ||
import io.circe.{Decoder, Encoder} | ||
import no.ndla.common.model.NDLADate | ||
import no.ndla.common.model.domain.{Content, Tag, Title} | ||
import no.ndla.language.Language.getSupportedLanguages | ||
|
||
case class LearningPath( | ||
id: Option[Long], | ||
revision: Option[Int], | ||
externalId: Option[String], | ||
isBasedOn: Option[Long], | ||
title: Seq[Title], | ||
description: Seq[Description], | ||
coverPhotoId: Option[String], | ||
duration: Option[Int], | ||
status: LearningPathStatus, | ||
verificationStatus: LearningPathVerificationStatus, | ||
lastUpdated: NDLADate, | ||
tags: Seq[Tag], | ||
owner: String, | ||
copyright: LearningpathCopyright, | ||
learningsteps: Option[Seq[LearningStep]] = None, | ||
message: Option[Message] = None | ||
) extends Content { | ||
|
||
def supportedLanguages: Seq[String] = { | ||
val stepLanguages = learningsteps.getOrElse(Seq.empty).flatMap(_.supportedLanguages) | ||
|
||
(getSupportedLanguages( | ||
title, | ||
description, | ||
tags | ||
) ++ stepLanguages).distinct | ||
} | ||
|
||
def isPrivate: Boolean = status == LearningPathStatus.PRIVATE | ||
def isPublished: Boolean = status == LearningPathStatus.PUBLISHED | ||
def isDeleted: Boolean = status == LearningPathStatus.DELETED | ||
|
||
} | ||
|
||
object LearningPath { | ||
implicit val encoder: Encoder[LearningPath] = deriveEncoder | ||
implicit val decoder: Decoder[LearningPath] = deriveDecoder | ||
|
||
} |
48 changes: 48 additions & 0 deletions
48
common/src/main/scala/no/ndla/common/model/domain/learningpath/LearningPathStatus.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,48 @@ | ||
/* | ||
* Part of NDLA common | ||
* Copyright (C) 2024 NDLA | ||
* | ||
* See LICENSE | ||
* | ||
*/ | ||
|
||
package no.ndla.common.model.domain.learningpath | ||
|
||
import enumeratum.* | ||
import no.ndla.common.errors.{ValidationException, ValidationMessage} | ||
|
||
import scala.util.{Failure, Success, Try} | ||
|
||
sealed trait LearningPathStatus extends EnumEntry {} | ||
object LearningPathStatus extends Enum[LearningPathStatus] with CirceEnum[LearningPathStatus] { | ||
|
||
case object PUBLISHED extends LearningPathStatus | ||
case object PRIVATE extends LearningPathStatus | ||
case object DELETED extends LearningPathStatus | ||
case object UNLISTED extends LearningPathStatus | ||
case object SUBMITTED extends LearningPathStatus | ||
case object READY_FOR_SHARING extends LearningPathStatus | ||
|
||
override def values: IndexedSeq[LearningPathStatus] = findValues | ||
|
||
def valueOf(s: String): Option[LearningPathStatus] = { | ||
LearningPathStatus.values.find(_.toString == s.toUpperCase) | ||
} | ||
|
||
def valueOfOrError(status: String): Try[LearningPathStatus] = { | ||
valueOf(status) match { | ||
case Some(status) => Success(status) | ||
case None => | ||
Failure( | ||
new ValidationException( | ||
errors = List(ValidationMessage("status", s"'$status' is not a valid publishingstatus.")) | ||
) | ||
) | ||
} | ||
|
||
} | ||
|
||
def valueOfOrDefault(s: String): LearningPathStatus = { | ||
valueOf(s).getOrElse(LearningPathStatus.PRIVATE) | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
.../main/scala/no/ndla/common/model/domain/learningpath/LearningPathVerificationStatus.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.learningpath | ||
|
||
import enumeratum.* | ||
|
||
sealed trait LearningPathVerificationStatus extends EnumEntry {} | ||
object LearningPathVerificationStatus | ||
extends Enum[LearningPathVerificationStatus] | ||
with CirceEnum[LearningPathVerificationStatus] { | ||
|
||
case object EXTERNAL extends LearningPathVerificationStatus | ||
case object CREATED_BY_NDLA extends LearningPathVerificationStatus | ||
case object VERIFIED_BY_NDLA extends LearningPathVerificationStatus | ||
|
||
override def values: IndexedSeq[LearningPathVerificationStatus] = findValues | ||
|
||
def valueOf(s: String): Option[LearningPathVerificationStatus] = { | ||
LearningPathVerificationStatus.values.find(_.toString == s.toUpperCase) | ||
} | ||
|
||
def valueOfOrDefault(s: String): LearningPathVerificationStatus = { | ||
valueOf(s).getOrElse(LearningPathVerificationStatus.EXTERNAL) | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
common/src/main/scala/no/ndla/common/model/domain/learningpath/LearningStep.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,42 @@ | ||
/* | ||
* Part of NDLA common | ||
* Copyright (C) 2024 NDLA | ||
* | ||
* See LICENSE | ||
* | ||
*/ | ||
|
||
package no.ndla.common.model.domain.learningpath | ||
|
||
import io.circe.generic.semiauto.{deriveDecoder, deriveEncoder} | ||
import io.circe.{Decoder, Encoder} | ||
import no.ndla.common.model.domain.Title | ||
import no.ndla.language.Language.getSupportedLanguages | ||
|
||
case class LearningStep( | ||
id: Option[Long], | ||
revision: Option[Int], | ||
externalId: Option[String], | ||
learningPathId: Option[Long], | ||
seqNo: Int, | ||
title: Seq[Title], | ||
description: Seq[Description], | ||
embedUrl: Seq[EmbedUrl], | ||
`type`: StepType, | ||
license: Option[String], | ||
showTitle: Boolean = false, | ||
status: StepStatus = StepStatus.ACTIVE | ||
) { | ||
def supportedLanguages: Seq[String] = { | ||
getSupportedLanguages( | ||
title, | ||
description, | ||
embedUrl | ||
) | ||
} | ||
} | ||
|
||
object LearningStep { | ||
implicit val encoder: Encoder[LearningStep] = deriveEncoder | ||
implicit val decoder: Decoder[LearningStep] = deriveDecoder | ||
} |
7 changes: 4 additions & 3 deletions
7
...earningpathapi/model/domain/Message.scala → ...n/model/domain/learningpath/Message.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
33 changes: 33 additions & 0 deletions
33
common/src/main/scala/no/ndla/common/model/domain/learningpath/StepStatus.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,33 @@ | ||
/* | ||
* Part of NDLA common | ||
* Copyright (C) 2024 NDLA | ||
* | ||
* See LICENSE | ||
* | ||
*/ | ||
|
||
package no.ndla.common.model.domain.learningpath | ||
|
||
import enumeratum.* | ||
import no.ndla.common.errors.{ValidationException, ValidationMessage} | ||
|
||
sealed abstract class StepStatus(override val entryName: String) extends EnumEntry | ||
object StepStatus extends Enum[StepStatus] with CirceEnum[StepStatus] { | ||
|
||
case object ACTIVE extends StepStatus("ACTIVE") | ||
case object DELETED extends StepStatus("DELETED") | ||
|
||
def values: IndexedSeq[StepStatus] = findValues | ||
|
||
def valueOf(s: String): Option[StepStatus] = { | ||
StepStatus.values.find(_.entryName == s) | ||
} | ||
|
||
def valueOfOrError(status: String): StepStatus = { | ||
valueOf(status) match { | ||
case Some(s) => s | ||
case None => | ||
throw new ValidationException(errors = List(ValidationMessage("status", s"'$status' is not a valid status."))) | ||
} | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
common/src/main/scala/no/ndla/common/model/domain/learningpath/StepType.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,36 @@ | ||
/* | ||
* Part of NDLA common | ||
* Copyright (C) 2024 NDLA | ||
* | ||
* See LICENSE | ||
* | ||
*/ | ||
|
||
package no.ndla.common.model.domain.learningpath | ||
|
||
import enumeratum.* | ||
import no.ndla.common.errors.{ValidationException, ValidationMessage} | ||
|
||
sealed trait StepType extends EnumEntry | ||
object StepType extends Enum[StepType] with CirceEnum[StepType] { | ||
case object INTRODUCTION extends StepType | ||
case object TEXT extends StepType | ||
case object QUIZ extends StepType | ||
case object TASK extends StepType | ||
case object MULTIMEDIA extends StepType | ||
case object SUMMARY extends StepType | ||
case object TEST extends StepType | ||
|
||
def valueOf(s: String): Option[StepType] = StepType.values.find(_.toString == s) | ||
def valueOfOrDefault(s: String): StepType = valueOf(s).getOrElse(StepType.TEXT) | ||
|
||
def valueOfOrError(s: String): StepType = { | ||
valueOf(s) match { | ||
case Some(stepType) => stepType | ||
case None => | ||
throw new ValidationException(errors = List(ValidationMessage("type", s"'$s' is not a valid steptype."))) | ||
} | ||
} | ||
|
||
override def values: IndexedSeq[StepType] = findValues | ||
} |
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.