Skip to content

Commit

Permalink
ADM-729[backend]feat: can get all history for card
Browse files Browse the repository at this point in the history
  • Loading branch information
BoBoDai committed Jan 8, 2024
1 parent f8c9ef3 commit ba82f79
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 40 deletions.
7 changes: 3 additions & 4 deletions backend/src/main/java/heartbeat/client/JiraFeignClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,9 @@ StatusSelfDTO getColumnStatusCategory(URI baseUrl, @PathVariable String statusNu
String getJiraCards(URI baseUrl, @PathVariable String boardId, @PathVariable int queryCount,
@PathVariable int startAt, @PathVariable String jql, @RequestHeader String authorization);

@Cacheable(cacheNames = "jiraActivityFeed", key = "#jiraCardKey")
@GetMapping(path = "/rest/internal/2/issue/{jiraCardKey}/activityfeed")
CardHistoryResponseDTO getJiraCardHistory(URI baseUrl, @PathVariable String jiraCardKey,
@RequestHeader String authorization);
@GetMapping(path = "/rest/internal/2/issue/{jiraCardKey}/activityfeed?startAt={startAt}&maxResults={queryCount}")
CardHistoryResponseDTO getJiraCardHistory(URI baseUrl, @PathVariable String jiraCardKey, @PathVariable int startAt,
@PathVariable int queryCount, @RequestHeader String authorization);

@Cacheable(cacheNames = "targetField", key = "#projectKey")
@GetMapping(path = "/rest/api/2/issue/createmeta?projectKeys={projectKey}&expand=projects.issuetypes.fields")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
@AllArgsConstructor
public class CardHistoryResponseDTO implements Serializable {

private Boolean isLast;

private List<HistoryDetail> items;

}
Original file line number Diff line number Diff line change
Expand Up @@ -417,8 +417,7 @@ private String parseJiraJql(BoardType boardType, List<String> doneColumns, Board
private List<String> getAssigneeSet(URI baseUrl, JiraCard jiraCard, String jiraToken) {
log.info("Start to get jira card history, card key: {}", jiraCard.getKey());
log.info("[Jira verify History] Start to get jira card history, card key: {}", jiraCard.getKey());
CardHistoryResponseDTO cardHistoryResponseDTO = jiraFeignClient.getJiraCardHistory(baseUrl, jiraCard.getKey(),
jiraToken);
CardHistoryResponseDTO cardHistoryResponseDTO = getCardAllHistory(baseUrl, jiraCard.getKey(), 0, jiraToken);
log.info("[Jira verify History] Successfully get jira card history, card key: {}, card history items size: {}",
jiraCard.getKey(), cardHistoryResponseDTO.getItems().size());

Expand Down Expand Up @@ -481,7 +480,7 @@ private List<JiraCardDTO> getRealDoneCards(StoryPointsAndCycleTimeRequest reques

for (JiraCard allDoneCard : allDoneCards) {
log.info("[Jira Service History] Start to get jira card history,card key: {}", allDoneCard.getKey());
CardHistoryResponseDTO jiraCardHistory = jiraFeignClient.getJiraCardHistory(baseUrl, allDoneCard.getKey(),
CardHistoryResponseDTO jiraCardHistory = getCardAllHistory(baseUrl, allDoneCard.getKey(), 0,
request.getToken());
log.info(
"[Jira Service History] Successfully get jira card history, card key: {}, card history items size:{}",
Expand Down Expand Up @@ -533,10 +532,22 @@ private List<String> getAssigneeSet(StoryPointsAndCycleTimeRequest request, URI
}

private List<String> getHistoricalAssignees(URI baseUrl, String cardKey, String token) {
CardHistoryResponseDTO jiraCardHistory = jiraFeignClient.getJiraCardHistory(baseUrl, cardKey, token);
CardHistoryResponseDTO jiraCardHistory = getCardAllHistory(baseUrl, cardKey, 0, token);
return jiraCardHistory.getItems().stream().map(item -> item.getActor().getDisplayName()).distinct().toList();
}

private CardHistoryResponseDTO getCardAllHistory(URI baseUrl, String cardKey, int startAt, String token) {
int pageCount = 100;
CardHistoryResponseDTO jiraCardHistory = jiraFeignClient.getJiraCardHistory(baseUrl, cardKey, startAt,
pageCount, token);
if (Boolean.FALSE.equals(jiraCardHistory.getIsLast())) {
CardHistoryResponseDTO cardAllHistory = getCardAllHistory(baseUrl, cardKey, startAt + pageCount, token);
jiraCardHistory.getItems().addAll(cardAllHistory.getItems());
jiraCardHistory.setIsLast(jiraCardHistory.getIsLast());
}
return jiraCardHistory;
}

private boolean useLastAssignee(String filterMethod) {
return filterMethod.equals(AssigneeFilterMethod.LAST_ASSIGNEE.getDescription())
|| StringUtils.isEmpty(filterMethod);
Expand Down Expand Up @@ -593,7 +604,7 @@ card, new SimpleDateFormat("yyyy 年 MM 月 dd 日 HH 时").format(new Date(last

private CycleTimeInfoDTO getCycleTime(URI baseUrl, String doneCardKey, String token, Boolean treatFlagCardAsBlock,
String keyFlagged, List<String> realDoneStatus) {
CardHistoryResponseDTO cardHistoryResponseDTO = jiraFeignClient.getJiraCardHistory(baseUrl, doneCardKey, token);
CardHistoryResponseDTO cardHistoryResponseDTO = getCardAllHistory(baseUrl, doneCardKey, 0, token);
List<StatusChangedItem> statusChangedArray = putStatusChangeEventsIntoAnArray(cardHistoryResponseDTO,
keyFlagged);
List<CycleTimeInfo> cycleTimeInfos = boardUtil.getCycleTimeInfos(statusChangedArray, realDoneStatus,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ public static AllDoneCardsResponseDTO.AllDoneCardsResponseDTOBuilder ONE_PAGE_NO

public static CardHistoryResponseDTO.CardHistoryResponseDTOBuilder CARD_HISTORY_RESPONSE_BUILDER() {
return CardHistoryResponseDTO.builder()
.isLast(true)
.items(List.of(new HistoryDetail(2, "status", new Status("In Dev"), new Status("To do"), null),
new HistoryDetail(3, "status", new Status(REVIEW), new Status("In Dev"), null),
new HistoryDetail(4, "status", new Status(WAITING_FOR_TESTING), new Status(REVIEW), null),
Expand All @@ -182,6 +183,7 @@ public static CardHistoryResponseDTO.CardHistoryResponseDTOBuilder CARD_HISTORY_

public static CardHistoryResponseDTO.CardHistoryResponseDTOBuilder CARD_HISTORY_RESPONSE_BUILDER_TO_DONE() {
return CardHistoryResponseDTO.builder()
.isLast(true)
.items(List.of(new HistoryDetail(2, "status", new Status("In Dev"), new Status("To do"), null),
new HistoryDetail(3, "status", new Status(REVIEW), new Status("In Dev"), null),
new HistoryDetail(4, "status", new Status(WAITING_FOR_TESTING), new Status(REVIEW), null),
Expand All @@ -190,6 +192,7 @@ public static CardHistoryResponseDTO.CardHistoryResponseDTOBuilder CARD_HISTORY_

public static CardHistoryResponseDTO.CardHistoryResponseDTOBuilder CARD_HISTORY_MULTI_RESPONSE_BUILDER() {
return CardHistoryResponseDTO.builder()
.isLast(true)
.items(List.of(new HistoryDetail(1, "status", new Status("To do"), new Status(BLOCK), null),
new HistoryDetail(2, "assignee", new Status("In Dev"), new Status("To do"), null),
new HistoryDetail(3, "status", new Status(REVIEW), new Status("In Dev"), null),
Expand Down
Loading

0 comments on commit ba82f79

Please sign in to comment.