Example #1
0
 /**
  * Returns a list of saved queries
  *
  * @param criteria a multivalued map that has the filter criteria
  * @param start Displacement from the start of the search result
  * @param count Count of number of records required
  * @return list of saved queries
  * @throws LensException
  */
 public ListResponse getList(MultivaluedMap<String, String> criteria, long start, long count)
     throws LensException {
   final StringBuilder selectQueryBuilder =
       new StringBuilder("select * from " + SAVED_QUERY_TABLE_NAME);
   final Set<String> availableFilterKeys = FILTER_KEYS.keySet();
   final Sets.SetView<String> intersection =
       Sets.intersection(availableFilterKeys, criteria.keySet());
   if (intersection.size() > 0) {
     final StringBuilder whereClauseBuilder = new StringBuilder(" where ");
     final List<String> predicates = Lists.newArrayList();
     for (String colName : intersection) {
       predicates.add(
           FILTER_KEYS.get(colName).resolveFilterExpression(colName, criteria.getFirst(colName)));
     }
     Joiner.on(" and ").skipNulls().appendTo(whereClauseBuilder, predicates);
     selectQueryBuilder.append(whereClauseBuilder.toString());
   }
   final String listCountQuery =
       "select count(*) as "
           + VALUE_ALIAS
           + " from ("
           + selectQueryBuilder.toString()
           + ") tmp_table";
   selectQueryBuilder.append(" limit ").append(start).append(", ").append(count);
   final String listQuery = selectQueryBuilder.toString();
   try {
     return new ListResponse(
         start,
         runner.query(listCountQuery, new SingleValuedResultHandler()),
         runner.query(listQuery, new SavedQueryResultSetHandler()));
   } catch (SQLException e) {
     throw new LensException("List query failed!", e);
   }
 }
 @Test
 @SuppressWarnings("unchecked")
 public void testExtraction() {
   StreamsDatum datum = new StreamsDatum(activity, "Test");
   List<StreamsDatum> result = new RegexHashtagExtractor().process(datum);
   assertThat(result.size(), is(equalTo(1)));
   Activity output = (Activity) result.get(0).getDocument();
   Set<String> extracted =
       (Set) ExtensionUtil.ensureExtensions(output).get(RegexHashtagExtractor.EXTENSION_KEY);
   Sets.SetView<String> diff = Sets.difference(extracted, hashtags);
   assertThat(diff.size(), is(equalTo(0)));
 }
  @Test
  public void testInitializationWithReservedFields() throws Exception {
    // This is madness!
    final Sets.SetView<String> fields =
        Sets.difference(Message.RESERVED_FIELDS, Message.RESERVED_SETTABLE_FIELDS);
    int errors = 0;

    for (String field : fields) {
      try {
        new TestExtractor.Builder().targetField(field).build();
      } catch (Extractor.ReservedFieldException e) {
        errors++;
      }
    }

    assertThat(errors).isEqualTo(fields.size());
  }