Search in sources :

Example 1 with Label

use of it.niedermann.nextcloud.deck.model.Label in project nextcloud-deck by stefan-niedermann.

the class SyncManager method createFullCard.

// public LiveData<FullCard> createCard(long accountId, long localBoardId, long localStackId, Card card) {
// 
// MutableLiveData<FullCard> liveData = new MutableLiveData<>();
// executor.submit(() -> {
// Account account = dataBaseAdapter.getAccountByIdDirectly(accountId);
// User owner = dataBaseAdapter.getUserByUidDirectly(accountId, account.getUserName());
// FullStack stack = dataBaseAdapter.getFullStackByLocalIdDirectly(localStackId);
// Board board = dataBaseAdapter.getBoardByLocalIdDirectly(localBoardId);
// card.setStackId(stack.getLocalId());
// FullCard fullCard = new FullCard();
// fullCard.setCard(card);
// fullCard.setOwner(owner);
// fullCard.setAccountId(accountId);
// new DataPropagationHelper(serverAdapter, dataBaseAdapter).createEntity(new CardPropagationDataProvider(null, board, stack), fullCard, new IResponseCallback<FullCard>(account) {
// @Override
// public void onResponse(FullCard response) {
// liveData.postValue(response);
// }
// }, (FullCard entity, FullCard response) -> {
// response.getCard().setUserId(entity.getCard().getUserId());
// response.getCard().setStackId(stack.getLocalId());
// });
// });
// return liveData;
// }
@AnyThread
public void createFullCard(long accountId, long localBoardId, long localStackId, @NonNull FullCard card, @NonNull IResponseCallback<FullCard> callback) {
    executor.submit(() -> {
        Account account = dataBaseAdapter.getAccountByIdDirectly(accountId);
        User owner = dataBaseAdapter.getUserByUidDirectly(accountId, account.getUserName());
        FullStack stack = dataBaseAdapter.getFullStackByLocalIdDirectly(localStackId);
        Board board = dataBaseAdapter.getBoardByLocalIdDirectly(localBoardId);
        card.getCard().setUserId(owner.getLocalId());
        card.getCard().setStackId(stack.getLocalId());
        card.getCard().setAccountId(accountId);
        card.getCard().setStatusEnum(DBStatus.LOCAL_EDITED);
        card.getCard().setOrder(dataBaseAdapter.getHighestCardOrderInStack(localStackId) + 1);
        long localCardId = dataBaseAdapter.createCardDirectly(accountId, card.getCard());
        card.getCard().setLocalId(localCardId);
        List<User> assignedUsers = card.getAssignedUsers();
        if (assignedUsers != null) {
            for (User assignedUser : assignedUsers) {
                dataBaseAdapter.createJoinCardWithUser(assignedUser.getLocalId(), localCardId, DBStatus.LOCAL_EDITED);
            }
        }
        List<Label> labels = card.getLabels();
        if (labels != null) {
            for (Label label : labels) {
                dataBaseAdapter.createJoinCardWithLabel(label.getLocalId(), localCardId, DBStatus.LOCAL_EDITED);
            }
        }
        if (card.getAttachments() != null) {
            for (Attachment attachment : card.getAttachments()) {
                if (attachment.getLocalId() == null) {
                    attachment.setCardId(localCardId);
                    dataBaseAdapter.createAttachment(accountId, attachment);
                }
            }
        }
        if (serverAdapter.hasInternetConnection()) {
            syncHelperFactory.create(serverAdapter, dataBaseAdapter, null).setResponseCallback(new ResponseCallback<>(account) {

                @Override
                public void onResponse(Boolean response) {
                    callback.onResponse(card);
                }

                @SuppressLint("MissingSuperCall")
                @Override
                public void onError(Throwable throwable) {
                    if (throwable.getClass() == DeckException.class && ((DeckException) throwable).getHint().equals(DeckException.Hint.DEPENDENCY_NOT_SYNCED_YET)) {
                        callback.onResponse(card);
                    } else {
                        callback.onError(throwable);
                    }
                }
            }).doUpSyncFor(new CardDataProvider(null, board, stack));
        } else {
            callback.onResponse(card);
        }
    });
}
Also used : Account(it.niedermann.nextcloud.deck.model.Account) JoinCardWithUser(it.niedermann.nextcloud.deck.model.JoinCardWithUser) User(it.niedermann.nextcloud.deck.model.User) CardDataProvider(it.niedermann.nextcloud.deck.persistence.sync.helpers.providers.CardDataProvider) Label(it.niedermann.nextcloud.deck.model.Label) Attachment(it.niedermann.nextcloud.deck.model.Attachment) FullStack(it.niedermann.nextcloud.deck.model.full.FullStack) DeckException(it.niedermann.nextcloud.deck.exceptions.DeckException) FullBoard(it.niedermann.nextcloud.deck.model.full.FullBoard) Board(it.niedermann.nextcloud.deck.model.Board) IResponseCallback(it.niedermann.nextcloud.deck.api.IResponseCallback) ResponseCallback(it.niedermann.nextcloud.deck.api.ResponseCallback) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AnyThread(androidx.annotation.AnyThread)

Example 2 with Label

use of it.niedermann.nextcloud.deck.model.Label in project nextcloud-deck by stefan-niedermann.

the class SyncManager method createAndAssignLabelToCard.

@AnyThread
private MutableLiveData<Label> createAndAssignLabelToCard(long accountId, @NonNull Label label, long localCardId, ServerAdapter serverAdapterToUse) {
    MutableLiveData<Label> liveData = new MutableLiveData<>();
    executor.submit(() -> {
        Account account = dataBaseAdapter.getAccountByIdDirectly(accountId);
        Board board = dataBaseAdapter.getBoardByLocalCardIdDirectly(localCardId);
        label.setAccountId(accountId);
        new DataPropagationHelper(serverAdapterToUse, dataBaseAdapter, executor).createEntity(new LabelDataProvider(null, board, null), label, new ResponseCallback<>(account) {

            @Override
            public void onResponse(Label response) {
                assignLabelToCard(response, dataBaseAdapter.getCardByLocalIdDirectly(accountId, localCardId));
                liveData.postValue(response);
            }

            @Override
            public void onError(Throwable throwable) {
                super.onError(throwable);
                assignLabelToCard(label, dataBaseAdapter.getCardByLocalIdDirectly(accountId, localCardId));
            }
        }, (entity, response) -> response.setBoardId(board.getLocalId()));
    });
    return liveData;
}
Also used : Account(it.niedermann.nextcloud.deck.model.Account) DataPropagationHelper(it.niedermann.nextcloud.deck.persistence.sync.helpers.DataPropagationHelper) FullBoard(it.niedermann.nextcloud.deck.model.full.FullBoard) Board(it.niedermann.nextcloud.deck.model.Board) Label(it.niedermann.nextcloud.deck.model.Label) MutableLiveData(androidx.lifecycle.MutableLiveData) LabelDataProvider(it.niedermann.nextcloud.deck.persistence.sync.helpers.providers.LabelDataProvider) AnyThread(androidx.annotation.AnyThread)

Example 3 with Label

use of it.niedermann.nextcloud.deck.model.Label in project nextcloud-deck by stefan-niedermann.

the class SyncManager method cloneBoard.

/**
 * 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}.
 *
 * @param cloneCards determines whether or not the cards in this {@link Board} shall be cloned or not
 *                   Does <strong>not</strong> clone any {@link Card} or {@link AccessControl} from the origin {@link Board}.
 */
@AnyThread
public void cloneBoard(long originAccountId, long originBoardLocalId, long targetAccountId, @ColorInt int targetBoardColor, boolean cloneCards, @NonNull IResponseCallback<FullBoard> callback) {
    executor.submit(() -> {
        Account originAccount = dataBaseAdapter.getAccountByIdDirectly(originAccountId);
        User newOwner = dataBaseAdapter.getUserByUidDirectly(originAccountId, originAccount.getUserName());
        if (newOwner == null) {
            callback.onError(new DeckException(DeckException.Hint.UNKNOWN_ACCOUNT_USER_ID, "User with Account-UID \"" + originAccount.getUserName() + "\" not found."));
            return;
        }
        FullBoard originalBoard = dataBaseAdapter.getFullBoardByLocalIdDirectly(originAccountId, originBoardLocalId);
        String newBoardTitleBaseName = originalBoard.getBoard().getTitle().trim();
        int newBoardTitleCopyIndex = 0;
        // already a copy?
        String regex = " \\(copy [0-9]+\\)$";
        Pattern pattern = Pattern.compile(regex);
        Matcher matcher = pattern.matcher(originalBoard.getBoard().getTitle());
        if (matcher.find()) {
            String found = matcher.group();
            newBoardTitleBaseName = newBoardTitleBaseName.substring(0, newBoardTitleBaseName.length() - found.length());
            Matcher indexMatcher = Pattern.compile("[0-9]+").matcher(found);
            // noinspection ResultOfMethodCallIgnored
            indexMatcher.find();
            String oldIndexString = indexMatcher.group();
            newBoardTitleCopyIndex = Integer.parseInt(oldIndexString);
        }
        String newBoardTitle;
        do {
            newBoardTitleCopyIndex++;
            newBoardTitle = newBoardTitleBaseName + " (copy " + newBoardTitleCopyIndex + ")";
        } while (dataBaseAdapter.getBoardForAccountByNameDirectly(targetAccountId, newBoardTitle) != null);
        originalBoard.setAccountId(targetAccountId);
        originalBoard.setId(null);
        originalBoard.setLocalId(null);
        originalBoard.getBoard().setTitle(newBoardTitle);
        originalBoard.getBoard().setColor(String.format("%06X", 0xFFFFFF & targetBoardColor));
        originalBoard.getBoard().setOwnerId(newOwner.getLocalId());
        originalBoard.setStatusEnum(DBStatus.LOCAL_EDITED);
        originalBoard.setOwner(newOwner);
        long newBoardId = dataBaseAdapter.createBoardDirectly(originAccountId, originalBoard.getBoard());
        originalBoard.setLocalId(newBoardId);
        boolean isSameAccount = targetAccountId == originAccountId;
        if (isSameAccount) {
            List<AccessControl> aclList = originalBoard.getParticipants();
            for (AccessControl acl : aclList) {
                acl.setLocalId(null);
                acl.setId(null);
                acl.setBoardId(newBoardId);
                dataBaseAdapter.createAccessControl(targetAccountId, acl);
            }
        }
        Map<Long, Long> oldToNewLabelIdsDictionary = new HashMap<>();
        for (Label label : originalBoard.getLabels()) {
            Long oldLocalId = label.getLocalId();
            label.setLocalId(null);
            label.setId(null);
            label.setAccountId(targetAccountId);
            label.setStatusEnum(DBStatus.LOCAL_EDITED);
            label.setBoardId(newBoardId);
            long newLocalId = dataBaseAdapter.createLabelDirectly(targetAccountId, label);
            oldToNewLabelIdsDictionary.put(oldLocalId, newLocalId);
        }
        List<Stack> oldStacks = originalBoard.getStacks();
        for (Stack stack : oldStacks) {
            Long oldStackId = stack.getLocalId();
            stack.setLocalId(null);
            stack.setId(null);
            stack.setStatusEnum(DBStatus.LOCAL_EDITED);
            stack.setAccountId(targetAccountId);
            stack.setBoardId(newBoardId);
            long createdStackId = dataBaseAdapter.createStack(targetAccountId, stack);
            if (cloneCards) {
                List<FullCard> oldCards = dataBaseAdapter.getFullCardsForStackDirectly(originAccountId, oldStackId, null);
                for (FullCard oldCard : oldCards) {
                    Card newCard = oldCard.getCard();
                    newCard.setId(null);
                    newCard.setUserId(newOwner.getLocalId());
                    newCard.setLocalId(null);
                    newCard.setStackId(createdStackId);
                    newCard.setAccountId(targetAccountId);
                    newCard.setStatusEnum(DBStatus.LOCAL_EDITED);
                    long createdCardId = dataBaseAdapter.createCardDirectly(targetAccountId, newCard);
                    if (oldCard.getLabels() != null) {
                        for (Label oldLabel : oldCard.getLabels()) {
                            Long newLabelId = oldToNewLabelIdsDictionary.get(oldLabel.getLocalId());
                            if (newLabelId != null) {
                                dataBaseAdapter.createJoinCardWithLabel(newLabelId, createdCardId, DBStatus.LOCAL_EDITED);
                            } else
                                DeckLog.error("ID of created Label is null! Skipping assignment of ", oldLabel.getTitle(), "…");
                        }
                    }
                    if (isSameAccount && oldCard.getAssignedUsers() != null) {
                        for (User assignedUser : oldCard.getAssignedUsers()) {
                            dataBaseAdapter.createJoinCardWithUser(assignedUser.getLocalId(), createdCardId, DBStatus.LOCAL_EDITED);
                        }
                    }
                }
            }
        }
        if (serverAdapter.hasInternetConnection()) {
            Account targetAccount = dataBaseAdapter.getAccountByIdDirectly(targetAccountId);
            ServerAdapter serverAdapterToUse = this.serverAdapter;
            if (originAccountId != targetAccountId) {
                serverAdapterToUse = new ServerAdapter(appContext, targetAccount.getName());
            }
            syncHelperFactory.create(serverAdapterToUse, dataBaseAdapter, null).setResponseCallback(new ResponseCallback<>(targetAccount) {

                @Override
                public void onResponse(Boolean response) {
                    callback.onResponse(dataBaseAdapter.getFullBoardByLocalIdDirectly(targetAccountId, newBoardId));
                }

                @SuppressLint("MissingSuperCall")
                @Override
                public void onError(Throwable throwable) {
                    callback.onError(throwable);
                }
            }).doUpSyncFor(new BoardWithStacksAndLabelsUpSyncDataProvider(dataBaseAdapter.getFullBoardByLocalIdDirectly(targetAccountId, newBoardId)));
        } else {
            callback.onResponse(dataBaseAdapter.getFullBoardByLocalIdDirectly(targetAccountId, newBoardId));
        }
    });
}
Also used : Account(it.niedermann.nextcloud.deck.model.Account) ServerAdapter(it.niedermann.nextcloud.deck.persistence.sync.adapters.ServerAdapter) JoinCardWithUser(it.niedermann.nextcloud.deck.model.JoinCardWithUser) User(it.niedermann.nextcloud.deck.model.User) Matcher(java.util.regex.Matcher) HashMap(java.util.HashMap) Label(it.niedermann.nextcloud.deck.model.Label) AccessControl(it.niedermann.nextcloud.deck.model.AccessControl) DeckException(it.niedermann.nextcloud.deck.exceptions.DeckException) FullBoard(it.niedermann.nextcloud.deck.model.full.FullBoard) IResponseCallback(it.niedermann.nextcloud.deck.api.IResponseCallback) ResponseCallback(it.niedermann.nextcloud.deck.api.ResponseCallback) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Pattern(java.util.regex.Pattern) BoardWithStacksAndLabelsUpSyncDataProvider(it.niedermann.nextcloud.deck.persistence.sync.helpers.providers.partial.BoardWithStacksAndLabelsUpSyncDataProvider) SuppressLint(android.annotation.SuppressLint) Stack(it.niedermann.nextcloud.deck.model.Stack) FullStack(it.niedermann.nextcloud.deck.model.full.FullStack) Card(it.niedermann.nextcloud.deck.model.Card) FullCard(it.niedermann.nextcloud.deck.model.full.FullCard) FilterWidgetCard(it.niedermann.nextcloud.deck.model.widget.filter.dto.FilterWidgetCard) FullCard(it.niedermann.nextcloud.deck.model.full.FullCard) AnyThread(androidx.annotation.AnyThread)

Example 4 with Label

use of it.niedermann.nextcloud.deck.model.Label in project nextcloud-deck by stefan-niedermann.

the class CardDataProvider method goDeeperForUpSync.

@Override
public void goDeeperForUpSync(SyncHelper syncHelper, ServerAdapter serverAdapter, DataBaseAdapter dataBaseAdapter, ResponseCallback<Boolean> callback) {
    FullStack stack;
    Board board;
    List<JoinCardWithLabel> changedLabels;
    if (this.stack == null) {
        changedLabels = dataBaseAdapter.getAllChangedLabelJoins();
    } else {
        changedLabels = dataBaseAdapter.getAllChangedLabelJoinsForStack(this.stack.getLocalId());
    }
    Account account = callback.getAccount();
    for (JoinCardWithLabel changedLabelLocal : changedLabels) {
        Card card = dataBaseAdapter.getCardByLocalIdDirectly(account.getId(), changedLabelLocal.getCardId());
        if (card == null) {
            // https://github.com/stefan-niedermann/nextcloud-deck/issues/683#issuecomment-759116820
            continue;
        }
        if (this.stack == null) {
            stack = dataBaseAdapter.getFullStackByLocalIdDirectly(card.getStackId());
        } else {
            stack = this.stack;
        }
        if (this.board == null) {
            board = dataBaseAdapter.getBoardByLocalIdDirectly(stack.getStack().getBoardId());
        } else {
            board = this.board;
        }
        JoinCardWithLabel changedLabel = dataBaseAdapter.getAllChangedLabelJoinsWithRemoteIDs(changedLabelLocal.getCardId(), changedLabelLocal.getLabelId());
        if (changedLabel.getStatusEnum() == DBStatus.LOCAL_DELETED) {
            if (changedLabel.getLabelId() == null || changedLabel.getCardId() == null) {
                dataBaseAdapter.deleteJoinedLabelForCardPhysicallyByRemoteIDs(account.getId(), changedLabel.getCardId(), changedLabel.getLabelId());
            } else {
                serverAdapter.unassignLabelFromCard(board.getId(), stack.getId(), changedLabel.getCardId(), changedLabel.getLabelId(), new ResponseCallback<>(account) {

                    @Override
                    public void onResponse(Void response) {
                        dataBaseAdapter.deleteJoinedLabelForCardPhysicallyByRemoteIDs(account.getId(), changedLabel.getCardId(), changedLabel.getLabelId());
                    }
                });
            }
        } else if (changedLabel.getStatusEnum() == DBStatus.LOCAL_EDITED) {
            if (changedLabel.getLabelId() == null || changedLabel.getCardId() == null) {
                // Sync next time, the card should be available on server then.
                continue;
            } else {
                serverAdapter.assignLabelToCard(board.getId(), stack.getId(), changedLabel.getCardId(), changedLabel.getLabelId(), new ResponseCallback<>(account) {

                    @Override
                    public void onResponse(Void response) {
                        Label label = dataBaseAdapter.getLabelByRemoteIdDirectly(account.getId(), changedLabel.getLabelId());
                        dataBaseAdapter.setStatusForJoinCardWithLabel(card.getLocalId(), label.getLocalId(), DBStatus.UP_TO_DATE.getId());
                    }
                });
            }
        }
    }
    List<JoinCardWithUser> changedUsers;
    if (this.stack == null) {
        changedUsers = dataBaseAdapter.getAllChangedUserJoinsWithRemoteIDs();
    } else {
        changedUsers = dataBaseAdapter.getAllChangedUserJoinsWithRemoteIDsForStack(this.stack.getLocalId());
    }
    for (JoinCardWithUser changedUser : changedUsers) {
        // not already known to server?
        if (changedUser.getCardId() == null) {
            // skip for now
            continue;
        }
        Card card = dataBaseAdapter.getCardByRemoteIdDirectly(account.getId(), changedUser.getCardId());
        if (card == null) {
            // this shouldn't actually happen, but does as it seems. the card cant be found by remote id (exists!) and account-ID.
            continue;
        }
        if (this.stack == null) {
            stack = dataBaseAdapter.getFullStackByLocalIdDirectly(card.getStackId());
        } else {
            stack = this.stack;
        }
        if (this.board == null) {
            board = dataBaseAdapter.getBoardByLocalIdDirectly(stack.getStack().getBoardId());
        } else {
            board = this.board;
        }
        User user = dataBaseAdapter.getUserByLocalIdDirectly(changedUser.getUserId());
        if (changedUser.getStatusEnum() == DBStatus.LOCAL_DELETED) {
            serverAdapter.unassignUserFromCard(board.getId(), stack.getId(), changedUser.getCardId(), user.getUid(), new ResponseCallback<>(account) {

                @Override
                public void onResponse(Void response) {
                    dataBaseAdapter.deleteJoinedUserForCardPhysicallyByRemoteIDs(account.getId(), changedUser.getCardId(), user.getUid());
                }
            });
        } else if (changedUser.getStatusEnum() == DBStatus.LOCAL_EDITED) {
            serverAdapter.assignUserToCard(board.getId(), stack.getId(), changedUser.getCardId(), user.getUid(), new ResponseCallback<>(account) {

                @Override
                public void onResponse(Void response) {
                    dataBaseAdapter.setStatusForJoinCardWithUser(card.getLocalId(), user.getLocalId(), DBStatus.UP_TO_DATE.getId());
                }
            });
        }
    }
    List<Attachment> attachments;
    if (this.stack == null) {
        attachments = dataBaseAdapter.getLocallyChangedAttachmentsDirectly(account.getId());
    } else {
        attachments = dataBaseAdapter.getLocallyChangedAttachmentsForStackDirectly(this.stack.getLocalId());
    }
    for (Attachment attachment : attachments) {
        FullCard card = dataBaseAdapter.getFullCardByLocalIdDirectly(account.getId(), attachment.getCardId());
        stack = dataBaseAdapter.getFullStackByLocalIdDirectly(card.getCard().getStackId());
        board = dataBaseAdapter.getBoardByLocalIdDirectly(stack.getStack().getBoardId());
        syncHelper.doUpSyncFor(new AttachmentDataProvider(this, board, stack.getStack(), card, Collections.singletonList(attachment)));
    }
    List<Card> cardsWithChangedComments;
    if (this.stack == null) {
        cardsWithChangedComments = dataBaseAdapter.getCardsWithLocallyChangedCommentsDirectly(account.getId());
    } else {
        cardsWithChangedComments = dataBaseAdapter.getCardsWithLocallyChangedCommentsForStackDirectly(this.stack.getLocalId());
    }
    for (Card card : cardsWithChangedComments) {
        syncHelper.doUpSyncFor(new DeckCommentsDataProvider(this, card));
    }
    callback.onResponse(Boolean.TRUE);
}
Also used : Account(it.niedermann.nextcloud.deck.model.Account) User(it.niedermann.nextcloud.deck.model.User) JoinCardWithUser(it.niedermann.nextcloud.deck.model.JoinCardWithUser) JoinCardWithLabel(it.niedermann.nextcloud.deck.model.JoinCardWithLabel) Label(it.niedermann.nextcloud.deck.model.Label) Attachment(it.niedermann.nextcloud.deck.model.Attachment) FullStack(it.niedermann.nextcloud.deck.model.full.FullStack) Card(it.niedermann.nextcloud.deck.model.Card) FullCard(it.niedermann.nextcloud.deck.model.full.FullCard) Board(it.niedermann.nextcloud.deck.model.Board) FullCard(it.niedermann.nextcloud.deck.model.full.FullCard) ResponseCallback(it.niedermann.nextcloud.deck.api.ResponseCallback) JoinCardWithUser(it.niedermann.nextcloud.deck.model.JoinCardWithUser) JoinCardWithLabel(it.niedermann.nextcloud.deck.model.JoinCardWithLabel)

Example 5 with Label

use of it.niedermann.nextcloud.deck.model.Label in project nextcloud-deck by stefan-niedermann.

the class DataBaseAdapter method getCardsForFilterWidget.

public List<FilterWidgetCard> getCardsForFilterWidget(@NonNull Integer filterWidgetId) {
    final FilterWidget filterWidget = getFilterWidgetByIdDirectly(filterWidgetId);
    final FilterInformation filter = new FilterInformation();
    final Set<FullCard> cardsResult = new HashSet<>();
    if (filterWidget.getDueType() != null) {
        filter.setDueType(filterWidget.getDueType());
    } else
        filter.setDueType(EDueType.NO_FILTER);
    if (filterWidget.getAccounts().isEmpty()) {
        cardsResult.addAll(db.getCardDao().getFilteredFullCardsForStackDirectly(getQueryForFilter(filter, null, null)));
    } else {
        for (FilterWidgetAccount account : filterWidget.getAccounts()) {
            filter.setNoAssignedUser(account.isIncludeNoUser());
            final List<User> users = new ArrayList<>();
            if (!account.getUsers().isEmpty()) {
                for (FilterWidgetUser user : account.getUsers()) {
                    User u = new User();
                    u.setLocalId(user.getUserId());
                    users.add(u);
                }
            }
            filter.setUsers(users);
            filter.setNoAssignedProject(account.isIncludeNoProject());
            final List<OcsProject> projects = new ArrayList<>();
            if (!account.getProjects().isEmpty()) {
                for (FilterWidgetProject project : account.getProjects()) {
                    OcsProject u = new OcsProject();
                    u.setLocalId(project.getProjectId());
                    projects.add(u);
                }
            }
            filter.setProjects(projects);
            if (!account.getBoards().isEmpty()) {
                for (FilterWidgetBoard board : account.getBoards()) {
                    filter.setNoAssignedLabel(board.isIncludeNoLabel());
                    final List<Long> stacks;
                    for (FilterWidgetLabel label : board.getLabels()) {
                        Label l = new Label();
                        l.setLocalId(label.getLabelId());
                        filter.addLabel(l);
                    }
                    if (board.getStacks().isEmpty()) {
                        stacks = db.getStackDao().getLocalStackIdsByLocalBoardIdDirectly(board.getBoardId());
                    } else {
                        stacks = new ArrayList<>();
                        for (FilterWidgetStack stack : board.getStacks()) {
                            stacks.add(stack.getStackId());
                        }
                    }
                    cardsResult.addAll(db.getCardDao().getFilteredFullCardsForStackDirectly(getQueryForFilter(filter, Collections.singletonList(account.getAccountId()), stacks)));
                }
            } else {
                cardsResult.addAll(db.getCardDao().getFilteredFullCardsForStackDirectly(getQueryForFilter(filter, Collections.singletonList(account.getAccountId()), null)));
            }
        }
    }
    handleWidgetTypeExtras(filterWidget, cardsResult);
    filterRelationsForCard(cardsResult);
    final List<FilterWidgetCard> result = new ArrayList<>(cardsResult.size());
    final Map<Long, Board> boardCache = new HashMap<>();
    final Map<Long, Stack> stackCache = new HashMap<>();
    for (FullCard fullCard : cardsResult) {
        final Long stackId = fullCard.getCard().getStackId();
        Stack stack = stackCache.get(stackId);
        if (stack == null) {
            stack = db.getStackDao().getStackByLocalIdDirectly(stackId);
            stackCache.put(stackId, stack);
        }
        Board board = boardCache.get(stack.getBoardId());
        if (board == null) {
            board = db.getBoardDao().getBoardByLocalIdDirectly(stackId);
            boardCache.put(stackId, board);
        }
        result.add(new FilterWidgetCard(fullCard, stack, board));
    }
    return result;
}
Also used : JoinCardWithUser(it.niedermann.nextcloud.deck.model.JoinCardWithUser) FilterWidgetUser(it.niedermann.nextcloud.deck.model.widget.filter.FilterWidgetUser) User(it.niedermann.nextcloud.deck.model.User) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) JoinCardWithLabel(it.niedermann.nextcloud.deck.model.JoinCardWithLabel) Label(it.niedermann.nextcloud.deck.model.Label) FilterWidgetLabel(it.niedermann.nextcloud.deck.model.widget.filter.FilterWidgetLabel) JoinBoardWithLabel(it.niedermann.nextcloud.deck.model.JoinBoardWithLabel) OcsProject(it.niedermann.nextcloud.deck.model.ocs.projects.OcsProject) FilterWidgetStack(it.niedermann.nextcloud.deck.model.widget.filter.FilterWidgetStack) FilterWidgetAccount(it.niedermann.nextcloud.deck.model.widget.filter.FilterWidgetAccount) FilterInformation(it.niedermann.nextcloud.deck.model.internal.FilterInformation) UserInBoard(it.niedermann.nextcloud.deck.model.relations.UserInBoard) FilterWidgetBoard(it.niedermann.nextcloud.deck.model.widget.filter.FilterWidgetBoard) FullBoard(it.niedermann.nextcloud.deck.model.full.FullBoard) Board(it.niedermann.nextcloud.deck.model.Board) FilterWidgetCard(it.niedermann.nextcloud.deck.model.widget.filter.dto.FilterWidgetCard) FilterWidget(it.niedermann.nextcloud.deck.model.widget.filter.FilterWidget) HashSet(java.util.HashSet) FilterWidgetBoard(it.niedermann.nextcloud.deck.model.widget.filter.FilterWidgetBoard) FilterWidgetUser(it.niedermann.nextcloud.deck.model.widget.filter.FilterWidgetUser) FilterWidgetProject(it.niedermann.nextcloud.deck.model.widget.filter.FilterWidgetProject) FilterWidgetLabel(it.niedermann.nextcloud.deck.model.widget.filter.FilterWidgetLabel) Stack(it.niedermann.nextcloud.deck.model.Stack) FullStack(it.niedermann.nextcloud.deck.model.full.FullStack) FilterWidgetStack(it.niedermann.nextcloud.deck.model.widget.filter.FilterWidgetStack) FullCard(it.niedermann.nextcloud.deck.model.full.FullCard)

Aggregations

Label (it.niedermann.nextcloud.deck.model.Label)18 User (it.niedermann.nextcloud.deck.model.User)9 FullBoard (it.niedermann.nextcloud.deck.model.full.FullBoard)9 Board (it.niedermann.nextcloud.deck.model.Board)8 FullStack (it.niedermann.nextcloud.deck.model.full.FullStack)8 Account (it.niedermann.nextcloud.deck.model.Account)7 FullCard (it.niedermann.nextcloud.deck.model.full.FullCard)7 AnyThread (androidx.annotation.AnyThread)6 JoinCardWithUser (it.niedermann.nextcloud.deck.model.JoinCardWithUser)6 IResponseCallback (it.niedermann.nextcloud.deck.api.IResponseCallback)4 ResponseCallback (it.niedermann.nextcloud.deck.api.ResponseCallback)4 Card (it.niedermann.nextcloud.deck.model.Card)4 ArrayList (java.util.ArrayList)4 AccessControl (it.niedermann.nextcloud.deck.model.AccessControl)3 Attachment (it.niedermann.nextcloud.deck.model.Attachment)3 Stack (it.niedermann.nextcloud.deck.model.Stack)3 FilterWidgetCard (it.niedermann.nextcloud.deck.model.widget.filter.dto.FilterWidgetCard)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 SuppressLint (android.annotation.SuppressLint)2 SQLiteConstraintException (android.database.sqlite.SQLiteConstraintException)2