Skip to content

Commit

Permalink
#1727 owner null: better error output
Browse files Browse the repository at this point in the history
  • Loading branch information
desperateCoder committed Jan 31, 2025
1 parent 982dfd4 commit c977103
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -875,6 +875,10 @@ public LiveData<List<User>> getUsersForAccount(final long accountId) {
.distinctUntilChanged();
}

public List<User> getAllUsersDirectly() {
return db.getUserDao().getAllUsersDirectly();
}

public LiveData<List<User>> searchUserByUidOrDisplayName(final long accountId, final long boardId, final long notYetAssignedToLocalCardId, final String searchTerm) {
validateSearchTerm(searchTerm);
return new ReactiveLiveData<>(db.getUserDao().searchUserByUidOrDisplayName(accountId, boardId, notYetAssignedToLocalCardId, "%" + searchTerm.trim() + "%"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ public interface UserDao extends GenericDao<User> {

@Query("SELECT * FROM user WHERE accountId = :accountId")
LiveData<List<User>> getUsersForAccount(final long accountId);
@Query("SELECT * FROM user")
List<User> getAllUsersDirectly();

@Query("SELECT * FROM user WHERE accountId = :accountId and localId = :localId")
LiveData<User> getUserByLocalId(final long accountId, final long localId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,8 @@ public void createBoard(@NonNull Account account, @NonNull Board board, @NonNull
executor.submit(() -> {
final User owner = dataBaseAdapter.getUserByUidDirectly(account.getId(), account.getUserName());
if (owner == null) {
callback.onError(new IllegalStateException("Owner is null. This can be the case if the Deck app has never before been opened in the webinterface"));
StringBuilder sb = buildOwnerNullMessage(account);
callback.onError(new IllegalStateException(sb.toString()));
} else {
final FullBoard fullBoard = new FullBoard();
board.setOwnerId(owner.getLocalId());
Expand All @@ -361,6 +362,30 @@ public void createBoard(@NonNull Account account, @NonNull Board board, @NonNull
});
}

@NonNull
private StringBuilder buildOwnerNullMessage(@NonNull Account account) {
StringBuilder sb = new StringBuilder("Owner is null. This can be the case if the Deck app has never before been opened in the webinterface. More:");
sb.append("\naccount_id:");
sb.append(account.getId());
sb.append("\nusername:");
sb.append(account.getUserName());

sb.append("\nList of available Users:");
sb.append(account.getUserName());
List<User> allUsers = dataBaseAdapter.getAllUsersDirectly();
if (allUsers != null) {
for (User u : allUsers) {
sb.append("\nuid:");
sb.append(u.getUid());
sb.append(" | account_id:");
sb.append(u.getAccountId());
}
} else {
sb.append("[none]");
}
return sb;
}

/**
* Creates a new {@link Board} and adds the same {@link Label} and {@link Stack} as in the origin {@link Board}.
* Owner of the target {@link Board} will be the {@link User} with the {@link Account} of {@param targetAccountId}.
Expand Down

0 comments on commit c977103

Please sign in to comment.