Search in sources :

Example 6 with EntityView

use of org.sagebionetworks.repo.model.table.EntityView in project BridgeServer2 by Sage-Bionetworks.

the class Exporter3ServiceTest method initExporter3_ErrorAddingToTrackingView.

// branch coverage
@Test
public void initExporter3_ErrorAddingToTrackingView() throws Exception {
    // App EX 3 Config doesn't have project, so we can verify the tracking view stuff.
    Exporter3Configuration ex3Config = new Exporter3Configuration();
    ex3Config.setDataAccessTeamId(DATA_ACCESS_TEAM_ID);
    ex3Config.setParticipantVersionTableId(PARTICIPANT_VERSION_TABLE_ID);
    ex3Config.setProjectId(null);
    ex3Config.setRawDataFolderId(RAW_FOLDER_ID);
    ex3Config.setStorageLocationId(STORAGE_LOCATION_ID);
    app.setExporter3Configuration(ex3Config);
    app.setExporter3Enabled(true);
    // Mock SynapseHelper.
    Project createdProject = new Project();
    createdProject.setId(PROJECT_ID);
    when(mockSynapseHelper.createEntityWithRetry(any(Project.class))).thenReturn(createdProject);
    EntityView trackingView = new EntityView();
    trackingView.setScopeIds(new ArrayList<>());
    when(mockSynapseHelper.getEntityWithRetry(SYNAPSE_TRACKING_VIEW_ID, EntityView.class)).thenReturn(trackingView);
    when(mockSynapseHelper.updateEntityWithRetry(any(EntityView.class))).thenThrow(UnknownSynapseServerException.class);
    // Execute and verify output.
    Exporter3Configuration returnedEx3Config = exporter3Service.initExporter3(TestConstants.TEST_APP_ID);
    assertEquals(returnedEx3Config.getDataAccessTeamId().longValue(), DATA_ACCESS_TEAM_ID);
    assertEquals(returnedEx3Config.getProjectId(), PROJECT_ID);
    assertEquals(returnedEx3Config.getRawDataFolderId(), RAW_FOLDER_ID);
    assertEquals(returnedEx3Config.getStorageLocationId().longValue(), STORAGE_LOCATION_ID);
    // Just verify the tracking view stuff. We call update, and then silently swallow the exception.
    verify(mockSynapseHelper).updateEntityWithRetry(any(EntityView.class));
}
Also used : Project(org.sagebionetworks.repo.model.Project) EntityView(org.sagebionetworks.repo.model.table.EntityView) Exporter3Configuration(org.sagebionetworks.bridge.models.apps.Exporter3Configuration) Test(org.testng.annotations.Test)

Example 7 with EntityView

use of org.sagebionetworks.repo.model.table.EntityView in project BridgeServer2 by Sage-Bionetworks.

the class AppServiceTest method createSynapseProjectTeam.

@Test
public void createSynapseProjectTeam() throws SynapseException {
    App app = getTestApp();
    app.setSynapseProjectId(null);
    app.setSynapseDataAccessTeamId(null);
    AccessControlList mockAcl = new AccessControlList();
    AccessControlList mockTeamAcl = new AccessControlList();
    mockAcl.setResourceAccess(new HashSet<>());
    mockTeamAcl.setResourceAccess(new HashSet<>());
    // pre-setup
    when(mockSynapseClient.createTeam(any())).thenReturn(team);
    when(mockSynapseClient.createEntity(any())).thenReturn(project);
    when(mockSynapseClient.getACL(any())).thenReturn(mockAcl);
    EntityView view = new EntityView();
    view.setScopeIds(new ArrayList<>());
    when(mockSynapseClient.getEntity(SYNAPSE_TRACKING_VIEW_ID, EntityView.class)).thenReturn(view);
    // execute
    App retApp = service.createSynapseProjectTeam(ImmutableList.of(TEST_USER_ID.toString()), ImmutableList.of(TEST_USER_SYNAPSE_ID, TEST_USER_SYNAPSE_ID_2), app);
    // verify
    // create project and team
    verify(mockSynapseClient).createTeam(any());
    verify(mockSynapseClient).createEntity(any());
    // get project acl
    verify(mockSynapseClient).getACL(eq(TEST_PROJECT_ID));
    // update project acl
    ArgumentCaptor<AccessControlList> argumentProjectAcl = ArgumentCaptor.forClass(AccessControlList.class);
    verify(mockSynapseClient).updateACL(argumentProjectAcl.capture());
    AccessControlList capturedProjectAcl = argumentProjectAcl.getValue();
    Set<ResourceAccess> capturedProjectAclSet = capturedProjectAcl.getResourceAccess();
    assertEquals(capturedProjectAclSet.size(), 5);
    Map<Long, ResourceAccess> principalIdToAcl = Maps.uniqueIndex(capturedProjectAclSet, ResourceAccess::getPrincipalId);
    assertEquals(principalIdToAcl.size(), 5);
    // 1. Exporter (admin)
    ResourceAccess capturedExporterRa = principalIdToAcl.get(Long.valueOf(EXPORTER_SYNAPSE_USER_ID));
    assertEquals(capturedExporterRa.getAccessType(), ModelConstants.ENTITY_ADMIN_ACCESS_PERMISSIONS);
    // 2. Bridge Admin
    ResourceAccess bridgeAdminAcl = principalIdToAcl.get(BRIDGE_ADMIN_TEAM_ID);
    assertEquals(bridgeAdminAcl.getAccessType(), ModelConstants.ENTITY_ADMIN_ACCESS_PERMISSIONS);
    // 3. Specified admin user
    ResourceAccess capturedUserRa = principalIdToAcl.get(TEST_USER_ID);
    assertEquals(capturedUserRa.getAccessType(), ModelConstants.ENTITY_ADMIN_ACCESS_PERMISSIONS);
    // 4. Bridge Staff
    ResourceAccess bridgeStaffAcl = principalIdToAcl.get(BRIDGE_STAFF_TEAM_ID);
    assertEquals(bridgeStaffAcl.getAccessType(), AppService.READ_DOWNLOAD_ACCESS);
    // 5. Created data access team.
    ResourceAccess capturedTeamRa = principalIdToAcl.get(Long.valueOf(TEST_TEAM_ID));
    assertEquals(capturedTeamRa.getAccessType(), AppService.READ_DOWNLOAD_ACCESS);
    // Add project to tracking view. We truncate the "syn" from the project ID.
    verify(mockSynapseClient).putEntity(view);
    assertEquals(view.getScopeIds().size(), 1);
    assertEquals(view.getScopeIds().get(0), "apseProjectId");
    // invite users to team
    verify(mockSynapseClient, times(3)).createMembershipInvitation(any(), eq(null), eq(null));
    verify(mockSynapseClient).setTeamMemberPermissions(TEST_TEAM_ID, Long.toString(TEST_USER_ID), true);
    verify(mockSynapseClient).setTeamMemberPermissions(TEST_TEAM_ID, TEST_USER_SYNAPSE_ID, false);
    verify(mockSynapseClient).setTeamMemberPermissions(TEST_TEAM_ID, TEST_USER_SYNAPSE_ID_2, false);
    // update app
    assertNotNull(retApp);
    assertEquals(retApp.getIdentifier(), app.getIdentifier());
    assertEquals(retApp.getName(), app.getName());
    assertEquals(retApp.getSynapseProjectId(), TEST_PROJECT_ID);
    assertEquals(retApp.getSynapseDataAccessTeamId().toString(), TEST_TEAM_ID);
}
Also used : DynamoApp(org.sagebionetworks.bridge.dynamodb.DynamoApp) App(org.sagebionetworks.bridge.models.apps.App) AccessControlList(org.sagebionetworks.repo.model.AccessControlList) ResourceAccess(org.sagebionetworks.repo.model.ResourceAccess) EntityView(org.sagebionetworks.repo.model.table.EntityView) Test(org.testng.annotations.Test)

Example 8 with EntityView

use of org.sagebionetworks.repo.model.table.EntityView in project BridgeServer2 by Sage-Bionetworks.

the class AppServiceTest method createAppAndUsers.

@Test
public void createAppAndUsers() throws SynapseException {
    RequestContext.set(new RequestContext.Builder().withCallerOrgMembership(TEST_ORG_ID).build());
    // mock
    App app = getTestApp();
    app.setSynapseProjectId(null);
    app.setSynapseDataAccessTeamId(null);
    app.setExternalIdRequiredOnSignup(false);
    app.setPasswordPolicy(PasswordPolicy.DEFAULT_PASSWORD_POLICY);
    StudyParticipant mockUser1 = new StudyParticipant.Builder().withEmail(TEST_USER_EMAIL).withSynapseUserId(TEST_USER_SYNAPSE_ID).withFirstName(TEST_USER_FIRST_NAME).withLastName(TEST_USER_LAST_NAME).withRoles(ImmutableSet.of(Roles.RESEARCHER, Roles.DEVELOPER)).withPassword(TEST_USER_PASSWORD).build();
    StudyParticipant mockUser2 = new StudyParticipant.Builder().withEmail(TEST_USER_EMAIL_2).withSynapseUserId(TEST_USER_SYNAPSE_ID_2).withFirstName(TEST_USER_FIRST_NAME).withLastName(TEST_USER_LAST_NAME).withRoles(ImmutableSet.of(Roles.RESEARCHER)).withPassword(TEST_USER_PASSWORD).build();
    List<StudyParticipant> mockUsers = ImmutableList.of(mockUser1, mockUser2);
    AppAndUsers mockAppAndUsers = new AppAndUsers(TEST_ADMIN_IDS, app, mockUsers);
    IdentifierHolder mockIdentifierHolder = new IdentifierHolder(TEST_IDENTIFIER);
    // stub out use of synapse client so we can validate it, not just ignore it.
    when(mockAccessControlList.getResourceAccess()).thenReturn(new HashSet<>());
    when(mockSynapseClient.createEntity(projectCaptor.capture())).thenReturn(project);
    when(mockSynapseClient.getACL(TEST_PROJECT_ID)).thenReturn(mockAccessControlList);
    when(mockSynapseClient.createTeam(teamCaptor.capture())).thenReturn(team);
    EntityView view = new EntityView();
    view.setScopeIds(new ArrayList<>());
    when(mockSynapseClient.getEntity(SYNAPSE_TRACKING_VIEW_ID, EntityView.class)).thenReturn(view);
    // stub
    when(mockParticipantService.createParticipant(any(), any(), anyBoolean())).thenReturn(mockIdentifierHolder);
    // execute
    service.createAppAndUsers(mockAppAndUsers);
    // verify
    verify(mockParticipantService).createParticipant(app, mockUser1, false);
    verify(mockParticipantService).createParticipant(app, mockUser2, false);
    verify(mockParticipantService, times(2)).requestResetPassword(app, mockIdentifierHolder.getIdentifier());
    verify(mockStudyService).createStudy(eq(TEST_APP_ID), studyCaptor.capture(), eq(false));
    Study capturedStudy = studyCaptor.getValue();
    assertEquals(capturedStudy.getAppId(), TEST_APP_ID);
    assertEquals(capturedStudy.getIdentifier(), TEST_APP_ID + "-study");
    assertEquals(capturedStudy.getName(), app.getName() + " Study");
    verify(service).createApp(app);
    verify(service).createSynapseProjectTeam(TEST_ADMIN_IDS, ImmutableList.of(TEST_USER_SYNAPSE_ID, TEST_USER_SYNAPSE_ID_2), app);
    assertEquals(projectCaptor.getValue().getName(), TEST_PROJECT_NAME);
    assertEquals(teamCaptor.getValue().getName(), TEST_TEAM_NAME);
}
Also used : DynamoApp(org.sagebionetworks.bridge.dynamodb.DynamoApp) App(org.sagebionetworks.bridge.models.apps.App) IdentifierHolder(org.sagebionetworks.bridge.models.accounts.IdentifierHolder) Study(org.sagebionetworks.bridge.models.studies.Study) EntityView(org.sagebionetworks.repo.model.table.EntityView) AppAndUsers(org.sagebionetworks.bridge.models.apps.AppAndUsers) RequestContext(org.sagebionetworks.bridge.RequestContext) StudyParticipant(org.sagebionetworks.bridge.models.accounts.StudyParticipant) Test(org.testng.annotations.Test)

Aggregations

EntityView (org.sagebionetworks.repo.model.table.EntityView)8 Test (org.testng.annotations.Test)6 App (org.sagebionetworks.bridge.models.apps.App)4 Exporter3Configuration (org.sagebionetworks.bridge.models.apps.Exporter3Configuration)3 Project (org.sagebionetworks.repo.model.Project)3 DynamoApp (org.sagebionetworks.bridge.dynamodb.DynamoApp)2 IdentifierHolder (org.sagebionetworks.bridge.models.accounts.IdentifierHolder)2 StudyParticipant (org.sagebionetworks.bridge.models.accounts.StudyParticipant)2 AppAndUsers (org.sagebionetworks.bridge.models.apps.AppAndUsers)2 SynapseException (org.sagebionetworks.client.exceptions.SynapseException)2 AccessControlList (org.sagebionetworks.repo.model.AccessControlList)2 Folder (org.sagebionetworks.repo.model.Folder)2 Team (org.sagebionetworks.repo.model.Team)2 ExternalS3StorageLocationSetting (org.sagebionetworks.repo.model.project.ExternalS3StorageLocationSetting)2 RequestContext (org.sagebionetworks.bridge.RequestContext)1 BridgeSynapseException (org.sagebionetworks.bridge.exceptions.BridgeSynapseException)1 Study (org.sagebionetworks.bridge.models.studies.Study)1 Entity (org.sagebionetworks.repo.model.Entity)1 ResourceAccess (org.sagebionetworks.repo.model.ResourceAccess)1 TableEntity (org.sagebionetworks.repo.model.table.TableEntity)1