Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specify project when creating a story using Rally Java toolkit?

Tags:

java

rally

I’m trying to use the Rally Java REST API - https://github.com/RallyTools/RallyRestToolkitForJava. How do I define the workspace and project for where I’d like to create a new user story? It seems to be just using my ‘default’ workspace as defined in my profile. I’m able to create user stories with no issues other than where I want them to be. Any help would be appreciated.

like image 597
Monika Liao Avatar asked Dec 19 '25 19:12

Monika Liao


1 Answers

you may set a project reference:

String projectRef = "/project/222";

and then use addProperty:

newStory.addProperty("Project", projectRef);

Here is a full example:

public class CreateStory {

    public static void main(String[] args) throws URISyntaxException, IOException {


           String host = "https://rally1.rallydev.com";
            String username = "[email protected]";
            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();
        }   

    } 

}
like image 151
nickm Avatar answered Dec 22 '25 14:12

nickm



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!