Search in sources :

Example 16 with PropertiesProvider

use of org.icij.datashare.PropertiesProvider in project datashare by ICIJ.

the class BatchSearchRunnerIntTest method test_search_with_phraseMatches_with_ner.

@Test
public void test_search_with_phraseMatches_with_ner() throws Exception {
    Document mydoc = createDoc("docId").with("anne's doc to find").build();
    indexer.add(TEST_INDEX, mydoc);
    indexer.add(TEST_INDEX, NamedEntity.create(NamedEntity.Category.PERSON, "anne", asList(12L), mydoc.getId(), mydoc.getRootDocument(), Pipeline.Type.CORENLP, Language.FRENCH));
    BatchSearch searchKo = new BatchSearch(project(TEST_INDEX), "name", "desc", asSet("anne doc"), User.local(), false, null, null, true);
    BatchSearch searchOk = new BatchSearch(project(TEST_INDEX), "name", "desc", asSet("anne's doc"), User.local(), false, null, null, true);
    new BatchSearchRunner(indexer, new PropertiesProvider(), searchKo, resultConsumer).call();
    new BatchSearchRunner(indexer, new PropertiesProvider(), searchOk, resultConsumer).call();
    verify(resultConsumer, never()).apply(eq(searchKo.uuid), eq("anne doc"), anyList());
    verify(resultConsumer).apply(searchOk.uuid, "anne's doc", singletonList(mydoc));
}
Also used : PropertiesProvider(org.icij.datashare.PropertiesProvider) BatchSearch(org.icij.datashare.batch.BatchSearch) Document(org.icij.datashare.text.Document)

Example 17 with PropertiesProvider

use of org.icij.datashare.PropertiesProvider in project datashare by ICIJ.

the class IndexTaskTest method test_index_task_null_user_uses_options_for_index_name.

@Test
public void test_index_task_null_user_uses_options_for_index_name() {
    ElasticsearchSpewer spewer = mock(ElasticsearchSpewer.class);
    new IndexTask(spewer, mock(Publisher.class), mock(DocumentCollectionFactory.class), nullUser(), "queueName", new PropertiesProvider(new HashMap<String, String>() {

        {
            put("redisAddress", "redis://redis:6379");
            put("defaultProject", "foo");
        }
    }).getProperties());
    Mockito.verify(spewer).withIndex("foo");
}
Also used : PropertiesProvider(org.icij.datashare.PropertiesProvider) ElasticsearchSpewer(org.icij.datashare.text.indexing.elasticsearch.ElasticsearchSpewer) Publisher(org.icij.datashare.com.Publisher) Test(org.junit.Test)

Example 18 with PropertiesProvider

use of org.icij.datashare.PropertiesProvider in project datashare by ICIJ.

the class LocalUserFilterTest method test_adds_cookie.

@Test
public void test_adds_cookie() throws Exception {
    LocalUserFilter localUserFilter = new LocalUserFilter(new PropertiesProvider());
    Payload payload = localUserFilter.apply("url", context, nextFilter);
    assertThat(payload.cookies().size()).isEqualTo(1);
    assertThat(payload.cookies().get(0).name()).isEqualTo("_ds_session_id");
    assertThat(payload.cookies().get(0).value()).contains("\"login\":\"local\"");
}
Also used : PropertiesProvider(org.icij.datashare.PropertiesProvider) Payload(net.codestory.http.payload.Payload) Test(org.junit.Test)

Example 19 with PropertiesProvider

use of org.icij.datashare.PropertiesProvider in project datashare by ICIJ.

the class LocalUserFilterTest method test_matches.

@Test
public void test_matches() {
    LocalUserFilter localUserFilter = new LocalUserFilter(new PropertiesProvider(new HashMap<String, String>() {

        {
            put("protectedUrPrefix", "test");
        }
    }));
    assertThat(localUserFilter.matches("foo", null)).isFalse();
    assertThat(localUserFilter.matches("/foo", null)).isFalse();
    assertThat(localUserFilter.matches("test", null)).isTrue();
    assertThat(localUserFilter.matches("/test", null)).isFalse();
    assertThat(localUserFilter.matches("test_bar", null)).isTrue();
}
Also used : PropertiesProvider(org.icij.datashare.PropertiesProvider) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 20 with PropertiesProvider

use of org.icij.datashare.PropertiesProvider in project datashare by ICIJ.

the class ElasticsearchConfiguration method createESClient.

public static RestHighLevelClient createESClient(final PropertiesProvider propertiesProvider) {
    System.setProperty("es.set.netty.runtime.available.processors", "false");
    try {
        URL indexUrl = new URL(propertiesProvider.get(INDEX_ADDRESS_PROP).orElse(DEFAULT_ADDRESS));
        HttpHost httpHost = create(format("%s://%s:%d", indexUrl.getProtocol(), indexUrl.getHost(), indexUrl.getPort()));
        RestClientBuilder.HttpClientConfigCallback httpClientConfigCallback = httpClientBuilder -> httpClientBuilder;
        if (indexUrl.getUserInfo() != null) {
            String[] userInfo = indexUrl.getUserInfo().split(":");
            LOGGER.info("using credentials from url (user={})", userInfo[0]);
            final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
            credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(userInfo[0], userInfo[1]));
            httpClientConfigCallback = httpClientBuilder -> httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider);
        }
        RestHighLevelClient client = new RestHighLevelClient(RestClient.builder(httpHost).setRequestConfigCallback(requestConfigBuilder -> requestConfigBuilder.setConnectTimeout(5000).setSocketTimeout(60000)).setHttpClientConfigCallback(httpClientConfigCallback));
        String clusterName = propertiesProvider.get(CLUSTER_PROP).orElse(ES_CLUSTER_NAME);
        return client;
    } catch (MalformedURLException e) {
        throw new RuntimeException(e);
    }
}
Also used : RestClient(org.elasticsearch.client.RestClient) RestClientBuilder(org.elasticsearch.client.RestClientBuilder) URLDecoder(java.net.URLDecoder) URL(java.net.URL) LoggerFactory(org.slf4j.LoggerFactory) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) WriteRequest(org.elasticsearch.action.support.WriteRequest) Settings(org.elasticsearch.common.settings.Settings) RequestOptions(org.elasticsearch.client.RequestOptions) HttpHost.create(org.apache.http.HttpHost.create) Logger(org.slf4j.Logger) CreateIndexRequest(org.elasticsearch.client.indices.CreateIndexRequest) PropertiesProvider(org.icij.datashare.PropertiesProvider) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) RestHighLevelClient(org.elasticsearch.client.RestHighLevelClient) String.format(java.lang.String.format) ByteStreams.toByteArray(com.google.common.io.ByteStreams.toByteArray) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials) HttpAsyncClientBuilder(org.apache.http.impl.nio.client.HttpAsyncClientBuilder) JSON(org.elasticsearch.common.xcontent.XContentType.JSON) AuthScope(org.apache.http.auth.AuthScope) CredentialsProvider(org.apache.http.client.CredentialsProvider) HttpHost(org.apache.http.HttpHost) UnsupportedEncodingException(java.io.UnsupportedEncodingException) GetIndexRequest(org.elasticsearch.client.indices.GetIndexRequest) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) MalformedURLException(java.net.MalformedURLException) RestClientBuilder(org.elasticsearch.client.RestClientBuilder) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) CredentialsProvider(org.apache.http.client.CredentialsProvider) RestHighLevelClient(org.elasticsearch.client.RestHighLevelClient) URL(java.net.URL) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials) HttpHost(org.apache.http.HttpHost)

Aggregations

PropertiesProvider (org.icij.datashare.PropertiesProvider)73 Test (org.junit.Test)44 HashMap (java.util.HashMap)27 Document (org.icij.datashare.text.Document)18 BatchSearch (org.icij.datashare.batch.BatchSearch)17 LocalUserFilter (org.icij.datashare.session.LocalUserFilter)15 AbstractProdWebServerTest (org.icij.datashare.web.testhelpers.AbstractProdWebServerTest)15 Path (java.nio.file.Path)11 Before (org.junit.Before)10 BatchDownload (org.icij.datashare.batch.BatchDownload)9 Publisher (org.icij.datashare.com.Publisher)8 Indexer (org.icij.datashare.text.indexing.Indexer)7 User (org.icij.datashare.user.User)7 Date (java.util.Date)6 Properties (java.util.Properties)6 RestAssert (net.codestory.rest.RestAssert)5 PipelineRegistry (org.icij.datashare.extension.PipelineRegistry)5 DocumentFactory (org.icij.extract.document.DocumentFactory)5 TikaDocument (org.icij.extract.document.TikaDocument)5 FieldNames (org.icij.spewer.FieldNames)5