Example usage for org.springframework.data.mongodb.core.query Criteria where

List of usage examples for org.springframework.data.mongodb.core.query Criteria where

Introduction

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

Prototype

public static Criteria where(String key) 

Source Link

Document

Static factory method to create a Criteria using the provided key

Usage

From source file:br.com.ezequieljuliano.argos.persistence.LoggerDAO.java

public boolean termsOfNotification(Logger logger) {
    Criteria criteria = Criteria.where("_id").is(new ObjectId(logger.getId()));
    List<Logger> loggers = findByTermsAndCriteria(logger.getUser().getTerms(), criteria, 1);
    return !loggers.isEmpty();
}

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:things.mongo.MongoConnector.java

public Observable<? extends Thing<?>> getChildrenMatchingTypeAndKey(Thing<?> thing, String typeMatcher,
        String keyMatcher) {/*  ww  w  . j  a  va  2s . c o m*/
    Query q = new Query();
    String regexType = MatcherUtils.convertGlobToRegex(typeMatcher);
    String regexKey = MatcherUtils.convertGlobToRegex(keyMatcher);
    q.addCriteria(Criteria.where("parents").is(thing.getId()).and("thingType").regex(regexType).and("key")
            .regex(regexKey));

    List<Thing> things = mongoTemplate.find(q, Thing.class);
    return Observable.from(things).map(t -> (Thing<?>) t);
}

From source file:example.springdata.mongodb.aggregation.SpringBooksIntegrationTests.java

/**
 * Retrieve the number of pages per author (and divide the number of pages by the number of authors).
 *///w  w  w. j  av  a 2s . co m
@Test
public void shouldRetrievePagesPerAuthor() {

    Aggregation aggregation = newAggregation( //
            match(Criteria.where("volumeInfo.authors").exists(true)), //
            replaceRoot("volumeInfo"), //
            project("authors", "pageCount") //
                    .and(ArithmeticOperators.valueOf("pageCount") //
                            .divideBy(ArrayOperators.arrayOf("authors").length()))
                    .as("pagesPerAuthor"),
            unwind("authors"), //
            group("authors") //
                    .sum("pageCount").as("totalPageCount") //
                    .sum("pagesPerAuthor").as("approxWritten"), //
            sort(Direction.DESC, "totalPageCount"));

    AggregationResults<PagesPerAuthor> result = operations.aggregate(aggregation, "books",
            PagesPerAuthor.class);

    PagesPerAuthor pagesPerAuthor = result.getMappedResults().get(0);

    assertThat(pagesPerAuthor.getAuthor()).isEqualTo("Josh Long");
    assertThat(pagesPerAuthor.getTotalPageCount()).isEqualTo(1892);
    assertThat(pagesPerAuthor.getApproxWritten()).isEqualTo(573);
}

From source file:quanlyhocvu.api.mongodb.DAO.AuthorityDAO.java

/**
 * get list user by role name/*from  w  w w.j a  va2 s  .  c om*/
 *
 * @param rolename
 * @return
 */
public List<UserDTO> getUsersByRoleName(String rolename) {
    RoleDTO role = getRoleByRoleName(rolename);
    Query query = Query.query(Criteria.where("roles.$id").is(new ObjectId(role.getId())));
    return mongoOperation.find(query, UserDTO.class);
}

From source file:demo.SpringTest.java

@Test
public void testOKBecauseOfNoCyclicRelationBetweenDocumentsDbRefRelated() {
    EagerFrom three = new EagerFrom("three");
    EagerTo four = new EagerTo("four");
    template.save(three);/* w  ww  . j ava  2  s.c o m*/
    template.save(four);

    three.refToFour = four;
    template.save(three);

    EagerFrom foundThree = template.findOne(Query.query(Criteria.where("id").is(three.id)), EagerFrom.class);
    Assert.assertThat(foundThree.refToFour, Matchers.notNullValue());
    Assert.assertThat(foundThree.refToFour, IsInstanceOf.instanceOf(EagerTo.class));
    Assert.assertThat(foundThree.refToFour.id, Matchers.is("four"));
    Assert.assertThat(foundThree.refToFour.refToThree, Matchers.nullValue());

    EagerTo foundFour = template.findOne(Query.query(Criteria.where("id").is(four.id)), EagerTo.class);
    Assert.assertThat(foundFour.refToThree, Matchers.nullValue());
}

From source file:it.smartcommunitylab.climb.contextstore.controller.ChildController.java

@RequestMapping(value = "/api/child/{ownerId}/{objectId}", method = RequestMethod.DELETE)
public @ResponseBody String deleteChild(@PathVariable String ownerId, @PathVariable String objectId,
        HttpServletRequest request, HttpServletResponse response) throws Exception {
    Criteria criteria = Criteria.where("objectId").is(objectId);
    Child child = storage.findOneData(Child.class, criteria, ownerId);
    if (!validateAuthorizationByExp(ownerId, child.getInstituteId(), child.getSchoolId(), null, "ALL",
            request)) {/*from w ww. ja  v  a  2  s  .  c  o  m*/
        throw new UnauthorizedException("Unauthorized Exception: token not valid");
    }
    storage.removeChild(ownerId, objectId);
    if (logger.isInfoEnabled()) {
        logger.info(String.format("deleteChild[%s]:%s", ownerId, objectId));
    }
    return "{\"status\":\"OK\"}";
}

From source file:com.traffitruck.service.MongoDAO.java

public void updateLoad(Load load) {
    Query q = new Query();
    q.addCriteria(Criteria.where("_id").is(load.getId()));
    Update update = new Update();
    update.set("source", load.getSource());
    update.set("sourceLocation", load.getSourceLocation());
    update.set("destinationLocation", load.getDestinationLocation());
    update.set("destination", load.getDestination());
    update.set("driveDate", load.getDriveDate());
    update.set("suggestedQuote", load.getSuggestedQuote());
    update.set("weight", load.getWeight());
    update.set("volume", load.getVolume());
    update.set("comments", load.getComments());
    update.set("comments", load.getComments());
    update.set("quantity", load.getQuantity());
    update.set("loadingType", load.getLoadingType());
    update.set("downloadingType", load.getDownloadingType());
    update.set("name", load.getName());
    update.set("waitingTime", load.getWaitingTime());
    if (load.getHasPhoto()) {
        update.set("loadPhoto", load.getLoadPhoto());
        update.set("hasPhoto", load.getHasPhoto());
    }// ww  w.j  ava 2s .c  om
    mongoTemplate.updateFirst(q, update, Load.class);
}

From source file:com.gongpingjia.carplay.service.impl.ActivityServiceImpl.java

private void saveInterestMessage(String userId, Activity activity, Long current) {
    InterestMessage oldMessage = interestMessageDao
            .findOne(Query.query(Criteria.where("relatedId").is(activity.getActivityId())));
    if (oldMessage == null) {
        LOG.debug("Old message is not exist, with activityId:{}", activity.getActivityId());
        InterestMessage interestMessage = new InterestMessage();
        interestMessage.setUserId(userId);
        interestMessage.setType(InterestMessage.USER_ACTIVITY);
        interestMessage.setRelatedId(activity.getActivityId());
        interestMessage.setCreateTime(current);
        interestMessageDao.save(interestMessage);
    } else {//from  w w  w.j  ava 2s  . com
        LOG.debug("Old message is exist, with activityId:{}, update create time", activity.getActivityId());
        interestMessageDao.update(Query.query(Criteria.where("relatedId").is(activity.getActivityId())),
                Update.update("createTime", current));
    }
}

From source file:no.nlf.dal.ParachutistController.java

public boolean validateUser(String melwinId) {
    Query searchPerson = new Query(Criteria.where("melwinId").is(melwinId));
    MongoParachutist mp = appContext.mongoOperation().findOne(searchPerson, MongoParachutist.class);

    if (mp == null)
        return false;

    return true;// w  w  w.  j a v a  2 s. c o m
}