use of com.ibm.cloud.cloudant.v1.Cloudant in project cloudant-java-sdk by IBM.
the class Cloudant method getDesignDocument.
/**
* Retrieve a design document.
*
* Returns design document with the specified `doc_id` from the specified database. Unless you request a specific
* revision, the current revision of the design document is always returned.
*
* @param getDesignDocumentOptions the {@link GetDesignDocumentOptions} containing the options for the call
* @return a {@link ServiceCall} with a result of type {@link DesignDocument}
*/
public ServiceCall<DesignDocument> getDesignDocument(GetDesignDocumentOptions getDesignDocumentOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(getDesignDocumentOptions, "getDesignDocumentOptions cannot be null");
Map<String, String> pathParamsMap = new HashMap<String, String>();
pathParamsMap.put("db", getDesignDocumentOptions.db());
pathParamsMap.put("ddoc", getDesignDocumentOptions.ddoc());
RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/{db}/_design/{ddoc}", pathParamsMap));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "getDesignDocument");
for (Entry<String, String> header : sdkHeaders.entrySet()) {
builder.header(header.getKey(), header.getValue());
}
builder.header("Accept", "application/json");
if (getDesignDocumentOptions.ifNoneMatch() != null) {
builder.header("If-None-Match", getDesignDocumentOptions.ifNoneMatch());
}
if (getDesignDocumentOptions.attachments() != null) {
builder.query("attachments", String.valueOf(getDesignDocumentOptions.attachments()));
}
if (getDesignDocumentOptions.attEncodingInfo() != null) {
builder.query("att_encoding_info", String.valueOf(getDesignDocumentOptions.attEncodingInfo()));
}
if (getDesignDocumentOptions.conflicts() != null) {
builder.query("conflicts", String.valueOf(getDesignDocumentOptions.conflicts()));
}
if (getDesignDocumentOptions.deletedConflicts() != null) {
builder.query("deleted_conflicts", String.valueOf(getDesignDocumentOptions.deletedConflicts()));
}
if (getDesignDocumentOptions.latest() != null) {
builder.query("latest", String.valueOf(getDesignDocumentOptions.latest()));
}
if (getDesignDocumentOptions.localSeq() != null) {
builder.query("local_seq", String.valueOf(getDesignDocumentOptions.localSeq()));
}
if (getDesignDocumentOptions.meta() != null) {
builder.query("meta", String.valueOf(getDesignDocumentOptions.meta()));
}
if (getDesignDocumentOptions.rev() != null) {
builder.query("rev", String.valueOf(getDesignDocumentOptions.rev()));
}
if (getDesignDocumentOptions.revs() != null) {
builder.query("revs", String.valueOf(getDesignDocumentOptions.revs()));
}
if (getDesignDocumentOptions.revsInfo() != null) {
builder.query("revs_info", String.valueOf(getDesignDocumentOptions.revsInfo()));
}
ResponseConverter<DesignDocument> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<DesignDocument>() {
}.getType());
return createServiceCall(builder.build(), responseConverter);
}
use of com.ibm.cloud.cloudant.v1.Cloudant in project cloudant-java-sdk by IBM.
the class Cloudant method postAllDocsQueries.
/**
* Multi-query the list of all documents in a database.
*
* Runs multiple queries using the primary index (all document IDs). Returns a JSON object that contains a list of
* result objects, one for each query, with a structure equivalent to that of a single `_all_docs` request. This
* enables you to request multiple queries in a single request, in place of multiple `POST /{db}/_all_docs` requests.
*
* @param postAllDocsQueriesOptions the {@link PostAllDocsQueriesOptions} containing the options for the call
* @return a {@link ServiceCall} with a result of type {@link AllDocsQueriesResult}
*/
public ServiceCall<AllDocsQueriesResult> postAllDocsQueries(PostAllDocsQueriesOptions postAllDocsQueriesOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(postAllDocsQueriesOptions, "postAllDocsQueriesOptions cannot be null");
Map<String, String> pathParamsMap = new HashMap<String, String>();
pathParamsMap.put("db", postAllDocsQueriesOptions.db());
RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/{db}/_all_docs/queries", pathParamsMap));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "postAllDocsQueries");
for (Entry<String, String> header : sdkHeaders.entrySet()) {
builder.header(header.getKey(), header.getValue());
}
builder.header("Accept", "application/json");
final JsonObject contentJson = new JsonObject();
contentJson.add("queries", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(postAllDocsQueriesOptions.queries()));
builder.bodyJson(contentJson);
ResponseConverter<AllDocsQueriesResult> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<AllDocsQueriesResult>() {
}.getType());
return createServiceCall(builder.build(), responseConverter);
}
use of com.ibm.cloud.cloudant.v1.Cloudant in project knative-eventing-java-app by IBM.
the class CloudEventStoreCloudant method getEvents.
@Override
public List<CloudEvent<?, ?>> getEvents() {
try {
List<CloudEvent<?, ?>> events = new ArrayList<>();
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();
@SuppressWarnings("rawtypes") CloudEventImpl evt = this.gson.fromJson(document.toString(), CloudEventImpl.class);
events.add(evt);
}
return events;
} catch (NotFoundException e) {
logger.warn("Unable to retrieve all documents from Cloudant", e);
return Collections.emptyList();
}
}
use of com.ibm.cloud.cloudant.v1.Cloudant 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.cloudant.v1.Cloudant in project knative-eventing-java-app by IBM.
the class CloudEventStoreCloudant method getNumEvents.
@Override
public long getNumEvents() {
try {
PostAllDocsOptions docsOptions = new PostAllDocsOptions.Builder().db(this.dbName).build();
AllDocsResult allDocResults = this.client.postAllDocs(docsOptions).execute().getResult();
return allDocResults.getTotalRows();
} catch (Exception e) {
logger.warn("Unable to retrieve all documents from Cloudant", e);
return -1;
}
}
Aggregations