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

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

Introduction

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

Prototype

public Criteria and(String key) 

Source Link

Document

Static factory method to create a Criteria using the provided key

Usage

From source file:eu.trentorise.smartcampus.communicatorservice.storage.CommunicatorStorage.java

public Notification getObjectByIdAndUser(String id, String userId, Class<Notification> class1)
        throws NotFoundException {
    Criteria criteria = new Criteria();
    criteria = criteria.and("id").is(id);
    if (userId != null && userId.compareTo("") != 0) {
        criteria.and("content.user").is(userId);
    }/*from   ww w  . ja v a2 s. c  o  m*/
    criteria = criteria.and("deleted").is(false);
    List<Notification> x = find(Query.query(criteria), Notification.class);
    if (x.isEmpty())
        throw new NotFoundException();
    return x.get(FIRST);
}

From source file:eu.trentorise.smartcampus.communicatorservice.storage.CommunicatorStorage.java

public Notification getObjectByIdAndApp(String id, String capp, Class<Notification> class1)
        throws NotFoundException {

    Criteria criteria = new Criteria();
    criteria = criteria.and("id").is(id);
    if (capp != null && capp.compareTo("") != 0) {
        criteria.and("content.type").is(capp);
    }//from  w w  w  .ja  va  2 s  .c  om
    criteria = criteria.and("deleted").is(false);
    List<Notification> x = find(Query.query(criteria), Notification.class);
    if (x.isEmpty())
        throw new NotFoundException();
    return x.get(FIRST);
}

From source file:eu.trentorise.smartcampus.profileservice.storage.ProfileStorage.java

public List<ExtendedProfile> findExtendedProfiles(String profileId, Map<String, Object> profileAttrs) {
    Criteria criteria = new Criteria();
    criteria = Criteria.where("content.profileId").is(profileId);
    for (String key : profileAttrs.keySet()) {
        criteria.and("content.content." + key).is(profileAttrs.get(key));
    }//from  w ww  .  j a v a 2s. com
    criteria.and("type").is(ExtendedProfile.class.getCanonicalName());
    criteria.and("deleted").is(false);

    List<ExtendedProfile> profiles = find(Query.query(criteria), ExtendedProfile.class);
    return profiles;
}

From source file:com.avanza.ymer.MongoQueryFactory.java

private Criteria addCriteria(Criteria c, String fieldName, Object mongoValue) {
    if (c == null) {
        return Criteria.where(fieldName).is(mongoValue);
    } else {//from  w  ww  .j av  a2  s. c o  m
        return c.and(fieldName).is(mongoValue);
    }
}

From source file:se.inera.axel.shs.broker.messagestore.internal.MongoMessageLogAdminService.java

private Criteria buildCriteria(Filter filter) {
    Criteria criteria = new Criteria();

    if (filter.getTo() != null) {
        criteria = criteria.and("label.to.value").regex("^" + filter.getTo());
    }//ww w. jav  a  2s .com

    if (filter.getFrom() != null) {
        criteria = criteria.and("label.originatorOrFrom.value").regex("^" + filter.getFrom());
    }

    if (filter.getTxId() != null) {
        criteria = criteria.and("label.txId").regex("^" + filter.getTxId());
    }

    if (filter.getCorrId() != null) {
        criteria = criteria.and("label.corrId").regex("^" + filter.getCorrId());
    }

    if (filter.getFilename() != null) {
        criteria = criteria.and("label.content.dataOrCompound.filename").regex("^" + filter.getFilename());
    }

    if (filter.getProduct() != null) {
        criteria = criteria.and("label.product.value").regex("^" + filter.getProduct());
    }

    /* show both acknowledged and un-acknowledged messages by default */
    if (filter.getAcknowledged() != null && filter.getAcknowledged() == false) {
        criteria = criteria.and("acknowledged").in(null, false);
    } else if (filter.getAcknowledged() != null && filter.getAcknowledged() == true) {
        criteria = criteria.and("acknowledged").is(true);
    }

    /* don't show archived messages at all, unless asked to. */
    if (filter.getArchived() == null || filter.getArchived() == false) {
        criteria = criteria.and("archived").in(false, null);
    } else {
        criteria = criteria.and("archived").is(true);
    }

    if (filter.getState() != null) {
        criteria = criteria.and("state").is(filter.getState());
    }

    return criteria;
}

From source file:eu.cloudwave.wp5.feedbackhandler.repositories.ProcedureExecutionRepositoryImpl.java

/**
 * {@inheritDoc}// w w  w  .j  ava2  s . c o m
 */
@Override
public List<ClientRequestCollector> getRequestsByCallee(final String callee, final Long timeRangeFrom,
        final Long timeRangeTo) {
    Criteria matchCriteria = getClientRequestAnnotationCriteria();
    matchCriteria = matchCriteria.and(ANNOTATION_TO_ATTRIBUTE).is(callee);
    matchCriteria = addTimeRangeCriteria(matchCriteria, timeRangeFrom, timeRangeTo);

    return getRequestsWithCriteria(matchCriteria);
}

From source file:eu.cloudwave.wp5.feedbackhandler.repositories.ProcedureExecutionRepositoryImpl.java

/**
 * {@inheritDoc}/* w w  w. j  av  a  2  s  . c  om*/
 */
@Override
public List<ClientRequestCollector> getRequestsByCaller(String caller, final Long timeRangeFrom,
        final Long timeRangeTo) {
    Criteria matchCriteria = getClientRequestAnnotationCriteria();
    matchCriteria = matchCriteria.and(ANNOTATION_FROM_ATTRIBUTE).is(caller);
    matchCriteria = addTimeRangeCriteria(matchCriteria, timeRangeFrom, timeRangeTo);

    return getRequestsWithCriteria(matchCriteria);
}

From source file:eu.trentorise.smartcampus.communicatorservice.storage.CommunicatorStorage.java

private Criteria createNotificationSearchWithTypeCriteria(String user, String capp, Long since,
        NotificationFilter filter) {
    Criteria criteria = new Criteria();
    // user is obligatory
    // criteria.and("user").is(user);
    // only non-deleted
    criteria = criteria.and("deleted").is(false);

    if (capp != null && capp.compareTo("") != 0) {
        criteria = criteria.and("content.type").is(capp);
    }/*from  w w w.  j a va 2s  . com*/
    //      if (user != null && user.compareTo("") != 0) {
    criteria = criteria.and("content.user").is(user);
    //      }
    if (since != null) {
        criteria = criteria.and("content.timestamp").gte(since);
    }
    if (filter.isReaded() != null) {
        criteria = criteria.and("content.readed").is(filter.isReaded());
    }
    if (filter.isStarred() != null) {
        criteria = criteria.and("content.starred").is(filter.isStarred());
    }
    if (filter.getSourceType() != null) {
        criteria = criteria.and("content.type").is(filter.getSourceType());
    }
    if (filter.getLabelId() != null) {
        criteria = criteria.and("content.labelIds").is(filter.getLabelId());
    }
    if (filter.getSearchText() != null) {
        criteria = criteria.orOperator(new Criteria().and("content.title").regex(filter.getSearchText(), "i"),
                new Criteria().and("content.description").regex(filter.getSearchText(), "i"));
    }
    return criteria;
}

From source file:eu.trentorise.game.managers.DBPlayerManager.java

private StatePersistence persist(String gameId, String playerId, List<GenericObjectPersistence> concepts,
        CustomData customData, Map<String, Object> metadata) {
    if (StringUtils.isBlank(gameId) || StringUtils.isBlank(playerId)) {
        throw new IllegalArgumentException("field gameId and playerId of PlayerState MUST be set");
    }/*  w w  w.j ava 2 s.  co m*/

    Criteria criteria = new Criteria();
    criteria = criteria.and("gameId").is(gameId).and("playerId").is(playerId);
    Query query = new Query(criteria);
    Update update = new Update();
    if (concepts != null) {
        update.set("concepts", concepts);
    }
    if (customData != null) {
        update.set("customData", customData);
    }
    if (metadata != null) {
        update.set("metadata", metadata);
    }
    FindAndModifyOptions options = new FindAndModifyOptions();
    options.upsert(true);
    options.returnNew(true);
    return mongoTemplate.findAndModify(query, update, options, StatePersistence.class);
}

From source file:eu.cloudwave.wp5.feedbackhandler.repositories.ProcedureExecutionRepositoryImpl.java

/**
 * Helper method that adds time criteria to given match criteria
 * /*ww w.  ja  v  a2  s  . c om*/
 * @param criteria
 * @param timeRangeFrom
 * @param timeRangeTo
 * @return criteria
 */
private Criteria addTimeRangeCriteria(Criteria criteria, Long timeRangeFrom, Long timeRangeTo) {
    if (timeRangeFrom == null && timeRangeTo == null) {
        return criteria;
    } else if (timeRangeFrom != null && timeRangeTo == null) {
        // greater than or equal
        return criteria.and(TIME_FIELD).gte(timeRangeFrom);
    } else if (timeRangeFrom == null && timeRangeTo != null) {
        // less than or equal
        return criteria.and(TIME_FIELD).lte(timeRangeTo);
    } else {
        // We have to use the andOperator instead of and() due to limitations of the com.mongodb.BasicDBObject when it
        // comes to multiple criteria on the same field (TIME_VALUE)
        return criteria.andOperator(Criteria.where(TIME_FIELD).gte(timeRangeFrom),
                Criteria.where(TIME_FIELD).lte(timeRangeTo));
    }
}