use of com.ibm.cloud.sdk.core.service.exception.NotFoundException in project knative-eventing-java-app by IBM.
the class CloudEventStoreCloudant method removeAllEvents.
@Override
public void removeAllEvents() throws Exception {
try {
PostAllDocsOptions docsOptions = new PostAllDocsOptions.Builder().db(this.dbName).includeDocs(true).build();
AllDocsResult allDocResults = this.client.postAllDocs(docsOptions).execute().getResult();
for (DocsResultRow docResult : allDocResults.getRows()) {
Document document = docResult.getDoc();
DeleteDocumentOptions deleteDocumentOptions = new DeleteDocumentOptions.Builder().db(this.dbName).docId(document.getId()).rev(document.getRev()).build();
DocumentResult deleteDocumentResponse = client.deleteDocument(deleteDocumentOptions).execute().getResult();
if (!deleteDocumentResponse.isOk()) {
logger.info("Could not delete a document.");
}
}
} catch (NotFoundException e) {
String errMsg = "Unable to retrieve all documents from Cloudant";
logger.error(errMsg, e);
throw new Exception(errMsg, e);
}
}
use of com.ibm.cloud.sdk.core.service.exception.NotFoundException in project java-sdk by watson-developer-cloud.
the class AssistantServiceIT method testListCounterexamples.
/**
* Test listCounterexamples.
*/
@Test
public void testListCounterexamples() {
String counterExampleText = // gotta be unique
"Make me a " + UUID.randomUUID().toString() + " sandwich";
try {
ListCounterexamplesOptions listOptions = new ListCounterexamplesOptions.Builder(workspaceId).build();
CounterexampleCollection ccResponse = service.listCounterexamples(listOptions).execute().getResult();
assertNotNull(ccResponse);
assertNotNull(ccResponse.getCounterexamples());
assertNotNull(ccResponse.getPagination());
assertNotNull(ccResponse.getPagination().getRefreshUrl());
// nextUrl may be null
Date start = new Date();
// Now add a counterexample and make sure we get it back
CreateCounterexampleOptions createOptions = new CreateCounterexampleOptions.Builder(workspaceId, counterExampleText).build();
service.createCounterexample(createOptions).execute().getResult();
long count = ccResponse.getCounterexamples().size();
CounterexampleCollection ccResponse2 = service.listCounterexamples(listOptions.newBuilder().pageLimit(count + 1).includeAudit(true).build()).execute().getResult();
assertNotNull(ccResponse2);
assertNotNull(ccResponse2.getCounterexamples());
List<Counterexample> counterexamples = ccResponse2.getCounterexamples();
assertTrue(counterexamples.size() > count);
Counterexample exResponse = null;
for (Counterexample resp : counterexamples) {
if (resp.text().equals(counterExampleText)) {
exResponse = resp;
break;
}
}
assertNotNull(exResponse);
Date now = new Date();
assertTrue(fuzzyBefore(exResponse.created(), now));
assertTrue(fuzzyAfter(exResponse.created(), start));
assertTrue(fuzzyBefore(exResponse.updated(), now));
assertTrue(fuzzyAfter(exResponse.updated(), start));
} catch (Exception ex) {
fail(ex.getMessage());
} finally {
// Clean up
try {
DeleteCounterexampleOptions deleteOptions = new DeleteCounterexampleOptions.Builder(workspaceId, counterExampleText).build();
service.deleteCounterexample(deleteOptions).execute();
} catch (NotFoundException ex) {
// Okay
}
}
}
use of com.ibm.cloud.sdk.core.service.exception.NotFoundException in project java-sdk by watson-developer-cloud.
the class EntitiesIT method testDeleteEntity.
/**
* Test deleteEntity.
*/
@Test
public void testDeleteEntity() {
// gotta be unique
String entity = "Hello" + UUID.randomUUID().toString();
CreateEntityOptions options = new CreateEntityOptions.Builder(workspaceId, entity).build();
Entity response = service.createEntity(options).execute().getResult();
try {
assertNotNull(response);
assertNotNull(response.getEntity());
assertEquals(response.getEntity(), entity);
assertNull(response.getDescription());
assertNull(response.getMetadata());
assertTrue(response.isFuzzyMatch() == null || response.isFuzzyMatch().equals(Boolean.FALSE));
} catch (Exception ex) {
DeleteEntityOptions deleteOptions = new DeleteEntityOptions.Builder(workspaceId, entity).build();
service.deleteEntity(deleteOptions).execute().getResult();
fail(ex.getMessage());
}
DeleteEntityOptions deleteOptions = new DeleteEntityOptions.Builder(workspaceId, entity).build();
service.deleteEntity(deleteOptions).execute().getResult();
try {
GetEntityOptions getOptions = new GetEntityOptions.Builder(workspaceId, entity).build();
service.getEntity(getOptions).execute().getResult();
fail("deleteEntity failed");
} catch (Exception ex) {
// Expected result
assertTrue(ex instanceof NotFoundException);
}
}
use of com.ibm.cloud.sdk.core.service.exception.NotFoundException in project java-sdk by watson-developer-cloud.
the class ValuesIT method testDeleteValue.
/**
* Test deleteValue.
*/
@Test
public void testDeleteValue() {
String entity = "beverage";
String entityValue = "coffee" + UUID.randomUUID().toString();
try {
CreateEntityOptions createOptions = new CreateEntityOptions.Builder(workspaceId, entity).build();
service.createEntity(createOptions).execute().getResult();
} catch (Exception ex) {
// Exception is okay if is for Unique Violation
assertTrue(ex.getLocalizedMessage().startsWith("Unique Violation"));
}
CreateValueOptions createOptions = new CreateValueOptions.Builder(workspaceId, entity, entityValue).build();
Value response = service.createValue(createOptions).execute().getResult();
try {
assertNotNull(response);
assertNotNull(response.value());
assertEquals(response.value(), entityValue);
assertNull(response.metadata());
} catch (Exception ex) {
// Clean up
DeleteValueOptions deleteOptions = new DeleteValueOptions.Builder(workspaceId, entity, entityValue).build();
service.deleteValue(deleteOptions).execute().getResult();
fail(ex.getMessage());
}
DeleteValueOptions deleteOptions = new DeleteValueOptions.Builder().workspaceId(workspaceId).entity(entity).value(entityValue).build();
service.deleteValue(deleteOptions).execute().getResult();
try {
GetValueOptions getOptions = new GetValueOptions.Builder(workspaceId, entity, entityValue).build();
service.getValue(getOptions).execute().getResult();
fail("deleteValue failed");
} catch (Exception ex) {
// Expected result
assertTrue(ex instanceof NotFoundException);
}
}
use of com.ibm.cloud.sdk.core.service.exception.NotFoundException in project cloudant-java-sdk by IBM.
the class DeleteDoc method main.
public static void main(String[] args) {
// 1. Create a client with `CLOUDANT` default service name ============
Cloudant client = Cloudant.newInstance();
// 2. Delete the document =============================================
// Set the options to get the document out of the database if it exists
String exampleDbName = "orders";
String exampleDocId = "example";
GetDocumentOptions documentInfoOptions = new GetDocumentOptions.Builder().db(exampleDbName).docId(exampleDocId).build();
try {
// Try to get the document if it previously existed in the database
Document document = client.getDocument(documentInfoOptions).execute().getResult();
// Delete the document from the database
DeleteDocumentOptions deleteDocumentOptions = new DeleteDocumentOptions.Builder().db(exampleDbName).docId(// docId is required for DELETE
exampleDocId).rev(// rev is required for DELETE
document.getRev()).build();
DocumentResult deleteDocumentResponse = client.deleteDocument(deleteDocumentOptions).execute().getResult();
if (deleteDocumentResponse.isOk()) {
System.out.println("You have deleted the document.");
}
} catch (NotFoundException nfe) {
System.out.println("Cannot delete document because " + "either \"orders\" database or the \"example\" " + "document was not found.");
}
}
Aggregations