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

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

Introduction

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

Prototype

public Query(CriteriaDefinition criteriaDefinition) 

Source Link

Document

Creates a new Query using the given CriteriaDefinition .

Usage

From source file:com.skymobi.monitor.service.AlertService.java

public List<Alert> findAlerts(String projectName) {
    Query query = Query.query(Criteria.where("projectName").is(projectName)).limit(50);
    query.sort().on("createTime", Order.DESCENDING);
    return mongoTemplate.find(query, Alert.class, collectionName);
}

From source file:com.enitalk.controllers.OpentokSessionController.java

@RequestMapping(method = RequestMethod.GET, value = "/session/student/{id}", produces = "text/html")
@ResponseBody/*from www  .  ja v a 2s .  c o m*/
public byte[] sessionStudent(@PathVariable String id, HttpServletResponse res) throws IOException {

    try {
        byte[] baseUrl = sessionTeacher(id, res, true);
        String url = new String(baseUrl);
        if (!StringUtils.startsWith(url, "events")) {
            return baseUrl;
        }

        Query q = Query.query(Criteria.where("ii").is(id).andOperator(Criteria.where("status").is(2)));
        q.fields().exclude("_id").include("student").include("ii");
        HashMap ev = mongo.findOne(q, HashMap.class, "events");
        ObjectNode evJson = jackson.convertValue(ev, ObjectNode.class);

        //            url += "?dest=" + evJson.at("/student/dest/sendTo").asLong() + "&i=" + evJson.path("ii").asText();
        url += "?dest=" + evJson.at("/student/email").asText() + "&i=" + evJson.path("ii").asText();
        String signed = signer.signUrl(url, new DateTime().plusMinutes(80));
        res.sendRedirect(signed);

    } catch (Exception e) {
        logger.error(ExceptionUtils.getFullStackTrace(e));
        return "Oops.Something went wrong. Contact us at ceo@enitalk.com".getBytes();
    }

    return null;
}

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

@Override
public SensorDataset getOne(Date timestamp) throws DaoException {
    Query timeQuery = new Query(Criteria.where("timestamp").is(timestamp));
    return mongoOperation.findOne(timeQuery, SensorDataset.class, collectionName);
}

From source file:lodsve.mongodb.core.GenericMongoRepository.java

public Iterable<T> findAll(Iterable<ID> ids) {
    Set<ID> parameters = new HashSet<>(tryDetermineRealSizeOrReturn(ids, 10));
    for (ID id : ids) {
        parameters.add(id);//from  w  w  w. ja v a 2s . c om
    }

    return findAll(new Query(new Criteria(entityInformation.getIdAttribute()).in(parameters)));
}

From source file:com.appleframework.monitor.service.AlertService.java

public List<Alert> findAlerts(String projectName) {
    Query query = Query.query(Criteria.where("projectName").is(projectName)).limit(50);
    //query.sort().on("createTime", Order.DESCENDING);
    query.with(new Sort(Direction.DESC, "createTime"));
    return mongoTemplate.find(query, Alert.class, collectionName);
}

From source file:com.telefonica.euro_iaas.sdc.puppetwrapper.services.impl.CatalogManagerMongoImpl.java

public boolean isLastGroupNode(String groupName) {
    Query searchNodeQuery = new Query(Criteria.where("groupName").is(groupName));
    List<Node> nodeList = mongoTemplate.find(searchNodeQuery, Node.class);
    if (nodeList != null && nodeList.size() == 1) {
        return true;
    } else {//w ww  . j a v  a2  s  .  c  o m
        return false;
    }
}

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

@Override
public Collection<SimpleUser> getSubscribers(String uid) {
    String kState = Account.CONTACTS + "." + SimpleUser.SUB_STATE;
    Query query = Query.query(Criteria.where(Account.USERNAME).is(uid).orOperator(
            Criteria.where(kState).is(SubState.FROM.name()), Criteria.where(kState).is(SubState.BOTH.name())));
    query.fields().include(Account.CONTACTS + ".$").exclude("_id");
    Account account = getMongoTemplate().findOne(query, Account.class);
    return account.getContactList();
}

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

@RabbitListener(queues = "eniwords")
public void consume(Message msg) {
    try {//w w  w .  j ava 2 s.c o m
        JsonNode user = jackson.readTree(msg.getBody());
        logger.info("Sending eniword to student {}", user);

        Integer lastWord = user.at("/eniword/wc").asInt(0) + 1;
        HashMap word = mongo.findOne(Query.query(Criteria.where("i").gt(lastWord)), HashMap.class, "words");
        if (word == null) {
            return;
        }

        ObjectNode wToSend = jackson.convertValue(word, ObjectNode.class);

        String text = "0x1f4d8 <b>EniWord</b>\n";
        text += "0x1f4e2 Word: <b>" + wToSend.path("word").asText() + "</b>\n";
        text += "0x1f4cb Part of speech: <b>" + parts.get(wToSend.path("type").asInt()) + "</b>\n";
        text += "0x1f6a9 <b>Usage:</b>\n";
        JsonNode exs = wToSend.at("/def/examples");
        Iterator<JsonNode> els = exs.elements();
        int i = 1;
        while (els.hasNext() && i < 2) {
            text += i++ + ". " + els.next().path("text").asText() + "\n";
        }

        text += "---------\nWe will send you another awesome word in 40 minutes.\nPress /recommend to get back to the menu and browse teachers.";

        logger.info("Text to send {}", text);

        ArrayNode tg = jackson.createArrayNode();
        ObjectNode o = tg.addObject();
        o.set("dest", user.path("dest"));
        ObjectNode message = jackson.createObjectNode();
        o.set("message", message);
        message.put("text", text);

        //make unsubscribe button
        ArrayNode a = jackson.createArrayNode();
        //            String buttonUrl = env.getProperty("self.url") + "/eniword/cancel/" + user.at("/dest/sendTo").asLong();
        //            logger.info("Button url {}", buttonUrl);

        //            makeButtonHref(a, "Stop sending words", buttonUrl);
        message.set("buttons", a);

        rate.acquire();
        sendMessages(tg);

        mongo.updateFirst(Query.query(Criteria.where("dest.sendTo").is(user.at("/dest/sendTo").asLong())),
                new Update().set("eniword.wc", wToSend.path("i").asLong()).inc("eniword.points", -1), "leads");

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

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

public Parachutist update(Parachutist parachutist) {
    MongoParachutist mongoParachutist = new MongoParachutist(parachutist);

    Update updateMongoParacutist = new Update();

    Query queryMongoParachutists = new Query(Criteria.where("melwinId").is(mongoParachutist.getMelwinId()));

    updateMongoParacutist.set("memberclubs", mongoParachutist.getMemberclubs());
    updateMongoParacutist.set("licenses", mongoParachutist.getLicenses());
    updateMongoParacutist.set("firstname", mongoParachutist.getFirstname());
    updateMongoParacutist.set("lastname", mongoParachutist.getLastname());
    updateMongoParacutist.set("bithdate", mongoParachutist.getBirthdate());
    updateMongoParacutist.set("street", mongoParachutist.getStreet());
    updateMongoParacutist.set("gender", mongoParachutist.getGender());
    updateMongoParacutist.set("phone", mongoParachutist.getPhone());
    updateMongoParacutist.set("mail", mongoParachutist.getMail());
    updateMongoParacutist.set("postnumber", mongoParachutist.getPostnumber());
    updateMongoParacutist.set("postplace", mongoParachutist.getPostplace());

    mongoParachutist = appContext.mongoOperation().findAndModify(queryMongoParachutists, updateMongoParacutist,
            new FindAndModifyOptions().returnNew(true), MongoParachutist.class);

    if (mongoParachutist != null) {
        return mongoParachutist.toParachutist();
    }//from w ww.  ja  v a  2 s  .  c  om

    return new Parachutist();
}

From source file:fr.cirad.mgdb.exporting.markeroriented.VcfExportHandler.java

/**
 * Creates the sam sequence dictionary.//w ww. j a  va2  s  .c  o m
 *
 * @param sModule the module
 * @param sequenceIDs the sequence i ds
 * @return the SAM sequence dictionary
 * @throws Exception the exception
 */
public SAMSequenceDictionary createSAMSequenceDictionary(String sModule, Collection<String> sequenceIDs)
        throws Exception {
    SAMSequenceDictionary dict1 = new SAMSequenceDictionary();
    MongoTemplate mongoTemplate = MongoTemplateManager.get(sModule);
    String sequenceSeqCollName = MongoTemplateManager.getMongoCollectionName(Sequence.class);
    if (mongoTemplate.collectionExists(sequenceSeqCollName) && sequenceIDs.size() > 1) {
        long before = System.currentTimeMillis();
        Query query = new Query(Criteria.where("_id").in(sequenceIDs));
        String mapFunction = "function() { emit(this._id, this." + Sequence.FIELDNAME_SEQUENCE + ".length); }";
        String reduceFunction = "function() { }";
        MapReduceResults<Map> rs = MongoTemplateManager.get(sModule).mapReduce(query, sequenceSeqCollName,
                mapFunction, reduceFunction, Map.class);
        Iterator<Map> it = rs.iterator();
        while (it.hasNext()) {
            Map map = it.next();
            dict1.addSequence(
                    new SAMSequenceRecord((String) map.get("_id"), ((Double) map.get("value")).intValue()));
        }
        LOG.info("createSAMSequenceDictionary took " + (System.currentTimeMillis() - before) / 1000d
                + "s to write " + sequenceIDs.size() + " sequences");
    } else
        LOG.info("No sequence data was found. No SAMSequenceDictionary could be created.");
    return dict1;
}