congrats Icon
New! Announcing Tabnine Chat Beta
Learn More
Tabnine Logo
ElasticSearchIndexer
Code IndexAdd Tabnine to your IDE (free)

How to use
ElasticSearchIndexer
in
org.apache.james.backends.es

Best Java code snippets using org.apache.james.backends.es.ElasticSearchIndexer (Showing top 18 results out of 315)

origin: org.apache.james/apache-james-mailbox-quota-search-elasticsearch

private void handleEvent(User user, QuotaUsageUpdatedEvent event) throws JsonProcessingException {
  indexer.index(user.getUserName(), 
      quotaRatioToElasticSearchJson.convertToJson(user.getUserName(), event));
}
origin: org.apache.james/apache-james-mailbox-elasticsearch

@Override
public void delete(MailboxSession session, Mailbox mailbox, List<MessageUid> expungedUids) throws MailboxException {
  try {
    elasticSearchIndexer.delete(expungedUids.stream()
      .map(uid ->  indexIdFor(mailbox, uid))
      .collect(Collectors.toList()));
  } catch (Exception e) {
    if (LOGGER.isErrorEnabled()) {
      LOGGER.error("Error when deleting messages {} in mailbox {} from index", mailbox.getMailboxId().serialize(), expungedUids.toArray(), e);
    }
  }
}
origin: org.apache.james/apache-james-mailbox-elasticsearch

@Override
public void deleteAll(MailboxSession session, Mailbox mailbox) throws MailboxException {
  try {
    elasticSearchIndexer.deleteAllMatchingQuery(
      termQuery(
        JsonMessageConstants.MAILBOX_ID,
        mailbox.getMailboxId().serialize()));
  } catch (Exception e) {
    LOGGER.error("Error when deleting all messages in mailbox {}", mailbox.getMailboxId().serialize(), e);
  }
}
origin: org.apache.james/apache-james-mailbox-elasticsearch

@Override
public void update(MailboxSession session, Mailbox mailbox, List<UpdatedFlags> updatedFlagsList) throws MailboxException {
  try {
    elasticSearchIndexer.update(updatedFlagsList.stream()
      .map(updatedFlags -> createUpdatedDocumentPartFromUpdatedFlags(mailbox, updatedFlags))
      .collect(Collectors.toList()));
  } catch (Exception e) {
    LOGGER.error("Error when updating index on mailbox {}", mailbox.getMailboxId().serialize(), e);
  }
}
origin: org.apache.james/apache-james-mailbox-quota-search-elasticsearch

@Before
public void setUp() {
  client = QuotaSearchIndexCreationUtil.prepareDefaultClient(
    new TestingClientProvider(embeddedElasticSearch.getNode()).get());
  quotaMailboxListener = new ElasticSearchQuotaMailboxListener(
    new ElasticSearchIndexer(client,
      Executors.newSingleThreadExecutor(),
      QuotaRatioElasticSearchConstants.DEFAULT_QUOTA_RATIO_WRITE_ALIAS,
      QuotaRatioElasticSearchConstants.QUOTA_RATIO_TYPE,
      BATCH_SIZE),
    new QuotaRatioToElasticSearchJson());
}
origin: org.apache.james/apache-james-backends-es

public IndexResponse index(String id, String content) {
  checkArgument(content);
  if (LOGGER.isDebugEnabled()) {
    LOGGER.debug("Indexing {}: {}", id, StringUtils.left(content, DEBUG_MAX_LENGTH_CONTENT));
  }
  return client.prepareIndex(aliasName.getValue(), typeName.getValue(), id)
    .setSource(content)
    .get();
}
origin: org.apache.james/apache-james-mailbox-elasticsearch

@Test
public void updateShouldWork() throws Exception {
  //Given
  Mailbox mailbox = mock(Mailbox.class);
  Flags flags = new Flags();
  UpdatedFlags updatedFlags = UpdatedFlags.builder()
    .uid(MESSAGE_UID)
    .modSeq(MODSEQ)
    .oldFlags(flags)
    .newFlags(flags)
    .build();
  when(mailbox.getMailboxId())
    .thenReturn(MAILBOX_ID);
  when(messageToElasticSearchJson.getUpdatedJsonMessagePart(any(Flags.class), any(Long.class)))
    .thenReturn("json updated content");
  
  //When
  testee.update(session, mailbox, Lists.newArrayList(updatedFlags));
  
  //Then
  ImmutableList<UpdatedRepresentation> expectedUpdatedRepresentations = ImmutableList.of(new UpdatedRepresentation(ELASTIC_SEARCH_ID, "json updated content"));
  verify(elasticSearchIndexer).update(expectedUpdatedRepresentations);
}
origin: org.apache.james/apache-james-mailbox-quota-search-elasticsearch

new ElasticSearchIndexer(client, Executors.newSingleThreadExecutor(),
  QuotaRatioElasticSearchConstants.DEFAULT_QUOTA_RATIO_WRITE_ALIAS,
  QuotaRatioElasticSearchConstants.QUOTA_RATIO_TYPE),
origin: org.apache.james/apache-james-mailbox-elasticsearch

@Test
public void addShouldIndexEmailBodyWhenNotIndexableAttachment() throws Exception {
  //Given
  Mailbox mailbox = mock(Mailbox.class);
  when(mailbox.getMailboxId())
    .thenReturn(MAILBOX_ID);
  
  MailboxMessage message = mockedMessage(MESSAGE_UID);
  
  when(messageToElasticSearchJson.convertToJson(eq(message), eq(users)))
    .thenThrow(JsonProcessingException.class);
  
  when(messageToElasticSearchJson.convertToJsonWithoutAttachment(eq(message), eq(users)))
    .thenReturn(EXPECTED_JSON_CONTENT);
  
  //When
  testee.add(session, mailbox, message);
  
  //Then
  verify(elasticSearchIndexer).index(eq(ELASTIC_SEARCH_ID), eq(EXPECTED_JSON_CONTENT));
}
origin: org.apache.james/apache-james-mailbox-elasticsearch

@Test
@SuppressWarnings("unchecked")
public void deleteShouldWork() throws Exception {
  //Given
  Mailbox mailbox = mock(Mailbox.class);
  when(mailbox.getMailboxId())
    .thenReturn(MAILBOX_ID);
  BulkResponse expectedBulkResponse = mock(BulkResponse.class);
  when(elasticSearchIndexer.delete(any(List.class)))
    .thenReturn(Optional.of(expectedBulkResponse));
  //When
  testee.delete(session, mailbox, Lists.newArrayList(MESSAGE_UID));
  //Then
  verify(elasticSearchIndexer).delete(eq(Lists.newArrayList(ELASTIC_SEARCH_ID)));
}
origin: org.apache.james/apache-james-mailbox-elasticsearch

@Test
public void updateShouldNotPropagateExceptionWhenExceptionOccurs() throws Exception {
  //Given
  Mailbox mailbox = mock(Mailbox.class);
  Flags flags = new Flags();
  UpdatedFlags updatedFlags = UpdatedFlags.builder()
    .uid(MESSAGE_UID)
    .modSeq(MODSEQ)
    .oldFlags(flags)
    .newFlags(flags)
    .build();
  when(mailbox.getMailboxId())
    .thenReturn(MAILBOX_ID);
  ImmutableList<UpdatedRepresentation> expectedUpdatedRepresentations = ImmutableList.of(new UpdatedRepresentation(ELASTIC_SEARCH_ID, "json updated content"));
  when(elasticSearchIndexer.update(expectedUpdatedRepresentations))
    .thenThrow(new ElasticsearchException(""));
  
  //When
  testee.update(session, mailbox, Lists.newArrayList(updatedFlags));
  
  //Then
  //No exception
}
origin: org.apache.james/apache-james-mailbox-elasticsearch

@Override
protected void initializeMailboxManager() throws Exception {
  Client client = MailboxIndexCreationUtil.prepareDefaultClient(
    new TestingClientProvider(embeddedElasticSearch.getNode()).get());
  storeMailboxManager = new InMemoryIntegrationResources()
    .createMailboxManager(new SimpleGroupMembershipResolver());
  ElasticSearchListeningMessageSearchIndex elasticSearchListeningMessageSearchIndex = new ElasticSearchListeningMessageSearchIndex(
    storeMailboxManager.getMapperFactory(),
    new ElasticSearchIndexer(client,
      Executors.newSingleThreadExecutor(),
      MailboxElasticSearchConstants.DEFAULT_MAILBOX_WRITE_ALIAS,
      MailboxElasticSearchConstants.MESSAGE_TYPE,
      BATCH_SIZE),
    new ElasticSearchSearcher(client, new QueryConverter(new CriterionConverter()), SEARCH_SIZE,
      new InMemoryId.Factory(), storeMailboxManager.getMessageIdFactory(),
      MailboxElasticSearchConstants.DEFAULT_MAILBOX_READ_ALIAS,
      MailboxElasticSearchConstants.MESSAGE_TYPE),
    new MessageToElasticSearchJson(textExtractor, ZoneId.of("Europe/Paris"), IndexAttachments.YES));
  messageIdManager = new StoreMessageIdManager(
    storeMailboxManager,
    storeMailboxManager.getMapperFactory(),
    storeMailboxManager.getEventDispatcher(),
    storeMailboxManager.getMessageIdFactory(),
    storeMailboxManager.getQuotaManager(),
    storeMailboxManager.getQuotaRootResolver());
  storeMailboxManager.setMessageSearchIndex(elasticSearchListeningMessageSearchIndex);
  storeMailboxManager.addGlobalListener(elasticSearchListeningMessageSearchIndex, new MockMailboxSession("admin"));
  this.messageSearchIndex = elasticSearchListeningMessageSearchIndex;
}
origin: org.apache.james/apache-james-mailbox-elasticsearch

@Test
public void deleteAllShouldNotPropagateExceptionWhenExceptionOccurs() throws Exception {
  //Given
  Mailbox mailbox = mock(Mailbox.class);
  when(mailbox.getMailboxId())
    .thenReturn(MAILBOX_ID);
  doThrow(RuntimeException.class)
    .when(elasticSearchIndexer).deleteAllMatchingQuery(QueryBuilders.termQuery("mailboxId", "12"));
  //When
  testee.deleteAll(session, mailbox);
  
  //Then
  //No Exception
}
origin: org.apache.james/apache-james-mailbox-elasticsearch

@Test
public void addShouldIndex() throws Exception {
  //Given
  Mailbox mailbox = mock(Mailbox.class);
  when(mailbox.getMailboxId())
    .thenReturn(MAILBOX_ID);
  MailboxMessage message = mockedMessage(MESSAGE_UID);
  
  when(messageToElasticSearchJson.convertToJson(eq(message), eq(users)))
    .thenReturn(EXPECTED_JSON_CONTENT);
  
  //When
  testee.add(session, mailbox, message);
  
  //Then
  verify(elasticSearchIndexer).index(eq(ELASTIC_SEARCH_ID), eq(EXPECTED_JSON_CONTENT));
}
origin: org.apache.james/apache-james-mailbox-elasticsearch

@Test
@SuppressWarnings("unchecked")
public void deleteShouldNotPropagateExceptionWhenExceptionOccurs() throws Exception {
  //Given
  Mailbox mailbox = mock(Mailbox.class);
  when(mailbox.getMailboxId())
    .thenReturn(MAILBOX_ID);
  
  when(elasticSearchIndexer.delete(any(List.class)))
    .thenThrow(new ElasticsearchException(""));
  
  //When
  testee.delete(session, mailbox, Lists.newArrayList(MESSAGE_UID));
  
  //Then
  //No exception
}
origin: org.apache.james/apache-james-mailbox-elasticsearch

@Test
public void deleteAllShouldWork() throws Exception {
  //Given
  Mailbox mailbox = mock(Mailbox.class);
  when(mailbox.getMailboxId())
    .thenReturn(MAILBOX_ID);
  //When
  testee.deleteAll(session, mailbox);
  
  //Then
  QueryBuilder expectedQueryBuilder = QueryBuilders.termQuery("mailboxId", "12");
  verify(elasticSearchIndexer).deleteAllMatchingQuery(refEq(expectedQueryBuilder));
}
origin: org.apache.james/apache-james-mailbox-elasticsearch

@Override
public void add(MailboxSession session, Mailbox mailbox, MailboxMessage message) throws MailboxException {
  try {
    LOGGER.info("Indexing mailbox {}-{} of user {} on message {}",
        mailbox.getName(),
        mailbox.getMailboxId(),
        session.getUser().getUserName(),
        message.getUid());
    elasticSearchIndexer.index(indexIdFor(mailbox, message.getUid()), messageToElasticSearchJson.convertToJson(message, ImmutableList.of(session.getUser())));
  } catch (Exception e) {
    try {
      LOGGER.warn("Indexing mailbox {}-{} of user {} on message {} without attachments ",
          mailbox.getName(),
          mailbox.getMailboxId().serialize(),
          session.getUser().getUserName(),
          message.getUid(),
          e);
      elasticSearchIndexer.index(indexIdFor(mailbox, message.getUid()), messageToElasticSearchJson.convertToJsonWithoutAttachment(message, ImmutableList.of(session.getUser())));
    } catch (JsonProcessingException e1) {
      LOGGER.error("Error when indexing mailbox {}-{} of user {} on message {} without its attachment",
          mailbox.getName(),
          mailbox.getMailboxId().serialize(),
          session.getUser().getUserName(),
          message.getUid(),
          e1);
    }
  }
}

origin: org.apache.james/apache-james-mailbox-elasticsearch

@Test
@SuppressWarnings("unchecked")
public void deleteShouldWorkWhenMultipleMessageIds() throws Exception {
  //Given
  Mailbox mailbox = mock(Mailbox.class);
  MessageUid messageId2 = MessageUid.of(2);
  MessageUid messageId3 = MessageUid.of(3);
  MessageUid messageId4 = MessageUid.of(4);
  MessageUid messageId5 = MessageUid.of(5);
  when(mailbox.getMailboxId())
    .thenReturn(MAILBOX_ID);
  BulkResponse expectedBulkResponse = mock(BulkResponse.class);
  when(elasticSearchIndexer.delete(any(List.class)))
    .thenReturn(Optional.of(expectedBulkResponse));
  
  //When
  testee.delete(session, mailbox, Lists.newArrayList(MESSAGE_UID, messageId2, messageId3, messageId4, messageId5));
  
  //Then
  verify(elasticSearchIndexer).delete(eq(Lists.newArrayList(ELASTIC_SEARCH_ID, "12:2", "12:3", "12:4", "12:5")));
}
org.apache.james.backends.esElasticSearchIndexer

Most used methods

  • index
  • <init>
  • delete
  • deleteAllMatchingQuery
  • update
  • checkArgument

Popular in Java

  • Start an intent from android
  • orElseThrow (Optional)
    Return the contained value, if present, otherwise throw an exception to be created by the provided s
  • notifyDataSetChanged (ArrayAdapter)
  • setRequestProperty (URLConnection)
  • Pointer (com.sun.jna)
    An abstraction for a native pointer data type. A Pointer instance represents, on the Java side, a na
  • BorderLayout (java.awt)
    A border layout lays out a container, arranging and resizing its components to fit in five regions:
  • Color (java.awt)
    The Color class is used to encapsulate colors in the default sRGB color space or colors in arbitrary
  • System (java.lang)
    Provides access to system-related information and resources including standard input and output. Ena
  • SecureRandom (java.security)
    This class generates cryptographically secure pseudo-random numbers. It is best to invoke SecureRand
  • AtomicInteger (java.util.concurrent.atomic)
    An int value that may be updated atomically. See the java.util.concurrent.atomic package specificati
  • Top PhpStorm plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now