Example usage for org.springframework.data.mongodb.core.query Query addCriteria

List of usage examples for org.springframework.data.mongodb.core.query Query addCriteria

Introduction

In this page you can find the example usage for org.springframework.data.mongodb.core.query Query addCriteria.

Prototype

public Query addCriteria(CriteriaDefinition criteriaDefinition) 

Source Link

Document

Adds the given CriteriaDefinition to the current Query .

Usage

From source file:com.tlantic.integration.authentication.service.security.TokenStoreService.java

@Override
public OAuth2Authentication readAuthenticationForRefreshToken(OAuth2RefreshToken token) {
    Query query = new Query();
    query.addCriteria(Criteria.where("tokenId").is(token.getValue()));
    OAuth2AuthenticationRefreshToken auth2AuthenticationRefreshToken = mongoTemplate.findOne(query,
            OAuth2AuthenticationRefreshToken.class, "oauth2_refresh_token");
    return auth2AuthenticationRefreshToken.getAuthentication();
}

From source file:com.tlantic.integration.authentication.service.security.TokenStoreService.java

@Override
public Collection<OAuth2AccessToken> findTokensByClientId(String clientId) {
    Query query = new Query();
    query.addCriteria(Criteria.where("clientId").is(clientId));
    List<OAuth2AuthenticationAccessToken> accessTokens = mongoTemplate.find(query,
            OAuth2AuthenticationAccessToken.class, "oauth2_access_token");
    return extractAccessTokens(accessTokens);
}

From source file:com.tlantic.integration.authentication.service.security.TokenStoreService.java

@Override
public Collection<OAuth2AccessToken> findTokensByClientIdAndUserName(String clientId, String userName) {
    Query query = new Query();
    query.addCriteria(Criteria.where("clientId").is(clientId));
    query.addCriteria(Criteria.where("userName").is(userName));
    List<OAuth2AuthenticationAccessToken> accessTokens = mongoTemplate.find(query,
            OAuth2AuthenticationAccessToken.class, "oauth2_access_token");
    return extractAccessTokens(accessTokens);
}

From source file:com.tlantic.integration.authentication.service.security.TokenStoreService.java

@Override
public void removeAccessToken(OAuth2AccessToken accessToken) {
    Query query = new Query();
    query.addCriteria(Criteria.where("tokenId").is(accessToken.getValue()));
    OAuth2AuthenticationAccessToken token = mongoTemplate.findOne(query, OAuth2AuthenticationAccessToken.class,
            "oauth2_access_token");
    if (token != null) {
        oAuth2AccessTokenRepository.delete(token);
    }//from   w  ww.  ja v a 2s  .c o m
}

From source file:com.tlantic.integration.authentication.service.security.TokenStoreService.java

@Override
public void removeRefreshToken(OAuth2RefreshToken accessToken) {
    Query query = new Query();
    query.addCriteria(Criteria.where("tokenId").is(accessToken.getValue()));
    OAuth2AuthenticationRefreshToken token = mongoTemplate.findOne(query,
            OAuth2AuthenticationRefreshToken.class, "oauth2_refresh_token");
    if (token != null) {
        oAuth2RefreshTokenRepository.delete(token);
    }/*  w  ww  .j a v a  2 s.  c  o m*/
}

From source file:com.tlantic.integration.authentication.service.security.TokenStoreService.java

@Override
public void removeAccessTokenUsingRefreshToken(OAuth2RefreshToken refreshToken) {
    Query query = new Query();
    query.addCriteria(Criteria.where("refreshToken").is(refreshToken.getValue()));
    OAuth2AuthenticationAccessToken token = mongoTemplate.findOne(query, OAuth2AuthenticationAccessToken.class,
            "oauth2_access_token");
    if (token != null) {
        oAuth2AccessTokenRepository.delete(token);
    }//from  ww w  .  java  2s. co  m
}

From source file:com.tlantic.integration.authentication.service.security.TokenStoreService.java

@Override
public OAuth2AccessToken readAccessToken(String tokenId) {
    Query query = new Query();
    query.addCriteria(Criteria.where("tokenId").is(tokenId));
    OAuth2AuthenticationAccessToken token = mongoTemplate.findOne(query, OAuth2AuthenticationAccessToken.class,
            "oauth2_access_token");
    if (null == token) {
        throw new InvalidTokenException("Token not valid");
    }//  w  w  w  .  j ava  2s.  co m
    return token.getoAuth2AccessToken();
}

From source file:com.tlantic.integration.authentication.service.security.TokenStoreService.java

@Override
public OAuth2AccessToken getAccessToken(OAuth2Authentication authentication) {
    String authenticationId = authenticationKeyGenerator.extractKey(authentication);
    if (null == authenticationId) {
        return null;
    }//from w w  w . j a  v a  2  s  . co  m
    Query query = new Query();
    query.addCriteria(Criteria.where("authenticationId").is(authenticationId));
    OAuth2AuthenticationAccessToken token = mongoTemplate.findOne(query, OAuth2AuthenticationAccessToken.class,
            "oauth2_access_token");
    return token == null ? null : token.getoAuth2AccessToken();
}

From source file:app.data.local.CollectionBindingRepositoryImpl.java

@Nullable
@Override/*  w ww .j  a va2s .  c om*/
public List<CollectionBinding> findByTags(List<String> tags, @Nullable Pageable pageable) {
    Query query = new Query();
    query.addCriteria(Criteria.where("tags").in(tags)).with(pageable);
    return mMongoTemplate.find(query, CollectionBinding.class);

    //        // such as [{$project: {key:"$key", count: {$size: {$ifNull: ["$value",[]]}}}}, {$sort: {"count":1}}]
    //        // FIXME: 2016/9/30 [block] waiting for spring-data-mongodb 1.10 release
    //        // https://github.com/spring-projects/spring-data-mongodb/blob/eb1392cc1a0fcf25aa9e636863d36e6fee73e632/src/main/asciidoc/new-features.adoc
    //        // due to $ifNull
    //        List<AggregationOperation> operations = new ArrayList<>();
    //        operations.add(Aggregation.match(Criteria.where("tags").in(tags)));
    //
    //        String op = "{ $project : { \"collectionId\" : \"$collectionId\" , \"favorsCount\" : { $size : { \"$ifNull\" : [\"$favors\", []]}}}}";
    //        // but the result will be modify to ...{ "$ifNull" : [ "$favors" , { }]}...
    //        DBObject dbObject = BasicDBObject.parse(op);
    //        operations.add(new CommonAggregationOperation(dbObject));
    ////        operations.add(Aggregation.project("collectionId")
    ////            .and(ifNull("favors", new ArrayList<CollectionBinding.Data>())).size().as("favorsCount"));
    //        //operations.add(Aggregation.sort(Sort.Direction.DESC, "favorsCount"));
    //        if (pageable != null) {
    //            operations.add(Aggregation.skip(pageable.getOffset()));
    //            operations.add(Aggregation.limit(pageable.getPageSize()));
    //        }
    //        TypedAggregation<CollectionBinding> aggregation = Aggregation.newAggregation(CollectionBinding.class, operations);
    //        logger.info(aggregation.toString());
    ////        Aggregation aggregation = Aggregation.newAggregation(operations);
    //        AggregationResults<CollectionBindingTemp> results =
    //            mMongoTemplate.aggregate(aggregation, CollectionBindingTemp.class);
    //        List<CollectionBindingTemp> tempList = results.getMappedResults();
    //
    //        List<CollectionBinding> colBindings = new ArrayList<>(tempList.size());
    //        for (CollectionBindingTemp item : tempList) {
    //            CollectionBinding colBinding = findByCollectionId(item.getCollectionId());
    //            // colBinding is non-null
    //            colBindings.add(colBinding);
    //        }
    //        return colBindings;
}

From source file:com.epam.ta.reportportal.database.dao.ShareableRepositoryImpl.java

@Override
public Page<T> findAllByFilter(Filter filter, Pageable pageable, String projectName, String owner) {
    if (filter == null || pageable == null || projectName == null || owner == null) {
        return new PageImpl<>(new ArrayList<>());
    }/*from  w w  w.  j  av a  2s . c o  m*/
    Query query = QueryBuilder.newBuilder().with(filter).with(pageable).build();
    query.addCriteria(getAllEntitiesCriteria(projectName, owner));
    return findPage(query, pageable);
}