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

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

Introduction

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

Prototype

Update

Source Link

Usage

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

public void addDevice(String username, String regid) {
    Query findByUsername = new Query().addCriteria(Criteria.where("username").is(username));
    Update update = new Update();
    update.addToSet("registrationIds", regid);
    mongoTemplate.upsert(findByUsername, update, LoadsUser.class);
}

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

public void updateTruck(Truck truck) {
    Query findtruckToUpdate = new Query().addCriteria(Criteria.where("_id").is(truck.getId()));
    Update update = new Update();
    update.set("registrationStatus", truck.getRegistrationStatus());
    update.set("type", truck.getType());
    update.set("ownerName", truck.getOwnerName());
    update.set("ownerId", truck.getOwnerId());
    update.set("ownerAddress", truck.getOwnerAddress());
    update.set("maxWeight", truck.getMaxWeight());
    update.set("maxVolume", truck.getMaxVolume());
    update.set("acceptableLoadTypes", truck.getAcceptableLoadTypes());
    update.set("acceptableLiftTypes", truck.getAcceptableLiftTypes());
    mongoTemplate.upsert(findtruckToUpdate, update, Truck.class);
}

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

public boolean assignReviewer(String id, String reviewer) throws UnknownHostException {
    boolean ok = false;
    Update assigner = new Update();
    assigner.set("rev", reviewer);
    mongoOps.findAndModify(query(where("id").is(id)), assigner, LearningElement.class);
    ok = true;//from  ww w . jav a 2 s  .com

    return ok;
}

From source file:net.cit.tetrad.rrd.dao.DataAccessObjectForMongoImpl.java

public void insertServerStatusInfo(ServerStatus serverStatusInfo) {
    try {//from www.java  2  s.c o  m
        Query query = new Query(Criteria.where(DEVICECODE).is(serverStatusInfo.getDeviceCode()));

        Update update = new Update();
        ObjectMapper converter = new ObjectMapper();
        Map<String, Object> props = converter.convertValue(serverStatusInfo, Map.class);

        Set<String> keys = props.keySet();
        Iterator<String> it = keys.iterator();
        while (it.hasNext()) {
            String key = it.next().toString();
            Object value = props.get(key);

            if (value != null)
                update.set(key, value);
        }

        WriteResult wr = operations.updateMulti(query, update, COLL_DASHBOARD, true);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.gongpingjia.carplay.official.service.impl.OfficialApproveServiceImpl.java

@Override
public ResponseDo approveUserPhotoAuthentication(String userId, JSONObject json) throws ApiException {
    String applicationId = json.getString("applicationId");
    AuthApplication application = authApplicationDao.findById(applicationId);
    if (application == null) {
        LOG.warn("authApplication is not exit with applicationId:{}", applicationId);
        throw new ApiException("?");
    }/*from ww w  .  j a v a2s  .  c om*/

    String status = getStatus(json.getBoolean("accept"));
    String remarks = getRemarks(json);

    LOG.debug("Begin update data");
    Long current = DateUtil.getTime();
    Update update = new Update();
    update.set("authTime", current);
    update.set("authUserId", userId);
    update.set("status", status);
    if (Constants.AuthStatus.ACCEPT.equals(status)) {
        update.set("remarks", "");
    } else {
        update.set("remarks", remarks);
    }

    authApplicationDao.update(applicationId, update);

    userDao.update(application.getApplyUserId(), Update.update("photoAuthStatus", status));

    recordHistory(userId, application, current, status, remarks);

    sendEmchatMessage(userId, application, status, remarks, Constants.MessageType.PHOTO_AUTH_MSG);

    LOG.debug("Finished approved user photo authentication apply");
    return ResponseDo.buildSuccessResponse();
}

From source file:net.cit.tetrad.rrd.dao.DataAccessObjectForMongoImpl.java

public void updateServerStatusInfo(int deviceCode) {
    try {//from w w w  .j ava 2s .c om
        Query query = new Query(Criteria.where(DEVICECODE).is(deviceCode));
        Update update = new Update();
        update.set(SERVERSTATUS_OK, 0);
        update.set(SERVERSTATUS_ERROR, 0);

        operations.updateMulti(query, update, COLL_DASHBOARD);

    } catch (Exception e) {
        e.printStackTrace();
    }
}

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

@Override
public ShsMessageEntry loadEntryAndLockForFetching(String shsTo, String txId) {

    Query query = new Query(Criteria.where("label.txId").is(txId).and("state").is(MessageState.RECEIVED)
            .and("archived").in(false, null).and("label.to.value").is(shsTo));

    Update update = new Update();
    update.set("stateTimeStamp", new Date());
    update.set("state", MessageState.FETCHING_IN_PROGRESS);

    // Enforces that the found object is returned by findAndModify(), i.e. not the original input object
    // It returns null if no document could be updated
    FindAndModifyOptions options = new FindAndModifyOptions().returnNew(true);

    ShsMessageEntry entry = mongoTemplate.findAndModify(query, update, options, ShsMessageEntry.class);

    if (entry == null) {
        throw new MessageNotFoundException("Message entry not found in message log: " + txId);
    }/* w w w .ja va  2s. c om*/

    return entry;
}

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

@Override
public ResponseDo sendAppointment(String activityId, String userId, Appointment appointment)
        throws ApiException {
    Activity activity = activityDao.findOne(Query.query(Criteria.where("activityId").is(activityId)));
    if (activity == null) {
        LOG.warn("No activity exist : {}", activityId);
        throw new ApiException("");
    }//w w  w.  ja  v  a2  s.c  o m

    List<String> members = activity.getMembers();
    for (String member : members) {
        if (member.equals(userId)) {
            LOG.warn("Already be a member");
            throw new ApiException("????");
        }
    }

    Appointment appointmentData = appointmentDao.findOne(Query.query(Criteria.where("activityId").is(activityId)
            .and("applyUserId").is(userId).and("status").is(Constants.AppointmentStatus.APPLYING)));
    if (appointmentData != null) {
        LOG.warn("already applying for this activity");
        throw new ApiException("??");
    }

    User user = userDao.findById(userId);

    Long current = DateUtil.getTime();
    appointment.setActivityId(activity.getActivityId());
    appointment.setApplyUserId(userId);
    appointment.setInvitedUserId(activity.getUserId());
    appointment.setCreateTime(current);
    appointment.setStatus(Constants.AppointmentStatus.APPLYING);
    appointment.setModifyTime(current);
    appointment.setActivityCategory(Constants.ActivityCatalog.COMMON);
    //appointment destination activity destination  destPoint   estabPoint
    //appointment  estabPoint  applyUserId ? landmark
    appointment.setDestPoint(activity.getEstabPoint());
    appointment.setDestination(activity.getDestination());
    appointment.setEstabPoint(user.getLandmark());
    appointment.setDistance(DistanceUtil.getDistance(appointment.getEstabPoint(), appointment.getDestPoint()));
    appointmentDao.save(appointment);

    //?ID
    Update update = new Update();
    update.addToSet("applyIds", userId);
    activityDao.update(activityId, update);

    //????
    User organizer = userDao.findById(activity.getUserId());
    User applier = userDao.findById(userId);
    String message = MessageFormat.format(
            PropertiesUtil.getProperty("dynamic.format.activity.invite", "{0}{1}"),
            applier.getNickname(), activity.getType());
    chatThirdPartyService.sendUserGroupMessage(chatCommonService.getChatToken(),
            Constants.EmchatAdmin.ACTIVITY_STATE, organizer.getEmchatName(), message);

    return ResponseDo.buildSuccessResponse();
}

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

@Override
public int releaseStaleFetchingInProgress() {
    // Anything older than one hour
    Date dateTime = new Date(System.currentTimeMillis() - 3600 * 1000);

    // List all FETCHING_IN_PROGRESS messages
    Query queryList = Query.query(
            Criteria.where("state").is(MessageState.FETCHING_IN_PROGRESS).and("stateTimeStamp").lt(dateTime));
    List<ShsMessageEntry> list = mongoTemplate.find(queryList, ShsMessageEntry.class);

    for (ShsMessageEntry item : list) {

        // Double check that it is still FETCHING_IN_PROGRESS
        Query queryItem = new Query(Criteria.where("label.txId").is(item.getLabel().getTxId()).and("state")
                .is(MessageState.FETCHING_IN_PROGRESS).and("stateTimeStamp").lt(dateTime));

        Update update = new Update();
        update.set("stateTimeStamp", new Date());
        update.set("state", MessageState.RECEIVED);

        // Enforces that the found object is returned by findAndModify(), i.e. not the original input object
        // It returns null if no document could be updated
        FindAndModifyOptions options = new FindAndModifyOptions().returnNew(true);

        ShsMessageEntry entry = mongoTemplate.findAndModify(queryItem, update, options, ShsMessageEntry.class);

        if (entry != null) {
            log.info("ShsMessageEntry with state FETCHING_IN_PROGRESS moved back to RECEIVED [txId: "
                    + entry.getLabel().getTxId() + "]");
        }//from   w  ww.j  a va2  s  . c om
    }

    return list.size();
}

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

@Override
public int archiveMessages(long messageAgeInSeconds) {

    //check the timestamp for old messages
    Date dateTime = new Date(System.currentTimeMillis() - messageAgeInSeconds * 1000);

    //criteria for automatic archiving
    Query query = new Query();
    query.addCriteria(Criteria.where("arrivalTimeStamp").lt(dateTime).and("archived").in(false, null)
            .orOperator(Criteria.where("state").in("NEW", "SENT", "FETCHED", "QUARANTINED"),
                    Criteria.where("label.transferType").is("SYNCH")));

    //update the archived flag and stateTimestamp value
    Update update = new Update();

    update.set("stateTimeStamp", new Date());
    update.set("archived", true);

    //update all matches in the mongodb
    WriteResult wr = mongoTemplate.updateMulti(query, update, ShsMessageEntry.class);

    log.debug("Archived {} messages modified before {}", wr.getN(), dateTime);
    return wr.getN();
}