use of com.intellij.tasks.trello.model.TrelloCard in project intellij-community by JetBrains.
the class TrelloRepository method fetchCards.
@NotNull
public List<TrelloCard> fetchCards(int limit, boolean withClosed) throws Exception {
boolean fromList = false;
// choose most appropriate card provider
String baseUrl;
if (myCurrentList != null && myCurrentList != UNSPECIFIED_LIST) {
baseUrl = getRestApiUrl("lists", myCurrentList.getId(), "cards");
fromList = true;
} else if (myCurrentBoard != null && myCurrentBoard != UNSPECIFIED_BOARD) {
baseUrl = getRestApiUrl("boards", myCurrentBoard.getId(), "cards");
} else if (myCurrentUser != null) {
baseUrl = getRestApiUrl("members", "me", "cards");
} else {
throw new IllegalStateException("Not configured");
}
final URIBuilder fetchCardUrl = new URIBuilder(baseUrl).addParameter("fields", TrelloCard.REQUIRED_FIELDS).addParameter("limit", String.valueOf(limit));
// 'visible' filter for some reason is not supported for lists
if (withClosed || fromList) {
fetchCardUrl.addParameter("filter", "all");
} else {
fetchCardUrl.addParameter("filter", "visible");
}
List<TrelloCard> cards = makeRequestAndDeserializeJsonResponse(fetchCardUrl.build(), TrelloUtil.LIST_OF_CARDS_TYPE);
LOG.debug("Total " + cards.size() + " cards downloaded");
if (!myIncludeAllCards) {
cards = ContainerUtil.filter(cards, card -> card.getIdMembers().contains(myCurrentUser.getId()));
LOG.debug("Total " + cards.size() + " cards after filtering");
}
if (!cards.isEmpty()) {
if (fromList) {
baseUrl = getRestApiUrl("boards", cards.get(0).getIdBoard(), "cards");
}
// fix for IDEA-111470 and IDEA-111475
// Select IDs of visible cards, e.d. cards that either archived explicitly, belong to archived list or closed board.
// This information can't be extracted from single card description, because its 'closed' field
// reflects only the card state and doesn't show state of parental list and board.
// NOTE: According to Trello REST API "filter=visible" parameter may be used only when fetching cards for
// particular board or user.
final URIBuilder visibleCardsUrl = new URIBuilder(baseUrl).addParameter("filter", "visible").addParameter("fields", "none");
final List<TrelloCard> visibleCards = makeRequestAndDeserializeJsonResponse(visibleCardsUrl.build(), TrelloUtil.LIST_OF_CARDS_TYPE);
LOG.debug("Total " + visibleCards.size() + " visible cards");
final Set<String> visibleCardsIDs = ContainerUtil.map2Set(visibleCards, card -> card.getId());
for (TrelloCard card : cards) {
card.setVisible(visibleCardsIDs.contains(card.getId()));
}
}
return cards;
}
use of com.intellij.tasks.trello.model.TrelloCard in project intellij-community by JetBrains.
the class TrelloRepository method getAvailableTaskStates.
@NotNull
@Override
public Set<CustomTaskState> getAvailableTaskStates(@NotNull Task task) throws Exception {
final TrelloCard card = fetchCardById(task.getId());
if (card != null) {
final List<TrelloList> lists = fetchBoardLists(card.getIdBoard());
final Set<CustomTaskState> result = new HashSet<>();
for (TrelloList list : lists) {
if (!list.getId().equals(card.getIdList())) {
result.add(new CustomTaskState(list.getId(), list.getName()));
}
}
return result;
}
return Collections.emptySet();
}
Aggregations