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;
}
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);
}
}
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);
}
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;
}
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);
}
Aggregations