在rally中,如何从webservice v2.0的给定条件列表中动态生成java中的搜索查询字符串

在rally中,如何从webservice v2.0的给定条件列表中动态生成java中的搜索查询字符串,java,web-services,rally,Java,Web Services,Rally,我在java hashmap中设置了一个搜索条件。此hashmap包含键作为Rally的字段名,值作为Rally中的字段值。从这个hashmap中,我想生成一个查询参数字符串,这些参数将在webservice url中传递 请注意,此hashmap还可能包含自定义字段的条件。对于Java,建议使用它,而不是直接访问端点。下面是查询故事的代码 public class FindStories { public static void main(String[] args) throws

我在java hashmap中设置了一个搜索条件。此hashmap包含键作为Rally的字段名,值作为Rally中的字段值。从这个hashmap中,我想生成一个查询参数字符串,这些参数将在webservice url中传递


请注意,此hashmap还可能包含自定义字段的条件。

对于Java,建议使用它,而不是直接访问端点。下面是查询故事的代码

public class FindStories {

    public static void main(String[] args) throws Exception {

        String host = "https://rally1.rallydev.com";
        String username = "user@co.com";
        String password = "secret";
        String applicationName = "RESTExampleFindStories";

        RallyRestApi restApi = null;
            try {
            restApi = new RallyRestApi(
                    new URI(host),
                    username,
                    password);
            restApi.setApplicationName(applicationName); 

            QueryRequest storyRequest = new QueryRequest("Requirement");
            storyRequest.setFetch(new Fetch(new String[] {"Name", "FormattedID", "ScheduleState", "State", "PlanEstimate", "TaskRemainingTotal", "CreationDate"}));
            storyRequest.setLimit(1000);
            storyRequest.setScopedDown(false);
            storyRequest.setScopedUp(false);
            storyRequest.setQueryFilter((new QueryFilter("Project.Name", "=", "Demandware")).and(new QueryFilter("Release.Name", "=", "201311 IT Integrated Release")));
            QueryResponse storyQueryResponse = restApi.query(storyRequest);
            System.out.println("Successful: " + storyQueryResponse.wasSuccessful());
            System.out.println("Size: " + storyQueryResponse.getTotalResultCount());
            System.out.println("Results Size: " + storyQueryResponse.getResults().size());
            for (int i=0; i<storyQueryResponse.getResults().size();i++){
                JsonObject storyJsonObject = storyQueryResponse.getResults().get(i).getAsJsonObject();
                System.out.println("Name: " + storyJsonObject.get("Name") + " ScheduleState: " + storyJsonObject.get("ScheduleState") + " State: " + storyJsonObject.get("State") + " PlanEstimate: " + storyJsonObject.get("PlanEstimate") + " TaskRemainingTotal: " + storyJsonObject.get("TaskRemainingTotal"));
            }
        } finally {
            if (restApi != null) {
                restApi.close();
            }
        }
    }

}
我们建议使用工具箱。如果选择不这样做,则必须从此终结点获取安全令牌:

HttpGet httpGet = new HttpGet("https://rally1.rallydev.com/slm/webservice/v2.0/security/authorize"); 
然后将其附加到创建请求:

HttpPost createDefect = new HttpPost("https://rally1.rallydev.com/slm/webservice/v2.0/defect/create?key="+key);
使用hasphamp创建有效负载输入,而不是下面的
{\'Name\':\'mynewdefect\'}

List<NameValuePair> pairs = new ArrayList<NameValuePair>();
pairs.add(new BasicNameValuePair("content-type", "application/json"));
StringEntity input = new StringEntity("{\"Defect\":{\"Name\":\"my new defect\"}}");
input.setContentType("application/json");
createDefect.setEntity(input);
for (NameValuePair h : pairs)
    {
        createDefect.addHeader(h.getName(), h.getValue());
    }
HttpResponse resp = httpClient.execute(createDefect);
List pairs=new ArrayList();
添加(新的BasicNameValuePair(“内容类型”、“应用程序/json”);
StringEntity输入=新的StringEntity(“{\”缺陷\“:{\”名称\“:\”我的新缺陷\“}”);
setContentType(“应用程序/json”);
createDefect.setEntity(输入);
对于(NameValuePair h:pairs)
{
createDefect.addHeader(h.getName(),h.getValue());
}
HttpResponse resp=httpClient.execute(createDefect);
我们建议使用工具箱,而不是直接访问端点

HttpPost createDefect = new HttpPost("https://rally1.rallydev.com/slm/webservice/v2.0/defect/create?key="+key);
List<NameValuePair> pairs = new ArrayList<NameValuePair>();
pairs.add(new BasicNameValuePair("content-type", "application/json"));
StringEntity input = new StringEntity("{\"Defect\":{\"Name\":\"my new defect\"}}");
input.setContentType("application/json");
createDefect.setEntity(input);
for (NameValuePair h : pairs)
    {
        createDefect.addHeader(h.getName(), h.getValue());
    }
HttpResponse resp = httpClient.execute(createDefect);