Search in sources :

Example 1 with TemplateType

use of org.sagebionetworks.bridge.models.templates.TemplateType 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 TemplateType

use of org.sagebionetworks.bridge.models.templates.TemplateType in project BridgeServer2 by Sage-Bionetworks.

the class AppServiceTest method createAppCreatesDefaultTemplates.

@Test
public void createAppCreatesDefaultTemplates() {
    // Mock this to verify that defaults are set in app
    GuidVersionHolder keys = new GuidVersionHolder("oneGuid", 1L);
    when(mockTemplateService.createTemplate(any(), any())).thenReturn(keys);
    app = TestUtils.getValidApp(AppServiceTest.class);
    app.setIdentifier(TEST_APP_ID);
    app.setDefaultTemplates(ImmutableMap.of());
    service.createApp(app);
    int templateTypeNum = TemplateType.values().length;
    assertEquals(app.getDefaultTemplates().size(), templateTypeNum);
    verify(mockTemplateService, times(templateTypeNum)).createTemplate(eq(app), templateCaptor.capture());
    for (int i = 0; i < templateTypeNum; i++) {
        TemplateType type = TemplateType.values()[i];
        Template template = templateCaptor.getAllValues().get(i);
        assertEquals(template.getTemplateType(), type);
        assertEquals(template.getName(), BridgeUtils.templateTypeToLabel(type));
        assertEquals(app.getDefaultTemplates().get(type.name().toLowerCase()), "oneGuid");
    }
}
Also used : TemplateType(org.sagebionetworks.bridge.models.templates.TemplateType) GuidVersionHolder(org.sagebionetworks.bridge.models.GuidVersionHolder) Template(org.sagebionetworks.bridge.models.templates.Template) Test(org.testng.annotations.Test)

Example 3 with TemplateType

use of org.sagebionetworks.bridge.models.templates.TemplateType in project BridgeServer2 by Sage-Bionetworks.

the class TemplateController method getTemplates.

@GetMapping("/v3/templates")
public PagedResourceList<? extends Template> getTemplates(@RequestParam(name = "type", required = false) String templateType, @RequestParam(required = false) String offsetBy, @RequestParam(required = false) String pageSize, @RequestParam(required = false) String includeDeleted) {
    UserSession session = getAuthenticatedSession(DEVELOPER);
    if (templateType == null) {
        throw new BadRequestException("Template type is required");
    }
    TemplateType type = null;
    try {
        type = TemplateType.valueOf(templateType.toUpperCase());
    } catch (IllegalArgumentException e) {
        throw new BadRequestException("Invalid template type: " + templateType);
    }
    Integer offsetInt = BridgeUtils.getIntOrDefault(offsetBy, 0);
    Integer pageSizeInt = BridgeUtils.getIntOrDefault(pageSize, API_DEFAULT_PAGE_SIZE);
    Boolean includeDeletedFlag = Boolean.valueOf(includeDeleted);
    return templateService.getTemplatesForType(session.getAppId(), type, offsetInt, pageSizeInt, includeDeletedFlag);
}
Also used : UserSession(org.sagebionetworks.bridge.models.accounts.UserSession) BadRequestException(org.sagebionetworks.bridge.exceptions.BadRequestException) TemplateType(org.sagebionetworks.bridge.models.templates.TemplateType) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 4 with TemplateType

use of org.sagebionetworks.bridge.models.templates.TemplateType in project BridgeServer2 by Sage-Bionetworks.

the class AppService method createApp.

public App createApp(App app) {
    checkNotNull(app);
    if (app.getVersion() != null) {
        throw new EntityAlreadyExistsException(App.class, "App has a version value; it may already exist", new ImmutableMap.Builder<String, Object>().put(IDENTIFIER_PROPERTY, app.getIdentifier()).build());
    }
    app.setActive(true);
    app.setConsentNotificationEmailVerified(false);
    app.setAppIdExcludedInExport(true);
    app.setVerifyChannelOnSignInEnabled(true);
    app.setEmailVerificationEnabled(true);
    app.getDataGroups().add(BridgeConstants.TEST_USER_GROUP);
    if (app.getPasswordPolicy() == null) {
        app.setPasswordPolicy(PasswordPolicy.DEFAULT_PASSWORD_POLICY);
    }
    // because we don't want to suddenly be creating reauth tokens for old apps that don't use reauth.
    if (app.isReauthenticationEnabled() == null) {
        app.setReauthenticationEnabled(true);
    }
    // If validation strictness isn't set on app creation, set it to a reasonable default.
    if (app.getUploadValidationStrictness() == null) {
        app.setUploadValidationStrictness(UploadValidationStrictness.REPORT);
    }
    Validate.entityThrowingException(validator, app);
    if (appDao.doesIdentifierExist(app.getIdentifier())) {
        throw new EntityAlreadyExistsException(App.class, IDENTIFIER_PROPERTY, app.getIdentifier());
    }
    Study study = Study.create();
    study.setAppId(app.getIdentifier());
    study.setIdentifier(app.getIdentifier() + "-study");
    study.setName(app.getName() + " Study");
    studyService.createStudy(app.getIdentifier(), study, false);
    subpopService.createDefaultSubpopulation(app, study);
    Map<String, String> map = new HashMap<>();
    for (TemplateType type : TemplateType.values()) {
        String typeName = type.name().toLowerCase();
        Template template = Template.create();
        template.setName(BridgeUtils.templateTypeToLabel(type));
        template.setTemplateType(type);
        GuidVersionHolder keys = templateService.createTemplate(app, template);
        map.put(typeName, keys.getGuid());
    }
    app.setDefaultTemplates(map);
    // do not create certs for whitelisted apps (legacy apps)
    if (!appWhitelist.contains(app.getIdentifier())) {
        uploadCertService.createCmsKeyPair(app.getIdentifier());
    }
    app = appDao.createApp(app);
    cacheProvider.setApp(app);
    emailVerificationService.verifyEmailAddress(app.getSupportEmail());
    if (app.getConsentNotificationEmail() != null) {
        sendVerifyEmail(app, AppEmailType.CONSENT_NOTIFICATION);
    }
    return app;
}
Also used : Study(org.sagebionetworks.bridge.models.studies.Study) EntityAlreadyExistsException(org.sagebionetworks.bridge.exceptions.EntityAlreadyExistsException) HashMap(java.util.HashMap) TemplateType(org.sagebionetworks.bridge.models.templates.TemplateType) ImmutableMap(com.google.common.collect.ImmutableMap) GuidVersionHolder(org.sagebionetworks.bridge.models.GuidVersionHolder) Template(org.sagebionetworks.bridge.models.templates.Template)

Aggregations

TemplateType (org.sagebionetworks.bridge.models.templates.TemplateType)4 HashMap (java.util.HashMap)2 GuidVersionHolder (org.sagebionetworks.bridge.models.GuidVersionHolder)2 Template (org.sagebionetworks.bridge.models.templates.Template)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 DynamoApp (org.sagebionetworks.bridge.dynamodb.DynamoApp)1 BadRequestException (org.sagebionetworks.bridge.exceptions.BadRequestException)1 EntityAlreadyExistsException (org.sagebionetworks.bridge.exceptions.EntityAlreadyExistsException)1 UserSession (org.sagebionetworks.bridge.models.accounts.UserSession)1 Exporter3Configuration (org.sagebionetworks.bridge.models.apps.Exporter3Configuration)1 Study (org.sagebionetworks.bridge.models.studies.Study)1 GetMapping (org.springframework.web.bind.annotation.GetMapping)1 Test (org.testng.annotations.Test)1