Search in sources :

Example 1 with AppSyncConflictUnhandledError

use of com.amplifyframework.datastore.appsync.AppSyncConflictUnhandledError in project amplify-android by aws-amplify.

the class ConflictResolver method resolve.

@NonNull
<T extends Model> Single<ModelWithMetadata<T>> resolve(@NonNull PendingMutation<T> pendingMutation, @NonNull AppSyncConflictUnhandledError<T> conflictUnhandledError) {
    final DataStoreConflictHandler conflictHandler;
    try {
        conflictHandler = configurationProvider.getConfiguration().getConflictHandler();
    } catch (DataStoreException badConfigurationProvider) {
        return Single.error(badConfigurationProvider);
    }
    ModelWithMetadata<T> serverData = conflictUnhandledError.getServerVersion();
    ModelMetadata metadata = serverData.getSyncMetadata();
    T local = getMutatedModelFromSerializedModel(pendingMutation);
    T remote = getServerModel(serverData, pendingMutation.getMutatedItem());
    ConflictData<T> conflictData = ConflictData.create(local, remote);
    return Single.<ConflictResolutionDecision<? extends Model>>create(emitter -> conflictHandler.onConflictDetected(conflictData, emitter::onSuccess)).flatMap(decision -> {
        @SuppressWarnings("unchecked") ConflictResolutionDecision<T> typedDecision = (ConflictResolutionDecision<T>) decision;
        return resolveModelAndMetadata(conflictData, metadata, typedDecision);
    });
}
Also used : DataStoreConfigurationProvider(com.amplifyframework.datastore.DataStoreConfigurationProvider) Single(io.reactivex.rxjava3.core.Single) DataStoreConflictHandler(com.amplifyframework.datastore.DataStoreConflictHandler) SerializedModel(com.amplifyframework.core.model.SerializedModel) NonNull(androidx.annotation.NonNull) ModelWithMetadata(com.amplifyframework.datastore.appsync.ModelWithMetadata) Model(com.amplifyframework.core.model.Model) AppSync(com.amplifyframework.datastore.appsync.AppSync) AppSyncConflictUnhandledError(com.amplifyframework.datastore.appsync.AppSyncConflictUnhandledError) SchemaRegistry(com.amplifyframework.core.model.SchemaRegistry) ConflictData(com.amplifyframework.datastore.DataStoreConflictHandler.ConflictData) GsonFactory(com.amplifyframework.util.GsonFactory) Objects(java.util.Objects) DataStoreException(com.amplifyframework.datastore.DataStoreException) Type(java.lang.reflect.Type) Gson(com.google.gson.Gson) ModelSchema(com.amplifyframework.core.model.ModelSchema) ModelMetadata(com.amplifyframework.datastore.appsync.ModelMetadata) GraphQLResponse(com.amplifyframework.api.graphql.GraphQLResponse) ConflictResolutionDecision(com.amplifyframework.datastore.DataStoreConflictHandler.ConflictResolutionDecision) DataStoreException(com.amplifyframework.datastore.DataStoreException) ConflictResolutionDecision(com.amplifyframework.datastore.DataStoreConflictHandler.ConflictResolutionDecision) DataStoreConflictHandler(com.amplifyframework.datastore.DataStoreConflictHandler) ModelMetadata(com.amplifyframework.datastore.appsync.ModelMetadata) NonNull(androidx.annotation.NonNull)

Aggregations

NonNull (androidx.annotation.NonNull)1 GraphQLResponse (com.amplifyframework.api.graphql.GraphQLResponse)1 Model (com.amplifyframework.core.model.Model)1 ModelSchema (com.amplifyframework.core.model.ModelSchema)1 SchemaRegistry (com.amplifyframework.core.model.SchemaRegistry)1 SerializedModel (com.amplifyframework.core.model.SerializedModel)1 DataStoreConfigurationProvider (com.amplifyframework.datastore.DataStoreConfigurationProvider)1 DataStoreConflictHandler (com.amplifyframework.datastore.DataStoreConflictHandler)1 ConflictData (com.amplifyframework.datastore.DataStoreConflictHandler.ConflictData)1 ConflictResolutionDecision (com.amplifyframework.datastore.DataStoreConflictHandler.ConflictResolutionDecision)1 DataStoreException (com.amplifyframework.datastore.DataStoreException)1 AppSync (com.amplifyframework.datastore.appsync.AppSync)1 AppSyncConflictUnhandledError (com.amplifyframework.datastore.appsync.AppSyncConflictUnhandledError)1 ModelMetadata (com.amplifyframework.datastore.appsync.ModelMetadata)1 ModelWithMetadata (com.amplifyframework.datastore.appsync.ModelWithMetadata)1 GsonFactory (com.amplifyframework.util.GsonFactory)1 Gson (com.google.gson.Gson)1 Single (io.reactivex.rxjava3.core.Single)1 Type (java.lang.reflect.Type)1 Objects (java.util.Objects)1