Search in sources :

Example 1 with IssueDTO

use of com.bbva.arq.devops.ae.mirrorgate.core.dto.IssueDTO in project mirrorgate-jira-stories-collector by BBVA.

the class JiraIssuesServiceImpl method getById.

public Pageable<IssueDTO> getById(List<Long> ids) {
    final StringBuilder sb = new StringBuilder(200);
    final Counter counter = new Counter();
    return (() -> {
        int firstItem = counter.get();
        if (counter.get() >= ids.size()) {
            return new ArrayList<>();
        }
        for (int i = 0; i < PAGE_SIZE && counter.get() < ids.size(); counter.inc(), i++) {
            if (i > 0) {
                sb.append(',');
            }
            sb.append(ids.get(counter.get()));
        }
        String query = String.format(ISSUES_BY_ID_QUERY_PATTERN, sb.toString());
        sb.delete(0, sb.length());
        LOGGER.info("-> Running Jira Query: " + query);
        try {
            Promise<SearchResult> results = client.searchJql(query);
            return StreamSupport.stream(results.claim().getIssues().spliterator(), false).map(getIssueMapper()).collect(Collectors.toList());
        } catch (RestClientException e) {
            LOGGER.warn("Exception", e);
            int statusCode = e.getStatusCode().isPresent() ? e.getStatusCode().get() : 0;
            if (statusCode == 401) {
                LOGGER.error("Error 401 connecting to JIRA server, your credentials are probably wrong. Note: Ensure you are using JIRA user name not your email address.");
                throw e;
            } else if (statusCode == 400) {
                if (ids.size() == 1) {
                    return new ArrayList<>();
                } else {
                    LOGGER.warn("Error 400 - Some issues where not found {}, keep on", ids);
                    LOGGER.warn(e.getMessage());
                    //Falling back to per issue invocation if one was not found... Why Jira o why...
                    List<IssueDTO> result = new ArrayList<>(PAGE_SIZE);
                    for (int i = firstItem; i < counter.get(); i++) {
                        result.addAll(getById(Arrays.asList(ids.get(i))).nextPage());
                    }
                    return result;
                }
            } else {
                LOGGER.error("No result was available from Jira unexpectedly - defaulting to blank response. The reason for this fault is the following:" + e.getCause());
                throw e;
            }
        }
    });
}
Also used : Counter(com.bbva.arq.devops.ae.mirrorgate.collectors.jira.support.Counter) ArrayList(java.util.ArrayList) RestClientException(com.atlassian.jira.rest.client.api.RestClientException) IssueDTO(com.bbva.arq.devops.ae.mirrorgate.core.dto.IssueDTO) SearchResult(com.atlassian.jira.rest.client.api.domain.SearchResult)

Example 2 with IssueDTO

use of com.bbva.arq.devops.ae.mirrorgate.core.dto.IssueDTO in project mirrorgate-jira-stories-collector by BBVA.

the class Main method getSprintsThatNeedUpdating.

private List<SprintDTO> getSprintsThatNeedUpdating() {
    final List<SprintDTO> sprints = sprintApi.getSprintSamples();
    final List<Long> ids = new ArrayList<>();
    final Map<Long, SprintDTO> idToSprint = new HashMap<>(ids.size() * 2);
    sprints.forEach((s) -> {
        for (IssueDTO issue : s.getIssues()) {
            idToSprint.put(issue.getId(), s);
            ids.add(issue.getId());
        }
    });
    Pageable<IssueDTO> samples = getIssuesByIdAndDeleteNotPresent(ids);
    List<SprintDTO> toUpdate = new ArrayList<>();
    List<IssueDTO> issues;
    while ((issues = samples.nextPage()).size() > 0) {
        LOGGER.info("-> Checking " + issues.get(0));
        issues.forEach((i) -> {
            SprintDTO current = i.getSprint();
            if (current == null) {
                toUpdate.add(idToSprint.get(i.getId()));
            } else if (!current.equals(idToSprint.get(i.getId()))) {
                toUpdate.add(i.getSprint());
            }
        });
    }
    LOGGER.info("-> Needs updating: " + toUpdate);
    return toUpdate;
}
Also used : IssueDTO(com.bbva.arq.devops.ae.mirrorgate.core.dto.IssueDTO) SprintDTO(com.bbva.arq.devops.ae.mirrorgate.core.dto.SprintDTO)

Aggregations

IssueDTO (com.bbva.arq.devops.ae.mirrorgate.core.dto.IssueDTO)2 RestClientException (com.atlassian.jira.rest.client.api.RestClientException)1 SearchResult (com.atlassian.jira.rest.client.api.domain.SearchResult)1 Counter (com.bbva.arq.devops.ae.mirrorgate.collectors.jira.support.Counter)1 SprintDTO (com.bbva.arq.devops.ae.mirrorgate.core.dto.SprintDTO)1 ArrayList (java.util.ArrayList)1