Java Code Examples for com.cloudant.client.api.CloudantClient#database()

The following examples show how to use com.cloudant.client.api.CloudantClient#database() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IndexTests.java    From java-cloudant with Apache License 2.0 6 votes vote down vote up
/**
 * Uses a mock web server to record a _find request using the specified options
 *
 * @param builder query to make
 * @return the JsonElement from the use_index property of the JsonObject POSTed with the request
 * @throws Exception
 */
private JsonElement getUseIndexFromRequest(QueryBuilder builder) throws Exception {
    JsonElement useIndexRequestProperty = null;
    MockWebServer mockWebServer = new MockWebServer();
    // Return 200 OK with empty array of docs (once for each request)
    mockWebServer.enqueue(new MockResponse().setBody("{ \"docs\" : []}"));
    mockWebServer.start();
    try {
        CloudantClient client = CloudantClientHelper.newMockWebServerClientBuilder
                (mockWebServer).build();
        Database db = client.database("mock", false);
        db.query(builder.build(), Movie.class);
        RecordedRequest request = mockWebServer.takeRequest(1, TimeUnit.SECONDS);
        JsonObject body = new Gson().fromJson(request.getBody().readUtf8(), JsonObject.class);
        useIndexRequestProperty = body.get("use_index");
    } finally {
        mockWebServer.shutdown();
    }
    return useIndexRequestProperty;
}
 
Example 2
Source File: DatabaseTest.java    From java-cloudant with Apache License 2.0 6 votes vote down vote up
@Test
public void permissionsParsing() throws Exception {
    CloudantClient client = CloudantClientHelper.newMockWebServerClientBuilder(mockWebServer)
            .build();
    Database db = client.database("notarealdb", false);

    // Mock up a request of all permissions
    mockWebServer.enqueue(MockWebServerResources.PERMISSIONS); // for GET _security
    mockWebServer.enqueue(MockWebServerResources.JSON_OK); // for PUT _security
    db.setPermissions("testUsername", EnumSet.allOf(Permissions.class));

    // Mock up a failing request
    String testError = "test error";
    String testReason = "test reason";
    mockWebServer.enqueue(MockWebServerResources.PERMISSIONS); // for GET _security
    mockWebServer.enqueue(new MockResponse().setResponseCode(400).setBody("{\"reason\":\"" +
            testReason + "\", \"error\":\"" + testError + "\"}"));
    try {
        db.setPermissions("testUsername", EnumSet.allOf(Permissions.class));
    } catch (CouchDbException e) {
        assertEquals(testError, e.getError());
        assertEquals(testReason, e.getReason());
    }
}
 
Example 3
Source File: DatabaseTest.java    From java-cloudant with Apache License 2.0 6 votes vote down vote up
@Test
public void customGsonDeserializerTest() throws MalformedURLException {
    GsonBuilder builder = new GsonBuilder();
    builder.setDateFormat("yyyy-MM-dd'T'HH:mm:ss");

    CloudantClient account = CloudantClientHelper.getClientBuilder()
            .gsonBuilder(builder)
            .build();

    Database db = account.database(dbResource.getDatabaseName(), false);

    Map<String, Object> h = new HashMap<String, Object>();
    h.put("_id", "serializertest");
    h.put("date", "2015-01-23T18:25:43.511Z");
    db.save(h);

    db.find(Foo.class, "serializertest"); // should not throw a JsonSyntaxException

}
 
Example 4
Source File: ViewsMockTest.java    From java-cloudant with Apache License 2.0 6 votes vote down vote up
/**
 * We can't test the server behaviour of stale, but we can test the URL values are what we
 * expect. This test uses the various values and checks the stale parameter in the URL, it makes
 * a request using getSingleValue() as it is easier to mock the responses.
 *
 * @throws Exception
 */
@Test
public void staleParameterValues() throws Exception {
    CloudantClient client = CloudantClientHelper.newMockWebServerClientBuilder(server)
        .build();
    Database database = client.database("notarealdb", false);
    for (String s : new String[]{
            SettableViewParameters.STALE_NO,
            SettableViewParameters.STALE_OK,
            SettableViewParameters.STALE_UPDATE_AFTER}) {
        UnpaginatedRequestBuilder<String, Integer> viewBuilder = database.getViewRequestBuilder
                ("testDDoc", "testView").newRequest(Key.Type.STRING, Integer.class);
        MockResponse mockResponse = new MockResponse().setResponseCode(200).setBody
                ("{\"rows\":[{\"key\":null,\"value\":10}]}");
        server.enqueue(mockResponse);
        viewBuilder.stale(s).build().getSingleValue();
        HttpUrl url = server.takeRequest(1, TimeUnit.SECONDS).getRequestUrl();
        Assert.assertEquals(s, url.queryParameter("stale"));
        Assert.assertEquals("/notarealdb/_design/testDDoc/_view/testView", url.encodedPath());
    }
}
 
Example 5
Source File: ViewsMockTest.java    From java-cloudant with Apache License 2.0 6 votes vote down vote up
/**
 * Similar to staleParameterValues, but for `stable` parameter
 * @throws Exception
 */
@Test
public void stableParameterValues() throws Exception {
    CloudantClient client = CloudantClientHelper.newMockWebServerClientBuilder(server)
            .build();
    Database database = client.database("notarealdb", false);
    for (Boolean b : new Boolean[]{
            false,
            true}) {
        UnpaginatedRequestBuilder<String, Integer> viewBuilder = database.getViewRequestBuilder
                ("testDDoc", "testView").newRequest(Key.Type.STRING, Integer.class);
        MockResponse mockResponse = new MockResponse().setResponseCode(200).setBody
                ("{\"rows\":[{\"key\":null,\"value\":10}]}");
        server.enqueue(mockResponse);
        viewBuilder.stable(b).build().getSingleValue();
        HttpUrl url = server.takeRequest(1, TimeUnit.SECONDS).getRequestUrl();
        Assert.assertEquals(Boolean.toString(b), url.queryParameter("stable"));
        Assert.assertEquals("/notarealdb/_design/testDDoc/_view/testView", url.encodedPath());
    }
}
 
Example 6
Source File: DbInfoMockTests.java    From java-cloudant with Apache License 2.0 6 votes vote down vote up
/**
 * Make sure disk_size using sizes works
 */
@Test
public void getDbInfoSizes() {
    CloudantClient c = CloudantClientHelper.newMockWebServerClientBuilder(server).build();
    Database db = c.database("animaldb", false);

    MockResponse response = new MockResponse()
            .setResponseCode(200)
            .setBody("{\"sizes\": {\"active\": 21, \"external\":22, \"file\": 23}}");
    server.enqueue(response);

    DbInfo info = db.info();
    assertEquals(21L, info.getSizes().getActive(), "The mock active disk size should be 21");
    assertEquals(22L, info.getSizes().getExternal(), "The mock external disk size should be 22");
    assertEquals(23L, info.getSizes().getFile(), "The mock file disk size should be 23");
}
 
Example 7
Source File: ChangeNotificationsTest.java    From java-cloudant with Apache License 2.0 6 votes vote down vote up
/**
 * Test that a custom parameter can be added to a changes request.
 */
@Test
public void changesCustomParameter() throws Exception {
    CloudantClient client = CloudantClientHelper.newMockWebServerClientBuilder(mockWebServer)
            .build();
    Database db = client.database("notreal", false);
    // Mock up an empty set of changes
    mockWebServer.enqueue(new MockResponse().setBody("{\"results\": []}"));
    db.changes().filter("myFilter").parameter("myParam", "paramValue").getChanges();
    RecordedRequest request = mockWebServer.takeRequest(1, TimeUnit.SECONDS);
    assertNotNull(request, "There should be a changes request");
    assertTrue(request.getPath()
            .contains("filter=myFilter"), "There should be a filter parameter on the request");
    assertTrue(request.getPath()
            .contains("myParam=paramValue"), "There should be a custom parameter on the " +
            "request");
}
 
Example 8
Source File: DbInfoMockTests.java    From java-cloudant with Apache License 2.0 5 votes vote down vote up
/**
 * Make sure disk_size still works
 */
@Test
public void getDbInfoDiskSize() {
    CloudantClient c = CloudantClientHelper.newMockWebServerClientBuilder(server).build();
    Database db = c.database("animaldb", false);

    MockResponse response = new MockResponse()
            .setResponseCode(200)
            .setBody("{\"disk_size\":17}");
    server.enqueue(response);

    DbInfo info = db.info();
    assertEquals(17L, info.getDiskSize(), "The mock disk size should be 17");
}
 
Example 9
Source File: DbInfoMockTests.java    From java-cloudant with Apache License 2.0 5 votes vote down vote up
@Test
public void getDbPartitionPartitionedIndexesIndexesSearch() {
    CloudantClient c = CloudantClientHelper.newMockWebServerClientBuilder(server).build();
    Database db = c.database("animaldb", false);

    MockResponse response = new MockResponse()
            .setResponseCode(200)
            .setBody("{\"partitioned_indexes\":{\"indexes\":{\"search\":3}}}");
    server.enqueue(response);

    assertEquals(3, db.info().getPartitionedIndexes().getIndexes().getSearch());
}
 
Example 10
Source File: DbInfoMockTests.java    From java-cloudant with Apache License 2.0 5 votes vote down vote up
/**
 * Make sure disk_size using sizes works
 */
@Test
public void getDbInfoDiskSizeFromSizes() {
    CloudantClient c = CloudantClientHelper.newMockWebServerClientBuilder(server).build();
    Database db = c.database("animaldb", false);

    MockResponse response = new MockResponse()
            .setResponseCode(200)
            .setBody("{\"sizes\": {\"active\": 21, \"external\":22, \"file\": 23}}");
    server.enqueue(response);

    DbInfo info = db.info();
    assertEquals(23L, info.getDiskSize(), "The mock disk size should be 23");
}
 
Example 11
Source File: PartitionInfoMockTests.java    From java-cloudant with Apache License 2.0 5 votes vote down vote up
@Test
public void getDbPartitionSizesActive() {
    String partitionKey = "myPartitionKey";
    CloudantClient c = CloudantClientHelper.newMockWebServerClientBuilder(server).build();
    Database db = c.database("animaldb", false);

    MockResponse response = new MockResponse()
            .setResponseCode(200)
            .setBody("{\"sizes\":{\"active\":1234}}");
    server.enqueue(response);

    assertEquals(1234, db.partitionInfo(partitionKey).getSizes().getActive());
}
 
Example 12
Source File: DbInfoMockTests.java    From java-cloudant with Apache License 2.0 5 votes vote down vote up
@Test
public void getDbInfoLongPurgeSeqAsString() {
    CloudantClient c = CloudantClientHelper.newMockWebServerClientBuilder(server).build();
    Database db = c.database("animaldb", false);

    MockResponse response = new MockResponse()
            .setResponseCode(200)
            .setBody("{\"purge_seq\":123}");
    server.enqueue(response);

    assertEquals("123", db.info().getStringPurgeSeq());
}
 
Example 13
Source File: DbInfoMockTests.java    From java-cloudant with Apache License 2.0 5 votes vote down vote up
@Test
public void getDbInfoStringPurgeSeqAsLong() {
    CloudantClient c = CloudantClientHelper.newMockWebServerClientBuilder(server).build();
    Database db = c.database("animaldb", false);

    String mockPurgeSeq = "\"3-g1AAAABXeJzLYWBgYMpgTmEQTM4vTc5ISXLIyU9OzMnILy7JAUklMiTV____PyuRAY-iPBYgydAApP6D1TJnAQCZtRxv\"";
    MockResponse response = new MockResponse()
            .setResponseCode(200)
            .setBody("{\"purge_seq\":" + mockPurgeSeq + "}");
    server.enqueue(response);

    assertEquals(0, db.info().getPurgeSeq());
}
 
Example 14
Source File: DbInfoMockTests.java    From java-cloudant with Apache License 2.0 5 votes vote down vote up
@Test
public void getDbInfoLongPurgeSeqAsLong() {
    CloudantClient c = CloudantClientHelper.newMockWebServerClientBuilder(server).build();
    Database db = c.database("animaldb", false);

    MockResponse response = new MockResponse()
            .setResponseCode(200)
            .setBody("{\"purge_seq\":123}");
    server.enqueue(response);

    assertEquals(123, db.info().getPurgeSeq());
}
 
Example 15
Source File: ChangeNotificationsTest.java    From java-cloudant with Apache License 2.0 5 votes vote down vote up
/**
 * Test that the continuous changes feed iterator correctly reads the last_seq line
 */
@Test
public void changesFeedLastSeq() throws Exception {

    CloudantClient client = CloudantClientHelper.newMockWebServerClientBuilder(mockWebServer)
            .build();
    Database db = client.database("notreal", false);

    // Mock up a set of changes with a last_seq
    String body = "{\"seq\":\"1" +
            "-g1AAAAETeJzLYWBgYMlgTmGQT0lKzi9KdUhJMtNLykxPyilN1UvOyS9NScwr0ctLLckBKmRKZEiy____f1YiA6oWI9xakhyAZFI9SFcGcyJjLpDHbmxukmponkjYBKIdlscCJBkagBTQov0Y7jMmpPMARCfIZ1kA23taSg\",\"id\":\"llama\",\"changes\":[{\"rev\":\"6-77acefc448de2129bb6427ebdeb021df\"}]}\n" +
            "{\"seq\":\"2-g1AAAAFDeJzLYWBgYMlgTmGQT0lKzi9KdUhJMtNLykxPyilN1UvOyS9NScwr0ctLLckBKmRKZEiy____f1YiA6oWI9xakhyAZFI9SFcGcyJjLpDHbmxukmponkjYBKIdlscCJBkagBTQov0Y7jMmpPMARCeyG41NTZPSTAmbkgUA-4RpJw\",\"id\":\"kookaburra\",\"changes\":[{\"rev\":\"4-6038cf35dfe1211f85484dec951142c7\"}]}\n" +
            "{\"seq\":\"3-g1AAAAFDeJzLYWBgYMlgTmGQT0lKzi9KdUhJMtNLykxPyilN1UvOyS9NScwr0ctLLckBKmRKZEiy____f1YiA6oWI9xakhyAZFI9SFcGcyJjLpDHbmxukmponkjYBKIdlscCJBkagBTQov0Y7jMmpPMARCfYjUwQNxqbmialmRI2JQsA-7RpKA\",\"id\":\"panda\",\"changes\":[{\"rev\":\"2-f578490963b0bd266f6c5bbf92302977\"}]}\n" +
            "{\"seq\":\"4-g1AAAAFDeJzLYWBgYMlgTmGQT0lKzi9KdUhJMtNLykxPyilN1UvOyS9NScwr0ctLLckBKmRKZEiy____f1YiA6oWI9xakhyAZFI9SFcGcyJjLpDHbmxukmponkjYBKIdlscCJBkagBTQov0Y7jMmpPMARCfYjcwQNxqbmialmRI2JQsA--RpKQ\",\"id\":\"snipe\",\"changes\":[{\"rev\":\"3-4b2fb3b7d6a226b13951612d6ca15a6b\"}]}\n" +
            "{\"seq\":\"5-g1AAAAFzeJzLYWBgYMlgTmGQT0lKzi9KdUhJMtNLykxPyilN1UvOyS9NScwr0ctLLckBKmRKZEiy____f1YGcyJjLlCA3dwkLcXczISwdlQrjHBbkeQAJJPqUWwxNjdJNTRPJGwC0R7JYwGSDA1ACmjR_qxEBlSdxoR0HoDoBLuRGeJGY1PTpDRTwqZkAQAv9XgS\",\"id\":\"badger\",\"changes\":[{\"rev\":\"4-51aa94e4b0ef37271082033bba52b850\"}]}\n" +
            "{\"seq\":\"6-g1AAAAGjeJzLYWBgYMlgTmGQT0lKzi9KdUhJMtNLykxPyilN1UvOyS9NScwr0ctLLckBKmRKZEiy____f1YGcyJjLlCA3dwkLcXczISwdlQrjHBbkeQAJJPqUWwxNjdJNTRPJGwC0R7JYwGSDA1ACmjRfoRNhubGZqaWlqT6x5iQTQcgNoH9xAzxk7GpaVKaKWFTsgBvlIad\",\"id\":\"870908b66ac0ed114512e6fb6d00260f\",\"changes\":[{\"rev\":\"2-eec205a9d413992850a6e32678485900\"}],\"deleted\":true}\n" +
            "{\"seq\":\"7-g1AAAAGjeJzLYWBgYMlgTmGQT0lKzi9KdUhJMtNLykxPyilN1UvOyS9NScwr0ctLLckBKmRKZEiy____f1YGcyJTLlCA3dwkLcXczISwdlQrjHBbkeQAJJPqobYwgm0xNjdJNTRPJGwC0R7JYwGSDA1ACmjRfoRNhubGZqaWlqT6x5iQTQcgNoH9xAzxk7GpaVKaKWFTsgBw_oae\",\"id\":\"_design/validation\",\"changes\":[{\"rev\":\"2-97e93126a6337d173f9b2810c0b9c0b6\"}],\"deleted\":true}\n" +
            "{\"seq\":\"8-g1AAAAGjeJzLYWBgYMlgTmGQT0lKzi9KdUhJMtNLykxPyilN1UvOyS9NScwr0ctLLckBKmRKZEiy____f1YGcyJzLlCA3dwkLcXczISwdlQrjHBbkeQAJJPqobYwgm0xNjdJNTRPJGwC0R7JYwGSDA1ACmjRfoRNhubGZqaWlqT6x5iQTQcgNiGFnLGxqWlSmilhU7IAcmiGnw\",\"id\":\"elephant\",\"changes\":[{\"rev\":\"3-f812228f45b5f4e496250556195372b2\"}]}\n" +
            "{\"seq\":\"9-g1AAAAGjeJzLYWBgYMlgTmGQT0lKzi9KdUhJMtNLykxPyilN1UvOyS9NScwr0ctLLckBKmRKZEiy____f1YGcyJzLlCA3dwkLcXczISwdlQrjHBbkeQAJJPqobYwgm0xNjdJNTRPJGwC0R7JYwGSDA1ACmjRfpBNTGCbDM2NzUwtLUn1jzEhmw5AbEIKOWNjU9OkNFPCpmQBAHMChqA\",\"id\":\"_design/views101\",\"changes\":[{\"rev\":\"1-a918dd4f11704143b535f0ab3af4bf75\"}]}\n" +
            "{\"seq\":\"10-g1AAAAGjeJzLYWBgYMlgTmGQT0lKzi9KdUhJMtNLykxPyilN1UvOyS9NScwr0ctLLckBKmRKZEiy____f1YGcyJLLlCA3dwkLcXczISwdlQrjHBbkeQAJJPqobYwgm0xNjdJNTRPJGwC0R7JYwGSDA1ACmjRfpBNTGCbDM2NzUwtLUn1jzEhmw5AbAL7iRniJ2NT06Q0U8KmZAEAdGyGoQ\",\"id\":\"lemur\",\"changes\":[{\"rev\":\"3-552d9dbf91fa914a07756e69b9ceaafa\"}]}\n" +
            "{\"seq\":\"11-g1AAAAGjeJzLYWBgYMlgTmGQT0lKzi9KdUhJMtNLykxPyilN1UvOyS9NScwr0ctLLckBKmRKZEiy____f1YGcyJLLlCA3dwkLcXczISwdlQrjHBbkeQAJJPqobYwgm0xNjdJNTRPJGwC0R7JYwGSDA1ACmjRfpBNzGCbDM2NzUwtLUn1jzEhmw5AbPqPsMnY2NQ0Kc2UsClZAHUGhqI\",\"id\":\"aardvark\",\"changes\":[{\"rev\":\"3-fe45a3e06244adbe7ba145e74e57aba5\"}]}\n" +
            "{\"seq\":\"12-g1AAAAGjeJzLYWBgYMlgTmGQT0lKzi9KdUhJMtNLykxPyilN1UvOyS9NScwr0ctLLckBKmRKZEiy____f1YGcyJrLlCA3dwkLcXczISwdlQrjHBbkeQAJJPqobYwgm0xNjdJNTRPJGwC0R7JYwGSDA1ACmjRfpBNzGCbDM2NzUwtLUn1jzEhmw5AbPqPsMnY2NQ0Kc2UsClZAHZwhqM\",\"id\":\"zebra\",\"changes\":[{\"rev\":\"3-750dac460a6cc41e6999f8943b8e603e\"}]}\n" +
            "{\"seq\":\"13-g1AAAAGjeJzLYWBgYMlgTmGQT0lKzi9KdUhJMtNLykxPyilN1UvOyS9NScwr0ctLLckBKmRKZEiy____f1YGcyJrLlCA3dwkLcXczISwdlQrjHBbkeQAJJPqobYwgm0xNjdJNTRPJGwC0R7JYwGSDA1ACmjRfpBNLGCbDM2NzUwtLUn1jzEhmw5AbAL7iRniJ2NT06Q0U8KmZAEAdwqGpA\",\"id\":\"cat\",\"changes\":[{\"rev\":\"2-eec205a9d413992850a6e32678485900\"}],\"deleted\":true}\n" +
            "{\"seq\":\"14-g1AAAAGjeJzLYWBgYMlgTmGQT0lKzi9KdUhJMtNLykxPyilN1UvOyS9NScwr0ctLLckBKmRKZEiy____f1YGcyJrLlCA3dwkLcXczISwdlQrjHBbkeQAJJPqobYwgm0xNjdJNTRPJGwC0R7JYwGSDA1ACmjRfoR_DM2NzUwtLUn1jzEhmw5AbAL7iRniJ2NT06Q0U8KmZAEAd6SGpQ\",\"id\":\"giraffe\",\"changes\":[{\"rev\":\"3-7665c3e66315ff40616cceef62886bd8\"}]}\n" +
            "{\"last_seq\":\"14-g1AAAAGjeJzLYWBgYMlgTmGQT0lKzi9KdUhJMtNLykxPyilN1UvOyS9NScwr0ctLLckBKmRKZEiy____f1YGcyJrLlCA3dwkLcXczISwdlQrjHBbkeQAJJPqobYwgm0xNjdJNTRPJGwC0R7JYwGSDA1ACmjRfoR_DM2NzUwtLUn1jzEhmw5AbAL7iRniJ2NT06Q0U8KmZAEAd6SGpQ\",\"pending\":0}";
    mockWebServer.enqueue(new MockResponse().setBody(body));
    Changes c = db.changes().continuousChanges();
    int nChanges = 0;
    // check against regression where hasNext() will hang
    while (c.hasNext()) {
        nChanges++;
        c.next();
    }
    RecordedRequest request = mockWebServer.takeRequest(1, TimeUnit.SECONDS);
    assertNotNull(request, "There should be a changes request");
    assertEquals(14, nChanges, "There should be 14 changes");
}
 
Example 16
Source File: DbInfoMockTests.java    From java-cloudant with Apache License 2.0 5 votes vote down vote up
/**
 * Make sure the fallback caused by disk_size 0, doesn't cause an exception
 */
@Test
public void getDbInfoDiskSizeZeroWithoutException() {
    CloudantClient c = CloudantClientHelper.newMockWebServerClientBuilder(server).build();
    Database db = c.database("animaldb", false);

    MockResponse response = new MockResponse()
            .setResponseCode(200)
            .setBody("{\"disk_size\":0}");
    server.enqueue(response);

    DbInfo info = db.info();
    assertEquals(0L, info.getDiskSize(), "The mock disk size should be 0");
}
 
Example 17
Source File: Utils.java    From java-cloudant with Apache License 2.0 5 votes vote down vote up
public static void removeReplicatorTestDoc(CloudantClient account, String replicatorDocId)
        throws Exception {

    //Grab replicator doc revision using HTTP HEAD command
    String replicatorDb = "_replicator";
    URI uri = new URIBase(account.getBaseUri()).path(replicatorDb).path(replicatorDocId)
            .build();
    HttpConnection head = Http.HEAD(uri);

    //add a response interceptor to allow us to retrieve the ETag revision header
    final AtomicReference<String> revisionRef = new AtomicReference<String>();
    head.responseInterceptors.add(new HttpConnectionResponseInterceptor() {

        @Override
        public HttpConnectionInterceptorContext interceptResponse
                (HttpConnectionInterceptorContext context) {
            revisionRef.set(context.connection.getConnection().getHeaderField("ETag"));
            return context;
        }
    });

    account.executeRequest(head);
    String revision = revisionRef.get();
    assertNotNull("The revision should not be null", revision);
    Database replicator = account.database(replicatorDb, false);
    Response removeResponse = replicator.remove(replicatorDocId,
            revision.replaceAll("\"", ""));

    assertThat(removeResponse.getError(), is(nullValue()));
}
 
Example 18
Source File: Application.java    From chatbot with Apache License 2.0 5 votes vote down vote up
@Autowired
public Helper(final CloudantClient cloudantClient,
              WolframRepository wolframRepository,
              @Value("${cloudant.chatDB}") String chatDBName,
              @Value("${cloudant.feedbackDB}") String feedbackDBName,
              @Value("${cloudant.explorerDB}") String explorerDBName,
              @Value("${tmdb.apiKey}") String tmdbApiKey) {
    try {
        chatDB = cloudantClient.database(chatDBName, true);
        feedbackDB = cloudantClient.database(feedbackDBName, true);
        explorerDB = cloudantClient.database(explorerDBName, true);
    }
    catch(Exception e) {
        logger.info("ERROR HERE");
        e.printStackTrace();
    }
    finally {
        this.tmdbApiKey = tmdbApiKey;
        this.wolframRepository = wolframRepository;

        riveScriptBot = new RiveScriptBot();
        eliza = new ElizaMain();
        eliza.readScript(true, "src/main/resources/eliza/script");

        sparql = new SPARQL(explorerDB);
        languageTool = new JLanguageTool(new AmericanEnglish());
        for (Rule rule : languageTool.getAllActiveRules()) {
            if (rule instanceof SpellingCheckRule) {
                List<String> wordsToIgnore = Arrays.asList(new String[] {"nlp", "merkel"});
                ((SpellingCheckRule) rule).addIgnoreTokens(wordsToIgnore);
            }
        }
    }
}
 
Example 19
Source File: CouchDbConfig.java    From Spring-5.0-Cookbook with MIT License 4 votes vote down vote up
@Bean
public Database hrsDb(CloudantClient cloudant) {
	return cloudant.database("hrs", true);
}
 
Example 20
Source File: CloudantConfiguration.java    From greeting-cloudant-spring with Apache License 2.0 4 votes vote down vote up
@Bean
public Database database(CloudantClient client) {
	Database db = client.database(config.getDb(), true);
	return db;
}