use of com.enonic.xp.security.IdProviderKeys in project xp by enonic.
the class PrincipalQueryNodeQueryTranslator method translate.
public static NodeQuery translate(final PrincipalQuery principalQuery) {
final NodeQuery.Builder nodeQueryBuilder = NodeQuery.create().from(principalQuery.getFrom()).size(principalQuery.getSize());
final IdProviderKeys idProviders = principalQuery.getIdProviders();
if (idProviders.isNotEmpty()) {
nodeQueryBuilder.addQueryFilter(ValueFilter.create().fieldName(ID_PROVIDER_KEY).addValues(idProviders.stream().map(IdProviderKey::toString).collect(toList())).build());
}
final Set<PrincipalType> types = principalQuery.getPrincipalTypes();
if (!types.isEmpty()) {
nodeQueryBuilder.addQueryFilter(ValueFilter.create().fieldName(PRINCIPAL_TYPE_KEY).addValues(types.stream().map(Object::toString).collect(toList())).build());
}
final String searchText = principalQuery.getSearchText();
if (!nullToEmpty(searchText).isBlank()) {
nodeQueryBuilder.query(getQueryExpression(searchText));
}
final String email = principalQuery.getEmail();
if (!nullToEmpty(email).isBlank()) {
nodeQueryBuilder.addQueryFilter(ValueFilter.create().fieldName(EMAIL_KEY).addValues(email).build());
}
final String name = principalQuery.getName();
if (!nullToEmpty(name).isBlank()) {
nodeQueryBuilder.addQueryFilter(ValueFilter.create().fieldName(NAME_KEY).addValues(name).build());
}
final String displayName = principalQuery.getDisplayName();
if (!nullToEmpty(displayName).isBlank()) {
nodeQueryBuilder.addQueryFilter(ValueFilter.create().fieldName(DISPLAY_NAME_KEY).addValues(displayName).build());
}
return nodeQueryBuilder.build();
}
Aggregations