Search in sources :

Example 1 with CategoryConfiguration

use of com.amplifyframework.core.category.CategoryConfiguration in project amplify-android by aws-amplify.

the class TestStorageCategory method create.

/**
 * Creates an instance of {@link StorageCategory} using the provided configuration resource.
 * @param context Android Context
 * @param resourceId Android resource ID for a configuration file
 * @return A StorageCategory instance using the provided configuration
 */
static StorageCategory create(@NonNull Context context, @RawRes int resourceId) {
    Objects.requireNonNull(context);
    final StorageCategory storageCategory = new StorageCategory();
    try {
        storageCategory.addPlugin(new AWSS3StoragePlugin(new TestCognitoAuthProvider()));
        CategoryConfiguration storageConfiguration = AmplifyConfiguration.fromConfigFile(context, resourceId).forCategoryType(CategoryType.STORAGE);
        storageCategory.configure(storageConfiguration, context);
    // storageCategory.initialize(context); // Doesn't do anything right now.
    } catch (AmplifyException initializationFailure) {
        throw new RuntimeException(initializationFailure);
    }
    return storageCategory;
}
Also used : AmplifyException(com.amplifyframework.AmplifyException) StorageCategory(com.amplifyframework.storage.StorageCategory) CategoryConfiguration(com.amplifyframework.core.category.CategoryConfiguration)

Example 2 with CategoryConfiguration

use of com.amplifyframework.core.category.CategoryConfiguration in project amplify-android by aws-amplify.

the class Amplify method configure.

/**
 * Configure Amplify with AmplifyConfiguration object.
 * @param configuration AmplifyConfiguration object for configuration via code
 * @param context An Android Context
 * @throws AmplifyException Indicates one of numerous possible failures to configure the Framework
 */
public static void configure(@NonNull final AmplifyConfiguration configuration, @NonNull Context context) throws AmplifyException {
    Objects.requireNonNull(configuration);
    Objects.requireNonNull(context);
    synchronized (CONFIGURATION_LOCK) {
        if (CONFIGURATION_LOCK.get()) {
            throw new AlreadyConfiguredException("Remove the duplicate call to `Amplify.configure()`.");
        }
        // Configure User-Agent utility
        UserAgent.configure(configuration.getPlatformVersions());
        if (configuration.isDevMenuEnabled()) {
            DeveloperMenu.singletonInstance(context).enableDeveloperMenu();
        }
        for (Category<? extends Plugin<?>> category : CATEGORIES.values()) {
            if (category.getPlugins().size() > 0) {
                CategoryConfiguration categoryConfiguration = configuration.forCategoryType(category.getCategoryType());
                category.configure(categoryConfiguration, context);
                beginInitialization(category, context);
            }
        }
        CONFIGURATION_LOCK.set(true);
    }
}
Also used : CategoryConfiguration(com.amplifyframework.core.category.CategoryConfiguration)

Example 3 with CategoryConfiguration

use of com.amplifyframework.core.category.CategoryConfiguration in project amplify-android by aws-amplify.

the class AmplifyConfiguration method configsFromJson.

private static Map<String, CategoryConfiguration> configsFromJson(JSONObject json) throws AmplifyException {
    final List<CategoryConfiguration> possibleConfigs = Arrays.asList(new AnalyticsCategoryConfiguration(), new ApiCategoryConfiguration(), new AuthCategoryConfiguration(), new DataStoreCategoryConfiguration(), new GeoCategoryConfiguration(), new HubCategoryConfiguration(), new LoggingCategoryConfiguration(), new PredictionsCategoryConfiguration(), new StorageCategoryConfiguration());
    final Map<String, CategoryConfiguration> actualConfigs = new HashMap<>();
    try {
        for (CategoryConfiguration possibleConfig : possibleConfigs) {
            String categoryJsonKey = possibleConfig.getCategoryType().getConfigurationKey();
            if (json.has(categoryJsonKey)) {
                possibleConfig.populateFromJSON(json.getJSONObject(categoryJsonKey));
                actualConfigs.put(categoryJsonKey, possibleConfig);
            }
        }
    } catch (JSONException error) {
        throw new AmplifyException("Could not parse amplifyconfiguration.json ", error, "Check any modifications made to the file.");
    }
    return Immutable.of(actualConfigs);
}
Also used : DataStoreCategoryConfiguration(com.amplifyframework.datastore.DataStoreCategoryConfiguration) StorageCategoryConfiguration(com.amplifyframework.storage.StorageCategoryConfiguration) AmplifyException(com.amplifyframework.AmplifyException) PredictionsCategoryConfiguration(com.amplifyframework.predictions.PredictionsCategoryConfiguration) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) AuthCategoryConfiguration(com.amplifyframework.auth.AuthCategoryConfiguration) LoggingCategoryConfiguration(com.amplifyframework.logging.LoggingCategoryConfiguration) AnalyticsCategoryConfiguration(com.amplifyframework.analytics.AnalyticsCategoryConfiguration) AuthCategoryConfiguration(com.amplifyframework.auth.AuthCategoryConfiguration) CategoryConfiguration(com.amplifyframework.core.category.CategoryConfiguration) GeoCategoryConfiguration(com.amplifyframework.geo.GeoCategoryConfiguration) DataStoreCategoryConfiguration(com.amplifyframework.datastore.DataStoreCategoryConfiguration) HubCategoryConfiguration(com.amplifyframework.hub.HubCategoryConfiguration) PredictionsCategoryConfiguration(com.amplifyframework.predictions.PredictionsCategoryConfiguration) StorageCategoryConfiguration(com.amplifyframework.storage.StorageCategoryConfiguration) ApiCategoryConfiguration(com.amplifyframework.api.ApiCategoryConfiguration) EmptyCategoryConfiguration(com.amplifyframework.core.category.EmptyCategoryConfiguration) JSONException(org.json.JSONException) GeoCategoryConfiguration(com.amplifyframework.geo.GeoCategoryConfiguration) AnalyticsCategoryConfiguration(com.amplifyframework.analytics.AnalyticsCategoryConfiguration) ApiCategoryConfiguration(com.amplifyframework.api.ApiCategoryConfiguration) HubCategoryConfiguration(com.amplifyframework.hub.HubCategoryConfiguration) LoggingCategoryConfiguration(com.amplifyframework.logging.LoggingCategoryConfiguration)

Example 4 with CategoryConfiguration

use of com.amplifyframework.core.category.CategoryConfiguration in project amplify-android by aws-amplify.

the class TestPredictionsCategory method create.

/**
 * Creates an instance of {@link PredictionsCategory} using the provided configuration resource.
 * @param context Android Context
 * @param resourceId Android resource ID for a configuration file
 * @return A PredictionsCategory instance using the provided configuration
 */
static PredictionsCategory create(@NonNull Context context, @RawRes int resourceId) {
    Objects.requireNonNull(context);
    final PredictionsCategory predictionsCategory = new PredictionsCategory();
    try {
        predictionsCategory.addPlugin(new AWSPredictionsPlugin(AWSMobileClient.getInstance()));
        CategoryConfiguration predictionsConfiguration = AmplifyConfiguration.fromConfigFile(context, resourceId).forCategoryType(CategoryType.PREDICTIONS);
        predictionsCategory.configure(predictionsConfiguration, context);
        predictionsCategory.initialize(context);
    } catch (AmplifyException initializationFailure) {
        throw new RuntimeException(initializationFailure);
    }
    return predictionsCategory;
}
Also used : AmplifyException(com.amplifyframework.AmplifyException) PredictionsCategory(com.amplifyframework.predictions.PredictionsCategory) CategoryConfiguration(com.amplifyframework.core.category.CategoryConfiguration)

Example 5 with CategoryConfiguration

use of com.amplifyframework.core.category.CategoryConfiguration in project amplify-android by aws-amplify.

the class HybridAssociationSyncInstrumentationTest method setup.

/**
 * DataStore is configured with a real AppSync endpoint. API and AppSync clients
 * are used to arrange/validate state before/after exercising the DataStore. The {@link Amplify}
 * facade is intentionally *not* used, since we don't want to pollute the instrumentation
 * test process with global state. We need an *instance* of the DataStore.
 * @throws AmplifyException On failure to configure Amplify, API/DataStore categories.
 */
@Ignore("It passes. Not automating due to operational concerns as noted in class-level @Ignore.")
@Before
public void setup() throws AmplifyException {
    Amplify.addPlugin(new AndroidLoggingPlugin(LogLevel.VERBOSE));
    StrictMode.enable();
    Context context = getApplicationContext();
    @RawRes int configResourceId = Resources.getRawResourceId(context, "amplifyconfiguration");
    // Setup an API
    CategoryConfiguration apiCategoryConfiguration = AmplifyConfiguration.fromConfigFile(context, configResourceId).forCategoryType(CategoryType.API);
    ApiCategory apiCategory = new ApiCategory();
    apiCategory.addPlugin(new AWSApiPlugin());
    apiCategory.configure(apiCategoryConfiguration, context);
    // To arrange and verify state, we need to access the supporting AppSync API
    api = SynchronousApi.delegatingTo(apiCategory);
    appSync = SynchronousAppSync.using(AppSyncClient.via(apiCategory));
    schemaProvider = SchemaLoader.loadFromAssetsDirectory("schemas/commentsblog");
    DataStoreCategory dataStoreCategory = DataStoreCategoryConfigurator.begin().api(apiCategory).clearDatabase(true).context(context).modelProvider(schemaProvider).resourceId(configResourceId).timeout(TIMEOUT_SECONDS, TimeUnit.SECONDS).finish();
    AWSDataStorePlugin plugin = (AWSDataStorePlugin) dataStoreCategory.getPlugin("awsDataStorePlugin");
    normalBehaviors = SynchronousDataStore.delegatingTo(dataStoreCategory);
    hybridBehaviors = SynchronousHybridBehaviors.delegatingTo(plugin);
}
Also used : Context(android.content.Context) ApplicationProvider.getApplicationContext(androidx.test.core.app.ApplicationProvider.getApplicationContext) AWSApiPlugin(com.amplifyframework.api.aws.AWSApiPlugin) RawRes(androidx.annotation.RawRes) CategoryConfiguration(com.amplifyframework.core.category.CategoryConfiguration) ApiCategory(com.amplifyframework.api.ApiCategory) AndroidLoggingPlugin(com.amplifyframework.logging.AndroidLoggingPlugin) Before(org.junit.Before) Ignore(org.junit.Ignore)

Aggregations

CategoryConfiguration (com.amplifyframework.core.category.CategoryConfiguration)12 ApiCategory (com.amplifyframework.api.ApiCategory)6 Context (android.content.Context)5 RawRes (androidx.annotation.RawRes)4 ApplicationProvider.getApplicationContext (androidx.test.core.app.ApplicationProvider.getApplicationContext)4 AmplifyException (com.amplifyframework.AmplifyException)4 AWSApiPlugin (com.amplifyframework.api.aws.AWSApiPlugin)4 AndroidLoggingPlugin (com.amplifyframework.logging.AndroidLoggingPlugin)4 CategoryType (com.amplifyframework.core.category.CategoryType)3 HashMap (java.util.HashMap)3 DefaultCognitoUserPoolsAuthProvider (com.amplifyframework.api.aws.sigv4.DefaultCognitoUserPoolsAuthProvider)2 AuthCategory (com.amplifyframework.auth.AuthCategory)2 AmplifyConfiguration (com.amplifyframework.core.AmplifyConfiguration)2 PredictionsCategory (com.amplifyframework.predictions.PredictionsCategory)2 HubAccumulator (com.amplifyframework.testutils.HubAccumulator)2 RandomString (com.amplifyframework.testutils.random.RandomString)2 JSONObject (org.json.JSONObject)2 Before (org.junit.Before)2 Ignore (org.junit.Ignore)2 Test (org.junit.Test)2