fix codacy issues

Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
This commit is contained in:
Andy Scherzinger 2022-07-23 18:27:14 +02:00
parent 8f6bb87761
commit 516b9190ad
No known key found for this signature in database
GPG key ID: 6CADC7E3523C308B
3 changed files with 9 additions and 235 deletions

View file

@ -56,7 +56,6 @@ public class ShareOperationWorker extends Worker {
private final String TAG = "ShareOperationWorker";
private long userId;
private User operationsUser;
private String roomToken;
private List<String> filesArray = new ArrayList<>();
private String credentials;
@ -71,7 +70,7 @@ public class ShareOperationWorker extends Worker {
roomToken = data.getString(BundleKeys.INSTANCE.getKEY_ROOM_TOKEN());
metaData = data.getString(BundleKeys.INSTANCE.getKEY_META_DATA());
Collections.addAll(filesArray, data.getStringArray(BundleKeys.INSTANCE.getKEY_FILE_PATHS()));
operationsUser = userManager.getUserWithId(userId).blockingGet();
User operationsUser = userManager.getUserWithId(userId).blockingGet();
credentials = ApiUtils.getCredentials(operationsUser.getUsername(), operationsUser.getToken());
baseUrl = operationsUser.getBaseUrl();
}

View file

@ -42,8 +42,6 @@ import autodagger.AutoInjector;
@AutoInjector(NextcloudTalkApplication.class)
public class WebsocketConnectionsWorker extends Worker {
private static final String TAG = "WebsocketConnectionsWorker";
@Inject
UserManager userManager;
@ -58,18 +56,16 @@ public class WebsocketConnectionsWorker extends Worker {
NextcloudTalkApplication.Companion.getSharedApplication().getComponentApplication().inject(this);
List<User> users = userManager.getUsers().blockingGet();
ExternalSignalingServer externalSignalingServer;
WebSocketConnectionHelper webSocketConnectionHelper = new WebSocketConnectionHelper();
for (User user : users) {
if (user.getExternalSignalingServer() != null) {
if (user.getExternalSignalingServer().getExternalSignalingServer() != null &&
!TextUtils.isEmpty(user.getExternalSignalingServer().getExternalSignalingServer()) &&
!TextUtils.isEmpty(user.getExternalSignalingServer().getExternalSignalingTicket())) {
webSocketConnectionHelper.getExternalSignalingInstanceForServer(
user.getExternalSignalingServer().getExternalSignalingServer(),
user, user.getExternalSignalingServer().getExternalSignalingTicket(),
false);
}
if (user.getExternalSignalingServer() != null &&
user.getExternalSignalingServer().getExternalSignalingServer() != null &&
!TextUtils.isEmpty(user.getExternalSignalingServer().getExternalSignalingServer()) &&
!TextUtils.isEmpty(user.getExternalSignalingServer().getExternalSignalingTicket())) {
webSocketConnectionHelper.getExternalSignalingInstanceForServer(
user.getExternalSignalingServer().getExternalSignalingServer(),
user, user.getExternalSignalingServer().getExternalSignalingTicket(),
false);
}
}

View file

@ -47,225 +47,4 @@ public class UserUtils {
UserUtils(ReactiveEntityStore<Persistable> dataStore) {
this.dataStore = dataStore;
}
private boolean anyUserExists() {
return (dataStore.count(User.class).where(UserEntity.SCHEDULED_FOR_DELETION.notEqual(Boolean.TRUE))
.limit(1).get().value() > 0);
}
private boolean hasMultipleUsers() {
return (dataStore.count(User.class).where(UserEntity.SCHEDULED_FOR_DELETION.notEqual(Boolean.TRUE))
.get().value() > 1);
}
private List getUsers() {
Result findUsersQueryResult = dataStore.select(User.class).where
(UserEntity.SCHEDULED_FOR_DELETION.notEqual(Boolean.TRUE)).get();
return findUsersQueryResult.toList();
}
private List getUsersScheduledForDeletion() {
Result findUsersQueryResult = dataStore.select(User.class)
.where(UserEntity.SCHEDULED_FOR_DELETION.eq(Boolean.TRUE)).get();
return findUsersQueryResult.toList();
}
private UserEntity getAnyUserAndSetAsActive() {
Result findUserQueryResult = dataStore.select(User.class)
.where(UserEntity.SCHEDULED_FOR_DELETION.notEqual(Boolean.TRUE))
.limit(1).get();
UserEntity userEntity;
if ((userEntity = (UserEntity) findUserQueryResult.firstOrNull()) != null) {
userEntity.setCurrent(true);
dataStore.update(userEntity).blockingGet();
return userEntity;
}
return null;
}
private Completable deleteUser(long internalId) {
Result findUserQueryResult = dataStore.select(User.class).where(UserEntity.ID.eq(internalId)).limit(1).get();
UserEntity user = (UserEntity) findUserQueryResult.firstOrNull();
return dataStore.delete(user)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread());
}
private Completable deleteUserWithId(long id) {
Result findUserQueryResult = dataStore.select(User.class).where(UserEntity.ID.eq(id)).limit(1).get();
UserEntity user = (UserEntity) findUserQueryResult.firstOrNull();
return dataStore.delete(user)
.subscribeOn(Schedulers.io());
}
private UserEntity getUserById(String id) {
Result findUserQueryResult = dataStore.select(User.class).where(UserEntity.USER_ID.eq(id))
.limit(1).get();
return (UserEntity) findUserQueryResult.firstOrNull();
}
private UserEntity getUserWithId(long id) {
Result findUserQueryResult = dataStore.select(User.class).where(UserEntity.ID.eq(id))
.limit(1).get();
return (UserEntity) findUserQueryResult.firstOrNull();
}
private void disableAllUsersWithoutId(long userId) {
Result findUserQueryResult = dataStore.select(User.class).where(UserEntity.ID.notEqual(userId)).get();
for (Object object : findUserQueryResult) {
UserEntity userEntity = (UserEntity) object;
userEntity.setCurrent(false);
dataStore.update(userEntity).blockingGet();
}
}
private boolean checkIfUserIsScheduledForDeletion(String username, String server) {
Result findUserQueryResult = dataStore.select(User.class).where(UserEntity.USERNAME.eq(username))
.and(UserEntity.BASE_URL.eq(server))
.limit(1).get();
UserEntity userEntity;
if ((userEntity = (UserEntity) findUserQueryResult.firstOrNull()) != null) {
return userEntity.getScheduledForDeletion();
}
return false;
}
private UserEntity getUserWithInternalId(long internalId) {
Result findUserQueryResult = dataStore.select(User.class).where(UserEntity.ID.eq(internalId)
.and(UserEntity.SCHEDULED_FOR_DELETION.notEqual(Boolean.TRUE)))
.limit(1).get();
return (UserEntity) findUserQueryResult.firstOrNull();
}
private boolean getIfUserWithUsernameAndServer(String username, String server) {
Result findUserQueryResult = dataStore.select(User.class).where(UserEntity.USERNAME.eq(username)
.and(UserEntity.BASE_URL.eq(server)))
.limit(1).get();
return findUserQueryResult.firstOrNull() != null;
}
private boolean scheduleUserForDeletionWithId(long id) {
Result findUserQueryResult = dataStore.select(User.class).where(UserEntity.ID.eq(id))
.limit(1).get();
UserEntity userEntity;
if ((userEntity = (UserEntity) findUserQueryResult.firstOrNull()) != null) {
userEntity.setScheduledForDeletion(true);
userEntity.setCurrent(false);
dataStore.update(userEntity).blockingGet();
}
return getAnyUserAndSetAsActive() != null;
}
private Observable<UserEntity> createOrUpdateUser(@Nullable String username, @Nullable String token,
@Nullable String serverUrl,
@Nullable String displayName,
@Nullable String pushConfigurationState,
@Nullable Boolean currentUser,
@Nullable String userId,
@Nullable Long internalId,
@Nullable String capabilities,
@Nullable String certificateAlias,
@Nullable String externalSignalingServer) {
Result findUserQueryResult;
if (internalId == null) {
findUserQueryResult = dataStore.select(User.class).where(UserEntity.USERNAME.eq(username).
and(UserEntity.BASE_URL.eq(serverUrl))).limit(1).get();
} else {
findUserQueryResult = dataStore.select(User.class).where(UserEntity.ID.eq(internalId)).get();
}
UserEntity user = (UserEntity) findUserQueryResult.firstOrNull();
if (user == null) {
user = new UserEntity();
user.setBaseUrl(serverUrl);
user.setUsername(username);
user.setToken(token);
if (!TextUtils.isEmpty(displayName)) {
user.setDisplayName(displayName);
}
if (pushConfigurationState != null) {
user.setPushConfigurationState(pushConfigurationState);
}
if (!TextUtils.isEmpty(userId)) {
user.setUserId(userId);
}
if (!TextUtils.isEmpty(capabilities)) {
user.setCapabilities(capabilities);
}
if (!TextUtils.isEmpty(certificateAlias)) {
user.setClientCertificate(certificateAlias);
}
if (!TextUtils.isEmpty(externalSignalingServer)) {
user.setExternalSignalingServer(externalSignalingServer);
}
user.setCurrent(true);
} else {
if (userId != null && (user.getUserId() == null || !user.getUserId().equals(userId))) {
user.setUserId(userId);
}
if (token != null && !token.equals(user.getToken())) {
user.setToken(token);
}
if ((displayName != null && user.getDisplayName() == null) || (displayName != null && user.getDisplayName()
!= null && !displayName.equals(user.getDisplayName()))) {
user.setDisplayName(displayName);
}
if (pushConfigurationState != null && !pushConfigurationState.equals(user.getPushConfigurationState())) {
user.setPushConfigurationState(pushConfigurationState);
}
if (capabilities != null && !capabilities.equals(user.getCapabilities())) {
user.setCapabilities(capabilities);
}
if (certificateAlias != null && !certificateAlias.equals(user.getClientCertificate())) {
user.setClientCertificate(certificateAlias);
}
if (externalSignalingServer != null && !externalSignalingServer.equals(user.getExternalSignalingServer())) {
user.setExternalSignalingServer(externalSignalingServer);
}
if (currentUser != null) {
user.setCurrent(currentUser);
}
}
return dataStore.upsert(user)
.toObservable()
.subscribeOn(Schedulers.io());
}
}