我正在尝试使用 Rally Java REST API - https://github.com/RallyTools/RallyRestToolkitForJava。如何定义要创建新用户故事的工作区和项目?它似乎只是在使用我的个人资料中定义的“默认”工作区。除了我希望它们出现的位置之外,我能够创建没有任何问题的用户故事。任何帮助,将不胜感激。
问问题
744 次
1 回答
3
您可以设置项目参考:
String projectRef = "/project/222";
然后使用 addProperty:
newStory.addProperty("Project", projectRef);
这是一个完整的例子:
public class CreateStory {
public static void main(String[] args) throws URISyntaxException, IOException {
String host = "https://rally1.rallydev.com";
String username = "user@co.com";
String password = "secret";
String wsapiVersion = "v2.0";
String projectRef = "/project/2222";
String workspaceRef = "/workspace/11111";
String applicationName = "RestExample_createStory";
RallyRestApi restApi = new RallyRestApi(
new URI(host),
username,
password);
restApi.setWsapiVersion(wsapiVersion);
restApi.setApplicationName(applicationName);
try {
for (int i=0; i<3; i++) {
//Add a story
System.out.println("Creating a story...");
JsonObject newStory = new JsonObject();
newStory.addProperty("Name", "my story");
newStory.addProperty("Project", projectRef);
CreateRequest createRequest = new CreateRequest("hierarchicalrequirement", newStory);
CreateResponse createResponse = restApi.create(createRequest);
if (createResponse.wasSuccessful()) {
System.out.println(String.format("Created %s", createResponse.getObject().get("_ref").getAsString()));
//Read story
String ref = Ref.getRelativeRef(createResponse.getObject().get("_ref").getAsString());
System.out.println(String.format("\nReading Story %s...", ref));
GetRequest getRequest = new GetRequest(ref);
} else {
String[] createErrors;
createErrors = createResponse.getErrors();
System.out.println("Error occurred creating story: ");
for (int j=0; i<createErrors.length;j++) {
System.out.println(createErrors[j]);
}
}
}
} finally {
//Release all resources
restApi.close();
}
}
}
于 2013-11-05T03:13:23.470 回答