Search in sources :

Example 1 with TrelloCard

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;
}
Also used : JsonParseException(com.google.gson.JsonParseException) TypeToken(com.google.gson.reflect.TypeToken) Tag(com.intellij.util.xmlb.annotations.Tag) URISyntaxException(java.net.URISyntaxException) BaseRepository(com.intellij.tasks.impl.BaseRepository) HttpUriRequest(org.apache.http.client.methods.HttpUriRequest) TrelloList(com.intellij.tasks.trello.model.TrelloList) ContainerUtil(com.intellij.util.containers.ContainerUtil) HttpRequestWrapper(org.apache.http.client.methods.HttpRequestWrapper) EntityUtils(org.apache.http.util.EntityUtils) TrelloBoard(com.intellij.tasks.trello.model.TrelloBoard) HashSet(java.util.HashSet) Comparing(com.intellij.openapi.util.Comparing) HttpClient(org.apache.http.client.HttpClient) URI(java.net.URI) Logger(com.intellij.openapi.diagnostic.Logger) TaskResponseUtil(com.intellij.tasks.impl.httpclient.TaskResponseUtil) URIBuilder(org.apache.http.client.utils.URIBuilder) StringUtil(com.intellij.openapi.util.text.StringUtil) GsonMultipleObjectsDeserializer(com.intellij.tasks.impl.httpclient.TaskResponseUtil.GsonMultipleObjectsDeserializer) TaskRepositoryType(com.intellij.tasks.TaskRepositoryType) Set(java.util.Set) IOException(java.io.IOException) GsonSingleObjectDeserializer(com.intellij.tasks.impl.httpclient.TaskResponseUtil.GsonSingleObjectDeserializer) org.apache.http(org.apache.http) CustomTaskState(com.intellij.tasks.CustomTaskState) Task(com.intellij.tasks.Task) TaskBundle(com.intellij.tasks.TaskBundle) NewBaseRepositoryImpl(com.intellij.tasks.impl.httpclient.NewBaseRepositoryImpl) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) HttpPut(org.apache.http.client.methods.HttpPut) HttpGet(org.apache.http.client.methods.HttpGet) HttpContext(org.apache.http.protocol.HttpContext) Function(com.intellij.util.Function) ObjectUtils(com.intellij.util.ObjectUtils) TrelloUser(com.intellij.tasks.trello.model.TrelloUser) ResponseHandler(org.apache.http.client.ResponseHandler) NotNull(org.jetbrains.annotations.NotNull) Collections(java.util.Collections) Condition(com.intellij.openapi.util.Condition) TrelloCard(com.intellij.tasks.trello.model.TrelloCard) TrelloCard(com.intellij.tasks.trello.model.TrelloCard) URIBuilder(org.apache.http.client.utils.URIBuilder) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with TrelloCard

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();
}
Also used : TrelloList(com.intellij.tasks.trello.model.TrelloList) TrelloCard(com.intellij.tasks.trello.model.TrelloCard) HashSet(java.util.HashSet) CustomTaskState(com.intellij.tasks.CustomTaskState) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

CustomTaskState (com.intellij.tasks.CustomTaskState)2 TrelloCard (com.intellij.tasks.trello.model.TrelloCard)2 TrelloList (com.intellij.tasks.trello.model.TrelloList)2 HashSet (java.util.HashSet)2 NotNull (org.jetbrains.annotations.NotNull)2 JsonParseException (com.google.gson.JsonParseException)1 TypeToken (com.google.gson.reflect.TypeToken)1 Logger (com.intellij.openapi.diagnostic.Logger)1 Comparing (com.intellij.openapi.util.Comparing)1 Condition (com.intellij.openapi.util.Condition)1 StringUtil (com.intellij.openapi.util.text.StringUtil)1 Task (com.intellij.tasks.Task)1 TaskBundle (com.intellij.tasks.TaskBundle)1 TaskRepositoryType (com.intellij.tasks.TaskRepositoryType)1 BaseRepository (com.intellij.tasks.impl.BaseRepository)1 NewBaseRepositoryImpl (com.intellij.tasks.impl.httpclient.NewBaseRepositoryImpl)1 TaskResponseUtil (com.intellij.tasks.impl.httpclient.TaskResponseUtil)1 GsonMultipleObjectsDeserializer (com.intellij.tasks.impl.httpclient.TaskResponseUtil.GsonMultipleObjectsDeserializer)1 GsonSingleObjectDeserializer (com.intellij.tasks.impl.httpclient.TaskResponseUtil.GsonSingleObjectDeserializer)1 TrelloBoard (com.intellij.tasks.trello.model.TrelloBoard)1