Refine search
protected <T> QueryRequest createQueryRequestFromExpression(Class<T> clazz, DynamoDBQueryExpression<T> xpress, DynamoDBMapperConfig config) { final DynamoDBMapperTableModel<T> model = getTableModel(clazz, config); QueryRequest req = new QueryRequest(); req.setConsistentRead(xpress.isConsistentRead()); req.setTableName(getTableName(clazz, xpress.getHashKeyValues(), config)); req.setIndexName(xpress.getIndexName()); req.setKeyConditionExpression(xpress.getKeyConditionExpression()); processKeyConditions(req, xpress, model); req.withScanIndexForward(xpress.isScanIndexForward()) .withLimit(xpress.getLimit()) .withExclusiveStartKey(xpress.getExclusiveStartKey()) .withQueryFilter(xpress.getQueryFilter()) .withConditionalOperator(xpress.getConditionalOperator()) .withSelect(xpress.getSelect()) .withProjectionExpression(xpress.getProjectionExpression()) .withFilterExpression(xpress.getFilterExpression()) .withExpressionAttributeNames(xpress.getExpressionAttributeNames()) .withExpressionAttributeValues(xpress.getExpressionAttributeValues()) .withReturnConsumedCapacity(xpress.getReturnConsumedCapacity()) .withRequestMetricCollector(config.getRequestMetricCollector()) ; return applyUserAgent(req); }
protected ItemCollection<QueryOutcome> doQuery(QuerySpec spec) { QueryRequest req = spec.getRequest().withTableName(tableName); final KeyAttribute hashKey = spec.getHashKey(); if (hashKey != null) { addHashKeyCondition(req, hashKey); RangeKeyCondition rangeKeyCond = spec.getRangeKeyCondition(); if (rangeKeyCond != null) { addRangeKeyCondition(req, rangeKeyCond); Collection<QueryFilter> filters = spec.getQueryFilters(); if (filters != null) { req.setQueryFilter(InternalUtils.toAttributeConditionMap(filters)); Collection<KeyAttribute> startKey = spec.getExclusiveStartKey(); if (startKey != null) req.setExclusiveStartKey(InternalUtils.toAttributeValueMap(startKey)); final Map<String,AttributeValue> attrValMap = InternalUtils.fromSimpleMap(spec.getValueMap()); req.withExpressionAttributeNames(spec.getNameMap()) .withExpressionAttributeValues(attrValMap)
@Override public int hashCode() { final int prime = 31; int hashCode = 1; hashCode = prime * hashCode + ((getTableName() == null) ? 0 : getTableName().hashCode()); hashCode = prime * hashCode + ((getIndexName() == null) ? 0 : getIndexName().hashCode()); hashCode = prime * hashCode + ((getSelect() == null) ? 0 : getSelect().hashCode()); hashCode = prime * hashCode + ((getAttributesToGet() == null) ? 0 : getAttributesToGet().hashCode()); hashCode = prime * hashCode + ((getLimit() == null) ? 0 : getLimit().hashCode()); hashCode = prime * hashCode + ((getConsistentRead() == null) ? 0 : getConsistentRead().hashCode()); hashCode = prime * hashCode + ((getKeyConditions() == null) ? 0 : getKeyConditions().hashCode()); hashCode = prime * hashCode + ((getQueryFilter() == null) ? 0 : getQueryFilter().hashCode()); hashCode = prime * hashCode + ((getConditionalOperator() == null) ? 0 : getConditionalOperator().hashCode()); hashCode = prime * hashCode + ((getScanIndexForward() == null) ? 0 : getScanIndexForward().hashCode()); hashCode = prime * hashCode + ((getExclusiveStartKey() == null) ? 0 : getExclusiveStartKey().hashCode()); hashCode = prime * hashCode + ((getReturnConsumedCapacity() == null) ? 0 : getReturnConsumedCapacity().hashCode()); hashCode = prime * hashCode + ((getProjectionExpression() == null) ? 0 : getProjectionExpression().hashCode()); hashCode = prime * hashCode + ((getFilterExpression() == null) ? 0 : getFilterExpression().hashCode()); hashCode = prime * hashCode + ((getKeyConditionExpression() == null) ? 0 : getKeyConditionExpression().hashCode()); hashCode = prime * hashCode + ((getExpressionAttributeNames() == null) ? 0 : getExpressionAttributeNames().hashCode()); hashCode = prime * hashCode + ((getExpressionAttributeValues() == null) ? 0 : getExpressionAttributeValues().hashCode()); return hashCode; }
@Override public Page<Item, QueryOutcome> firstPage() { QueryRequest request = spec.getRequest(); request.setExclusiveStartKey(startKey); request.setLimit(InternalUtils.minimum( spec.getMaxResultSize(), spec.getMaxPageSize())); QueryResult result = client.query(request); QueryOutcome outcome = new QueryOutcome(result); setLastLowLevelResult(outcome); return new QueryPage(client, spec, request, 0, outcome); }
private void addKeyCondition(QueryRequest req, String keyName, ComparisonOperator comparison, AttributeValue... values) { Map<String, Condition> currentConditions = req.getKeyConditions(); Condition currentCondition = currentConditions == null ? null : currentConditions.get(keyName); Condition newCondition = new Condition().withComparisonOperator(comparison) .withAttributeValueList(values); // If there's already a condition on the key in the item, make sure it's not any different than the condition they // specified in the query spec if (currentCondition == null) { req.addKeyConditionsEntry(keyName, newCondition); } else if (!currentCondition.equals(newCondition)) { throw new IllegalArgumentException("a different condition was specified for '" + keyName + "' in the query spec " + "and the query request"); } }
try { restApi = new RallyRestApi( new URI(host), username, password); restApi.setApplicationName(applicationName); QueryRequest defectRequest = new QueryRequest("Defect"); defectRequest.setProject(projectRef); defectRequest.setFetch(new Fetch(new String[] {"Name", "FormattedID","State", "Priority", "Severity", "Requirement"})); defectRequest.setLimit(1000); defectRequest.setScopedDown(false); defectRequest.setScopedUp(false); defectRequest.setQueryFilter(new QueryFilter("Requirement", "=", storyRef)); QueryResponse defectQueryResponse = restApi.query(defectRequest); for (int i=0; i<defectQueryResponse.getResults().size();i++){ JsonObject defectJsonObject = defectQueryResponse.getResults().get(i).getAsJsonObject(); System.out.println("Name: " + defectJsonObject.get("Name") + " State: " + defectJsonObject.get("State") + " Priority: " + defectJsonObject.get("Priority") + " FormattedID: " + defectJsonObject.get("Requirement")); } } finally { if (restApi != null) { restApi.close(); } }
public static void main(String[] args) throws URISyntaxException, IOException { // Create and configure a new instance of RallyRestApi String host = "https://rally1.rallydev.com"; String username = "user@domain.com"; String password = "secret"; String wsapiVersion = "v2.0"; String workspaceRef = "/workspace/1111"; String projectRef = "/project/2222"; String applicationName = "DirectChildrenCount"; RallyRestApi restApi = new RallyRestApi( new URI(host), username, password); restApi.setWsapiVersion(wsapiVersion); restApi.setApplicationName(applicationName); QueryRequest storyRequest = new QueryRequest("HierarchicalRequirement"); storyRequest.setFetch(new Fetch("Name","DirectChildrenCount")); storyRequest.setWorkspace(workspaceRef); storyRequest.setQueryFilter(new QueryFilter("FormattedID", "=", "US16")); QueryResponse storyQueryResponse = restApi.query(storyRequest); JsonObject storyJsonObject = storyQueryResponse.getResults().get(0).getAsJsonObject(); System.out.println(storyJsonObject.get("Name") + " DirectChildrenCount: " + storyJsonObject.get("DirectChildrenCount")); }
// Query for Story to associate with Defect String storyFormattedID = "US20142"; QueryRequest storyRequest = new QueryRequest("HierarchicalRequirement"); storyRequest.setFetch(new Fetch("FormattedID","Name","Changesets")); storyRequest.setQueryFilter(new QueryFilter("FormattedID", "=", storyFormattedID)); QueryResponse storyQueryResponse = restApi.query(storyRequest); JsonObject storyJsonObject = storyQueryResponse.getResults().get(0).getAsJsonObject(); String storyRef = storyJsonObject.get("_ref").toString(); JsonObject newDefect = new JsonObject(); newDefect.addProperty("Name", "Test Defect"); newDefect.addProperty("Priority", "High Attention"); newDefect.addProperty("Severity", "Major Problem"); newDefect.addProperty("Requirement", storyRef); CreateRequest storyCreateRequest = new CreateRequest("defect", newDefect); CreateResponse storyCreateResponse = restApi.create(storyCreateRequest);
RallyRestApi restApi = new RallyRestApi(new URI("https://rally.rallydev.com/"), "_apogjlfdkjglfjlksr23rfdlj"); String wsapiVersion = "v2.0"; String workspaceRef = "/workspace/01245"; String projectRef = "/project/6757552"; if(restApi!=null){ restApi.setWsapiVersion(wsapiVersion); QueryRequest queryRequest = new QueryRequest("TestFolders"); queryRequest.setFetch(new Fetch(new String[] { "Name","FormattedID","TestFolder"})); queryRequest.setWorkspace(workspaceRef); queryRequest.setProject(projectRef); queryRequest.setScopedDown(true); queryRequest.setLimit(Integer.MAX_VALUE); queryRequest.setPageSize(Integer.MAX_VALUE); QueryResponse queryResponse = null; JsonArray jsonarr = new JsonArray(); queryResponse = restApi.query(queryRequest); int responseTotalResultsCount = queryResponse.getTotalResultCount(); jsonarr.addAll(queryResponse.getResults()); int jsonArrSize = jsonarr.size(); for (int i=0; i<queryResponse.getResults().size();i++){ JsonObject testCaseJsonObject = queryResponse.getResults().get(i).getAsJsonObject(); System.out.println(testCaseJsonObject.getAsJsonObject().get("FormattedID")+": "+testCaseJsonObject.getAsJsonObject().get("Name")); } }
new URI(host), username, password); QueryRequest storyRequest = new QueryRequest("HierarchicalRequirement"); storyRequest.setLimit(1000); storyRequest.setScopedDown(true); storyRequest.setScopedUp(false); storyRequest.setWorkspace(workspaceRef); storyRequest.setProject(projectRef); System.out.println(storyQueryResponse.getResults().size());
QueryRequest testCaseRequest = new QueryRequest("testcase"); testCaseRequest.setQueryFilter(new QueryFilter("FormattedID", "=", "TC1")); testCaseRequest.setFetch(new Fetch("FormattedID", "Name", "Steps")); QueryResponse testCaseResponse = restApi.query(testCaseRequest); JsonObject testCase = testCaseResponse.getResults().get(0).getAsJsonObject(); System.out.println(String.format("Found: %s - %s", testCase.get("FormattedID").getAsString(), testCase.get("Name").getAsString())); //Inspect the steps collection JsonObject steps = testCase.getAsJsonObject("Steps"); int stepCount = steps.get("Count").getAsInt(); System.out.println(String.format("\nTotal steps: %d", stepCount)); //Query the steps collection QueryRequest stepRequest = new QueryRequest(steps); stepRequest.setFetch(new Fetch("StepIndex","ExpectedResult","Input")); QueryResponse queryResponse = restApi.query(stepRequest); if (queryResponse.wasSuccessful()) { for (JsonElement result : queryResponse.getResults()) { JsonObject step = result.getAsJsonObject(); System.out.println(String.format("\t%d: Input=%s, ExpectedResult=%s", step.get("StepIndex").getAsInt(), step.get("Input").getAsString(), step.get("ExpectedResult").getAsString())); } }
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(); }
QueryRequest userRequest = new QueryRequest("User"); userRequest.setFetch(new Fetch("UserName", "Subscription", "DisplayName", "SubscriptionAdmin")); userRequest.setQueryFilter(new QueryFilter("UserName", "=", "someuser@co.com")); QueryResponse userQueryResponse = restApi.query(userRequest); JsonArray userQueryResults = userQueryResponse.getResults(); JsonElement userQueryElement = userQueryResults.get(0); JsonObject userQueryObject = userQueryElement.getAsJsonObject(); String userRef = userQueryObject.get("_ref").getAsString(); System.out.println(userRef); if (userQueryObject.get("SubscriptionAdmin").getAsBoolean() == false){ System.out.println(userQueryObject.get("SubscriptionAdmin")); }
// Query for Test Case to which we want to add results QueryRequest testCaseRequest = new QueryRequest("TestCase"); testCaseRequest.setFetch(new Fetch("FormattedID","Name")); testCaseRequest.setQueryFilter(new QueryFilter("FormattedID", "=", "TC4")); QueryResponse testCaseQueryResponse = restApi.query(testCaseRequest); JsonObject testCaseJsonObject = testCaseQueryResponse.getResults().get(0).getAsJsonObject(); String testCaseRef = testCaseQueryResponse.getResults().get(0).getAsJsonObject().get("_ref").toString(); String testCaseFormattedID = testCaseQueryResponse.getResults().get(0).getAsJsonObject.get("FormattedID").toString(); // Query for Test Case Results that are associated to this particular Test Case QueryRequest testCaseResultsRequest = new QueryRequest("TestCaseResult"); testCaseResultsRequest.setFetch(new Fetch("Build","TestCase","Verdict","FormattedID")); testCaseResultsRequest.setQueryFilter(new QueryFilter("TestCase.FormattedID", "=", testCaseFormattedID)); QueryResponse testCaseResultResponse = restApi.query(testCaseResultsRequest); int numberTestCaseResults = testCaseResultResponse.getTotalResultCount();
QueryRequest queryRequest = new QueryRequest("hierarchicalrequirement"); queryRequest.setFetch(new Fetch(new String[] {"ObjectID", "CreationDate", "LastUpdateDate", "FormattedId"})); queryRequest.setQueryFilter(new QueryFilter("CreationDate", ">=", "2013-01-01T07:00:00.000Z")); queryRequest.setLimit(Integer.MAX_VALUE); while ((queryRequest.getStart()) < responseTotalResultsCount && actualResultsProcessedSoFar < responseTotalResultsCount) { responseTotalResultsCount = queryResponse.getTotalResultCount();// Set to correct value here JsonArray results = queryResponse.getResults(); } else { for (JsonElement jsonElement : queryResponse.getResults()) { queryRequest.setStart(queryRequest.getStart() + queryRequest.getPageSize());
QueryRequest testsetRequest = new QueryRequest("TestSet"); //no spaces testsetRequest.setFetch(new Fetch("FormattedID","Name")); //No need to specify type again testsetRequest.setQueryFilter(new QueryFilter("Name", "=", "TestSetName")); QueryResponse testSetQueryResponse = restApi.query(testsetRequest); if(testSetQueryResponse.wasSuccessful()) { for (JsonElement result : testSetQueryResponse.getResults()) { //handle results } } else { //See what error occurred for (String err : testSetQueryResponse.getErrors()) { System.err.println("\t" + err); } }
try{ QueryRequest c = new QueryRequest("testcaseresult"); c.setFetch(new Fetch("testcase")); c.setQueryFilter(new QueryFilter("testcase", "=", testCaseRef)); QueryResponse cc = r.query(c); String testresultRef = cc.getResults().get(0).getAsJsonObject().get("_ref").toString(); } catch(IndexOutOfBoundsException e){ //Create a testcaseresult here. }
public static QueryRequest copyQueryRequest(QueryRequest queryRequest) { QueryRequest copiedQueryRequest = new QueryRequest().withAttributesToGet(queryRequest.getAttributesToGet()) .withConsistentRead(queryRequest.getConsistentRead()) .withExclusiveStartKey(queryRequest.getExclusiveStartKey()).withIndexName(queryRequest.getIndexName()) .withKeyConditions(queryRequest.getKeyConditions()).withLimit(queryRequest.getLimit()) .withReturnConsumedCapacity(queryRequest.getReturnConsumedCapacity()) .withScanIndexForward(queryRequest.getScanIndexForward()).withSelect(queryRequest.getSelect()) .withTableName(queryRequest.getTableName()); return copiedQueryRequest; } }
private List<Document> getNextQueryResultSet() { final List<Document> returnValue = new ArrayList<Document>(); final QueryRequest request = new QueryRequest(); request.withExclusiveStartKey(nextKey) .withAttributesToGet(attributesToGet) .withLimit(limit) .withTableName(tableName) .withConsistentRead(isConsistentRead) .withIndexName(this.indexName); request.withSelect(select); request.getIndexName()); final Map<String, Condition> filterConditions = getFilterConditions( (QueryFilter) this.filter, request.getIndexName()); if (!keyConditions.isEmpty()) { request.withKeyConditions(keyConditions); request.withQueryFilter(filterConditions); request.withKeyConditions(null).withQueryFilter(null); if (request.getQueryFilter() != null && request.getQueryFilter().size() > 1) { request.withConditionalOperator(this.conditionalOperator); } else { request.withConditionalOperator((String) null);
QueryRequest alltags = new QueryRequest("Tag"); alltags.setQueryFilter(new QueryFilter("Name", "=", tagx); QueryResponse resp = r.query(alltags); if(resp.wasSuccessful() && resp.getResults().size() == 1) { //tag is at index 0 in results }