Search in sources :

Example 11 with Credentials

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

the class Discovery method updateCredentials.

/**
 * Update credentials.
 *
 * <p>Updates an existing set of source credentials.
 *
 * <p>**Note:** All credentials are sent over an encrypted connection and encrypted at rest.
 *
 * @param updateCredentialsOptions the {@link UpdateCredentialsOptions} containing the options for
 *     the call
 * @return a {@link ServiceCall} with a result of type {@link Credentials}
 */
public ServiceCall<Credentials> updateCredentials(UpdateCredentialsOptions updateCredentialsOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(updateCredentialsOptions, "updateCredentialsOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("environment_id", updateCredentialsOptions.environmentId());
    pathParamsMap.put("credential_id", updateCredentialsOptions.credentialId());
    RequestBuilder builder = RequestBuilder.put(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/environments/{environment_id}/credentials/{credential_id}", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("discovery", "v1", "updateCredentials");
    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 (updateCredentialsOptions.sourceType() != null) {
        contentJson.addProperty("source_type", updateCredentialsOptions.sourceType());
    }
    if (updateCredentialsOptions.credentialDetails() != null) {
        contentJson.add("credential_details", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(updateCredentialsOptions.credentialDetails()));
    }
    if (updateCredentialsOptions.status() != null) {
        contentJson.add("status", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(updateCredentialsOptions.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)

Example 12 with Credentials

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

the class Discovery method deleteCredentials.

/**
 * Delete credentials.
 *
 * <p>Deletes a set of stored credentials from your Discovery instance.
 *
 * @param deleteCredentialsOptions the {@link DeleteCredentialsOptions} containing the options for
 *     the call
 * @return a {@link ServiceCall} with a result of type {@link DeleteCredentials}
 */
public ServiceCall<DeleteCredentials> deleteCredentials(DeleteCredentialsOptions deleteCredentialsOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(deleteCredentialsOptions, "deleteCredentialsOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("environment_id", deleteCredentialsOptions.environmentId());
    pathParamsMap.put("credential_id", deleteCredentialsOptions.credentialId());
    RequestBuilder builder = RequestBuilder.delete(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/environments/{environment_id}/credentials/{credential_id}", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("discovery", "v1", "deleteCredentials");
    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<DeleteCredentials> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<DeleteCredentials>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) DeleteCredentials(com.ibm.watson.discovery.v1.model.DeleteCredentials)

Example 13 with Credentials

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

the class DiscoveryServiceTest method deleteCredentialsIsSuccessful.

/**
 * Delete credentials is successful.
 *
 * @throws InterruptedException the interrupted exception
 */
@Test
public void deleteCredentialsIsSuccessful() throws InterruptedException {
    server.enqueue(jsonResponse(deleteCredentialsResp));
    DeleteCredentialsOptions options = new DeleteCredentialsOptions.Builder().environmentId(environmentId).credentialId("credential_id").build();
    DeleteCredentials response = discoveryService.deleteCredentials(options).execute().getResult();
    RecordedRequest request = server.takeRequest();
    assertEquals(DELETE_CREDENTIALS_PATH, request.getPath());
    assertEquals(DELETE, request.getMethod());
    assertEquals(deleteCredentialsResp.getCredentialId(), response.getCredentialId());
    assertEquals(deleteCredentialsResp.getStatus(), response.getStatus());
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) DeleteCredentials(com.ibm.watson.discovery.v1.model.DeleteCredentials) DeleteCredentialsOptions(com.ibm.watson.discovery.v1.model.DeleteCredentialsOptions) WatsonServiceUnitTest(com.ibm.watson.common.WatsonServiceUnitTest)

Example 14 with Credentials

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

the class DiscoveryServiceTest method updateCredentialsIsSuccessful.

/**
 * Update credentials is successful.
 *
 * @throws InterruptedException the interrupted exception
 */
@Test
public void updateCredentialsIsSuccessful() throws InterruptedException {
    server.enqueue(jsonResponse(credentialsResp));
    CredentialDetails newDetails = new CredentialDetails.Builder().clientId("new_client_id").clientSecret("new_client_secret").credentialType(CredentialDetails.CredentialType.USERNAME_PASSWORD).enterpriseId("new_enterprise_id").organizationUrl("new_organization_url").passphrase("new_passphrase").password("new_password").privateKey("new_private_key").publicKeyId("new_public_key_id").siteCollectionPath("new_site_collection_path").url("new_url").username("new_username").build();
    Credentials newCredentials = new Credentials.Builder().sourceType(Credentials.SourceType.SALESFORCE).credentialDetails(newDetails).build();
    UpdateCredentialsOptions options = new UpdateCredentialsOptions.Builder().environmentId(environmentId).credentialId("new_credential_id").sourceType(Credentials.SourceType.SALESFORCE).credentials(newCredentials).credentialDetails(newDetails).build();
    Credentials response = discoveryService.updateCredentials(options).execute().getResult();
    RecordedRequest request = server.takeRequest();
    assertEquals(UPDATE_CREDENTIALS_PATH, request.getPath());
    assertEquals(PUT, request.getMethod());
    assertEquals(credentialsResp, response);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) UpdateCredentialsOptions(com.ibm.watson.discovery.v1.model.UpdateCredentialsOptions) CredentialDetails(com.ibm.watson.discovery.v1.model.CredentialDetails) Credentials(com.ibm.watson.discovery.v1.model.Credentials) DeleteCredentials(com.ibm.watson.discovery.v1.model.DeleteCredentials) WatsonServiceUnitTest(com.ibm.watson.common.WatsonServiceUnitTest)

Example 15 with Credentials

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

the class DiscoveryServiceTest method listCredentialsIsSuccessful.

/**
 * List credentials is successful.
 *
 * @throws InterruptedException the interrupted exception
 */
@Test
public void listCredentialsIsSuccessful() throws InterruptedException {
    server.enqueue(jsonResponse(listCredentialsResp));
    ListCredentialsOptions options = new ListCredentialsOptions.Builder().environmentId(environmentId).build();
    CredentialsList response = discoveryService.listCredentials(options).execute().getResult();
    RecordedRequest request = server.takeRequest();
    assertEquals(LIST_CREDENTIALS_PATH, request.getPath());
    assertEquals(GET, request.getMethod());
    assertEquals(listCredentialsResp, response);
    assertTrue(response.getCredentials().size() == 3);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) CredentialsList(com.ibm.watson.discovery.v1.model.CredentialsList) ListCredentialsOptions(com.ibm.watson.discovery.v1.model.ListCredentialsOptions) WatsonServiceUnitTest(com.ibm.watson.common.WatsonServiceUnitTest)

Aggregations

DeleteCredentials (com.ibm.watson.discovery.v1.model.DeleteCredentials)12 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)10 Credentials (com.ibm.watson.discovery.v1.model.Credentials)9 RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)5 WatsonServiceUnitTest (com.ibm.watson.common.WatsonServiceUnitTest)5 HashMap (java.util.HashMap)5 MockResponse (okhttp3.mockwebserver.MockResponse)5 Test (org.testng.annotations.Test)5 CredentialDetails (com.ibm.watson.discovery.v1.model.CredentialDetails)4 CredentialsList (com.ibm.watson.discovery.v1.model.CredentialsList)3 JsonObject (com.google.gson.JsonObject)2 Credentials (com.haleconnect.api.user.v1.model.Credentials)2 CreateCredentialsOptions (com.ibm.watson.discovery.v1.model.CreateCredentialsOptions)2 DeleteCredentialsOptions (com.ibm.watson.discovery.v1.model.DeleteCredentialsOptions)2 GetCredentialsOptions (com.ibm.watson.discovery.v1.model.GetCredentialsOptions)2 ListCredentialsOptions (com.ibm.watson.discovery.v1.model.ListCredentialsOptions)2 StatusDetails (com.ibm.watson.discovery.v1.model.StatusDetails)2 UpdateCredentialsOptions (com.ibm.watson.discovery.v1.model.UpdateCredentialsOptions)2 ApiException (com.haleconnect.api.user.v1.ApiException)1 LoginApi (com.haleconnect.api.user.v1.api.LoginApi)1