@Override public void updateSearchIndexDocumentTag(SearchIndexUpdateDto searchIndexUpdateDto) { final String indexName = SearchIndexTypeEntity.SearchIndexTypes.TAG.name().toLowerCase(); final String documentType = configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class); String modificationType = searchIndexUpdateDto.getModificationType(); List<Integer> ids = searchIndexUpdateDto.getTagIds(); LOGGER.info("Updating the search index document representation(s) of the tag(s)." + " tagIds=[{}], searchIndexUpdateType=\"{}\"", ids.stream().map(String::valueOf).collect(Collectors.joining(", ")), modificationType); // Switch on the type of CRUD modification to be done switch (modificationType) { case SEARCH_INDEX_UPDATE_TYPE_CREATE: // Create a search index document indexFunctionsDao.createIndexDocuments(indexName, documentType, convertTagEntityListToJSONStringMap(tagDao.getTagsByIds(ids))); break; case SEARCH_INDEX_UPDATE_TYPE_UPDATE: // Update a search index document indexFunctionsDao.updateIndexDocuments(indexName, documentType, convertTagEntityListToJSONStringMap(tagDao.getTagsByIds(ids))); break; case SEARCH_INDEX_UPDATE_TYPE_DELETE: // Delete a search index document indexFunctionsDao.deleteIndexDocuments(indexName, documentType, ids); break; default: LOGGER.warn("Unknown modification type received."); break; } }
@Override public void updateSearchIndexDocumentTag(SearchIndexUpdateDto searchIndexUpdateDto) { final String indexName = SearchIndexTypeEntity.SearchIndexTypes.TAG.name().toLowerCase(); final String documentType = configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class); String modificationType = searchIndexUpdateDto.getModificationType(); List<Integer> ids = searchIndexUpdateDto.getTagIds(); LOGGER.info("Updating the search index document representation(s) of the tag(s)." + " tagIds=[{}], searchIndexUpdateType=\"{}\"", ids.stream().map(String::valueOf).collect(Collectors.joining(", ")), modificationType); // Switch on the type of CRUD modification to be done switch (modificationType) { case SEARCH_INDEX_UPDATE_TYPE_CREATE: // Create a search index document indexFunctionsDao.createIndexDocuments(indexName, documentType, convertTagEntityListToJSONStringMap(tagDao.getTagsByIds(ids))); break; case SEARCH_INDEX_UPDATE_TYPE_UPDATE: // Update a search index document indexFunctionsDao.updateIndexDocuments(indexName, documentType, convertTagEntityListToJSONStringMap(tagDao.getTagsByIds(ids))); break; case SEARCH_INDEX_UPDATE_TYPE_DELETE: // Delete a search index document indexFunctionsDao.deleteIndexDocuments(indexName, documentType, ids); break; default: LOGGER.warn("Unknown modification type received."); break; } }
@Test public void testUpdateSearchIndexDocumentTagUpdate() throws Exception { List<TagEntity> tagEntityList = new ArrayList<>(); TagEntity tagEntity1 = tagDaoTestHelper.createTagEntity(new TagKey(TAG_TYPE, TAG_CODE), TAG_DISPLAY_NAME, TAG_DESCRIPTION); TagEntity tagEntity2 = tagDaoTestHelper.createTagEntity(new TagKey(TAG_TYPE_2, TAG_CODE_2), TAG_DISPLAY_NAME_2, TAG_DESCRIPTION_2); tagEntityList.add(tagEntity1); tagEntityList.add(tagEntity2); List<Integer> tagIds = new ArrayList<>(); tagEntityList.forEach(tagEntity -> tagIds.add(tagEntity.getId())); // Create a document on the search index SearchIndexUpdateDto searchIndexUpdateDto = new SearchIndexUpdateDto(MESSAGE_TYPE_TAG_UPDATE, tagIds, SEARCH_INDEX_UPDATE_TYPE_UPDATE); // Mock the call to external methods when(configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class)).thenReturn("DOCUMENT_TYPE"); when(tagDao.getTagsByIds(tagIds)).thenReturn(tagEntityList); when(tagHelper.safeObjectMapperWriteValueAsString(any(TagEntity.class))).thenReturn("JSON_STRING"); // Call the method under test tagService.updateSearchIndexDocumentTag(searchIndexUpdateDto); // Verify the calls to external methods verify(configurationHelper, times(1)).getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class); verify(tagDao, times(1)).getTagsByIds(tagIds); verify(tagHelper, times(2)).safeObjectMapperWriteValueAsString(any(TagEntity.class)); verify(indexFunctionsDao, times(1)).updateIndexDocuments(any(), any(), any()); }
@Test public void testGetTagsByIds() { // Create two tag type entities List<TagTypeEntity> tagTypeEntities = Arrays .asList(tagTypeDaoTestHelper.createTagTypeEntity(TAG_TYPE, TAG_TYPE_DISPLAY_NAME, TAG_TYPE_ORDER, TAG_DESCRIPTION), tagTypeDaoTestHelper.createTagTypeEntity(TAG_TYPE_2, TAG_TYPE_DISPLAY_NAME_2, TAG_TYPE_ORDER_2, TAG_DESCRIPTION_2)); // Create two root tag entities for each tag type List<TagEntity> tagEntities = Arrays.asList(tagDaoTestHelper.createTagEntity(tagTypeEntities.get(0), TAG_CODE, TAG_DISPLAY_NAME, TAG_DESCRIPTION), tagDaoTestHelper.createTagEntity(tagTypeEntities.get(0), TAG_CODE_2, TAG_DISPLAY_NAME_2, TAG_DESCRIPTION_2), tagDaoTestHelper.createTagEntity(tagTypeEntities.get(1), TAG_CODE_3, TAG_DISPLAY_NAME_3, TAG_DESCRIPTION_3), tagDaoTestHelper.createTagEntity(tagTypeEntities.get(1), TAG_CODE_4, TAG_DISPLAY_NAME_4, TAG_DESCRIPTION_4)); List<Integer> tagIds = new ArrayList<>(); tagEntities.forEach(tagEntity -> tagIds.add(tagEntity.getId())); // Get all tags. assertEquals(Arrays.asList(tagEntities.get(0), tagEntities.get(1), tagEntities.get(2), tagEntities.get(3)), tagDao.getTagsByIds(tagIds)); }
@Test public void testUpdateSearchIndexDocumentTagCreateEmpty() throws Exception { List<TagEntity> tagEntityList = new ArrayList<>(); TagEntity tagEntity1 = tagDaoTestHelper.createTagEntity(new TagKey(TAG_TYPE, TAG_CODE), TAG_DISPLAY_NAME, TAG_DESCRIPTION); TagEntity tagEntity2 = tagDaoTestHelper.createTagEntity(new TagKey(TAG_TYPE_2, TAG_CODE_2), TAG_DISPLAY_NAME_2, TAG_DESCRIPTION_2); tagEntityList.add(tagEntity1); tagEntityList.add(tagEntity2); List<Integer> tagIds = new ArrayList<>(); tagEntityList.forEach(tagEntity -> tagIds.add(tagEntity.getId())); // Create a document on the search index SearchIndexUpdateDto searchIndexUpdateDto = new SearchIndexUpdateDto(MESSAGE_TYPE_TAG_UPDATE, tagIds, SEARCH_INDEX_UPDATE_TYPE_CREATE); // Mock the call to external methods when(configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class)).thenReturn("DOCUMENT_TYPE"); when(tagDao.getTagsByIds(tagIds)).thenReturn(tagEntityList); when(tagHelper.safeObjectMapperWriteValueAsString(any(TagEntity.class))).thenReturn(""); doNothing().when(indexFunctionsDao).createIndexDocuments(any(), any(), any()); // Call the method under test tagService.updateSearchIndexDocumentTag(searchIndexUpdateDto); // Verify the calls to external methods verify(configurationHelper, times(1)).getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class); verify(tagDao, times(1)).getTagsByIds(tagIds); verify(tagHelper, times(2)).safeObjectMapperWriteValueAsString(any(TagEntity.class)); verify(indexFunctionsDao, times(1)).createIndexDocuments(any(), any(), any()); }
@Test public void testUpdateSearchIndexDocumentTagUpdateEmpty() throws Exception { List<TagEntity> tagEntityList = new ArrayList<>(); TagEntity tagEntity1 = tagDaoTestHelper.createTagEntity(new TagKey(TAG_TYPE, TAG_CODE), TAG_DISPLAY_NAME, TAG_DESCRIPTION); TagEntity tagEntity2 = tagDaoTestHelper.createTagEntity(new TagKey(TAG_TYPE_2, TAG_CODE_2), TAG_DISPLAY_NAME_2, TAG_DESCRIPTION_2); tagEntityList.add(tagEntity1); tagEntityList.add(tagEntity2); List<Integer> tagIds = new ArrayList<>(); tagEntityList.forEach(tagEntity -> tagIds.add(tagEntity.getId())); // Create a document on the search index SearchIndexUpdateDto searchIndexUpdateDto = new SearchIndexUpdateDto(MESSAGE_TYPE_TAG_UPDATE, tagIds, SEARCH_INDEX_UPDATE_TYPE_UPDATE); // Mock the call to external methods when(configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class)).thenReturn("DOCUMENT_TYPE"); when(tagDao.getTagsByIds(tagIds)).thenReturn(tagEntityList); when(tagHelper.safeObjectMapperWriteValueAsString(any(TagEntity.class))).thenReturn(""); // Call the method under test tagService.updateSearchIndexDocumentTag(searchIndexUpdateDto); // Verify the calls to external methods verify(configurationHelper, times(1)).getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class); verify(tagDao, times(1)).getTagsByIds(tagIds); verify(tagHelper, times(2)).safeObjectMapperWriteValueAsString(any(TagEntity.class)); verify(indexFunctionsDao, times(1)).updateIndexDocuments(any(), any(), any()); }
@Test public void testUpdateSearchIndexDocumentTagCreate() throws Exception { List<TagEntity> tagEntityList = new ArrayList<>(); TagEntity tagEntity1 = tagDaoTestHelper.createTagEntity(new TagKey(TAG_TYPE, TAG_CODE), TAG_DISPLAY_NAME, TAG_DESCRIPTION); TagEntity tagEntity2 = tagDaoTestHelper.createTagEntity(new TagKey(TAG_TYPE_2, TAG_CODE_2), TAG_DISPLAY_NAME_2, TAG_DESCRIPTION_2); tagEntityList.add(tagEntity1); tagEntityList.add(tagEntity2); List<Integer> tagIds = new ArrayList<>(); tagEntityList.forEach(tagEntity -> tagIds.add(tagEntity.getId())); // Create a document on the search index SearchIndexUpdateDto searchIndexUpdateDto = new SearchIndexUpdateDto(MESSAGE_TYPE_TAG_UPDATE, tagIds, SEARCH_INDEX_UPDATE_TYPE_CREATE); // Mock the call to external methods when(configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class)).thenReturn("DOCUMENT_TYPE"); when(tagDao.getTagsByIds(tagIds)).thenReturn(tagEntityList); when(tagHelper.safeObjectMapperWriteValueAsString(any(TagEntity.class))).thenReturn("JSON_STRING"); // Call the method under test tagService.updateSearchIndexDocumentTag(searchIndexUpdateDto); // Verify the calls to external methods verify(configurationHelper, times(1)).getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class); verify(tagDao, times(1)).getTagsByIds(tagIds); verify(tagHelper, times(2)).safeObjectMapperWriteValueAsString(any(TagEntity.class)); }