diff --git a/api-admin/src/test/java/bio/terra/pearl/api/admin/service/PopulateExtServiceTests.java b/api-admin/src/test/java/bio/terra/pearl/api/admin/service/PopulateExtServiceTests.java index aec19df5f8..6385000327 100644 --- a/api-admin/src/test/java/bio/terra/pearl/api/admin/service/PopulateExtServiceTests.java +++ b/api-admin/src/test/java/bio/terra/pearl/api/admin/service/PopulateExtServiceTests.java @@ -9,6 +9,7 @@ import bio.terra.pearl.api.admin.BaseSpringBootTest; import bio.terra.pearl.api.admin.service.auth.SuperuserOnly; import bio.terra.pearl.api.admin.service.auth.context.PortalStudyEnvAuthContext; +import bio.terra.pearl.core.factory.StudyEnvironmentBundle; import bio.terra.pearl.core.factory.StudyEnvironmentFactory; import bio.terra.pearl.core.factory.admin.AdminUserFactory; import bio.terra.pearl.core.model.EnvironmentName; @@ -59,7 +60,7 @@ public void allMethodsAuthed(TestInfo info) { @Test @Transactional public void populatesNewEnrolleeType(TestInfo info) { - StudyEnvironmentFactory.StudyEnvironmentBundle bundle = + StudyEnvironmentBundle bundle = studyEnvironmentFactory.buildBundle(getTestName(info), EnvironmentName.live); AdminUser operator = adminUserFactory.buildPersisted(getTestName(info), true); populateExtService.populateEnrollee( diff --git a/api-admin/src/test/java/bio/terra/pearl/api/admin/service/auth/EnforcePortalEnrolleePermissionTest.java b/api-admin/src/test/java/bio/terra/pearl/api/admin/service/auth/EnforcePortalEnrolleePermissionTest.java index 6b0f9840ca..ec13c4305b 100644 --- a/api-admin/src/test/java/bio/terra/pearl/api/admin/service/auth/EnforcePortalEnrolleePermissionTest.java +++ b/api-admin/src/test/java/bio/terra/pearl/api/admin/service/auth/EnforcePortalEnrolleePermissionTest.java @@ -4,6 +4,7 @@ import bio.terra.pearl.api.admin.BaseSpringBootTest; import bio.terra.pearl.api.admin.service.auth.context.PortalEnrolleeAuthContext; +import bio.terra.pearl.core.factory.StudyEnvironmentBundle; import bio.terra.pearl.core.factory.StudyEnvironmentFactory; import bio.terra.pearl.core.factory.admin.*; import bio.terra.pearl.core.factory.participant.EnrolleeFactory; @@ -38,7 +39,7 @@ public class EnforcePortalEnrolleePermissionTest extends BaseSpringBootTest { @Test @Transactional public void testEnforceEnrollee(TestInfo info) { - StudyEnvironmentFactory.StudyEnvironmentBundle bundle = + StudyEnvironmentBundle bundle = studyEnvironmentFactory.buildBundle(getTestName(info), EnvironmentName.sandbox); String portalShortcode = bundle.getPortal().getShortcode(); @@ -59,7 +60,7 @@ public void testEnforceEnrollee(TestInfo info) { @Test @Transactional public void testWrongEnvironmentThrows(TestInfo info) { - StudyEnvironmentFactory.StudyEnvironmentBundle bundle = + StudyEnvironmentBundle bundle = studyEnvironmentFactory.buildBundle(getTestName(info), EnvironmentName.sandbox); String portalShortcode = bundle.getPortal().getShortcode(); @@ -87,7 +88,7 @@ public void testWrongEnvironmentThrows(TestInfo info) { @Test @Transactional public void testEnrolleeInDifferentPortalThrows(TestInfo info) { - StudyEnvironmentFactory.StudyEnvironmentBundle bundle = + StudyEnvironmentBundle bundle = studyEnvironmentFactory.buildBundle(getTestName(info), EnvironmentName.sandbox); String portalShortcode = bundle.getPortal().getShortcode(); @@ -113,7 +114,7 @@ public void testEnrolleeInDifferentPortalThrows(TestInfo info) { @Test @Transactional public void testAdminNotInPortal(TestInfo info) { - StudyEnvironmentFactory.StudyEnvironmentBundle bundle = + StudyEnvironmentBundle bundle = studyEnvironmentFactory.buildBundle(getTestName(info), EnvironmentName.sandbox); String portalShortcode = bundle.getPortal().getShortcode(); @@ -140,7 +141,7 @@ public void testAdminNotInPortal(TestInfo info) { @Test @Transactional public void testBasePermAdminInPortal(TestInfo info) { - StudyEnvironmentFactory.StudyEnvironmentBundle bundle = + StudyEnvironmentBundle bundle = studyEnvironmentFactory.buildBundle(getTestName(info), EnvironmentName.sandbox); String portalShortcode = bundle.getPortal().getShortcode(); @@ -163,7 +164,7 @@ public void testBasePermAdminInPortal(TestInfo info) { @Test @Transactional public void testAdminDoesNotHavePermission(TestInfo info) { - StudyEnvironmentFactory.StudyEnvironmentBundle bundle = + StudyEnvironmentBundle bundle = studyEnvironmentFactory.buildBundle(getTestName(info), EnvironmentName.sandbox); String portalShortcode = bundle.getPortal().getShortcode(); @@ -193,7 +194,7 @@ public void testAdminDoesNotHavePermission(TestInfo info) { @Test @Transactional public void testUserInPortalWithPermission(TestInfo info) { - StudyEnvironmentFactory.StudyEnvironmentBundle bundle = + StudyEnvironmentBundle bundle = studyEnvironmentFactory.buildBundle(getTestName(info), EnvironmentName.sandbox); String portalShortcode = bundle.getPortal().getShortcode(); diff --git a/api-admin/src/test/java/bio/terra/pearl/api/admin/service/enrollee/EnrolleeExtServiceTests.java b/api-admin/src/test/java/bio/terra/pearl/api/admin/service/enrollee/EnrolleeExtServiceTests.java index 401a236936..a50f915042 100644 --- a/api-admin/src/test/java/bio/terra/pearl/api/admin/service/enrollee/EnrolleeExtServiceTests.java +++ b/api-admin/src/test/java/bio/terra/pearl/api/admin/service/enrollee/EnrolleeExtServiceTests.java @@ -4,8 +4,10 @@ import static org.hamcrest.Matchers.equalTo; import bio.terra.pearl.api.admin.BaseSpringBootTest; +import bio.terra.pearl.core.factory.StudyEnvironmentBundle; import bio.terra.pearl.core.factory.StudyEnvironmentFactory; import bio.terra.pearl.core.factory.admin.PortalAdminUserFactory; +import bio.terra.pearl.core.factory.participant.EnrolleeBundle; import bio.terra.pearl.core.factory.participant.EnrolleeFactory; import bio.terra.pearl.core.model.EnvironmentName; import bio.terra.pearl.core.model.admin.AdminUser; @@ -28,13 +30,13 @@ public class EnrolleeExtServiceTests extends BaseSpringBootTest { @Test @Transactional public void testFindById(TestInfo info) { - StudyEnvironmentFactory.StudyEnvironmentBundle bundle = + StudyEnvironmentBundle bundle = studyEnvironmentFactory.buildBundle(getTestName(info), EnvironmentName.sandbox); AdminUser operator = portalAdminUserFactory .buildPersistedWithPortals(getTestName(info), List.of(bundle.getPortal())) .user(); - EnrolleeFactory.EnrolleeBundle enrollee1 = + EnrolleeBundle enrollee1 = enrolleeFactory.buildWithPortalUser( getTestName(info), bundle.getPortalEnv(), bundle.getStudyEnv()); diff --git a/api-admin/src/test/java/bio/terra/pearl/api/admin/service/enrollee/EnrolleeRelationExtServiceTest.java b/api-admin/src/test/java/bio/terra/pearl/api/admin/service/enrollee/EnrolleeRelationExtServiceTest.java index 9b922f41d2..efa9ccc5d4 100644 --- a/api-admin/src/test/java/bio/terra/pearl/api/admin/service/enrollee/EnrolleeRelationExtServiceTest.java +++ b/api-admin/src/test/java/bio/terra/pearl/api/admin/service/enrollee/EnrolleeRelationExtServiceTest.java @@ -7,8 +7,10 @@ import bio.terra.pearl.api.admin.AuthTestUtils; import bio.terra.pearl.api.admin.BaseSpringBootTest; import bio.terra.pearl.api.admin.service.auth.context.PortalStudyEnvAuthContext; +import bio.terra.pearl.core.factory.StudyEnvironmentBundle; import bio.terra.pearl.core.factory.StudyEnvironmentFactory; import bio.terra.pearl.core.factory.admin.AdminUserFactory; +import bio.terra.pearl.core.factory.participant.EnrolleeAndProxy; import bio.terra.pearl.core.factory.participant.EnrolleeFactory; import bio.terra.pearl.core.factory.participant.FamilyFactory; import bio.terra.pearl.core.model.EnvironmentName; @@ -48,13 +50,13 @@ public void testAuthentication() { @Transactional public void testFindRelationsForTargetEnrolleeOnlyInCorrectStudyEnv(TestInfo info) { AdminUser operator = adminUserFactory.buildPersisted(getTestName(info), true); - StudyEnvironmentFactory.StudyEnvironmentBundle studyEnvBundle = + StudyEnvironmentBundle studyEnvBundle = studyEnvironmentFactory.buildBundle(getTestName(info), EnvironmentName.sandbox); - EnrolleeFactory.EnrolleeAndProxy enrolleeAndProxy = + EnrolleeAndProxy enrolleeAndProxy = enrolleeFactory.buildProxyAndGovernedEnrollee( getTestName(info), studyEnvBundle.getPortalEnv(), studyEnvBundle.getStudyEnv()); - StudyEnvironmentFactory.StudyEnvironmentBundle otherStudyEnv = + StudyEnvironmentBundle otherStudyEnv = studyEnvironmentFactory.buildBundle(getTestName(info), EnvironmentName.sandbox); List relations = @@ -95,7 +97,7 @@ public void testFindRelationsForTargetEnrolleeOnlyInCorrectStudyEnv(TestInfo inf @Transactional public void testCannotCreateBetweenDifferentStudyEnvs(TestInfo info) { AdminUser operator = adminUserFactory.buildPersisted(getTestName(info), true); - StudyEnvironmentFactory.StudyEnvironmentBundle studyEnvBundle = + StudyEnvironmentBundle studyEnvBundle = studyEnvironmentFactory.buildBundle(getTestName(info), EnvironmentName.sandbox); Enrollee enrollee1 = enrolleeFactory.buildPersisted(getTestName(info), studyEnvBundle.getStudyEnv()); diff --git a/api-admin/src/test/java/bio/terra/pearl/api/admin/service/enrollee/ParticipantTaskExtServiceTests.java b/api-admin/src/test/java/bio/terra/pearl/api/admin/service/enrollee/ParticipantTaskExtServiceTests.java index 954aeeb757..c187818d11 100644 --- a/api-admin/src/test/java/bio/terra/pearl/api/admin/service/enrollee/ParticipantTaskExtServiceTests.java +++ b/api-admin/src/test/java/bio/terra/pearl/api/admin/service/enrollee/ParticipantTaskExtServiceTests.java @@ -6,8 +6,10 @@ import bio.terra.pearl.api.admin.BaseSpringBootTest; import bio.terra.pearl.api.admin.service.auth.AuthUtilService; +import bio.terra.pearl.core.factory.StudyEnvironmentBundle; import bio.terra.pearl.core.factory.StudyEnvironmentFactory; import bio.terra.pearl.core.factory.admin.PortalAdminUserFactory; +import bio.terra.pearl.core.factory.participant.EnrolleeBundle; import bio.terra.pearl.core.factory.participant.EnrolleeFactory; import bio.terra.pearl.core.factory.participant.ParticipantTaskFactory; import bio.terra.pearl.core.model.EnvironmentName; @@ -37,16 +39,16 @@ public class ParticipantTaskExtServiceTests extends BaseSpringBootTest { @Test @Transactional public void testUpdateTasksForSurvey(TestInfo info) { - StudyEnvironmentFactory.StudyEnvironmentBundle bundle = + StudyEnvironmentBundle bundle = studyEnvironmentFactory.buildBundle(getTestName(info), EnvironmentName.sandbox); AdminUser operator = portalAdminUserFactory .buildPersistedWithPortals(getTestName(info), List.of(bundle.getPortal())) .user(); - EnrolleeFactory.EnrolleeBundle enrollee1 = + EnrolleeBundle enrollee1 = enrolleeFactory.buildWithPortalUser( getTestName(info), bundle.getPortalEnv(), bundle.getStudyEnv()); - EnrolleeFactory.EnrolleeBundle enrollee2 = + EnrolleeBundle enrollee2 = enrolleeFactory.buildWithPortalUser( getTestName(info), bundle.getPortalEnv(), bundle.getStudyEnv()); diff --git a/api-admin/src/test/java/bio/terra/pearl/api/admin/service/family/FamilyExtServiceTest.java b/api-admin/src/test/java/bio/terra/pearl/api/admin/service/family/FamilyExtServiceTest.java index 69f5ed910b..3e217e7139 100644 --- a/api-admin/src/test/java/bio/terra/pearl/api/admin/service/family/FamilyExtServiceTest.java +++ b/api-admin/src/test/java/bio/terra/pearl/api/admin/service/family/FamilyExtServiceTest.java @@ -7,6 +7,7 @@ import bio.terra.pearl.api.admin.AuthTestUtils; import bio.terra.pearl.api.admin.BaseSpringBootTest; import bio.terra.pearl.api.admin.service.auth.context.PortalStudyEnvAuthContext; +import bio.terra.pearl.core.factory.StudyEnvironmentBundle; import bio.terra.pearl.core.factory.StudyEnvironmentFactory; import bio.terra.pearl.core.factory.admin.AdminUserFactory; import bio.terra.pearl.core.factory.participant.EnrolleeFactory; @@ -63,9 +64,9 @@ public void testAuthentication() { @Transactional public void testFindOnlyInCorrectStudyEnv(TestInfo info) { AdminUser operator = adminUserFactory.buildPersisted(getTestName(info), true); - StudyEnvironmentFactory.StudyEnvironmentBundle bundle = + StudyEnvironmentBundle bundle = studyEnvironmentFactory.buildBundle(getTestName(info), EnvironmentName.sandbox); - StudyEnvironmentFactory.StudyEnvironmentBundle otherBundle = + StudyEnvironmentBundle otherBundle = studyEnvironmentFactory.buildBundle(getTestName(info), EnvironmentName.sandbox); StudyEnvironment studyEnv = bundle.getStudyEnv(); @@ -129,7 +130,7 @@ public void testFindOnlyInCorrectStudyEnv(TestInfo info) { @Transactional public void testAddMemberOnlyInCorrectStudyEnv(TestInfo info) { AdminUser operator = adminUserFactory.buildPersisted(getTestName(info), true); - StudyEnvironmentFactory.StudyEnvironmentBundle bundle = + StudyEnvironmentBundle bundle = studyEnvironmentFactory.buildBundle(getTestName(info), EnvironmentName.sandbox); Enrollee enrollee = @@ -170,7 +171,7 @@ public void testAddMemberOnlyInCorrectStudyEnv(TestInfo info) { @Transactional public void createAlsoAddsProbandToFamily(TestInfo info) { AdminUser operator = adminUserFactory.buildPersisted(getTestName(info), true); - StudyEnvironmentFactory.StudyEnvironmentBundle bundle = + StudyEnvironmentBundle bundle = studyEnvironmentFactory.buildBundle(getTestName(info), EnvironmentName.sandbox); Enrollee enrollee = diff --git a/api-admin/src/test/java/bio/terra/pearl/api/admin/service/forms/SurveyExtServiceTests.java b/api-admin/src/test/java/bio/terra/pearl/api/admin/service/forms/SurveyExtServiceTests.java index 9dee2892f1..8108e33b49 100644 --- a/api-admin/src/test/java/bio/terra/pearl/api/admin/service/forms/SurveyExtServiceTests.java +++ b/api-admin/src/test/java/bio/terra/pearl/api/admin/service/forms/SurveyExtServiceTests.java @@ -9,6 +9,7 @@ import bio.terra.pearl.api.admin.service.auth.SandboxOnly; import bio.terra.pearl.api.admin.service.auth.context.PortalAuthContext; import bio.terra.pearl.api.admin.service.auth.context.PortalStudyEnvAuthContext; +import bio.terra.pearl.core.factory.StudyEnvironmentBundle; import bio.terra.pearl.core.factory.StudyEnvironmentFactory; import bio.terra.pearl.core.factory.admin.AdminUserBundle; import bio.terra.pearl.core.factory.admin.AdminUserFactory; @@ -97,7 +98,7 @@ public void getRequiresSurveyMatchedToPortal(TestInfo info) { @Transactional public void replaceStudyEnvSurvey(TestInfo testInfo) { AdminUser operator = adminUserFactory.buildPersisted(getTestName(testInfo), true); - StudyEnvironmentFactory.StudyEnvironmentBundle bundle = + StudyEnvironmentBundle bundle = studyEnvironmentFactory.buildBundle(getTestName(testInfo), EnvironmentName.sandbox); Survey survey1 = surveyFactory.buildPersisted(getTestName(testInfo)); Survey survey2 = surveyService.createNewVersion(bundle.getPortal().getId(), survey1); @@ -133,7 +134,7 @@ public void replaceStudyEnvSurvey(TestInfo testInfo) { @Transactional public void updateConfiguredSurveys(TestInfo testInfo) { AdminUser operator = adminUserFactory.buildPersisted(getTestName(testInfo), true); - StudyEnvironmentFactory.StudyEnvironmentBundle bundle = + StudyEnvironmentBundle bundle = studyEnvironmentFactory.buildBundle(getTestName(testInfo), EnvironmentName.sandbox); Survey survey1 = surveyFactory.buildPersisted(getTestName(testInfo), bundle.getPortal().getId()); diff --git a/api-admin/src/test/java/bio/terra/pearl/api/admin/service/notifications/NotificationExtServiceTests.java b/api-admin/src/test/java/bio/terra/pearl/api/admin/service/notifications/NotificationExtServiceTests.java index fa61165c66..f3758c9621 100644 --- a/api-admin/src/test/java/bio/terra/pearl/api/admin/service/notifications/NotificationExtServiceTests.java +++ b/api-admin/src/test/java/bio/terra/pearl/api/admin/service/notifications/NotificationExtServiceTests.java @@ -6,6 +6,7 @@ import bio.terra.pearl.api.admin.BaseSpringBootTest; import bio.terra.pearl.core.factory.notification.TriggerFactory; +import bio.terra.pearl.core.factory.participant.EnrolleeBundle; import bio.terra.pearl.core.factory.participant.EnrolleeFactory; import bio.terra.pearl.core.model.EnvironmentName; import bio.terra.pearl.core.model.admin.AdminUser; @@ -43,8 +44,7 @@ public class NotificationExtServiceTests extends BaseSpringBootTest { @Transactional public void testSendAdHocNotification(TestInfo info) throws Exception { AdminUser user = AdminUser.builder().superuser(true).build(); - EnrolleeFactory.EnrolleeBundle enrolleeBundle = - enrolleeFactory.buildWithPortalUser(getTestName(info)); + EnrolleeBundle enrolleeBundle = enrolleeFactory.buildWithPortalUser(getTestName(info)); Portal portal = portalService.find(enrolleeBundle.portalId()).get(); Study study = studyService diff --git a/api-admin/src/test/java/bio/terra/pearl/api/admin/service/notifications/SendgridEventServiceTests.java b/api-admin/src/test/java/bio/terra/pearl/api/admin/service/notifications/SendgridEventServiceTests.java index 3120814a46..725de99d38 100644 --- a/api-admin/src/test/java/bio/terra/pearl/api/admin/service/notifications/SendgridEventServiceTests.java +++ b/api-admin/src/test/java/bio/terra/pearl/api/admin/service/notifications/SendgridEventServiceTests.java @@ -9,6 +9,7 @@ import bio.terra.pearl.core.factory.StudyEnvironmentFactory; import bio.terra.pearl.core.factory.notification.NotificationFactory; import bio.terra.pearl.core.factory.notification.TriggerFactory; +import bio.terra.pearl.core.factory.participant.EnrolleeBundle; import bio.terra.pearl.core.factory.participant.EnrolleeFactory; import bio.terra.pearl.core.factory.portal.PortalEnvironmentFactory; import bio.terra.pearl.core.model.notification.*; @@ -56,7 +57,7 @@ public void testCorrelationSingleEvent(TestInfo info) { PortalEnvironment portalEnv = portalEnvironmentFactory.buildPersisted(getTestName(info)); StudyEnvironment studyEnv = studyEnvironmentFactory.buildPersisted(portalEnv, getTestName(info)); - EnrolleeFactory.EnrolleeBundle enrolleeBundle = + EnrolleeBundle enrolleeBundle = enrolleeFactory.buildWithPortalUser(getTestName(info), portalEnv, studyEnv); Trigger trigger = @@ -88,7 +89,7 @@ public void testCorrelationBatchedEvents(TestInfo info) { PortalEnvironment portalEnv = portalEnvironmentFactory.buildPersisted(getTestName(info)); StudyEnvironment studyEnv = studyEnvironmentFactory.buildPersisted(portalEnv, getTestName(info)); - EnrolleeFactory.EnrolleeBundle enrolleeBundle = + EnrolleeBundle enrolleeBundle = enrolleeFactory.buildWithPortalUser(getTestName(info), portalEnv, studyEnv); Trigger trigger = diff --git a/api-admin/src/test/java/bio/terra/pearl/api/admin/service/notifications/TriggerExtServiceTests.java b/api-admin/src/test/java/bio/terra/pearl/api/admin/service/notifications/TriggerExtServiceTests.java index 8edefb3021..0e18b7a577 100644 --- a/api-admin/src/test/java/bio/terra/pearl/api/admin/service/notifications/TriggerExtServiceTests.java +++ b/api-admin/src/test/java/bio/terra/pearl/api/admin/service/notifications/TriggerExtServiceTests.java @@ -5,6 +5,7 @@ import bio.terra.pearl.api.admin.BaseSpringBootTest; import bio.terra.pearl.api.admin.service.auth.context.PortalStudyEnvAuthContext; +import bio.terra.pearl.core.factory.StudyEnvironmentBundle; import bio.terra.pearl.core.factory.StudyEnvironmentFactory; import bio.terra.pearl.core.factory.notification.NotificationFactory; import bio.terra.pearl.core.factory.notification.TriggerFactory; @@ -36,7 +37,7 @@ public class TriggerExtServiceTests extends BaseSpringBootTest { @Test @Transactional public void testNotificationConfigReplace(TestInfo testInfo) { - StudyEnvironmentFactory.StudyEnvironmentBundle bundle = + StudyEnvironmentBundle bundle = studyEnvironmentFactory.buildBundle(getTestName(testInfo), EnvironmentName.sandbox); Trigger oldConfig = triggerFactory.buildPersisted( @@ -75,7 +76,7 @@ public void testNotificationConfigReplace(TestInfo testInfo) { @Test @Transactional public void testDeleteNotificationConfigNotFound(TestInfo testInfo) { - StudyEnvironmentFactory.StudyEnvironmentBundle bundle = + StudyEnvironmentBundle bundle = studyEnvironmentFactory.buildBundle(getTestName(testInfo), EnvironmentName.sandbox); AdminUser user = AdminUser.builder().superuser(true).build(); @@ -95,7 +96,7 @@ public void testDeleteNotificationConfigNotFound(TestInfo testInfo) { @Test @Transactional public void testDeleteNotificationConfigMustBeAuthenticated(TestInfo testInfo) { - StudyEnvironmentFactory.StudyEnvironmentBundle bundle = + StudyEnvironmentBundle bundle = studyEnvironmentFactory.buildBundle(getTestName(testInfo), EnvironmentName.sandbox); Trigger config = @@ -128,7 +129,7 @@ public void testDeleteNotificationConfigMustBeAuthenticated(TestInfo testInfo) { @Test @Transactional public void testDeleteNotificationConfig(TestInfo testInfo) { - StudyEnvironmentFactory.StudyEnvironmentBundle bundle = + StudyEnvironmentBundle bundle = studyEnvironmentFactory.buildBundle(getTestName(testInfo), EnvironmentName.sandbox); Trigger config = diff --git a/api-admin/src/test/java/bio/terra/pearl/api/admin/service/participant/ProfileExtServiceTests.java b/api-admin/src/test/java/bio/terra/pearl/api/admin/service/participant/ProfileExtServiceTests.java index 95f1508876..a4b2b0f3ec 100644 --- a/api-admin/src/test/java/bio/terra/pearl/api/admin/service/participant/ProfileExtServiceTests.java +++ b/api-admin/src/test/java/bio/terra/pearl/api/admin/service/participant/ProfileExtServiceTests.java @@ -4,6 +4,7 @@ import bio.terra.pearl.api.admin.AuthTestUtils; import bio.terra.pearl.api.admin.BaseSpringBootTest; import bio.terra.pearl.api.admin.service.auth.context.PortalEnrolleeAuthContext; +import bio.terra.pearl.core.factory.StudyEnvironmentBundle; import bio.terra.pearl.core.factory.StudyEnvironmentFactory; import bio.terra.pearl.core.factory.admin.AdminUserFactory; import bio.terra.pearl.core.factory.participant.EnrolleeFactory; @@ -44,7 +45,7 @@ public void testAllAuthenticated() { @Test @Transactional public void testUpdateProfileForEnrolleeFailsIfAdminNotInPortal(TestInfo info) { - StudyEnvironmentFactory.StudyEnvironmentBundle studyEnvBundle = + StudyEnvironmentBundle studyEnvBundle = studyEnvironmentFactory.buildBundle(getTestName(info), EnvironmentName.irb); Enrollee enrollee = @@ -71,7 +72,7 @@ public void testUpdateProfileForEnrolleeFailsIfAdminNotInPortal(TestInfo info) { @Test @Transactional public void testUpdateProfileForEnrolleeFailsIfEnrolleeNotInPortal(TestInfo info) { - StudyEnvironmentFactory.StudyEnvironmentBundle studyEnvBundle = + StudyEnvironmentBundle studyEnvBundle = studyEnvironmentFactory.buildBundle(getTestName(info), EnvironmentName.irb); Enrollee wrongStudyEnv = enrolleeFactory.buildPersisted(getTestName(info)); @@ -96,7 +97,7 @@ public void testUpdateProfileForEnrolleeFailsIfEnrolleeNotInPortal(TestInfo info @Test @Transactional public void testUpdateProfileForEnrolleeFailsIfWrongEnvironment(TestInfo info) { - StudyEnvironmentFactory.StudyEnvironmentBundle studyEnvBundle = + StudyEnvironmentBundle studyEnvBundle = studyEnvironmentFactory.buildBundle(getTestName(info), EnvironmentName.irb); Enrollee enrollee = @@ -123,7 +124,7 @@ public void testUpdateProfileForEnrolleeFailsIfWrongEnvironment(TestInfo info) { @Test @Transactional public void testUpdateProfileForEnrolleeDoesNotUpdateWrongProfile(TestInfo info) { - StudyEnvironmentFactory.StudyEnvironmentBundle studyEnvBundle = + StudyEnvironmentBundle studyEnvBundle = studyEnvironmentFactory.buildBundle(getTestName(info), EnvironmentName.irb); Enrollee enrollee = @@ -132,7 +133,7 @@ public void testUpdateProfileForEnrolleeDoesNotUpdateWrongProfile(TestInfo info) studyEnvBundle.getStudyEnv(), Profile.builder().mailingAddress(MailingAddress.builder().build()).build()); - StudyEnvironmentFactory.StudyEnvironmentBundle wrongStudyEnvBundle = + StudyEnvironmentBundle wrongStudyEnvBundle = studyEnvironmentFactory.buildBundle(getTestName(info), EnvironmentName.irb); Enrollee wrongStudyEnv = @@ -184,7 +185,7 @@ public void testUpdateProfileForEnrolleeDoesNotUpdateWrongProfile(TestInfo info) @Test @Transactional public void testUpdateProfileForEnrollee(TestInfo info) { - StudyEnvironmentFactory.StudyEnvironmentBundle studyEnvBundle = + StudyEnvironmentBundle studyEnvBundle = studyEnvironmentFactory.buildBundle(getTestName(info), EnvironmentName.irb); Enrollee enrollee = diff --git a/api-admin/src/test/java/bio/terra/pearl/api/admin/service/workflow/ParticipantDataChangeServiceTest.java b/api-admin/src/test/java/bio/terra/pearl/api/admin/service/workflow/ParticipantDataChangeServiceTest.java index 3530e4bd91..d0071268f1 100644 --- a/api-admin/src/test/java/bio/terra/pearl/api/admin/service/workflow/ParticipantDataChangeServiceTest.java +++ b/api-admin/src/test/java/bio/terra/pearl/api/admin/service/workflow/ParticipantDataChangeServiceTest.java @@ -1,6 +1,7 @@ package bio.terra.pearl.api.admin.service.workflow; import bio.terra.pearl.api.admin.BaseSpringBootTest; +import bio.terra.pearl.core.factory.participant.EnrolleeBundle; import bio.terra.pearl.core.factory.participant.EnrolleeFactory; import bio.terra.pearl.core.model.audit.ParticipantDataChange; import bio.terra.pearl.core.service.workflow.ParticipantDataChangeService; @@ -16,8 +17,7 @@ public class ParticipantDataChangeServiceTest extends BaseSpringBootTest { @Test public void testFindAllRecordsForEnrollee(TestInfo info) { - EnrolleeFactory.EnrolleeBundle enrolleeBundle = - enrolleeFactory.buildWithPortalUser(info.getDisplayName()); + EnrolleeBundle enrolleeBundle = enrolleeFactory.buildWithPortalUser(info.getDisplayName()); Assertions.assertEquals( 0, diff --git a/api-participant/src/test/java/bio/terra/pearl/api/participant/service/AuthUtilServiceTests.java b/api-participant/src/test/java/bio/terra/pearl/api/participant/service/AuthUtilServiceTests.java index 590fade080..d83b8040ca 100644 --- a/api-participant/src/test/java/bio/terra/pearl/api/participant/service/AuthUtilServiceTests.java +++ b/api-participant/src/test/java/bio/terra/pearl/api/participant/service/AuthUtilServiceTests.java @@ -4,6 +4,7 @@ import static org.hamcrest.Matchers.notNullValue; import bio.terra.pearl.api.participant.BaseSpringBootTest; +import bio.terra.pearl.core.factory.participant.EnrolleeBundle; import bio.terra.pearl.core.factory.participant.EnrolleeFactory; import bio.terra.pearl.core.factory.participant.ParticipantUserFactory; import bio.terra.pearl.core.model.participant.Enrollee; @@ -57,7 +58,7 @@ public void testAuthToEnrolleeDisallowsIfNotParticipant(TestInfo info) { @Test @Transactional public void testAuthToPortalParticipantUserAllowsIfParticipant(TestInfo info) { - EnrolleeFactory.EnrolleeBundle bundle = enrolleeFactory.buildWithPortalUser(getTestName(info)); + EnrolleeBundle bundle = enrolleeFactory.buildWithPortalUser(getTestName(info)); PortalParticipantUser ppUser = authUtilService.authParticipantUserToPortalParticipantUser( bundle.enrollee().getParticipantUserId(), bundle.portalParticipantUser().getId()); @@ -68,10 +69,8 @@ public void testAuthToPortalParticipantUserAllowsIfParticipant(TestInfo info) { @Transactional public void testAuthToPortalParticipantUserAllowsIfProxy(TestInfo info) { - EnrolleeFactory.EnrolleeBundle proxyBundle = - enrolleeFactory.buildWithPortalUser(getTestName(info)); - EnrolleeFactory.EnrolleeBundle targetBundle = - enrolleeFactory.buildWithPortalUser(getTestName(info)); + EnrolleeBundle proxyBundle = enrolleeFactory.buildWithPortalUser(getTestName(info)); + EnrolleeBundle targetBundle = enrolleeFactory.buildWithPortalUser(getTestName(info)); enrolleeRelationService.create( EnrolleeRelation.builder() @@ -92,7 +91,7 @@ public void testAuthToPortalParticipantUserAllowsIfProxy(TestInfo info) { @Test @Transactional public void testAuthToPortalParticipantUserDisallowsIfNotParticipantOrProxy(TestInfo info) { - EnrolleeFactory.EnrolleeBundle bundle = enrolleeFactory.buildWithPortalUser(getTestName(info)); + EnrolleeBundle bundle = enrolleeFactory.buildWithPortalUser(getTestName(info)); StudyEnvironment studyEnv = studyEnvironmentService.find(bundle.enrollee().getStudyEnvironmentId()).get(); ParticipantUser otherUser = diff --git a/api-participant/src/test/java/bio/terra/pearl/api/participant/service/CurrentUserServiceTests.java b/api-participant/src/test/java/bio/terra/pearl/api/participant/service/CurrentUserServiceTests.java index 067b986f1c..1cf6777e1d 100644 --- a/api-participant/src/test/java/bio/terra/pearl/api/participant/service/CurrentUserServiceTests.java +++ b/api-participant/src/test/java/bio/terra/pearl/api/participant/service/CurrentUserServiceTests.java @@ -4,7 +4,10 @@ import static org.hamcrest.Matchers.*; import bio.terra.pearl.api.participant.BaseSpringBootTest; +import bio.terra.pearl.core.factory.StudyEnvironmentBundle; import bio.terra.pearl.core.factory.StudyEnvironmentFactory; +import bio.terra.pearl.core.factory.participant.EnrolleeAndProxy; +import bio.terra.pearl.core.factory.participant.EnrolleeBundle; import bio.terra.pearl.core.factory.participant.EnrolleeFactory; import bio.terra.pearl.core.factory.participant.ParticipantUserFactory; import bio.terra.pearl.core.factory.portal.PortalEnvironmentFactory; @@ -110,9 +113,9 @@ public void testRegisterOrLoginExistingUser(TestInfo info) { @Test @Transactional public void testUserLoginWithEnrollees(TestInfo info) { - StudyEnvironmentFactory.StudyEnvironmentBundle studyEnvBundle = + StudyEnvironmentBundle studyEnvBundle = studyEnvironmentFactory.buildBundle(getTestName(info), EnvironmentName.irb); - EnrolleeFactory.EnrolleeBundle enrolleeBundle = + EnrolleeBundle enrolleeBundle = enrolleeFactory.buildWithPortalUser( getTestName(info), studyEnvBundle.getPortalEnv(), studyEnvBundle.getStudyEnv()); @@ -152,7 +155,7 @@ public void testUserLoginWithEnrollees(TestInfo info) { @Transactional public void testUserLoginWithProxy(TestInfo info) { String email = "proxy" + RandomStringUtils.randomAlphabetic(5) + "@test.com"; - EnrolleeFactory.EnrolleeAndProxy enrolleeAndProxy = + EnrolleeAndProxy enrolleeAndProxy = enrolleeFactory.buildProxyAndGovernedEnrollee(getTestName(info), email); String token = generateFakeJwtToken(email); String portalShortcode = diff --git a/api-participant/src/test/java/bio/terra/pearl/api/participant/service/EnrollmentExtServiceTest.java b/api-participant/src/test/java/bio/terra/pearl/api/participant/service/EnrollmentExtServiceTest.java index b03ee09134..4015d9b7f1 100644 --- a/api-participant/src/test/java/bio/terra/pearl/api/participant/service/EnrollmentExtServiceTest.java +++ b/api-participant/src/test/java/bio/terra/pearl/api/participant/service/EnrollmentExtServiceTest.java @@ -4,6 +4,7 @@ import bio.terra.pearl.api.participant.BaseSpringBootTest; import bio.terra.pearl.core.factory.StudyEnvironmentFactory; +import bio.terra.pearl.core.factory.participant.EnrolleeAndProxy; import bio.terra.pearl.core.factory.participant.EnrolleeFactory; import bio.terra.pearl.core.factory.portal.PortalEnvironmentFactory; import bio.terra.pearl.core.factory.survey.PreEnrollmentSurveyFactory; @@ -51,7 +52,7 @@ void testEnrollGovernedUser_NewProxy(TestInfo info) { StudyEnvironment studyEnvironment = studyEnvironmentFactory.buildPersisted(portalEnv, getTestName(info)); // step 3: enroll a user with a proxy via factory - EnrolleeFactory.EnrolleeAndProxy bundle = + EnrolleeAndProxy bundle = enrolleeFactory.buildProxyAndGovernedEnrollee( getTestName(info), portalEnv, studyEnvironment); Enrollee proxyEnrollee = bundle.proxy(); @@ -93,7 +94,7 @@ void testEnrollGovernedUser_ExistingProxyNewStudy(TestInfo info) { StudyEnvironment studyEnvironment2 = studyEnvironmentFactory.buildPersisted(portalEnv, getTestName(info)); // step 3: enroll a user with a proxy via factory - EnrolleeFactory.EnrolleeAndProxy bundle = + EnrolleeAndProxy bundle = enrolleeFactory.buildProxyAndGovernedEnrollee( getTestName(info), portalEnv, studyEnvironment1); Enrollee originalProxy = bundle.proxy(); diff --git a/api-participant/src/test/java/bio/terra/pearl/api/participant/service/SurveyResponseExtServiceTest.java b/api-participant/src/test/java/bio/terra/pearl/api/participant/service/SurveyResponseExtServiceTest.java index 0413d9a56a..86cda8be78 100644 --- a/api-participant/src/test/java/bio/terra/pearl/api/participant/service/SurveyResponseExtServiceTest.java +++ b/api-participant/src/test/java/bio/terra/pearl/api/participant/service/SurveyResponseExtServiceTest.java @@ -3,7 +3,9 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import bio.terra.pearl.api.participant.BaseSpringBootTest; +import bio.terra.pearl.core.factory.StudyEnvironmentBundle; import bio.terra.pearl.core.factory.StudyEnvironmentFactory; +import bio.terra.pearl.core.factory.participant.EnrolleeAndProxy; import bio.terra.pearl.core.factory.participant.EnrolleeFactory; import bio.terra.pearl.core.factory.survey.SurveyFactory; import bio.terra.pearl.core.model.EnvironmentName; @@ -37,7 +39,7 @@ class SurveyResponseExtServiceTest extends BaseSpringBootTest { @Transactional public void testProxyProfileMapping(TestInfo info) { - StudyEnvironmentFactory.StudyEnvironmentBundle studyEnvironmentBundle = + StudyEnvironmentBundle studyEnvironmentBundle = studyEnvironmentFactory.buildBundle(getTestName(info), EnvironmentName.sandbox); List answerMappings = @@ -60,7 +62,7 @@ public void testProxyProfileMapping(TestInfo info) { surveyFactory.attachToEnv(survey, studyEnvironmentBundle.getStudyEnv().getId(), true); - EnrolleeFactory.EnrolleeAndProxy enrolleeAndProxy = + EnrolleeAndProxy enrolleeAndProxy = enrolleeFactory.buildProxyAndGovernedEnrollee( getTestName(info), studyEnvironmentBundle.getPortalEnv(), diff --git a/core/src/main/java/bio/terra/pearl/core/dao/dataimport/MergeDao.java b/core/src/main/java/bio/terra/pearl/core/dao/dataimport/MergeDao.java new file mode 100644 index 0000000000..7cddf7c1f5 --- /dev/null +++ b/core/src/main/java/bio/terra/pearl/core/dao/dataimport/MergeDao.java @@ -0,0 +1,61 @@ +package bio.terra.pearl.core.dao.dataimport; + +import bio.terra.pearl.core.dao.workflow.ParticipantDataChangeDao; +import bio.terra.pearl.core.model.audit.ParticipantDataChange; +import org.jdbi.v3.core.Jdbi; +import org.springframework.stereotype.Component; + +import java.util.UUID; + +/** dao for operations that are illegal outside of merge contexts */ +@Component +public class MergeDao { + private final Jdbi jdbi; + private final ParticipantDataChangeDao participantDataChangeDao; + + public MergeDao(Jdbi jdbi, ParticipantDataChangeDao participantDataChangeDao) { + this.jdbi = jdbi; + this.participantDataChangeDao = participantDataChangeDao; + } + + public void reassignEnrolleeEvents(UUID sourceEnrolleeId, UUID targetEnrolleeId) { + // reassign all events from source to target + jdbi.withHandle(handle -> + handle.createUpdate(""" + update event set enrollee_id = :targetEnrolleeId where enrollee_id = :sourceEnrolleeId; + """) + .bind("sourceEnrolleeId", sourceEnrolleeId) + .bind("targetEnrolleeId", targetEnrolleeId) + .execute() + ); + } + + public void reassignEnrolleeNotifications(UUID sourceEnrolleeId, UUID targetEnrolleeId) { + // reassign all events from source to target + jdbi.withHandle(handle -> + handle.createUpdate(""" + update notification set enrollee_id = :targetEnrolleeId where enrollee_id = :sourceEnrolleeId; + """) + .bind("sourceEnrolleeId", sourceEnrolleeId) + .bind("targetEnrolleeId", targetEnrolleeId) + .execute() + ); + } + + public void updateParticipantDataChange(ParticipantDataChange change) { + // reassign all events from source to target + jdbi.withHandle(handle -> + handle.createUpdate(""" + update participant_data_change set responsible_user_id = :responsibleUserId, + enrollee_id = :enrolleeId, + portal_participant_user_id = :portalParticipantUserId + where id = :id; + """) + .bind("enrolleeId", change.getEnrolleeId()) + .bind("responsibleUserId", change.getResponsibleUserId()) + .bind("portalParticipantUserId", change.getPortalParticipantUserId()) + .bind("id", change.getId()) + .execute() + ); + } +} diff --git a/core/src/main/java/bio/terra/pearl/core/dao/study/StudyEnvironmentDao.java b/core/src/main/java/bio/terra/pearl/core/dao/study/StudyEnvironmentDao.java index 9ea76d4dd8..569ba5ee7e 100644 --- a/core/src/main/java/bio/terra/pearl/core/dao/study/StudyEnvironmentDao.java +++ b/core/src/main/java/bio/terra/pearl/core/dao/study/StudyEnvironmentDao.java @@ -44,10 +44,8 @@ public List findByStudy(UUID studyId) { } public Optional findByStudy(String shortcode, EnvironmentName environmentName) { - List primaryCols = getQueryColumns.stream().map(col -> "a." + col) - .collect(Collectors.toList()); return jdbi.withHandle(handle -> - handle.createQuery("select " + StringUtils.join(primaryCols, ", ") + " from " + tableName + handle.createQuery("select " + prefixedGetQueryColumns("a") + " from " + tableName + " a join study on study_id = study.id" + " where study.shortcode = :shortcode and environment_name = :environmentName") .bind("shortcode", shortcode) @@ -57,6 +55,21 @@ public Optional findByStudy(String shortcode, EnvironmentName ); } + public List findAllByPortalAndEnvironment(UUID portalId, EnvironmentName environmentName) { + return jdbi.withHandle(handle -> + handle.createQuery(""" + select %s from %s a + join study on study_id = study.id + join portal_study on study.id = portal_study.study_id + where portal_study.portal_id = :portalId and environment_name = :environmentName + """.formatted(prefixedGetQueryColumns("a"), tableName)) + .bind("portalId", portalId) + .bind("environmentName", environmentName) + .mapTo(clazz) + .list() + ); + } + /** * returns all the studies associated with the given portal for the given environment * So, for example, if a portal has two studies, this might return the 'sandbox' environment for diff --git a/core/src/main/java/bio/terra/pearl/core/dao/survey/AnswerDao.java b/core/src/main/java/bio/terra/pearl/core/dao/survey/AnswerDao.java index 459cbdaf45..b36b90e6c5 100644 --- a/core/src/main/java/bio/terra/pearl/core/dao/survey/AnswerDao.java +++ b/core/src/main/java/bio/terra/pearl/core/dao/survey/AnswerDao.java @@ -50,6 +50,10 @@ public List findByResponseAndQuestions(UUID surveyResponseId, List findByEnrollee(UUID enrolleeId) { + return findAllByProperty("enrollee_id", enrolleeId); + } + public List findByEnrolleeAndSurvey(UUID enrolleeId, String surveyStableId) { return findAllByTwoProperties("enrollee_id", enrolleeId, "survey_stable_id", surveyStableId); } diff --git a/core/src/main/java/bio/terra/pearl/core/service/kit/KitRequestService.java b/core/src/main/java/bio/terra/pearl/core/service/kit/KitRequestService.java index 40eecf7b22..847e29ba04 100644 --- a/core/src/main/java/bio/terra/pearl/core/service/kit/KitRequestService.java +++ b/core/src/main/java/bio/terra/pearl/core/service/kit/KitRequestService.java @@ -197,6 +197,13 @@ public List findByEnrollee(Enrollee enrollee) { return createKitRequestDto(kits, getKitTypeMap(), getEnrollees(kits)); } + /** + * Fetch all kits for an enrollee without converting into dtos. + */ + public List findByEnrolleeRaw(Enrollee enrollee) { + return dao.findByEnrollee(enrollee.getId()); + } + public KitRequest findByEnrolleeAndBarcode(Enrollee enrollee, String barcode) { return dao.findByEnrolleeAndLabel(enrollee.getId(), barcode).orElseThrow(() -> new NotFoundException("Kit request not found for enrollee %s and barcode %s" diff --git a/core/src/main/java/bio/terra/pearl/core/service/participant/EnrolleeService.java b/core/src/main/java/bio/terra/pearl/core/service/participant/EnrolleeService.java index 63a3b0557a..2fbc2e7204 100644 --- a/core/src/main/java/bio/terra/pearl/core/service/participant/EnrolleeService.java +++ b/core/src/main/java/bio/terra/pearl/core/service/participant/EnrolleeService.java @@ -70,7 +70,7 @@ public EnrolleeService(EnrolleeDao enrolleeDao, SecureRandom secureRandom, RandomUtilService randomUtilService, EnrolleeRelationService enrolleeRelationService, - PortalParticipantUserService portalParticipantUserService, + @Lazy PortalParticipantUserService portalParticipantUserService, FamilyService familyService, ShortcodeService shortcodeService, FamilyEnrolleeService familyEnrolleeService) { super(enrolleeDao); this.surveyResponseDao = surveyResponseDao; diff --git a/core/src/main/java/bio/terra/pearl/core/service/participant/ParticipantUserService.java b/core/src/main/java/bio/terra/pearl/core/service/participant/ParticipantUserService.java index 81c3f16117..76d6d25926 100644 --- a/core/src/main/java/bio/terra/pearl/core/service/participant/ParticipantUserService.java +++ b/core/src/main/java/bio/terra/pearl/core/service/participant/ParticipantUserService.java @@ -1,13 +1,10 @@ package bio.terra.pearl.core.service.participant; import bio.terra.pearl.core.dao.participant.ParticipantUserDao; -import bio.terra.pearl.core.model.BaseEntity; import bio.terra.pearl.core.model.EnvironmentName; -import bio.terra.pearl.core.model.participant.Enrollee; import bio.terra.pearl.core.model.participant.ParticipantUser; import bio.terra.pearl.core.service.CascadeProperty; import bio.terra.pearl.core.service.CrudService; -import bio.terra.pearl.core.service.ImmutableEntityService; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -62,5 +59,4 @@ public void deleteOrphans(List userIds, Set cascades) { public Optional findOne(String username, EnvironmentName environmentName) { return dao.findOne(username, environmentName); } - } diff --git a/core/src/main/java/bio/terra/pearl/core/service/participant/merge/EnrolleeMerge.java b/core/src/main/java/bio/terra/pearl/core/service/participant/merge/EnrolleeMerge.java new file mode 100644 index 0000000000..ab929c40ef --- /dev/null +++ b/core/src/main/java/bio/terra/pearl/core/service/participant/merge/EnrolleeMerge.java @@ -0,0 +1,27 @@ +package bio.terra.pearl.core.service.participant.merge; + + +import bio.terra.pearl.core.model.kit.KitRequest; +import bio.terra.pearl.core.model.participant.ParticipantNote; +import bio.terra.pearl.core.model.survey.SurveyResponse; +import bio.terra.pearl.core.model.workflow.ParticipantTask; +import lombok.Builder; +import lombok.Getter; +import lombok.Setter; + +import java.util.ArrayList; +import java.util.List; + +@Getter +@Setter +@Builder +public class EnrolleeMerge { + @Builder.Default + private List> tasks = new ArrayList<>(); + @Builder.Default + private List> surveyResponses = new ArrayList<>(); + @Builder.Default + private List> kitRequests = new ArrayList<>(); + @Builder.Default + private List> participantNotes = new ArrayList<>(); +} diff --git a/core/src/main/java/bio/terra/pearl/core/service/participant/merge/MergeAction.java b/core/src/main/java/bio/terra/pearl/core/service/participant/merge/MergeAction.java new file mode 100644 index 0000000000..3f5613ce77 --- /dev/null +++ b/core/src/main/java/bio/terra/pearl/core/service/participant/merge/MergeAction.java @@ -0,0 +1,51 @@ +package bio.terra.pearl.core.service.participant.merge; + +import bio.terra.pearl.core.model.BaseEntity; +import lombok.Builder; +import lombok.Getter; +import lombok.Setter; + +@Builder +@Getter +@Setter +public class MergeAction { + private MergePair pair; + private Action action; + private MP mergePlan; // if the action is MERGE, this is the merge plan + + public MergeAction(MergePair pair, Action action) { + this.pair = pair; + this.action = action; + } + + public MergeAction(MergePair pair, Action action, MP mergePlan) { + if (action ==Action.MOVE_SOURCE && pair.getSource() == null) { + throw new IllegalArgumentException("source cannot be null for MOVE_SOURCE action"); + } + if (action ==Action.DELETE_SOURCE && pair.getSource() == null) { + throw new IllegalArgumentException("source cannot be null for DELETE_SOURCE action"); + } + if (action == Action.MERGE && (pair.getSource() == null || pair.getTarget() == null)) { + throw new IllegalArgumentException("MERGE requires a source, target and plan"); + } + this.pair = pair; + this.action = action; + this.mergePlan = mergePlan; + } + + public T getSource() { + return pair.getSource(); + } + + public T getTarget() { + return pair.getTarget(); + } + + public enum Action { + MOVE_SOURCE, + NO_ACTION, + MERGE, + DELETE_SOURCE, + MOVE_SOURCE_DELETE_TARGET + } +} diff --git a/core/src/main/java/bio/terra/pearl/core/service/participant/merge/MergeOptions.java b/core/src/main/java/bio/terra/pearl/core/service/participant/merge/MergeOptions.java new file mode 100644 index 0000000000..a220e8d33d --- /dev/null +++ b/core/src/main/java/bio/terra/pearl/core/service/participant/merge/MergeOptions.java @@ -0,0 +1,5 @@ +package bio.terra.pearl.core.service.participant.merge; + + +public class MergeOptions { +} diff --git a/core/src/main/java/bio/terra/pearl/core/service/participant/merge/MergePair.java b/core/src/main/java/bio/terra/pearl/core/service/participant/merge/MergePair.java new file mode 100644 index 0000000000..c20097f4bc --- /dev/null +++ b/core/src/main/java/bio/terra/pearl/core/service/participant/merge/MergePair.java @@ -0,0 +1,54 @@ +package bio.terra.pearl.core.service.participant.merge; + +import bio.terra.pearl.core.model.BaseEntity; +import lombok.Getter; +import lombok.Setter; + +import java.util.ArrayList; +import java.util.List; +import java.util.function.BiFunction; +import java.util.function.Function; + +@Getter +@Setter +public class MergePair { + private T source; + private T target; + + public MergePair(T source, T target) { + this.source = source; + this.target = target; + } + + public static List> pairLists(List sourceList, List targetList, BiFunction comparator) { + List> pairs = new ArrayList<>(); + for (D source : sourceList) { + D target = targetList.stream().filter(t -> comparator.apply(source, t)).findFirst().orElse(null); + pairs.add(new MergePair(source, target)); + } + for (D target : targetList) { + D source = sourceList.stream().filter(t -> comparator.apply(target, t)).findFirst().orElse(null); + // we only need to add unmatched targets -- matched will have been handled in the loop above + if (source == null) { + pairs.add(new MergePair(source, target)); + } + } + return pairs; + } + + public PairType getPairType() { + if (source == null && target != null) { + return PairType.TARGET_ONLY; + } else if (source != null && target == null) { + return PairType.SOURCE_ONLY; + } else { + return PairType.BOTH; + } + } + + public enum PairType { + SOURCE_ONLY, + TARGET_ONLY, + BOTH + } +} diff --git a/core/src/main/java/bio/terra/pearl/core/service/participant/merge/ParticipantMergePlanService.java b/core/src/main/java/bio/terra/pearl/core/service/participant/merge/ParticipantMergePlanService.java new file mode 100644 index 0000000000..fb5811e923 --- /dev/null +++ b/core/src/main/java/bio/terra/pearl/core/service/participant/merge/ParticipantMergePlanService.java @@ -0,0 +1,147 @@ +package bio.terra.pearl.core.service.participant.merge; + +import bio.terra.pearl.core.dao.dataimport.MergeDao; +import bio.terra.pearl.core.model.participant.Enrollee; +import bio.terra.pearl.core.model.participant.ParticipantUser; +import bio.terra.pearl.core.model.participant.PortalParticipantUser; +import bio.terra.pearl.core.model.portal.Portal; +import bio.terra.pearl.core.model.workflow.ParticipantTask; +import bio.terra.pearl.core.service.kit.KitRequestService; +import bio.terra.pearl.core.service.notification.NotificationService; +import bio.terra.pearl.core.service.participant.EnrolleeService; +import bio.terra.pearl.core.service.participant.PortalParticipantUserService; +import bio.terra.pearl.core.service.participant.ProfileService; +import bio.terra.pearl.core.service.participant.WithdrawnEnrolleeService; +import bio.terra.pearl.core.service.study.StudyEnvironmentService; +import bio.terra.pearl.core.service.survey.AnswerService; +import bio.terra.pearl.core.service.survey.SurveyResponseService; +import bio.terra.pearl.core.service.workflow.ParticipantDataChangeService; +import bio.terra.pearl.core.service.workflow.ParticipantTaskService; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.ArrayList; +import java.util.List; + +@Service +public class ParticipantMergePlanService { + private final PortalParticipantUserService portalParticipantUserService; + private final ParticipantTaskService participantTaskService; + private final ParticipantDataChangeService participantDataChangeService; + private final ProfileService profileService; + private final EnrolleeService enrolleeService; + private final StudyEnvironmentService studyEnvironmentService; + private final WithdrawnEnrolleeService withdrawnEnrolleeService; + private final SurveyResponseService surveyResponseService; + private final AnswerService answerService; + private final KitRequestService kitRequestService; + private final NotificationService notificationService; + private final MergeDao mergeDao; + + public ParticipantMergePlanService(PortalParticipantUserService portalParticipantUserService, + ParticipantTaskService participantTaskService, + ParticipantDataChangeService participantDataChangeService, + ProfileService profileService, + EnrolleeService enrolleeService, + StudyEnvironmentService studyEnvironmentService, + WithdrawnEnrolleeService withdrawnEnrolleeService, + SurveyResponseService surveyResponseService, + AnswerService answerService, + KitRequestService kitRequestService, + NotificationService notificationService, + MergeDao mergeDao) { + this.portalParticipantUserService = portalParticipantUserService; + this.participantTaskService = participantTaskService; + this.participantDataChangeService = participantDataChangeService; + this.profileService = profileService; + this.enrolleeService = enrolleeService; + this.studyEnvironmentService = studyEnvironmentService; + this.withdrawnEnrolleeService = withdrawnEnrolleeService; + this.surveyResponseService = surveyResponseService; + this.answerService = answerService; + this.kitRequestService = kitRequestService; + this.notificationService = notificationService; + this.mergeDao = mergeDao; + } + + @Transactional + public ParticipantUserMerge planMerge(ParticipantUser participantUser, ParticipantUser mergeTarget, Portal portal) { + if (!participantUser.getEnvironmentName().equals(mergeTarget.getEnvironmentName())) { + throw new IllegalArgumentException("ParticipantUsers must be in the same environment to merge"); + } + + ParticipantUserMerge mergePlan = ParticipantUserMerge.builder() + .users(new MergeAction<>(new MergePair<>(participantUser, mergeTarget), MergeAction.Action.DELETE_SOURCE)) + .build(); + + PortalParticipantUser ppUser = portalParticipantUserService.findOne(participantUser.getId(), portal.getShortcode()) + .orElseThrow(() -> new IllegalArgumentException("ParticipantUser not found in portal")); + PortalParticipantUser ppMergeTarget = portalParticipantUserService.findOne(mergeTarget.getId(), portal.getShortcode()) + .orElseThrow(() -> new IllegalArgumentException("ParticipantUser not found in portal")); + + mergePlan.setPpUsers(new MergeAction(new MergePair<>(ppUser, ppMergeTarget), MergeAction.Action.DELETE_SOURCE)); + + List> enrollees = planMergePortalParticipantUsers(mergePlan, portal); + + mergePlan.setEnrollees(enrollees); + return mergePlan; + } + + protected List> planMergePortalParticipantUsers(ParticipantUserMerge merge, Portal portal) { + List enrollees = enrolleeService.findByPortalParticipantUser(merge.getPpUsers().getSource()); + List targetEnrollees = enrolleeService.findByPortalParticipantUser(merge.getPpUsers().getTarget()); + + List> enrolleePairs = MergePair.pairLists(enrollees, targetEnrollees, + (e1, e2) -> e1.getStudyEnvironmentId().equals(e2.getStudyEnvironmentId())); + + List> enrolleeMerges = new ArrayList<>(); + for (MergePair enrolleePair : enrolleePairs) { + if (enrolleePair.getPairType().equals(MergePair.PairType.TARGET_ONLY)) { + enrolleeMerges.add(new MergeAction<>(enrolleePair, MergeAction.Action.NO_ACTION)); + } else if (enrolleePair.getPairType().equals(MergePair.PairType.SOURCE_ONLY)) { + // move the enrollee to the target user + enrolleeMerges.add(new MergeAction<>(enrolleePair, MergeAction.Action.MOVE_SOURCE)); + } else if (enrolleePair.getPairType().equals(MergePair.PairType.BOTH)){ + // this user has enrolled twice in the same study, we need a merge plan + enrolleeMerges.add(new MergeAction<>(enrolleePair, MergeAction.Action.MERGE, + planMergeEnrollees(enrolleePair.getSource(), enrolleePair.getTarget()))); + } + } + return enrolleeMerges; + } + + protected EnrolleeMerge planMergeEnrollees(Enrollee source, Enrollee target) { + EnrolleeMerge enrolleeMerge = EnrolleeMerge.builder() + .build(); + List sourceTasks = participantTaskService.findByEnrolleeId(source.getId()); + List targetTasks = participantTaskService.findByEnrolleeId(target.getId()); + + List> taskPairs = MergePair.pairLists(sourceTasks, targetTasks, + (t1, t2) -> t1.getTargetStableId().equals(t2.getTargetStableId())); + for (MergePair taskPair : taskPairs) { + if (taskPair.getPairType().equals(MergePair.PairType.TARGET_ONLY)) { + enrolleeMerge.getTasks().add(new MergeAction<>(taskPair, MergeAction.Action.NO_ACTION)); + } else if (taskPair.getPairType().equals(MergePair.PairType.SOURCE_ONLY)) { + enrolleeMerge.getTasks().add(new MergeAction<>(taskPair, MergeAction.Action.MOVE_SOURCE)); + } else if (taskPair.getPairType().equals(MergePair.PairType.BOTH)) { + // this task has been assigned twice, we need to determine a merge action based on content + if (!hasMergeData(taskPair.getSource())) { + // if no source data, just drop the source task + enrolleeMerge.getTasks().add(new MergeAction<>(taskPair, MergeAction.Action.DELETE_SOURCE)); + } else if (!hasMergeData(taskPair.getTarget())) { + // if no target data, just drop the target task + enrolleeMerge.getTasks().add(new MergeAction<>(taskPair, MergeAction.Action.MOVE_SOURCE_DELETE_TARGET)); + } else { + // otherwise, we need to merge the tasks + enrolleeMerge.getTasks().add(new MergeAction<>(taskPair, MergeAction.Action.MERGE, + null)); + } + } + } + return enrolleeMerge; + } + + public static boolean hasMergeData(ParticipantTask task) { + return task.getSurveyResponseId() != null || task.getKitRequestId() != null || task.getParticipantNoteId() != null; + } +} diff --git a/core/src/main/java/bio/terra/pearl/core/service/participant/merge/ParticipantMergeService.java b/core/src/main/java/bio/terra/pearl/core/service/participant/merge/ParticipantMergeService.java new file mode 100644 index 0000000000..9a152ebb66 --- /dev/null +++ b/core/src/main/java/bio/terra/pearl/core/service/participant/merge/ParticipantMergeService.java @@ -0,0 +1,199 @@ +package bio.terra.pearl.core.service.participant.merge; + +import bio.terra.pearl.core.dao.dataimport.MergeDao; +import bio.terra.pearl.core.model.audit.DataAuditInfo; +import bio.terra.pearl.core.model.audit.ParticipantDataChange; +import bio.terra.pearl.core.model.kit.KitRequest; +import bio.terra.pearl.core.model.participant.Enrollee; +import bio.terra.pearl.core.model.participant.PortalParticipantUser; +import bio.terra.pearl.core.model.survey.Answer; +import bio.terra.pearl.core.model.survey.SurveyResponse; +import bio.terra.pearl.core.model.workflow.ParticipantTask; +import bio.terra.pearl.core.service.CascadeProperty; +import bio.terra.pearl.core.service.kit.KitRequestService; +import bio.terra.pearl.core.service.participant.*; +import bio.terra.pearl.core.service.survey.AnswerService; +import bio.terra.pearl.core.service.survey.SurveyResponseService; +import bio.terra.pearl.core.service.workflow.ParticipantDataChangeService; +import bio.terra.pearl.core.service.workflow.ParticipantTaskService; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; +import java.util.UUID; + +@Service +public class ParticipantMergeService { + private final PortalParticipantUserService portalParticipantUserService; + private final ParticipantTaskService participantTaskService; + private final ParticipantDataChangeService participantDataChangeService; + private final EnrolleeService enrolleeService; + private final WithdrawnEnrolleeService withdrawnEnrolleeService; + private final SurveyResponseService surveyResponseService; + private final AnswerService answerService; + private final KitRequestService kitRequestService; + private final ParticipantUserService participantUserService; + private final MergeDao mergeDao; + + public ParticipantMergeService(PortalParticipantUserService portalParticipantUserService, + ParticipantTaskService participantTaskService, + ParticipantDataChangeService participantDataChangeService, + EnrolleeService enrolleeService, + WithdrawnEnrolleeService withdrawnEnrolleeService, + SurveyResponseService surveyResponseService, + AnswerService answerService, + KitRequestService kitRequestService, + ParticipantUserService participantUserService, + MergeDao mergeDao) { + this.portalParticipantUserService = portalParticipantUserService; + this.participantTaskService = participantTaskService; + this.participantDataChangeService = participantDataChangeService; + this.enrolleeService = enrolleeService; + this.withdrawnEnrolleeService = withdrawnEnrolleeService; + this.surveyResponseService = surveyResponseService; + this.answerService = answerService; + this.kitRequestService = kitRequestService; + this.participantUserService = participantUserService; + this.mergeDao = mergeDao; + } + + @Transactional + public ParticipantUserMerge applyMerge(ParticipantUserMerge merge, DataAuditInfo auditInfo) { + for (MergeAction enrolleeMerge : merge.getEnrollees()) { + applyMergeEnrollee(enrolleeMerge, merge, auditInfo); + } + portalParticipantUserService.delete(merge.getPpUsers().getSource().getId(), CascadeProperty.EMPTY_SET); + participantUserService.delete(merge.getUsers().getSource().getId(), CascadeProperty.EMPTY_SET); + return merge; + } + + protected void applyMergeEnrollee(MergeAction mergeAction, ParticipantUserMerge parentMerge, DataAuditInfo auditInfo) { + if (mergeAction.getAction().equals(MergeAction.Action.NO_ACTION)) { + // nothing to do + } else if (mergeAction.getAction().equals(MergeAction.Action.DELETE_SOURCE)) { + // delete the source enrollee + deleteMergedEnrollee(mergeAction.getSource(), auditInfo); + } else if (mergeAction.getAction().equals(MergeAction.Action.MOVE_SOURCE)) { + // move the source enrollee to the target user + moveEnrollee(mergeAction.getSource(), parentMerge.getPpUsers().getTarget(), auditInfo); + } else if (mergeAction.getAction().equals(MergeAction.Action.MERGE)) { + // merge the source enrollee into the target enrollee + mergeEnrolleeData(mergeAction.getSource(), mergeAction.getTarget(), mergeAction.getMergePlan(), parentMerge.getPpUsers().getTarget(), auditInfo); + deleteMergedEnrollee(mergeAction.getSource(), auditInfo); + } + } + + protected void deleteMergedEnrollee(Enrollee enrollee, DataAuditInfo auditInfo) { + withdrawnEnrolleeService.withdrawEnrollee(enrollee, auditInfo); + } + + /** merges data from one enrollee into another. Does not delete the source enrollee */ + protected void mergeEnrolleeData(Enrollee source, Enrollee target, EnrolleeMerge mergePlan, PortalParticipantUser targetPpUser, DataAuditInfo auditInfo) { + for (MergeAction action : mergePlan.getTasks()) { + if (action.getAction().equals(MergeAction.Action.DELETE_SOURCE)) { + deleteTask(action.getSource(), auditInfo); + } else if (action.getAction().equals(MergeAction.Action.MOVE_SOURCE) || + action.getAction().equals(MergeAction.Action.MERGE) || + action.getAction().equals(MergeAction.Action.MOVE_SOURCE_DELETE_TARGET)) { + moveTask(action.getSource().getId(), target, targetPpUser, auditInfo); + if (action.getAction().equals(MergeAction.Action.MOVE_SOURCE_DELETE_TARGET)) { + deleteTask(action.getTarget(), auditInfo); + } + } else if (action.getAction().equals(MergeAction.Action.NO_ACTION)) { + // nothing to do + } else { + throw new IllegalArgumentException("Unexpected action in ParticipantTask merge plan"); + } + } + + // for now, we reassign all notifications and events to the target enrollee + mergeDao.reassignEnrolleeNotifications(source.getId(), target.getId()); + mergeDao.reassignEnrolleeEvents(source.getId(), target.getId()); + reassignDataChanges(source, target, targetPpUser); + } + + private void moveTask(UUID taskId, Enrollee targetEnrollee, PortalParticipantUser targetPpUser, DataAuditInfo auditInfo) { + // refetch the target task to make sure we have the latest version and for safety (since the task + // may come from a Merge object from the client), the reassign ids + ParticipantTask task = participantTaskService.find(taskId).orElseThrow(); + task.setEnrolleeId(targetEnrollee.getId()); + task.setPortalParticipantUserId(targetPpUser.getId()); + participantTaskService.update(task, auditInfo); + + if (task.getSurveyResponseId() != null) { + moveResponse(task.getSurveyResponseId(), targetEnrollee, targetPpUser, auditInfo); + } else if (task.getKitRequestId() != null) { + moveKitRequest(task.getKitRequestId(), targetEnrollee, targetPpUser, auditInfo); + } + } + + private void deleteTask(ParticipantTask task, DataAuditInfo auditInfo) { + // for now, we only support deleting tasks with no data attached + task = participantTaskService.find(task.getId()).orElseThrow(); + if (ParticipantMergePlanService.hasMergeData(task)) { + throw new IllegalArgumentException("Cannot delete task with data"); + } + participantTaskService.delete(task.getId(), auditInfo); + } + + private void moveResponse(UUID responseId, Enrollee targetEnrollee, PortalParticipantUser targetPpUser, DataAuditInfo auditInfo) { + SurveyResponse response = surveyResponseService.find(responseId).orElseThrow(); + response.setEnrolleeId(targetEnrollee.getId()); + if (response.getCreatingParticipantUserId() != null) { + response.setCreatingParticipantUserId(targetPpUser.getParticipantUserId()); + } + surveyResponseService.update(response); + List answers = answerService.findByResponse(responseId); + for (Answer answer : answers) { + if (answer.getCreatingParticipantUserId() != null) { + answer.setCreatingParticipantUserId(targetPpUser.getParticipantUserId()); + } + answerService.update(answer); + } + } + + private void moveKitRequest(UUID kitRequestId, Enrollee targetEnrollee, PortalParticipantUser targetPpUser, DataAuditInfo auditInfo) { + KitRequest kitRequest = kitRequestService.find(kitRequestId).orElseThrow(); + kitRequest.setEnrolleeId(targetEnrollee.getId()); + kitRequestService.update(kitRequest); + } + + private void moveEnrollee(Enrollee enrollee, PortalParticipantUser targetPpUser, DataAuditInfo auditInfo) { + enrollee.setParticipantUserId(targetPpUser.getParticipantUserId()); + enrollee.setProfileId(targetPpUser.getProfileId()); + enrolleeService.update(enrollee); + + // merge the data from enrollee into targetEnrollee + // delete the enrollee + List tasks = participantTaskService.findByEnrolleeId(enrollee.getId()); + for (ParticipantTask task : tasks) { + // this is a task that has data -- move it to the target + task.setPortalParticipantUserId(targetPpUser.getId()); + participantTaskService.update(task, auditInfo); + } + + // copy across the survey responses + List responses = surveyResponseService.findByEnrolleeId(enrollee.getId()); + for (SurveyResponse response : responses) { + if (response.getCreatingParticipantUserId() != null) { + response.setCreatingParticipantUserId(targetPpUser.getParticipantUserId()); + surveyResponseService.update(response); + } + } + reassignDataChanges(enrollee, enrollee, targetPpUser); + } + + protected void reassignDataChanges(Enrollee sourceEnrollee, Enrollee targetEnrollee, PortalParticipantUser targetPpUser) { + List participantDataChanges = participantDataChangeService.findByEnrollee(sourceEnrollee.getId()); + for (ParticipantDataChange participantDataChange : participantDataChanges) { + participantDataChange.setEnrolleeId(targetEnrollee.getId()); + if (participantDataChange.getPortalParticipantUserId() != null) { + participantDataChange.setPortalParticipantUserId(targetPpUser.getId()); + } + if (participantDataChange.getResponsibleUserId() != null) { + participantDataChange.setResponsibleUserId(targetPpUser.getParticipantUserId()); + } + mergeDao.updateParticipantDataChange(participantDataChange); + } + } +} diff --git a/core/src/main/java/bio/terra/pearl/core/service/participant/merge/ParticipantUserMerge.java b/core/src/main/java/bio/terra/pearl/core/service/participant/merge/ParticipantUserMerge.java new file mode 100644 index 0000000000..8ed16dd443 --- /dev/null +++ b/core/src/main/java/bio/terra/pearl/core/service/participant/merge/ParticipantUserMerge.java @@ -0,0 +1,24 @@ +package bio.terra.pearl.core.service.participant.merge; + +import bio.terra.pearl.core.model.participant.Enrollee; +import bio.terra.pearl.core.model.participant.ParticipantUser; +import bio.terra.pearl.core.model.participant.PortalParticipantUser; +import lombok.Builder; +import lombok.Getter; +import lombok.Setter; + +import java.util.ArrayList; +import java.util.List; + +/** a record of an enrollee merge operation */ +@Getter +@Setter +@Builder +public class ParticipantUserMerge { + private MergeAction users; + private MergeAction ppUsers; + @Builder.Default + private List> enrollees = new ArrayList<>(); +} + + diff --git a/core/src/main/java/bio/terra/pearl/core/service/study/StudyEnvironmentService.java b/core/src/main/java/bio/terra/pearl/core/service/study/StudyEnvironmentService.java index f9daba2da3..daf7e92cba 100644 --- a/core/src/main/java/bio/terra/pearl/core/service/study/StudyEnvironmentService.java +++ b/core/src/main/java/bio/terra/pearl/core/service/study/StudyEnvironmentService.java @@ -92,6 +92,10 @@ public Optional findByStudy(String studyShortcode, Environment return dao.findByStudy(studyShortcode, environmentName); } + public List findAllByPortalAndEnvironment(UUID portalId, EnvironmentName environmentName) { + return dao.findAllByPortalAndEnvironment(portalId, environmentName); + } + public StudyEnvironment verifyStudy(String studyShortcode, EnvironmentName environmentName) { return findByStudy(studyShortcode, environmentName).orElseThrow(() -> new NotFoundException("Study not found for environment %s: %s" diff --git a/core/src/main/java/bio/terra/pearl/core/service/survey/AnswerService.java b/core/src/main/java/bio/terra/pearl/core/service/survey/AnswerService.java index ba8088bd5c..ed10fa927e 100644 --- a/core/src/main/java/bio/terra/pearl/core/service/survey/AnswerService.java +++ b/core/src/main/java/bio/terra/pearl/core/service/survey/AnswerService.java @@ -27,6 +27,10 @@ public List findByResponseAndQuestions(UUID surveyResponseId, List findByEnrollee(UUID enrolleeID) { + return dao.findByEnrollee(enrolleeID); + } + public List findByEnrolleeAndSurvey(UUID enrolleeID, String surveyStableId) { return dao.findByEnrolleeAndSurvey(enrolleeID, surveyStableId); } diff --git a/core/src/main/java/bio/terra/pearl/core/service/survey/SurveyResponseService.java b/core/src/main/java/bio/terra/pearl/core/service/survey/SurveyResponseService.java index 1080856c53..96d5375689 100644 --- a/core/src/main/java/bio/terra/pearl/core/service/survey/SurveyResponseService.java +++ b/core/src/main/java/bio/terra/pearl/core/service/survey/SurveyResponseService.java @@ -12,6 +12,7 @@ import bio.terra.pearl.core.model.workflow.TaskStatus; import bio.terra.pearl.core.model.workflow.TaskType; import bio.terra.pearl.core.service.CascadeProperty; +import bio.terra.pearl.core.service.CrudService; import bio.terra.pearl.core.service.ImmutableEntityService; import bio.terra.pearl.core.service.exception.NotFoundException; import bio.terra.pearl.core.service.study.StudyEnvironmentSurveyService; @@ -25,7 +26,7 @@ import java.util.*; @Service -public class SurveyResponseService extends ImmutableEntityService { +public class SurveyResponseService extends CrudService { private final AnswerService answerService; private final SurveyService surveyService; private final ParticipantTaskService participantTaskService; diff --git a/core/src/test/java/bio/terra/pearl/core/dao/participant/EnrolleeDaoTests.java b/core/src/test/java/bio/terra/pearl/core/dao/participant/EnrolleeDaoTests.java index c78a67822a..360fd1158f 100644 --- a/core/src/test/java/bio/terra/pearl/core/dao/participant/EnrolleeDaoTests.java +++ b/core/src/test/java/bio/terra/pearl/core/dao/participant/EnrolleeDaoTests.java @@ -1,17 +1,15 @@ package bio.terra.pearl.core.dao.participant; import bio.terra.pearl.core.BaseSpringBootTest; -import bio.terra.pearl.core.dao.workflow.ParticipantTaskDao; +import bio.terra.pearl.core.factory.StudyEnvironmentBundle; import bio.terra.pearl.core.factory.StudyEnvironmentFactory; +import bio.terra.pearl.core.factory.participant.EnrolleeBundle; import bio.terra.pearl.core.factory.participant.EnrolleeFactory; import bio.terra.pearl.core.factory.participant.ParticipantTaskFactory; import bio.terra.pearl.core.model.EnvironmentName; import bio.terra.pearl.core.model.participant.Enrollee; -import bio.terra.pearl.core.model.study.StudyEnvironment; -import bio.terra.pearl.core.model.workflow.ParticipantTask; import bio.terra.pearl.core.model.workflow.TaskStatus; import bio.terra.pearl.core.model.workflow.TaskType; -import org.checkerframework.checker.units.qual.A; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestInfo; import org.springframework.beans.factory.annotation.Autowired; @@ -38,13 +36,13 @@ public class EnrolleeDaoTests extends BaseSpringBootTest { public void testFindUnassignedToTask(TestInfo testInfo) { String TASK_STABLE_ID = "testFindUnassignedToTask"; // set up a sandbox and irb environment, with 2 enrollees in each - StudyEnvironmentFactory.StudyEnvironmentBundle sandboxBundle = studyEnvironmentFactory.buildBundle(getTestName(testInfo), EnvironmentName.sandbox); - EnrolleeFactory.EnrolleeBundle sandbox1 = enrolleeFactory.buildWithPortalUser(getTestName(testInfo), sandboxBundle.getPortalEnv(), sandboxBundle.getStudyEnv()); - EnrolleeFactory.EnrolleeBundle sandbox2 = enrolleeFactory.buildWithPortalUser(getTestName(testInfo), sandboxBundle.getPortalEnv(), sandboxBundle.getStudyEnv()); + StudyEnvironmentBundle sandboxBundle = studyEnvironmentFactory.buildBundle(getTestName(testInfo), EnvironmentName.sandbox); + EnrolleeBundle sandbox1 = enrolleeFactory.buildWithPortalUser(getTestName(testInfo), sandboxBundle.getPortalEnv(), sandboxBundle.getStudyEnv()); + EnrolleeBundle sandbox2 = enrolleeFactory.buildWithPortalUser(getTestName(testInfo), sandboxBundle.getPortalEnv(), sandboxBundle.getStudyEnv()); - StudyEnvironmentFactory.StudyEnvironmentBundle irbBundle = studyEnvironmentFactory.buildBundle(getTestName(testInfo), EnvironmentName.irb); - EnrolleeFactory.EnrolleeBundle irb1 = enrolleeFactory.buildWithPortalUser(getTestName(testInfo), irbBundle.getPortalEnv(), irbBundle.getStudyEnv()); - EnrolleeFactory.EnrolleeBundle irb2 = enrolleeFactory.buildWithPortalUser(getTestName(testInfo), irbBundle.getPortalEnv(), irbBundle.getStudyEnv()); + StudyEnvironmentBundle irbBundle = studyEnvironmentFactory.buildBundle(getTestName(testInfo), EnvironmentName.irb); + EnrolleeBundle irb1 = enrolleeFactory.buildWithPortalUser(getTestName(testInfo), irbBundle.getPortalEnv(), irbBundle.getStudyEnv()); + EnrolleeBundle irb2 = enrolleeFactory.buildWithPortalUser(getTestName(testInfo), irbBundle.getPortalEnv(), irbBundle.getStudyEnv()); // returns both enrollees if no one is assigned any tasks List unassignedEnrollees = enrolleeDao.findUnassignedToTask(sandboxBundle.getStudyEnv().getId(), TASK_STABLE_ID, null); @@ -75,9 +73,9 @@ public void testFindUnassignedToTask(TestInfo testInfo) { public void testFindUnassignedToTaskByVersion(TestInfo testInfo) { String TASK_STABLE_ID = "testFindUnassignedToTaskByVersion"; // set up a sandbox and irb environment, with 2 enrollees in each - StudyEnvironmentFactory.StudyEnvironmentBundle sandboxBundle = studyEnvironmentFactory.buildBundle(getTestName(testInfo), EnvironmentName.sandbox); - EnrolleeFactory.EnrolleeBundle sandbox1 = enrolleeFactory.buildWithPortalUser(getTestName(testInfo), sandboxBundle.getPortalEnv(), sandboxBundle.getStudyEnv()); - EnrolleeFactory.EnrolleeBundle sandbox2 = enrolleeFactory.buildWithPortalUser(getTestName(testInfo), sandboxBundle.getPortalEnv(), sandboxBundle.getStudyEnv()); + StudyEnvironmentBundle sandboxBundle = studyEnvironmentFactory.buildBundle(getTestName(testInfo), EnvironmentName.sandbox); + EnrolleeBundle sandbox1 = enrolleeFactory.buildWithPortalUser(getTestName(testInfo), sandboxBundle.getPortalEnv(), sandboxBundle.getStudyEnv()); + EnrolleeBundle sandbox2 = enrolleeFactory.buildWithPortalUser(getTestName(testInfo), sandboxBundle.getPortalEnv(), sandboxBundle.getStudyEnv()); // give the first enrollee v1 of the task, and the second enrollee v2 participantTaskFactory.buildPersisted(sandbox1, ParticipantTaskFactory.DEFAULT_BUILDER diff --git a/core/src/test/java/bio/terra/pearl/core/dao/participant/ParticipantTaskDaoTests.java b/core/src/test/java/bio/terra/pearl/core/dao/participant/ParticipantTaskDaoTests.java index 5f85135633..53ad039ec9 100644 --- a/core/src/test/java/bio/terra/pearl/core/dao/participant/ParticipantTaskDaoTests.java +++ b/core/src/test/java/bio/terra/pearl/core/dao/participant/ParticipantTaskDaoTests.java @@ -5,6 +5,7 @@ import bio.terra.pearl.core.factory.StudyEnvironmentFactory; import bio.terra.pearl.core.factory.notification.NotificationFactory; import bio.terra.pearl.core.factory.notification.TriggerFactory; +import bio.terra.pearl.core.factory.participant.EnrolleeBundle; import bio.terra.pearl.core.factory.participant.EnrolleeFactory; import bio.terra.pearl.core.factory.participant.ParticipantTaskFactory; import bio.terra.pearl.core.factory.portal.PortalEnvironmentFactory; @@ -38,7 +39,7 @@ public class ParticipantTaskDaoTests extends BaseSpringBootTest { public void testFindByStatusAndTimeOneTask(TestInfo info) { PortalEnvironment portalEnv = portalEnvironmentFactory.buildPersisted(getTestName(info)); StudyEnvironment studyEnv = studyEnvironmentFactory.buildPersisted(portalEnv, getTestName(info)); - EnrolleeFactory.EnrolleeBundle enrolleeBundle = enrolleeFactory.buildWithPortalUser(getTestName(info), portalEnv, studyEnv); + EnrolleeBundle enrolleeBundle = enrolleeFactory.buildWithPortalUser(getTestName(info), portalEnv, studyEnv); ParticipantTask newTask1 = participantTaskFactory.buildPersisted(enrolleeBundle, TaskStatus.NEW, TaskType.CONSENT); // check status filtering @@ -81,8 +82,8 @@ public void testFindByStatusAndTimeOneTask(TestInfo info) { public void testFindByStatusAndTimeMultiTasks(TestInfo info) { PortalEnvironment portalEnv = portalEnvironmentFactory.buildPersisted(getTestName(info)); StudyEnvironment studyEnv = studyEnvironmentFactory.buildPersisted(portalEnv, getTestName(info)); - EnrolleeFactory.EnrolleeBundle enrolleeBundle = enrolleeFactory.buildWithPortalUser(getTestName(info), portalEnv, studyEnv); - EnrolleeFactory.EnrolleeBundle enrolleeBundle2 = enrolleeFactory.buildWithPortalUser(getTestName(info), portalEnv, studyEnv); + EnrolleeBundle enrolleeBundle = enrolleeFactory.buildWithPortalUser(getTestName(info), portalEnv, studyEnv); + EnrolleeBundle enrolleeBundle2 = enrolleeFactory.buildWithPortalUser(getTestName(info), portalEnv, studyEnv); ParticipantTask task1_1 = participantTaskFactory.buildPersisted(enrolleeBundle, TaskStatus.NEW, TaskType.CONSENT); ParticipantTask task1_2 = participantTaskFactory.buildPersisted(enrolleeBundle, TaskStatus.NEW, TaskType.CONSENT); @@ -119,8 +120,8 @@ void testFindTasksByStudy(TestInfo testInfo) { String testName = getTestName(testInfo); PortalEnvironment portalEnv = portalEnvironmentFactory.buildPersisted(testName); StudyEnvironment studyEnv = studyEnvironmentFactory.buildPersisted(portalEnv, testName); - EnrolleeFactory.EnrolleeBundle enrolleeBundle = enrolleeFactory.buildWithPortalUser(testName, portalEnv, studyEnv); - EnrolleeFactory.EnrolleeBundle enrolleeBundle2 = enrolleeFactory.buildWithPortalUser(testName, portalEnv, studyEnv); + EnrolleeBundle enrolleeBundle = enrolleeFactory.buildWithPortalUser(testName, portalEnv, studyEnv); + EnrolleeBundle enrolleeBundle2 = enrolleeFactory.buildWithPortalUser(testName, portalEnv, studyEnv); participantTaskFactory.buildPersisted(enrolleeBundle, "stable_id_1", "task_name1", TaskStatus.NEW, TaskType.CONSENT); participantTaskFactory.buildPersisted(enrolleeBundle, "stable_id_2", "task_name2", TaskStatus.NEW, TaskType.SURVEY); diff --git a/core/src/test/java/bio/terra/pearl/core/dao/search/EnrolleeSearchExpressionDaoTests.java b/core/src/test/java/bio/terra/pearl/core/dao/search/EnrolleeSearchExpressionDaoTests.java index 5ac923e36f..112b9bd837 100644 --- a/core/src/test/java/bio/terra/pearl/core/dao/search/EnrolleeSearchExpressionDaoTests.java +++ b/core/src/test/java/bio/terra/pearl/core/dao/search/EnrolleeSearchExpressionDaoTests.java @@ -1,11 +1,10 @@ package bio.terra.pearl.core.dao.search; import bio.terra.pearl.core.BaseSpringBootTest; +import bio.terra.pearl.core.factory.StudyEnvironmentBundle; import bio.terra.pearl.core.factory.StudyEnvironmentFactory; import bio.terra.pearl.core.factory.kit.KitRequestFactory; -import bio.terra.pearl.core.factory.participant.EnrolleeFactory; -import bio.terra.pearl.core.factory.participant.FamilyFactory; -import bio.terra.pearl.core.factory.participant.ParticipantTaskFactory; +import bio.terra.pearl.core.factory.participant.*; import bio.terra.pearl.core.factory.survey.SurveyFactory; import bio.terra.pearl.core.factory.survey.SurveyResponseFactory; import bio.terra.pearl.core.model.EnvironmentName; @@ -328,7 +327,7 @@ public void testAnswersWithParensEvaluate(TestInfo info) { @Test @Transactional public void testTaskFacets(TestInfo info) { - StudyEnvironmentFactory.StudyEnvironmentBundle studyEnvBundle = studyEnvironmentFactory.buildBundle(getTestName(info), EnvironmentName.sandbox); + StudyEnvironmentBundle studyEnvBundle = studyEnvironmentFactory.buildBundle(getTestName(info), EnvironmentName.sandbox); EnrolleeSearchExpression assignedExp = enrolleeSearchExpressionParser.parseRule( "{task.demographic_survey.assigned} = true" ); @@ -338,21 +337,21 @@ public void testTaskFacets(TestInfo info) { ); // enrollee not assigned - EnrolleeFactory.EnrolleeBundle eBundleNotAssigned = enrolleeFactory.buildWithPortalUser(getTestName(info), studyEnvBundle.getPortalEnv(), studyEnvBundle.getStudyEnv()); + EnrolleeBundle eBundleNotAssigned = enrolleeFactory.buildWithPortalUser(getTestName(info), studyEnvBundle.getPortalEnv(), studyEnvBundle.getStudyEnv()); Enrollee enrolleeNotAssigned = eBundleNotAssigned.enrollee(); // enrollee assigned not started - EnrolleeFactory.EnrolleeBundle eBundleNotStarted = enrolleeFactory.buildWithPortalUser(getTestName(info), studyEnvBundle.getPortalEnv(), studyEnvBundle.getStudyEnv()); + EnrolleeBundle eBundleNotStarted = enrolleeFactory.buildWithPortalUser(getTestName(info), studyEnvBundle.getPortalEnv(), studyEnvBundle.getStudyEnv()); participantTaskFactory.buildPersisted(eBundleNotStarted, "demographic_survey", TaskStatus.NEW, TaskType.SURVEY); Enrollee enrolleeNotStarted = eBundleNotStarted.enrollee(); // enrollee assigned in progress - EnrolleeFactory.EnrolleeBundle eBundleInProgress = enrolleeFactory.buildWithPortalUser(getTestName(info), studyEnvBundle.getPortalEnv(), studyEnvBundle.getStudyEnv()); + EnrolleeBundle eBundleInProgress = enrolleeFactory.buildWithPortalUser(getTestName(info), studyEnvBundle.getPortalEnv(), studyEnvBundle.getStudyEnv()); participantTaskFactory.buildPersisted(eBundleInProgress, "demographic_survey", TaskStatus.IN_PROGRESS, TaskType.SURVEY); Enrollee enrolleeInProgress = eBundleInProgress.enrollee(); // enrollee assigned in progress but different task - EnrolleeFactory.EnrolleeBundle eBundleInProgressWrongTask = enrolleeFactory.buildWithPortalUser(getTestName(info), studyEnvBundle.getPortalEnv(), studyEnvBundle.getStudyEnv()); + EnrolleeBundle eBundleInProgressWrongTask = enrolleeFactory.buildWithPortalUser(getTestName(info), studyEnvBundle.getPortalEnv(), studyEnvBundle.getStudyEnv()); participantTaskFactory.buildPersisted(eBundleInProgressWrongTask, "something_else", TaskStatus.IN_PROGRESS, TaskType.SURVEY); List resultsAssigned = enrolleeSearchExpressionDao.executeSearch(assignedExp, studyEnvBundle.getStudyEnv().getId()); @@ -374,7 +373,7 @@ public void testTaskFacets(TestInfo info) { @Test @Transactional public void testEnrolleeFacets(TestInfo info) { - StudyEnvironmentFactory.StudyEnvironmentBundle studyEnvBundle = studyEnvironmentFactory.buildBundle(getTestName(info), EnvironmentName.sandbox); + StudyEnvironmentBundle studyEnvBundle = studyEnvironmentFactory.buildBundle(getTestName(info), EnvironmentName.sandbox); UUID studyEnvId = studyEnvBundle.getStudyEnv().getId(); EnrolleeSearchExpression consentedExp = enrolleeSearchExpressionParser.parseRule( "{enrollee.consented} = true" @@ -419,7 +418,7 @@ public void testEnrolleeFacets(TestInfo info) { @Test @Transactional public void testContains(TestInfo info) { - StudyEnvironmentFactory.StudyEnvironmentBundle studyEnvBundle = studyEnvironmentFactory.buildBundle(getTestName(info), EnvironmentName.sandbox); + StudyEnvironmentBundle studyEnvBundle = studyEnvironmentFactory.buildBundle(getTestName(info), EnvironmentName.sandbox); UUID studyEnvId = studyEnvBundle.getStudyEnv().getId(); EnrolleeSearchExpression shortcodeExp = enrolleeSearchExpressionParser.parseRule( @@ -449,7 +448,7 @@ public void testContains(TestInfo info) { @Test @Transactional public void testProfileName(TestInfo info) { - StudyEnvironmentFactory.StudyEnvironmentBundle studyEnvBundle = studyEnvironmentFactory.buildBundle(getTestName(info), EnvironmentName.sandbox); + StudyEnvironmentBundle studyEnvBundle = studyEnvironmentFactory.buildBundle(getTestName(info), EnvironmentName.sandbox); PortalEnvironment portalEnv = studyEnvBundle.getPortalEnv(); StudyEnvironment studyEnv = studyEnvBundle.getStudyEnv(); @@ -458,19 +457,19 @@ public void testProfileName(TestInfo info) { ); - EnrolleeFactory.EnrolleeBundle jsalkBundle = enrolleeFactory.buildWithPortalUser( + EnrolleeBundle jsalkBundle = enrolleeFactory.buildWithPortalUser( getTestName(info), portalEnv, studyEnv, Profile.builder().givenName("Jonas").familyName("Salk").build()); - EnrolleeFactory.EnrolleeBundle psalkBundle = enrolleeFactory.buildWithPortalUser( + EnrolleeBundle psalkBundle = enrolleeFactory.buildWithPortalUser( getTestName(info), portalEnv, studyEnv, Profile.builder().givenName("Peter").familyName("Salk").build()); - EnrolleeFactory.EnrolleeBundle reversedBundle = enrolleeFactory.buildWithPortalUser( + EnrolleeBundle reversedBundle = enrolleeFactory.buildWithPortalUser( getTestName(info), portalEnv, studyEnv, @@ -550,7 +549,7 @@ public void testLowerFunction(TestInfo info) { @Test @Transactional public void testNot(TestInfo info) { - EnrolleeFactory.EnrolleeAndProxy bundle = enrolleeFactory.buildProxyAndGovernedEnrollee(getTestName(info), "proxy@test.com"); + EnrolleeAndProxy bundle = enrolleeFactory.buildProxyAndGovernedEnrollee(getTestName(info), "proxy@test.com"); EnrolleeSearchExpression notSubjectExp = enrolleeSearchExpressionParser.parseRule( "!{enrollee.subject} = true" diff --git a/core/src/test/java/bio/terra/pearl/core/dao/survey/StudyEnvironmentSurveyDaoTests.java b/core/src/test/java/bio/terra/pearl/core/dao/survey/StudyEnvironmentSurveyDaoTests.java index 2e09ac875e..b35ad0a1c1 100644 --- a/core/src/test/java/bio/terra/pearl/core/dao/survey/StudyEnvironmentSurveyDaoTests.java +++ b/core/src/test/java/bio/terra/pearl/core/dao/survey/StudyEnvironmentSurveyDaoTests.java @@ -2,13 +2,12 @@ import bio.terra.pearl.core.BaseSpringBootTest; import bio.terra.pearl.core.dao.study.StudyEnvironmentSurveyDao; +import bio.terra.pearl.core.factory.StudyEnvironmentBundle; import bio.terra.pearl.core.factory.StudyEnvironmentFactory; import bio.terra.pearl.core.factory.survey.SurveyFactory; import bio.terra.pearl.core.model.EnvironmentName; -import bio.terra.pearl.core.model.study.StudyEnvironment; import bio.terra.pearl.core.model.survey.StudyEnvironmentSurvey; import bio.terra.pearl.core.model.survey.Survey; -import bio.terra.pearl.core.service.study.StudyEnvironmentSurveyService; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestInfo; import org.springframework.beans.factory.annotation.Autowired; @@ -31,7 +30,7 @@ public class StudyEnvironmentSurveyDaoTests extends BaseSpringBootTest { @Test @Transactional public void testFindSurveyNoContent(TestInfo testInfo) { - StudyEnvironmentFactory.StudyEnvironmentBundle bundle = studyEnvironmentFactory.buildBundle(getTestName(testInfo), EnvironmentName.sandbox); + StudyEnvironmentBundle bundle = studyEnvironmentFactory.buildBundle(getTestName(testInfo), EnvironmentName.sandbox); Survey survey = surveyFactory.buildPersisted(getTestName(testInfo)); surveyFactory.attachToEnv(survey, bundle.getStudyEnv().getId(), true); diff --git a/core/src/test/java/bio/terra/pearl/core/dao/workflow/EventDaoTests.java b/core/src/test/java/bio/terra/pearl/core/dao/workflow/EventDaoTests.java index be4dcbac30..a7b8de31be 100644 --- a/core/src/test/java/bio/terra/pearl/core/dao/workflow/EventDaoTests.java +++ b/core/src/test/java/bio/terra/pearl/core/dao/workflow/EventDaoTests.java @@ -2,6 +2,7 @@ import bio.terra.pearl.core.BaseSpringBootTest; import bio.terra.pearl.core.factory.DaoTestUtils; +import bio.terra.pearl.core.factory.participant.EnrolleeBundle; import bio.terra.pearl.core.factory.participant.EnrolleeFactory; import bio.terra.pearl.core.model.workflow.Event; import bio.terra.pearl.core.model.workflow.EventClass; @@ -73,7 +74,7 @@ public void testForeignKeyConstraints() { @Test @Transactional public void testFullEventCreation(TestInfo info) { - EnrolleeFactory.EnrolleeBundle bundle = enrolleeFactory.buildWithPortalUser(getTestName(info)); + EnrolleeBundle bundle = enrolleeFactory.buildWithPortalUser(getTestName(info)); Event event = Event .builder() diff --git a/core/src/test/java/bio/terra/pearl/core/service/dataimport/ImportServiceTest.java b/core/src/test/java/bio/terra/pearl/core/service/dataimport/ImportServiceTest.java index 92af9aba63..c21a108914 100644 --- a/core/src/test/java/bio/terra/pearl/core/service/dataimport/ImportServiceTest.java +++ b/core/src/test/java/bio/terra/pearl/core/service/dataimport/ImportServiceTest.java @@ -2,6 +2,7 @@ import bio.terra.pearl.core.BaseSpringBootTest; import bio.terra.pearl.core.factory.DaoTestUtils; +import bio.terra.pearl.core.factory.StudyEnvironmentBundle; import bio.terra.pearl.core.factory.StudyEnvironmentFactory; import bio.terra.pearl.core.factory.admin.AdminUserFactory; import bio.terra.pearl.core.model.EnvironmentName; @@ -33,7 +34,7 @@ public class ImportServiceTest extends BaseSpringBootTest { @Test @Transactional public void testCrud(TestInfo info) { - StudyEnvironmentFactory.StudyEnvironmentBundle bundle = studyEnvironmentFactory.buildBundle(getTestName(info), EnvironmentName.irb); + StudyEnvironmentBundle bundle = studyEnvironmentFactory.buildBundle(getTestName(info), EnvironmentName.irb); AdminUser user = adminUserFactory.buildPersisted(getTestName(info)); Import dataImport = Import.builder() .responsibleUserId(user.getId()) diff --git a/core/src/test/java/bio/terra/pearl/core/service/export/EnrolleeExportServiceTests.java b/core/src/test/java/bio/terra/pearl/core/service/export/EnrolleeExportServiceTests.java index 1ce1ad6016..3a035f21c0 100644 --- a/core/src/test/java/bio/terra/pearl/core/service/export/EnrolleeExportServiceTests.java +++ b/core/src/test/java/bio/terra/pearl/core/service/export/EnrolleeExportServiceTests.java @@ -1,7 +1,9 @@ package bio.terra.pearl.core.service.export; import bio.terra.pearl.core.BaseSpringBootTest; +import bio.terra.pearl.core.factory.StudyEnvironmentBundle; import bio.terra.pearl.core.factory.StudyEnvironmentFactory; +import bio.terra.pearl.core.factory.participant.EnrolleeAndProxy; import bio.terra.pearl.core.factory.participant.EnrolleeFactory; import bio.terra.pearl.core.factory.survey.AnswerFactory; import bio.terra.pearl.core.factory.survey.SurveyFactory; @@ -99,9 +101,9 @@ public void testExportNumberLimit(TestInfo testInfo) { @Transactional public void testExportWithProxies(TestInfo testInfo) { String testName = getTestName(testInfo); - StudyEnvironmentFactory.StudyEnvironmentBundle studyEnvBundle = studyEnvironmentFactory.buildBundle(testName, EnvironmentName.live); + StudyEnvironmentBundle studyEnvBundle = studyEnvironmentFactory.buildBundle(testName, EnvironmentName.live); StudyEnvironment studyEnv = studyEnvBundle.getStudyEnv(); - EnrolleeFactory.EnrolleeAndProxy enrolleeWithProxy = enrolleeFactory.buildProxyAndGovernedEnrollee(testName, studyEnvBundle.getPortalEnv(), studyEnvBundle.getStudyEnv()); + EnrolleeAndProxy enrolleeWithProxy = enrolleeFactory.buildProxyAndGovernedEnrollee(testName, studyEnvBundle.getPortalEnv(), studyEnvBundle.getStudyEnv()); Enrollee regularEnrollee = enrolleeFactory.buildPersisted(testName, studyEnv, new Profile()); List exportData = enrolleeExportService.loadEnrolleeExportData(studyEnv.getId(), new ExportOptionsWithExpression()); @@ -150,7 +152,7 @@ public void testExportWithProxies(TestInfo testInfo) { @Transactional public void testExportChecksStudyEnvConfigProxy(TestInfo testInfo) { String testName = getTestName(testInfo); - StudyEnvironmentFactory.StudyEnvironmentBundle studyEnvBundle = studyEnvironmentFactory.buildBundle(testName, EnvironmentName.sandbox); + StudyEnvironmentBundle studyEnvBundle = studyEnvironmentFactory.buildBundle(testName, EnvironmentName.sandbox); StudyEnvironment studyEnv = studyEnvBundle.getStudyEnv(); PortalEnvironment portalEnv = studyEnvBundle.getPortalEnv(); @@ -347,7 +349,7 @@ public void testGenerateSurveyModules(TestInfo testInfo) throws Exception { @Transactional public void testGenerateSurveyModulesAcrossVersions(TestInfo testInfo) throws Exception { String testName = getTestName(testInfo); - StudyEnvironmentFactory.StudyEnvironmentBundle bundle = studyEnvironmentFactory.buildBundle(testName, EnvironmentName.sandbox); + StudyEnvironmentBundle bundle = studyEnvironmentFactory.buildBundle(testName, EnvironmentName.sandbox); StudyEnvironment studyEnv = bundle.getStudyEnv(); Survey survey = surveyService.create( diff --git a/core/src/test/java/bio/terra/pearl/core/service/export/EnrolleeImportServiceTests.java b/core/src/test/java/bio/terra/pearl/core/service/export/EnrolleeImportServiceTests.java index 5f81d1f60e..763c3fb582 100644 --- a/core/src/test/java/bio/terra/pearl/core/service/export/EnrolleeImportServiceTests.java +++ b/core/src/test/java/bio/terra/pearl/core/service/export/EnrolleeImportServiceTests.java @@ -1,8 +1,10 @@ package bio.terra.pearl.core.service.export; import bio.terra.pearl.core.BaseSpringBootTest; +import bio.terra.pearl.core.factory.StudyEnvironmentBundle; import bio.terra.pearl.core.factory.StudyEnvironmentFactory; import bio.terra.pearl.core.factory.admin.AdminUserFactory; +import bio.terra.pearl.core.factory.participant.EnrolleeBundle; import bio.terra.pearl.core.factory.participant.EnrolleeFactory; import bio.terra.pearl.core.factory.survey.SurveyFactory; import bio.terra.pearl.core.model.EnvironmentName; @@ -90,7 +92,7 @@ public class EnrolleeImportServiceTests extends BaseSpringBootTest { KitRequestService kitRequestService; public DataImportSetUp setup(TestInfo info, String csvString) { - StudyEnvironmentFactory.StudyEnvironmentBundle bundle = studyEnvironmentFactory.buildBundle(getTestName(info), EnvironmentName.irb); + StudyEnvironmentBundle bundle = studyEnvironmentFactory.buildBundle(getTestName(info), EnvironmentName.irb); AdminUser adminUser = adminUserFactory.buildPersisted(getTestName(info)); //create survey @@ -298,7 +300,7 @@ public void testImportEnrolleeUpdateDiffPortalCSV(TestInfo info) { @Test @Transactional public void testImportEnrollees(TestInfo info) { - StudyEnvironmentFactory.StudyEnvironmentBundle bundle = studyEnvironmentFactory.buildBundle(getTestName(info), EnvironmentName.irb); + StudyEnvironmentBundle bundle = studyEnvironmentFactory.buildBundle(getTestName(info), EnvironmentName.irb); AdminUser adminUser = adminUserFactory.buildPersisted(getTestName(info)); @@ -347,7 +349,7 @@ public void testGenerateImportMaps(TestInfo info) { @Test @Transactional public void testBaseEnrolleeImport(TestInfo info) { - StudyEnvironmentFactory.StudyEnvironmentBundle bundle = studyEnvironmentFactory.buildBundle(getTestName(info), EnvironmentName.irb); + StudyEnvironmentBundle bundle = studyEnvironmentFactory.buildBundle(getTestName(info), EnvironmentName.irb); String username = "test-%s@test.com".formatted(RandomStringUtils.randomAlphabetic(5)); Map enrolleeMap = Map.of("enrollee.subject", "true", "account.username", username); enrolleeImportService.importEnrollee( @@ -364,7 +366,7 @@ public void testBaseEnrolleeImport(TestInfo info) { @Test @Transactional public void testEnrolleeProfileImport(TestInfo info) { - StudyEnvironmentFactory.StudyEnvironmentBundle bundle = studyEnvironmentFactory.buildBundle(getTestName(info), EnvironmentName.irb); + StudyEnvironmentBundle bundle = studyEnvironmentFactory.buildBundle(getTestName(info), EnvironmentName.irb); String username = "test-%s@test.com".formatted(RandomStringUtils.randomAlphabetic(5)); Map enrolleeMap = Map.of( "account.username", username, @@ -393,8 +395,8 @@ public void testEnrolleeProfileImport(TestInfo info) { @Test @Transactional public void testEnrolleeProfileImportDoesntOverwrite(TestInfo info) { - StudyEnvironmentFactory.StudyEnvironmentBundle study1Bundle = studyEnvironmentFactory.buildBundle(getTestName(info), EnvironmentName.irb); - StudyEnvironmentFactory.StudyEnvironmentBundle study2Bundle = studyEnvironmentFactory.buildBundle(getTestName(info), EnvironmentName.irb, + StudyEnvironmentBundle study1Bundle = studyEnvironmentFactory.buildBundle(getTestName(info), EnvironmentName.irb); + StudyEnvironmentBundle study2Bundle = studyEnvironmentFactory.buildBundle(getTestName(info), EnvironmentName.irb, study1Bundle.getPortal(), study1Bundle.getPortalEnv()); Profile existingProfile = Profile.builder() .givenName("John") @@ -404,7 +406,7 @@ public void testEnrolleeProfileImportDoesntOverwrite(TestInfo info) { .postalCode("12345") .build()) .build(); - EnrolleeFactory.EnrolleeBundle enrolleeBundle = enrolleeFactory.buildWithPortalUser(getTestName(info), study1Bundle.getPortalEnv(), study1Bundle.getStudyEnv(), existingProfile); + EnrolleeBundle enrolleeBundle = enrolleeFactory.buildWithPortalUser(getTestName(info), study1Bundle.getPortalEnv(), study1Bundle.getStudyEnv(), existingProfile); String username = enrolleeBundle.participantUser().getUsername(); Map enrolleeMap = Map.of( "account.username", username, @@ -459,7 +461,7 @@ public void testEnrolleeProfileImportDoesntOverwrite(TestInfo info) { @Test @Transactional public void testSurveyResponseImport(TestInfo info) { - StudyEnvironmentFactory.StudyEnvironmentBundle bundle = studyEnvironmentFactory.buildBundle(getTestName(info), EnvironmentName.irb); + StudyEnvironmentBundle bundle = studyEnvironmentFactory.buildBundle(getTestName(info), EnvironmentName.irb); Survey survey = surveyFactory.buildPersisted(surveyFactory.builder(getTestName(info)) .stableId("importTest1") .content(TWO_QUESTION_SURVEY_CONTENT) @@ -512,7 +514,7 @@ public void testSurveyResponseImport(TestInfo info) { @Test @Transactional public void testSurveyResponseImportDefaultComplete(TestInfo info) { - StudyEnvironmentFactory.StudyEnvironmentBundle bundle = studyEnvironmentFactory.buildBundle(getTestName(info), EnvironmentName.irb); + StudyEnvironmentBundle bundle = studyEnvironmentFactory.buildBundle(getTestName(info), EnvironmentName.irb); Survey survey = surveyFactory.buildPersisted(surveyFactory.builder(getTestName(info)) .stableId("importTest1") .content(TWO_QUESTION_SURVEY_CONTENT) @@ -595,7 +597,7 @@ private void verifyImport(Import dataImport, int importItemCount) { assertThat(enrolleeCount, equalTo(Long.valueOf(importItemCount))); } - private Import doImport(StudyEnvironmentFactory.StudyEnvironmentBundle bundle, String csvString, AdminUser admin, ImportFileFormat fileType) { + private Import doImport(StudyEnvironmentBundle bundle, String csvString, AdminUser admin, ImportFileFormat fileType) { return enrolleeImportService.importEnrollees( bundle.getPortal().getShortcode(), bundle.getStudy().getShortcode(), @@ -634,7 +636,7 @@ private void verifyKitRequests(ImportItem importItem, List expect @NoArgsConstructor @Builder public static class DataImportSetUp { - private StudyEnvironmentFactory.StudyEnvironmentBundle bundle; + private StudyEnvironmentBundle bundle; private AdminUser adminUser; private String csvString; } diff --git a/core/src/test/java/bio/terra/pearl/core/service/kit/KitRequestServiceTest.java b/core/src/test/java/bio/terra/pearl/core/service/kit/KitRequestServiceTest.java index 29e89d5a09..8caa68df61 100644 --- a/core/src/test/java/bio/terra/pearl/core/service/kit/KitRequestServiceTest.java +++ b/core/src/test/java/bio/terra/pearl/core/service/kit/KitRequestServiceTest.java @@ -3,10 +3,12 @@ import bio.terra.pearl.core.BaseSpringBootTest; import bio.terra.pearl.core.dao.kit.KitRequestDao; import bio.terra.pearl.core.dao.study.StudyDao; +import bio.terra.pearl.core.factory.StudyEnvironmentBundle; import bio.terra.pearl.core.factory.StudyEnvironmentFactory; import bio.terra.pearl.core.factory.admin.AdminUserFactory; import bio.terra.pearl.core.factory.kit.KitRequestFactory; import bio.terra.pearl.core.factory.kit.KitTypeFactory; +import bio.terra.pearl.core.factory.participant.EnrolleeBundle; import bio.terra.pearl.core.factory.participant.EnrolleeFactory; import bio.terra.pearl.core.factory.portal.PortalEnvironmentFactory; import bio.terra.pearl.core.model.EnvironmentName; @@ -33,8 +35,6 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestInfo; -import org.mockito.ArgumentMatcher; -import org.mockito.ArgumentMatchers; import org.mockito.Mockito; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.mock.mockito.MockBean; @@ -64,7 +64,7 @@ public class KitRequestServiceTest extends BaseSpringBootTest { @Test public void testRequestKitAssemble(TestInfo testInfo) throws Exception { AdminUser adminUser = adminUserFactory.buildPersisted(getTestName(testInfo)); - EnrolleeFactory.EnrolleeBundle enrolleeBundle = enrolleeFactory.buildWithPortalUser(getTestName(testInfo)); + EnrolleeBundle enrolleeBundle = enrolleeFactory.buildWithPortalUser(getTestName(testInfo)); Enrollee enrollee = enrolleeBundle.enrollee(); Profile profile = enrollee.getProfile(); profile.setGivenName("Alex"); @@ -93,7 +93,7 @@ public void testRequestKitAssemble(TestInfo testInfo) throws Exception { public void testRequestKitError(TestInfo testInfo) { AdminUser adminUser = adminUserFactory.buildPersisted(getTestName(testInfo)); KitType kitType = kitTypeFactory.buildPersisted(getTestName(testInfo)); - EnrolleeFactory.EnrolleeBundle enrolleeBundle = enrolleeFactory.buildWithPortalUser(getTestName(testInfo)); + EnrolleeBundle enrolleeBundle = enrolleeFactory.buildWithPortalUser(getTestName(testInfo)); Enrollee enrollee = enrolleeBundle.enrollee(); Profile profile = enrollee.getProfile(); profile.setGivenName("Alex"); @@ -120,7 +120,7 @@ public void testRequestKitError(TestInfo testInfo) { public void testRequestKitMailed(TestInfo testInfo) throws JsonProcessingException { AdminUser adminUser = adminUserFactory.buildPersisted(getTestName(testInfo)); KitType kitType = kitTypeFactory.buildPersisted(getTestName(testInfo)); - EnrolleeFactory.EnrolleeBundle enrolleeBundle = enrolleeFactory.buildWithPortalUser(getTestName(testInfo)); + EnrolleeBundle enrolleeBundle = enrolleeFactory.buildWithPortalUser(getTestName(testInfo)); Enrollee enrollee = enrolleeBundle.enrollee(); Profile profile = enrollee.getProfile(); profile.setGivenName("Alex"); @@ -151,7 +151,7 @@ public void testRequestKitMailed(TestInfo testInfo) throws JsonProcessingExcepti public void testRequestKitInPerson(TestInfo testInfo) { AdminUser adminUser = adminUserFactory.buildPersisted(getTestName(testInfo)); KitType kitType = kitTypeFactory.buildPersisted(getTestName(testInfo)); - EnrolleeFactory.EnrolleeBundle enrolleeBundle = enrolleeFactory.buildWithPortalUser(getTestName(testInfo)); + EnrolleeBundle enrolleeBundle = enrolleeFactory.buildWithPortalUser(getTestName(testInfo)); Enrollee enrollee = enrolleeBundle.enrollee(); Profile profile = enrollee.getProfile(); profile.setGivenName("Alex"); @@ -177,7 +177,7 @@ public void testRequestKitInPerson(TestInfo testInfo) { @Test void testUpdateKitStatus(TestInfo testInfo) throws Exception { String testName = getTestName(testInfo); - EnrolleeFactory.EnrolleeBundle enrolleeBundle = enrolleeFactory.buildWithPortalUser(testName); + EnrolleeBundle enrolleeBundle = enrolleeFactory.buildWithPortalUser(testName); AdminUser adminUser = adminUserFactory.buildPersisted(testName); Enrollee enrollee = enrolleeBundle.enrollee(); KitType kitType = kitTypeFactory.buildPersisted(testName); @@ -255,7 +255,7 @@ public void testGetKitsByStudyEnvironment(TestInfo testInfo) throws Exception { public void testCantCollectMailedKit(TestInfo testInfo) throws JsonProcessingException { String testName = getTestName(testInfo); AdminUser adminUser = adminUserFactory.buildPersisted(getTestName(testInfo)); - EnrolleeFactory.EnrolleeBundle enrolleeBundle = enrolleeFactory.buildWithPortalUser(getTestName(testInfo)); + EnrolleeBundle enrolleeBundle = enrolleeFactory.buildWithPortalUser(getTestName(testInfo)); Enrollee enrollee = enrolleeBundle.enrollee(); KitType kitType = kitTypeFactory.buildPersisted(testName); KitRequest kitRequest = kitRequestFactory.buildPersisted(testName, @@ -271,7 +271,7 @@ public void testCantCollectMailedKit(TestInfo testInfo) throws JsonProcessingExc public void testAssignKit(TestInfo testInfo) throws JsonProcessingException { String testName = getTestName(testInfo); AdminUser adminUser = adminUserFactory.buildPersisted(getTestName(testInfo)); - EnrolleeFactory.EnrolleeBundle enrolleeBundle = enrolleeFactory.buildWithPortalUser(getTestName(testInfo)); + EnrolleeBundle enrolleeBundle = enrolleeFactory.buildWithPortalUser(getTestName(testInfo)); Enrollee enrollee = enrolleeBundle.enrollee(); KitType kitType = kitTypeFactory.buildPersisted(testName); KitRequest kitRequest = kitRequestDao.create( @@ -294,7 +294,7 @@ public void testAssignKit(TestInfo testInfo) throws JsonProcessingException { public void testCollectInPersonKit(TestInfo testInfo) throws JsonProcessingException { String testName = getTestName(testInfo); AdminUser adminUser = adminUserFactory.buildPersisted(getTestName(testInfo)); - EnrolleeFactory.EnrolleeBundle enrolleeBundle = enrolleeFactory.buildWithPortalUser(getTestName(testInfo)); + EnrolleeBundle enrolleeBundle = enrolleeFactory.buildWithPortalUser(getTestName(testInfo)); Enrollee enrollee = enrolleeBundle.enrollee(); KitType kitType = kitTypeFactory.buildPersisted(testName); KitRequest kitRequest = kitRequestDao.create( @@ -414,8 +414,8 @@ public void testSyncAllKitStatusesFromPepper(TestInfo testInfo) throws Exception PortalEnvironment portalEnv = portalEnvironmentFactory.buildPersisted(testName); kitTypeFactory.attachTypeToEnvironment(kitType.getId(), studyEnvironment.getId()); Study study = studyDao.find(studyEnvironment.getStudyId()).get(); - EnrolleeFactory.EnrolleeBundle enrolleeBundle1a = enrolleeFactory.buildWithPortalUser(testName, portalEnv, studyEnvironment); - EnrolleeFactory.EnrolleeBundle enrolleeBundle1b = enrolleeFactory.buildWithPortalUser(testName, portalEnv, studyEnvironment); + EnrolleeBundle enrolleeBundle1a = enrolleeFactory.buildWithPortalUser(testName, portalEnv, studyEnvironment); + EnrolleeBundle enrolleeBundle1b = enrolleeFactory.buildWithPortalUser(testName, portalEnv, studyEnvironment); Enrollee enrollee1a = enrolleeBundle1a.enrollee(); Enrollee enrollee1b = enrolleeBundle1b.enrollee(); @@ -427,7 +427,7 @@ public void testSyncAllKitStatusesFromPepper(TestInfo testInfo) throws Exception StudyEnvironment studyEnvironment2 = studyEnvironmentFactory.buildPersisted(testName); kitTypeFactory.attachTypeToEnvironment(kitType.getId(), studyEnvironment2.getId()); Study study2 = studyDao.find(studyEnvironment2.getStudyId()).get(); - EnrolleeFactory.EnrolleeBundle enrolleeBundle2 = enrolleeFactory.buildWithPortalUser(testName, portalEnv, studyEnvironment2); + EnrolleeBundle enrolleeBundle2 = enrolleeFactory.buildWithPortalUser(testName, portalEnv, studyEnvironment2); Enrollee enrollee2 = enrolleeBundle2.enrollee(); KitRequest kitRequest2 = kitRequestFactory.buildPersisted(testName, enrollee2, PepperKitStatus.CREATED, kitType.getId(), adminUser.getId()); @@ -474,7 +474,7 @@ public void testSyncAllKitStatusesFromPepper(TestInfo testInfo) throws Exception @Test void testNotifyKitStatus(TestInfo testInfo) { String testName = getTestName(testInfo); - EnrolleeFactory.EnrolleeBundle enrolleeBundle = enrolleeFactory.buildWithPortalUser(testName); + EnrolleeBundle enrolleeBundle = enrolleeFactory.buildWithPortalUser(testName); UUID kitRequestId = UUID.randomUUID(); KitRequest kitRequest = KitRequest.builder() @@ -524,7 +524,7 @@ public void testRequestKitStudyEnvConfig(TestInfo testInfo) throws Exception { // set up a study and enrollee, initially set the study env to use stub DSM String testName = getTestName(testInfo); AdminUser adminUser = adminUserFactory.buildPersisted(testName); - StudyEnvironmentFactory.StudyEnvironmentBundle envBundle = studyEnvironmentFactory.buildBundle(testName, EnvironmentName.sandbox); + StudyEnvironmentBundle envBundle = studyEnvironmentFactory.buildBundle(testName, EnvironmentName.sandbox); StudyEnvironmentConfig config = studyEnvironmentConfigService.find(envBundle.getStudyEnv().getStudyEnvironmentConfigId()).orElseThrow(); config.setUseStubDsm(true); studyEnvironmentConfigService.update(config); diff --git a/core/src/test/java/bio/terra/pearl/core/service/kit/KitTaskDispatcherTest.java b/core/src/test/java/bio/terra/pearl/core/service/kit/KitTaskDispatcherTest.java index 3597a64d07..f247edf13c 100644 --- a/core/src/test/java/bio/terra/pearl/core/service/kit/KitTaskDispatcherTest.java +++ b/core/src/test/java/bio/terra/pearl/core/service/kit/KitTaskDispatcherTest.java @@ -10,6 +10,7 @@ import java.util.UUID; import bio.terra.pearl.core.BaseSpringBootTest; +import bio.terra.pearl.core.factory.participant.EnrolleeBundle; import bio.terra.pearl.core.factory.participant.EnrolleeFactory; import bio.terra.pearl.core.model.kit.KitRequest; import bio.terra.pearl.core.model.kit.KitRequestStatus; @@ -35,7 +36,7 @@ class KitTaskDispatcherTest extends BaseSpringBootTest { @Transactional void testKitSentEventHandler(TestInfo testInfo) { String testName = getTestName(testInfo); - EnrolleeFactory.EnrolleeBundle enrolleeBundle = enrolleeFactory.buildWithPortalUser(testName); + EnrolleeBundle enrolleeBundle = enrolleeFactory.buildWithPortalUser(testName); KitRequest kitRequest = buildKitRequest(enrolleeBundle); UUID kitRequestId = kitRequest.getId(); @@ -63,7 +64,7 @@ void testKitSentEventHandler(TestInfo testInfo) { @Transactional void testKitReceivedEventHandler(TestInfo testInfo) { String testName = getTestName(testInfo); - EnrolleeFactory.EnrolleeBundle enrolleeBundle = enrolleeFactory.buildWithPortalUser(testName); + EnrolleeBundle enrolleeBundle = enrolleeFactory.buildWithPortalUser(testName); KitRequest kitRequest = buildKitRequest(enrolleeBundle); UUID kitRequestId = kitRequest.getId(); @@ -94,7 +95,7 @@ void testKitReceivedEventHandler(TestInfo testInfo) { @Transactional void testKitSentEventHandlerWithReset(TestInfo testInfo) { String testName = getTestName(testInfo); - EnrolleeFactory.EnrolleeBundle enrolleeBundle = enrolleeFactory.buildWithPortalUser(testName); + EnrolleeBundle enrolleeBundle = enrolleeFactory.buildWithPortalUser(testName); KitRequest kitRequest = buildKitRequest(enrolleeBundle); UUID kitRequestId = kitRequest.getId(); @@ -120,7 +121,7 @@ void testKitSentEventHandlerWithReset(TestInfo testInfo) { verify(mockTaskService).update(any(ParticipantTask.class), any(DataAuditInfo.class)); } - private KitRequest buildKitRequest(EnrolleeFactory.EnrolleeBundle enrolleeBundle) { + private KitRequest buildKitRequest(EnrolleeBundle enrolleeBundle) { UUID kitRequestId = UUID.randomUUID(); return KitRequest.builder() .id(kitRequestId) @@ -129,7 +130,7 @@ private KitRequest buildKitRequest(EnrolleeFactory.EnrolleeBundle enrolleeBundle .build(); } - private void verifyTask(ParticipantTask task, EnrolleeFactory.EnrolleeBundle enrolleeBundle, UUID kitRequestId) { + private void verifyTask(ParticipantTask task, EnrolleeBundle enrolleeBundle, UUID kitRequestId) { assertThat(task.getTaskType(), equalTo(TaskType.KIT_REQUEST)); assertThat(task.getTargetName(), equalTo("Kit Request")); assertThat(task.getTargetStableId(), equalTo("kit_request")); diff --git a/core/src/test/java/bio/terra/pearl/core/service/notification/EnrolleeReminderServiceTests.java b/core/src/test/java/bio/terra/pearl/core/service/notification/EnrolleeReminderServiceTests.java index a3e96ab0dc..039398bc9d 100644 --- a/core/src/test/java/bio/terra/pearl/core/service/notification/EnrolleeReminderServiceTests.java +++ b/core/src/test/java/bio/terra/pearl/core/service/notification/EnrolleeReminderServiceTests.java @@ -3,6 +3,7 @@ import bio.terra.pearl.core.BaseSpringBootTest; import bio.terra.pearl.core.dao.notification.NotificationDao; import bio.terra.pearl.core.factory.StudyEnvironmentFactory; +import bio.terra.pearl.core.factory.participant.EnrolleeBundle; import bio.terra.pearl.core.factory.participant.EnrolleeFactory; import bio.terra.pearl.core.factory.participant.ParticipantTaskFactory; import bio.terra.pearl.core.factory.portal.PortalEnvironmentFactory; @@ -36,7 +37,7 @@ public class EnrolleeReminderServiceTests extends BaseSpringBootTest { public void testConsentReminders(TestInfo info) { PortalEnvironment portalEnv = portalEnvironmentFactory.buildPersisted(getTestName(info)); StudyEnvironment studyEnv = studyEnvironmentFactory.buildPersisted(portalEnv, getTestName(info)); - EnrolleeFactory.EnrolleeBundle enrolleeBundle = enrolleeFactory.buildWithPortalUser(getTestName(info), portalEnv, studyEnv); + EnrolleeBundle enrolleeBundle = enrolleeFactory.buildWithPortalUser(getTestName(info), portalEnv, studyEnv); ParticipantTask newTask1 = participantTaskFactory.buildPersisted(enrolleeBundle, TaskStatus.NEW, TaskType.CONSENT); Trigger config = Trigger.builder() diff --git a/core/src/test/java/bio/terra/pearl/core/service/notification/NotificationDispatcherTests.java b/core/src/test/java/bio/terra/pearl/core/service/notification/NotificationDispatcherTests.java index 83ae2e3933..e3aa6f5991 100644 --- a/core/src/test/java/bio/terra/pearl/core/service/notification/NotificationDispatcherTests.java +++ b/core/src/test/java/bio/terra/pearl/core/service/notification/NotificationDispatcherTests.java @@ -2,6 +2,7 @@ import bio.terra.pearl.core.BaseSpringBootTest; import bio.terra.pearl.core.factory.kit.KitTypeFactory; +import bio.terra.pearl.core.factory.participant.EnrolleeBundle; import bio.terra.pearl.core.factory.participant.EnrolleeFactory; import bio.terra.pearl.core.model.kit.KitRequest; import bio.terra.pearl.core.model.kit.KitRequestStatus; @@ -21,7 +22,7 @@ public class NotificationDispatcherTests extends BaseSpringBootTest { @Test @Transactional public void testEventTriggersNotificationCreation() { - EnrolleeFactory.EnrolleeBundle enrolleeBundle = enrolleeFactory + EnrolleeBundle enrolleeBundle = enrolleeFactory .buildWithPortalUser("notificationTriggers"); Trigger config = createNotificationConfig(enrolleeBundle, TriggerEventType.STUDY_ENROLLMENT); @@ -33,7 +34,7 @@ public void testEventTriggersNotificationCreation() { @Transactional void testKitSentEvent(TestInfo testInfo) { String testName = getTestName(testInfo); - EnrolleeFactory.EnrolleeBundle enrolleeBundle = enrolleeFactory + EnrolleeBundle enrolleeBundle = enrolleeFactory .buildWithPortalUser(testName); Trigger config = createNotificationConfig(enrolleeBundle, TriggerEventType.KIT_SENT); KitRequest kitRequest = KitRequest.builder() @@ -51,7 +52,7 @@ void testKitSentEvent(TestInfo testInfo) { @Transactional void testKitReceivedEvent(TestInfo testInfo) { String testName = getTestName(testInfo); - EnrolleeFactory.EnrolleeBundle enrolleeBundle = enrolleeFactory + EnrolleeBundle enrolleeBundle = enrolleeFactory .buildWithPortalUser(testName); Trigger config = createNotificationConfig(enrolleeBundle, TriggerEventType.KIT_RECEIVED); KitRequest kitRequest = KitRequest.builder() @@ -65,7 +66,7 @@ void testKitReceivedEvent(TestInfo testInfo) { verifyNotification(config, enrolleeBundle); } - private Trigger createNotificationConfig(EnrolleeFactory.EnrolleeBundle enrolleeBundle, TriggerEventType eventType) { + private Trigger createNotificationConfig(EnrolleeBundle enrolleeBundle, TriggerEventType eventType) { Enrollee enrollee = enrolleeBundle.enrollee(); Trigger config = Trigger.builder() .studyEnvironmentId(enrollee.getStudyEnvironmentId()) @@ -79,7 +80,7 @@ private Trigger createNotificationConfig(EnrolleeFactory.EnrolleeBundle enrollee } - private void verifyNotification(Trigger config, EnrolleeFactory.EnrolleeBundle enrolleeBundle) { + private void verifyNotification(Trigger config, EnrolleeBundle enrolleeBundle) { Enrollee enrollee = enrolleeBundle.enrollee(); List notifications = notificationService.findByEnrolleeId(enrollee.getId()); assertThat(notifications, hasSize(1)); diff --git a/core/src/test/java/bio/terra/pearl/core/service/notification/NotificationServiceTest.java b/core/src/test/java/bio/terra/pearl/core/service/notification/NotificationServiceTest.java index 7e385f51c5..106ea6da71 100644 --- a/core/src/test/java/bio/terra/pearl/core/service/notification/NotificationServiceTest.java +++ b/core/src/test/java/bio/terra/pearl/core/service/notification/NotificationServiceTest.java @@ -4,6 +4,7 @@ import bio.terra.pearl.core.dao.notification.SendgridEventDao; import bio.terra.pearl.core.factory.notification.NotificationFactory; import bio.terra.pearl.core.factory.notification.TriggerFactory; +import bio.terra.pearl.core.factory.participant.EnrolleeBundle; import bio.terra.pearl.core.factory.participant.EnrolleeFactory; import bio.terra.pearl.core.model.notification.Notification; import bio.terra.pearl.core.model.notification.SendgridEvent; @@ -33,8 +34,8 @@ class NotificationServiceTest extends BaseSpringBootTest { @Transactional void findAllByConfigId(TestInfo info) { - EnrolleeFactory.EnrolleeBundle bundle1 = enrolleeFactory.buildWithPortalUser(getTestName(info)); - EnrolleeFactory.EnrolleeBundle bundle2 = enrolleeFactory.buildWithPortalUser(getTestName(info)); + EnrolleeBundle bundle1 = enrolleeFactory.buildWithPortalUser(getTestName(info)); + EnrolleeBundle bundle2 = enrolleeFactory.buildWithPortalUser(getTestName(info)); Trigger trigger1 = triggerFactory.buildPersisted(getTestName(info)); Trigger trigger2 = triggerFactory.buildPersisted(getTestName(info)); @@ -63,8 +64,8 @@ void findAllByConfigId(TestInfo info) { @Transactional void findAllByConfigIdWithEnrollees(TestInfo info) { - EnrolleeFactory.EnrolleeBundle bundle1 = enrolleeFactory.buildWithPortalUser(getTestName(info)); - EnrolleeFactory.EnrolleeBundle bundle2 = enrolleeFactory.buildWithPortalUser(getTestName(info)); + EnrolleeBundle bundle1 = enrolleeFactory.buildWithPortalUser(getTestName(info)); + EnrolleeBundle bundle2 = enrolleeFactory.buildWithPortalUser(getTestName(info)); Trigger trigger1 = triggerFactory.buildPersisted(getTestName(info)); @@ -86,9 +87,9 @@ void findAllByConfigIdWithEnrollees(TestInfo info) { @Transactional void findAllByConfigIdAttachSendgridEvents(TestInfo info) { - EnrolleeFactory.EnrolleeBundle bundle1 = enrolleeFactory.buildWithPortalUser(getTestName(info)); - EnrolleeFactory.EnrolleeBundle bundle2 = enrolleeFactory.buildWithPortalUser(getTestName(info)); - EnrolleeFactory.EnrolleeBundle bundle3 = enrolleeFactory.buildWithPortalUser(getTestName(info)); + EnrolleeBundle bundle1 = enrolleeFactory.buildWithPortalUser(getTestName(info)); + EnrolleeBundle bundle2 = enrolleeFactory.buildWithPortalUser(getTestName(info)); + EnrolleeBundle bundle3 = enrolleeFactory.buildWithPortalUser(getTestName(info)); Trigger trigger1 = triggerFactory.buildPersisted(getTestName(info)); diff --git a/core/src/test/java/bio/terra/pearl/core/service/notification/email/AdminEmailServiceTest.java b/core/src/test/java/bio/terra/pearl/core/service/notification/email/AdminEmailServiceTest.java index fce0a4b887..d5160b6838 100644 --- a/core/src/test/java/bio/terra/pearl/core/service/notification/email/AdminEmailServiceTest.java +++ b/core/src/test/java/bio/terra/pearl/core/service/notification/email/AdminEmailServiceTest.java @@ -1,11 +1,13 @@ package bio.terra.pearl.core.service.notification.email; import bio.terra.pearl.core.BaseSpringBootTest; +import bio.terra.pearl.core.factory.StudyEnvironmentBundle; import bio.terra.pearl.core.factory.StudyEnvironmentFactory; import bio.terra.pearl.core.factory.admin.AdminUserBundle; import bio.terra.pearl.core.factory.admin.PortalAdminUserFactory; import bio.terra.pearl.core.factory.notification.EmailTemplateFactory; import bio.terra.pearl.core.factory.notification.TriggerFactory; +import bio.terra.pearl.core.factory.participant.EnrolleeBundle; import bio.terra.pearl.core.factory.participant.EnrolleeFactory; import bio.terra.pearl.core.model.EnvironmentName; import bio.terra.pearl.core.model.notification.*; @@ -47,7 +49,7 @@ class AdminEmailServiceTest extends BaseSpringBootTest { @Transactional public void testSendFromTrigger(TestInfo info) throws Exception { - StudyEnvironmentFactory.StudyEnvironmentBundle bundle = studyEnvironmentFactory.buildBundle(getTestName(info), EnvironmentName.sandbox); + StudyEnvironmentBundle bundle = studyEnvironmentFactory.buildBundle(getTestName(info), EnvironmentName.sandbox); EmailTemplate emailTemplate = emailTemplateFactory.buildPersisted(getTestName(info), bundle.getPortal().getId()); localizedEmailTemplateService.create(LocalizedEmailTemplate.builder().emailTemplateId(emailTemplate.getId()).language("en").subject("subject").body("body").build()); @@ -61,7 +63,7 @@ public void testSendFromTrigger(TestInfo info) throws Exception { bundle.getStudyEnv().getId(), bundle.getPortalEnv().getId()); - EnrolleeFactory.EnrolleeBundle enrolleeBundle = enrolleeFactory.buildWithPortalUser(getTestName(info), bundle.getPortalEnv(), bundle.getStudyEnv()); + EnrolleeBundle enrolleeBundle = enrolleeFactory.buildWithPortalUser(getTestName(info), bundle.getPortalEnv(), bundle.getStudyEnv()); AdminUserBundle adminUserBundle1 = portalAdminUserFactory.buildPersistedWithPortals(getTestName(info), List.of(bundle.getPortal())); diff --git a/core/src/test/java/bio/terra/pearl/core/service/notification/email/EnrolleeEmailServiceTests.java b/core/src/test/java/bio/terra/pearl/core/service/notification/email/EnrolleeEmailServiceTests.java index bfc358f788..398ffd1588 100644 --- a/core/src/test/java/bio/terra/pearl/core/service/notification/email/EnrolleeEmailServiceTests.java +++ b/core/src/test/java/bio/terra/pearl/core/service/notification/email/EnrolleeEmailServiceTests.java @@ -4,6 +4,7 @@ import bio.terra.pearl.core.factory.notification.EmailTemplateFactory; import bio.terra.pearl.core.factory.notification.NotificationFactory; import bio.terra.pearl.core.factory.notification.TriggerFactory; +import bio.terra.pearl.core.factory.participant.EnrolleeBundle; import bio.terra.pearl.core.factory.participant.EnrolleeFactory; import bio.terra.pearl.core.model.EnvironmentName; import bio.terra.pearl.core.model.notification.*; @@ -155,7 +156,7 @@ public void testEmailBuildingWithMissingPreferredTemplate(TestInfo info) { @Test @Transactional public void testEmailSendOrSkip(TestInfo info) { - EnrolleeFactory.EnrolleeBundle enrolleeBundle = enrolleeFactory.buildWithPortalUser(getTestName(info)); + EnrolleeBundle enrolleeBundle = enrolleeFactory.buildWithPortalUser(getTestName(info)); EmailTemplate emailTemplate = emailTemplateFactory.buildPersisted(getTestName(info), enrolleeBundle.portalId()); Trigger config = triggerFactory.buildPersisted(Trigger.builder() .emailTemplateId(emailTemplate.getId()) @@ -170,7 +171,7 @@ public void testEmailSendOrSkip(TestInfo info) { @Test @Transactional public void testEmailSendOrSkipSolicit(TestInfo info) { - EnrolleeFactory.EnrolleeBundle enrolleeBundle = enrolleeFactory.buildWithPortalUser(getTestName(info)); + EnrolleeBundle enrolleeBundle = enrolleeFactory.buildWithPortalUser(getTestName(info)); EmailTemplate emailTemplate = emailTemplateFactory.buildPersisted(getTestName(info), enrolleeBundle.portalId()); Trigger config = triggerFactory.buildPersisted(Trigger.builder() .emailTemplateId(emailTemplate.getId()) @@ -183,7 +184,7 @@ public void testEmailSendOrSkipSolicit(TestInfo info) { testDoNotSendSolicitProfile(enrolleeEmailService, enrolleeBundle, config); } - private void testSendProfile(EnrolleeEmailService enrolleeEmailService, EnrolleeFactory.EnrolleeBundle enrolleeBundle, Trigger config) { + private void testSendProfile(EnrolleeEmailService enrolleeEmailService, EnrolleeBundle enrolleeBundle, Trigger config) { Notification notification = notificationFactory.buildPersisted(enrolleeBundle, config); EnrolleeContext ruleData = new EnrolleeContext(enrolleeBundle.enrollee(), Profile.builder().contactEmail("someAddress").build(), null); NotificationContextInfo contextInfo = new NotificationContextInfo(null, null, null, null, null); @@ -193,7 +194,7 @@ private void testSendProfile(EnrolleeEmailService enrolleeEmailService, Enrollee assertThat(updatedNotification.getDeliveryStatus(), equalTo(NotificationDeliveryStatus.FAILED)); } - private void testDoNotSendProfile(EnrolleeEmailService enrolleeEmailService, EnrolleeFactory.EnrolleeBundle enrolleeBundle, Trigger config) { + private void testDoNotSendProfile(EnrolleeEmailService enrolleeEmailService, EnrolleeBundle enrolleeBundle, Trigger config) { Notification notification = notificationFactory.buildPersisted(enrolleeBundle, config); EnrolleeContext ruleData = new EnrolleeContext(enrolleeBundle.enrollee(), Profile.builder().doNotEmail(true).build(), null); NotificationContextInfo contextInfo = new NotificationContextInfo(null, null, null, null, null); @@ -202,7 +203,7 @@ private void testDoNotSendProfile(EnrolleeEmailService enrolleeEmailService, Enr assertThat(updatedNotification.getDeliveryStatus(), equalTo(NotificationDeliveryStatus.SKIPPED)); } - private void testDoNotSendSolicitProfile(EnrolleeEmailService enrolleeEmailService, EnrolleeFactory.EnrolleeBundle enrolleeBundle, Trigger config) { + private void testDoNotSendSolicitProfile(EnrolleeEmailService enrolleeEmailService, EnrolleeBundle enrolleeBundle, Trigger config) { Notification notification = notificationFactory.buildPersisted(enrolleeBundle, config); EnrolleeContext ruleData = new EnrolleeContext(enrolleeBundle.enrollee(), Profile.builder().doNotEmail(false).doNotEmailSolicit(true).build(), null); NotificationContextInfo contextInfo = new NotificationContextInfo(null, null, null, null, null); diff --git a/core/src/test/java/bio/terra/pearl/core/service/participant/EnrolleeRelationServiceTest.java b/core/src/test/java/bio/terra/pearl/core/service/participant/EnrolleeRelationServiceTest.java index 676f2013e7..a6f807d118 100644 --- a/core/src/test/java/bio/terra/pearl/core/service/participant/EnrolleeRelationServiceTest.java +++ b/core/src/test/java/bio/terra/pearl/core/service/participant/EnrolleeRelationServiceTest.java @@ -2,6 +2,8 @@ import bio.terra.pearl.core.BaseSpringBootTest; import bio.terra.pearl.core.factory.StudyEnvironmentFactory; +import bio.terra.pearl.core.factory.participant.EnrolleeAndProxy; +import bio.terra.pearl.core.factory.participant.EnrolleeBundle; import bio.terra.pearl.core.factory.participant.EnrolleeFactory; import bio.terra.pearl.core.factory.participant.FamilyFactory; import bio.terra.pearl.core.factory.portal.PortalEnvironmentFactory; @@ -50,11 +52,11 @@ void testIsUserProxyForAnyOf(TestInfo info) { StudyEnvironment studyEnv1 = studyEnvironmentFactory.buildPersisted(portalEnv, getTestName(info)); StudyEnvironment studyEnv2 = studyEnvironmentFactory.buildPersisted(portalEnv, getTestName(info)); - EnrolleeFactory.EnrolleeBundle proxyBundle = enrolleeFactory.buildWithPortalUser(getTestName(info), portalEnv, studyEnv1); + EnrolleeBundle proxyBundle = enrolleeFactory.buildWithPortalUser(getTestName(info), portalEnv, studyEnv1); PortalParticipantUser proxyPpUser = proxyBundle.portalParticipantUser(); Enrollee proxyEnrollee = proxyBundle.enrollee(); - EnrolleeFactory.EnrolleeBundle targetBundle = enrolleeFactory.buildWithPortalUser(getTestName(info), portalEnv, studyEnv1); + EnrolleeBundle targetBundle = enrolleeFactory.buildWithPortalUser(getTestName(info), portalEnv, studyEnv1); Enrollee targetEnrollee1 = targetBundle.enrollee(); Enrollee targetEnrollee2 = enrolleeFactory.buildPersisted( getTestName(info), @@ -86,9 +88,9 @@ void testIsUserProxyForAnyOf(TestInfo info) { void testIsRelationshipValid(TestInfo info){ PortalEnvironment portalEnv = portalEnvironmentFactory.buildPersisted(getTestName(info)); StudyEnvironment studyEnv1 = studyEnvironmentFactory.buildPersisted(portalEnv, getTestName(info)); - EnrolleeFactory.EnrolleeBundle proxyBundle = enrolleeFactory.buildWithPortalUser(getTestName(info), portalEnv, studyEnv1); + EnrolleeBundle proxyBundle = enrolleeFactory.buildWithPortalUser(getTestName(info), portalEnv, studyEnv1); Enrollee proxyEnrollee = proxyBundle.enrollee(); - EnrolleeFactory.EnrolleeBundle targetBundle = enrolleeFactory.buildWithPortalUser(getTestName(info), portalEnv, studyEnv1); + EnrolleeBundle targetBundle = enrolleeFactory.buildWithPortalUser(getTestName(info), portalEnv, studyEnv1); Enrollee targetEnrollee1 = targetBundle.enrollee(); EnrolleeRelation enrolleeRelation = enrolleeRelationService.create( EnrolleeRelation @@ -118,11 +120,11 @@ void testIsRelationshipValid(TestInfo info){ public void testFindAllValidByTwoProperties(TestInfo info) { PortalEnvironment portalEnv = portalEnvironmentFactory.buildPersisted(getTestName(info)); StudyEnvironment studyEnv1 = studyEnvironmentFactory.buildPersisted(portalEnv, getTestName(info)); - EnrolleeFactory.EnrolleeBundle proxyBundle = enrolleeFactory.buildWithPortalUser(getTestName(info), portalEnv, studyEnv1); + EnrolleeBundle proxyBundle = enrolleeFactory.buildWithPortalUser(getTestName(info), portalEnv, studyEnv1); Enrollee proxyEnrollee = proxyBundle.enrollee(); - EnrolleeFactory.EnrolleeBundle targetBundle = enrolleeFactory.buildWithPortalUser(getTestName(info), portalEnv, studyEnv1); + EnrolleeBundle targetBundle = enrolleeFactory.buildWithPortalUser(getTestName(info), portalEnv, studyEnv1); Enrollee targetEnrollee1 = targetBundle.enrollee(); - EnrolleeFactory.EnrolleeBundle targetBundle2 = enrolleeFactory.buildWithPortalUser(getTestName(info), portalEnv, studyEnv1); + EnrolleeBundle targetBundle2 = enrolleeFactory.buildWithPortalUser(getTestName(info), portalEnv, studyEnv1); Enrollee targetEnrollee2 = targetBundle2.enrollee(); Instant yesterday = Instant.now().minusSeconds(86400); Instant tomorrow = Instant.now().plusSeconds(86400); @@ -164,11 +166,11 @@ public void testFindAllValidByTwoProperties(TestInfo info) { public void testFindAllValidByOneProperty(TestInfo info) { PortalEnvironment portalEnv = portalEnvironmentFactory.buildPersisted(getTestName(info)); StudyEnvironment studyEnv1 = studyEnvironmentFactory.buildPersisted(portalEnv, getTestName(info)); - EnrolleeFactory.EnrolleeBundle proxyBundle = enrolleeFactory.buildWithPortalUser(getTestName(info), portalEnv, studyEnv1); + EnrolleeBundle proxyBundle = enrolleeFactory.buildWithPortalUser(getTestName(info), portalEnv, studyEnv1); Enrollee proxyEnrollee = proxyBundle.enrollee(); - EnrolleeFactory.EnrolleeBundle targetBundle = enrolleeFactory.buildWithPortalUser(getTestName(info), portalEnv, studyEnv1); + EnrolleeBundle targetBundle = enrolleeFactory.buildWithPortalUser(getTestName(info), portalEnv, studyEnv1); Enrollee targetEnrollee1 = targetBundle.enrollee(); - EnrolleeFactory.EnrolleeBundle targetBundle2 = enrolleeFactory.buildWithPortalUser(getTestName(info), portalEnv, studyEnv1); + EnrolleeBundle targetBundle2 = enrolleeFactory.buildWithPortalUser(getTestName(info), portalEnv, studyEnv1); Enrollee targetEnrollee2 = targetBundle2.enrollee(); Instant yesterday = Instant.now().minusSeconds(86400); Instant tomorrow = Instant.now().plusSeconds(86400); @@ -209,7 +211,7 @@ public void testFindAllValidByOneProperty(TestInfo info) { @Test @Transactional public void findExclusiveProxiedEnrolleesTest(TestInfo info){ - EnrolleeFactory.EnrolleeAndProxy hubResponse = enrolleeFactory.buildProxyAndGovernedEnrollee(getTestName(info), "proxyEmail@test.com"); + EnrolleeAndProxy hubResponse = enrolleeFactory.buildProxyAndGovernedEnrollee(getTestName(info), "proxyEmail@test.com"); Enrollee proxyEnrollee = hubResponse.proxy(); Enrollee governedEnrollee = hubResponse.governedEnrollee(); List targetEnrollees = enrolleeRelationService.findExclusiveProxiesForTargetEnrollee(governedEnrollee.getId()); @@ -256,7 +258,7 @@ public void findExclusiveProxiedEnrolleesTest(TestInfo info){ @Test @Transactional void testFindByTargetEnrolleeIdWithEnrolleesAndFamily(TestInfo info) { - EnrolleeFactory.EnrolleeAndProxy hubResponse = enrolleeFactory.buildProxyAndGovernedEnrollee(getTestName(info), "proxyEmail@test.com"); + EnrolleeAndProxy hubResponse = enrolleeFactory.buildProxyAndGovernedEnrollee(getTestName(info), "proxyEmail@test.com"); Enrollee proxyEnrollee = hubResponse.proxy(); Enrollee governedEnrollee = hubResponse.governedEnrollee(); diff --git a/core/src/test/java/bio/terra/pearl/core/service/participant/EnrolleeServiceTests.java b/core/src/test/java/bio/terra/pearl/core/service/participant/EnrolleeServiceTests.java index dad7e91777..e40309b2ba 100644 --- a/core/src/test/java/bio/terra/pearl/core/service/participant/EnrolleeServiceTests.java +++ b/core/src/test/java/bio/terra/pearl/core/service/participant/EnrolleeServiceTests.java @@ -2,7 +2,9 @@ import bio.terra.pearl.core.BaseSpringBootTest; import bio.terra.pearl.core.factory.DaoTestUtils; +import bio.terra.pearl.core.factory.StudyEnvironmentBundle; import bio.terra.pearl.core.factory.StudyEnvironmentFactory; +import bio.terra.pearl.core.factory.participant.EnrolleeBundle; import bio.terra.pearl.core.factory.participant.EnrolleeFactory; import bio.terra.pearl.core.factory.portal.PortalEnvironmentFactory; import bio.terra.pearl.core.model.EnvironmentName; @@ -45,7 +47,7 @@ public void testEnrolleeCreate(TestInfo info) { public void testEnrolleeDelete(TestInfo info) { PortalEnvironment portalEnv = portalEnvironmentFactory.buildPersisted(getTestName(info), EnvironmentName.irb); StudyEnvironment studyEnv = studyEnvironmentFactory.buildPersisted(portalEnv, getTestName(info)); - EnrolleeFactory.EnrolleeBundle enrolleeBundle = enrolleeFactory.buildWithPortalUser(getTestName(info), portalEnv, studyEnv); + EnrolleeBundle enrolleeBundle = enrolleeFactory.buildWithPortalUser(getTestName(info), portalEnv, studyEnv); enrolleeService.delete(enrolleeBundle.enrollee().getId(), CascadeProperty.EMPTY_SET); assertThat(enrolleeService.find(enrolleeBundle.enrollee().getId()).isPresent(), equalTo(false)); @@ -56,7 +58,7 @@ public void testEnrolleeDelete(TestInfo info) { public void testEnrolleeCannotDeleteLive(TestInfo info) { PortalEnvironment portalEnv = portalEnvironmentFactory.buildPersisted(getTestName(info), EnvironmentName.live); StudyEnvironment studyEnv = studyEnvironmentFactory.buildPersisted(portalEnv, getTestName(info)); - EnrolleeFactory.EnrolleeBundle enrolleeBundle = enrolleeFactory.buildWithPortalUser(getTestName(info), portalEnv, studyEnv); + EnrolleeBundle enrolleeBundle = enrolleeFactory.buildWithPortalUser(getTestName(info), portalEnv, studyEnv); Assertions.assertThrows(UnsupportedOperationException.class, () -> { enrolleeService.delete(enrolleeBundle.enrollee().getId(), CascadeProperty.EMPTY_SET); @@ -67,15 +69,15 @@ public void testEnrolleeCannotDeleteLive(TestInfo info) { @Test @Transactional public void testFindByShortcodeAndStudyEnv(TestInfo info) { - StudyEnvironmentFactory.StudyEnvironmentBundle bundle1 = studyEnvironmentFactory.buildBundle(getTestName(info), EnvironmentName.sandbox); + StudyEnvironmentBundle bundle1 = studyEnvironmentFactory.buildBundle(getTestName(info), EnvironmentName.sandbox); StudyEnvironment studyEnv1 = bundle1.getStudyEnv(); Study study = bundle1.getStudy(); PortalEnvironment portalEnv1 = bundle1.getPortalEnv(); - StudyEnvironmentFactory.StudyEnvironmentBundle bundle2 = studyEnvironmentFactory.buildBundle(getTestName(info), EnvironmentName.sandbox); + StudyEnvironmentBundle bundle2 = studyEnvironmentFactory.buildBundle(getTestName(info), EnvironmentName.sandbox); - EnrolleeFactory.EnrolleeBundle enrolleeBundle = enrolleeFactory.buildWithPortalUser(getTestName(info), portalEnv1, studyEnv1); + EnrolleeBundle enrolleeBundle = enrolleeFactory.buildWithPortalUser(getTestName(info), portalEnv1, studyEnv1); Enrollee foundEnrollee = enrolleeService .findByShortcodeAndStudyEnv(enrolleeBundle.enrollee().getShortcode(), study.getShortcode(), EnvironmentName.sandbox) diff --git a/core/src/test/java/bio/terra/pearl/core/service/participant/ProfileServiceTests.java b/core/src/test/java/bio/terra/pearl/core/service/participant/ProfileServiceTests.java index 999670e6f6..8d54c24a37 100644 --- a/core/src/test/java/bio/terra/pearl/core/service/participant/ProfileServiceTests.java +++ b/core/src/test/java/bio/terra/pearl/core/service/participant/ProfileServiceTests.java @@ -7,6 +7,8 @@ import bio.terra.pearl.core.BaseSpringBootTest; import bio.terra.pearl.core.factory.DaoTestUtils; +import bio.terra.pearl.core.factory.participant.EnrolleeAndProxy; +import bio.terra.pearl.core.factory.participant.EnrolleeBundle; import bio.terra.pearl.core.factory.participant.EnrolleeFactory; import bio.terra.pearl.core.model.address.MailingAddress; import bio.terra.pearl.core.model.audit.DataAuditInfo; @@ -70,7 +72,7 @@ public void testProfileCreatesWithExistingMailingAddress(TestInfo info) { @Test @Transactional public void testProfileAudit(TestInfo info) { - EnrolleeFactory.EnrolleeBundle bundle = enrolleeFactory.buildWithPortalUser(getTestName(info)); + EnrolleeBundle bundle = enrolleeFactory.buildWithPortalUser(getTestName(info)); Profile profile = bundle.enrollee().getProfile(); @@ -100,7 +102,7 @@ public void testProfileAudit(TestInfo info) { @Test @Transactional public void testProfileAuditContainsMailingList(TestInfo info) { - EnrolleeFactory.EnrolleeBundle bundle = enrolleeFactory.buildWithPortalUser(getTestName(info)); + EnrolleeBundle bundle = enrolleeFactory.buildWithPortalUser(getTestName(info)); Profile profile = bundle.enrollee().getProfile(); @@ -159,7 +161,7 @@ record = (participantDataChanges.get(0).getCreatedAt().isAfter(participantDataCh @Test @Transactional public void testProfileUpdateWithMailingAddress(TestInfo info) { - EnrolleeFactory.EnrolleeBundle bundle = enrolleeFactory.buildWithPortalUser(getTestName(info)); + EnrolleeBundle bundle = enrolleeFactory.buildWithPortalUser(getTestName(info)); Profile profile = bundle.enrollee().getProfile(); @@ -186,7 +188,7 @@ public void testProfileUpdateWithMailingAddress(TestInfo info) { @Test @Transactional public void testGovernedUserProfile(TestInfo testInfo){ - EnrolleeFactory.EnrolleeAndProxy enrolleeAndProxy = enrolleeFactory.buildProxyAndGovernedEnrollee(getTestName(testInfo), getTestName(testInfo)); + EnrolleeAndProxy enrolleeAndProxy = enrolleeFactory.buildProxyAndGovernedEnrollee(getTestName(testInfo), getTestName(testInfo)); Enrollee proxyEnrollee = enrolleeAndProxy.proxy(); Profile proxyUserProfile = profileService.find(proxyEnrollee.getProfileId()).get(); List relations = enrolleeRelationService.findByEnrolleeIdAndRelationType(proxyEnrollee.getId(), RelationshipType.PROXY); diff --git a/core/src/test/java/bio/terra/pearl/core/service/participant/WithdrawnEnrolleeServiceTests.java b/core/src/test/java/bio/terra/pearl/core/service/participant/WithdrawnEnrolleeServiceTests.java index 4df298cf39..e70e7e4f78 100644 --- a/core/src/test/java/bio/terra/pearl/core/service/participant/WithdrawnEnrolleeServiceTests.java +++ b/core/src/test/java/bio/terra/pearl/core/service/participant/WithdrawnEnrolleeServiceTests.java @@ -2,7 +2,10 @@ import bio.terra.pearl.core.BaseSpringBootTest; import bio.terra.pearl.core.factory.DaoTestUtils; +import bio.terra.pearl.core.factory.StudyEnvironmentBundle; import bio.terra.pearl.core.factory.StudyEnvironmentFactory; +import bio.terra.pearl.core.factory.participant.EnrolleeAndProxy; +import bio.terra.pearl.core.factory.participant.EnrolleeBundle; import bio.terra.pearl.core.factory.participant.EnrolleeFactory; import bio.terra.pearl.core.model.EnvironmentName; import bio.terra.pearl.core.model.participant.Enrollee; @@ -57,7 +60,7 @@ public void testWithdraw(TestInfo info) { @Test @Transactional public void testWithdrawProxyEnrollee(TestInfo info) { - EnrolleeFactory.EnrolleeAndProxy enrolleeAndProxy = enrolleeFactory.buildProxyAndGovernedEnrollee(getTestName(info), "proxy-email@test.com"); + EnrolleeAndProxy enrolleeAndProxy = enrolleeFactory.buildProxyAndGovernedEnrollee(getTestName(info), "proxy-email@test.com"); Enrollee proxyEnrollee = enrolleeAndProxy.proxy(); Enrollee governedEnrollee = enrolleeAndProxy.governedEnrollee(); DaoTestUtils.assertGeneratedProperties(proxyEnrollee); @@ -78,13 +81,13 @@ public void testWithdrawSubjectThatProxies(TestInfo info) { // potential edge case: withdrawing a subject that is also a proxy should withdraw the proxy // but then recreate a non-subject enrollee so that they can keep proxying. - StudyEnvironmentFactory.StudyEnvironmentBundle studyEnvBundle = studyEnvironmentFactory.buildBundle(getTestName(info), EnvironmentName.sandbox); + StudyEnvironmentBundle studyEnvBundle = studyEnvironmentFactory.buildBundle(getTestName(info), EnvironmentName.sandbox); StudyEnvironment studyEnvironment = studyEnvBundle.getStudyEnv(); PortalEnvironment portalEnvironment = studyEnvBundle.getPortalEnv(); - EnrolleeFactory.EnrolleeBundle proxyBundle = enrolleeFactory.buildWithPortalUser(getTestName(info), portalEnvironment, studyEnvironment); - EnrolleeFactory.EnrolleeBundle governedBundle = enrolleeFactory.buildWithPortalUser(getTestName(info), portalEnvironment, studyEnvironment); + EnrolleeBundle proxyBundle = enrolleeFactory.buildWithPortalUser(getTestName(info), portalEnvironment, studyEnvironment); + EnrolleeBundle governedBundle = enrolleeFactory.buildWithPortalUser(getTestName(info), portalEnvironment, studyEnvironment); Enrollee proxyEnrollee = proxyBundle.enrollee(); Enrollee governedEnrollee = governedBundle.enrollee(); @@ -133,13 +136,13 @@ public void testWithdrawSubjectThatProxies(TestInfo info) { @Transactional public void testWithdrawGovernedUserWithProxyThatIsSubject(TestInfo info) { // potential edge case: withdrawing a governed user that is being proxied by a subject should withdraw ONLY the governed user - StudyEnvironmentFactory.StudyEnvironmentBundle studyEnvBundle = studyEnvironmentFactory.buildBundle(getTestName(info), EnvironmentName.sandbox); + StudyEnvironmentBundle studyEnvBundle = studyEnvironmentFactory.buildBundle(getTestName(info), EnvironmentName.sandbox); StudyEnvironment studyEnvironment = studyEnvBundle.getStudyEnv(); PortalEnvironment portalEnvironment = studyEnvBundle.getPortalEnv(); - EnrolleeFactory.EnrolleeBundle proxyBundle = enrolleeFactory.buildWithPortalUser(getTestName(info), portalEnvironment, studyEnvironment); - EnrolleeFactory.EnrolleeBundle governedBundle = enrolleeFactory.buildWithPortalUser(getTestName(info), portalEnvironment, studyEnvironment); + EnrolleeBundle proxyBundle = enrolleeFactory.buildWithPortalUser(getTestName(info), portalEnvironment, studyEnvironment); + EnrolleeBundle governedBundle = enrolleeFactory.buildWithPortalUser(getTestName(info), portalEnvironment, studyEnvironment); Enrollee proxyEnrollee = proxyBundle.enrollee(); Enrollee governedEnrollee = governedBundle.enrollee(); diff --git a/core/src/test/java/bio/terra/pearl/core/service/participant/merge/ParticipantMergeServiceTests.java b/core/src/test/java/bio/terra/pearl/core/service/participant/merge/ParticipantMergeServiceTests.java new file mode 100644 index 0000000000..1b2d42feba --- /dev/null +++ b/core/src/test/java/bio/terra/pearl/core/service/participant/merge/ParticipantMergeServiceTests.java @@ -0,0 +1,201 @@ +package bio.terra.pearl.core.service.participant.merge; + +import bio.terra.pearl.core.BaseSpringBootTest; +import bio.terra.pearl.core.factory.StudyEnvironmentBundle; +import bio.terra.pearl.core.factory.StudyEnvironmentFactory; +import bio.terra.pearl.core.factory.participant.EnrolleeBundle; +import bio.terra.pearl.core.factory.participant.EnrolleeFactory; +import bio.terra.pearl.core.factory.survey.SurveyFactory; +import bio.terra.pearl.core.factory.survey.SurveyResponseFactory; +import bio.terra.pearl.core.model.EnvironmentName; +import bio.terra.pearl.core.model.audit.DataAuditInfo; +import bio.terra.pearl.core.model.participant.Enrollee; +import bio.terra.pearl.core.model.participant.ParticipantUser; +import bio.terra.pearl.core.model.participant.WithdrawnEnrollee; +import bio.terra.pearl.core.model.survey.Survey; +import bio.terra.pearl.core.model.workflow.HubResponse; +import bio.terra.pearl.core.model.workflow.ParticipantTask; +import bio.terra.pearl.core.service.participant.EnrolleeService; +import bio.terra.pearl.core.service.participant.ParticipantUserService; +import bio.terra.pearl.core.service.participant.WithdrawnEnrolleeService; +import bio.terra.pearl.core.service.workflow.EnrollmentService; +import bio.terra.pearl.core.service.workflow.ParticipantTaskService; +import bio.terra.pearl.core.service.workflow.RegistrationService; +import com.google.api.client.util.Objects; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInfo; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.*; + +public class ParticipantMergeServiceTests extends BaseSpringBootTest { + @Autowired + private ParticipantMergePlanService participantMergePlanService; + @Autowired + private EnrolleeFactory enrolleeFactory; + @Autowired + private StudyEnvironmentFactory studyEnvironmentFactory; + @Autowired + private SurveyFactory surveyFactory; + @Autowired + private ParticipantMergeService participantMergeService; + @Autowired + private EnrolleeService enrolleeService; + @Autowired + private EnrollmentService enrollmentService; + @Autowired + private ParticipantUserService participantUserService; + @Autowired + private ParticipantTaskService participantTaskService; + @Autowired + private WithdrawnEnrolleeService withdrawnEnrolleeService; + @Autowired + private SurveyResponseFactory surveyResponseFactory; + @Autowired + private RegistrationService registrationService; + + /** merge two enrollees who each have a single not-started survey task */ + @Test + @Transactional + public void testSimpleMerge(TestInfo info) { + + StudyEnvironmentBundle studyEnvBundle = studyEnvironmentFactory.buildBundle(getTestName(info), EnvironmentName.sandbox); + Survey survey = surveyFactory.buildPersisted(getTestName(info), studyEnvBundle.getPortal().getId()); + surveyFactory.attachToEnv(survey, studyEnvBundle.getStudyEnv().getId(), true); + + // note we use the 'enroll' factory method so that tasks are added + EnrolleeBundle sourceBundle = enrolleeFactory.enroll("source@test.com", studyEnvBundle.getPortal().getShortcode(), + studyEnvBundle.getStudy().getShortcode(), studyEnvBundle.getStudyEnv().getEnvironmentName()); + + EnrolleeBundle targetBundle = enrolleeFactory.enroll("target@test.com", studyEnvBundle.getPortal().getShortcode(), + studyEnvBundle.getStudy().getShortcode(), studyEnvBundle.getStudyEnv().getEnvironmentName()); + + ParticipantUserMerge merge = participantMergePlanService.planMerge(sourceBundle.participantUser(), targetBundle.participantUser(), + studyEnvBundle.getPortal()); + assertThat(merge.getEnrollees(), hasSize(1)); + + participantMergeService.applyMerge(merge, DataAuditInfo.builder().systemProcess("test").build()); + + // confirm only the target enrollee is left + List allEnrollees = enrolleeService.findByStudyEnvironment(studyEnvBundle.getStudyEnv().getId()); + assertThat(allEnrollees, hasSize(1)); + assertThat(allEnrollees.get(0).getId(), equalTo(targetBundle.enrollee().getId())); + assertThat(participantTaskService.findByEnrolleeId(allEnrollees.get(0).getId()), hasSize(1)); + + // confirm only the target user is left + assertThat(participantUserService.find(sourceBundle.participantUser().getId()).isPresent(), is(false)); + assertThat(participantUserService.find(targetBundle.participantUser().getId()).isPresent(), is(true)); + + // confirm the source enrollee is withdrawn + List withdrawnUsers = withdrawnEnrolleeService.findByStudyEnvironmentIdNoData(studyEnvBundle.getStudyEnv().getId()); + assertThat(withdrawnUsers, hasSize(1)); + assertThat(withdrawnUsers.get(0).getShortcode(), equalTo(sourceBundle.enrollee().getShortcode())); + } + + /** test merge of two participants who have enrolled in a combination of studies within a portal */ + @Test + @Transactional + public void testMultiStudyMerge(TestInfo info) { + // build 3 studies in the same portal + StudyEnvironmentBundle studyEnvBundle1 = studyEnvironmentFactory.buildBundle(getTestName(info), EnvironmentName.sandbox); + StudyEnvironmentBundle studyEnvBundle2 = studyEnvironmentFactory.buildBundle(getTestName(info), EnvironmentName.sandbox, studyEnvBundle1.getPortal(), studyEnvBundle1.getPortalEnv()); + StudyEnvironmentBundle studyEnvBundle3 = studyEnvironmentFactory.buildBundle(getTestName(info), EnvironmentName.sandbox, studyEnvBundle1.getPortal(), studyEnvBundle1.getPortalEnv()); + + // a person created two accounts. They enrolled in study 1 under both, but only one in study 2 and the other one in study 3 + RegistrationService.RegistrationResult sourceUser = registrationService.register(studyEnvBundle1.getPortal().getShortcode(), studyEnvBundle1.getStudyEnv().getEnvironmentName(), + "username1", null, null); + RegistrationService.RegistrationResult targetUser = registrationService.register(studyEnvBundle1.getPortal().getShortcode(), studyEnvBundle1.getStudyEnv().getEnvironmentName(), + "username2", null, null); + + HubResponse sourceEnrollee1 = enrollmentService.enroll(studyEnvBundle1.getStudyEnv().getEnvironmentName(), studyEnvBundle1.getStudy().getShortcode(), sourceUser.participantUser(), sourceUser.portalParticipantUser(), null); + HubResponse targetEnrollee1 = enrollmentService.enroll(studyEnvBundle2.getStudyEnv().getEnvironmentName(), studyEnvBundle1.getStudy().getShortcode(), targetUser.participantUser(), targetUser.portalParticipantUser(), null); + HubResponse sourceEnrollee2 = enrollmentService.enroll(studyEnvBundle1.getStudyEnv().getEnvironmentName(), studyEnvBundle2.getStudy().getShortcode(), sourceUser.participantUser(), sourceUser.portalParticipantUser(), null); + HubResponse targetEnrollee3 = enrollmentService.enroll(studyEnvBundle3.getStudyEnv().getEnvironmentName(), studyEnvBundle3.getStudy().getShortcode(), targetUser.participantUser(), targetUser.portalParticipantUser(), null); + + ParticipantUserMerge merge = participantMergePlanService.planMerge(sourceUser.participantUser(), targetUser.participantUser(), + studyEnvBundle1.getPortal()); + // we expect three merge pairs, one for each study + assertThat(merge.getEnrollees(), hasSize(3)); + for(MergeAction enrolleeMerge : merge.getEnrollees()) { + if (enrolleeMerge.getSource() != null && enrolleeMerge.getSource().getId().equals(sourceEnrollee1.getEnrollee().getId())) { + assertThat(enrolleeMerge.getTarget().getId(), equalTo(targetEnrollee1.getEnrollee().getId())); + assertThat(enrolleeMerge.getAction(), equalTo(MergeAction.Action.MERGE)); + } else if (enrolleeMerge.getSource() != null && enrolleeMerge.getSource().getId().equals(sourceEnrollee2.getEnrollee().getId())) { + assertThat(enrolleeMerge.getTarget(), nullValue()); + assertThat(enrolleeMerge.getAction(), equalTo(MergeAction.Action.MOVE_SOURCE)); + } else if (enrolleeMerge.getTarget() != null && enrolleeMerge.getTarget().getId().equals(targetEnrollee3.getEnrollee().getId())) { + assertThat(enrolleeMerge.getSource(), nullValue()); + assertThat(enrolleeMerge.getAction(), equalTo(MergeAction.Action.NO_ACTION)); + } else { + throw new RuntimeException("unexpected enrollee merge"); + } + } + + participantMergeService.applyMerge(merge, DataAuditInfo.builder().systemProcess("test").build()); + + } + + + /** merge two enrollees who each have a survey task with a response */ + @Test + @Transactional + public void testSurveyTaskMerge(TestInfo info) { + StudyEnvironmentBundle studyEnvBundle = studyEnvironmentFactory.buildBundle(getTestName(info), EnvironmentName.sandbox); + Survey survey1 = surveyFactory.buildPersisted(getTestName(info), studyEnvBundle.getPortal().getId()); + surveyFactory.attachToEnv(survey1, studyEnvBundle.getStudyEnv().getId(), true); + Survey survey2 = surveyFactory.buildPersisted(getTestName(info), studyEnvBundle.getPortal().getId()); + surveyFactory.attachToEnv(survey2, studyEnvBundle.getStudyEnv().getId(), true); + Survey survey3 = surveyFactory.buildPersisted(getTestName(info), studyEnvBundle.getPortal().getId()); + surveyFactory.attachToEnv(survey3, studyEnvBundle.getStudyEnv().getId(), true); + + // note we use the 'enroll' factory method so that tasks are added + EnrolleeBundle sourceBundle = enrolleeFactory.enroll("source@test.com", studyEnvBundle.getPortal().getShortcode(), + studyEnvBundle.getStudy().getShortcode(), studyEnvBundle.getStudyEnv().getEnvironmentName()); + + EnrolleeBundle targetBundle = enrolleeFactory.enroll("target@test.com", studyEnvBundle.getPortal().getShortcode(), + studyEnvBundle.getStudy().getShortcode(), studyEnvBundle.getStudyEnv().getEnvironmentName()); + + List sourceTasks = participantTaskService.findByEnrolleeId(sourceBundle.enrollee().getId()); + List targetTasks = participantTaskService.findByEnrolleeId(targetBundle.enrollee().getId()); + + // survey1 has a response from both, survey2 has a response from the source, survey 3 has a response from the target + surveyResponseFactory.submitStringAnswer( + sourceTasks.stream().filter(t -> t.getTargetStableId().equals(survey1.getStableId())).findFirst().orElseThrow(), + "question1", "source1", true, sourceBundle, studyEnvBundle.getPortal()); + surveyResponseFactory.submitStringAnswer( + targetTasks.stream().filter(t -> t.getTargetStableId().equals(survey1.getStableId())).findFirst().orElseThrow(), + "question1", "target1", true, targetBundle, studyEnvBundle.getPortal()); + surveyResponseFactory.submitStringAnswer( + sourceTasks.stream().filter(t -> t.getTargetStableId().equals(survey2.getStableId())).findFirst().orElseThrow(), + "question1", "source2", true, sourceBundle, studyEnvBundle.getPortal()); + surveyResponseFactory.submitStringAnswer( + targetTasks.stream().filter(t -> t.getTargetStableId().equals(survey3.getStableId())).findFirst().orElseThrow(), + "question1", "target3", true, targetBundle, studyEnvBundle.getPortal()); + + ParticipantUserMerge merge = participantMergePlanService.planMerge(sourceBundle.participantUser(), targetBundle.participantUser(), + studyEnvBundle.getPortal()); + + assertThat(merge.getEnrollees(), hasSize(1)); + List> taskMerges = merge.getEnrollees().get(0).getMergePlan().getTasks(); + // there should be 3 task 'pairs' + assertThat(taskMerges, hasSize(3)); + for (MergeAction taskMerge : taskMerges) { + if (Objects.equal(taskMerge.getSource().getTargetStableId(), survey1.getStableId())) { + assertThat(taskMerge.getTarget().getTargetStableId(), equalTo(survey1.getStableId())); + assertThat(taskMerge.getAction(), equalTo(MergeAction.Action.MERGE)); + } else if (Objects.equal(taskMerge.getSource().getTargetStableId(), survey2.getStableId())) { + assertThat(taskMerge.getTarget().getTargetStableId(), equalTo(survey2.getStableId())); + assertThat(taskMerge.getAction(), equalTo(MergeAction.Action.MOVE_SOURCE_DELETE_TARGET)); + } else if (Objects.equal(taskMerge.getTarget().getTargetStableId(), survey3.getStableId())) { + assertThat(taskMerge.getSource().getTargetStableId(), equalTo(survey3.getStableId())); + assertThat(taskMerge.getAction(), equalTo(MergeAction.Action.DELETE_SOURCE)); + } else { + throw new RuntimeException("unexpected task merge"); + } + } + } +} diff --git a/core/src/test/java/bio/terra/pearl/core/service/publishing/StudyPublishingServiceTests.java b/core/src/test/java/bio/terra/pearl/core/service/publishing/StudyPublishingServiceTests.java index e7c9d87634..c1570d8603 100644 --- a/core/src/test/java/bio/terra/pearl/core/service/publishing/StudyPublishingServiceTests.java +++ b/core/src/test/java/bio/terra/pearl/core/service/publishing/StudyPublishingServiceTests.java @@ -2,9 +2,11 @@ import bio.terra.pearl.core.BaseSpringBootTest; import bio.terra.pearl.core.dao.study.StudyEnvironmentSurveyDao; +import bio.terra.pearl.core.factory.StudyEnvironmentBundle; import bio.terra.pearl.core.factory.StudyEnvironmentFactory; import bio.terra.pearl.core.factory.StudyFactory; import bio.terra.pearl.core.factory.notification.TriggerFactory; +import bio.terra.pearl.core.factory.participant.EnrolleeBundle; import bio.terra.pearl.core.factory.participant.EnrolleeFactory; import bio.terra.pearl.core.factory.participant.ParticipantTaskFactory; import bio.terra.pearl.core.factory.portal.PortalFactory; @@ -72,8 +74,8 @@ public void testApplyChangesPublishSurvey(TestInfo testInfo) throws Exception { String testName = getTestName(testInfo); Portal portal = portalFactory.buildPersisted(testName); Study study = studyFactory.buildPersisted(portal.getId(), testName); - StudyEnvironmentFactory.StudyEnvironmentBundle irbBundle = studyEnvironmentFactory.buildBundle(testName, EnvironmentName.irb, portal, study); - StudyEnvironmentFactory.StudyEnvironmentBundle liveBundle = studyEnvironmentFactory.buildBundle(testName, EnvironmentName.live, portal, study); + StudyEnvironmentBundle irbBundle = studyEnvironmentFactory.buildBundle(testName, EnvironmentName.irb, portal, study); + StudyEnvironmentBundle liveBundle = studyEnvironmentFactory.buildBundle(testName, EnvironmentName.live, portal, study); Survey survey = surveyFactory.buildPersisted(testName, portal.getId()); StudyEnvironment irbStudyEnv = irbBundle.getStudyEnv(); irbStudyEnv.setPreEnrollSurveyId(survey.getId()); @@ -93,8 +95,8 @@ public void testApplyChangesPublishTrigger(TestInfo testInfo) throws Exception { String testName = getTestName(testInfo); Portal portal = portalFactory.buildPersisted(testName); Study study = studyFactory.buildPersisted(portal.getId(), testName); - StudyEnvironmentFactory.StudyEnvironmentBundle irbBundle = studyEnvironmentFactory.buildBundle(testName, EnvironmentName.irb, portal, study); - StudyEnvironmentFactory.StudyEnvironmentBundle liveBundle = studyEnvironmentFactory.buildBundle(testName, EnvironmentName.live, portal, study); + StudyEnvironmentBundle irbBundle = studyEnvironmentFactory.buildBundle(testName, EnvironmentName.irb, portal, study); + StudyEnvironmentBundle liveBundle = studyEnvironmentFactory.buildBundle(testName, EnvironmentName.live, portal, study); triggerFactory.buildPersisted(Trigger.builder() .triggerType(TriggerType.EVENT) @@ -111,8 +113,8 @@ public void testApplyChangesPublishSurveyConfig(TestInfo testInfo) throws Except String testName = getTestName(testInfo); Portal portal = portalFactory.buildPersisted(testName); Study study = studyFactory.buildPersisted(portal.getId(), testName); - StudyEnvironmentFactory.StudyEnvironmentBundle irbBundle = studyEnvironmentFactory.buildBundle(testName, EnvironmentName.irb, portal, study); - StudyEnvironmentFactory.StudyEnvironmentBundle liveBundle = studyEnvironmentFactory.buildBundle(testName, EnvironmentName.live, portal, study ); + StudyEnvironmentBundle irbBundle = studyEnvironmentFactory.buildBundle(testName, EnvironmentName.irb, portal, study); + StudyEnvironmentBundle liveBundle = studyEnvironmentFactory.buildBundle(testName, EnvironmentName.live, portal, study ); Survey survey = surveyFactory.buildPersisted(testName, portal.getId()); StudyEnvironmentSurvey surveyConfig = surveyFactory.attachToEnv(survey, irbBundle.getStudyEnv().getId(), true); @@ -146,8 +148,8 @@ public void testApplyChangesPublishSurveyConfig(TestInfo testInfo) throws Except @Transactional public void testApplyChangesPublishSurveyUpdate(TestInfo testInfo) throws Exception { String testName = getTestName(testInfo); - StudyEnvironmentFactory.StudyEnvironmentBundle sandboxBundle = studyEnvironmentFactory.buildBundle(testName, EnvironmentName.sandbox); - StudyEnvironmentFactory.StudyEnvironmentBundle irbBundle = studyEnvironmentFactory.buildBundle(testName, EnvironmentName.irb, + StudyEnvironmentBundle sandboxBundle = studyEnvironmentFactory.buildBundle(testName, EnvironmentName.sandbox); + StudyEnvironmentBundle irbBundle = studyEnvironmentFactory.buildBundle(testName, EnvironmentName.irb, sandboxBundle.getPortal(), sandboxBundle.getStudy()); UUID portalId = sandboxBundle.getPortal().getId(); @@ -159,7 +161,7 @@ public void testApplyChangesPublishSurveyUpdate(TestInfo testInfo) throws Except surveyFactory.attachToEnv(surveyV2, sandboxBundle.getStudyEnv().getId(), true); // assign v1 of the survey to an enrollee in the irb environment - EnrolleeFactory.EnrolleeBundle irbEnrollee = enrolleeFactory.buildWithPortalUser(testName, irbBundle.getPortalEnv(), irbBundle.getStudyEnv()); + EnrolleeBundle irbEnrollee = enrolleeFactory.buildWithPortalUser(testName, irbBundle.getPortalEnv(), irbBundle.getStudyEnv()); participantTaskFactory.buildPersisted(irbEnrollee, ParticipantTaskFactory.DEFAULT_BUILDER .targetStableId(survey.getStableId()) .targetAssignedVersion(survey.getVersion())); @@ -181,8 +183,8 @@ public void testApplyChangesPublishSurveyUpdate(TestInfo testInfo) throws Except @Transactional public void testPublishSurveyAssignExisting(TestInfo testInfo) throws Exception { String testName = getTestName(testInfo); - StudyEnvironmentFactory.StudyEnvironmentBundle sandboxBundle = studyEnvironmentFactory.buildBundle(testName, EnvironmentName.sandbox); - StudyEnvironmentFactory.StudyEnvironmentBundle irbBundle = studyEnvironmentFactory.buildBundle(testName, EnvironmentName.irb, + StudyEnvironmentBundle sandboxBundle = studyEnvironmentFactory.buildBundle(testName, EnvironmentName.sandbox); + StudyEnvironmentBundle irbBundle = studyEnvironmentFactory.buildBundle(testName, EnvironmentName.irb, sandboxBundle.getPortal(), sandboxBundle.getStudy()); UUID portalId = sandboxBundle.getPortal().getId(); @@ -191,7 +193,7 @@ public void testPublishSurveyAssignExisting(TestInfo testInfo) throws Exception surveyFactory.builder(getTestName(testInfo)).portalId(portalId).assignToExistingEnrollees(true)); // create an enrollee in the irb environment with no survey tasks - EnrolleeFactory.EnrolleeBundle irbEnrollee = enrolleeFactory.buildWithPortalUser(testName, irbBundle.getPortalEnv(), irbBundle.getStudyEnv()); + EnrolleeBundle irbEnrollee = enrolleeFactory.buildWithPortalUser(testName, irbBundle.getPortalEnv(), irbBundle.getStudyEnv()); // attach surveys to sandbox, then copy sandbox to irb surveyFactory.attachToEnv(survey, sandboxBundle.getStudyEnv().getId(), true); diff --git a/core/src/test/java/bio/terra/pearl/core/service/search/EnrolleeSearchServiceTest.java b/core/src/test/java/bio/terra/pearl/core/service/search/EnrolleeSearchServiceTest.java index 4d020ca7ee..6aeb32b712 100644 --- a/core/src/test/java/bio/terra/pearl/core/service/search/EnrolleeSearchServiceTest.java +++ b/core/src/test/java/bio/terra/pearl/core/service/search/EnrolleeSearchServiceTest.java @@ -1,6 +1,7 @@ package bio.terra.pearl.core.service.search; import bio.terra.pearl.core.BaseSpringBootTest; +import bio.terra.pearl.core.factory.StudyEnvironmentBundle; import bio.terra.pearl.core.factory.StudyEnvironmentFactory; import bio.terra.pearl.core.factory.StudyFactory; import bio.terra.pearl.core.factory.portal.PortalFactory; @@ -48,7 +49,7 @@ class EnrolleeSearchServiceTest extends BaseSpringBootTest { void testGetSearchFacetsForPortal(TestInfo info) { Portal portal = portalFactory.buildPersisted(getTestName(info)); Study study = studyFactory.buildPersisted(portal.getId(), getTestName(info)); - StudyEnvironmentFactory.StudyEnvironmentBundle bundle1 = studyEnvironmentFactory.buildBundle(getTestName(info), EnvironmentName.sandbox, portal, study); + StudyEnvironmentBundle bundle1 = studyEnvironmentFactory.buildBundle(getTestName(info), EnvironmentName.sandbox, portal, study); StudyEnvironment se2 = studyEnvironmentFactory.buildPersisted(bundle1.getPortalEnv(), getTestName(info)); Survey survey1 = surveyFactory.buildPersisted( diff --git a/core/src/test/java/bio/terra/pearl/core/service/search/expressions/EnrolleeSearchExpressionTest.java b/core/src/test/java/bio/terra/pearl/core/service/search/expressions/EnrolleeSearchExpressionTest.java index 773a2636d3..ee11868a13 100644 --- a/core/src/test/java/bio/terra/pearl/core/service/search/expressions/EnrolleeSearchExpressionTest.java +++ b/core/src/test/java/bio/terra/pearl/core/service/search/expressions/EnrolleeSearchExpressionTest.java @@ -1,11 +1,10 @@ package bio.terra.pearl.core.service.search.expressions; import bio.terra.pearl.core.BaseSpringBootTest; +import bio.terra.pearl.core.factory.StudyEnvironmentBundle; import bio.terra.pearl.core.factory.StudyEnvironmentFactory; import bio.terra.pearl.core.factory.kit.KitRequestFactory; -import bio.terra.pearl.core.factory.participant.EnrolleeFactory; -import bio.terra.pearl.core.factory.participant.FamilyFactory; -import bio.terra.pearl.core.factory.participant.ParticipantTaskFactory; +import bio.terra.pearl.core.factory.participant.*; import bio.terra.pearl.core.factory.survey.SurveyFactory; import bio.terra.pearl.core.factory.survey.SurveyResponseFactory; import bio.terra.pearl.core.model.EnvironmentName; @@ -329,7 +328,7 @@ public void testAnswersWithParensEvaluate(TestInfo info) { @Test public void testTaskEvaluate(TestInfo info) { - StudyEnvironmentFactory.StudyEnvironmentBundle studyEnvBundle = studyEnvironmentFactory.buildBundle(getTestName(info), EnvironmentName.sandbox); + StudyEnvironmentBundle studyEnvBundle = studyEnvironmentFactory.buildBundle(getTestName(info), EnvironmentName.sandbox); EnrolleeSearchExpression assignedExp = enrolleeSearchExpressionParser.parseRule( "{task.demographic_survey.assigned} = true" ); @@ -339,21 +338,21 @@ public void testTaskEvaluate(TestInfo info) { ); // enrollee not assigned - EnrolleeFactory.EnrolleeBundle eBundleNotAssigned = enrolleeFactory.buildWithPortalUser(getTestName(info), studyEnvBundle.getPortalEnv(), studyEnvBundle.getStudyEnv()); + EnrolleeBundle eBundleNotAssigned = enrolleeFactory.buildWithPortalUser(getTestName(info), studyEnvBundle.getPortalEnv(), studyEnvBundle.getStudyEnv()); Enrollee enrolleeNotAssigned = eBundleNotAssigned.enrollee(); // enrollee assigned not started - EnrolleeFactory.EnrolleeBundle eBundleNotStarted = enrolleeFactory.buildWithPortalUser(getTestName(info), studyEnvBundle.getPortalEnv(), studyEnvBundle.getStudyEnv()); + EnrolleeBundle eBundleNotStarted = enrolleeFactory.buildWithPortalUser(getTestName(info), studyEnvBundle.getPortalEnv(), studyEnvBundle.getStudyEnv()); participantTaskFactory.buildPersisted(eBundleNotStarted, "demographic_survey", TaskStatus.NEW, TaskType.SURVEY); Enrollee enrolleeNotStarted = eBundleNotStarted.enrollee(); // enrollee assigned in progress - EnrolleeFactory.EnrolleeBundle eBundleInProgress = enrolleeFactory.buildWithPortalUser(getTestName(info), studyEnvBundle.getPortalEnv(), studyEnvBundle.getStudyEnv()); + EnrolleeBundle eBundleInProgress = enrolleeFactory.buildWithPortalUser(getTestName(info), studyEnvBundle.getPortalEnv(), studyEnvBundle.getStudyEnv()); participantTaskFactory.buildPersisted(eBundleInProgress, "demographic_survey", TaskStatus.IN_PROGRESS, TaskType.SURVEY); Enrollee enrolleeInProgress = eBundleInProgress.enrollee(); // enrollee assigned in progress but different task - EnrolleeFactory.EnrolleeBundle eBundleInProgressWrongTask = enrolleeFactory.buildWithPortalUser(getTestName(info), studyEnvBundle.getPortalEnv(), studyEnvBundle.getStudyEnv()); + EnrolleeBundle eBundleInProgressWrongTask = enrolleeFactory.buildWithPortalUser(getTestName(info), studyEnvBundle.getPortalEnv(), studyEnvBundle.getStudyEnv()); participantTaskFactory.buildPersisted(eBundleInProgressWrongTask, "something_else", TaskStatus.IN_PROGRESS, TaskType.SURVEY); Enrollee enrolleeInProgressWrongTask = eBundleInProgressWrongTask.enrollee(); @@ -517,7 +516,7 @@ public void testLowerFunction(TestInfo info) { @Test @Transactional public void testNot(TestInfo info) { - EnrolleeFactory.EnrolleeAndProxy bundle = enrolleeFactory.buildProxyAndGovernedEnrollee(getTestName(info), "proxy@test.com"); + EnrolleeAndProxy bundle = enrolleeFactory.buildProxyAndGovernedEnrollee(getTestName(info), "proxy@test.com"); EnrolleeSearchExpression notSubjectExp = enrolleeSearchExpressionParser.parseRule( "!{enrollee.subject} = true" diff --git a/core/src/test/java/bio/terra/pearl/core/service/survey/AnswerProcessingServiceTests.java b/core/src/test/java/bio/terra/pearl/core/service/survey/AnswerProcessingServiceTests.java index 145ffddc09..d8dc1e2864 100644 --- a/core/src/test/java/bio/terra/pearl/core/service/survey/AnswerProcessingServiceTests.java +++ b/core/src/test/java/bio/terra/pearl/core/service/survey/AnswerProcessingServiceTests.java @@ -2,6 +2,8 @@ import bio.terra.pearl.core.BaseSpringBootTest; import bio.terra.pearl.core.factory.StudyEnvironmentFactory; +import bio.terra.pearl.core.factory.participant.EnrolleeAndProxy; +import bio.terra.pearl.core.factory.participant.EnrolleeBundle; import bio.terra.pearl.core.factory.participant.EnrolleeFactory; import bio.terra.pearl.core.factory.portal.PortalEnvironmentFactory; import bio.terra.pearl.core.factory.survey.AnswerFactory; @@ -173,7 +175,7 @@ public void mapToDateErrorsIfSet() { public void testProfileUpdate(TestInfo info) { PortalEnvironment portalEnv = portalEnvironmentFactory.buildPersisted(getTestName(info), EnvironmentName.irb); StudyEnvironment studyEnv = studyEnvironmentFactory.buildPersisted(portalEnv, getTestName(info)); - EnrolleeFactory.EnrolleeBundle enrolleeBundle = enrolleeFactory.buildWithPortalUser(getTestName(info), portalEnv, studyEnv); + EnrolleeBundle enrolleeBundle = enrolleeFactory.buildWithPortalUser(getTestName(info), portalEnv, studyEnv); Survey survey = surveyFactory.buildPersisted(getTestName(info)); List answers = AnswerFactory.fromMap(Map.of( @@ -227,7 +229,7 @@ public void testProfileUpdate(TestInfo info) { public void testProxyProfileUpdate(TestInfo info) { PortalEnvironment portalEnv = portalEnvironmentFactory.buildPersisted(getTestName(info), EnvironmentName.irb); StudyEnvironment studyEnv = studyEnvironmentFactory.buildPersisted(portalEnv, getTestName(info)); - EnrolleeFactory.EnrolleeAndProxy enrolleeAndProxy = enrolleeFactory.buildProxyAndGovernedEnrollee(getTestName(info), portalEnv, studyEnv); + EnrolleeAndProxy enrolleeAndProxy = enrolleeFactory.buildProxyAndGovernedEnrollee(getTestName(info), portalEnv, studyEnv); ParticipantUser pUser = participantUserService.find(enrolleeAndProxy.proxyPpUser().getParticipantUserId()).orElseThrow(); Survey survey = surveyFactory.buildPersisted(getTestName(info)); diff --git a/core/src/test/java/bio/terra/pearl/core/service/survey/SurveyResponseServiceTests.java b/core/src/test/java/bio/terra/pearl/core/service/survey/SurveyResponseServiceTests.java index 53c6078b4e..0fa09c050c 100644 --- a/core/src/test/java/bio/terra/pearl/core/service/survey/SurveyResponseServiceTests.java +++ b/core/src/test/java/bio/terra/pearl/core/service/survey/SurveyResponseServiceTests.java @@ -2,6 +2,8 @@ import bio.terra.pearl.core.BaseSpringBootTest; import bio.terra.pearl.core.factory.DaoTestUtils; +import bio.terra.pearl.core.factory.StudyEnvironmentBundle; +import bio.terra.pearl.core.factory.participant.EnrolleeBundle; import bio.terra.pearl.core.factory.StudyEnvironmentFactory; import bio.terra.pearl.core.factory.participant.EnrolleeFactory; import bio.terra.pearl.core.factory.participant.PortalParticipantUserFactory; @@ -116,7 +118,7 @@ public void testSurveyResponseWithAnswers(TestInfo testInfo) { @Test @Transactional public void testSurveyResponseWithAnswersAttachesReferencesAnswers(TestInfo info) { - StudyEnvironmentFactory.StudyEnvironmentBundle studyEnvBundle = studyEnvironmentFactory.buildBundle(getTestName(info), EnvironmentName.sandbox); + StudyEnvironmentBundle studyEnvBundle = studyEnvironmentFactory.buildBundle(getTestName(info), EnvironmentName.sandbox); Survey survey1 = surveyFactory.buildPersisted(surveyFactory.builder(getTestName(info)) .portalId(studyEnvBundle.getPortal().getId()) @@ -139,7 +141,7 @@ public void testSurveyResponseWithAnswersAttachesReferencesAnswers(TestInfo info surveyResponseFactory.buildWithAnswers(enrollee, survey1, Map.of("diagnosis", "old response, should ignore")); surveyResponseFactory.buildWithAnswers(enrollee, survey1, Map.of("diagnosis", "cancer")); - + SurveyWithResponse surveyWithResponse = surveyResponseService.findWithActiveResponse(studyEnvBundle.getStudyEnv().getId(), studyEnvBundle.getPortal().getId(), survey2.getStableId(), survey2.getVersion(), enrollee, null); @@ -203,7 +205,7 @@ public void testSurveyResponseUpdateAnswers(TestInfo testInfo) { public void testUpdateResponse(TestInfo testInfo) { // create a survey and an enrollee with one task to complete that survey String testName = getTestName(testInfo); - EnrolleeFactory.EnrolleeBundle enrolleeBundle = enrolleeFactory.buildWithPortalUser(testName); + EnrolleeBundle enrolleeBundle = enrolleeFactory.buildWithPortalUser(testName); Survey survey = surveyFactory.buildPersisted(testName); StudyEnvironmentSurvey configuredSurvey = surveyFactory.attachToEnv(survey, enrolleeBundle.enrollee().getStudyEnvironmentId(), true); @@ -253,7 +255,7 @@ public void testUpdateResponse(TestInfo testInfo) { public void testCompletedSurveyResponseCannotBeUpdatedToIncomplete(TestInfo testInfo) { // create a survey and an enrollee with one survey task String testName = getTestName(testInfo); - EnrolleeFactory.EnrolleeBundle enrolleeBundle = enrolleeFactory.buildWithPortalUser(testName); + EnrolleeBundle enrolleeBundle = enrolleeFactory.buildWithPortalUser(testName); Survey survey = surveyFactory.buildPersisted(testName); StudyEnvironmentSurvey configuredSurvey = surveyFactory.attachToEnv(survey, enrolleeBundle.enrollee().getStudyEnvironmentId(), true); diff --git a/core/src/test/java/bio/terra/pearl/core/service/survey/SurveyServiceTests.java b/core/src/test/java/bio/terra/pearl/core/service/survey/SurveyServiceTests.java index 7d4990d537..cd70d0c298 100644 --- a/core/src/test/java/bio/terra/pearl/core/service/survey/SurveyServiceTests.java +++ b/core/src/test/java/bio/terra/pearl/core/service/survey/SurveyServiceTests.java @@ -3,6 +3,7 @@ import bio.terra.pearl.core.BaseSpringBootTest; import bio.terra.pearl.core.dao.i18n.LanguageTextDao; import bio.terra.pearl.core.factory.DaoTestUtils; +import bio.terra.pearl.core.factory.StudyEnvironmentBundle; import bio.terra.pearl.core.factory.StudyEnvironmentFactory; import bio.terra.pearl.core.factory.admin.AdminUserFactory; import bio.terra.pearl.core.factory.portal.PortalFactory; @@ -510,7 +511,7 @@ void testCreateSurveyWithDynamicPanel(TestInfo info) { @Test @Transactional public void testSurveyReferencesAnswers(TestInfo info) { - StudyEnvironmentFactory.StudyEnvironmentBundle studyEnvBundle = studyEnvironmentFactory.buildBundle(getTestName(info), EnvironmentName.sandbox); + StudyEnvironmentBundle studyEnvBundle = studyEnvironmentFactory.buildBundle(getTestName(info), EnvironmentName.sandbox); Survey survey = surveyFactory.buildPersisted(surveyFactory.builder(getTestName(info)) .portalId(studyEnvBundle.getPortal().getId()) @@ -525,7 +526,7 @@ public void testSurveyReferencesAnswers(TestInfo info) { @Test @Transactional public void testSurveyReferencesAnswerFiltersObjectQuestions(TestInfo info) { - StudyEnvironmentFactory.StudyEnvironmentBundle studyEnvBundle = studyEnvironmentFactory.buildBundle(getTestName(info), EnvironmentName.sandbox); + StudyEnvironmentBundle studyEnvBundle = studyEnvironmentFactory.buildBundle(getTestName(info), EnvironmentName.sandbox); Survey survey = surveyFactory.buildPersisted(surveyFactory.builder(getTestName(info)) .portalId(studyEnvBundle.getPortal().getId()) diff --git a/core/src/test/java/bio/terra/pearl/core/service/survey/SurveyTaskDispatcherTest.java b/core/src/test/java/bio/terra/pearl/core/service/survey/SurveyTaskDispatcherTest.java index e1e2e4770d..1117409c07 100644 --- a/core/src/test/java/bio/terra/pearl/core/service/survey/SurveyTaskDispatcherTest.java +++ b/core/src/test/java/bio/terra/pearl/core/service/survey/SurveyTaskDispatcherTest.java @@ -1,8 +1,11 @@ package bio.terra.pearl.core.service.survey; import bio.terra.pearl.core.BaseSpringBootTest; +import bio.terra.pearl.core.factory.StudyEnvironmentBundle; import bio.terra.pearl.core.factory.StudyEnvironmentFactory; import bio.terra.pearl.core.factory.admin.AdminUserFactory; +import bio.terra.pearl.core.factory.participant.EnrolleeAndProxy; +import bio.terra.pearl.core.factory.participant.EnrolleeBundle; import bio.terra.pearl.core.factory.participant.EnrolleeFactory; import bio.terra.pearl.core.factory.participant.ParticipantTaskFactory; import bio.terra.pearl.core.factory.survey.SurveyFactory; @@ -11,7 +14,6 @@ import bio.terra.pearl.core.model.admin.AdminUser; import bio.terra.pearl.core.model.audit.ResponsibleEntity; import bio.terra.pearl.core.model.participant.Profile; -import bio.terra.pearl.core.model.portal.Portal; import bio.terra.pearl.core.model.survey.StudyEnvironmentSurvey; import bio.terra.pearl.core.model.survey.Survey; import bio.terra.pearl.core.model.workflow.ParticipantTask; @@ -105,7 +107,7 @@ void testIsDuplicateForTaskTypes() { @Test @Transactional public void testAutoAssign(TestInfo testInfo) { - StudyEnvironmentFactory.StudyEnvironmentBundle sandboxBundle = studyEnvironmentFactory.buildBundle(getTestName(testInfo), EnvironmentName.sandbox); + StudyEnvironmentBundle sandboxBundle = studyEnvironmentFactory.buildBundle(getTestName(testInfo), EnvironmentName.sandbox); Survey survey = surveyFactory.buildPersisted(surveyFactory.builderWithDependencies(getTestName(testInfo)) .stableId("main") .content("{\"pages\":[{\"elements\":[{\"type\":\"text\",\"name\":\"diagnosis\",\"title\":\"What is your diagnosis?\"}]}]}") @@ -118,7 +120,7 @@ public void testAutoAssign(TestInfo testInfo) { .autoAssign(false)); surveyFactory.attachToEnv(followUpSurvey, sandboxBundle.getStudyEnv().getId(), true); - EnrolleeFactory.EnrolleeBundle sandbox1 = enrolleeFactory.enroll(getTestName(testInfo), sandboxBundle.getPortal().getShortcode(), sandboxBundle.getStudy().getShortcode(), sandboxBundle.getPortalEnv().getEnvironmentName()); + EnrolleeBundle sandbox1 = enrolleeFactory.enroll(getTestName(testInfo), sandboxBundle.getPortal().getShortcode(), sandboxBundle.getStudy().getShortcode(), sandboxBundle.getPortalEnv().getEnvironmentName()); // confirm only the main survey is assigned automatically List participantTasks = participantTaskService.findByEnrolleeId(sandbox1.enrollee().getId()); @@ -135,10 +137,10 @@ public void testAutoAssign(TestInfo testInfo) { @Test @Transactional public void testAssign(TestInfo testInfo) { - StudyEnvironmentFactory.StudyEnvironmentBundle sandboxBundle = studyEnvironmentFactory.buildBundle(getTestName(testInfo), EnvironmentName.sandbox); + StudyEnvironmentBundle sandboxBundle = studyEnvironmentFactory.buildBundle(getTestName(testInfo), EnvironmentName.sandbox); AdminUser operator = adminUserFactory.buildPersisted(getTestName(testInfo), true); - EnrolleeFactory.EnrolleeBundle sandbox1 = enrolleeFactory.buildWithPortalUser(getTestName(testInfo), sandboxBundle.getPortalEnv(), sandboxBundle.getStudyEnv()); - EnrolleeFactory.EnrolleeBundle sandbox2 = enrolleeFactory.buildWithPortalUser(getTestName(testInfo), sandboxBundle.getPortalEnv(), sandboxBundle.getStudyEnv()); + EnrolleeBundle sandbox1 = enrolleeFactory.buildWithPortalUser(getTestName(testInfo), sandboxBundle.getPortalEnv(), sandboxBundle.getStudyEnv()); + EnrolleeBundle sandbox2 = enrolleeFactory.buildWithPortalUser(getTestName(testInfo), sandboxBundle.getPortalEnv(), sandboxBundle.getStudyEnv()); Survey survey = surveyFactory.buildPersisted(getTestName(testInfo)); surveyFactory.attachToEnv(survey, sandboxBundle.getStudyEnv().getId(), true); ParticipantTaskAssignDto assignDto = new ParticipantTaskAssignDto(TaskType.SURVEY, survey.getStableId(), survey.getVersion(), null, true, true ); @@ -150,9 +152,9 @@ public void testAssign(TestInfo testInfo) { @Test @Transactional public void testAssignDoesntDuplicate(TestInfo testInfo) { - StudyEnvironmentFactory.StudyEnvironmentBundle sandboxBundle = studyEnvironmentFactory.buildBundle(getTestName(testInfo), EnvironmentName.sandbox); + StudyEnvironmentBundle sandboxBundle = studyEnvironmentFactory.buildBundle(getTestName(testInfo), EnvironmentName.sandbox); AdminUser operator = adminUserFactory.buildPersisted(getTestName(testInfo), true); - EnrolleeFactory.EnrolleeBundle sandbox1 = enrolleeFactory.buildWithPortalUser(getTestName(testInfo), sandboxBundle.getPortalEnv(), sandboxBundle.getStudyEnv()); + EnrolleeBundle sandbox1 = enrolleeFactory.buildWithPortalUser(getTestName(testInfo), sandboxBundle.getPortalEnv(), sandboxBundle.getStudyEnv()); Survey survey = surveyFactory.buildPersisted(getTestName(testInfo)); surveyFactory.attachToEnv(survey, sandboxBundle.getStudyEnv().getId(), true); // the enrollee already has a task @@ -181,16 +183,16 @@ public void testAssignDoesntDuplicate(TestInfo testInfo) { @Test @Transactional public void testAssignWithSearchExpression(TestInfo testInfo) { - StudyEnvironmentFactory.StudyEnvironmentBundle sandboxBundle = studyEnvironmentFactory.buildBundle(getTestName(testInfo), EnvironmentName.sandbox); + StudyEnvironmentBundle sandboxBundle = studyEnvironmentFactory.buildBundle(getTestName(testInfo), EnvironmentName.sandbox); AdminUser operator = adminUserFactory.buildPersisted(getTestName(testInfo), true); Survey survey = surveyFactory.buildPersisted(surveyFactory.builderWithDependencies(getTestName(testInfo)) .eligibilityRule("{profile.givenName} = 'John'")); surveyFactory.attachToEnv(survey, sandboxBundle.getStudyEnv().getId(), true); - EnrolleeFactory.EnrolleeBundle e1 = enrolleeFactory.buildWithPortalUser(getTestName(testInfo), sandboxBundle.getPortalEnv(), sandboxBundle.getStudyEnv(), Profile.builder().givenName("John").familyName("Doe").build()); + EnrolleeBundle e1 = enrolleeFactory.buildWithPortalUser(getTestName(testInfo), sandboxBundle.getPortalEnv(), sandboxBundle.getStudyEnv(), Profile.builder().givenName("John").familyName("Doe").build()); enrolleeFactory.buildWithPortalUser(getTestName(testInfo), sandboxBundle.getPortalEnv(), sandboxBundle.getStudyEnv()); enrolleeFactory.buildWithPortalUser(getTestName(testInfo), sandboxBundle.getPortalEnv(), sandboxBundle.getStudyEnv()); - EnrolleeFactory.EnrolleeBundle e2 = enrolleeFactory.buildWithPortalUser(getTestName(testInfo), sandboxBundle.getPortalEnv(), sandboxBundle.getStudyEnv(), Profile.builder().givenName("John").familyName("Smith").build()); + EnrolleeBundle e2 = enrolleeFactory.buildWithPortalUser(getTestName(testInfo), sandboxBundle.getPortalEnv(), sandboxBundle.getStudyEnv(), Profile.builder().givenName("John").familyName("Smith").build()); surveyTaskDispatcher.assign( new ParticipantTaskAssignDto(TaskType.SURVEY, survey.getStableId(), survey.getVersion(), null, true, false), @@ -205,13 +207,13 @@ public void testAssignWithSearchExpression(TestInfo testInfo) { @Test @Transactional public void testDoesNotAssignToProxyByDefault(TestInfo testInfo) { - StudyEnvironmentFactory.StudyEnvironmentBundle sandboxBundle = studyEnvironmentFactory.buildBundle(getTestName(testInfo), EnvironmentName.sandbox); + StudyEnvironmentBundle sandboxBundle = studyEnvironmentFactory.buildBundle(getTestName(testInfo), EnvironmentName.sandbox); AdminUser operator = adminUserFactory.buildPersisted(getTestName(testInfo), true); Survey survey = surveyFactory.buildPersisted(getTestName(testInfo)); surveyFactory.attachToEnv(survey, sandboxBundle.getStudyEnv().getId(), true); - EnrolleeFactory.EnrolleeAndProxy enrolleeAndProxy = enrolleeFactory.buildProxyAndGovernedEnrollee(getTestName(testInfo), sandboxBundle.getPortalEnv(), sandboxBundle.getStudyEnv()); - EnrolleeFactory.EnrolleeBundle normalEnrollee = enrolleeFactory.buildWithPortalUser(getTestName(testInfo), sandboxBundle.getPortalEnv(), sandboxBundle.getStudyEnv()); + EnrolleeAndProxy enrolleeAndProxy = enrolleeFactory.buildProxyAndGovernedEnrollee(getTestName(testInfo), sandboxBundle.getPortalEnv(), sandboxBundle.getStudyEnv()); + EnrolleeBundle normalEnrollee = enrolleeFactory.buildWithPortalUser(getTestName(testInfo), sandboxBundle.getPortalEnv(), sandboxBundle.getStudyEnv()); surveyTaskDispatcher.assign( new ParticipantTaskAssignDto(TaskType.SURVEY, survey.getStableId(), survey.getVersion(), null, true, false), @@ -227,7 +229,7 @@ public void testDoesNotAssignToProxyByDefault(TestInfo testInfo) { @Test @Transactional public void testAssignOnSurveyEvent(TestInfo testInfo) { - StudyEnvironmentFactory.StudyEnvironmentBundle sandboxBundle = studyEnvironmentFactory.buildBundle(getTestName(testInfo), EnvironmentName.sandbox); + StudyEnvironmentBundle sandboxBundle = studyEnvironmentFactory.buildBundle(getTestName(testInfo), EnvironmentName.sandbox); AdminUser operator = adminUserFactory.buildPersisted(getTestName(testInfo), true); Survey survey = surveyFactory.buildPersisted(surveyFactory.builderWithDependencies(getTestName(testInfo)) .content("{\"pages\":[{\"elements\":[{\"type\":\"text\",\"name\":\"diagnosis\",\"title\":\"What is your diagnosis?\"}]}]}") @@ -240,7 +242,7 @@ public void testAssignOnSurveyEvent(TestInfo testInfo) { .eligibilityRule("{answer.medForm.diagnosis} = 'sick'")); surveyFactory.attachToEnv(followUpSurvey, sandboxBundle.getStudyEnv().getId(), true); - EnrolleeFactory.EnrolleeBundle bundle = enrolleeFactory.enroll("healthy@test.com", sandboxBundle.getPortal().getShortcode(), sandboxBundle.getStudy().getShortcode(), sandboxBundle.getPortalEnv().getEnvironmentName()); + EnrolleeBundle bundle = enrolleeFactory.enroll("healthy@test.com", sandboxBundle.getPortal().getShortcode(), sandboxBundle.getStudy().getShortcode(), sandboxBundle.getPortalEnv().getEnvironmentName()); List tasks = participantTaskService.findByEnrolleeId(bundle.enrollee().getId()); // confirm the follow-up survey has not yet been assigned to the participant diff --git a/core/src/test/java/bio/terra/pearl/core/service/workflow/EnrollmentServiceTests.java b/core/src/test/java/bio/terra/pearl/core/service/workflow/EnrollmentServiceTests.java index 60c7463c02..b1bb0da14a 100644 --- a/core/src/test/java/bio/terra/pearl/core/service/workflow/EnrollmentServiceTests.java +++ b/core/src/test/java/bio/terra/pearl/core/service/workflow/EnrollmentServiceTests.java @@ -3,6 +3,7 @@ import bio.terra.pearl.core.BaseSpringBootTest; import bio.terra.pearl.core.factory.DaoTestUtils; import bio.terra.pearl.core.factory.StudyEnvironmentFactory; +import bio.terra.pearl.core.factory.participant.EnrolleeAndProxy; import bio.terra.pearl.core.factory.participant.EnrolleeFactory; import bio.terra.pearl.core.factory.participant.ParticipantUserFactory; import bio.terra.pearl.core.factory.portal.PortalEnvironmentFactory; @@ -150,7 +151,7 @@ public void testEnrollProxy(TestInfo testInfo) throws JsonProcessingException { PortalEnvironment portalEnv = portalEnvironmentFactory.buildPersisted(getTestName(testInfo)); StudyEnvironment studyEnv = studyEnvironmentFactory.buildPersisted(portalEnv, getTestName(testInfo)); - EnrolleeFactory.EnrolleeAndProxy enrolleeAndProxy = enrolleeFactory.buildProxyAndGovernedEnrollee(getTestName(testInfo), portalEnv, studyEnv); + EnrolleeAndProxy enrolleeAndProxy = enrolleeFactory.buildProxyAndGovernedEnrollee(getTestName(testInfo), portalEnv, studyEnv); Enrollee proxy = enrolleeAndProxy.proxy(); PortalParticipantUser ppUser = portalParticipantUserService.findForEnrollee(proxy); ParticipantUser user = participantUserService.find(ppUser.getParticipantUserId()).orElseThrow(); diff --git a/core/src/test/java/bio/terra/pearl/core/service/workflow/EnrollmentWorkflowTests.java b/core/src/test/java/bio/terra/pearl/core/service/workflow/EnrollmentWorkflowTests.java index e948f850b4..2c802ae27d 100644 --- a/core/src/test/java/bio/terra/pearl/core/service/workflow/EnrollmentWorkflowTests.java +++ b/core/src/test/java/bio/terra/pearl/core/service/workflow/EnrollmentWorkflowTests.java @@ -2,9 +2,9 @@ import bio.terra.pearl.core.BaseSpringBootTest; import bio.terra.pearl.core.dao.survey.AnswerMappingDao; +import bio.terra.pearl.core.factory.StudyEnvironmentBundle; import bio.terra.pearl.core.factory.StudyEnvironmentFactory; import bio.terra.pearl.core.factory.participant.ParticipantUserFactory; -import bio.terra.pearl.core.factory.portal.PortalEnvironmentFactory; import bio.terra.pearl.core.factory.survey.AnswerFactory; import bio.terra.pearl.core.factory.survey.PreEnrollmentSurveyFactory; import bio.terra.pearl.core.factory.survey.SurveyFactory; @@ -20,14 +20,11 @@ import bio.terra.pearl.core.model.study.StudyEnvironmentConfig; import bio.terra.pearl.core.model.survey.*; import bio.terra.pearl.core.model.workflow.*; -import bio.terra.pearl.core.service.consent.EnrolleeConsentEvent; import bio.terra.pearl.core.service.participant.EnrolleeRelationService; import bio.terra.pearl.core.service.participant.EnrolleeService; import bio.terra.pearl.core.service.participant.ProfileService; -import bio.terra.pearl.core.service.portal.PortalService; import bio.terra.pearl.core.service.study.StudyEnvironmentConfigService; import bio.terra.pearl.core.service.study.StudyEnvironmentService; -import bio.terra.pearl.core.service.study.StudyEnvironmentSurveyService; import bio.terra.pearl.core.service.study.StudyService; import bio.terra.pearl.core.service.survey.AnswerService; import bio.terra.pearl.core.service.survey.SurveyResponseService; @@ -87,7 +84,7 @@ public class EnrollmentWorkflowTests extends BaseSpringBootTest { @Test @Transactional public void testEnroll(TestInfo info) { - StudyEnvironmentFactory.StudyEnvironmentBundle bundle = studyEnvironmentFactory.buildBundle(getTestName(info), EnvironmentName.sandbox); + StudyEnvironmentBundle bundle = studyEnvironmentFactory.buildBundle(getTestName(info), EnvironmentName.sandbox); PortalEnvironment portalEnv = bundle.getPortalEnv(); StudyEnvironment studyEnv = bundle.getStudyEnv(); String studyShortcode = bundle.getStudy().getShortcode(); @@ -116,7 +113,7 @@ public void testEnroll(TestInfo info) { @Test @Transactional public void testParticipantWorkflow(TestInfo info) { - StudyEnvironmentFactory.StudyEnvironmentBundle bundle = studyEnvironmentFactory.buildBundle(getTestName(info), EnvironmentName.sandbox); + StudyEnvironmentBundle bundle = studyEnvironmentFactory.buildBundle(getTestName(info), EnvironmentName.sandbox); PortalEnvironment portalEnv = bundle.getPortalEnv(); StudyEnvironment studyEnv = bundle.getStudyEnv(); String studyShortcode = bundle.getStudy().getShortcode(); @@ -191,7 +188,7 @@ public void testParticipantWorkflow(TestInfo info) { @Test @Transactional public void testBackfillPreEnroll(TestInfo info) { - StudyEnvironmentFactory.StudyEnvironmentBundle studyEnvBundle = studyEnvironmentFactory.buildBundle(getTestName(info), EnvironmentName.sandbox); + StudyEnvironmentBundle studyEnvBundle = studyEnvironmentFactory.buildBundle(getTestName(info), EnvironmentName.sandbox); PortalEnvironment portalEnv = studyEnvBundle.getPortalEnv(); StudyEnvironment studyEnv = studyEnvBundle.getStudyEnv(); EnvironmentName envName = studyEnv.getEnvironmentName(); @@ -248,7 +245,7 @@ public void testBackfillPreEnroll(TestInfo info) { @Test @Transactional public void testGovernedUserEnrollment(TestInfo info){ - StudyEnvironmentFactory.StudyEnvironmentBundle studyEnvBundle = studyEnvironmentFactory.buildBundle(getTestName(info), EnvironmentName.sandbox); + StudyEnvironmentBundle studyEnvBundle = studyEnvironmentFactory.buildBundle(getTestName(info), EnvironmentName.sandbox); PortalEnvironment portalEnv = studyEnvBundle.getPortalEnv(); StudyEnvironment studyEnv = studyEnvBundle.getStudyEnv(); ParticipantUserFactory.ParticipantUserAndPortalUser userBundle = participantUserFactory.buildPersisted(portalEnv,getTestName(info)); @@ -289,7 +286,7 @@ public void testGovernedUserEnrollment(TestInfo info){ @Test @Transactional public void testProxyEnrollingMultipleChild(TestInfo info){ - StudyEnvironmentFactory.StudyEnvironmentBundle studyEnvBundle = studyEnvironmentFactory.buildBundle(getTestName(info), EnvironmentName.sandbox); + StudyEnvironmentBundle studyEnvBundle = studyEnvironmentFactory.buildBundle(getTestName(info), EnvironmentName.sandbox); PortalEnvironment portalEnv = studyEnvBundle.getPortalEnv(); StudyEnvironment studyEnv = studyEnvBundle.getStudyEnv(); ParticipantUserFactory.ParticipantUserAndPortalUser userBundle = participantUserFactory.buildPersisted(portalEnv,getTestName(info)); @@ -338,7 +335,7 @@ public void testProxyEnrollingMultipleChild(TestInfo info){ @Test @Transactional public void testDetectingProxyWhileEnrollment(TestInfo info) { - StudyEnvironmentFactory.StudyEnvironmentBundle studyEnvBundle = studyEnvironmentFactory.buildBundle(getTestName(info), EnvironmentName.sandbox); + StudyEnvironmentBundle studyEnvBundle = studyEnvironmentFactory.buildBundle(getTestName(info), EnvironmentName.sandbox); PortalEnvironment portalEnv = studyEnvBundle.getPortalEnv(); StudyEnvironment studyEnv = studyEnvBundle.getStudyEnv(); EnvironmentName envName = studyEnv.getEnvironmentName(); @@ -381,7 +378,7 @@ public void testDetectingProxyWhileEnrollment(TestInfo info) { @Test @Transactional public void testNotAcceptingProxyEnrollment(TestInfo info) { - StudyEnvironmentFactory.StudyEnvironmentBundle studyEnvBundle = studyEnvironmentFactory.buildBundle(getTestName(info), EnvironmentName.sandbox); + StudyEnvironmentBundle studyEnvBundle = studyEnvironmentFactory.buildBundle(getTestName(info), EnvironmentName.sandbox); PortalEnvironment portalEnv = studyEnvBundle.getPortalEnv(); StudyEnvironment studyEnv = studyEnvBundle.getStudyEnv(); EnvironmentName envName = studyEnv.getEnvironmentName(); @@ -413,7 +410,7 @@ public void testNotAcceptingProxyEnrollment(TestInfo info) { @Test @Transactional public void testMappingProxyAndGovernedUserProfileFromPreEnroll(TestInfo info) { - StudyEnvironmentFactory.StudyEnvironmentBundle studyEnvBundle = studyEnvironmentFactory.buildBundle(getTestName(info), EnvironmentName.sandbox); + StudyEnvironmentBundle studyEnvBundle = studyEnvironmentFactory.buildBundle(getTestName(info), EnvironmentName.sandbox); PortalEnvironment portalEnv = studyEnvBundle.getPortalEnv(); StudyEnvironment studyEnv = studyEnvBundle.getStudyEnv(); StudyEnvironmentConfig config = studyEnvironmentConfigService.find(studyEnv.getStudyEnvironmentConfigId()).get(); @@ -503,7 +500,7 @@ public void testMappingProxyAndGovernedUserProfileFromPreEnroll(TestInfo info) { @Test @Transactional public void testDetectingProxyNoPreEnroll(TestInfo info) { - StudyEnvironmentFactory.StudyEnvironmentBundle studyEnvBundle = studyEnvironmentFactory.buildBundle(getTestName(info), EnvironmentName.sandbox); + StudyEnvironmentBundle studyEnvBundle = studyEnvironmentFactory.buildBundle(getTestName(info), EnvironmentName.sandbox); StudyEnvironment studyEnv = studyEnvBundle.getStudyEnv(); EnvironmentName envName = studyEnv.getEnvironmentName(); String studyShortcode = studyEnvBundle.getStudy().getShortcode(); diff --git a/core/src/test/java/bio/terra/pearl/core/service/workflow/EventServiceTests.java b/core/src/test/java/bio/terra/pearl/core/service/workflow/EventServiceTests.java index be1d69ad6e..3cb8371f36 100644 --- a/core/src/test/java/bio/terra/pearl/core/service/workflow/EventServiceTests.java +++ b/core/src/test/java/bio/terra/pearl/core/service/workflow/EventServiceTests.java @@ -1,6 +1,7 @@ package bio.terra.pearl.core.service.workflow; import bio.terra.pearl.core.BaseSpringBootTest; +import bio.terra.pearl.core.factory.participant.EnrolleeBundle; import bio.terra.pearl.core.factory.participant.EnrolleeFactory; import bio.terra.pearl.core.factory.portal.PortalEnvironmentFactory; import bio.terra.pearl.core.model.kit.KitRequest; @@ -10,7 +11,6 @@ import bio.terra.pearl.core.model.workflow.Event; import bio.terra.pearl.core.model.workflow.EventClass; import bio.terra.pearl.core.model.workflow.ParticipantTask; -import bio.terra.pearl.core.model.workflow.TaskStatus; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestInfo; @@ -30,7 +30,7 @@ public class EventServiceTests extends BaseSpringBootTest { @Test @Transactional public void testPersistsEnrolleeConsentEvent(TestInfo info) { - EnrolleeFactory.EnrolleeBundle bundle = enrolleeFactory.buildWithPortalUser(getTestName(info)); + EnrolleeBundle bundle = enrolleeFactory.buildWithPortalUser(getTestName(info)); Assertions.assertEquals(0, eventService.findAll().size()); eventService.publishEnrolleeConsentEvent( bundle.enrollee(), @@ -47,7 +47,7 @@ public void testPersistsEnrolleeConsentEvent(TestInfo info) { @Test @Transactional public void testPersistsEnrolleeCreationEvent() { - EnrolleeFactory.EnrolleeBundle bundle = enrolleeFactory.buildWithPortalUser("testPersistsEnrolleeCreationEvent"); + EnrolleeBundle bundle = enrolleeFactory.buildWithPortalUser("testPersistsEnrolleeCreationEvent"); Assertions.assertEquals(0, eventService.findAll().size()); eventService.publishEnrolleeCreationEvent( bundle.enrollee(), @@ -64,7 +64,7 @@ public void testPersistsEnrolleeCreationEvent() { @Transactional public void testPersistsEnrolleeSurveyEvent() { - EnrolleeFactory.EnrolleeBundle bundle = enrolleeFactory.buildWithPortalUser("testPersistsEnrolleeSurveyEvent"); + EnrolleeBundle bundle = enrolleeFactory.buildWithPortalUser("testPersistsEnrolleeSurveyEvent"); Assertions.assertEquals(0, eventService.findAll().size()); eventService.publishEnrolleeSurveyEvent( bundle.enrollee(), @@ -83,7 +83,7 @@ public void testPersistsEnrolleeSurveyEvent() { @Transactional public void testPersistsKitStatusEvent() { - EnrolleeFactory.EnrolleeBundle bundle = enrolleeFactory.buildWithPortalUser("testPersistsKitStatusEvent"); + EnrolleeBundle bundle = enrolleeFactory.buildWithPortalUser("testPersistsKitStatusEvent"); Assertions.assertEquals(0, eventService.findAll().size()); eventService.publishKitStatusEvent( KitRequest.builder().build(), @@ -102,7 +102,7 @@ public void testPersistsKitStatusEvent() { @Transactional public void testPersistsPublishPortalRegistrationEvent(TestInfo info) { - EnrolleeFactory.EnrolleeBundle bundle = enrolleeFactory.buildWithPortalUser("testPersistsPublishPortalRegistrationEvent"); + EnrolleeBundle bundle = enrolleeFactory.buildWithPortalUser("testPersistsPublishPortalRegistrationEvent"); PortalEnvironment portalEnv = portalEnvironmentFactory.buildPersisted(getTestName(info)); Assertions.assertEquals(0, eventService.findAll().size()); @@ -121,7 +121,7 @@ public void testPersistsPublishPortalRegistrationEvent(TestInfo info) { Assertions.assertEquals(portalEnv.getId(), createdEvent.getPortalEnvironmentId()); } - private void assertValidCreatedEventForEnrollee(Event created, EventClass eventClass, EnrolleeFactory.EnrolleeBundle bundle) { + private void assertValidCreatedEventForEnrollee(Event created, EventClass eventClass, EnrolleeBundle bundle) { Assertions.assertNotNull(created.getCreatedAt()); Assertions.assertEquals(eventClass, created.getEventClass()); Assertions.assertEquals(bundle.enrollee().getId(), created.getEnrolleeId()); diff --git a/core/src/test/java/bio/terra/pearl/core/service/workflow/ParticipantTaskServiceTests.java b/core/src/test/java/bio/terra/pearl/core/service/workflow/ParticipantTaskServiceTests.java index 088666f487..15cdd72336 100644 --- a/core/src/test/java/bio/terra/pearl/core/service/workflow/ParticipantTaskServiceTests.java +++ b/core/src/test/java/bio/terra/pearl/core/service/workflow/ParticipantTaskServiceTests.java @@ -1,7 +1,9 @@ package bio.terra.pearl.core.service.workflow; import bio.terra.pearl.core.BaseSpringBootTest; +import bio.terra.pearl.core.factory.StudyEnvironmentBundle; import bio.terra.pearl.core.factory.StudyEnvironmentFactory; +import bio.terra.pearl.core.factory.participant.EnrolleeBundle; import bio.terra.pearl.core.factory.participant.EnrolleeFactory; import bio.terra.pearl.core.factory.participant.ParticipantTaskFactory; import bio.terra.pearl.core.model.EnvironmentName; @@ -27,12 +29,12 @@ public class ParticipantTaskServiceTests extends BaseSpringBootTest { @Test @Transactional public void testUpdateTasksForSurvey(TestInfo info) { - StudyEnvironmentFactory.StudyEnvironmentBundle bundle = + StudyEnvironmentBundle bundle = studyEnvironmentFactory.buildBundle(getTestName(info), EnvironmentName.sandbox); - EnrolleeFactory.EnrolleeBundle enrollee1 = + EnrolleeBundle enrollee1 = enrolleeFactory.buildWithPortalUser( getTestName(info), bundle.getPortalEnv(), bundle.getStudyEnv()); - EnrolleeFactory.EnrolleeBundle enrollee2 = + EnrolleeBundle enrollee2 = enrolleeFactory.buildWithPortalUser( getTestName(info), bundle.getPortalEnv(), bundle.getStudyEnv()); diff --git a/core/src/test/java/bio/terra/pearl/core/service/workflow/RegistrationServiceTests.java b/core/src/test/java/bio/terra/pearl/core/service/workflow/RegistrationServiceTests.java index 34722e1b6c..79c9ea4873 100644 --- a/core/src/test/java/bio/terra/pearl/core/service/workflow/RegistrationServiceTests.java +++ b/core/src/test/java/bio/terra/pearl/core/service/workflow/RegistrationServiceTests.java @@ -1,7 +1,9 @@ package bio.terra.pearl.core.service.workflow; import bio.terra.pearl.core.BaseSpringBootTest; +import bio.terra.pearl.core.factory.StudyEnvironmentBundle; import bio.terra.pearl.core.factory.StudyEnvironmentFactory; +import bio.terra.pearl.core.factory.participant.EnrolleeBundle; import bio.terra.pearl.core.factory.participant.EnrolleeFactory; import bio.terra.pearl.core.factory.portal.PortalEnvironmentFactory; import bio.terra.pearl.core.model.EnvironmentName; @@ -46,9 +48,9 @@ public void testRegisterWithNoPreReg(TestInfo info) { @Test @Transactional public void testRegisterForGovernedUser(TestInfo info) { - StudyEnvironmentFactory.StudyEnvironmentBundle bundle = studyEnvironmentFactory.buildBundle(getTestName(info), EnvironmentName.sandbox); + StudyEnvironmentBundle bundle = studyEnvironmentFactory.buildBundle(getTestName(info), EnvironmentName.sandbox); - EnrolleeFactory.EnrolleeBundle proxyBundle = enrolleeFactory.buildWithPortalUser(getTestName(info), bundle.getPortalEnv(), bundle.getStudyEnv()); + EnrolleeBundle proxyBundle = enrolleeFactory.buildWithPortalUser(getTestName(info), bundle.getPortalEnv(), bundle.getStudyEnv()); ParticipantUser proxyUser = participantUserService.find(proxyBundle.enrollee().getParticipantUserId()).orElseThrow(); RegistrationService.RegistrationResult registerGovernedUser = registrationService.registerGovernedUser(proxyUser, proxyBundle.portalParticipantUser(), proxyUser.getUsername()+"-prox-RFGU", null); Assertions.assertTrue(registerGovernedUser.participantUser().getUsername().contains(proxyUser.getUsername())); diff --git a/core/src/test/java/bio/terra/pearl/core/service/workflow/TriggerActionServiceTests.java b/core/src/test/java/bio/terra/pearl/core/service/workflow/TriggerActionServiceTests.java index 6ea64c6323..65c0145d8e 100644 --- a/core/src/test/java/bio/terra/pearl/core/service/workflow/TriggerActionServiceTests.java +++ b/core/src/test/java/bio/terra/pearl/core/service/workflow/TriggerActionServiceTests.java @@ -2,6 +2,7 @@ import bio.terra.pearl.core.BaseSpringBootTest; import bio.terra.pearl.core.factory.kit.KitTypeFactory; +import bio.terra.pearl.core.factory.participant.EnrolleeBundle; import bio.terra.pearl.core.factory.participant.EnrolleeFactory; import bio.terra.pearl.core.model.kit.KitRequest; import bio.terra.pearl.core.model.kit.KitRequestStatus; @@ -35,11 +36,11 @@ public class TriggerActionServiceTests extends BaseSpringBootTest { @Transactional public void testUpdateTaskStatus(TestInfo testInfo) { // simulate updating an survey task on completion of a kit request - EnrolleeFactory.EnrolleeBundle enrolleeBundle = enrolleeFactory + EnrolleeBundle enrolleeBundle = enrolleeFactory .buildWithPortalUser(getTestName(testInfo)); ParticipantTask task = createTask(enrolleeBundle, "exampleTask", TaskStatus.NEW); ParticipantTask otherTask = createTask(enrolleeBundle, "otherTask", TaskStatus.NEW); - EnrolleeFactory.EnrolleeBundle otherEnrollee = enrolleeFactory + EnrolleeBundle otherEnrollee = enrolleeFactory .buildWithPortalUser(getTestName(testInfo)); ParticipantTask otherEnrolleeTask = createTask(otherEnrollee, "exampleTask", TaskStatus.NEW); @@ -62,7 +63,7 @@ public void testUpdateTaskStatus(TestInfo testInfo) { assertThat(otherEnrolleeTask.getStatus(), equalTo(TaskStatus.NEW)); } - private ParticipantTask createTask(EnrolleeFactory.EnrolleeBundle enrolleeBundle, String taskStableId, TaskStatus status ) { + private ParticipantTask createTask(EnrolleeBundle enrolleeBundle, String taskStableId, TaskStatus status ) { Enrollee enrollee = enrolleeBundle.enrollee(); ParticipantTask task = ParticipantTask.builder() .enrolleeId(enrollee.getId()) @@ -76,7 +77,7 @@ private ParticipantTask createTask(EnrolleeFactory.EnrolleeBundle enrolleeBundle return task; } - private Trigger createStatusTrigger(EnrolleeFactory.EnrolleeBundle enrolleeBundle, TriggerEventType eventType) { + private Trigger createStatusTrigger(EnrolleeBundle enrolleeBundle, TriggerEventType eventType) { Enrollee enrollee = enrolleeBundle.enrollee(); Trigger config = Trigger.builder() .studyEnvironmentId(enrollee.getStudyEnvironmentId()) @@ -89,7 +90,7 @@ private Trigger createStatusTrigger(EnrolleeFactory.EnrolleeBundle enrolleeBundl return config; } - private KitRequest createKitRequest(EnrolleeFactory.EnrolleeBundle enrolleeBundle, String testName) { + private KitRequest createKitRequest(EnrolleeBundle enrolleeBundle, String testName) { KitRequest kitRequest = KitRequest.builder() .status(KitRequestStatus.SENT) .enrolleeId(enrolleeBundle.enrollee().getId()) diff --git a/core/src/testFixtures/java/bio/terra/pearl/core/factory/StudyEnvironmentBundle.java b/core/src/testFixtures/java/bio/terra/pearl/core/factory/StudyEnvironmentBundle.java new file mode 100644 index 0000000000..b5a89a4095 --- /dev/null +++ b/core/src/testFixtures/java/bio/terra/pearl/core/factory/StudyEnvironmentBundle.java @@ -0,0 +1,19 @@ +package bio.terra.pearl.core.factory; + +import bio.terra.pearl.core.model.portal.Portal; +import bio.terra.pearl.core.model.portal.PortalEnvironment; +import bio.terra.pearl.core.model.study.Study; +import bio.terra.pearl.core.model.study.StudyEnvironment; +import lombok.Builder; +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +@Builder +public class StudyEnvironmentBundle { + private Study study; + private StudyEnvironment studyEnv; + private Portal portal; + private PortalEnvironment portalEnv; +} diff --git a/core/src/testFixtures/java/bio/terra/pearl/core/factory/StudyEnvironmentFactory.java b/core/src/testFixtures/java/bio/terra/pearl/core/factory/StudyEnvironmentFactory.java index 603005c014..8c79ae0028 100644 --- a/core/src/testFixtures/java/bio/terra/pearl/core/factory/StudyEnvironmentFactory.java +++ b/core/src/testFixtures/java/bio/terra/pearl/core/factory/StudyEnvironmentFactory.java @@ -12,9 +12,6 @@ import bio.terra.pearl.core.service.participant.PortalParticipantUserService; import bio.terra.pearl.core.service.portal.PortalService; import bio.terra.pearl.core.service.study.StudyEnvironmentService; -import lombok.Builder; -import lombok.Getter; -import lombok.Setter; import org.apache.commons.lang3.RandomUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -98,13 +95,4 @@ public StudyEnvironmentBundle buildBundle(String testName, EnvironmentName envNa .build(); } - @Getter @Setter - @Builder - public static class StudyEnvironmentBundle { - private Study study; - private StudyEnvironment studyEnv; - private Portal portal; - private PortalEnvironment portalEnv; - } - } diff --git a/core/src/testFixtures/java/bio/terra/pearl/core/factory/notification/NotificationFactory.java b/core/src/testFixtures/java/bio/terra/pearl/core/factory/notification/NotificationFactory.java index 3f70397cae..e4b945e4c8 100644 --- a/core/src/testFixtures/java/bio/terra/pearl/core/factory/notification/NotificationFactory.java +++ b/core/src/testFixtures/java/bio/terra/pearl/core/factory/notification/NotificationFactory.java @@ -1,6 +1,6 @@ package bio.terra.pearl.core.factory.notification; -import bio.terra.pearl.core.factory.participant.EnrolleeFactory; +import bio.terra.pearl.core.factory.participant.EnrolleeBundle; import bio.terra.pearl.core.model.notification.Notification; import bio.terra.pearl.core.model.notification.Trigger; import bio.terra.pearl.core.model.notification.NotificationDeliveryStatus; @@ -13,7 +13,7 @@ public class NotificationFactory { @Autowired private NotificationService notificationService; - public Notification.NotificationBuilder builder(EnrolleeFactory.EnrolleeBundle enrolleeBundle, + public Notification.NotificationBuilder builder(EnrolleeBundle enrolleeBundle, Trigger config) { Enrollee enrollee = enrolleeBundle.enrollee(); return Notification.builder() @@ -27,7 +27,7 @@ public Notification.NotificationBuilder builder(EnrolleeFactory.EnrolleeBundle e .retries(0); } - public Notification buildPersisted(EnrolleeFactory.EnrolleeBundle enrolleeBundle, + public Notification buildPersisted(EnrolleeBundle enrolleeBundle, Trigger config) { return notificationService.create(builder(enrolleeBundle, config).build()); } diff --git a/core/src/testFixtures/java/bio/terra/pearl/core/factory/participant/EnrolleeAndProxy.java b/core/src/testFixtures/java/bio/terra/pearl/core/factory/participant/EnrolleeAndProxy.java new file mode 100644 index 0000000000..fca7839cf1 --- /dev/null +++ b/core/src/testFixtures/java/bio/terra/pearl/core/factory/participant/EnrolleeAndProxy.java @@ -0,0 +1,9 @@ +package bio.terra.pearl.core.factory.participant; + +import bio.terra.pearl.core.model.participant.Enrollee; +import bio.terra.pearl.core.model.participant.PortalParticipantUser; +import bio.terra.pearl.core.model.portal.PortalEnvironment; + +public record EnrolleeAndProxy(Enrollee governedEnrollee, Enrollee proxy, PortalParticipantUser proxyPpUser, + PortalEnvironment portalEnv) { +} diff --git a/core/src/testFixtures/java/bio/terra/pearl/core/factory/participant/EnrolleeBundle.java b/core/src/testFixtures/java/bio/terra/pearl/core/factory/participant/EnrolleeBundle.java new file mode 100644 index 0000000000..544b167e24 --- /dev/null +++ b/core/src/testFixtures/java/bio/terra/pearl/core/factory/participant/EnrolleeBundle.java @@ -0,0 +1,11 @@ +package bio.terra.pearl.core.factory.participant; + +import bio.terra.pearl.core.model.participant.Enrollee; +import bio.terra.pearl.core.model.participant.ParticipantUser; +import bio.terra.pearl.core.model.participant.PortalParticipantUser; + +import java.util.UUID; + +public record EnrolleeBundle(Enrollee enrollee, ParticipantUser participantUser, + PortalParticipantUser portalParticipantUser, UUID portalId) { +} diff --git a/core/src/testFixtures/java/bio/terra/pearl/core/factory/participant/EnrolleeFactory.java b/core/src/testFixtures/java/bio/terra/pearl/core/factory/participant/EnrolleeFactory.java index e46cbb72e0..507df4daa3 100644 --- a/core/src/testFixtures/java/bio/terra/pearl/core/factory/participant/EnrolleeFactory.java +++ b/core/src/testFixtures/java/bio/terra/pearl/core/factory/participant/EnrolleeFactory.java @@ -160,9 +160,4 @@ public EnrolleeBundle enroll(String email, String portalShortcode, String studyS HubResponse response = enrollmentService.enroll(environmentName, studyShortcode, result.participantUser(), result.portalParticipantUser(), null); return new EnrolleeBundle(response.getEnrollee(), result.participantUser(), result.portalParticipantUser(), portal.getId()); } - - - public record EnrolleeBundle(Enrollee enrollee, ParticipantUser participantUser, PortalParticipantUser portalParticipantUser, UUID portalId) {} - - public record EnrolleeAndProxy(Enrollee governedEnrollee, Enrollee proxy, PortalParticipantUser proxyPpUser, PortalEnvironment portalEnv) {} } diff --git a/core/src/testFixtures/java/bio/terra/pearl/core/factory/participant/ParticipantTaskFactory.java b/core/src/testFixtures/java/bio/terra/pearl/core/factory/participant/ParticipantTaskFactory.java index d17c252e2c..94db099a14 100644 --- a/core/src/testFixtures/java/bio/terra/pearl/core/factory/participant/ParticipantTaskFactory.java +++ b/core/src/testFixtures/java/bio/terra/pearl/core/factory/participant/ParticipantTaskFactory.java @@ -20,17 +20,17 @@ public class ParticipantTaskFactory { .targetName("test") .taskOrder(1); - public ParticipantTask buildPersisted(EnrolleeFactory.EnrolleeBundle enrolleeBundle, - TaskStatus status, TaskType type) { + public ParticipantTask buildPersisted(EnrolleeBundle enrolleeBundle, + TaskStatus status, TaskType type) { return buildPersisted(enrolleeBundle, null, status, type); } - public ParticipantTask buildPersisted(EnrolleeFactory.EnrolleeBundle enrolleeBundle, String targetStableId, + public ParticipantTask buildPersisted(EnrolleeBundle enrolleeBundle, String targetStableId, TaskStatus status, TaskType type) { return buildPersisted(enrolleeBundle, targetStableId, RandomStringUtils.randomAlphabetic(6), status, type); } - public ParticipantTask buildPersisted(EnrolleeFactory.EnrolleeBundle enrolleeBundle, String targetStableId, + public ParticipantTask buildPersisted(EnrolleeBundle enrolleeBundle, String targetStableId, String targetName, TaskStatus status, TaskType type) { DataAuditInfo auditInfo = DataAuditInfo.builder().systemProcess( DataAuditInfo.systemProcessName(getClass(), "buildPersisted") @@ -48,7 +48,7 @@ public ParticipantTask buildPersisted(EnrolleeFactory.EnrolleeBundle enrolleeBun } /** auto-sets the enrollee and environment-related fields, otherwise builds the task as provided */ - public ParticipantTask buildPersisted(EnrolleeFactory.EnrolleeBundle enrolleeBundle, ParticipantTask.ParticipantTaskBuilder builder) { + public ParticipantTask buildPersisted(EnrolleeBundle enrolleeBundle, ParticipantTask.ParticipantTaskBuilder builder) { DataAuditInfo auditInfo = DataAuditInfo.builder().systemProcess( DataAuditInfo.systemProcessName(getClass(), "buildPersisted") ).build(); diff --git a/core/src/testFixtures/java/bio/terra/pearl/core/factory/survey/SurveyResponseFactory.java b/core/src/testFixtures/java/bio/terra/pearl/core/factory/survey/SurveyResponseFactory.java index 823902bd1e..d9081e3011 100644 --- a/core/src/testFixtures/java/bio/terra/pearl/core/factory/survey/SurveyResponseFactory.java +++ b/core/src/testFixtures/java/bio/terra/pearl/core/factory/survey/SurveyResponseFactory.java @@ -1,5 +1,6 @@ package bio.terra.pearl.core.factory.survey; +import bio.terra.pearl.core.factory.participant.EnrolleeBundle; import bio.terra.pearl.core.factory.participant.EnrolleeFactory; import bio.terra.pearl.core.model.audit.ResponsibleEntity; import bio.terra.pearl.core.model.participant.Enrollee; @@ -57,7 +58,7 @@ public HubResponse submitStringAnswer(ParticipantTask task, String questionStableId, String answerValue, boolean complete, - EnrolleeFactory.EnrolleeBundle bundle, + EnrolleeBundle bundle, Portal portal) { SurveyResponse response = SurveyResponse.builder() .answers(List.of( diff --git a/populate/src/test/java/bio/terra/pearl/populate/PopulateHeartHiveTest.java b/populate/src/test/java/bio/terra/pearl/populate/PopulateHeartHiveTest.java index 4fba31d1b9..1f13b642b8 100644 --- a/populate/src/test/java/bio/terra/pearl/populate/PopulateHeartHiveTest.java +++ b/populate/src/test/java/bio/terra/pearl/populate/PopulateHeartHiveTest.java @@ -1,6 +1,6 @@ package bio.terra.pearl.populate; -import bio.terra.pearl.core.factory.participant.EnrolleeFactory; +import bio.terra.pearl.core.factory.participant.EnrolleeBundle; import bio.terra.pearl.core.model.EnvironmentName; import bio.terra.pearl.core.model.audit.DataAuditInfo; import bio.terra.pearl.core.model.participant.Enrollee; @@ -50,7 +50,7 @@ public void testPopulateHeartHive() { PortalEnvironment liveEnv = portalEnvironmentService.findOne("hearthive", EnvironmentName.live).get(); StudyEnvironment liveStudyEnv = studyEnvironmentService.findByStudy(myopathyStudy.getShortcode(), EnvironmentName.live).get(); - EnrolleeFactory.EnrolleeBundle prodEnrollee = enrolleeFactory.buildWithPortalUser("testPopulateHeartHive", liveEnv, liveStudyEnv); + EnrolleeBundle prodEnrollee = enrolleeFactory.buildWithPortalUser("testPopulateHeartHive", liveEnv, liveStudyEnv); // confirm we can't populate with overwrite if the liveEnrollee isn't withdrawn Object savepoint = status.createSavepoint(); Assertions.assertThrows(UnsupportedOperationException.class, () -> {