Skip to content

Commit

Permalink
Cleaned up build errors
Browse files Browse the repository at this point in the history
  • Loading branch information
njhlai committed Feb 16, 2022
1 parent b2202b3 commit 7b57367
Showing 1 changed file with 16 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -147,18 +147,19 @@ class V3StudyMigrationUpgrade(
EnumSet.of(MetadataOption.LAST_WRITE),
Optional.empty(),
false
).forEach { (v2Id, fqnToValue) ->
logger.info("Processing study with entity_key_id $v2Id")
).forEach { (studyEkid, fqnToValue) ->
logger.info("Processing study with entity_key_id $studyEkid")

// process study entities into a Study table
logger.info("Inserting study $fqnToValue into studies")
if (insertIntoStudiesTable(connection, orgId, v2Id, fqnToValue)) {
if (insertIntoStudiesTable(connection, orgId, studyEkid, fqnToValue)) {
// process participants of studies
logger.info("Processing all participants of $v2Id")
logger.info("Processing all participants of $studyEkid")
try {
processParticipantsOfStudy(connection, v2Id, orgStudyEntitySetIds, orgMaybeParticipantEntitySetIds)
val studyStringId = fqnToValue[FullQualifiedName("general.stringid")]!!.first() as String
processParticipantsOfStudy(connection, studyEkid, studyStringId, orgStudyEntitySetIds, orgMaybeParticipantEntitySetIds)
} catch (ex: Exception) {
logger.error("An error occurred processing participants of $v2Id", ex)
logger.error("An error occurred processing participants of $studyEkid", ex)
}
}
}
Expand All @@ -184,6 +185,7 @@ class V3StudyMigrationUpgrade(
entitySets.keySet(
Predicates.equal<UUID, EntitySet>("name", "chronicle_participants_${legacyStudyFqnToValue.getOrDefault(FullQualifiedName("general.stringid"), null)}")
).forEach { participantESID ->
val legacyStudyStringId = legacyStudyFqnToValue[FullQualifiedName("general.stringid")]!!.first() as String
dataQueryService.getEntitiesWithPropertyTypeFqns(
mapOf(participantESID to Optional.of(setOf<UUID>())),
mapOf(participantESID to legacyParticipantPropertyTypes),
Expand All @@ -193,7 +195,7 @@ class V3StudyMigrationUpgrade(
false
).forEach { (_, legacyParticipantFqnToValue) ->
logger.info("Inserting participant: $legacyParticipantFqnToValue into candidates")
insertIntoCandidatesTable(connection, legacyStudyEkid, legacyParticipantFqnToValue)
insertIntoCandidatesTable(connection, legacyStudyStringId, legacyParticipantFqnToValue)
}
}
} catch (ex: Exception) {
Expand All @@ -206,7 +208,7 @@ class V3StudyMigrationUpgrade(
return true
}

private fun insertIntoStudiesTable(conn: Connection, orgId: UUID, studyId: UUID, fqnToValue: Map<FullQualifiedName, MutableSet<Any>>): Boolean {
private fun insertIntoStudiesTable(conn: Connection, orgId: UUID, studyEkid: UUID, fqnToValue: Map<FullQualifiedName, MutableSet<Any>>): Boolean {
val columns = fqnToStudiesColumnName.filter { fqnToValue.containsKey(it.key) }
if (columns.isEmpty()) {
logger.info("No useful property to record for study ${fqnToValue}, skipping")
Expand All @@ -222,7 +224,7 @@ class V3StudyMigrationUpgrade(
try {
var index = 1

ps.setObject(index++, studyId)
ps.setObject(index++, studyEkid)
ps.setObject(index++, orgId)
columns.keys.forEach {
when (it.namespace) {
Expand All @@ -246,7 +248,7 @@ class V3StudyMigrationUpgrade(
return true
}

private fun processParticipantsOfStudy(conn: Connection, studyEkid: UUID, orgStudyEntitySetIds: Set<UUID>, orgMaybeParticipantEntitySetIds: Set<UUID>) {
private fun processParticipantsOfStudy(conn: Connection, studyEkid: UUID, studyStringId: String, orgStudyEntitySetIds: Set<UUID>, orgMaybeParticipantEntitySetIds: Set<UUID>) {

val filter = EntityNeighborsFilter(setOf(studyEkid), Optional.of(orgMaybeParticipantEntitySetIds), Optional.of(orgStudyEntitySetIds), Optional.empty())

Expand All @@ -273,28 +275,28 @@ class V3StudyMigrationUpgrade(
val neighborFqnToValue = neighbor.neighborDetails.get() + neighbor.associationDetails.filterKeys { it == FullQualifiedName("ol.status") }

logger.info("Inserting participant: $neighborFqnToValue into candidates")
insertIntoCandidatesTable(conn, studyEkid, neighborFqnToValue)
insertIntoCandidatesTable(conn, studyStringId, neighborFqnToValue)
}
}
}

private fun insertIntoCandidatesTable(conn: Connection, studyId: UUID, fqnToValue: Map<FullQualifiedName, Set<Any>>) {
private fun insertIntoCandidatesTable(conn: Connection, studyStringId: String, fqnToValue: Map<FullQualifiedName, Set<Any>>) {
val columns = fqnToCandidatesColumnName.filter { fqnToValue.containsKey(it.key) }
if (columns.isEmpty()) {
logger.info("No useful property to record for participant ${fqnToValue}, skipping")
return
}

val INSERT_INTO_CANDIDATE_SQL = """
INSERT INTO candidates (v2_study_ekid, ${columns.values.joinToString()}) VALUES (?${",?".repeat(columns.size)})
INSERT INTO candidates (v2_study_id, ${columns.values.joinToString()}) VALUES (?${",?".repeat(columns.size)})
""".trimIndent()
logger.debug(INSERT_INTO_CANDIDATE_SQL)

conn.prepareStatement(INSERT_INTO_CANDIDATE_SQL).use { ps ->
try {
var index = 1

ps.setObject(index++, studyId)
ps.setString(index++, studyStringId)
columns.keys.forEach {
when (it.name) {
"PersonBirthDate" -> ps.setObject(index++, fqnToValue[it]!!.first() as LocalDate)
Expand Down

0 comments on commit 7b57367

Please sign in to comment.