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:strat.mining.multipool.stats.persistence.dao.coinshift.impl.AddressStatsDAOMongo.java

@Override
public void deleteAddressStatsBefore(Integer addressId, Date time) {
    Query query = new Query(Criteria.where("refreshTime").lt(time).and("addressId").is(addressId));
    mongoOperation.remove(query, AddressStats.class);

}

From source file:com.enitalk.controllers.bots.EniWordController.java

public void runEniword() {
    try {/*from   w  w  w .j  a v  a 2s . co  m*/

        mongo.updateMulti(Query.query(Criteria.where("eniword.nextPing").exists(false)), new Update()
                .set("eniword.nextPing", new DateTime().minusSeconds(10).toDate()).set("eniword.points", 300),
                "leads");

        Criteria d = Criteria.where("eniword.nextPing").lte(new Date());
        Criteria cal = Criteria.where("calendar").exists(true);
        Criteria unsubscribed = Criteria.where("eniword.disabled").exists(false);

        Query q = Query.query(Criteria.where("eniword.points").gt(0).andOperator(d, cal, unsubscribed));
        q.fields().exclude("_id").include("dest").include("eniword").include("calendar");

        List<HashMap> acolates = mongo.find(q, HashMap.class, "leads");
        ArrayNode leads = jackson.convertValue(acolates, ArrayNode.class);
        Iterator<JsonNode> els = leads.iterator();
        while (els.hasNext()) {
            JsonNode el = els.next();
            String tz = el.at("/calendar/timeZone").asText();
            DateTime now = new DateTime(DateTimeZone.forID(tz));

            if (now.hourOfDay().get() < 9 || now.getHourOfDay() > 20) {
                logger.info("Too late to bother {}", el);
                mongo.updateFirst(Query.query(Criteria.where("dest.sendTo").is(el.at("/dest/sendTo").asLong())),
                        new Update().set("eniword.nextPing", new DateTime().plusHours(1).toDate()), "leads");
                return;
            }

            mongo.updateFirst(Query.query(Criteria.where("dest.sendTo").is(el.at("/dest/sendTo").asLong())),
                    new Update().set("eniword.nextPing", new DateTime().plusSeconds(60 * 40).toDate()),
                    "leads");
            rabbit.send("eniwords", MessageBuilder.withBody(jackson.writeValueAsBytes(el)).build());
        }

    } catch (Exception e) {
        logger.error(ExceptionUtils.getFullStackTrace(e));
    }
}

From source file:uk.gov.nationalarchives.discovery.taxonomy.common.repository.mongo.impl.IAViewUpdateRepositoryImpl.java

@Override
public List<IAViewUpdate> findDocumentsCreatedAfterDocumentAndCreatedBeforeDate(IAViewUpdate afterIAViewUpdate,
        Date ltDate, Integer limit) {
    List<Criteria> listOfCriterias = new ArrayList<Criteria>();
    listOfCriterias.add(new Criteria().orOperator(
            Criteria.where(IAViewUpdate.FIELD_CREATIONDATE).gt(afterIAViewUpdate.getCreationDate()),
            new Criteria().andOperator(
                    Criteria.where(IAViewUpdate.FIELD_CREATIONDATE).gte(afterIAViewUpdate.getCreationDate()),
                    Criteria.where(IAViewUpdate.FIELD_DOCREFERENCE).gt(afterIAViewUpdate.getDocReference()))));
    if (ltDate != null) {
        listOfCriterias.add(Criteria.where(IAViewUpdate.FIELD_CREATIONDATE).lt(ltDate));
    }// ww  w. jav  a  2 s.  c  o m
    Query query = new Query(new Criteria().andOperator(listOfCriterias.toArray(new Criteria[0])));

    query.limit(limit + 1);
    query.with(new Sort(new Order(Sort.Direction.ASC, IAViewUpdate.FIELD_CREATIONDATE),
            new Order(Sort.Direction.ASC, IAViewUpdate.FIELD_DOCREFERENCE)));
    return mongoTemplate.find(query, IAViewUpdate.class);
}

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

public LopHocDTO getLopHocById(String id) {
    Query query = Query.query(Criteria.where("id").is(id));
    return mongoOperation.findOne(query, LopHocDTO.class);
}

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

@Test
public void testComparasion() {
    Log log1 = new Log();
    log1.setLevel(LogLevel.ERROR);/*from   w w w.  j  av a 2  s  .  co  m*/
    mongoOperations.save(log1);

    Log log2 = new Log();
    log2.setLevel(LogLevel.DEBUG);
    mongoOperations.save(log2);

    Query q = Query.query(Criteria.where("level").gt(LogLevel.INFO));

    List<Log> logs = mongoOperations.find(q, Log.class);
    Assert.assertThat(logs, is(not(empty())));
    Assert.assertThat(logs.size(), is(1));
    Assert.assertThat(logs.get(0).getLevel(), is(LogLevel.ERROR));
}

From source file:tv.arte.resteventapi.core.domain.repositories.impl.mongo.db.RestEventRepositoryImpl.java

/**
 * {@inheritDoc}/* w  w w . j a va  2s  .  c o m*/
 */
public boolean exists(Object id) {
    Query query = new Query(Criteria.where("_id").is(id));

    return mongoTemplate.exists(query, RestEvent.class);
}

From source file:demo.SpringNoChangeTest.java

@Test
public void testTwoWithMap() {
    Map values = new HashMap();
    values.put("TITLE", "title two from map wins");
    Two two = new Two("two2", "title two", "desc two", values);
    template.save(two);/*  w  w  w  .j  a  va  2 s  . c  o  m*/

    Two foundTwo = template.findOne(Query.query(Criteria.where("id").is(two.id)), Two.class);
    Assert.assertThat(foundTwo.title, Matchers.is("title two from map wins"));
    Assert.assertThat(foundTwo.desc, Matchers.nullValue());
    Assert.assertThat((String) foundTwo.map.get("TITLE"), Matchers.is("title two from map wins"));
    Assert.assertThat((String) foundTwo.map.get("DESC"), Matchers.nullValue());
}

From source file:de.steilerdev.myVerein.server.model.GridFSRepository.java

/**
 * This function gathers the current club logo. If several files or none matches the defined club logo filename, all of them get deleted.
 * @return The current club logo, or null if there is none or more than one.
 *//*from w w  w .j a  va2  s.com*/
public GridFSDBFile findClubLogo() {
    List<GridFSDBFile> clubLogoFiles;
    try {
        clubLogoFiles = gridFS.find(new Query().addCriteria(Criteria.where("filename").is(clubLogoFileName)));
    } catch (MongoTimeoutException e) {
        logger.warn("Timeout while trying to find club logo");
        return null;
    }

    if (clubLogoFiles == null || clubLogoFiles.isEmpty()) {
        logger.warn("Unable to find any club logo");
        return null;
    } else if (clubLogoFiles.size() > 1) {
        logger.warn("Multiple files matching club logo name, deleting all");
        deleteCurrentClubLogo();
        return null;
    } else {
        return clubLogoFiles.get(0);
    }
}

From source file:com.telefonica.euro_iaas.sdc.pupperwrapper.services.tests.CatalogManagerMongoTest.java

@Before
public void setUp() {

    mongoTemplateMock = mock(MongoTemplate.class);

    catalogManagerMongo = new CatalogManagerMongoImpl4Test();
    catalogManagerMongo.setMongoTemplate(mongoTemplateMock);

    final Node node = new Node();
    node.setId("test");
    node.setGroupName("group");
    node.setManifestGenerated(true);//from  www . j  a va2s . c  om

    Software soft = new Software();
    soft.setName("test");
    soft.setVersion("1.0.0");
    soft.setAction(Action.INSTALL);
    node.addSoftware(soft);

    final Node node2 = new Node();
    node2.setId("test2");
    node2.setGroupName("group2");
    node2.setManifestGenerated(true);

    final Node node3 = new Node();
    node3.setId("test3");
    node3.setGroupName("group2");
    node3.setManifestGenerated(true);

    //        Query query = mock(Query.class);
    Query query = new Query(Criteria.where("id").is("test"));
    when(mongoTemplateMock.findOne(query, Node.class)).thenReturn(node);

    query = new Query(Criteria.where("id").is("test3"));
    when(mongoTemplateMock.findOne(query, Node.class)).thenThrow(new NoSuchElementException());

    when(mongoTemplateMock.findAll(Node.class)).thenReturn(new ArrayList<Node>() {
        {
            add(node);
            add(node2);
            add(node3);
        }
    }).thenReturn(new ArrayList<Node>() {
        {
            add(node);
            add(node2);
            add(node3);
        }
    }).thenReturn(new ArrayList<Node>() {
        {
            add(node);
            add(node2);
        }
    });

    Query queryFindOK = new Query(Criteria.where("groupName").is("groupNameOK"));
    when(mongoTemplateMock.find(queryFindOK, Node.class)).thenReturn(new ArrayList<Node>() {
        {
            add(node);
        }
    });

    Query queryFindErr = new Query(Criteria.where("groupName").is("groupNameErr"));
    when(mongoTemplateMock.find(queryFindErr, Node.class)).thenReturn(null);

}

From source file:org.maodian.flyingcat.im.repository.AccountRepositoryImpl.java

@Override
public void persistSubscriptionRequest(String username, SubscriptionRequest sr) {
    Query query = Query.query(Criteria.where(Account.USERNAME).is(username));
    Update update = new Update().addToSet(Account.UNREAD_REQUEST, sr);
    getMongoTemplate().updateFirst(query, update, Account.class);
}