Search in sources :

Example 21 with Source

use of com.ibm.watson.discovery.v1.model.Source in project event-notifications-java-admin-sdk by IBM.

the class SourceTest method testSource.

@Test
public void testSource() throws Throwable {
    Source sourceModel = new Source();
    assertNull(sourceModel.getId());
    assertNull(sourceModel.getName());
    assertNull(sourceModel.getDescription());
    assertNull(sourceModel.isEnabled());
    assertNull(sourceModel.getType());
    assertNull(sourceModel.getUpdatedAt());
    assertNull(sourceModel.getTopicCount());
    assertNull(sourceModel.getTopicNames());
}
Also used : Source(com.ibm.cloud.eventnotifications.event_notifications.v1.model.Source) Test(org.testng.annotations.Test)

Example 22 with Source

use of com.ibm.watson.discovery.v1.model.Source in project java-sdk by watson-developer-cloud.

the class DiscoveryServiceTest method testSourceOptions.

/**
 * Test source options.
 */
@Test
public void testSourceOptions() {
    String folderOwnerUserId = "folder_owner_user_id";
    String folderId = "folder_id";
    Long limit = 10L;
    String objectName = "object_name";
    String siteCollectionPath = "site_collection_path";
    String url = "url";
    Long maximumHops = 5L;
    Long requestTimeout = 2L;
    String bucketName = "bucket_name";
    SourceOptionsFolder folder = new SourceOptionsFolder.Builder().ownerUserId(folderOwnerUserId).folderId(folderId).limit(limit).build();
    SourceOptionsObject object = new SourceOptionsObject.Builder().name(objectName).limit(limit).build();
    SourceOptionsSiteColl siteColl = new SourceOptionsSiteColl.Builder().siteCollectionPath(siteCollectionPath).limit(limit).build();
    SourceOptionsWebCrawl webCrawl = new SourceOptionsWebCrawl.Builder().url(url).limitToStartingHosts(true).crawlSpeed(SourceOptionsWebCrawl.CrawlSpeed.AGGRESSIVE).allowUntrustedCertificate(true).maximumHops(maximumHops).requestTimeout(requestTimeout).overrideRobotsTxt(true).build();
    SourceOptionsBuckets buckets = new SourceOptionsBuckets.Builder().name(bucketName).limit(limit).build();
    SourceOptions sourceOptions = new SourceOptions.Builder().folders(Collections.singletonList(folder)).objects(Collections.singletonList(object)).siteCollections(Collections.singletonList(siteColl)).urls(Collections.singletonList(webCrawl)).buckets(Collections.singletonList(buckets)).crawlAllBuckets(true).build();
    assertEquals(folderOwnerUserId, sourceOptions.folders().get(0).ownerUserId());
    assertEquals(folderId, sourceOptions.folders().get(0).folderId());
    assertEquals(limit, sourceOptions.folders().get(0).limit());
    assertEquals(objectName, sourceOptions.objects().get(0).name());
    assertEquals(limit, sourceOptions.objects().get(0).limit());
    assertEquals(siteCollectionPath, sourceOptions.siteCollections().get(0).siteCollectionPath());
    assertEquals(limit, sourceOptions.siteCollections().get(0).limit());
    assertEquals(url, sourceOptions.urls().get(0).url());
    assertTrue(sourceOptions.urls().get(0).limitToStartingHosts());
    assertEquals(SourceOptionsWebCrawl.CrawlSpeed.AGGRESSIVE, sourceOptions.urls().get(0).crawlSpeed());
    assertTrue(sourceOptions.urls().get(0).allowUntrustedCertificate());
    assertEquals(maximumHops, sourceOptions.urls().get(0).maximumHops());
    assertEquals(requestTimeout, sourceOptions.urls().get(0).requestTimeout());
    assertTrue(sourceOptions.urls().get(0).overrideRobotsTxt());
    assertEquals(bucketName, sourceOptions.buckets().get(0).name());
    assertEquals(limit, sourceOptions.buckets().get(0).limit());
    assertTrue(sourceOptions.crawlAllBuckets());
}
Also used : SourceOptionsSiteColl(com.ibm.watson.discovery.v1.model.SourceOptionsSiteColl) SourceOptionsBuckets(com.ibm.watson.discovery.v1.model.SourceOptionsBuckets) SourceOptionsFolder(com.ibm.watson.discovery.v1.model.SourceOptionsFolder) SourceOptions(com.ibm.watson.discovery.v1.model.SourceOptions) SourceOptionsWebCrawl(com.ibm.watson.discovery.v1.model.SourceOptionsWebCrawl) SourceOptionsObject(com.ibm.watson.discovery.v1.model.SourceOptionsObject) WatsonServiceUnitTest(com.ibm.watson.common.WatsonServiceUnitTest)

Example 23 with Source

use of com.ibm.watson.discovery.v1.model.Source in project java-sdk by watson-developer-cloud.

the class Discovery method listCredentials.

/**
 * List credentials.
 *
 * <p>List all the source credentials that have been created for this service instance.
 *
 * <p>**Note:** All credentials are sent over an encrypted connection and encrypted at rest.
 *
 * @param listCredentialsOptions the {@link ListCredentialsOptions} containing the options for the
 *     call
 * @return a {@link ServiceCall} with a result of type {@link CredentialsList}
 */
public ServiceCall<CredentialsList> listCredentials(ListCredentialsOptions listCredentialsOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(listCredentialsOptions, "listCredentialsOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("environment_id", listCredentialsOptions.environmentId());
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/environments/{environment_id}/credentials", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("discovery", "v1", "listCredentials");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    builder.query("version", String.valueOf(this.version));
    ResponseConverter<CredentialsList> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<CredentialsList>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) CredentialsList(com.ibm.watson.discovery.v1.model.CredentialsList) HashMap(java.util.HashMap)

Example 24 with Source

use of com.ibm.watson.discovery.v1.model.Source in project java-sdk by watson-developer-cloud.

the class Discovery method updateConfiguration.

/**
 * Update a configuration.
 *
 * <p>Replaces an existing configuration. * Completely replaces the original configuration. * The
 * **configuration_id**, **updated**, and **created** fields are accepted in the request, but they
 * are ignored, and an error is not generated. It is also acceptable for users to submit an
 * updated configuration with none of the three properties. * Documents are processed with a
 * snapshot of the configuration as it was at the time the document was submitted to be ingested.
 * This means that already submitted documents will not see any updates made to the configuration.
 *
 * @param updateConfigurationOptions the {@link UpdateConfigurationOptions} containing the options
 *     for the call
 * @return a {@link ServiceCall} with a result of type {@link Configuration}
 */
public ServiceCall<Configuration> updateConfiguration(UpdateConfigurationOptions updateConfigurationOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(updateConfigurationOptions, "updateConfigurationOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("environment_id", updateConfigurationOptions.environmentId());
    pathParamsMap.put("configuration_id", updateConfigurationOptions.configurationId());
    RequestBuilder builder = RequestBuilder.put(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/environments/{environment_id}/configurations/{configuration_id}", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("discovery", "v1", "updateConfiguration");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    builder.query("version", String.valueOf(this.version));
    final JsonObject contentJson = new JsonObject();
    contentJson.addProperty("name", updateConfigurationOptions.name());
    if (updateConfigurationOptions.description() != null) {
        contentJson.addProperty("description", updateConfigurationOptions.description());
    }
    if (updateConfigurationOptions.conversions() != null) {
        contentJson.add("conversions", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(updateConfigurationOptions.conversions()));
    }
    if (updateConfigurationOptions.enrichments() != null) {
        contentJson.add("enrichments", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(updateConfigurationOptions.enrichments()));
    }
    if (updateConfigurationOptions.normalizations() != null) {
        contentJson.add("normalizations", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(updateConfigurationOptions.normalizations()));
    }
    if (updateConfigurationOptions.source() != null) {
        contentJson.add("source", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(updateConfigurationOptions.source()));
    }
    builder.bodyJson(contentJson);
    ResponseConverter<Configuration> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<Configuration>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) Configuration(com.ibm.watson.discovery.v1.model.Configuration) HashMap(java.util.HashMap) JsonObject(com.google.gson.JsonObject)

Example 25 with Source

use of com.ibm.watson.discovery.v1.model.Source in project java-sdk by watson-developer-cloud.

the class Discovery method createCredentials.

/**
 * Create credentials.
 *
 * <p>Creates a set of credentials to connect to a remote source. Created credentials are used in
 * a configuration to associate a collection with the remote source.
 *
 * <p>**Note:** All credentials are sent over an encrypted connection and encrypted at rest.
 *
 * @param createCredentialsOptions the {@link CreateCredentialsOptions} containing the options for
 *     the call
 * @return a {@link ServiceCall} with a result of type {@link Credentials}
 */
public ServiceCall<Credentials> createCredentials(CreateCredentialsOptions createCredentialsOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(createCredentialsOptions, "createCredentialsOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("environment_id", createCredentialsOptions.environmentId());
    RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/environments/{environment_id}/credentials", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("discovery", "v1", "createCredentials");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    builder.query("version", String.valueOf(this.version));
    final JsonObject contentJson = new JsonObject();
    if (createCredentialsOptions.sourceType() != null) {
        contentJson.addProperty("source_type", createCredentialsOptions.sourceType());
    }
    if (createCredentialsOptions.credentialDetails() != null) {
        contentJson.add("credential_details", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(createCredentialsOptions.credentialDetails()));
    }
    if (createCredentialsOptions.status() != null) {
        contentJson.add("status", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(createCredentialsOptions.status()));
    }
    builder.bodyJson(contentJson);
    ResponseConverter<Credentials> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<Credentials>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) JsonObject(com.google.gson.JsonObject) Credentials(com.ibm.watson.discovery.v1.model.Credentials) DeleteCredentials(com.ibm.watson.discovery.v1.model.DeleteCredentials)

Aggregations

RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)8 HashMap (java.util.HashMap)8 Test (org.testng.annotations.Test)7 FieldMetadata (com.google.api.services.people.v1.model.FieldMetadata)6 Name (com.google.api.services.people.v1.model.Name)6 Source (com.google.api.services.people.v1.model.Source)6 StructuredName (ezvcard.property.StructuredName)6 MockResponse (okhttp3.mockwebserver.MockResponse)6 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)6 JsonObject (com.google.gson.JsonObject)5 Configuration (com.ibm.watson.discovery.v1.model.Configuration)5 Source (com.ibm.cloud.eventnotifications.event_notifications.v1.model.Source)4 SourceOptionsWebCrawl (com.ibm.watson.discovery.v1.model.SourceOptionsWebCrawl)4 EmailAddress (com.google.api.services.people.v1.model.EmailAddress)3 Person (com.google.api.services.people.v1.model.Person)3 PhoneNumber (com.google.api.services.people.v1.model.PhoneNumber)3 Truth.assertThat (com.google.common.truth.Truth.assertThat)3 Pair (com.google.gdata.util.common.base.Pair)3 WatsonServiceUnitTest (com.ibm.watson.common.WatsonServiceUnitTest)3 Conversions (com.ibm.watson.discovery.v1.model.Conversions)3