1
我正在寻找任何可用的代码来添加用Java编写的Rally中的新用户?如果它已经存在,我想要得到相同的结果。任何援助表示赞赏。向Java中的Rally添加新用户
我正在寻找任何可用的代码来添加用Java编写的Rally中的新用户?如果它已经存在,我想要得到相同的结果。任何援助表示赞赏。向Java中的Rally添加新用户
使用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 = "[email protected]"; //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", "[email protected]");
newUser.addProperty("EmailAddress", "[email protected]");
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();
}
}
}
我看到Ruby围绕用户管理,而不是Java。 Java在技术上可行吗? – user2702052