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

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

Introduction

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

Prototype

public Criteria() 

Source Link

Usage

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());
    }/*from   w w  w .ja va 2  s  . c  om*/

    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.trentorise.smartcampus.profileservice.storage.ProfileStorage.java

/**
 * @param entityId/*w  w w . j  ava 2  s .  c  o m*/
 */
public ExtendedProfile getObjectByEntityId(Long entityId, String profileId) {
    Criteria criteria = new Criteria();
    criteria = Criteria.where("content.socialId").is(entityId);
    if (profileId != null)
        criteria.and("content.profileId").is(profileId);
    criteria.and("type").is(ExtendedProfile.class.getCanonicalName());
    criteria.and("deleted").is(false);

    List<ExtendedProfile> profiles = find(Query.query(criteria), ExtendedProfile.class);
    return profiles == null || profiles.isEmpty() ? null : profiles.get(0);
}

From source file:eu.trentorise.smartcampus.communicatorservice.manager.UserAccountManager.java

/**
 * retrieves all the {@link UserAccount} of a given user
 * /*from w ww.  j a  va  2s .c  om*/
 * @param uid
 *            id of the owner of user storage accounts
 * @param appName
 * 
 * @return a list of UserAccount of the given user id and appName
 */
public UserAccount findByUserIdAndAppName(String userid, String appId) {
    Criteria criteria = new Criteria();
    criteria = criteria.and("userId").is(userid);
    criteria = criteria.and("appId").is(appId);
    return db.findOne(Query.query(criteria), UserAccount.class);
}

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 .co  m*/
    //      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:com.epam.ta.reportportal.database.dao.UserFilterRepositoryCustomImpl.java

@Override
public List<UserFilter> findAvailableFilters(String projectName, String[] ids, String userName) {
    //where ID from provided array AND it's shared on project
    Query q = Query.query(where(ID).in(Arrays.asList(ids))
            .andOperator(new Criteria().orOperator(where(OWNER).is(userName), where(PROJECT).is(projectName),
                    where(ENTRIES).elemMatch(where("projectId").is(projectName)))));
    return mongoTemplate.find(q, UserFilter.class);
}

From source file:org.starfishrespect.myconsumption.server.business.repositories.repositoriesimpl.ValuesRepositoryImpl.java

@Override
public List<SensorDataset> getSensor(Date startTime, Date endTime) throws DaoException {
    Query timeQuery = new Query(new Criteria().andOperator(Criteria.where("timestamp").gte(startTime),
            Criteria.where("timestamp").lte(endTime)));
    timeQuery.with(new Sort(Sort.Direction.ASC, "timestamp"));
    return mongoOperation.find(timeQuery, SensorDataset.class, collectionName);
}

From source file:eu.trentorise.smartcampus.communicatorservice.manager.UserAccountManager.java

/**
 * retrieves all the {@link UserAccount} for a given appId
 * /*from   w w w .  j  a v a2s . c  o  m*/
 * @param uid
 *            id of the owner of user storage accounts
 * @param appName
 * 
 * @return a list of UserAccount of the given user id and appName
 */
public List<UserAccount> findByAppName(String appId) {
    Criteria criteria = new Criteria();
    criteria = criteria.and("appId").is(appId);
    return db.find(Query.query(criteria), UserAccount.class);
}

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");
    }/*from   w w  w.  jav a 2s.c o 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:com.epam.ta.reportportal.database.dao.ShareableRepositoryImpl.java

/**
 * Create criteria for loading owned entities and shared to specified project entities
 * //  ww  w  .  j av  a  2s . co m
 * @param projectName
 * @param userName
 * @return
 */
private Criteria getAllEntitiesCriteria(String projectName, String userName) {
    return new Criteria().orOperator(
            new Criteria().andOperator(Criteria.where("acl.entries.projectId").is(projectName),
                    Criteria.where("acl.entries.permissions").is(AclPermissions.READ.name())),
            new Criteria().andOperator(Criteria.where("acl.ownerUserId").is(userName),
                    Criteria.where("projectName").is(projectName)));
}

From source file:tv.arte.resteventapi.core.querying.mongo.db.AbstractBaseMongoDBQueryBuilder.java

/**
 * Build a Mongo query based on a field name, {@link QueryOp} and a given value suited for the 
 * provided operation /*from  w w  w  . j  ava 2  s.c  o  m*/
 * 
 * @param fieldName The field name (Should never be <code>null</code>)
 * @param queryOpParamValue A query op / value param
 * @return A Mongo query based on a field name, {@link QueryOp} and a given value suited for the 
 *          provided operation 
 */
protected Criteria buildSimpleCriteria(String fieldName, QueryOpParamValue<?> queryOpParamValue) {
    Criteria criteria = null;
    QueryOp paramQueryOp = queryOpParamValue.getQueryOp();
    Object paramValue = queryOpParamValue.getValue();

    if (paramQueryOp == null) {
        if (paramValue == null) {
            criteria = Criteria.where(fieldName).exists(false);
        } else {
            criteria = Criteria.where(fieldName).is(paramValue);
        }
    } else {
        switch (paramQueryOp) {
        case GT:
            criteria = Criteria.where(fieldName).gt(paramValue);
            break;
        case GTE:
            criteria = Criteria.where(fieldName).gte(paramValue);
            break;
        case LT:
            criteria = Criteria.where(fieldName).lt(paramValue);
            break;
        case LTE:
            criteria = Criteria.where(fieldName).lte(paramValue);
            break;
        case NE:
            criteria = Criteria.where(fieldName).ne(paramValue);
            break;
        case IN:
            criteria = Criteria.where(fieldName).in((Collection<?>) paramValue);
            break;
        case NIN:
            criteria = Criteria.where(fieldName).nin((Collection<?>) paramValue);
            break;
        case ALL:
            criteria = Criteria.where(fieldName).all((Collection<?>) paramValue);
            break;
        case ONLY:
            criteria = new Criteria().andOperator(Criteria.where(fieldName).all((Collection<?>) paramValue),
                    Criteria.where(fieldName).size(((Collection<?>) paramValue).size()));
            break;
        default:
            criteria = new Criteria();
            break;
        }
    }

    return criteria;
}