Search in sources :

Example 1 with View

use of org.ektorp.support.View in project cas by apereo.

the class MultifactorAuthenticationTrustRecordCouchDbRepository method findOnOrAfterExpirationDate.

/**
 * Find record created on or after exp date.
 * Remove all records whose expiration date is greater than the given date.
 *
 * @param onOrAfterDate cutoff date
 * @return records created on or after date
 */
@View(name = "by_expirationDate", map = "function(doc) { if (doc.principal && doc.deviceFingerprint && doc.expirationDate) { emit(doc.expirationDate, doc) } }")
public List<CouchDbMultifactorAuthenticationTrustRecord> findOnOrAfterExpirationDate(final ZonedDateTime onOrAfterDate) {
    val expDate = DateTimeUtils.dateOf(onOrAfterDate);
    val query = createQuery("by_expirationDate").endKey(expDate);
    return db.queryView(query, CouchDbMultifactorAuthenticationTrustRecord.class);
}
Also used : lombok.val(lombok.val) View(org.ektorp.support.View)

Example 2 with View

use of org.ektorp.support.View in project cas by apereo.

the class RegisteredServiceCouchDbRepository method size.

/**
 * Size of the service database.
 *
 * @return The service count in the database.
 */
@View(name = "size", map = "function(doc) { if (doc.service) { emit(doc, doc._id) }}", reduce = "_count")
public int size() {
    val r = db.queryView(createQuery("size"));
    LOGGER.trace("r.isEmpty [{}]", r.isEmpty());
    LOGGER.trace("r.getRows [{}]", r.getRows());
    if (r.isEmpty()) {
        return 0;
    }
    return r.getRows().get(0).getValueAsInt();
}
Also used : lombok.val(lombok.val) View(org.ektorp.support.View)

Example 3 with View

use of org.ektorp.support.View in project cas by apereo.

the class GoogleAuthenticatorTokenCouchDbRepository method countByUserId.

/**
 * Token count for a user.
 *
 * @param userId user to count tokens for
 * @return count of the user's tokens
 */
@View(name = "count_by_userId", map = "function(doc) { if(doc.token && doc.userId) { emit(doc.userId, doc) } }", reduce = "_count")
public long countByUserId(final String userId) {
    val view = createQuery("count_by_userId").key(userId.trim().toLowerCase());
    val rows = db.queryView(view).getRows();
    if (rows.isEmpty()) {
        return 0;
    }
    return rows.get(0).getValueAsInt();
}
Also used : lombok.val(lombok.val) View(org.ektorp.support.View)

Aggregations

lombok.val (lombok.val)3 View (org.ektorp.support.View)3