List of usage examples for com.amazonaws.services.dynamodbv2.datamodeling DynamoDBQueryExpression setHashKeyValues
public void setHashKeyValues(T hashKeyValues)
From source file:com.alertlogic.aws.kinesis.test1.webserver.GetCountsServlet.java
License:Open Source License
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { MultiMap<String> params = new MultiMap<>(); UrlEncoded.decodeTo(req.getQueryString(), params, "UTF-8"); // We need both parameters to properly query for counts if (!params.containsKey(PARAMETER_RESOURCE) || !params.containsKey(PARAMETER_RANGE_IN_SECONDS)) { resp.setStatus(HttpServletResponse.SC_BAD_REQUEST); return;/* w ww. j av a2s. c om*/ } // Parse query string as a single integer - the number of seconds since "now" to query for new counts String resource = params.getString(PARAMETER_RESOURCE); int rangeInSeconds = Integer.parseInt(params.getString(PARAMETER_RANGE_IN_SECONDS)); Calendar c = Calendar.getInstance(); c.add(Calendar.SECOND, -1 * rangeInSeconds); Date startTime = c.getTime(); if (LOG.isDebugEnabled()) { LOG.debug(String.format("Querying for counts of resource %s since %s", resource, DATE_FORMATTER.get().format(startTime))); } DynamoDBQueryExpression<HttpReferrerPairsCount> query = new DynamoDBQueryExpression<>(); HttpReferrerPairsCount hashKey = new HttpReferrerPairsCount(); hashKey.setResource(resource); query.setHashKeyValues(hashKey); Condition recentUpdates = new Condition().withComparisonOperator(ComparisonOperator.GT) .withAttributeValueList(new AttributeValue().withS(DATE_FORMATTER.get().format(startTime))); query.setRangeKeyConditions(Collections.singletonMap("timestamp", recentUpdates)); List<HttpReferrerPairsCount> counts = mapper.query(HttpReferrerPairsCount.class, query); // Return the counts as JSON resp.setContentType("application/json"); resp.setStatus(HttpServletResponse.SC_OK); JSON.writeValue(resp.getWriter(), counts); }
From source file:com.kinesis.datavis.servlet.GetBidRqCountsServlet.java
License:Open Source License
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { MultiMap<String> params = new MultiMap<>(); UrlEncoded.decodeTo(req.getQueryString(), params, "UTF-8"); // We need both parameters to properly query for counts if (!params.containsKey(PARAMETER_RESOURCE) || !params.containsKey(PARAMETER_RANGE_IN_SECONDS)) { resp.setStatus(HttpServletResponse.SC_BAD_REQUEST); return;//from w ww . j a va2 s . c o m } // Parse query string as a single integer - the number of seconds since "now" to query for new counts String resource = params.getString(PARAMETER_RESOURCE); int rangeInSeconds = Integer.parseInt(params.getString(PARAMETER_RANGE_IN_SECONDS)); Calendar c = Calendar.getInstance(); c.add(Calendar.SECOND, -1 * rangeInSeconds); Date startTime = c.getTime(); if (LOG.isDebugEnabled()) { LOG.debug(String.format("Querying for counts of resource %s since %s", resource, DATE_FORMATTER.get().format(startTime))); } DynamoDBQueryExpression<BidRequestCount> query = new DynamoDBQueryExpression<>(); BidRequestCount hashKey = new BidRequestCount(); hashKey.setHashKey(Ticker.getInstance().hashKey()); query.setHashKeyValues(hashKey); Condition recentUpdates = new Condition().withComparisonOperator(ComparisonOperator.GT) .withAttributeValueList(new AttributeValue().withS(DATE_FORMATTER.get().format(startTime))); // Condition attrFilter = // new Condition(). // withComparisonOperator(ComparisonOperator.EQ).withAttributeValueList(new AttributeValue().withS(resource)); query.setRangeKeyConditions(Collections.singletonMap("timestamp", recentUpdates)); // query.setQueryFilter(Collections.singletonMap("wh", attrFilter)); List<BidRequestCount> counts = mapper.query(BidRequestCount.class, query); // System.out.println(counts.size()); // Return the counts as JSON resp.setContentType("application/json"); resp.setStatus(HttpServletResponse.SC_OK); JSON.writeValue(resp.getWriter(), counts); }
From source file:eu.roschi.obdkinesis.webserver.GetCountsServlet.java
License:Open Source License
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { MultiMap<String> params = new MultiMap<>(); UrlEncoded.decodeTo(req.getQueryString(), params, "UTF-8"); // We need both parameters to properly query for counts if (!params.containsKey(PARAMETER_RESOURCE) || !params.containsKey(PARAMETER_RANGE_IN_SECONDS)) { resp.setStatus(HttpServletResponse.SC_BAD_REQUEST); return;//from w w w .j a v a 2 s . com } // Parse query string as a single integer - the number of seconds since "now" to query for new counts String resource = params.getString(PARAMETER_RESOURCE); int rangeInSeconds = Integer.parseInt(params.getString(PARAMETER_RANGE_IN_SECONDS)); Calendar c = Calendar.getInstance(); c.add(Calendar.SECOND, -1 * rangeInSeconds); Date startTime = c.getTime(); //if (LOG.isDebugEnabled()) { LOG.debug(String.format("Querying for counts of resource %s since %s", resource, DATE_FORMATTER.get().format(startTime))); //} DynamoDBQueryExpression<HttpReferrerPairsCount> query = new DynamoDBQueryExpression<>(); HttpReferrerPairsCount hashKey = new HttpReferrerPairsCount(); hashKey.setResource(resource); query.setHashKeyValues(hashKey); Condition recentUpdates = new Condition().withComparisonOperator(ComparisonOperator.GT) .withAttributeValueList(new AttributeValue().withS(DATE_FORMATTER.get().format(startTime))); query.setRangeKeyConditions(Collections.singletonMap("timestamp", recentUpdates)); List<HttpReferrerPairsCount> counts = mapper.query(HttpReferrerPairsCount.class, query); // Return the counts as JSON resp.setContentType("application/json"); resp.setStatus(HttpServletResponse.SC_OK); JSON.writeValue(resp.getWriter(), counts); }