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

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

Introduction

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

Prototype

public Query with(Sort sort) 

Source Link

Document

Adds a Sort to the Query instance.

Usage

From source file:com.mobileman.kuravis.core.services.event.impl.EventServiceImpl.java

@Override
public TreatmentEvent findLastTreatmentEvent(String userId, String diseaseId, String treatmentId) {
    Query query = Query.query(Criteria.where(TreatmentEvent.USER_ID).is(userId).and(TreatmentEvent.DISEASE_ID)
            .is(diseaseId).and(TreatmentEvent.TREATMENT_ID).is(treatmentId));
    query.with(new Sort(Sort.Direction.DESC, TreatmentEvent.CREATED_ON));
    query.limit(1);//w ww .  j a v a2s .  c om
    return getMongoTemplate().findOne(query, TreatmentEvent.class);
}

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

public List<Truck> getNonApprovedTrucks() {
    Query findNonApprovedTrucks = new Query()
            .addCriteria(Criteria.where("registrationStatus").is(TruckRegistrationStatus.REGISTERED));
    findNonApprovedTrucks.fields().exclude("vehicleLicensePhoto");
    findNonApprovedTrucks.fields().exclude("truckPhoto");
    findNonApprovedTrucks.with(new Sort("creationDate"));
    return mongoTemplate.find(findNonApprovedTrucks, Truck.class);
}

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

public List<Truck> getMyApprovedTrucksId(String username) {
    Query findByUsername = new Query().addCriteria(Criteria.where("username").is(username));
    findByUsername.addCriteria(Criteria.where("registrationStatus").is(TruckRegistrationStatus.APPROVED));
    findByUsername.fields().include("id");
    findByUsername.fields().include("licensePlateNumber");
    findByUsername.with(new Sort("creationDate"));
    return mongoTemplate.find(findByUsername, Truck.class);
}

From source file:com.card.loop.xyz.dao.LearningObjectDAO.java

public List<LearningObject> searchLO(String title, String subject, Date fromDate, Date toDate, String orderBy)
        throws UnknownHostException {
    Query query = new Query();
    if (title != null || !"".equals(title))
        query.addCriteria(Criteria.where("title").regex(title));
    else if (subject != null || !"".equals(subject))
        query.addCriteria(Criteria.where("subject").regex(subject));
    else if (fromDate != null && toDate != null)
        query.addCriteria(Criteria.where("uploadDate").gte(fromDate).lte(toDate));
    else if (orderBy != null || !"".equals(orderBy)) {
        switch (orderBy) {
        case "uploadDate":
            query.with(new Sort(new Sort.Order(Sort.Direction.DESC, "uploadedDate")));
            break;
        case "downloads":
            query.with(new Sort(new Sort.Order(Sort.Direction.DESC, "downloads")));
            break;
        case "title":
            query.with(new Sort(new Sort.Order(Sort.Direction.DESC, "title")));
            break;
        }//from  w  ww  .  j  a v a 2 s.  c om
    }
    return mongoOps.find(query, LearningObject.class);
}

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

public List<Truck> getTrucksForUserAndRegistration(String username,
        TruckRegistrationStatus registrationStatus) {
    Query query = new Query().addCriteria(Criteria.where("username").is(username));
    if (registrationStatus != null) {
        query.addCriteria(Criteria.where("registrationStatus").is(registrationStatus));
    }/*  w w  w  .  jav a 2 s. c o  m*/
    query.fields().exclude("vehicleLicensePhoto");
    query.fields().exclude("truckPhoto");
    query.with(new Sort("creationDate"));
    return mongoTemplate.find(query, Truck.class);
}

From source file:org.tylproject.vaadin.addon.MongoContainer.java

protected Query applySort(Query q, Sort s) {
    q.with(s);
    return q;
}

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

@Override
public Iterable<ShsMessageEntry> listMessages(String shsTo, Filter filter) {

    Criteria criteria = Criteria.where("label.to.value").is(shsTo).and("label.transferType")
            .is(TransferType.ASYNCH).and("state").is(MessageState.RECEIVED).and("archived").in(null, false);

    if (filter.getProductIds() != null && !filter.getProductIds().isEmpty()) {
        criteria = criteria.and("label.product.value").in(filter.getProductIds());
    }//from  w  ww.  jav a 2 s .c om

    if (filter.getNoAck() == true) {
        criteria = criteria.and("acknowledged").in(false, null);
    }

    if (filter.getStatus() != null) {
        criteria = criteria.and("label.status").is(filter.getStatus());
    }

    if (filter.getEndRecipient() != null) {
        criteria = criteria.and("label.endRecipient.value").is(filter.getEndRecipient());
    }

    if (filter.getOriginator() != null) {
        criteria = criteria.and("label.originatorOrFrom.value").is(filter.getOriginator());
    }

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

    if (filter.getContentId() != null) {
        criteria = criteria.and("label.content.contentId").is(filter.getContentId());
    }

    if (filter.getMetaName() != null) {
        criteria = criteria.and("label.meta.name").is(filter.getMetaName());
    }

    if (filter.getMetaValue() != null) {
        criteria = criteria.and("label.meta.value").is(filter.getMetaValue());
    }

    if (filter.getSince() != null) {
        criteria = criteria.and("stateTimeStamp").gte(filter.getSince());
    }

    Query query = Query.query(criteria);

    Sort sort = createAttributeSort(filter);

    Sort arrivalOrderSort = createArrivalOrderSort(filter);

    if (sort != null)
        sort.and(arrivalOrderSort);
    else
        sort = arrivalOrderSort;

    query.with(sort);

    if (filter.getMaxHits() != null && filter.getMaxHits() > 0)
        query = query.limit(filter.getMaxHits());
    else
        query = query.limit(200);

    return mongoTemplate.find(query, ShsMessageEntry.class);
}

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

@Override
public ResponseDo viewUserActivity(String activityId) throws ApiException {
    Activity activity = activityDao.findById(activityId);
    if (null == activity) {
        throw new ApiException("?");
    }// w  ww .  j av a2s . c o  m
    User organizer = userDao.findById(activity.getUserId());
    if (null == organizer || StringUtils.isEmpty(organizer.getUserId())) {
        throw new ApiException("");
    }
    activity.setOrganizer(organizer.buildCommonUserMap());

    Criteria criteria = new Criteria();
    criteria.and("activityId").is(activity.getActivityId());
    Query query = Query.query(criteria);
    query.with(new Sort(new Sort.Order(Sort.Direction.DESC, "createTime")));
    List<Appointment> appointmentList = appointmentDao.find(query);
    if (null != appointmentList && !appointmentList.isEmpty()) {
        activity.setAppointmentList(appointmentList);
    }
    return ResponseDo.buildSuccessResponse(activity);
}

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

@Override
public ResponseDo getViewHistory(String userId, String token, int limit, int ignore) throws ApiException {
    LOG.debug("get user view history information, userId:{}", userId);
    checker.checkUserInfo(userId, token);

    Criteria criteria = Criteria.where("userId").is(userId);
    Query query = Query.query(criteria);
    query.with(new Sort(new Sort.Order(Sort.Direction.DESC, "viewTime"))).skip(ignore).limit(limit);
    List<AlbumViewHistory> viewHistoryList = albumViewHistoryDao.find(query);
    Set<String> userIdSet = new HashSet<>(viewHistoryList.size());
    for (AlbumViewHistory item : viewHistoryList) {
        userIdSet.add(item.getViewUserId());
    }//  ww w  .ja v  a  2  s .  com

    List<User> userList = userDao.findByIds(userIdSet);
    //distance
    if (null == userList || userList.size() == 0) {
        return ResponseDo.buildSuccessResponse(new ArrayList<>(0));
    }

    Map<String, User> userMap = new HashMap<>(userList.size());
    for (User item : userList) {
        userMap.put(item.getUserId(), item);
    }

    //???
    User nowUser = userDao.findById(userId);

    List<Map<String, Object>> users = new ArrayList<>(userIdSet.size());
    for (AlbumViewHistory item : viewHistoryList) {
        User user = userMap.get(item.getViewUserId());
        Map<String, Object> map = user.buildCommonUserMap();
        User.appendDistance(map, DistanceUtil.getDistance(nowUser.getLandmark(), user.getLandmark()));
        User.appendCover(map, userDao.getCover(null, user.getUserId()));
        map.put("viewTime", item.getViewTime());
        users.add(map);
    }
    return ResponseDo.buildSuccessResponse(users);
}

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

@Override
public ResponseDo getAuthHistory(String userId, String token, int limit, int ignore) throws ApiException {
    checker.checkUserInfo(userId, token);

    Criteria criteria = Criteria.where("applyUserId").is(userId);
    Query query = Query.query(criteria);
    query.with(new Sort(new Sort.Order(Sort.Direction.DESC, "authTime")));
    query.skip(ignore).limit(limit);//w  w w.  ja va2 s. c om
    List<AuthenticationHistory> authenticationHistoryList = authenticationHistoryDao.find(query);

    //        //???
    //        HashSet<String> applicationIds = new HashSet<>();
    //        for (AuthenticationHistory history : authenticationHistoryList) {
    //            applicationIds.add(history.getApplicationId());
    //        }
    //        List<AuthApplication> authApplications = authApplicationDao.findByIds((String[])applicationIds.toArray());

    //??
    HashSet<String> authUserIds = new HashSet<>();
    for (AuthenticationHistory item : authenticationHistoryList) {
        authUserIds.add(item.getAuthId());
    }
    List<User> userList = userDao.findByIds(authUserIds);
    Map<String, User> userMap = new HashMap<>(userList.size(), 1);
    for (User user : userList) {
        userMap.put(user.getUserId(), user);
    }

    //??
    //? ?? ? ?? authUserId  ? 
    for (AuthenticationHistory history : authenticationHistoryList) {
        history.setAuthUser(userMap.get(history.getAuthId()));
    }
    //        JSONArray jsonArr = new JSONArray();
    //        for (AuthenticationHistory history : authenticationHistoryList) {
    //            JSONObject jsonObject = JSONObject.fromObject(history);
    //            jsonObject.put("authUser", getUserFromList(userList, history.getAuthId()));
    //        }
    return ResponseDo.buildSuccessResponse(authenticationHistoryList);
}