我正在寻找任何可用于在用 Java 编写的 Rally 中添加新用户的代码?如果它已经在某个地方,我想得到相同的。任何帮助表示赞赏。
问问题
280 次
1 回答
0
使用 Java REST 工具包在技术上是可行的,因为它使用与 Ruby REST 工具包相同的 WS API。这是创建用户的示例代码:
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.response.GetResponse;
import com.rallydev.rest.util.Ref;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
public class aRestcreateUser {
public static void main(String[] args) throws URISyntaxException, IOException {
//Create and configure a new instance of RallyRestApi
String myRallyURL = "https://rally1.rallydev.com";
String myRallyUser = "administrator@company.com"; //must have admin rights
String myRallyPassword = "adminPassword";
String wsapiVersion = "1.43";
RallyRestApi restApi = new RallyRestApi(
new URI(myRallyURL),
myRallyUser,
myRallyPassword);
restApi.setWsapiVersion(wsapiVersion);
System.out.println(restApi.getWsapiVersion());
try {
System.out.println("Creating User...");
JsonObject newUser = new JsonObject();
newUser.addProperty("UserName", "nick002@test.com");
newUser.addProperty("EmailAddress", "nmusaelian@rallydev.com");
CreateRequest createRequest = new CreateRequest("User", newUser);
CreateResponse createResponse = restApi.create(createRequest);
if (createResponse.wasSuccessful()) {
System.out.println(String.format("Created User %s", createResponse.getObject().get("_ref").getAsString()));
String ref = Ref.getRelativeRef(createResponse.getObject().get("_ref").getAsString());
System.out.println(String.format("\nReading User %s...", ref));
GetRequest getRequest = new GetRequest(ref);
GetResponse getResponse = restApi.get(getRequest);
JsonObject obj = getResponse.getObject();
System.out.println(String.format("Read User. Name = %s, State = %s",
obj.get("UserName").getAsString(), obj.get("EmailAddress").getAsString()));
} else {
String[] errorList;
errorList = createResponse.getErrors();
for (int i=0;i<errorList.length;i++) {
System.out.println(errorList[i]);
}
}
} finally {
//Release all resources
restApi.close();
}
}
}
于 2013-08-23T18:11:43.280 回答