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