我提起了GitHub的問題,增加了對ScopedAttributeDefinition支持:https://github.com/RallyTools/RallyRestToolkitForJava/issues/19
但是在此期間,你可以解決它通過直接使用底層的HTTP客戶端。該代碼查詢工作區中的所有項目,然後查找Portfolio Item的類型定義,然後爲每個項目通過scopedattributedefinition端點獲取所有自定義屬性defs,並打印出其隱藏/必需的狀態。
QueryRequest projectQuery = new QueryRequest("project");
projectQuery.setLimit(Integer.MAX_VALUE);
QueryResponse projectResponse = restApi.query(projectQuery);
QueryRequest typeDefQuery = new QueryRequest("typedefinition");
typeDefQuery.setQueryFilter(new QueryFilter("Name", "=", "Portfolio Item"));
QueryResponse typeDefResponse = restApi.query(typeDefQuery);
JsonObject piTypeDef = typeDefResponse.getResults().get(0).getAsJsonObject();
for(JsonElement projectResult : projectResponse.getResults()) {
JsonObject project = projectResult.getAsJsonObject();
System.out.println("Project: " + project.get("Name").getAsString());
//Begin hackery (note we're not handling multiple pages-
// if you have more than 200 custom attributes you'll have to page
String scopedAttributeDefUrl = "/project/" + project.get("ObjectID").getAsLong() +
"/typedefinition/" + piTypeDef.get("ObjectID").getAsLong() + "/scopedattributedefinition" +
"?fetch=Hidden,Required,Name&query=" + URLEncoder.encode("(Custom = true)", "utf-8");
String attributes = restApi.getClient().doGet(scopedAttributeDefUrl);
QueryResponse attributeResponse = new QueryResponse(attributes);
//End hackery
for(JsonElement customAttributeResult : attributeResponse.getResults()) {
JsonObject customAttribute = customAttributeResult.getAsJsonObject();
System.out.print("\tAttribute: " + customAttribute.get("Name").getAsString());
System.out.print(", Hidden: " + customAttribute.get("Hidden").getAsBoolean());
System.out.println(", Required: " + customAttribute.get("Required").getAsBoolean());
}
System.out.println();
}
你想爲每個自定義字段的任何其他信息應該只是通過查詢從piTypeDef屬性集合訪問。
ScopedAttributeDefinition實際上只是特定作用域(工作空間或項目)中系統中另一個屬性的視圖。它允許您查看某個特定屬性是否在該特定範圍內隱藏或需要。那是你之後的數據嗎? –
我需要屬性的存在及其元數據(例如可見或隱藏,類型,可接受的值等)。 現在我正在查詢工作區中的所有TypeDefinitions,並獲取其屬性列表。這不會返回自定義數據類型,例如上面描述的Enabler Lead字段(所有返回的數據類型都具有「Custom = false」)。 –
從查看工具包源我不完全相信,它甚至會允許您不幸地查詢作用域屬性定義... –