我正在寻找可用于在用Java编写的Rally中添加新用户的任何代码?如果它已经存在某个地方,我想得到同样的结果。任何帮助表示赞赏。
答案 0 :(得分: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();
}
}
}