我想编写一个Java API来检索Rally中每个项目的团队成员并推送到db。是否有任何查询可以帮助我处理此请求?
可以通过命名约定来识别项目,因为我们的工作区具有基于层次结构的项目,其中只有最后一层的层次结构包含团队成员列表。
如果您需要更多详细信息,请发邮件给我
由于
SREE
答案 0 :(得分:1)
以下是返回项目团队成员的代码示例:
public static void main(String[] args) throws URISyntaxException, IOException {
String host = "https://rally1.rallydev.com";
String username = "user@co.com";
String password = "secret";
String workspaceRef = "/workspace/12352608129";
String applicationName = "RESTExample get team members";
RallyRestApi restApi = new RallyRestApi(
new URI(host),
username,
password);
restApi.setApplicationName(applicationName);
System.out.println(restApi.getWsapiVersion());
try{
QueryRequest projectRequest = new QueryRequest("Project");
projectRequest.setFetch(new Fetch("Name", "TeamMembers"));
projectRequest.setWorkspace(workspaceRef);
projectRequest.setQueryFilter(new QueryFilter("Name", "=", "Company X"));
QueryResponse projectQueryResponse = restApi.query(projectRequest);
int count = projectQueryResponse.getResults().size();
System.out.println(count);
if(count > 0){
JsonObject projectObject = projectQueryResponse.getResults().get(count-1).getAsJsonObject();
int numberOfTeamMembers = projectObject.getAsJsonObject("TeamMembers").get("Count").getAsInt();
if(numberOfTeamMembers > 0) {
QueryRequest teamRequest = new QueryRequest(projectObject.getAsJsonObject("TeamMembers"));
JsonArray teammates = restApi.query(teamRequest).getResults();
for (int j=0;j<numberOfTeamMembers;j++){
System.out.println(teammates.get(j).getAsJsonObject().get("_refObjectName").getAsString());
}
}
}
}catch(Exception e){
e.printStackTrace();
} finally{
restApi.close();
}
}