extract methods and add log commands in AccountRemovalWorker

Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
Marcel Hibbe 2021-04-30 14:46:25 +02:00
parent cb11c36400
commit c2032b6554
No known key found for this signature in database
GPG Key ID: C793F8B59F43CE7B

View File

@ -96,7 +96,6 @@ public class AccountRemovalWorker extends Worker {
ncApi = retrofit.newBuilder().client(okHttpClient.newBuilder().cookieJar(new ncApi = retrofit.newBuilder().client(okHttpClient.newBuilder().cookieJar(new
JavaNetCookieJar(new CookieManager())).build()).build().create(NcApi.class); JavaNetCookieJar(new CookieManager())).build()).build().create(NcApi.class);
String finalCredentials = credentials;
ncApi.unregisterDeviceForNotificationsWithNextcloud(credentials, ApiUtils.getUrlNextcloudPush(userEntity ncApi.unregisterDeviceForNotificationsWithNextcloud(credentials, ApiUtils.getUrlNextcloudPush(userEntity
.getBaseUrl())) .getBaseUrl()))
.blockingSubscribe(new Observer<GenericOverall>() { .blockingSubscribe(new Observer<GenericOverall>() {
@ -114,7 +113,33 @@ public class AccountRemovalWorker extends Worker {
queryMap.put("userPublicKey", finalPushConfigurationState.getUserPublicKey()); queryMap.put("userPublicKey", finalPushConfigurationState.getUserPublicKey());
queryMap.put("deviceIdentifierSignature", queryMap.put("deviceIdentifierSignature",
finalPushConfigurationState.getDeviceIdentifierSignature()); finalPushConfigurationState.getDeviceIdentifierSignature());
unregisterDeviceForNotificationWithProxy(queryMap, userEntity);
}
}
@Override
public void onError(Throwable e) {
Log.e(TAG, "error while trying to unregister Device For Notifications", e);
}
@Override
public void onComplete() {
}
});
} else {
deleteUser(userEntity);
}
} catch (IOException e) {
Log.d(TAG, "Something went wrong while removing job at parsing PushConfigurationState");
deleteUser(userEntity);
}
}
return Result.success();
}
private void unregisterDeviceForNotificationWithProxy(HashMap<String, String> queryMap, UserEntity userEntity) {
ncApi.unregisterDeviceForNotificationsWithProxy ncApi.unregisterDeviceForNotificationsWithProxy
(ApiUtils.getUrlPushProxy(), queryMap) (ApiUtils.getUrlPushProxy(), queryMap)
.subscribe(new Observer<Void>() { .subscribe(new Observer<Void>() {
@ -125,7 +150,6 @@ public class AccountRemovalWorker extends Worker {
@Override @Override
public void onNext(Void aVoid) { public void onNext(Void aVoid) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
String groupName = String.format(getApplicationContext().getResources() String groupName = String.format(getApplicationContext().getResources()
.getString(R.string .getString(R.string
@ -141,9 +165,23 @@ public class AccountRemovalWorker extends Worker {
.toString(crc32.getValue())); .toString(crc32.getValue()));
} }
} }
WebSocketConnectionHelper.deleteExternalSignalingInstanceForUserEntity(userEntity.getId()); WebSocketConnectionHelper.deleteExternalSignalingInstanceForUserEntity(userEntity.getId());
deleteAllEntriesForAccountIdentifier(userEntity);
}
@Override
public void onError(Throwable e) {
Log.e(TAG, "error while trying to unregister Device For Notification With Proxy", e);
}
@Override
public void onComplete() {
}
});
}
private void deleteAllEntriesForAccountIdentifier(UserEntity userEntity) {
arbitraryStorageUtils.deleteAllEntriesForAccountIdentifier(userEntity.getId()).subscribe(new Observer() { arbitraryStorageUtils.deleteAllEntriesForAccountIdentifier(userEntity.getId()).subscribe(new Observer() {
@Override @Override
public void onSubscribe(Disposable d) { public void onSubscribe(Disposable d) {
@ -152,27 +190,12 @@ public class AccountRemovalWorker extends Worker {
@Override @Override
public void onNext(Object o) { public void onNext(Object o) {
userUtils.deleteUser(userEntity.getId()).subscribe(new CompletableObserver() { deleteUser(userEntity);
@Override
public void onSubscribe(Disposable d) {
}
@Override
public void onComplete() {
} }
@Override @Override
public void onError(Throwable e) { public void onError(Throwable e) {
Log.e(TAG, "error while trying to delete All Entries For Account Identifier", e);
}
});
}
@Override
public void onError(Throwable e) {
} }
@Override @Override
@ -182,30 +205,8 @@ public class AccountRemovalWorker extends Worker {
}); });
} }
@Override private void deleteUser(UserEntity userEntity) {
public void onError(Throwable e) { String username = userEntity.getUsername();
}
@Override
public void onComplete() {
}
});
}
}
@Override
public void onError(Throwable e) {
}
@Override
public void onComplete() {
}
});
} else {
userUtils.deleteUser(userEntity.getId()) userUtils.deleteUser(userEntity.getId())
.subscribe(new CompletableObserver() { .subscribe(new CompletableObserver() {
@Override @Override
@ -215,37 +216,13 @@ public class AccountRemovalWorker extends Worker {
@Override @Override
public void onComplete() { public void onComplete() {
Log.d(TAG, "deleted user: " + username);
} }
@Override @Override
public void onError(Throwable e) { public void onError(Throwable e) {
Log.e(TAG, "error while trying to delete user", e);
}
});
}
} catch (IOException e) {
Log.d(TAG, "Something went wrong while removing job at parsing PushConfigurationState");
userUtils.deleteUser(userEntity.getId())
.subscribe(new CompletableObserver() {
@Override
public void onSubscribe(Disposable d) {
}
@Override
public void onComplete() {
}
@Override
public void onError(Throwable e) {
} }
}); });
} }
} }
return Result.success();
}
}