Java Code Examples for com.hazelcast.query.PagingPredicate#setPage()

The following examples show how to use com.hazelcast.query.PagingPredicate#setPage() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Oauth2RefreshTokenGetHandler.java    From light-oauth2 with Apache License 2.0 6 votes vote down vote up
@Override
public void handleRequest(HttpServerExchange exchange) throws Exception {
    IMap<String, RefreshToken> tokens = CacheStartupHookProvider.hz.getMap("tokens");
    Deque<String> userIdDeque = exchange.getQueryParameters().get("userId");
    String userId = userIdDeque == null? "%" : userIdDeque.getFirst() + "%";
    int page = Integer.valueOf(exchange.getQueryParameters().get("page").getFirst()) - 1;
    Deque<String> pageSizeDeque = exchange.getQueryParameters().get("pageSize");
    int pageSize = pageSizeDeque == null? 10 : Integer.valueOf(pageSizeDeque.getFirst());
    if(logger.isDebugEnabled()) logger.debug("userId = " + userId + " page = " + page + " pageSize = " + pageSize);
    LikePredicate likePredicate = new LikePredicate("userId", userId);

    PagingPredicate pagingPredicate = new PagingPredicate(likePredicate, new RefreshTokenComparator(), pageSize);
    pagingPredicate.setPage(page);
    Collection<RefreshToken> values = tokens.values(pagingPredicate);

    exchange.getResponseHeaders().add(new HttpString("Content-Type"), "application/json");
    exchange.getResponseSender().send(Config.getInstance().getMapper().writeValueAsString(values));
    processAudit(exchange);
}
 
Example 2
Source File: Oauth2UserGetHandler.java    From light-oauth2 with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public void handleRequest(HttpServerExchange exchange) throws Exception {
    IMap<String, User> users = CacheStartupHookProvider.hz.getMap("users");
    Deque<String> userIdDeque = exchange.getQueryParameters().get("userId");
    String userId = userIdDeque == null? "%" : userIdDeque.getFirst() + "%";
    int page = Integer.valueOf(exchange.getQueryParameters().get("page").getFirst()) - 1;
    Deque<String> pageSizeDeque = exchange.getQueryParameters().get("pageSize");
    int pageSize = pageSizeDeque == null? 10 : Integer.valueOf(pageSizeDeque.getFirst());

    LikePredicate likePredicate = new LikePredicate("userId", userId);

    PagingPredicate pagingPredicate = new PagingPredicate(likePredicate, new UserComparator(), pageSize);
    pagingPredicate.setPage(page);
    Collection<User> values = users.values(pagingPredicate);

    for (User value : values) {
        value.setPassword(null);
    }
    exchange.getResponseHeaders().add(Headers.CONTENT_TYPE, "application/json");
    exchange.getResponseSender().send(Config.getInstance().getMapper().writeValueAsString(values));
    processAudit(exchange);
}
 
Example 3
Source File: Oauth2ServiceGetHandler.java    From light-oauth2 with Apache License 2.0 6 votes vote down vote up
@Override
public void handleRequest(HttpServerExchange exchange) throws Exception {
    IMap<String, Service> services = CacheStartupHookProvider.hz.getMap("services");

    Deque<String> serviceIdDeque = exchange.getQueryParameters().get("serviceId");
    String serviceId = serviceIdDeque == null? "%" : serviceIdDeque.getFirst() + "%";
    int page = Integer.valueOf(exchange.getQueryParameters().get("page").getFirst()) - 1;
    Deque<String> pageSizeDeque = exchange.getQueryParameters().get("pageSize");
    int pageSize = pageSizeDeque == null? 10 : Integer.valueOf(pageSizeDeque.getFirst());

    LikePredicate likePredicate = new LikePredicate("serviceId", serviceId);

    PagingPredicate pagingPredicate = new PagingPredicate(likePredicate, new ServiceComparator(), pageSize);
    pagingPredicate.setPage(page);
    Collection<Service> values = services.values(pagingPredicate);

    exchange.getResponseHeaders().add(Headers.CONTENT_TYPE, "application/json");
    exchange.getResponseSender().send(Config.getInstance().getMapper().writeValueAsString(values));
    processAudit(exchange);
}
 
Example 4
Source File: Oauth2ClientGetHandler.java    From light-oauth2 with Apache License 2.0 6 votes vote down vote up
@Override
public void handleRequest(HttpServerExchange exchange) throws Exception {
    IMap<String, Client> clients = CacheStartupHookProvider.hz.getMap("clients");
    Deque<String> clientNameDeque = exchange.getQueryParameters().get("clientName");
    String clientName = clientNameDeque == null? "%" : clientNameDeque.getFirst() + "%";
    int page = Integer.valueOf(exchange.getQueryParameters().get("page").getFirst()) - 1;
    Deque<String> pageSizeDeque = exchange.getQueryParameters().get("pageSize");
    int pageSize = pageSizeDeque == null? 10 : Integer.valueOf(pageSizeDeque.getFirst());

    LikePredicate likePredicate = new LikePredicate("clientName", clientName);

    PagingPredicate pagingPredicate = new PagingPredicate(likePredicate, new ClientComparator(), pageSize);
    pagingPredicate.setPage(page);
    Collection<Client> values = clients.values(pagingPredicate);

    List results = new ArrayList();
    for (Client value : values) {
        Client c = Client.copyClient(value);
        c.setClientSecret(null);
        results.add(c);
    }
    exchange.getResponseHeaders().add(new HttpString("Content-Type"), "application/json");
    exchange.getResponseSender().send(Config.getInstance().getMapper().writeValueAsString(results));
    processAudit(exchange);
}
 
Example 5
Source File: CallOutQuene.java    From youkefu with Apache License 2.0 5 votes vote down vote up
/**
 * 外呼监控,包含机器人和人工两个部分
 * @param agentStatus
 */
@SuppressWarnings("unchecked")
public static List<CallOutNames> callOutNames(String calltype , int p , int ps){
	List<CallOutNames> callOutNamesList = new ArrayList<CallOutNames>();
	if(CacheHelper.getCallOutCacheBean()!=null && CacheHelper.getCallOutCacheBean().getCache()!=null) {
		PagingPredicate<String, CallOutNames> pagingPredicate = new PagingPredicate<String, CallOutNames>(  new SqlPredicate( "calltype = '"+calltype+"'") , 10 ) ;
		pagingPredicate.setPage(p);
		callOutNamesList.addAll(((IMap<String , CallOutNames>) CacheHelper.getCallOutCacheBean().getCache()).values(pagingPredicate)) ;
	}
	return callOutNamesList ;
}