2015-03-31 47 views
0

我正嘗試在java的拉力賽中創建用戶故事。我沒有得到迴應,並拋出「無法解析對象引用」。創建故事時發生錯誤:「無法解析對象參考」,拉力賽

我的集會簡介:假設我有項目名稱「字符」,它的子集爲A,B,C,D。我必須在C中創建我的用戶故事。我的以下代碼是否正確?任何人都可以幫忙嗎?

package samplerally; 

import java.io.IOException; 
import java.net.URI; 
import java.net.URISyntaxException; 

import com.google.gson.JsonObject; 
import com.rallydev.rest.RallyRestApi; 
import com.rallydev.rest.request.CreateRequest; 
import com.rallydev.rest.request.GetRequest; 
import com.rallydev.rest.response.CreateResponse; 
import com.rallydev.rest.util.Ref; 

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

    String host = "https://rally1.rallydev.com"; 
    String username = "[email protected]"; 
    String password = "password"; 
    String wsapiVersion = "v2.0"; 
    String applicationName = "C"; 

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", "Characters"); 

      CreateRequest createRequest = new CreateRequest("hierarchicalrequirement", newStory); 
      CreateResponse createResponse = restApi.create(createRequest); 
      System.out.println("Response ::: "+createResponse.wasSuccessful()); 
      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; j < createErrors.length; j++) { 
        System.out.println(createErrors[j]); 
       } 
      } 
     } 
    } finally { 
     // Release all resources 
     restApi.close(); 
    } 
} 
} 

而且我得到錯誤爲:

Creating a story... 
Response ::: false 
Error occurred creating story: 
Could not read: Cannot parse object reference from "BSS HWSE Team Columbia" 
Creating a story... 
Response ::: false 
Error occurred creating story: 
Could not read: Cannot parse object reference from "BSS HWSE Team Columbia" 
Creating a story... 
Response ::: false 
Error occurred creating story: 
Could not read: Cannot parse object reference from "BSS HWSE Team Columbia" 
Picked up JAVA_TOOL_OPTIONS: -agentlib:jvmhook 
Picked up _JAVA_OPTIONS: -Xrunjvmhook -Xbootclasspath/a:"C:\Program Files\HP\Unified Functional Testing\bin\java_shared\classes";"C:\Program Files\HP\Unified Functional Testing\bin\java_shared\classes\jasmine.jar" 

請幫助。新的集會。在此先感謝

回答

2

當設置指向完整對象的項目,迭代,發佈,WorkProduduct,父等參考字段使用引用,而不是名稱。

找出項目「C」的唯一ObjectID,例如, 123456

替換:

newStory.addProperty("Project", "Characters"); 

newStory.addProperty("Project", "/project/123456"); 

爲了您可以由它的名字查詢在WS API找到一個項目的對象ID,或看拉力賽的一個網頁的URL中地址欄,而在該項目中,例如Backlog頁面的URL:https://rally1.rallydev.com/#/123456/backlog

如果存在附加到ObjectID字符串的du,例如, 123456d,不要將其包含在字符串中。在URL中,它表明您目前是在向上還是向下。