ElasticsearchActivityStore implements ActivityStore { public List<ActivityType> getActivityTypes(Context context) throws Exception { if (context == null) { throw new Exception(java.util.PropertyResourceBundle.getBundle( "activity-store-elasticsearch.Messages").getString("ACTIVITY-STORE-ELASTICSEARCH-4")); } RefreshRequestBuilder refreshRequestBuilder = _client.getElasticsearchClient().admin().indices().prepareRefresh(_client.getIndex()); _client.getElasticsearchClient().admin().indices().refresh(refreshRequestBuilder.request()).actionGet(); if (LOG.isLoggable(Level.FINEST)) { LOG.finest("getActivityTypes=" + context); } QueryBuilder b2 = QueryBuilders.nestedQuery("context", QueryBuilders.boolQuery() .must(QueryBuilders.matchQuery("context.value", context.getValue())).must(QueryBuilders.matchQuery("context.type", context.getType())) ); SearchResponse response = _client.getElasticsearchClient().prepareSearch( _client.getIndex()).setTypes(_client.getType() + "type") .setSearchType(SearchType.DFS_QUERY_THEN_FETCH) .setTimeout(TimeValue.timeValueMillis(_timeout)) .setSize(_responseSize) .setQuery(b2).execute().actionGet(); if (response.isTimedOut()) { throw new Exception(MessageFormat.format( java.util.PropertyResourceBundle.getBundle( "activity-store-elasticsearch.Messages").getString("ACTIVITY-STORE-ELASTICSEARCH-3"), _client.getIndex(), _client.getType(), b2.toString() )); } List<ActivityType> list = new ArrayList<ActivityType>(); for (SearchHit searchHitFields : response.getHits()) { list.add(ElasticsearchClient.<ActivityType>convertJsonToType(searchHitFields.getSourceAsString(), ActivityType.class)); } if (LOG.isLoggable(Level.FINEST)) { LOG.finest("Returning activity list for context '"+context+"': " +new String(ActivityUtil.serializeActivityTypeList(list))); } return list; } ElasticsearchActivityStore(); @ServiceInit void init(); void store(List<ActivityUnit> activities); ActivityUnit getActivityUnit(String id); List<ActivityType> getActivityTypes(Context context); List<ActivityType> getActivityTypes(Context context, long from, long to); @Deprecated List<ActivityType> query(QuerySpec query); @ServiceClose void close();  }
@Test public void testGetActivityTypesWithNoContextAndNoTimeframe() { try { _elasticsearchActivityStore.getActivityTypes(null, 0, 0); fail("Should have reported exception"); } catch (Exception e) { } }