From 03c587028043cc0f1788efa2298b740b54aaccd3 Mon Sep 17 00:00:00 2001 From: njhlai Date: Wed, 16 Feb 2022 00:00:07 -0800 Subject: [PATCH] Added legacy study processing --- .../upgrades/V3StudyMigrationUpgrade.kt | 56 ++++++++++++++++++- 1 file changed, 53 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/com/openlattice/mechanic/upgrades/V3StudyMigrationUpgrade.kt b/src/main/kotlin/com/openlattice/mechanic/upgrades/V3StudyMigrationUpgrade.kt index dabdd7c7..5a6aa4d2 100644 --- a/src/main/kotlin/com/openlattice/mechanic/upgrades/V3StudyMigrationUpgrade.kt +++ b/src/main/kotlin/com/openlattice/mechanic/upgrades/V3StudyMigrationUpgrade.kt @@ -56,8 +56,8 @@ class V3StudyMigrationUpgrade( // mappings of v2 fqn to v3 column names for participants(v2)/candidates(v3) private val fqnToCandidatesColumnName = mapOf( - FullQualifiedName("Person.GivenName") to "first_name", - FullQualifiedName("Person.SurName") to "last_name", + FullQualifiedName("nc.PersonGivenName") to "first_name", + FullQualifiedName("nc.PersonSurName") to "last_name", FullQualifiedName("general.fullname") to "name", FullQualifiedName("nc.PersonBirthDate") to "dob", FullQualifiedName("nc.SubjectIdentification") to "participant_id", @@ -84,6 +84,24 @@ class V3StudyMigrationUpgrade( ) ).toMap() + // Property Types of general.person (for legacy) + private val legacyParticipantPropertyTypes = propertyTypes.getAll( + setOf( + // "nc.PersonGivenName", + UUID.fromString("e9a0b4dc-5298-47c1-8837-20af172379a5"), + // "nc.PersonSurName", + UUID.fromString("7b038634-a0b4-4ce1-a04f-85d1775937aa"), + // "general.fullname", + UUID.fromString("70d2ff1c-2450-4a47-a954-a7641b7399ae"), + // "nc.PersonBirthDate", + UUID.fromString("1e6ff0f0-0545-4368-b878-677823459e57"), + // "nc.SubjectIdentification", + UUID.fromString("5260cfbd-bfa4-40c1-ade5-cd83cc9f99b2"), + // "ol.status", + UUID.fromString("2a45205e-703c-43eb-a060-921bf7245f6a") + ) + ).toMap() + // entity type of association entity general.participatedin private val associationParticipatedInEntityType = UUID.fromString("34836b35-76b1-4ecf-b588-c22ad19e2378") @@ -148,6 +166,38 @@ class V3StudyMigrationUpgrade( logger.info("================================") logger.info("================================") } + + // deal with legacy studies + logger.info("Legacy clean-up") + dataQueryService.getEntitiesWithPropertyTypeFqns( + mapOf(UUID.fromString("574e04d0-48ce-4f06-a30b-54bbd11a4754") to Optional.of(setOf())), + mapOf(UUID.fromString("574e04d0-48ce-4f06-a30b-54bbd11a4754") to studiesPropertyTypes), + emptyMap(), + EnumSet.of(MetadataOption.LAST_WRITE), + Optional.empty(), + false + ).forEach { (legacyStudyEkid, _) -> + logger.info("Processing all legacy participants of $legacyStudyEkid") + try { + entitySets.entrySet( + Predicates.equal("name", "chronicle_participants_${legacyStudyEkid}") + ).forEach { participantESID -> + dataQueryService.getEntitiesWithPropertyTypeFqns( + mapOf(participantESID to Optional.of(setOf())), + mapOf(participantESID to legacyParticipantPropertyTypes), + emptyMap(), + EnumSet.noneOf(MetadataOption::class.java), + Optional.empty(), + false + ).forEach { (_, legacyParticipantFqnToValue) + logger.info("Inserting participant: $legacyParticipantFqnToValue into candidates") + insertIntoCandidatesTable(connection, legacyStudyEkid, legacyParticipantFqnToValue) + } + } + } catch (ex: Exception) { + logger.error("An error occurred processing legacy participants of $legacyStudyEkid", ex) + } + } } return true @@ -219,7 +269,7 @@ class V3StudyMigrationUpgrade( val neighborFqnToValue = neighbor.neighborDetails.get() + neighbor.associationDetails.filterKeys { it == FullQualifiedName("ol.status") } - logger.info("Inserting participant: $neighborFqnToValue into study_participants") + logger.info("Inserting participant: $neighborFqnToValue into candidates") insertIntoCandidatesTable(conn, studyEkid, neighborFqnToValue) } }