如何使用Rally Java工具包创建故事时指定项目?

时间:2013-11-05 03:05:34

标签: java rally

我正在尝试使用Rally Java REST API - https://github.com/RallyTools/RallyRestToolkitForJava。如何定义工作区和项目以便创建新的用户故事?它似乎只是使用我的个人资料中定义的“默认”工作区。我能够创建用户故事,除了我想要的地方之外没有任何问题。任何帮助将不胜感激。

1 个答案:

答案 0 :(得分: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();
        }   

    } 

}