Search in sources :

Example 1 with CloudEventImpl

use of io.cloudevents.v02.CloudEventImpl 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();
    }
}
Also used : DocsResultRow(com.ibm.cloud.cloudant.v1.model.DocsResultRow) ArrayList(java.util.ArrayList) NotFoundException(com.ibm.cloud.sdk.core.service.exception.NotFoundException) AllDocsResult(com.ibm.cloud.cloudant.v1.model.AllDocsResult) PostAllDocsOptions(com.ibm.cloud.cloudant.v1.model.PostAllDocsOptions) Document(com.ibm.cloud.cloudant.v1.model.Document) CloudEvent(io.cloudevents.CloudEvent) CloudEventImpl(io.cloudevents.v02.CloudEventImpl)

Aggregations

AllDocsResult (com.ibm.cloud.cloudant.v1.model.AllDocsResult)1 DocsResultRow (com.ibm.cloud.cloudant.v1.model.DocsResultRow)1 Document (com.ibm.cloud.cloudant.v1.model.Document)1 PostAllDocsOptions (com.ibm.cloud.cloudant.v1.model.PostAllDocsOptions)1 NotFoundException (com.ibm.cloud.sdk.core.service.exception.NotFoundException)1 CloudEvent (io.cloudevents.CloudEvent)1 CloudEventImpl (io.cloudevents.v02.CloudEventImpl)1 ArrayList (java.util.ArrayList)1