fix(测试用例): 集成禅道11.5版本获取需求失败

This commit is contained in:
shiziyuan9527 2021-08-31 16:08:00 +08:00 committed by 刘瑞斌
parent 43c156adbf
commit 1394f6947a
1 changed files with 33 additions and 15 deletions

View File

@ -107,25 +107,43 @@ public class ZentaoPlatform extends AbstractIssuePlatform {
String body = responseEntity.getBody(); String body = responseEntity.getBody();
JSONObject obj = JSONObject.parseObject(body); JSONObject obj = JSONObject.parseObject(body);
LogUtil.info("project story" + key + obj); LogUtil.info("project story: " + key + obj);
if (obj != null) { if (obj != null) {
JSONObject data = obj.getJSONObject("data"); String data = obj.getString("data");
String s = JSON.toJSONString(data); if (StringUtils.isBlank(data)) {
Map<String, Object> map = JSONArray.parseObject(s, new TypeReference<Map<String, Object>>(){}); return list;
Collection<Object> values = map.values(); }
values.forEach(v -> { // 兼容处理11.5版本格式 [{obj},{obj}]
JSONObject jsonObject = JSONObject.parseObject(JSON.toJSONString(v)); if (data.charAt(0) == '[') {
DemandDTO demandDTO = new DemandDTO(); JSONArray array = obj.getJSONArray("data");
demandDTO.setId(jsonObject.getString("id")); for (int i = 0; i < array.size(); i++) {
demandDTO.setName(jsonObject.getString("title")); JSONObject o = array.getJSONObject(i);
demandDTO.setPlatform(IssuesManagePlatform.Zentao.name()); DemandDTO demandDTO = new DemandDTO();
list.add(demandDTO); demandDTO.setId(o.getString("id"));
}); demandDTO.setName(o.getString("title"));
demandDTO.setPlatform(IssuesManagePlatform.Zentao.name());
list.add(demandDTO);
}
}
// 处理格式 {{"id": {obj}},{"id",{obj}}}
else if (data.charAt(0) == '{') {
JSONObject dataObject = obj.getJSONObject("data");
String s = JSON.toJSONString(dataObject);
Map<String, Object> map = JSONArray.parseObject(s, new TypeReference<Map<String, Object>>(){});
Collection<Object> values = map.values();
values.forEach(v -> {
JSONObject jsonObject = JSONObject.parseObject(JSON.toJSONString(v));
DemandDTO demandDTO = new DemandDTO();
demandDTO.setId(jsonObject.getString("id"));
demandDTO.setName(jsonObject.getString("title"));
demandDTO.setPlatform(IssuesManagePlatform.Zentao.name());
list.add(demandDTO);
});
}
} }
} catch (Exception e) { } catch (Exception e) {
LogUtil.error("get zentao bug fail " + e.getMessage()); LogUtil.error("get zentao demand fail " + e.getMessage());
} }
return list; return list;
} }