diff --git a/article-api/src/main/scala/no/ndla/articleapi/controller/ArticleControllerV2.scala b/article-api/src/main/scala/no/ndla/articleapi/controller/ArticleControllerV2.scala index fe6c684e3..fb8202da3 100644 --- a/article-api/src/main/scala/no/ndla/articleapi/controller/ArticleControllerV2.scala +++ b/article-api/src/main/scala/no/ndla/articleapi/controller/ArticleControllerV2.scala @@ -37,9 +37,9 @@ trait ArticleControllerV2 { ContentValidator & Props & ErrorHandling & TapirController => val articleControllerV2: ArticleControllerV2 - import props._ + import props.* - class ArticleControllerV2() extends TapirController { + class ArticleControllerV2 extends TapirController { protected val applicationDescription = "Services for accessing articles from NDLA." override val serviceName: String = "articles" @@ -97,7 +97,7 @@ trait ArticleControllerV2 { searchContext: Option[String] ) - /** Does a scroll with [[AudioSearchService]] If no scrollId is specified execute the function @orFunction in the + /** Does a scroll with [[ArticleSearchService]] If no scrollId is specified execute the function @orFunction in the * second parameter list. * * @param orFunction diff --git a/article-api/src/main/scala/no/ndla/articleapi/controller/InternController.scala b/article-api/src/main/scala/no/ndla/articleapi/controller/InternController.scala index fa6ea57c2..19862a9a4 100644 --- a/article-api/src/main/scala/no/ndla/articleapi/controller/InternController.scala +++ b/article-api/src/main/scala/no/ndla/articleapi/controller/InternController.scala @@ -51,7 +51,8 @@ trait InternController { .out(stringBody) .errorOut(stringInternalServerError) .serverLogicPure(numShards => { - implicit val ec = ExecutionContext.fromExecutorService(Executors.newSingleThreadExecutor) + implicit val ec: ExecutionContextExecutorService = + ExecutionContext.fromExecutorService(Executors.newSingleThreadExecutor) val articleIndex = Future { articleIndexService.indexDocuments(numShards) } Await.result(articleIndex, Duration(10, TimeUnit.MINUTES)) match { @@ -71,7 +72,8 @@ trait InternController { .out(stringBody) .errorOut(stringInternalServerError) .serverLogicPure { _ => - implicit val ec = ExecutionContext.fromExecutorService(Executors.newSingleThreadExecutor) + implicit val ec: ExecutionContextExecutorService = + ExecutionContext.fromExecutorService(Executors.newSingleThreadExecutor) def pluralIndex(n: Int) = if (n == 1) "1 index" else s"$n indexes" val articleIndex = Future { articleIndexService.findAllIndexes(props.ArticleSearchIndex) } diff --git a/article-api/src/main/scala/no/ndla/articleapi/integration/FrontpageApiClient.scala b/article-api/src/main/scala/no/ndla/articleapi/integration/FrontpageApiClient.scala index 473891655..48839f0b4 100644 --- a/article-api/src/main/scala/no/ndla/articleapi/integration/FrontpageApiClient.scala +++ b/article-api/src/main/scala/no/ndla/articleapi/integration/FrontpageApiClient.scala @@ -17,7 +17,7 @@ import sttp.client3.quick.* import scala.util.Try trait FrontpageApiClient { - this: NdlaClient with ConverterService with Props => + this: NdlaClient & ConverterService & Props => val frontpageApiClient: FrontpageApiClient class FrontpageApiClient(FrontpageApiBaseUrl: String = props.FrontpageApiUrl) extends StrictLogging { diff --git a/article-api/src/main/scala/no/ndla/articleapi/integration/SearchApiClient.scala b/article-api/src/main/scala/no/ndla/articleapi/integration/SearchApiClient.scala index 9aef3fc99..18996ae8e 100644 --- a/article-api/src/main/scala/no/ndla/articleapi/integration/SearchApiClient.scala +++ b/article-api/src/main/scala/no/ndla/articleapi/integration/SearchApiClient.scala @@ -22,7 +22,7 @@ import scala.concurrent.{ExecutionContext, ExecutionContextExecutorService, Futu import scala.util.{Failure, Success, Try} trait SearchApiClient { - this: NdlaClient with ConverterService with Props => + this: NdlaClient & ConverterService & Props => val searchApiClient: SearchApiClient class SearchApiClient(SearchApiBaseUrl: String = props.SearchApiUrl) extends StrictLogging { diff --git a/article-api/src/main/scala/no/ndla/articleapi/model/api/ArticleContent.scala b/article-api/src/main/scala/no/ndla/articleapi/model/api/ArticleContentV2.scala similarity index 100% rename from article-api/src/main/scala/no/ndla/articleapi/model/api/ArticleContent.scala rename to article-api/src/main/scala/no/ndla/articleapi/model/api/ArticleContentV2.scala diff --git a/article-api/src/main/scala/no/ndla/articleapi/model/api/ArticleId.scala b/article-api/src/main/scala/no/ndla/articleapi/model/api/ArticleIdV2.scala similarity index 100% rename from article-api/src/main/scala/no/ndla/articleapi/model/api/ArticleId.scala rename to article-api/src/main/scala/no/ndla/articleapi/model/api/ArticleIdV2.scala diff --git a/article-api/src/main/scala/no/ndla/articleapi/model/api/ArticleSummary.scala b/article-api/src/main/scala/no/ndla/articleapi/model/api/ArticleSummaryV2.scala similarity index 100% rename from article-api/src/main/scala/no/ndla/articleapi/model/api/ArticleSummary.scala rename to article-api/src/main/scala/no/ndla/articleapi/model/api/ArticleSummaryV2.scala diff --git a/article-api/src/main/scala/no/ndla/articleapi/model/api/Article.scala b/article-api/src/main/scala/no/ndla/articleapi/model/api/ArticleV2.scala similarity index 98% rename from article-api/src/main/scala/no/ndla/articleapi/model/api/Article.scala rename to article-api/src/main/scala/no/ndla/articleapi/model/api/ArticleV2.scala index beab44066..d2abdde4f 100644 --- a/article-api/src/main/scala/no/ndla/articleapi/model/api/Article.scala +++ b/article-api/src/main/scala/no/ndla/articleapi/model/api/ArticleV2.scala @@ -10,7 +10,7 @@ package no.ndla.articleapi.model.api import io.circe.generic.semiauto.{deriveDecoder, deriveEncoder} import io.circe.{Decoder, Encoder} -import no.ndla.common.implicits._ +import no.ndla.common.implicits.* import no.ndla.common.model.NDLADate import no.ndla.common.model.api.{Copyright, RelatedContent, RelatedContentLink} import sttp.tapir.Schema.annotations.description diff --git a/article-api/src/main/scala/no/ndla/articleapi/model/api/NDLAErrors.scala b/article-api/src/main/scala/no/ndla/articleapi/model/api/NDLAErrors.scala index 64d76152b..46e6b7ce6 100644 --- a/article-api/src/main/scala/no/ndla/articleapi/model/api/NDLAErrors.scala +++ b/article-api/src/main/scala/no/ndla/articleapi/model/api/NDLAErrors.scala @@ -25,9 +25,9 @@ import no.ndla.search.{IndexNotFoundException, NdlaSearchException} import org.postgresql.util.PSQLException trait ErrorHandling extends TapirErrorHandling with StrictLogging { - this: Props with Clock with DataSource => + this: Props & Clock & DataSource => - import ErrorHelpers._ + import ErrorHelpers.* override def handleErrors: PartialFunction[Throwable, AllErrors] = { case a: AccessDeniedException if a.unauthorized => diff --git a/article-api/src/main/scala/no/ndla/articleapi/model/api/TSTypes.scala b/article-api/src/main/scala/no/ndla/articleapi/model/api/TSTypes.scala index 77a71dde5..dbdcfe242 100644 --- a/article-api/src/main/scala/no/ndla/articleapi/model/api/TSTypes.scala +++ b/article-api/src/main/scala/no/ndla/articleapi/model/api/TSTypes.scala @@ -8,6 +8,6 @@ object TSTypes { implicit val nullAlias: TSNamedType[Null] = TSType.alias[Null]("NullAlias", TSNull) // https://github.com/scala-tsi/scala-tsi/issues/172 - // Type-aliases referencing generics doesn't not work without this in scala-tsi. See: https://github.com/scala-tsi/scala-tsi/issues/184 + // Type-aliases referencing generics does not work without this in scala-tsi. See: https://github.com/scala-tsi/scala-tsi/issues/184 implicit val relatedContent: TSIType[RelatedContentLink] = TSType.fromCaseClass[RelatedContentLink] } diff --git a/article-api/src/main/scala/no/ndla/articleapi/model/api/ValidationError.scala b/article-api/src/main/scala/no/ndla/articleapi/model/api/ValidationError.scala index 61558de7d..acd1aa52b 100644 --- a/article-api/src/main/scala/no/ndla/articleapi/model/api/ValidationError.scala +++ b/article-api/src/main/scala/no/ndla/articleapi/model/api/ValidationError.scala @@ -18,5 +18,5 @@ case class ValidationError( @description("Code stating the type of error") code: String, @description("Description of the error") description: String, @description("List of validation messages") messages: Seq[ValidationMessage], - @description("When the error occured") occuredAt: LocalDateTime = LocalDateTime.now() + @description("When the error occurred") occuredAt: LocalDateTime = LocalDateTime.now() ) diff --git a/article-api/src/main/scala/no/ndla/articleapi/model/domain/Sort.scala b/article-api/src/main/scala/no/ndla/articleapi/model/domain/Sort.scala index 0268811d3..605a32c62 100644 --- a/article-api/src/main/scala/no/ndla/articleapi/model/domain/Sort.scala +++ b/article-api/src/main/scala/no/ndla/articleapi/model/domain/Sort.scala @@ -38,6 +38,6 @@ object Sort extends Enum[Sort] with CirceEnum[Sort] { private val tsEnumValues: Seq[(String, String)] = values.map(e => e.toString -> e.entryName) implicit val enumTsType: TSNamedType[Sort] = TSType.alias[Sort]( "Sort", - TSEnum.string("ArticleSortEnum", tsEnumValues: _*) + TSEnum.string("ArticleSortEnum", tsEnumValues*) ) } diff --git a/article-api/src/main/scala/no/ndla/articleapi/repository/ArticleRepository.scala b/article-api/src/main/scala/no/ndla/articleapi/repository/ArticleRepository.scala index d4bb624da..74473e235 100644 --- a/article-api/src/main/scala/no/ndla/articleapi/repository/ArticleRepository.scala +++ b/article-api/src/main/scala/no/ndla/articleapi/repository/ArticleRepository.scala @@ -20,7 +20,7 @@ import scalikejdbc.* import scala.util.{Failure, Success, Try} trait ArticleRepository { - this: DataSource with DBArticle => + this: DataSource & DBArticle => val articleRepository: ArticleRepository class ArticleRepository extends StrictLogging { @@ -64,7 +64,7 @@ trait ArticleRepository { update ${Article.table} set document=null where article_id=$articleId - and revision=(select max(revision) from ${Article.table} where article_id=${articleId}) + and revision=(select max(revision) from ${Article.table} where article_id=$articleId) """.update() if (numRows == 1) { Success(articleId) @@ -93,7 +93,7 @@ trait ArticleRepository { sql""" delete from ${Article.table} where article_id = $articleId - and revision=(select max(revision) from ${Article.table} where article_id=${articleId}) + and revision=(select max(revision) from ${Article.table} where article_id=$articleId) """.update() if (numRows == 1) { Success(articleId) @@ -135,7 +135,7 @@ trait ArticleRepository { articleWhere( sqls""" ar.article_id=${articleId.toInt} - and ar.revision=${revision} + and ar.revision=$revision """ ) } @@ -178,7 +178,7 @@ trait ArticleRepository { sql""" select revision from ${Article.table} - where article_id=${articleId} + where article_id=$articleId and document is not NULL; """ .map(rs => rs.int("revision")) @@ -266,11 +266,11 @@ trait ArticleRepository { val tags = sql"""select tags from (select distinct JSONB_ARRAY_ELEMENTS_TEXT(tagObj->'tags') tags from (select JSONB_ARRAY_ELEMENTS(document#>'{tags}') tagObj from ${Article.table}) _ - where tagObj->>'language' like ${langOrAll} + where tagObj->>'language' like $langOrAll order by tags) sorted_tags where sorted_tags.tags ilike ${sanitizedInput + '%'} - offset ${offset} - limit ${pageSize} + offset $offset + limit $pageSize """ .map(rs => rs.string("tags")) .list() @@ -280,7 +280,7 @@ trait ArticleRepository { select count(*) from (select distinct JSONB_ARRAY_ELEMENTS_TEXT(tagObj->'tags') tags from (select JSONB_ARRAY_ELEMENTS(document#>'{tags}') tagObj from ${Article.table}) _ - where tagObj->>'language' like ${langOrAll}) all_tags + where tagObj->>'language' like $langOrAll) all_tags where all_tags.tags ilike ${sanitizedInput + '%'}; """ .map(rs => rs.int("count")) diff --git a/article-api/src/main/scala/no/ndla/articleapi/service/ConverterService.scala b/article-api/src/main/scala/no/ndla/articleapi/service/ConverterService.scala index 9b14c4a5f..1a2d7ccd0 100644 --- a/article-api/src/main/scala/no/ndla/articleapi/service/ConverterService.scala +++ b/article-api/src/main/scala/no/ndla/articleapi/service/ConverterService.scala @@ -41,10 +41,10 @@ import org.jsoup.Jsoup import scala.util.{Failure, Success, Try} trait ConverterService { - this: Clock with ArticleRepository with Props => + this: Clock & ArticleRepository & Props => val converterService: ConverterService - import props._ + import props.* class ConverterService extends StrictLogging { @@ -70,7 +70,7 @@ trait ConverterService { .lastOption } - val highlightKeys: Option[Map[String, _]] = Option(result.highlight) + val highlightKeys: Option[Map[String, ?]] = Option(result.highlight) val matchLanguage = keyToLanguage(highlightKeys.getOrElse(Map()).keys) matchLanguage match { diff --git a/article-api/src/main/scala/no/ndla/articleapi/service/WriteService.scala b/article-api/src/main/scala/no/ndla/articleapi/service/WriteService.scala index 36670825a..a249dfe88 100644 --- a/article-api/src/main/scala/no/ndla/articleapi/service/WriteService.scala +++ b/article-api/src/main/scala/no/ndla/articleapi/service/WriteService.scala @@ -21,12 +21,7 @@ import no.ndla.common.model.domain.article.Article import scala.util.{Failure, Success, Try} trait WriteService { - this: ArticleRepository - with ConverterService - with ContentValidator - with ArticleIndexService - with ReadService - with SearchApiClient => + this: ArticleRepository & ConverterService & ContentValidator & ArticleIndexService & ReadService & SearchApiClient => val writeService: WriteService class WriteService extends StrictLogging { diff --git a/article-api/src/main/scala/no/ndla/articleapi/service/search/ArticleSearchService.scala b/article-api/src/main/scala/no/ndla/articleapi/service/search/ArticleSearchService.scala index 3f6d3a262..b6de9bc8e 100644 --- a/article-api/src/main/scala/no/ndla/articleapi/service/search/ArticleSearchService.scala +++ b/article-api/src/main/scala/no/ndla/articleapi/service/search/ArticleSearchService.scala @@ -8,36 +8,31 @@ package no.ndla.articleapi.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.articleapi.Props import no.ndla.articleapi.model.api import no.ndla.articleapi.model.api.{ArticleSummaryV2, ErrorHandling} -import no.ndla.articleapi.model.domain._ +import no.ndla.articleapi.model.domain.* import no.ndla.articleapi.model.search.SearchResult import no.ndla.articleapi.service.ConverterService -import no.ndla.common.implicits._ +import no.ndla.common.implicits.* import no.ndla.common.model.domain.Availability import no.ndla.language.Language import no.ndla.mapping.License import no.ndla.search.Elastic4sClient import java.util.concurrent.Executors -import scala.concurrent.{ExecutionContext, Future} +import scala.concurrent.{ExecutionContext, ExecutionContextExecutorService, Future} import scala.util.{Failure, Success, Try} trait ArticleSearchService { - this: Elastic4sClient - with SearchConverterService - with SearchService - with ArticleIndexService - with ConverterService - with Props - with ErrorHandling => + this: Elastic4sClient & SearchConverterService & SearchService & ArticleIndexService & ConverterService & Props & + ErrorHandling => val articleSearchService: ArticleSearchService - import props._ + import props.* class ArticleSearchService extends StrictLogging with SearchService[api.ArticleSummaryV2] { private val noCopyright = boolQuery().not(termQuery("license", License.Copyrighted.toString)) @@ -158,7 +153,8 @@ trait ArticleSearchService { } override def scheduleIndexDocuments(): Unit = { - implicit val ec = ExecutionContext.fromExecutorService(Executors.newSingleThreadExecutor) + implicit val ec: ExecutionContextExecutorService = + ExecutionContext.fromExecutorService(Executors.newSingleThreadExecutor) val f = Future { articleIndexService.indexDocuments(None) } diff --git a/article-api/src/main/scala/no/ndla/articleapi/service/search/IndexService.scala b/article-api/src/main/scala/no/ndla/articleapi/service/search/IndexService.scala index 19d81f1dd..051e6c40a 100644 --- a/article-api/src/main/scala/no/ndla/articleapi/service/search/IndexService.scala +++ b/article-api/src/main/scala/no/ndla/articleapi/service/search/IndexService.scala @@ -25,7 +25,7 @@ import scala.collection.mutable.ListBuffer import scala.util.{Failure, Success, Try} trait IndexService { - this: Elastic4sClient with BaseIndexService with Props with ArticleRepository => + this: Elastic4sClient & BaseIndexService & Props & ArticleRepository => trait IndexService extends BaseIndexService with StrictLogging { override val MaxResultWindowOption: Int = props.ElasticSearchIndexMaxResultWindow @@ -124,20 +124,19 @@ trait IndexService { * Sequence of FieldDefinitions for a field. */ protected def generateLanguageSupportedFieldList(fieldName: String, keepRaw: Boolean = false): Seq[ElasticField] = { - keepRaw match { - case true => - languageAnalyzers.map(langAnalyzer => - textField(s"$fieldName.${langAnalyzer.languageTag.toString}") - .fielddata(false) - .analyzer(langAnalyzer.analyzer) - .fields(keywordField("raw")) - ) - case false => - languageAnalyzers.map(langAnalyzer => - textField(s"$fieldName.${langAnalyzer.languageTag.toString}") - .fielddata(false) - .analyzer(langAnalyzer.analyzer) - ) + if (keepRaw) { + languageAnalyzers.map(langAnalyzer => + textField(s"$fieldName.${langAnalyzer.languageTag.toString}") + .fielddata(false) + .analyzer(langAnalyzer.analyzer) + .fields(keywordField("raw")) + ) + } else { + languageAnalyzers.map(langAnalyzer => + textField(s"$fieldName.${langAnalyzer.languageTag.toString}") + .fielddata(false) + .analyzer(langAnalyzer.analyzer) + ) } } @@ -167,13 +166,13 @@ trait IndexService { pathMatch = Some(name) ) }) - val catchAlltemplate = DynamicTemplateRequest( + val catchAllTemplate = DynamicTemplateRequest( name = fieldName, mapping = textField(fieldName).analyzer(SearchLanguage.standardAnalyzer).fields(fields.toList), matchMappingType = Some("string"), pathMatch = Some(s"$fieldName.*") ) - languageTemplates ++ Seq(catchAlltemplate) + languageTemplates ++ Seq(catchAllTemplate) } } diff --git a/article-api/src/main/scala/no/ndla/articleapi/service/search/SearchConverterService.scala b/article-api/src/main/scala/no/ndla/articleapi/service/search/SearchConverterService.scala index e697bcac3..6a6eea2dd 100644 --- a/article-api/src/main/scala/no/ndla/articleapi/service/search/SearchConverterService.scala +++ b/article-api/src/main/scala/no/ndla/articleapi/service/search/SearchConverterService.scala @@ -10,7 +10,7 @@ package no.ndla.articleapi.service.search import com.typesafe.scalalogging.StrictLogging import no.ndla.articleapi.model.api.{ArticleSummaryV2, SearchResultV2} -import no.ndla.articleapi.model.search._ +import no.ndla.articleapi.model.search.* import no.ndla.articleapi.service.ConverterService import no.ndla.common.model.domain.article.Article import no.ndla.search.SearchLanguage.languageAnalyzers diff --git a/article-api/src/main/scala/no/ndla/articleapi/service/search/SearchService.scala b/article-api/src/main/scala/no/ndla/articleapi/service/search/SearchService.scala index 860b984fb..2f0c53126 100644 --- a/article-api/src/main/scala/no/ndla/articleapi/service/search/SearchService.scala +++ b/article-api/src/main/scala/no/ndla/articleapi/service/search/SearchService.scala @@ -8,13 +8,13 @@ package no.ndla.articleapi.service.search -import com.sksamuel.elastic4s.ElasticDsl._ +import com.sksamuel.elastic4s.ElasticDsl.* import com.sksamuel.elastic4s.RequestFailure import com.sksamuel.elastic4s.requests.searches.SearchResponse import com.sksamuel.elastic4s.requests.searches.sort.{FieldSort, SortOrder} import com.typesafe.scalalogging.StrictLogging import no.ndla.articleapi.Props -import no.ndla.articleapi.model.domain._ +import no.ndla.articleapi.model.domain.* import no.ndla.articleapi.model.search.SearchResult import no.ndla.articleapi.service.ConverterService import no.ndla.language.Language.{AllLanguages, NoLanguage} @@ -24,7 +24,7 @@ import java.lang.Math.max import scala.util.{Failure, Success, Try} trait SearchService { - this: Elastic4sClient with ConverterService with Props => + this: Elastic4sClient & ConverterService & Props => trait SearchService[T] extends StrictLogging { val searchIndex: String @@ -126,7 +126,7 @@ trait SearchService { case NdlaSearchException(_, Some(RequestFailure(status, _, _, _)), _, _) if status == 404 => logger.error(s"Index $searchIndex not found. Scheduling a reindex.") scheduleIndexDocuments() - Failure(new IndexNotFoundException(s"Index $searchIndex not found. Scheduling a reindex")) + Failure(IndexNotFoundException(s"Index $searchIndex not found. Scheduling a reindex")) case e: NdlaSearchException[?] => logger.error(e.getMessage) Failure(NdlaSearchException(s"Unable to execute search in $searchIndex", e)) diff --git a/article-api/src/test/scala/no/ndla/articleapi/TestData.scala b/article-api/src/test/scala/no/ndla/articleapi/TestData.scala index 4036d5c1f..aea6da220 100644 --- a/article-api/src/test/scala/no/ndla/articleapi/TestData.scala +++ b/article-api/src/test/scala/no/ndla/articleapi/TestData.scala @@ -9,12 +9,12 @@ package no.ndla.articleapi import no.ndla.articleapi.model.api -import no.ndla.articleapi.model.domain._ +import no.ndla.articleapi.model.domain.* import no.ndla.common.configuration.Constants.EmbedTagName import no.ndla.common.model import no.ndla.common.model.NDLADate import no.ndla.common.model.domain.article.{Article, Copyright} -import no.ndla.common.model.domain._ +import no.ndla.common.model.domain.* import no.ndla.mapping.License trait TestData { diff --git a/article-api/src/test/scala/no/ndla/articleapi/TestEnvironment.scala b/article-api/src/test/scala/no/ndla/articleapi/TestEnvironment.scala index 1d86751c7..55a3a04f0 100644 --- a/article-api/src/test/scala/no/ndla/articleapi/TestEnvironment.scala +++ b/article-api/src/test/scala/no/ndla/articleapi/TestEnvironment.scala @@ -70,7 +70,7 @@ trait TestEnvironment val internController: InternController = mock[InternController] val articleControllerV2: ArticleControllerV2 = mock[ArticleControllerV2] - val healthController = mock[TapirHealthController] + val healthController: TapirHealthController = mock[TapirHealthController] val dataSource: HikariDataSource = mock[HikariDataSource] val articleRepository: ArticleRepository = mock[ArticleRepository] diff --git a/article-api/src/test/scala/no/ndla/articleapi/controller/HealthControllerTest.scala b/article-api/src/test/scala/no/ndla/articleapi/controller/HealthControllerTest.scala index fcc9b0a3f..44b281611 100644 --- a/article-api/src/test/scala/no/ndla/articleapi/controller/HealthControllerTest.scala +++ b/article-api/src/test/scala/no/ndla/articleapi/controller/HealthControllerTest.scala @@ -10,7 +10,7 @@ package no.ndla.articleapi.controller import no.ndla.articleapi.{TestEnvironment, UnitSuite} import no.ndla.tapirtesting.TapirControllerTest -import sttp.client3.quick._ +import sttp.client3.quick.* class HealthControllerTest extends UnitSuite with TestEnvironment with TapirControllerTest { override val controller: TapirHealthController = new TapirHealthController() diff --git a/article-api/src/test/scala/no/ndla/articleapi/controller/InternControllerTest.scala b/article-api/src/test/scala/no/ndla/articleapi/controller/InternControllerTest.scala index f5cfa61bd..7c1d8638b 100644 --- a/article-api/src/test/scala/no/ndla/articleapi/controller/InternControllerTest.scala +++ b/article-api/src/test/scala/no/ndla/articleapi/controller/InternControllerTest.scala @@ -43,7 +43,7 @@ class InternControllerTest extends UnitSuite with TestEnvironment with TapirCont when(contentValidator.validateArticle(any[Article], any)) .thenReturn(Success(TestData.sampleArticleWithByNcSa)) - import io.circe.syntax._ + import io.circe.syntax.* val jsonStr = TestData.sampleArticleWithByNcSa.asJson.deepDropNullValues.noSpaces val response = simpleHttpClient.send( @@ -59,8 +59,8 @@ class InternControllerTest extends UnitSuite with TestEnvironment with TapirCont test("That DELETE /index removes all indexes") { reset(articleIndexService) when(articleIndexService.findAllIndexes(any[String])).thenReturn(Success(List("index1", "index2"))) - doReturn(Success(""), Nil: _*).when(articleIndexService).deleteIndexWithName(Some("index1")) - doReturn(Success(""), Nil: _*).when(articleIndexService).deleteIndexWithName(Some("index2")) + doReturn(Success(""), Nil*).when(articleIndexService).deleteIndexWithName(Some("index1")) + doReturn(Success(""), Nil*).when(articleIndexService).deleteIndexWithName(Some("index2")) val response = simpleHttpClient.send( quickRequest.delete( uri"http://localhost:$serverPort/intern/index" @@ -78,11 +78,11 @@ class InternControllerTest extends UnitSuite with TestEnvironment with TapirCont test("That DELETE /index fails if at least one index isn't found, and no indexes are deleted") { reset(articleIndexService) - doReturn(Failure(new RuntimeException("Failed to find indexes")), Nil: _*) + doReturn(Failure(new RuntimeException("Failed to find indexes")), Nil*) .when(articleIndexService) .findAllIndexes(props.ArticleSearchIndex) - doReturn(Success(""), Nil: _*).when(articleIndexService).deleteIndexWithName(Some("index1")) - doReturn(Success(""), Nil: _*).when(articleIndexService).deleteIndexWithName(Some("index2")) + doReturn(Success(""), Nil*).when(articleIndexService).deleteIndexWithName(Some("index1")) + doReturn(Success(""), Nil*).when(articleIndexService).deleteIndexWithName(Some("index2")) val response = simpleHttpClient.send( quickRequest.delete( uri"http://localhost:$serverPort/intern/index" @@ -101,8 +101,8 @@ class InternControllerTest extends UnitSuite with TestEnvironment with TapirCont when(articleIndexService.findAllIndexes(any[String])).thenReturn(Success(List("index1", "index2"))) - doReturn(Success(""), Nil: _*).when(articleIndexService).deleteIndexWithName(Some("index1")) - doReturn(Failure(new RuntimeException("No index with name 'index2' exists")), Nil: _*) + doReturn(Success(""), Nil*).when(articleIndexService).deleteIndexWithName(Some("index1")) + doReturn(Failure(new RuntimeException("No index with name 'index2' exists")), Nil*) .when(articleIndexService) .deleteIndexWithName(Some("index2")) val response = simpleHttpClient.send( @@ -126,7 +126,7 @@ class InternControllerTest extends UnitSuite with TestEnvironment with TapirCont val authHeaderWithWriteRole = "Bearer eyJhbGciOiJIUzI1NiJ9.eyJodHRwczovL25kbGEubm8vY2xpZW50X2lkIjoieHh4eXl5IiwiaXNzIjoiaHR0cHM6Ly9uZGxhLmV1LmF1dGgwLmNvbS8iLCJzdWIiOiJ4eHh5eXlAY2xpZW50cyIsImF1ZCI6Im5kbGFfc3lzdGVtIiwiYXpwIjoiMTIzIiwiaWF0IjoxNTEwMzA1NzczLCJleHAiOjE1MTAzOTIxNzMsInNjb3BlIjoiYXVkaW86d3JpdGUiLCJndHkiOiJjbGllbnQtY3JlZGVudGlhbHMiLCJwZXJtaXNzaW9ucyI6WyJhdWRpbzp3cml0ZSIsImFydGljbGVzOnB1Ymxpc2giLCJhcnRpY2xlczp3cml0ZSIsImNvbmNlcHQ6YWRtaW4iLCJjb25jZXB0OndyaXRlIiwiZHJhZnRzOmFkbWluIiwiZHJhZnRzOmh0bWwiLCJkcmFmdHM6cHVibGlzaCIsImRyYWZ0czp3cml0ZSIsImZyb250cGFnZTphZG1pbiIsImZyb250cGFnZTp3cml0ZSIsImltYWdlczp3cml0ZSIsImxlYXJuaW5ncGF0aDphZG1pbiIsImxlYXJuaW5ncGF0aDpwdWJsaXNoIiwibGVhcm5pbmdwYXRoOndyaXRlIl19.nm77NIe8aFACafNhC1nROU1bTspbT-hCvxlg6_8ztDk" - import io.circe.syntax._ + import io.circe.syntax.* val art = TestData.sampleArticleWithByNcSa.copy(id = Some(10L)) val jsonStr = art.asJson.deepDropNullValues.noSpaces diff --git a/article-api/src/test/scala/no/ndla/articleapi/model/CachableTest.scala b/article-api/src/test/scala/no/ndla/articleapi/model/CachableTest.scala index 3326f5030..b468c1b41 100644 --- a/article-api/src/test/scala/no/ndla/articleapi/model/CachableTest.scala +++ b/article-api/src/test/scala/no/ndla/articleapi/model/CachableTest.scala @@ -8,7 +8,7 @@ package no.ndla.articleapi.model -import no.ndla.articleapi._ +import no.ndla.articleapi.* import no.ndla.articleapi.model.domain.Cachable import scala.util.{Success, Try} @@ -28,7 +28,7 @@ class CachableTest extends UnitSuite with TestEnvironment { a <- c1 b <- c2 c <- c3 - } yield (a + b + c) + } yield a + b + c x should be(Cachable(6, true)) } diff --git a/article-api/src/test/scala/no/ndla/articleapi/repository/ArticleRepositoryTest.scala b/article-api/src/test/scala/no/ndla/articleapi/repository/ArticleRepositoryTest.scala index 9cda3d9f6..e77febdca 100644 --- a/article-api/src/test/scala/no/ndla/articleapi/repository/ArticleRepositoryTest.scala +++ b/article-api/src/test/scala/no/ndla/articleapi/repository/ArticleRepositoryTest.scala @@ -9,6 +9,7 @@ package no.ndla.articleapi.repository import cats.implicits.* +import com.zaxxer.hikari.HikariDataSource import no.ndla.articleapi.* import no.ndla.articleapi.model.domain.ArticleIds import no.ndla.common.model.domain.Tag @@ -23,9 +24,9 @@ class ArticleRepositoryTest extends IntegrationSuite(EnablePostgresContainer = true) with UnitSuite with TestEnvironment { - override val dataSource = testDataSource.get - override val migrator = new DBMigrator - var repository: ArticleRepository = _ + override val dataSource: HikariDataSource = testDataSource.get + override val migrator = new DBMigrator + var repository: ArticleRepository = _ lazy val sampleArticle: Article = TestData.sampleArticleWithByNcSa @@ -229,7 +230,7 @@ class ArticleRepositoryTest ) val Right(relatedId) = repository.withId(1).toArticle.get.relatedContent.head - relatedId.toLong should be(2L) + relatedId should be(2L) } test("Dumping articles should ignore unpublished ones") { diff --git a/article-api/src/test/scala/no/ndla/articleapi/service/search/ArticleSearchConverterServiceTest.scala b/article-api/src/test/scala/no/ndla/articleapi/service/search/ArticleSearchConverterServiceTest.scala index d5e8f5c90..b501bc558 100644 --- a/article-api/src/test/scala/no/ndla/articleapi/service/search/ArticleSearchConverterServiceTest.scala +++ b/article-api/src/test/scala/no/ndla/articleapi/service/search/ArticleSearchConverterServiceTest.scala @@ -8,7 +8,7 @@ package no.ndla.articleapi.service.search -import no.ndla.articleapi.model.search._ +import no.ndla.articleapi.model.search.* import no.ndla.articleapi.{TestEnvironment, UnitSuite} import no.ndla.common.model.domain.article.Article import no.ndla.common.model.domain.{ArticleContent, Tag, Title} diff --git a/article-api/src/test/scala/no/ndla/articleapi/service/search/ArticleSearchServiceTest.scala b/article-api/src/test/scala/no/ndla/articleapi/service/search/ArticleSearchServiceTest.scala index b9e8350fb..3e71dda24 100644 --- a/article-api/src/test/scala/no/ndla/articleapi/service/search/ArticleSearchServiceTest.scala +++ b/article-api/src/test/scala/no/ndla/articleapi/service/search/ArticleSearchServiceTest.scala @@ -8,12 +8,12 @@ package no.ndla.articleapi.service.search -import no.ndla.articleapi._ +import no.ndla.articleapi.* import no.ndla.articleapi.model.api -import no.ndla.articleapi.model.domain._ +import no.ndla.articleapi.model.domain.* import no.ndla.common.model.NDLADate import no.ndla.common.model.domain.article.Copyright -import no.ndla.common.model.domain._ +import no.ndla.common.model.domain.* import no.ndla.language.Language import no.ndla.mapping.License.{CC_BY_NC_SA, Copyrighted, PublicDomain} import no.ndla.scalatestsuite.IntegrationSuite @@ -25,7 +25,7 @@ class ArticleSearchServiceTest with UnitSuite with TestEnvironment { import TestData.testSettings - import props._ + import props.* e4sClient = Elastic4sClientFactory.getClient(elasticSearchHost.getOrElse("http://localhost:9200")) @@ -465,7 +465,7 @@ class ArticleSearchServiceTest val hits = search.results search.totalCount should equal(11) - hits(0).id should equal(1) + hits.head.id should equal(1) hits(1).id should equal(2) hits(2).id should equal(3) hits(3).id should equal(5) diff --git a/common/src/main/scala/no/ndla/common/model/domain/learningpath/LearningStep.scala b/common/src/main/scala/no/ndla/common/model/domain/learningpath/LearningStep.scala index 11b415dfb..e7ff270fd 100644 --- a/common/src/main/scala/no/ndla/common/model/domain/learningpath/LearningStep.scala +++ b/common/src/main/scala/no/ndla/common/model/domain/learningpath/LearningStep.scala @@ -31,6 +31,7 @@ case class LearningStep( def supportedLanguages: Seq[String] = { getSupportedLanguages( title, + introduction, description, embedUrl )