Skip to content

Commit

Permalink
Naming improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
grzesiek2010 committed Jan 8, 2025
1 parent eb8b324 commit d825b0a
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import org.odk.collect.db.sqlite.SQLiteDatabaseExt.getColumnNames
import org.odk.collect.db.sqlite.SQLiteDatabaseExt.query
import org.odk.collect.db.sqlite.SynchronizedDatabaseConnection
import org.odk.collect.db.sqlite.toSql
import org.odk.collect.entities.javarosa.parse.EntityItemElement
import org.odk.collect.entities.javarosa.parse.EntitySchema
import org.odk.collect.entities.storage.EntitiesRepository
import org.odk.collect.entities.storage.Entity
import org.odk.collect.shared.Query
Expand Down Expand Up @@ -214,9 +214,9 @@ class DatabaseEntitiesRepository(context: Context, dbPath: String) : EntitiesRep

return queryWithAttachedRowId(list, query.mapColumns { columnName ->
when (columnName) {
EntityItemElement.ID -> EntitiesTable.COLUMN_ID
EntityItemElement.LABEL -> EntitiesTable.COLUMN_LABEL
EntityItemElement.VERSION -> EntitiesTable.COLUMN_VERSION
EntitySchema.ID -> EntitiesTable.COLUMN_ID
EntitySchema.LABEL -> EntitiesTable.COLUMN_LABEL
EntitySchema.VERSION -> EntitiesTable.COLUMN_VERSION
else -> EntitiesTable.getPropertyColumn(columnName)
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package org.odk.collect.entities
import org.apache.commons.csv.CSVRecord
import org.javarosa.core.model.instance.SecondaryInstanceCSVParserBuilder
import org.odk.collect.entities.javarosa.finalization.EntitiesExtra
import org.odk.collect.entities.javarosa.parse.EntityItemElement
import org.odk.collect.entities.javarosa.parse.EntitySchema
import org.odk.collect.entities.javarosa.spec.EntityAction
import org.odk.collect.entities.storage.EntitiesRepository
import org.odk.collect.entities.storage.Entity
Expand Down Expand Up @@ -125,9 +125,9 @@ object LocalEntityUseCases {
private fun parseEntityFromRecord(record: CSVRecord): ServerEntity? {
val map = record.toMap()

val id = map.remove(EntityItemElement.ID)
val label = map.remove(EntityItemElement.LABEL)
val version = map.remove(EntityItemElement.VERSION)?.toInt()
val id = map.remove(EntitySchema.ID)
val label = map.remove(EntitySchema.LABEL)
val version = map.remove(EntitySchema.VERSION)?.toInt()
if (id == null || label == null || version == null) {
return null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package org.odk.collect.entities.javarosa.intance

import org.javarosa.core.model.data.StringData
import org.javarosa.core.model.instance.TreeElement
import org.odk.collect.entities.javarosa.parse.EntityItemElement
import org.odk.collect.entities.javarosa.parse.EntitySchema
import org.odk.collect.entities.storage.EntitiesRepository
import org.odk.collect.entities.storage.Entity
import org.odk.collect.shared.Query
Expand Down Expand Up @@ -46,11 +46,11 @@ class LocalEntitiesInstanceAdapter(private val entitiesRepository: EntitiesRepos
}

private fun convertToElement(entity: Entity.Saved): TreeElement {
val name = TreeElement(EntityItemElement.ID)
val label = TreeElement(EntityItemElement.LABEL)
val version = TreeElement(EntityItemElement.VERSION)
val trunkVersion = TreeElement(EntityItemElement.TRUNK_VERSION)
val branchId = TreeElement(EntityItemElement.BRANCH_ID)
val name = TreeElement(EntitySchema.ID)
val label = TreeElement(EntitySchema.LABEL)
val version = TreeElement(EntitySchema.VERSION)
val trunkVersion = TreeElement(EntitySchema.TRUNK_VERSION)
val branchId = TreeElement(EntitySchema.BRANCH_ID)

name.value = StringData(entity.id)
version.value = StringData(entity.version.toString())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.odk.collect.entities.javarosa.parse

object EntityItemElement {
object EntitySchema {
const val ID = "name"
const val LABEL = "label"
const val VERSION = "__version"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.odk.collect.entities.storage

import org.odk.collect.entities.javarosa.parse.EntityItemElement
import org.odk.collect.entities.javarosa.parse.EntitySchema
import org.odk.collect.shared.Query

class InMemEntitiesRepository : EntitiesRepository {
Expand Down Expand Up @@ -56,9 +56,9 @@ class InMemEntitiesRepository : EntitiesRepository {
is Query.Eq -> {
entities.filter {
val fieldName: String? = when (query.column) {
EntityItemElement.ID -> it.id
EntityItemElement.LABEL -> it.label
EntityItemElement.VERSION -> it.version.toString()
EntitySchema.ID -> it.id
EntitySchema.LABEL -> it.label
EntitySchema.VERSION -> it.version.toString()
else -> it.properties.find { propertyName ->
propertyName.first == query.column
}?.second
Expand All @@ -69,9 +69,9 @@ class InMemEntitiesRepository : EntitiesRepository {
is Query.NotEq -> {
entities.filter {
val fieldName: String? = when (query.column) {
EntityItemElement.ID -> it.id
EntityItemElement.LABEL -> it.label
EntityItemElement.VERSION -> it.version.toString()
EntitySchema.ID -> it.id
EntitySchema.LABEL -> it.label
EntitySchema.VERSION -> it.version.toString()
else -> it.properties.find { propertyName ->
propertyName.first == query.column
}?.second
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import org.hamcrest.Matchers.not
import org.junit.Test
import org.odk.collect.entities.javarosa.finalization.EntitiesExtra
import org.odk.collect.entities.javarosa.finalization.FormEntity
import org.odk.collect.entities.javarosa.parse.EntityItemElement
import org.odk.collect.entities.javarosa.parse.EntitySchema
import org.odk.collect.entities.javarosa.spec.EntityAction
import org.odk.collect.entities.storage.EntitiesRepository
import org.odk.collect.entities.storage.Entity
Expand Down Expand Up @@ -458,9 +458,9 @@ class LocalEntityUseCasesTest {
private fun createEntityList(vararg entities: Entity): File {
if (entities.isNotEmpty()) {
val header = listOf(
EntityItemElement.ID,
EntityItemElement.LABEL,
EntityItemElement.VERSION
EntitySchema.ID,
EntitySchema.LABEL,
EntitySchema.VERSION
) + entities[0].properties.map { it.first }

val rows = entities.map { entity ->
Expand All @@ -474,9 +474,9 @@ class LocalEntityUseCasesTest {
return createCsv(header, *rows)
} else {
val header = listOf(
EntityItemElement.ID,
EntityItemElement.LABEL,
EntityItemElement.VERSION
EntitySchema.ID,
EntitySchema.LABEL,
EntitySchema.VERSION
)

return createCsv(header)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import org.hamcrest.CoreMatchers.equalTo
import org.hamcrest.MatcherAssert.assertThat
import org.junit.Test
import org.odk.collect.entities.javarosa.intance.LocalEntitiesInstanceProvider
import org.odk.collect.entities.javarosa.parse.EntityItemElement
import org.odk.collect.entities.javarosa.parse.EntitySchema
import org.odk.collect.entities.storage.Entity
import org.odk.collect.entities.storage.InMemEntitiesRepository

Expand Down Expand Up @@ -48,7 +48,7 @@ class LocalEntitiesInstanceProviderTest {

val item = instance.getChildAt(0)!!
assertThat(item.numChildren, equalTo(5))
assertThat(item.getFirstChild(EntityItemElement.VERSION)?.value?.value, equalTo("1"))
assertThat(item.getFirstChild(EntitySchema.VERSION)?.value?.value, equalTo("1"))
}

@Test
Expand All @@ -67,7 +67,7 @@ class LocalEntitiesInstanceProviderTest {

val item = instance.getChildAt(0)!!
assertThat(item.numChildren, equalTo(5))
assertThat(item.getFirstChild(EntityItemElement.TRUNK_VERSION)?.value?.value, equalTo("1"))
assertThat(item.getFirstChild(EntitySchema.TRUNK_VERSION)?.value?.value, equalTo("1"))
}

@Test
Expand All @@ -87,7 +87,7 @@ class LocalEntitiesInstanceProviderTest {
val item = instance.getChildAt(0)!!
assertThat(item.numChildren, equalTo(5))
assertThat(
item.getFirstChild(EntityItemElement.BRANCH_ID)?.value?.value,
item.getFirstChild(EntitySchema.BRANCH_ID)?.value?.value,
equalTo("branch-1")
)
}
Expand All @@ -107,7 +107,7 @@ class LocalEntitiesInstanceProviderTest {
assertThat(instance.numChildren, equalTo(1))

val item = instance.getChildAt(0)!!
assertThat(item.getFirstChild(EntityItemElement.TRUNK_VERSION)?.value, equalTo(null))
assertThat(item.getFirstChild(EntitySchema.TRUNK_VERSION)?.value, equalTo(null))
}

@Test
Expand Down Expand Up @@ -184,6 +184,6 @@ class LocalEntitiesInstanceProviderTest {
assertThat(instance.numChildren, equalTo(1))

val item = instance.getChildAt(0)!!
assertThat(item.getFirstChild(EntityItemElement.LABEL)?.value, equalTo(null))
assertThat(item.getFirstChild(EntitySchema.LABEL)?.value, equalTo(null))
}
}

0 comments on commit d825b0a

Please sign in to comment.