Search in sources :

Example 1 with Exporter3Configuration

use of org.sagebionetworks.bridge.models.apps.Exporter3Configuration in project BridgeServer2 by Sage-Bionetworks.

the class TestUtils method getValidApp.

public static DynamoApp getValidApp(Class<?> clazz) {
    String id = TestUtils.randomName(clazz);
    Map<String, String> pushNotificationARNs = Maps.newHashMap();
    pushNotificationARNs.put(OperatingSystem.IOS, "arn:ios:" + id);
    pushNotificationARNs.put(OperatingSystem.ANDROID, "arn:android:" + id);
    // This app will save without further modification.
    DynamoApp app = new DynamoApp();
    app.setName("Test App [" + clazz.getSimpleName() + "]");
    app.setShortName("ShortName");
    app.setAutoVerificationEmailSuppressed(true);
    app.setPasswordPolicy(PasswordPolicy.DEFAULT_PASSWORD_POLICY);
    app.setAppIdExcludedInExport(true);
    app.setIdentifier(id);
    app.setMinAgeOfConsent(18);
    app.setSponsorName("The Council on Test Studies");
    app.setConsentNotificationEmail("bridge-testing+consent@sagebase.org");
    app.setConsentNotificationEmailVerified(true);
    app.setSynapseDataAccessTeamId(1234L);
    app.setSynapseProjectId("test-synapse-project-id");
    app.setTechnicalEmail("bridge-testing+technical@sagebase.org");
    app.setUploadValidationStrictness(UploadValidationStrictness.REPORT);
    app.setUsesCustomExportSchedule(true);
    app.setSupportEmail("bridge-testing+support@sagebase.org");
    app.setUserProfileAttributes(Sets.newHashSet("a", "b"));
    app.setTaskIdentifiers(Sets.newHashSet("task1", "task2"));
    app.setActivityEventKeys(Sets.newHashSet("event1", "event2"));
    app.setDataGroups(Sets.newHashSet("beta_users", "production_users"));
    app.setStrictUploadValidationEnabled(true);
    app.setHealthCodeExportEnabled(true);
    app.setEmailVerificationEnabled(true);
    app.setReauthenticationEnabled(true);
    app.setEmailSignInEnabled(true);
    app.setPhoneSignInEnabled(true);
    app.setVerifyChannelOnSignInEnabled(true);
    app.setExternalIdRequiredOnSignup(true);
    app.setActive(true);
    app.setDisableExport(false);
    app.setAccountLimit(0);
    app.setPushNotificationARNs(pushNotificationARNs);
    app.setAutoVerificationPhoneSuppressed(true);
    Map<String, String> defaultTemplates = new HashMap<>();
    for (TemplateType type : TemplateType.values()) {
        String typeName = type.name().toLowerCase();
        defaultTemplates.put(typeName, "ABC-DEF");
    }
    app.setDefaultTemplates(defaultTemplates);
    Exporter3Configuration exporter3Config = new Exporter3Configuration();
    exporter3Config.setDataAccessTeamId(1234L);
    exporter3Config.setParticipantVersionTableId("participant-version-synapse-table-id");
    exporter3Config.setProjectId("synapse-project-id");
    exporter3Config.setRawDataFolderId("synapse-folder-id");
    exporter3Config.setStorageLocationId(5678L);
    app.setExporter3Configuration(exporter3Config);
    return app;
}
Also used : DynamoApp(org.sagebionetworks.bridge.dynamodb.DynamoApp) HashMap(java.util.HashMap) TemplateType(org.sagebionetworks.bridge.models.templates.TemplateType) Exporter3Configuration(org.sagebionetworks.bridge.models.apps.Exporter3Configuration)

Example 2 with Exporter3Configuration

use of org.sagebionetworks.bridge.models.apps.Exporter3Configuration in project BridgeServer2 by Sage-Bionetworks.

the class DynamoAppTest method appFullySerializesForCaching.

@Test
public void appFullySerializesForCaching() throws Exception {
    final DynamoApp app = TestUtils.getValidApp(DynamoAppTest.class);
    OAuthProvider oauthProvider = new OAuthProvider("clientId", "secret", "endpoint", OAuthProviderTest.CALLBACK_URL, null);
    app.getOAuthProviders().put("myProvider", oauthProvider);
    app.setAutomaticCustomEvents(ImmutableMap.of("3-days-after-enrollment", "P3D"));
    app.setVersion(2L);
    app.setMinSupportedAppVersions(ImmutableMap.<String, Integer>builder().put(OperatingSystem.IOS, 2).build());
    app.setUploadMetadataFieldDefinitions(ImmutableList.of(new UploadFieldDefinition.Builder().withName("test-metadata-field").withType(UploadFieldType.INT).build()));
    app.setAndroidAppLinks(ANDROID_APP_LINKS);
    app.setAppleAppLinks(APPLE_APP_LINKS);
    final JsonNode node = BridgeObjectMapper.get().valueToTree(app);
    assertTrue(node.get("autoVerificationEmailSuppressed").booleanValue());
    assertEqualsAndNotNull(app.getConsentNotificationEmail(), node.get("consentNotificationEmail").asText());
    assertEqualsAndNotNull(app.getExporter3Configuration(), JsonUtils.asEntity(node, "exporter3Configuration", Exporter3Configuration.class));
    assertFalse(node.get("participantIpLockingEnabled").booleanValue());
    assertTrue(node.get("appIdExcludedInExport").booleanValue());
    assertEqualsAndNotNull(app.getSupportEmail(), node.get("supportEmail").asText());
    assertEqualsAndNotNull(app.getSynapseDataAccessTeamId(), node.get("synapseDataAccessTeamId").longValue());
    assertEqualsAndNotNull(app.getSynapseProjectId(), node.get("synapseProjectId").textValue());
    assertEqualsAndNotNull(app.getTechnicalEmail(), node.get("technicalEmail").asText());
    assertEqualsAndNotNull(app.getUploadValidationStrictness().toString().toLowerCase(), node.get("uploadValidationStrictness").textValue());
    assertTrue(node.get("usesCustomExportSchedule").asBoolean());
    assertEqualsAndNotNull(app.getSponsorName(), node.get("sponsorName").asText());
    assertEqualsAndNotNull(app.getName(), node.get("name").asText());
    assertEqualsAndNotNull(app.getShortName(), node.get("shortName").textValue());
    assertEqualsAndNotNull(app.isActive(), node.get("active").asBoolean());
    assertEqualsAndNotNull(app.getIdentifier(), node.get("identifier").asText());
    assertEqualsAndNotNull(app.getMinAgeOfConsent(), node.get("minAgeOfConsent").asInt());
    assertEqualsAndNotNull(app.getPasswordPolicy(), JsonUtils.asEntity(node, "passwordPolicy", PasswordPolicy.class));
    assertEqualsAndNotNull(app.getUserProfileAttributes(), JsonUtils.asStringSet(node, "userProfileAttributes"));
    assertEqualsAndNotNull(app.getTaskIdentifiers(), JsonUtils.asStringSet(node, "taskIdentifiers"));
    assertEqualsAndNotNull(app.getActivityEventKeys(), JsonUtils.asStringSet(node, "activityEventKeys"));
    assertEqualsAndNotNull(app.getDataGroups(), JsonUtils.asStringSet(node, "dataGroups"));
    assertEqualsAndNotNull(app.getVersion(), node.get("version").longValue());
    assertTrue(node.get("strictUploadValidationEnabled").asBoolean());
    assertTrue(node.get("healthCodeExportEnabled").asBoolean());
    assertTrue(node.get("emailVerificationEnabled").asBoolean());
    assertTrue(node.get("externalIdRequiredOnSignup").asBoolean());
    assertTrue(node.get("emailSignInEnabled").asBoolean());
    assertTrue(node.get("reauthenticationEnabled").booleanValue());
    assertTrue(node.get("autoVerificationPhoneSuppressed").booleanValue());
    assertTrue(node.get("verifyChannelOnSignInEnabled").booleanValue());
    assertEquals(node.get("accountLimit").asInt(), 0);
    assertFalse(node.get("disableExport").asBoolean());
    assertEqualsAndNotNull("App", node.get("type").asText());
    assertEqualsAndNotNull(app.getPushNotificationARNs().get(OperatingSystem.IOS), node.get("pushNotificationARNs").get(OperatingSystem.IOS).asText());
    assertEqualsAndNotNull(app.getPushNotificationARNs().get(OperatingSystem.ANDROID), node.get("pushNotificationARNs").get(OperatingSystem.ANDROID).asText());
    JsonNode automaticCustomEventsNode = node.get("automaticCustomEvents");
    assertEquals(automaticCustomEventsNode.size(), 1);
    assertEquals(automaticCustomEventsNode.get("3-days-after-enrollment").textValue(), "P3D");
    JsonNode appleLink = node.get("appleAppLinks").get(0);
    assertEquals(appleLink.get("appID").textValue(), "appId");
    assertEquals(appleLink.get("paths").get(0).textValue(), "/appId/");
    assertEquals(appleLink.get("paths").get(1).textValue(), "/appId/*");
    JsonNode androidLink = node.get("androidAppLinks").get(0);
    assertEquals(androidLink.get("namespace").textValue(), "namespace");
    assertEquals(androidLink.get("package_name").textValue(), "package_name");
    assertEquals(androidLink.get("sha256_cert_fingerprints").get(0).textValue(), "sha256_cert_fingerprints");
    // validate minAppVersion
    JsonNode supportedVersionsNode = JsonUtils.asJsonNode(node, "minSupportedAppVersions");
    assertNotNull(supportedVersionsNode);
    assertEqualsAndNotNull(app.getMinSupportedAppVersions().get(OperatingSystem.IOS), supportedVersionsNode.get(OperatingSystem.IOS).intValue());
    // validate metadata field defs
    JsonNode metadataFieldDefListNode = node.get("uploadMetadataFieldDefinitions");
    assertEquals(metadataFieldDefListNode.size(), 1);
    JsonNode oneMetadataFieldDefNode = metadataFieldDefListNode.get(0);
    assertEquals(oneMetadataFieldDefNode.get("name").textValue(), "test-metadata-field");
    assertEquals(oneMetadataFieldDefNode.get("type").textValue(), "int");
    JsonNode providerNode = node.get("oAuthProviders").get("myProvider");
    assertEquals(providerNode.get("clientId").textValue(), "clientId");
    assertEquals(providerNode.get("secret").textValue(), "secret");
    assertEquals(providerNode.get("endpoint").textValue(), "endpoint");
    assertEquals(providerNode.get("callbackUrl").textValue(), OAuthProviderTest.CALLBACK_URL);
    assertEquals(providerNode.get("type").textValue(), "OAuthProvider");
    JsonNode defaultTemplates = node.get("defaultTemplates");
    assertEquals(defaultTemplates.get("email_account_exists").textValue(), "ABC-DEF");
    // Deserialize back to a POJO and verify.
    final App deserApp = BridgeObjectMapper.get().readValue(node.toString(), App.class);
    assertEquals(deserApp, app);
}
Also used : UploadFieldDefinition(org.sagebionetworks.bridge.models.upload.UploadFieldDefinition) App(org.sagebionetworks.bridge.models.apps.App) PasswordPolicy(org.sagebionetworks.bridge.models.apps.PasswordPolicy) OAuthProvider(org.sagebionetworks.bridge.models.apps.OAuthProvider) JsonNode(com.fasterxml.jackson.databind.JsonNode) Exporter3Configuration(org.sagebionetworks.bridge.models.apps.Exporter3Configuration) Test(org.testng.annotations.Test) OAuthProviderTest(org.sagebionetworks.bridge.models.apps.OAuthProviderTest)

Example 3 with Exporter3Configuration

use of org.sagebionetworks.bridge.models.apps.Exporter3Configuration in project BridgeServer2 by Sage-Bionetworks.

the class Exporter3ServiceTest method initExporter3.

@Test
public void initExporter3() throws Exception {
    // App has no exporter3config.
    app.setExporter3Configuration(null);
    app.setExporter3Enabled(false);
    // Mock SynapseHelper.
    Team createdTeam = new Team();
    createdTeam.setId(String.valueOf(DATA_ACCESS_TEAM_ID));
    when(mockSynapseHelper.createTeamWithRetry(any())).thenReturn(createdTeam);
    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);
    TableEntity createdTable = new TableEntity();
    createdTable.setId(PARTICIPANT_VERSION_TABLE_ID);
    when(mockSynapseHelper.createTableWithColumnsAndAcls(anyList(), anySet(), anySet(), anyString(), anyString())).thenReturn(PARTICIPANT_VERSION_TABLE_ID);
    Folder createdFolder = new Folder();
    createdFolder.setId(RAW_FOLDER_ID);
    when(mockSynapseHelper.createEntityWithRetry(any(Folder.class))).thenReturn(createdFolder);
    ExternalS3StorageLocationSetting createdStorageLocation = new ExternalS3StorageLocationSetting();
    createdStorageLocation.setStorageLocationId(STORAGE_LOCATION_ID);
    when(mockSynapseHelper.createStorageLocationForEntity(eq(RAW_FOLDER_ID), any(ExternalS3StorageLocationSetting.class))).thenReturn(createdStorageLocation);
    // Execute and verify output.
    Exporter3Configuration returnedEx3Config = exporter3Service.initExporter3(TestConstants.TEST_APP_ID);
    assertEquals(returnedEx3Config.getDataAccessTeamId().longValue(), DATA_ACCESS_TEAM_ID);
    assertEquals(returnedEx3Config.getParticipantVersionTableId(), PARTICIPANT_VERSION_TABLE_ID);
    assertEquals(returnedEx3Config.getProjectId(), PROJECT_ID);
    assertEquals(returnedEx3Config.getRawDataFolderId(), RAW_FOLDER_ID);
    assertEquals(returnedEx3Config.getStorageLocationId().longValue(), STORAGE_LOCATION_ID);
    // Verify created team.
    ArgumentCaptor<Team> teamToCreateCaptor = ArgumentCaptor.forClass(Team.class);
    verify(mockSynapseHelper).createTeamWithRetry(teamToCreateCaptor.capture());
    Team teamToCreate = teamToCreateCaptor.getValue();
    assertEquals(teamToCreate.getName(), EXPECTED_TEAM_NAME);
    // Verify created project. Note that we call this method again later, which is why we verify it twice now.
    ArgumentCaptor<Entity> entitiesToCreateCaptor = ArgumentCaptor.forClass(Project.class);
    verify(mockSynapseHelper, times(2)).createEntityWithRetry(entitiesToCreateCaptor.capture());
    List<Entity> entitiesToCreateList = entitiesToCreateCaptor.getAllValues();
    Project projectToCreate = (Project) entitiesToCreateList.get(0);
    assertEquals(projectToCreate.getName(), EXPECTED_PROJECT_NAME);
    // Verify project ACLs.
    verify(mockSynapseHelper).createAclWithRetry(PROJECT_ID, ADMIN_PRINCIPAL_ID_SET, READ_ONLY_PRINCIPAL_ID_SET);
    // Verify project added to tracking view. For whatever reason, view scope IDs don't include the "syn" prefix.
    ArgumentCaptor<EntityView> viewToUpdateCaptor = ArgumentCaptor.forClass(EntityView.class);
    verify(mockSynapseHelper).updateEntityWithRetry(viewToUpdateCaptor.capture());
    EntityView viewToUpdate = viewToUpdateCaptor.getValue();
    assertTrue(viewToUpdate.getScopeIds().contains(PROJECT_ID_WITHOUT_PREFIX));
    // Verify created participant version table.
    verify(mockSynapseHelper).createTableWithColumnsAndAcls(Exporter3Service.PARTICIPANT_VERSION_COLUMN_MODELS, READ_ONLY_PRINCIPAL_ID_SET, ADMIN_PRINCIPAL_ID_SET, PROJECT_ID, Exporter3Service.TABLE_NAME_PARTICIPANT_VERSIONS);
    // Verify created folder.
    Folder folderToCreate = (Folder) entitiesToCreateList.get(1);
    assertEquals(folderToCreate.getName(), Exporter3Service.FOLDER_NAME_BRIDGE_RAW_DATA);
    assertEquals(folderToCreate.getParentId(), PROJECT_ID);
    // Verify folder ACLs.
    verify(mockSynapseHelper).createAclWithRetry(RAW_FOLDER_ID, ADMIN_PRINCIPAL_ID_SET, READ_ONLY_PRINCIPAL_ID_SET);
    // Verify we write to S3 for the storage location.
    verify(mockS3Helper).writeLinesToS3(RAW_HEALTH_DATA_BUCKET, TestConstants.TEST_APP_ID + "/owner.txt", ImmutableList.of(EXPORTER_SYNAPSE_USER));
    // Verify created storage location.
    ArgumentCaptor<ExternalS3StorageLocationSetting> storageLocationToCreateCaptor = ArgumentCaptor.forClass(ExternalS3StorageLocationSetting.class);
    verify(mockSynapseHelper).createStorageLocationForEntity(eq(RAW_FOLDER_ID), storageLocationToCreateCaptor.capture());
    ExternalS3StorageLocationSetting storageLocationToCreate = storageLocationToCreateCaptor.getValue();
    assertEquals(storageLocationToCreate.getBaseKey(), TestConstants.TEST_APP_ID);
    assertEquals(storageLocationToCreate.getBucket(), RAW_HEALTH_DATA_BUCKET);
    assertTrue(storageLocationToCreate.getStsEnabled());
    // Verify updated app.
    ArgumentCaptor<App> appToUpdateCaptor = ArgumentCaptor.forClass(App.class);
    verify(mockAppService).updateApp(appToUpdateCaptor.capture(), eq((true)));
    App appToUpdate = appToUpdateCaptor.getValue();
    assertTrue(appToUpdate.isExporter3Enabled());
    Exporter3Configuration ex3ConfigToCreate = appToUpdate.getExporter3Configuration();
    assertEquals(ex3ConfigToCreate, returnedEx3Config);
}
Also used : App(org.sagebionetworks.bridge.models.apps.App) Entity(org.sagebionetworks.repo.model.Entity) TableEntity(org.sagebionetworks.repo.model.table.TableEntity) EntityView(org.sagebionetworks.repo.model.table.EntityView) Folder(org.sagebionetworks.repo.model.Folder) Project(org.sagebionetworks.repo.model.Project) ExternalS3StorageLocationSetting(org.sagebionetworks.repo.model.project.ExternalS3StorageLocationSetting) TableEntity(org.sagebionetworks.repo.model.table.TableEntity) Team(org.sagebionetworks.repo.model.Team) Exporter3Configuration(org.sagebionetworks.bridge.models.apps.Exporter3Configuration) Test(org.testng.annotations.Test)

Example 4 with Exporter3Configuration

use of org.sagebionetworks.bridge.models.apps.Exporter3Configuration in project BridgeServer2 by Sage-Bionetworks.

the class Exporter3Service method initExporter3.

/**
 * Initializes configs and Synapse resources for Exporter 3.0. Note that if any config already exists, this API
 * will simply ignore them. This allows for two notable scenarios
 * (a) Advanced users can use existing projects or data access teams for Exporter 3.0.
 * (b) If in the future, we add something new (like a notification queue, or a default view), we can re-run this
 * API to create the new stuff without affecting the old stuff.
 */
public Exporter3Configuration initExporter3(String appId) throws BridgeSynapseException, IOException, SynapseException {
    boolean isAppModified = false;
    App app = appService.getApp(appId);
    // Init the Exporter3Config object.
    Exporter3Configuration ex3Config = app.getExporter3Configuration();
    if (ex3Config == null) {
        ex3Config = new Exporter3Configuration();
        app.setExporter3Configuration(ex3Config);
        isAppModified = true;
    }
    // Name in Synapse are globally unique, so we add a random token to the name to ensure it
    // doesn't conflict with an existing name. Also, Synapse names can only contain a certain
    // subset of characters. We've verified this name is acceptable for this transformation.
    String synapseName = BridgeUtils.toSynapseFriendlyName(app.getName());
    String nameScopingToken = getNameScopingToken();
    // Create data access team.
    Long dataAccessTeamId = ex3Config.getDataAccessTeamId();
    if (dataAccessTeamId == null) {
        Team team = new Team();
        team.setName(synapseName + " Access Team " + nameScopingToken);
        team = synapseHelper.createTeamWithRetry(team);
        dataAccessTeamId = Long.parseLong(team.getId());
        LOG.info("Created Synapse team " + dataAccessTeamId);
        ex3Config.setDataAccessTeamId(dataAccessTeamId);
        isAppModified = true;
    }
    Set<Long> adminPrincipalIds = ImmutableSet.of(exporterSynapseId, bridgeAdminTeamId);
    Set<Long> readOnlyPrincipalIds = ImmutableSet.of(bridgeStaffTeamId, dataAccessTeamId);
    // Create project.
    String projectId = ex3Config.getProjectId();
    if (projectId == null) {
        Project project = new Project();
        project.setName(synapseName + " Project " + nameScopingToken);
        project = synapseHelper.createEntityWithRetry(project);
        projectId = project.getId();
        LOG.info("Created Synapse project " + projectId);
        // Create ACLs for project.
        synapseHelper.createAclWithRetry(projectId, adminPrincipalIds, readOnlyPrincipalIds);
        ex3Config.setProjectId(projectId);
        isAppModified = true;
        // We also need to add this project to the tracking view.
        if (StringUtils.isNotBlank(synapseTrackingViewId)) {
            try {
                EntityView view = synapseHelper.getEntityWithRetry(synapseTrackingViewId, EntityView.class);
                if (view != null) {
                    // For whatever reason, view.getScopes() doesn't include the "syn" prefix.
                    view.getScopeIds().add(projectId.substring(3));
                    synapseHelper.updateEntityWithRetry(view);
                }
            } catch (SynapseException ex) {
                LOG.error("Error adding new project " + projectId + " to tracking view " + synapseTrackingViewId + ": " + ex.getMessage(), ex);
            }
        }
    }
    // Create Participant Version Table.
    String participantVersionTableId = ex3Config.getParticipantVersionTableId();
    if (participantVersionTableId == null) {
        participantVersionTableId = synapseHelper.createTableWithColumnsAndAcls(PARTICIPANT_VERSION_COLUMN_MODELS, readOnlyPrincipalIds, adminPrincipalIds, projectId, TABLE_NAME_PARTICIPANT_VERSIONS);
        LOG.info("Created Synapse table " + participantVersionTableId);
        ex3Config.setParticipantVersionTableId(participantVersionTableId);
        isAppModified = true;
    }
    // Create Folder for raw data.
    String rawDataFolderId = ex3Config.getRawDataFolderId();
    if (rawDataFolderId == null) {
        Folder folder = new Folder();
        folder.setName(FOLDER_NAME_BRIDGE_RAW_DATA);
        folder.setParentId(projectId);
        folder = synapseHelper.createEntityWithRetry(folder);
        rawDataFolderId = folder.getId();
        LOG.info("Created Synapse folder " + rawDataFolderId);
        // Create ACLs for folder. This is a separate ACL because we don't want to allow people to modify the
        // raw data.
        synapseHelper.createAclWithRetry(rawDataFolderId, adminPrincipalIds, readOnlyPrincipalIds);
        ex3Config.setRawDataFolderId(rawDataFolderId);
        isAppModified = true;
    }
    // Create storage location.
    Long storageLocationId = ex3Config.getStorageLocationId();
    if (storageLocationId == null) {
        // Create owner.txt so that we can create the storage location.
        s3Helper.writeLinesToS3(rawHealthDataBucket, appId + "/owner.txt", ImmutableList.of(exporterSynapseUser));
        // Create storage location.
        ExternalS3StorageLocationSetting storageLocation = new ExternalS3StorageLocationSetting();
        storageLocation.setBaseKey(appId);
        storageLocation.setBucket(rawHealthDataBucket);
        storageLocation.setStsEnabled(true);
        storageLocation = synapseHelper.createStorageLocationForEntity(rawDataFolderId, storageLocation);
        storageLocationId = storageLocation.getStorageLocationId();
        LOG.info("Created Synapse storage location " + storageLocationId);
        ex3Config.setStorageLocationId(storageLocationId);
        isAppModified = true;
    }
    // Finally, enable Exporter 3.0 if it's not already enabled.
    if (!app.isExporter3Enabled()) {
        app.setExporter3Enabled(true);
        isAppModified = true;
    }
    // exporter3config and exporter3enabled.
    if (isAppModified) {
        appService.updateApp(app, true);
    }
    return ex3Config;
}
Also used : App(org.sagebionetworks.bridge.models.apps.App) Project(org.sagebionetworks.repo.model.Project) ExternalS3StorageLocationSetting(org.sagebionetworks.repo.model.project.ExternalS3StorageLocationSetting) BridgeSynapseException(org.sagebionetworks.bridge.exceptions.BridgeSynapseException) SynapseException(org.sagebionetworks.client.exceptions.SynapseException) EntityView(org.sagebionetworks.repo.model.table.EntityView) Team(org.sagebionetworks.repo.model.Team) Exporter3Configuration(org.sagebionetworks.bridge.models.apps.Exporter3Configuration) Folder(org.sagebionetworks.repo.model.Folder)

Example 5 with Exporter3Configuration

use of org.sagebionetworks.bridge.models.apps.Exporter3Configuration in project BridgeServer2 by Sage-Bionetworks.

the class Exporter3ServiceTest method initExporter3_MissingTrackingView.

// branch coverage
@Test
public void initExporter3_MissingTrackingView() 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);
    // For whatever reason, the tracking view does not exist in Synapse.
    when(mockSynapseHelper.getEntityWithRetry(SYNAPSE_TRACKING_VIEW_ID, EntityView.class)).thenReturn(null);
    // 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. Specifically, since it doesn't exist, we never wrote it back to
    // Synapse.
    verify(mockSynapseHelper, never()).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)

Aggregations

Exporter3Configuration (org.sagebionetworks.bridge.models.apps.Exporter3Configuration)8 Test (org.testng.annotations.Test)6 Project (org.sagebionetworks.repo.model.Project)4 EntityView (org.sagebionetworks.repo.model.table.EntityView)4 App (org.sagebionetworks.bridge.models.apps.App)3 Folder (org.sagebionetworks.repo.model.Folder)2 Team (org.sagebionetworks.repo.model.Team)2 ExternalS3StorageLocationSetting (org.sagebionetworks.repo.model.project.ExternalS3StorageLocationSetting)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 HashMap (java.util.HashMap)1 DynamoApp (org.sagebionetworks.bridge.dynamodb.DynamoApp)1 BridgeSynapseException (org.sagebionetworks.bridge.exceptions.BridgeSynapseException)1 UserSession (org.sagebionetworks.bridge.models.accounts.UserSession)1 OAuthProvider (org.sagebionetworks.bridge.models.apps.OAuthProvider)1 OAuthProviderTest (org.sagebionetworks.bridge.models.apps.OAuthProviderTest)1 PasswordPolicy (org.sagebionetworks.bridge.models.apps.PasswordPolicy)1 TemplateType (org.sagebionetworks.bridge.models.templates.TemplateType)1 UploadFieldDefinition (org.sagebionetworks.bridge.models.upload.UploadFieldDefinition)1 SynapseException (org.sagebionetworks.client.exceptions.SynapseException)1 Entity (org.sagebionetworks.repo.model.Entity)1