gpt4 book ai didi

java - 在 Java 中向 Rally 添加新用户

转载 作者:行者123 更新时间:2023-12-01 04:27:26 24 4
gpt4 key购买 nike

我正在寻找任何可用于在用 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 = "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();
}
}
}

关于java - 在 Java 中向 Rally 添加新用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18394404/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com