Add predicates to find active and inactive accounts

'is:active' is equivalent to '-is:inactive' and 'is:inactive' is
equivalent to '-is:active', so strictly speaking only one operator of
'is:active' and 'is:inactive' is needed. However typing 'is:inactive'
is a little more convenient than typing '-is:active', hence both
operators are offered.

Change-Id: I700caa9633043abc8f10b0fa03f88717e30d1f4c
Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
Edwin Kempin
2016-06-27 10:41:58 +02:00
parent b0477988db
commit b2326bec27
2 changed files with 19 additions and 0 deletions

View File

@@ -38,6 +38,14 @@ public class AccountPredicates {
AccountQueryBuilder.FIELD_NAME, name);
}
static Predicate<AccountState> isActive() {
return new AccountPredicate(AccountField.ACTIVE, "1");
}
static Predicate<AccountState> isInactive() {
return new AccountPredicate(AccountField.ACTIVE, "0");
}
static Predicate<AccountState> username(String username) {
return new AccountPredicate(AccountField.USERNAME,
AccountQueryBuilder.FIELD_USERNAME, username);

View File

@@ -91,6 +91,17 @@ public class AccountQueryBuilder extends QueryBuilder<AccountState> {
return AccountPredicates.email(email);
}
@Operator
public Predicate<AccountState> is(String value) throws QueryParseException {
if ("active".equalsIgnoreCase(value)) {
return AccountPredicates.isActive();
}
if ("inactive".equalsIgnoreCase(value)) {
return AccountPredicates.isInactive();
}
throw error("Invalid query");
}
@Operator
public Predicate<AccountState> limit(String query)
throws QueryParseException {