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);
}
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);
}
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());
}
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);
}
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);
}
Aggregations