Search in sources :

Example 1 with ViewRow

use of com.couchbase.client.java.view.ViewRow in project cas by apereo.

the class CouchbaseServiceRegistryDao method load.

@Override
public List<RegisteredService> load() {
    try {
        LOGGER.debug("Loading services");
        final ViewResult allKeys = executeViewQueryForAllServices();
        final List<RegisteredService> services = new LinkedList<>();
        for (final ViewRow row : allKeys) {
            final RawJsonDocument document = row.document(RawJsonDocument.class);
            if (document != null) {
                final String json = document.content();
                LOGGER.debug("Found service: [{}]", json);
                final StringReader stringReader = new StringReader(json);
                services.add(this.registeredServiceJsonSerializer.from(stringReader));
            }
        }
        return services;
    } catch (final RuntimeException e) {
        LOGGER.error(e.getMessage(), e);
        return new LinkedList<>();
    }
}
Also used : StringReader(java.io.StringReader) RawJsonDocument(com.couchbase.client.java.document.RawJsonDocument) ViewResult(com.couchbase.client.java.view.ViewResult) LinkedList(java.util.LinkedList) ViewRow(com.couchbase.client.java.view.ViewRow)

Example 2 with ViewRow

use of com.couchbase.client.java.view.ViewRow in project cas by apereo.

the class CouchbaseServiceRegistry method load.

@Override
public List<RegisteredService> load() {
    try {
        final ViewResult allKeys = executeViewQueryForAllServices();
        final List<RegisteredService> services = new ArrayList<>();
        for (final ViewRow row : allKeys) {
            final RawJsonDocument document = row.document(RawJsonDocument.class);
            if (document != null) {
                final String json = document.content();
                LOGGER.debug("Found service: [{}]", json);
                final StringReader stringReader = new StringReader(json);
                final RegisteredService service = this.registeredServiceJsonSerializer.from(stringReader);
                services.add(service);
                publishEvent(new CasRegisteredServiceLoadedEvent(this, service));
            }
        }
        return services;
    } catch (final Exception e) {
        LOGGER.error(e.getMessage(), e);
        throw new IllegalArgumentException(e.getMessage(), e);
    }
}
Also used : CasRegisteredServiceLoadedEvent(org.apereo.cas.support.events.service.CasRegisteredServiceLoadedEvent) ArrayList(java.util.ArrayList) StringReader(java.io.StringReader) RawJsonDocument(com.couchbase.client.java.document.RawJsonDocument) ViewResult(com.couchbase.client.java.view.ViewResult) ViewRow(com.couchbase.client.java.view.ViewRow)

Example 3 with ViewRow

use of com.couchbase.client.java.view.ViewRow in project cas by apereo.

the class CouchbaseTicketRegistry method getTickets.

@Override
public Collection<Ticket> getTickets() {
    final List<Ticket> tickets = new ArrayList<>();
    this.ticketCatalog.findAll().forEach(t -> {
        final Iterator<ViewRow> it = getViewResultIteratorForPrefixedTickets(t.getPrefix() + '-').iterator();
        while (it.hasNext()) {
            final ViewRow row = it.next();
            if (StringUtils.isNotBlank(row.id())) {
                final JsonDocument document = row.document();
                final Ticket ticket = (Ticket) document.content();
                LOGGER.debug("Got ticket [{}] from the registry.", ticket);
                final Ticket decoded = decodeTicket(ticket);
                if (decoded == null || decoded.isExpired()) {
                    LOGGER.warn("Ticket has expired or cannot be decoded");
                } else {
                    tickets.add(decoded);
                }
            }
        }
    });
    return tickets;
}
Also used : ServiceTicket(org.apereo.cas.ticket.ServiceTicket) TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) Ticket(org.apereo.cas.ticket.Ticket) ArrayList(java.util.ArrayList) ViewRow(com.couchbase.client.java.view.ViewRow) JsonDocument(com.couchbase.client.java.document.JsonDocument)

Example 4 with ViewRow

use of com.couchbase.client.java.view.ViewRow in project cas by apereo.

the class CouchbaseTicketRegistry method getViewRowCountFromViewResultIterator.

private static int getViewRowCountFromViewResultIterator(final Iterator<ViewRow> iterator) {
    if (iterator.hasNext()) {
        final ViewRow res = iterator.next();
        final Integer count = (Integer) res.value();
        LOGGER.debug("Found [{}] rows", count);
        return count;
    }
    LOGGER.debug("No rows could be found by the query iterator.");
    return 0;
}
Also used : ViewRow(com.couchbase.client.java.view.ViewRow)

Example 5 with ViewRow

use of com.couchbase.client.java.view.ViewRow in project ff4j by ff4j.

the class EventRepositoryCouchbase method queryView.

public void queryView(Bucket bucket, String design, String view) {
    ViewQuery queryAllFeatures = ViewQuery.from(design, view);
    ViewResult queryResult = bucket.query(queryAllFeatures);
    List<ViewRow> rows = queryResult.allRows();
    for (ViewRow viewRow : rows) {
        System.out.println("Result view:" + viewRow.id() + ":" + viewRow.value());
    }
}
Also used : ViewQuery(com.couchbase.client.java.view.ViewQuery) ViewResult(com.couchbase.client.java.view.ViewResult) ViewRow(com.couchbase.client.java.view.ViewRow)

Aggregations

ViewRow (com.couchbase.client.java.view.ViewRow)10 ViewResult (com.couchbase.client.java.view.ViewResult)6 ViewQuery (com.couchbase.client.java.view.ViewQuery)4 JsonDocument (com.couchbase.client.java.document.JsonDocument)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 RawJsonDocument (com.couchbase.client.java.document.RawJsonDocument)2 StringReader (java.io.StringReader)2 JsonArray (com.couchbase.client.java.document.json.JsonArray)1 LinkedList (java.util.LinkedList)1 CasRegisteredServiceLoadedEvent (org.apereo.cas.support.events.service.CasRegisteredServiceLoadedEvent)1 ServiceTicket (org.apereo.cas.ticket.ServiceTicket)1 Ticket (org.apereo.cas.ticket.Ticket)1 TicketGrantingTicket (org.apereo.cas.ticket.TicketGrantingTicket)1