openmrs-android-sdk/src/main/java/com/openmrs/android_sdk/library/api/repository/ProviderRepository.java
/**
     * Update provider.
     *
     * @param provider the provider
     * @param callback the callback
     */
Update provider.
@param provider the provider
@param callback the callback
Update provider . @param provider the provider @param callback the callback
public void updateProvider(Provider provider, DefaultResponseCallback callback) {
        if (NetworkUtils.isOnline()) {
            restApi.UpdateProvider(provider.getUuid(), provider).enqueue(new Callback<Provider>() {
                @Override
                public void onResponse(@NotNull Call<Provider> call, @NotNull Response<Provider> response) {
                    if (response.isSuccessful()) {
                        providerRoomDao.updateProviderByUuid(response.body().getDisplay(), provider.getId(), response.body().getPerson(), response.body().getUuid(),
                                response.body().getIdentifier());
                        ToastUtil.success(context.getString(R.string.edit_provider_success_msg));
                        logger.e("Editing Provider Successful " + response.raw());
                        callback.onResponse();
                    }
                }
                @Override
                public void onFailure(@NotNull Call<Provider> call, @NotNull Throwable t) {
                    logger.e("Failed to edit provider. Error:  " + t.getMessage());
                    callback.onErrorResponse(context.getString(R.string.edit_provider_failure_msg));
                }
            });
        } else {
            providerRoomDao.updateProviderByUuid(provider.getDisplay(), provider.getId(), provider.getPerson(), provider.getUuid(), provider.getIdentifier());
            callback.onResponse();
            Data data = new Data.Builder().putString("uuid", provider.getUuid()).build();
            Constraints constraints = new Constraints.Builder().setRequiredNetworkType(NetworkType.CONNECTED).build();
            workManager.enqueue(new OneTimeWorkRequest.Builder(UpdateProviderWorker.class).setConstraints(constraints).setInputData(data).build());
            ToastUtil.success(context.getString(R.string.offline_provider_edit));
            logger.e("updated provider will be synced to the server when device gets connected to network");
        }
    }
public void updateProvider ( Provider provider , DefaultResponseCallback callback ) { if ( NetworkUtils . isOnline ( ) ) { restApi . UpdateProvider ( provider . getUuid ( ) , provider ) . enqueue ( new Callback < Provider > ( ) { @ Override public void onResponse ( @ NotNull Call < Provider > call , @ NotNull Response < Provider > response ) { if ( response . isSuccessful ( ) ) { providerRoomDao . updateProviderByUuid ( response . body ( ) . getDisplay ( ) , provider . getId ( ) , response . body ( ) . getPerson ( ) , response . body ( ) . getUuid ( ) , response . body ( ) . getIdentifier ( ) ) ; ToastUtil . success ( context . getString ( R . string . edit_provider_success_msg ) ) ; logger . e ( "Editing Provider Successful " + response . raw ( ) ) ; callback . onResponse ( ) ; } } @ Override public void onFailure ( @ NotNull Call < Provider > call , @ NotNull Throwable t ) { logger . e ( "Failed to edit provider. Error:  " + t . getMessage ( ) ) ; callback . onErrorResponse ( context . getString ( R . string . edit_provider_failure_msg ) ) ; } } ) ; } else { providerRoomDao . updateProviderByUuid ( provider . getDisplay ( ) , provider . getId ( ) , provider . getPerson ( ) , provider . getUuid ( ) , provider . getIdentifier ( ) ) ; callback . onResponse ( ) ; Data data = new Data . Builder ( ) . putString ( "uuid" , provider . getUuid ( ) ) . build ( ) ; Constraints constraints = new Constraints . Builder ( ) . setRequiredNetworkType ( NetworkType . CONNECTED ) . build ( ) ; workManager . enqueue ( new OneTimeWorkRequest . Builder ( UpdateProviderWorker . class ) . setConstraints ( constraints ) . setInputData ( data ) . build ( ) ) ; ToastUtil . success ( context . getString ( R . string . offline_provider_edit ) ) ; logger . e ( "updated provider will be synced to the server when device gets connected to network" ) ; } }
Update provider.
Update provider .
//offline update operation //offline update operation //delegate to the WorkManager for this work //toast about deferred provider updation