log.debug("Completed query scroll query in {} tries. Succeeded: {}", retry + 1, result.isSucceeded()); return result; } catch (IOException e) {
/** {@inheritDoc} */ @Override public Map<String, Feature> readGroup(String groupName) { assertGroupExist(groupName); SearchResult result = getConnection().search(getBuilder().queryReadGroup(groupName)); LinkedHashMap<String, Feature> mapOfFeatures = new LinkedHashMap<String, Feature>(); if (null != result && result.isSucceeded()) { for (Hit<Feature, Void> hit : result.getHits(Feature.class)) { mapOfFeatures.put(hit.source.getUid(), hit.source); } } return mapOfFeatures; }
log.debug("Completed total requests query. Succeeded: {}", result.isSucceeded()); return result; } catch (IOException e) {
@Test public void testIndexFunction() { SearchResult jestResult = mock(SearchResult.class); // Build mocks when(jestClientHelper.execute(any())).thenReturn(jestResult); // Call the method under test indexFunctionsDao.createIndexDocument("INDEX_NAME", "DOCUMENT_TYPE", "ID", "JSON"); // Verify the calls to external methods verify(jestClientHelper).execute(any()); verify(jestResult).isSucceeded(); verifyNoMoreInteractions(jestClientHelper); }
/** {@inheritDoc} */ @Override public Map<String, Feature> readAll() { SearchResult search = getConnection().search(getBuilder().queryReadAllFeatures(), true); Map<String, Feature> mapOfFeatures = new HashMap<String, Feature>(); if (null != search && search.isSucceeded()) { Integer total = search.getTotal(); SearchResult searchAllResult = getConnection().search(getBuilder().queryReadAllFeatures(total), true); if (null != searchAllResult && searchAllResult.isSucceeded()) { for (Hit<Feature, Void> feature : searchAllResult.getHits(Feature.class)) { mapOfFeatures.put(feature.source.getUid(), feature.source); } } } return mapOfFeatures; }
@Test public void testValidateFunctionUpdate() { SearchResult jestResult = mock(SearchResult.class); // Build mocks when(jestClientHelper.execute(any())).thenReturn(jestResult); when(jestResult.getSourceAsString()).thenReturn("JSON_UPDATE"); indexFunctionsDao.validateDocumentIndex("INDEX_NAME", "DOCUMENT_TYPE", "ID", "JSON"); // Verify the calls to external methods verify(jestClientHelper, times(2)).execute(any()); verify(jestResult).getSourceAsString(); verify(jestResult).isSucceeded(); verifyNoMoreInteractions(jestClientHelper); }
/** {@inheritDoc} */ @SuppressWarnings("rawtypes") @Override public Map<String, Property<?>> readAllProperties() { SearchResult search = getConnection().search(getBuilder().queryReadAllProperties(), true); Map<String, Property<?>> mapOfProperties = new HashMap<String, Property<?>>(); if (null != search && search.isSucceeded()) { Integer total = search.getTotal(); SearchResult searchAllResult = getConnection().search(getBuilder().queryReadAllProperties(total), true); if (null != searchAllResult && searchAllResult.isSucceeded()) { for (Hit<Property, Void> property : searchAllResult.getHits(Property.class)) { mapOfProperties.put(property.source.getName(), property.source); } } } return mapOfProperties; }
@Test public void testValidateFunctionIndex() { SearchResult jestResult = mock(SearchResult.class); // Build mocks when(jestClientHelper.execute(any())).thenReturn(jestResult); when(jestResult.getSourceAsString()).thenReturn(""); indexFunctionsDao.validateDocumentIndex("INDEX_NAME", "DOCUMENT_TYPE", "ID", "JSON"); // Verify the calls to external methods verify(jestClientHelper, times(2)).execute(any()); verify(jestResult).getSourceAsString(); verify(jestResult).isSucceeded(); verifyNoMoreInteractions(jestClientHelper); }
@SuppressWarnings({ "rawtypes" }) public Set<String> getFeatureTechIdByGroup(String groupName) { SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); searchSourceBuilder.query(QueryBuilders.matchQuery("group", groupName)); Search search = new Search.Builder(searchSourceBuilder.toString()) // .addIndex(connection.getIndexName()) // .addType(ElasticConstants.TYPE_FEATURE) // .build(); SearchResult result = connection.search(search, true); Set<String> metadatas = new HashSet<String>(); if (null != result && result.isSucceeded()) { List<Hit<Map, Void>> features = result.getHits(Map.class); for (Hit<Map, Void> hit : features) { metadatas.add(hit.source.get(JestResult.ES_METADATA_ID).toString()); } } return metadatas; }
@Test public void testDeleteIndexDocumentsFunctionWithFailures() { SearchResult jestResult = mock(SearchResult.class); JestResult jestResultAliases = mock(JestResult.class); JsonObject jsonObject = new JsonObject(); jsonObject.addProperty("INDEX_NAME_1", "INDEX_NAME"); jsonObject.addProperty("INDEX_NAME_2", "INDEX_NAME"); // Build mocks when(jestClientHelper.execute(any())).thenReturn(jestResult); when(jestResult.isSucceeded()).thenReturn(false); when(jestClientHelper.execute(any())).thenReturn(jestResultAliases); when(jestResultAliases.isSucceeded()).thenReturn(true); when(jestResultAliases.getJsonObject()).thenReturn(jsonObject); // Call the method under test List<Integer> businessObjectDefinitionIds = new ArrayList<>(); businessObjectDefinitionIds.add(1); indexFunctionsDao.deleteIndexDocuments("INDEX_NAME", "DOCUMENT_TYPE", businessObjectDefinitionIds); // Verify the calls to external methods verify(jestClientHelper, times(3)).execute(any()); verifyNoMoreInteractions(jestClientHelper); }
@Test public void testUpdateIndexDocumentsFunctionWithFailures() { SearchResult jestResult = mock(SearchResult.class); JestResult jestResultAliases = mock(JestResult.class); JsonObject jsonObject = new JsonObject(); jsonObject.addProperty("INDEX_NAME_1", "INDEX_NAME"); jsonObject.addProperty("INDEX_NAME_2", "INDEX_NAME"); // Build mocks when(jestClientHelper.execute(any())).thenReturn(jestResult); when(jestResult.isSucceeded()).thenReturn(false); when(jestClientHelper.execute(any())).thenReturn(jestResultAliases); when(jestResultAliases.isSucceeded()).thenReturn(true); when(jestResultAliases.getJsonObject()).thenReturn(jsonObject); // Call the method under test Map<String, String> documentMap = new HashMap<>(); documentMap.put("1", "JSON"); indexFunctionsDao.updateIndexDocuments("INDEX_NAME", "DOCUMENT_TYPE", documentMap); // Verify the calls to external methods verify(jestClientHelper, times(3)).execute(any()); verifyNoMoreInteractions(jestClientHelper); } }
@Test public void testDeleteIndexDocumentsFunction() { SearchResult jestResult = mock(SearchResult.class); JestResult jestResultAliases = mock(JestResult.class); JsonObject jsonObject = new JsonObject(); jsonObject.addProperty("INDEX_NAME_1", "INDEX_NAME"); jsonObject.addProperty("INDEX_NAME_2", "INDEX_NAME"); // Build mocks when(jestClientHelper.execute(any())).thenReturn(jestResult); when(jestResult.isSucceeded()).thenReturn(true); when(jestClientHelper.execute(any())).thenReturn(jestResultAliases); when(jestResultAliases.isSucceeded()).thenReturn(true); when(jestResultAliases.getJsonObject()).thenReturn(jsonObject); // Call the method under test List<Integer> businessObjectDefinitionIds = new ArrayList<>(); businessObjectDefinitionIds.add(1); indexFunctionsDao.deleteIndexDocuments("INDEX_NAME", "DOCUMENT_TYPE", businessObjectDefinitionIds); // Verify the calls to external methods verify(jestClientHelper, times(3)).execute(any()); verifyNoMoreInteractions(jestClientHelper); }
@Test public void testUpdateIndexDocumentsFunction() { SearchResult jestResult = mock(SearchResult.class); JestResult jestResultAliases = mock(JestResult.class); JsonObject jsonObject = new JsonObject(); jsonObject.addProperty("INDEX_NAME_1", "INDEX_NAME"); jsonObject.addProperty("INDEX_NAME_2", "INDEX_NAME"); // Build mocks when(jestClientHelper.execute(any())).thenReturn(jestResult); when(jestResult.isSucceeded()).thenReturn(true); when(jestClientHelper.execute(any())).thenReturn(jestResultAliases); when(jestResultAliases.isSucceeded()).thenReturn(true); when(jestResultAliases.getJsonObject()).thenReturn(jsonObject); // Call the method under test Map<String, String> documentMap = new HashMap<>(); documentMap.put("1", "JSON"); indexFunctionsDao.updateIndexDocuments("INDEX_NAME", "DOCUMENT_TYPE", documentMap); // Verify the calls to external methods verify(jestClientHelper, times(3)).execute(any()); verifyNoMoreInteractions(jestClientHelper); }
@Test public void testCreateIndexDocumentsFunctionWithFailures() { SearchResult jestResult = mock(SearchResult.class); JestResult jestResultAliases = mock(JestResult.class); JsonObject jsonObject = new JsonObject(); jsonObject.addProperty("INDEX_NAME_1", "INDEX_NAME"); jsonObject.addProperty("INDEX_NAME_2", "INDEX_NAME"); // Build mocks when(jestClientHelper.execute(any())).thenReturn(jestResult); when(jestClientHelper.execute(any())).thenReturn(jestResultAliases); when(jestResultAliases.isSucceeded()).thenReturn(true); when(jestResultAliases.getJsonObject()).thenReturn(jsonObject); when(jestResult.isSucceeded()).thenReturn(false); Map<String, String> documentMap = new HashMap<>(); documentMap.put("1", "JSON"); indexFunctionsDao.createIndexDocuments("INDEX_NAME", "DOCUMENT_TYPE", documentMap); verify(jestClientHelper, times(3)).execute(any()); verify(jestResultAliases).getJsonObject(); verifyNoMoreInteractions(jestClientHelper); }
@Test public void testCreateIndexDocumentsFunction() { SearchResult jestResult = mock(SearchResult.class); JestResult jestResultAliases = mock(JestResult.class); JsonObject jsonObject = new JsonObject(); jsonObject.addProperty("INDEX_NAME_1", "INDEX_NAME"); jsonObject.addProperty("INDEX_NAME_2", "INDEX_NAME"); // Build mocks when(jestClientHelper.execute(any())).thenReturn(jestResult); when(jestResult.isSucceeded()).thenReturn(true); when(jestClientHelper.execute(any())).thenReturn(jestResultAliases); when(jestResultAliases.isSucceeded()).thenReturn(true); when(jestResultAliases.getJsonObject()).thenReturn(jsonObject); Map<String, String> documentMap = new HashMap<>(); documentMap.put("1", "JSON"); indexFunctionsDao.createIndexDocuments("INDEX_NAME", "DOCUMENT_TYPE", documentMap); verify(jestClientHelper, times(3)).execute(any()); verify(jestResultAliases).getJsonObject(); verifyNoMoreInteractions(jestClientHelper); }
@SuppressWarnings({ "unchecked", "rawtypes" }) private void fetch() throws StorageException { try { Builder builder = new SearchScroll.Builder(scrollId, "1m"); SearchScroll scroll = new SearchScroll(builder) { @Override public JestResult createNewElasticSearchResult(String responseBody, int statusCode, String reasonPhrase, Gson gson) { return createNewElasticSearchResult(new SearchResult(gson), responseBody, statusCode, reasonPhrase, gson); } }; SearchResult response = (SearchResult) esClient.execute(scroll); if (!response.isSucceeded()) { throw new StorageException("Scrolled fetch failed " + response.getErrorMessage()); } this.hits = (List) response.getHits(Map.class); } catch (IOException e) { throw new StorageException(e); } }
@SuppressWarnings({ "unchecked", "rawtypes" }) private void fetch() throws StorageException { try { Builder builder = new SearchScroll.Builder(scrollId, "1m"); SearchScroll scroll = new SearchScroll(builder) { @Override public JestResult createNewElasticSearchResult(String responseBody, int statusCode, String reasonPhrase, Gson gson) { return createNewElasticSearchResult(new SearchResult(gson), responseBody, statusCode, reasonPhrase, gson); } }; SearchResult response = (SearchResult) esClient.execute(scroll); if (!response.isSucceeded()) { throw new StorageException("Scrolled fetch failed " + response.getErrorMessage()); } this.hits = (List) response.getHits(Map.class); } catch (IOException e) { throw new StorageException(e); } }
private void initScroll() throws StorageException { try { Search search = new Search.Builder(query) .addIndex(getIndexName()) .addType(entityType) .setParameter(Parameters.SCROLL, "1m") .addSort(sort) .build(); SearchResult response = esClient.execute(search); if (!response.isSucceeded()) { throw new StorageException("Scrolled query failed " + response.getErrorMessage()); } scrollId = response.getJsonObject().get("_scroll_id").getAsString(); this.hits = (List) response.getHits(Map.class); } catch (IOException e) { throw new StorageException(e); } }
private void initScroll() throws StorageException { try { Search search = new Search.Builder(query) .addIndex(getIndexName()) .addType(entityType) .setParameter(Parameters.SCROLL, "1m") .addSort(sort) .build(); SearchResult response = esClient.execute(search); if (!response.isSucceeded()) { throw new StorageException("Scrolled query failed " + response.getErrorMessage()); } scrollId = response.getJsonObject().get("_scroll_id").getAsString(); this.hits = (List) response.getHits(Map.class); } catch (IOException e) { throw new StorageException(e); } }
@Override public void purgeAuditTrail(EventQueryDefinition query) { SearchResult result = getConnection().search(getBuilder().queryReadAllEvents(), true); if (result != null && result.isSucceeded()) { for (Hit<Event, Void> event : result.getHits(Event.class)) { getConnection().execute(getBuilder().queryDeleteEvent(event.source.getUuid())); } } }