Skip to content

Commit

Permalink
Use Psalm instead of Chapter as chapter title for book of Psalms (#1132)
Browse files Browse the repository at this point in the history
* Use book name instead of chapter in chapter title

* Use book name instead of chapter in chapter title (updated)

* refactored ChapterLabel
  • Loading branch information
mXaln authored Apr 26, 2024
1 parent c77a42a commit 002fb9e
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.wycliffeassociates.otter.common.data.primitives

const val PSALMS_SLUG = "psa"

object ChapterLabel {
fun of(bookSlug: String): String {
return if (bookSlug.startsWith(PSALMS_SLUG)) {
ContentLabel.PSALM.value
} else ContentLabel.CHAPTER.value
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,19 @@ package org.wycliffeassociates.otter.common.data.primitives
)
enum class ContentLabel(val value: String, val type: ContentType) {
CHAPTER("chapter", ContentType.META),
PSALM("psalm", ContentType.META),
VERSE("verse", ContentType.TEXT),
HELP_TITLE("title", ContentType.TITLE),
HELP_BODY("body", ContentType.BODY);

companion object {
fun of(contentType: ContentType) = when (contentType) {
ContentType.META -> CHAPTER
ContentType.TEXT -> VERSE
ContentType.TITLE -> HELP_TITLE
ContentType.BODY -> HELP_BODY
fun of(contentType: ContentType, bookSlug: String? = null): ContentLabel {
return when (contentType) {
ContentType.META -> if (bookSlug?.startsWith(PSALMS_SLUG) == true) PSALM else CHAPTER
ContentType.TEXT -> VERSE
ContentType.TITLE -> HELP_TITLE
ContentType.BODY -> HELP_BODY
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,12 @@
*/
package org.wycliffeassociates.otter.common.domain.resourcecontainer.project

import com.fasterxml.jackson.annotation.JsonInclude
import com.fasterxml.jackson.core.JsonFactory
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.module.kotlin.KotlinModule
import org.wycliffeassociates.otter.common.collections.OtterTree
import org.wycliffeassociates.otter.common.collections.OtterTreeNode
import org.wycliffeassociates.otter.common.data.primitives.*
import org.wycliffeassociates.otter.common.data.primitives.Collection
import org.wycliffeassociates.otter.common.domain.resourcecontainer.toCollection
import org.wycliffeassociates.otter.common.domain.versification.ParatextVersification
import org.wycliffeassociates.otter.common.domain.versification.Versification
import org.wycliffeassociates.otter.common.persistence.IDirectoryProvider
import org.wycliffeassociates.otter.common.persistence.repositories.IVersificationRepository
import org.wycliffeassociates.resourcecontainer.ResourceContainer
import org.wycliffeassociates.resourcecontainer.entity.Project
Expand All @@ -47,7 +41,7 @@ class VersificationTreeBuilder @Inject constructor(
}

private fun getVersification(container: ResourceContainer): Versification? {
var versificationCode = container.manifest.projects.firstOrNull()?.versification ?: return null
val versificationCode = container.manifest.projects.firstOrNull()?.versification ?: return null
if (versificationCode == "") return null
return versificationRepository.getVersification(versificationCode).blockingGet()
}
Expand All @@ -73,11 +67,13 @@ class VersificationTreeBuilder @Inject constructor(
)
val projectTree = OtterTree<CollectionOrContent>(project.toCollection())
val chapters = versification.getChaptersInBook(project.identifier)
val chapterLabel = ChapterLabel.of(project.identifier)

for (i in 1..chapters) {
val chapterCollection = Collection(
sort = i,
slug = "${project.identifier}_${i}",
labelKey = "chapter",
labelKey = chapterLabel,
titleKey = "$i",
resourceContainer = null
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package org.wycliffeassociates.otter.common.domain.resourcecontainer.project.mar

import org.wycliffeassociates.otter.common.collections.OtterTree
import org.wycliffeassociates.otter.common.collections.OtterTreeNode
import org.wycliffeassociates.otter.common.data.primitives.ChapterLabel
import org.wycliffeassociates.otter.common.data.primitives.Collection
import org.wycliffeassociates.otter.common.data.primitives.CollectionOrContent
import org.wycliffeassociates.otter.common.data.primitives.Content
Expand All @@ -43,7 +44,6 @@ import java.util.ArrayDeque
private val extensions = Regex(".+\\.(md|mkdn?|mdown|markdown)$", RegexOption.IGNORE_CASE)

private const val PRIMARY_COLLECTION_KEY = "project"
private const val SECONDARY_COLLECTION_KEY = "chapter"

class MarkdownProjectReader(private val isHelp: Boolean) : IProjectReader {
private val collectionForEachFile = !isHelp
Expand Down Expand Up @@ -135,7 +135,7 @@ class MarkdownProjectReader(private val isHelp: Boolean) : IProjectReader {
) = Collection(
sort = fileToSort(file),
slug = fileToSlug(file = file, projectRoot = projectRoot, project = project),
labelKey = SECONDARY_COLLECTION_KEY,
labelKey = ChapterLabel.of(fileToSlug(file = file, projectRoot = projectRoot, project = project)),
titleKey = simplifyTitle(file.nameWithoutExtension),
resourceContainer = null
)
Expand Down Expand Up @@ -220,7 +220,10 @@ class MarkdownProjectReader(private val isHelp: Boolean) : IProjectReader {
if (isHelp) return
this.children.forEach { (it as? OtterTree)?.addMetaContents() }
val labelKey = (this.value as? Collection)?.labelKey
if (labelKey == SECONDARY_COLLECTION_KEY) {
val expectedLabelKey = (this.value as? Collection)?.slug?.let {
ChapterLabel.of(it)
}
if (labelKey == expectedLabelKey) {
addChild(chapterMetaNode(this))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import com.fasterxml.jackson.annotation.JsonProperty
import com.fasterxml.jackson.annotation.JsonPropertyOrder
import jooq.Tables.CONTENT_DERIVATIVE
import org.junit.Assert
import org.wycliffeassociates.otter.common.data.primitives.ChapterLabel
import org.wycliffeassociates.otter.common.data.primitives.Collection
import org.wycliffeassociates.otter.common.data.primitives.Language
import org.wycliffeassociates.otter.common.domain.collections.CreateProject
Expand Down Expand Up @@ -136,7 +137,7 @@ class DatabaseEnvironment @Inject constructor(
Assert.assertNotNull("Retrieving resource container info", rc)

chapter.forEach { (slug, verseCount) ->
val entity = db.collectionDao.fetch(containerId = rc!!.id, label = "chapter", slug = slug)
val entity = db.collectionDao.fetch(containerId = rc!!.id, label = ChapterLabel.of(slug), slug = slug)
Assert.assertNotNull("Retrieving chapter $slug", entity)
val content = db.contentDao.fetchByCollectionId(entity!!.id)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,8 @@ class TestRcImport {
"ulb",
CollectionDescriptor(label = "bundle", slug = "ulb"),
CollectionDescriptor(label = "project", slug = "gen"),
CollectionDescriptor(label = "chapter", slug = "gen_1")
CollectionDescriptor(label = "chapter", slug = "gen_1"),
CollectionDescriptor(label = "psalm", slug = "psa_1")
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,14 @@ import org.jooq.exception.DataAccessException
import org.jooq.impl.DSL
import org.jooq.impl.SQLDataType
import org.slf4j.LoggerFactory
import org.wycliffeassociates.otter.assets.initialization.InitializeProjects
import org.wycliffeassociates.otter.common.data.primitives.ContentLabel
import org.wycliffeassociates.otter.common.data.primitives.PSALMS_SLUG
import org.wycliffeassociates.otter.common.persistence.IDirectoryProvider
import org.wycliffeassociates.otter.common.utils.SELECTED_TAKES_FROM_DB
import java.io.File
import org.wycliffeassociates.otter.common.data.primitives.CheckingStatus as CheckingStatusEnum

const val SCHEMA_VERSION = 13
const val SCHEMA_VERSION = 14
const val DATABASE_INSTALLABLE_NAME = "DATABASE"

class DatabaseMigrator(
Expand All @@ -57,6 +58,7 @@ class DatabaseMigrator(
currentVersion = migrate10to11(dsl, currentVersion)
currentVersion = migrate11to12(dsl, currentVersion)
currentVersion = migrate12to13(dsl, currentVersion)
currentVersion = migrate13to14(dsl, currentVersion)
updateDatabaseVersion(dsl, currentVersion)
}
}
Expand Down Expand Up @@ -473,6 +475,34 @@ class DatabaseMigrator(
}
}

/**
* Version 14
* Renames 'chapter' labels of Psalms collections to 'psalm'.
*/
private fun migrate13to14(dsl: DSLContext, current: Int): Int {
return if (current < 14) {
try {
dsl
.update(CollectionEntity.COLLECTION_ENTITY)
.set(CollectionEntity.COLLECTION_ENTITY.LABEL, ContentLabel.PSALM.value)
.where(
CollectionEntity.COLLECTION_ENTITY.LABEL.eq(ContentLabel.CHAPTER.value)
.and(CollectionEntity.COLLECTION_ENTITY.SLUG.startsWith(PSALMS_SLUG))
)
.execute()
} catch (e: DataAccessException) {
// Exception is thrown because the column might already exist but an existence check cannot
// be performed in sqlite.
logger.error("Error in while migrating database from version 13 to 14", e)
return 13
}
logger.info("Updated database from version 13 to 14")
14
} else {
current
}
}

private fun createWorkbookTypeTable(dsl: DSLContext) {
dsl
.createTableIfNotExists(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ class NarrationViewModel : ViewModel() {
chapterTitleProperty.set(
MessageFormat.format(
messages["chapterTitle"],
messages["chapter"],
messages[chapter.label],
chapter.title
)
)
Expand Down
1 change: 1 addition & 0 deletions jvm/workbookapp/src/main/resources/Messages_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@ recording = Recording
take = Take
takes = Takes
chapter = Chapter
psalm = Psalm
chunk = Chunk
verse = Verse
oldTestament = Old Testament
Expand Down

0 comments on commit 002fb9e

Please sign in to comment.