Skip to content

Commit

Permalink
Disclaimer is optional
Browse files Browse the repository at this point in the history
  • Loading branch information
katrinewi committed Dec 16, 2024
1 parent 5cf53cc commit 65a98ed
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 36 deletions.
10 changes: 5 additions & 5 deletions article-api/src/test/scala/no/ndla/articleapi/TestData.scala
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ trait TestData {
relatedContent = Seq.empty,
revisionDate = Some(NDLADate.now().withNano(0)),
slug = None,
disclaimer = Seq.empty
disclaimer = None
)

val sampleDomainArticle: Article = Article(
Expand All @@ -179,7 +179,7 @@ trait TestData {
relatedContent = Seq.empty,
revisionDate = None,
slug = None,
disclaimer = Seq.empty
disclaimer = None
)

val sampleDomainArticle2: Article = Article(
Expand All @@ -205,7 +205,7 @@ trait TestData {
relatedContent = Seq.empty,
revisionDate = None,
slug = None,
disclaimer = Seq.empty
disclaimer = None
)

val sampleArticleWithByNcSa: Article = sampleArticleWithPublicDomain.copy(copyright = byNcSaCopyright)
Expand Down Expand Up @@ -243,7 +243,7 @@ trait TestData {
relatedContent = Seq.empty,
revisionDate = None,
slug = None,
disclaimer = Seq.empty
disclaimer = None
)

val apiArticleWithHtmlFaultV2: api.ArticleV2DTO = api.ArticleV2DTO(
Expand Down Expand Up @@ -313,7 +313,7 @@ trait TestData {
relatedContent = Seq.empty,
revisionDate = None,
slug = None,
disclaimer = Seq.empty
disclaimer = None
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ case class Article(
relatedContent: Seq[RelatedContent],
revisionDate: Option[NDLADate],
slug: Option[String],
disclaimer: Seq[Disclaimer]
disclaimer: Option[Seq[Disclaimer]]
) extends Content

object Article {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ case class Draft(
priority: Priority,
started: Boolean,
qualityEvaluation: Option[QualityEvaluation],
disclaimer: Seq[Disclaimer]
disclaimer: Option[Seq[Disclaimer]]
) extends Content {

def supportedLanguages: Seq[String] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ trait ConverterService {
val domainContent = newArticle.content
.map(content => common.ArticleContent(removeUnknownEmbedTagAttribute(content), newArticle.language))
.toSeq
val domainDisclaimer = Seq(common.Disclaimer(newArticle.disclaimer.getOrElse(""), newArticle.language))
val domainDisclaimer = newArticle.disclaimer.map { d => Seq(common.Disclaimer(d, newArticle.language)) }

val status = externalIds match {
case Nil => common.Status(PLANNED, Set.empty)
Expand Down Expand Up @@ -391,7 +391,8 @@ trait ConverterService {
val metaImage = findByLanguageOrBestEffort(article.metaImage, language).map(toApiArticleMetaImage)
val revisionMetas = article.revisionMeta.map(toApiRevisionMeta)
val responsible = article.responsible.map(toApiResponsible)
val disclaimer = findByLanguageOrBestEffort((article.disclaimer), language).map(toApiArticleDisclaimer)
val disclaimer =
article.disclaimer.flatMap { d => findByLanguageOrBestEffort(d, language).map(toApiArticleDisclaimer) }

Success(
api.ArticleDTO(
Expand Down Expand Up @@ -460,7 +461,7 @@ trait ConverterService {
def toApiArticleTitle(title: common.Title): api.ArticleTitleDTO =
api.ArticleTitleDTO(Jsoup.parseBodyFragment(title.title).body().text(), title.title, title.language)

def toApiArticleDisclaimer(disclaimer: common.Disclaimer): api.DisclaimerDTO =
private def toApiArticleDisclaimer(disclaimer: common.Disclaimer): api.DisclaimerDTO =
api.DisclaimerDTO(
disclaimer.disclaimer,
disclaimer.language
Expand Down Expand Up @@ -795,14 +796,18 @@ trait ConverterService {
.traverse(lang => articleWithNewContent.title.toSeq.map(t => toDomainTitle(api.ArticleTitleDTO(t, t, lang))))
.flatten
)
val updatedDisclaimer = mergeLanguageFields(
toMergeInto.disclaimer,
maybeLang
.traverse(lang =>
articleWithNewContent.disclaimer.toSeq.map(d => toDomainDisclaimer(api.DisclaimerDTO(d, lang)))
)
.flatten
)

val updatedDisclaimer = toMergeInto.disclaimer.map { disclaimer =>
mergeLanguageFields(
disclaimer,
maybeLang
.traverse(lang =>
articleWithNewContent.disclaimer.toSeq.map(d => toDomainDisclaimer(api.DisclaimerDTO(d, lang)))
)
.flatten
)
}

val updatedContents = mergeLanguageFields(
toMergeInto.content,
maybeLang
Expand Down Expand Up @@ -957,7 +962,7 @@ trait ConverterService {
priority = priority,
started = false,
qualityEvaluation = qualityEvaluationToDomain(article.qualityEvaluation),
disclaimer = article.disclaimer.map(d => common.Disclaimer(d, lang)).toSeq
disclaimer = article.disclaimer.map { d => Seq(common.Disclaimer(d, lang)) }
)
}

Expand Down
8 changes: 4 additions & 4 deletions draft-api/src/test/scala/no/ndla/draftapi/TestData.scala
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ object TestData {
Priority.Unspecified,
false,
None,
Seq.empty
None
)

val sampleArticleWithPublicDomain: Draft = Draft(
Expand Down Expand Up @@ -357,7 +357,7 @@ object TestData {
Priority.Unspecified,
false,
None,
Seq.empty
None
)

val sampleDomainArticle: Draft = Draft(
Expand Down Expand Up @@ -394,7 +394,7 @@ object TestData {
Priority.Unspecified,
false,
None,
Seq.empty
None
)

val newArticle: NewArticleDTO = api.NewArticleDTO(
Expand Down Expand Up @@ -485,7 +485,7 @@ object TestData {
priority = Priority.Unspecified,
started = false,
qualityEvaluation = None,
disclaimer = Seq.empty
disclaimer = None
)

val apiArticleWithHtmlFaultV2: api.ArticleDTO = api.ArticleDTO(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ class ConverterServiceTest extends UnitSuite with TestEnvironment {
priority = Priority.Unspecified,
started = false,
qualityEvaluation = None,
disclaimer = Seq(Disclaimer("Disclaimer test", "nb"))
disclaimer = Some(Seq(Disclaimer("Disclaimer test", "nb")))
)

val updatedNothing = TestData.blankUpdatedArticle.copy(
Expand Down Expand Up @@ -381,7 +381,7 @@ class ConverterServiceTest extends UnitSuite with TestEnvironment {
priority = Priority.Unspecified,
started = false,
qualityEvaluation = None,
disclaimer = Seq(Disclaimer("Disclaimer test", "nb"))
disclaimer = Some(Seq(Disclaimer("Disclaimer test", "nb")))
)

val expectedArticle = Draft(
Expand Down Expand Up @@ -416,7 +416,7 @@ class ConverterServiceTest extends UnitSuite with TestEnvironment {
priority = Priority.Unspecified,
started = false,
qualityEvaluation = None,
disclaimer = Seq(Disclaimer("NyDisclaimer test", "nb"))
disclaimer = Some(Seq(Disclaimer("NyDisclaimer test", "nb")))
)

val updatedEverything = TestData.blankUpdatedArticle.copy(
Expand Down Expand Up @@ -482,7 +482,7 @@ class ConverterServiceTest extends UnitSuite with TestEnvironment {
priority = Priority.Unspecified,
started = false,
qualityEvaluation = None,
disclaimer = Seq.empty
disclaimer = None
)

val expectedArticle = Draft(
Expand Down Expand Up @@ -525,7 +525,7 @@ class ConverterServiceTest extends UnitSuite with TestEnvironment {
priority = Priority.Unspecified,
started = false,
qualityEvaluation = None,
disclaimer = Seq.empty
disclaimer = None
)

val updatedEverything = TestData.blankUpdatedArticle.copy(
Expand Down Expand Up @@ -1127,7 +1127,7 @@ class ConverterServiceTest extends UnitSuite with TestEnvironment {
priority = Priority.Unspecified,
started = false,
qualityEvaluation = None,
disclaimer = Seq(Disclaimer("articleDisclaimer", "nb"))
disclaimer = Some(Seq(Disclaimer("articleDisclaimer", "nb")))
)
val article = common.model.domain.article.Article(
id = Some(articleId),
Expand All @@ -1153,7 +1153,7 @@ class ConverterServiceTest extends UnitSuite with TestEnvironment {
relatedContent = Seq.empty,
revisionDate = None,
slug = Some("kjempe-slug"),
disclaimer = Seq(Disclaimer("articleDisclaimer", "nb"))
disclaimer = Some(Seq(Disclaimer("articleDisclaimer", "nb")))
)

val result = service.toArticleApiArticle(draft)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ class StateTransitionRulesTest extends UnitSuite with TestEnvironment {
priority = Priority.Unspecified,
started = false,
qualityEvaluation = None,
disclaimer = Seq.empty
disclaimer = None
)
val article = common.article.Article(
id = Some(articleId),
Expand All @@ -381,7 +381,7 @@ class StateTransitionRulesTest extends UnitSuite with TestEnvironment {
relatedContent = Seq.empty,
revisionDate = None,
slug = None,
disclaimer = Seq.empty
disclaimer = None
)
val status = common.Status(END_CONTROL, Set.empty)

Expand Down Expand Up @@ -479,7 +479,7 @@ class StateTransitionRulesTest extends UnitSuite with TestEnvironment {
priority = Priority.Unspecified,
started = false,
qualityEvaluation = None,
disclaimer = Seq.empty
disclaimer = None
)
val status = common.Status(PLANNED, Set.empty)
val transitionsToTest = StateTransitionRules.StateTransitions.filter(_.to == PUBLISHED)
Expand Down Expand Up @@ -536,7 +536,7 @@ class StateTransitionRulesTest extends UnitSuite with TestEnvironment {
priority = Priority.Unspecified,
started = false,
qualityEvaluation = None,
disclaimer = Seq.empty
disclaimer = None
)
val status = common.Status(PLANNED, Set.empty)
val transitionsToTest = StateTransitionRules.StateTransitions.filter(_.to == ARCHIVED)
Expand Down Expand Up @@ -597,7 +597,7 @@ class StateTransitionRulesTest extends UnitSuite with TestEnvironment {
priority = Priority.Unspecified,
started = false,
qualityEvaluation = None,
disclaimer = Seq.empty
disclaimer = None
)
val status = common.Status(PLANNED, Set.empty)
val transitionsToTest = StateTransitionRules.StateTransitions.filter(_.to == UNPUBLISHED)
Expand Down Expand Up @@ -659,7 +659,7 @@ class StateTransitionRulesTest extends UnitSuite with TestEnvironment {
priority = Priority.Unspecified,
started = false,
qualityEvaluation = None,
disclaimer = Seq.empty
disclaimer = None
)
val status = common.Status(PUBLISHED, Set.empty)
val transitionToTest: StateTransition = PUBLISHED -> IN_PROGRESS
Expand Down

0 comments on commit 65a98ed

Please sign in to comment.