@Override @Async public Future<Void> indexValidateAllTags(String indexName) { final String documentType = configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class); // Get a list of all tags final List<TagEntity> tagEntityList = Collections.unmodifiableList(tagDao.getTags()); // Remove any index documents that are not in the database removeAnyIndexDocumentsThatAreNotInTagsList(indexName, documentType, tagEntityList); // Validate all Tags tagHelper.executeFunctionForTagEntities(indexName, documentType, tagEntityList, indexFunctionsDao::validateDocumentIndex); // Return an AsyncResult so callers will know the future is "done". They can call "isDone" to know when this method has completed and they // can call "get" to see if any exceptions were thrown. return new AsyncResult<>(null); }
tagEntities.addAll(tagDao.getTags());
@Override @Async public Future<Void> indexValidateAllTags(String indexName) { final String documentType = configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class); // Get a list of all tags final List<TagEntity> tagEntityList = Collections.unmodifiableList(tagDao.getTags()); // Remove any index documents that are not in the database removeAnyIndexDocumentsThatAreNotInTagsList(indexName, documentType, tagEntityList); // Validate all Tags tagHelper.executeFunctionForTagEntities(indexName, documentType, tagEntityList, indexFunctionsDao::validateDocumentIndex); // Return an AsyncResult so callers will know the future is "done". They can call "isDone" to know when this method has completed and they // can call "get" to see if any exceptions were thrown. return new AsyncResult<>(null); }
tagEntities.addAll(tagDao.getTags());
@Override @Async public Future<Void> indexAllTags(SearchIndexKey searchIndexKey, String documentType) { // Get a list of all tags final List<TagEntity> tagEntities = Collections.unmodifiableList(tagDao.getTags()); // Index all tags. tagHelper.executeFunctionForTagEntities(searchIndexKey.getSearchIndexName(), documentType, tagEntities, indexFunctionsDao::createIndexDocument); // Simple count validation, index size should equal entity list size. validateSearchIndexSize(searchIndexKey.getSearchIndexName(), documentType, tagEntities.size()); // Update search index status to READY. searchIndexDaoHelper.updateSearchIndexStatus(searchIndexKey, SearchIndexStatusEntity.SearchIndexStatuses.READY.name()); // Return an AsyncResult so callers will know the future is "done". They can call "isDone" to know when this method has completed and they can call // "get" to see if any exceptions were thrown. return new AsyncResult<>(null); }
@Override @Async public Future<Void> indexAllTags(SearchIndexKey searchIndexKey, String documentType) { // Get a list of all tags final List<TagEntity> tagEntities = Collections.unmodifiableList(tagDao.getTags()); // Index all tags. tagHelper.executeFunctionForTagEntities(searchIndexKey.getSearchIndexName(), documentType, tagEntities, indexFunctionsDao::createIndexDocument); // Simple count validation, index size should equal entity list size. validateSearchIndexSize(searchIndexKey.getSearchIndexName(), documentType, tagEntities.size()); // Update search index status to READY. searchIndexDaoHelper.updateSearchIndexStatus(searchIndexKey, SearchIndexStatusEntity.SearchIndexStatuses.READY.name()); // Return an AsyncResult so callers will know the future is "done". They can call "isDone" to know when this method has completed and they can call // "get" to see if any exceptions were thrown. return new AsyncResult<>(null); }
@Test public void testIndexValidateTags() throws Exception { // Create a tag type entity. TagTypeEntity tagTypeEntity = tagTypeDaoTestHelper.createTagTypeEntity(TAG_TYPE, TAG_TYPE_DISPLAY_NAME, TAG_TYPE_ORDER, TAG_TYPE_DESCRIPTION); // Create two root tag entities for the tag type with tag display name in reverse order. List<TagEntity> tagEntityList = Arrays.asList(tagDaoTestHelper.createTagEntity(tagTypeEntity, TAG_CODE, TAG_DISPLAY_NAME_2, TAG_DESCRIPTION), tagDaoTestHelper.createTagEntity(tagTypeEntity, TAG_CODE_2, TAG_DISPLAY_NAME, TAG_DESCRIPTION_2)); List<String> tagEntityIdList = new ArrayList<>(); tagEntityIdList.add("100"); tagEntityIdList.add("101"); tagEntityIdList.add("110"); // Mock the call to external methods when(tagDao.getTags()).thenReturn(tagEntityList); when(tagHelper.safeObjectMapperWriteValueAsString(any(TagEntity.class))).thenReturn("JSON_STRING"); when(configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class)).thenReturn("DOCUMENT_TYPE"); // Call the method under test Future<Void> future = tagService.indexValidateAllTags(SEARCH_INDEX_TYPE_TAG); assertThat("Tag service index all tags method returned null value.", future, not(nullValue())); assertThat("Tag service index all tags method return value is not instance of future.", future, instanceOf(Future.class)); // Verify the calls to external methods verify(tagDao).getTags(); verify(configurationHelper).getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class); verify(tagHelper).executeFunctionForTagEntities(eq("TAG"), eq("DOCUMENT_TYPE"), eq(tagEntityList), any()); }
@Test public void testGetTags() { // Create two tag type entities with tag type order values in reverse order. List<TagTypeEntity> tagTypeEntities = Arrays .asList(tagTypeDaoTestHelper.createTagTypeEntity(TAG_TYPE, TAG_TYPE_DISPLAY_NAME, TAG_TYPE_ORDER_2, TAG_TYPE_DESCRIPTION), tagTypeDaoTestHelper.createTagTypeEntity(TAG_TYPE_2, TAG_TYPE_DISPLAY_NAME, TAG_TYPE_ORDER, TAG_TYPE_DESCRIPTION_2)); // Create two root tag entities for each tag type with tag display name in reverse order. List<TagEntity> tagEntities = Arrays.asList(tagDaoTestHelper.createTagEntity(tagTypeEntities.get(0), TAG_CODE, TAG_DISPLAY_NAME_2, TAG_DESCRIPTION), tagDaoTestHelper.createTagEntity(tagTypeEntities.get(0), TAG_CODE_2, TAG_DISPLAY_NAME, TAG_DESCRIPTION_2), tagDaoTestHelper.createTagEntity(tagTypeEntities.get(1), TAG_CODE_3, TAG_DISPLAY_NAME_4, TAG_DESCRIPTION_3), tagDaoTestHelper.createTagEntity(tagTypeEntities.get(1), TAG_CODE_4, TAG_DISPLAY_NAME_3, TAG_DESCRIPTION_4)); // Get all tags. assertEquals(Arrays.asList(tagEntities.get(3), tagEntities.get(2), tagEntities.get(1), tagEntities.get(0)), tagDao.getTags()); }