use of com.couchbase.client.java.document.json.JsonObject in project sling by apache.
the class CouchbaseNoSqlAdapter method getChildren.
@Override
public Iterator<NoSqlData> getChildren(String parentPath) {
Bucket bucket = couchbaseClient.getBucket();
// fetch all direct children of this path
N1qlQuery query = N1qlQuery.simple(select("*").from(couchbaseClient.getBucketName()).where(x(PN_PARENT_PATH).eq(s(parentPath))), N1QL_PARAMS);
N1qlQueryResult queryResult = bucket.query(query);
handleQueryError(queryResult);
final Iterator<N1qlQueryRow> results = queryResult.iterator();
return new Iterator<NoSqlData>() {
@Override
public boolean hasNext() {
return results.hasNext();
}
@Override
public NoSqlData next() {
JsonObject item = results.next().value();
JsonObject envelope = item.getObject(couchbaseClient.getBucketName());
String path = envelope.getString(PN_PATH);
JsonObject data = envelope.getObject(PN_DATA);
return new NoSqlData(path, data.toMap(), MultiValueMode.LISTS);
}
@Override
public void remove() {
throw new UnsupportedOperationException();
}
};
}
use of com.couchbase.client.java.document.json.JsonObject in project sling by apache.
the class CouchbaseNoSqlAdapter method get.
@Override
public NoSqlData get(String path) {
Bucket bucket = couchbaseClient.getBucket();
String cacheKey = CouchbaseKey.build(path, cacheKeyPrefix);
JsonDocument doc = bucket.get(cacheKey);
if (doc == null) {
return null;
} else {
JsonObject data = doc.content().getObject(PN_DATA);
if (data == null) {
return null;
} else {
return new NoSqlData(path, data.toMap(), MultiValueMode.LISTS);
}
}
}
use of com.couchbase.client.java.document.json.JsonObject in project sling by apache.
the class CouchbaseNoSqlAdapter method deleteRecursive.
@Override
public boolean deleteRecursive(String path) {
Bucket bucket = couchbaseClient.getBucket();
// fetch all descendants and self for deletion
Pattern descendantsAndSelf = Pattern.compile("^" + path + "(/.+)?$");
N1qlQuery query = N1qlQuery.simple(select("*").from(couchbaseClient.getBucketName()).where("REGEXP_LIKE(`" + PN_PATH + "`, '" + descendantsAndSelf.pattern() + "')"), N1QL_PARAMS);
N1qlQueryResult queryResult = bucket.query(query);
handleQueryError(queryResult);
final Iterator<N1qlQueryRow> results = queryResult.iterator();
boolean deletedAny = false;
while (results.hasNext()) {
JsonObject item = results.next().value();
JsonObject envelope = item.getObject(couchbaseClient.getBucketName());
String itemPath = envelope.getString(PN_PATH);
String itemCacheKey = CouchbaseKey.build(itemPath, cacheKeyPrefix);
bucket.remove(itemCacheKey);
deletedAny = true;
}
return deletedAny;
}
use of com.couchbase.client.java.document.json.JsonObject in project cas by apereo.
the class CouchbasePersonAttributeDao method getPerson.
@Override
@SneakyThrows
public IPersonAttributes getPerson(final String uid) {
final N1qlQueryResult result = couchbase.query(couchbaseProperties.getUsernameAttribute(), uid);
final Map<String, ?> attributes;
if (result.allRows().isEmpty()) {
LOGGER.debug("Couchbase query did not return any results/rows.");
attributes = new LinkedHashMap<>();
} else {
attributes = result.allRows().stream().filter(row -> row.value().containsKey(couchbase.getBucket().name())).filter(row -> {
final JsonObject value = (JsonObject) row.value().get(couchbase.getBucket().name());
return value.containsKey(couchbaseProperties.getUsernameAttribute());
}).map(row -> (JsonObject) row.value().get(couchbase.getBucket().name())).map(entity -> couchbase.collectAttributesFromEntity(entity, s -> !s.equals(couchbaseProperties.getUsernameAttribute())).entrySet()).flatMap(Collection::stream).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
}
return new CaseInsensitiveNamedPersonImpl(uid, stuffAttributesIntoList(attributes));
}
Aggregations