gpt4 book ai didi

java - 拉力赛:Java Rest Api:返回结果的限制?

转载 作者:搜寻专家 更新时间:2023-11-01 02:29:32 24 4
gpt4 key购买 nike

返回结果的数量/大小是否有限制?例如,当实际数量超过 600 时,我查询了所有缺陷并返回了 185。有没有一种方法可以检测查询是否无法获得所有结果?

编辑:我好像达到了 200 页的限制大小。有谁知道如何设计一个循环来获得下一组结果?

这是我的代码:

    String rallyProjectOid = getRallyProjectOid(rallyApi, rallyProjectName);
// Get the list of Rally defects for the project
QueryRequest defectRequest = new QueryRequest("defect");
defectRequest.setFetch(new Fetch("Project", "LastUpdateDate", "FormattedId", "SubmittedBy", "Owner"));
defectRequest.setProject(rallyProjectOid);
defectRequest.setQueryFilter(new QueryFilter("LastUpdateDate", ">", timestamp));
QueryResponse projectDefects = rallyApi.query(defectRequest);

最佳答案

尽管设置:

queryRequest.setLimit(Integer.MAX_VALUE);

确实处理很多类型,它并不适用于所有类型。

例如,DefectIteration 类型似乎在单个页面(对 Rally 的单个查询调用)中返回数千个结果,而其他类型如 UserHierarchicalRequirement 忽略了该限制,而是强制我使用分页(设置开始然后重新查询)来获取所有结果。

这是我如何处理两者的示例:

// NOTE : no pagination needed for defect or iteration, but required for hierarchicalrequirement or user
QueryRequest queryRequest = new QueryRequest("hierarchicalrequirement");

queryRequest.setFetch(new Fetch(new String[] {"ObjectID", "CreationDate", "LastUpdateDate", "FormattedId"}));
queryRequest.setQueryFilter(new QueryFilter("CreationDate", ">=", "2013-01-01T07:00:00.000Z"));
queryRequest.setLimit(Integer.MAX_VALUE);

int responseTotalResultsCount = Integer.MAX_VALUE;// So we enter while loop first time
int actualResultsProcessedSoFar = 0;

// Handle both cases
while ((queryRequest.getStart()) < responseTotalResultsCount && actualResultsProcessedSoFar < responseTotalResultsCount) {

QueryResponse queryResponse = restApi.query(queryRequest);

responseTotalResultsCount = queryResponse.getTotalResultCount();// Set to correct value here

JsonArray results = queryResponse.getResults();

if (results.size() == 0) {
return;
} else {

for (JsonElement jsonElement : queryResponse.getResults()) {

// Process this particular JsonElement here

// If no pagination required, this counter lets us exit while loop
actualResultsProcessedSoFar++;

}// end for loop

}// end if (results.size() == 0)

// Setting this to handle pagination, if required
queryRequest.setStart(queryRequest.getStart() + queryRequest.getPageSize());

} // end while loop

关于java - 拉力赛:Java Rest Api:返回结果的限制?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12943640/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com