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);
}
});
}
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;
}
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));
}
});
}
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);
}
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;
}
Aggregations