use of com.amplifyframework.datastore.DataStoreConflictHandler.ConflictData 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);
});
}
Aggregations