Skip to content

Commit

Permalink
Properly handle copyrighted data
Browse files Browse the repository at this point in the history
  • Loading branch information
gunnarvelle committed Jan 9, 2025
1 parent d8c6d8b commit 6c0ca1a
Show file tree
Hide file tree
Showing 16 changed files with 95 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import no.ndla.audioapi.model.{api, domain}
import no.ndla.common.CirceUtil
import no.ndla.common.implicits.*
import no.ndla.language.Language.AllLanguages
import no.ndla.mapping.License
import no.ndla.search.Elastic4sClient

import scala.concurrent.ExecutionContext.Implicits.global
Expand Down Expand Up @@ -82,7 +83,7 @@ trait AudioSearchService {
): Try[domain.SearchResult[api.AudioSummaryDTO]] = {

val licenseFilter = settings.license match {
case None => Some(boolQuery().not(termQuery("license", "copyrighted")))
case None => Some(boolQuery().not(termQuery("license", License.Copyrighted.toString)))
case Some(lic) => Some(termQuery("license", lic))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import no.ndla.audioapi.{TestEnvironment, UnitSuite}
import no.ndla.common.model.NDLADate
import no.ndla.common.model.domain.article.Copyright
import no.ndla.common.model.domain.{Author, Tag, Title}
import no.ndla.mapping.License
import no.ndla.tapirtesting.TapirControllerTest
import org.mockito.Mockito.when
import sttp.client3.quick.*
Expand All @@ -31,7 +32,16 @@ class HealthControllerTest extends UnitSuite with TestEnvironment with TapirCont
val created: NDLADate = NDLADate.of(2017, 3, 1, 12, 15, 32)

val copyrighted: Copyright =
Copyright("copyrighted", Some("New York"), Seq(Author("Forfatter", "Clark Kent")), Seq(), Seq(), None, None, false)
Copyright(
License.Copyrighted.toString,
Some("New York"),
Seq(Author("Forfatter", "Clark Kent")),
Seq(),
Seq(),
None,
None,
false
)

val audioMeta: AudioMetaInformation = domain.AudioMetaInformation(
Some(1),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@

package no.ndla.audioapi.service

import no.ndla.audioapi.model.domain._
import no.ndla.audioapi.model.domain.*
import no.ndla.audioapi.model.{api, domain}
import no.ndla.audioapi.{TestEnvironment, UnitSuite}
import no.ndla.common.model.domain.article.Copyright
import no.ndla.common.model.domain.{Author, Tag, Title}
import no.ndla.common.model.{NDLADate, domain => common, api => commonApi}
import no.ndla.common.model.{NDLADate, api as commonApi, domain as common}
import no.ndla.mapping.License
import no.ndla.mapping.License.CC_BY_SA

import scala.util.Success
Expand All @@ -25,7 +26,16 @@ class ConverterServiceTest extends UnitSuite with TestEnvironment {
val created: NDLADate = NDLADate.of(2017, 3, 1, 12, 15, 32)

val copyrighted: Copyright =
Copyright("copyrighted", Some("New York"), Seq(Author("Forfatter", "Clark Kent")), Seq(), Seq(), None, None, false)
Copyright(
License.Copyrighted.toString,
Some("New York"),
Seq(Author("Forfatter", "Clark Kent")),
Seq(),
Seq(),
None,
None,
false
)

val audioMeta: AudioMetaInformation = domain.AudioMetaInformation(
Some(1),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import no.ndla.audioapi.{TestData, TestEnvironment, UnitSuite}
import no.ndla.common.model.NDLADate
import no.ndla.common.model.domain.article.Copyright
import no.ndla.common.model.domain.{Author, Tag, Title}
import no.ndla.mapping.License
import no.ndla.scalatestsuite.IntegrationSuite
import org.mockito.ArgumentMatchers.any
import org.mockito.Mockito.when
Expand Down Expand Up @@ -53,7 +54,16 @@ class AudioSearchServiceTest
)

val copyrighted: Copyright =
Copyright("copyrighted", Some("New York"), List(Author("Forfatter", "Clark Kent")), Seq(), Seq(), None, None, false)
Copyright(
License.Copyrighted.toString,
Some("New York"),
List(Author("Forfatter", "Clark Kent")),
Seq(),
Seq(),
None,
None,
false
)

val updated1: NDLADate = NDLADate.of(2017, 4, 1, 12, 15, 32)
val updated2: NDLADate = NDLADate.of(2017, 5, 1, 12, 15, 32)
Expand Down Expand Up @@ -339,7 +349,7 @@ class AudioSearchServiceTest
searchSettings.copy(
query = Some("batmen"),
language = Some("nb"),
license = Some("copyrighted")
license = Some(License.Copyrighted.toString)
)
)
results.totalCount should be(1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import no.ndla.common.model.domain.concept.{
WordClass
}
import no.ndla.conceptapi.integration.model.TaxonomyData
import no.ndla.mapping.License
import org.mockito.Mockito.when

import java.util.UUID
Expand Down Expand Up @@ -73,7 +74,7 @@ class DraftConceptSearchServiceTest extends IntegrationSuite(EnableElasticsearch
)

val copyrighted: DraftCopyright = DraftCopyright(
Some("copyrighted"),
Some(License.Copyrighted.toString),
Some("New York"),
List(Author("Forfatter", "Clark Kent")),
List(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import no.ndla.common.model.domain.concept.{
WordClass
}
import no.ndla.conceptapi.integration.model.TaxonomyData
import no.ndla.mapping.License
import no.ndla.search.model.domain.{Bucket, TermAggregation}
import org.mockito.Mockito.when

Expand Down Expand Up @@ -69,7 +70,7 @@ class PublishedConceptSearchServiceTest
)

val copyrighted: DraftCopyright = DraftCopyright(
Some("copyrighted"),
Some(License.Copyrighted.toString),
Some("New York"),
List(Author("Forfatter", "Clark Kent")),
List(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@

package no.ndla.draftapi.service.search

import com.sksamuel.elastic4s.ElasticDsl._
import com.sksamuel.elastic4s.ElasticDsl.*
import com.sksamuel.elastic4s.requests.searches.queries.compound.BoolQuery
import com.typesafe.scalalogging.StrictLogging
import no.ndla.draftapi.Props
import no.ndla.draftapi.model.api
import no.ndla.draftapi.model.api.ErrorHandling
import no.ndla.draftapi.model.domain._
import no.ndla.draftapi.model.domain.*
import no.ndla.language.Language
import no.ndla.mapping.License
import no.ndla.search.Elastic4sClient

import java.util.concurrent.Executors
Expand All @@ -34,7 +35,7 @@ trait ArticleSearchService {
class ArticleSearchService extends StrictLogging with SearchService[api.ArticleSummaryDTO] {
import props.{ElasticSearchIndexMaxResultWindow, ElasticSearchScrollKeepAlive}

private val noCopyright = boolQuery().not(termQuery("license", "copyrighted"))
private val noCopyright = boolQuery().not(termQuery("license", License.Copyrighted.toString))

override val searchIndex: String = props.DraftSearchIndex

Expand Down
3 changes: 2 additions & 1 deletion draft-api/src/test/scala/no/ndla/draftapi/TestData.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import no.ndla.common.model.{NDLADate, api as commonApi, domain as common}
import no.ndla.draftapi.integration.{LearningPath, Title}
import no.ndla.draftapi.model.api.*
import no.ndla.draftapi.model.{api, domain}
import no.ndla.mapping.License
import no.ndla.mapping.License.{CC_BY, CC_BY_NC_SA}
import no.ndla.network.tapir.auth.Permission.{DRAFT_API_ADMIN, DRAFT_API_PUBLISH, DRAFT_API_WRITE}
import no.ndla.network.tapir.auth.TokenUser
Expand Down Expand Up @@ -54,7 +55,7 @@ object TestData {
false
)
private val copyrighted = common.draft.DraftCopyright(
Some("copyrighted"),
Some(License.Copyrighted.toString),
Some("New York"),
List(common.Author("Forfatter", "Clark Kent")),
List(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@
package no.ndla.draftapi.service.search

import no.ndla.common.model.NDLADate
import no.ndla.common.model.domain._
import no.ndla.common.model.domain.draft._
import no.ndla.common.model.domain.*
import no.ndla.common.model.domain.draft.*
import no.ndla.draftapi.TestData.searchSettings
import no.ndla.draftapi._
import no.ndla.draftapi.model.domain._
import no.ndla.draftapi.*
import no.ndla.draftapi.model.domain.*
import no.ndla.language.Language
import no.ndla.mapping.License
import no.ndla.scalatestsuite.IntegrationSuite

import scala.util.Success
Expand Down Expand Up @@ -53,7 +54,7 @@ class ArticleSearchServiceTest extends IntegrationSuite(EnableElasticsearchConta
)

val copyrighted: DraftCopyright = DraftCopyright(
Some("copyrighted"),
Some(License.Copyrighted.toString),
Some("New York"),
List(Author("Forfatter", "Clark Kent")),
List(),
Expand Down Expand Up @@ -494,7 +495,7 @@ class ArticleSearchServiceTest extends IntegrationSuite(EnableElasticsearchConta
val Success(results) = articleSearchService.matchingQuery(
searchSettings.copy(
query = Some("supermann"),
license = Some("copyrighted"),
license = Some(License.Copyrighted.toString),
sort = Sort.ByTitleAsc
)
)
Expand Down Expand Up @@ -592,7 +593,7 @@ class ArticleSearchServiceTest extends IntegrationSuite(EnableElasticsearchConta
val Success(search) = articleSearchService.matchingQuery(
searchSettings.copy(
searchLanguage = Language.AllLanguages,
license = Some("copyrighted"),
license = Some(License.Copyrighted.toString),
sort = Sort.ByTitleAsc,
pageSize = 100
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ trait ImageSearchService {
val imageSearchService: ImageSearchService
class ImageSearchService extends StrictLogging with SearchService[(SearchableImage, MatchedLanguage)] {
import props.{ElasticSearchIndexMaxResultWindow, ElasticSearchScrollKeepAlive}
private val noCopyright = boolQuery().not(termQuery("license", "copyrighted"))
private val noCopyright = boolQuery().not(termQuery("license", "COPYRIGHTED"))
override val searchIndex: String = props.SearchIndex
override val indexService: ImageIndexService = imageIndexService

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import no.ndla.imageapi.model.domain.{
}
import no.ndla.tapirtesting.TapirControllerTest
import no.ndla.imageapi.{TestEnvironment, UnitSuite}
import no.ndla.mapping.License
import org.mockito.Mockito.when
import sttp.client3.quick.*

Expand All @@ -35,7 +36,7 @@ class HealthControllerTest extends UnitSuite with TestEnvironment with TapirCont

val copyrighted: Copyright =
Copyright(
"copyrighted",
License.Copyrighted.toString,
Some("New York"),
Seq(Author("Forfatter", "Clark Kent")),
Seq(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import no.ndla.common.model.domain.{Content, Priority}
import no.ndla.common.model.domain.draft.DraftStatus
import no.ndla.language.Language.AllLanguages
import no.ndla.language.model.Iso639
import no.ndla.mapping.License
import no.ndla.search.AggregationBuilder.{buildTermsAggregation, getAggregationsFromResult}
import no.ndla.search.Elastic4sClient
import no.ndla.searchapi.Props
Expand Down Expand Up @@ -268,7 +269,7 @@ trait MultiDraftSearchService {
val idFilter = if (settings.withIdIn.isEmpty) None else Some(idsQuery(settings.withIdIn))

val licenseFilter = settings.license match {
case None => Some(boolQuery().not(termQuery("license", "copyrighted")))
case None => Some(boolQuery().not(termQuery("license", License.Copyrighted.toString)))
case Some(lic) => Some(termQuery("license", lic))
}
val grepCodesFilter =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import com.typesafe.scalalogging.StrictLogging
import no.ndla.common.model.domain.{Availability, Content}
import no.ndla.language.Language.AllLanguages
import no.ndla.language.model.Iso639
import no.ndla.mapping.License
import no.ndla.search.AggregationBuilder.{buildTermsAggregation, getAggregationsFromResult}
import no.ndla.search.Elastic4sClient
import no.ndla.searchapi.Props
Expand Down Expand Up @@ -138,7 +139,7 @@ trait MultiSearchService {
val idFilter = if (settings.withIdIn.isEmpty) None else Some(idsQuery(settings.withIdIn))

val licenseFilter = settings.license match {
case None => Some(boolQuery().not(termQuery("license", "copyrighted")))
case None => Some(boolQuery().not(termQuery("license", License.Copyrighted.toString)))
case Some(lic) => Some(termQuery("license", lic))
}

Expand Down
14 changes: 12 additions & 2 deletions search-api/src/test/scala/no/ndla/searchapi/TestData.scala
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import no.ndla.common.model.domain.learningpath.{
}
import no.ndla.common.model.{NDLADate, domain as common}
import no.ndla.language.Language.DefaultLanguage
import no.ndla.mapping.License
import no.ndla.search.model.domain.EmbedValues
import no.ndla.search.model.{LanguageValue, SearchableLanguageList, SearchableLanguageValues}
import no.ndla.searchapi.model.domain.*
Expand All @@ -73,7 +74,16 @@ object TestData {
private val byNcSaCopyright =
Copyright("by-nc-sa", Some("Gotham City"), List(Author("Writer", "DC Comics")), List(), List(), None, None, false)
private val copyrighted =
Copyright("copyrighted", Some("New York"), List(Author("Writer", "Clark Kent")), List(), List(), None, None, false)
Copyright(
License.Copyrighted.toString,
Some("New York"),
List(Author("Writer", "Clark Kent")),
List(),
List(),
None,
None,
false
)
val today: NDLADate = NDLADate.now().withNano(0)

val sampleArticleTitle: ArticleApiTitle = ArticleApiTitle("tittell", "tittell", "nb")
Expand Down Expand Up @@ -601,7 +611,7 @@ object TestData {
)

val draftCopyrighted: DraftCopyright = draft.DraftCopyright(
Some("copyrighted"),
Some(License.Copyrighted.toString),
Some("New York"),
List(Author("Forfatter", "Clark Kent")),
List(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import no.ndla.common.model.NDLADate
import no.ndla.common.model.domain.ArticleType
import no.ndla.common.model.domain.draft.DraftStatus
import no.ndla.language.Language.AllLanguages
import no.ndla.mapping.License
import no.ndla.network.tapir.NonEmptyString
import no.ndla.scalatestsuite.IntegrationSuite
import no.ndla.searchapi.TestData.*
Expand Down Expand Up @@ -67,7 +68,7 @@ class MultiDraftSearchServiceTest extends IntegrationSuite(EnableElasticsearchCo
else {
draftsToIndex.filter(_.title.map(_.language).contains(language))
}
x.filter(!_.copyright.flatMap(_.license).contains("copyrighted"))
x.filter(!_.copyright.flatMap(_.license).contains(License.Copyrighted.toString))
.filterNot(_.status.current == DraftStatus.ARCHIVED)
}

Expand All @@ -76,7 +77,7 @@ class MultiDraftSearchServiceTest extends IntegrationSuite(EnableElasticsearchCo
else {
learningPathsToIndex.filter(_.title.map(_.language).contains(language))
}
x.filter(_.copyright.license != "copyrighted")
x.filter(_.copyright.license != License.Copyrighted.toString)
}

private def idsForLang(language: String) =
Expand Down Expand Up @@ -252,7 +253,7 @@ class MultiDraftSearchServiceTest extends IntegrationSuite(EnableElasticsearchCo
multiDraftSearchService.matchingQuery(
multiDraftSearchSettings.copy(
query = Some(NonEmptyString.fromString("supermann").get),
license = Some("copyrighted"),
license = Some(License.Copyrighted.toString),
sort = Sort.ByTitleAsc
)
)
Expand Down Expand Up @@ -352,7 +353,12 @@ class MultiDraftSearchServiceTest extends IntegrationSuite(EnableElasticsearchCo
test("Search for all languages should return all languages if copyrighted") {
val Success(search) = multiDraftSearchService.matchingQuery(
multiDraftSearchSettings
.copy(language = AllLanguages, license = Some("copyrighted"), pageSize = 100, sort = Sort.ByTitleAsc)
.copy(
language = AllLanguages,
license = Some(License.Copyrighted.toString),
pageSize = 100,
sort = Sort.ByTitleAsc
)
)
val hits = search.results

Expand Down
Loading

0 comments on commit 6c0ca1a

Please sign in to comment.