def fromInput()

in src/main/scala/managehelpcontentpublisher/Topic.scala [14:40]


  def fromInput(input: InputModel): Seq[Topic] = {
    import input.{article => newArticle, dataCategories}

    val titles = newArticle.dataCategories.map(cat => cat.name -> cat.label).toMap

    val publishedArticleUrls = (for {
      topic <- dataCategories
      publishedArticle <- topic.publishedArticles
    } yield publishedArticle.urlName).distinct

    /*
        If this is a newly published article, this will be manually added to each topic list. Refer to PR: https://github.com/guardian/manage-help-content-publisher/pull/501
     */
    def addNewArticleToTopics(cat: DataCategory) =
      if (!publishedArticleUrls.contains(newArticle.urlName))
        Seq(TopicArticle(newArticle.urlName, newArticle.title)) ++ cat.publishedArticles.map(TopicArticle.fromInput).sortBy(_.title)
      else cat.publishedArticles.map(TopicArticle.fromInput).sortBy(_.title)

    input
      .dataCategories.map(cat =>
        Topic(
          path = cleanCustomFieldName(cat.name),
          title = titles(cat.name),
          articles = addNewArticleToTopics(cat)
        )
      )
  }