case SEARCH_INDEX_UPDATE_TYPE_DELETE: indexFunctionsDao.deleteIndexDocuments(indexName, documentType, ids.subList(fromIndex, toIndex)); break; default:
case SEARCH_INDEX_UPDATE_TYPE_DELETE: indexFunctionsDao.deleteIndexDocuments(indexName, documentType, ids.subList(fromIndex, toIndex)); break; default:
@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 testUpdateSearchIndexDocumentTagDelete() 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())); // Delete from the search index SearchIndexUpdateDto searchIndexUpdateDto = new SearchIndexUpdateDto(MESSAGE_TYPE_TAG_UPDATE, tagIds, SEARCH_INDEX_UPDATE_TYPE_DELETE); // Mock the call to external methods when(configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class)).thenReturn("DOCUMENT_TYPE"); doNothing().when(indexFunctionsDao).deleteIndexDocuments(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(indexFunctionsDao, times(1)).deleteIndexDocuments(any(), any(), any()); }
@Test public void testUpdateSearchIndexDocumentBusinessObjectDefinitionDelete() { List<BusinessObjectDefinitionEntity> businessObjectDefinitionEntityList = new ArrayList<>(); businessObjectDefinitionEntityList.add(businessObjectDefinitionDaoTestHelper .createBusinessObjectDefinitionEntity(NAMESPACE, BDEF_NAME, DATA_PROVIDER_NAME, BDEF_DESCRIPTION, businessObjectDefinitionServiceTestHelper.getNewAttributes())); businessObjectDefinitionEntityList.add(businessObjectDefinitionDaoTestHelper .createBusinessObjectDefinitionEntity(NAMESPACE, BDEF_NAME_2, DATA_PROVIDER_NAME_2, BDEF_DESCRIPTION_2, businessObjectDefinitionServiceTestHelper.getNewAttributes())); List<Integer> businessObjectDefinitionIds = new ArrayList<>(); businessObjectDefinitionEntityList.forEach(businessObjectDefinitionEntity -> businessObjectDefinitionIds.add(businessObjectDefinitionEntity.getId())); // Delete from the search index SearchIndexUpdateDto searchIndexUpdateDto = new SearchIndexUpdateDto(MESSAGE_TYPE_BUSINESS_OBJECT_DEFINITION_UPDATE, businessObjectDefinitionIds, SEARCH_INDEX_UPDATE_TYPE_DELETE); // Mock the call to external methods when(configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_INDEX_NAME, String.class)).thenReturn(SEARCH_INDEX_NAME); when(configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class)).thenReturn(SEARCH_INDEX_DOCUMENT_TYPE); // Call the method under test businessObjectDefinitionService.updateSearchIndexDocumentBusinessObjectDefinition(searchIndexUpdateDto); // Verify the calls to external methods verify(configurationHelper).getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_INDEX_NAME, String.class); verify(configurationHelper).getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class); verify(indexFunctionsDao).deleteIndexDocuments(any(), any(), any()); verifyNoMoreInteractionsHelper(); }