Search in sources :

Example 1 with IdProviderKeys

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();
}
Also used : NodeQuery(com.enonic.xp.node.NodeQuery) IdProviderKey(com.enonic.xp.security.IdProviderKey) IdProviderKeys(com.enonic.xp.security.IdProviderKeys) PrincipalType(com.enonic.xp.security.PrincipalType)

Aggregations

NodeQuery (com.enonic.xp.node.NodeQuery)1 IdProviderKey (com.enonic.xp.security.IdProviderKey)1 IdProviderKeys (com.enonic.xp.security.IdProviderKeys)1 PrincipalType (com.enonic.xp.security.PrincipalType)1