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