Commit 14cc2b4b authored by Matija Obreza's avatar Matija Obreza
Browse files

Merge branch '19-autocomplete-oauthclient' into 'master'

Autocomplete OAuthClient

Closes #19

See merge request genesys-pgr/application-blocks!18
parents 36bb3422 17c96f3a
...@@ -16,9 +16,13 @@ ...@@ -16,9 +16,13 @@
package org.genesys.blocks.oauth.persistence; package org.genesys.blocks.oauth.persistence;
import org.genesys.blocks.oauth.model.OAuthClient; import org.genesys.blocks.oauth.model.OAuthClient;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import java.util.List;
/** /**
* The Interface OAuthClientRepository. * The Interface OAuthClientRepository.
*/ */
...@@ -42,4 +46,14 @@ public interface OAuthClientRepository extends JpaRepository<OAuthClient, Long> ...@@ -42,4 +46,14 @@ public interface OAuthClientRepository extends JpaRepository<OAuthClient, Long>
*/ */
OAuthClient findByIdAndVersion(long id, int version); OAuthClient findByIdAndVersion(long id, int version);
/**
* Autocomplete OAuth clients by title.
*
* @param title the title
* @param pageable the pageable
* @return list of auth clients
*/
@Query("select client from OAuthClient client where client.title like ?1")
List<OAuthClient> autocompleteByTitle(String title, Pageable pageable);
} }
...@@ -70,4 +70,12 @@ public interface OAuthClientDetailsService extends ClientDetailsService { ...@@ -70,4 +70,12 @@ public interface OAuthClientDetailsService extends ClientDetailsService {
*/ */
OAuthClient removeClient(OAuthClient oauthClient); OAuthClient removeClient(OAuthClient oauthClient);
/**
* Autocomplete OAuth clients by title.
*
* @param title the title
* @return list of auth clients
*/
List<OAuthClient> autocompleteClients(String title);
} }
...@@ -20,6 +20,7 @@ import java.math.BigInteger; ...@@ -20,6 +20,7 @@ import java.math.BigInteger;
import java.security.MessageDigest; import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
...@@ -38,6 +39,7 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -38,6 +39,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.cache.annotation.CacheEvict; import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable; import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort; import org.springframework.data.domain.Sort;
import org.springframework.security.oauth2.common.DefaultExpiringOAuth2RefreshToken; import org.springframework.security.oauth2.common.DefaultExpiringOAuth2RefreshToken;
import org.springframework.security.oauth2.common.OAuth2AccessToken; import org.springframework.security.oauth2.common.OAuth2AccessToken;
...@@ -637,4 +639,11 @@ public class OAuthServiceImpl implements OAuthClientDetailsService, OAuthTokenSt ...@@ -637,4 +639,11 @@ public class OAuthServiceImpl implements OAuthClientDetailsService, OAuthTokenSt
client.apply(updates); client.apply(updates);
return oauthClientRepository.save(client); return oauthClientRepository.save(client);
} }
@Override
public List<OAuthClient> autocompleteClients(final String title) {
if (StringUtils.isBlank(title) || title.length() < 4)
return Collections.emptyList();
return oauthClientRepository.autocompleteByTitle(title + "%", new PageRequest(0, 10, new Sort("title")));
}
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment