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

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

Introduction

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

Prototype

public Update set(String key, Object value) 

Source Link

Document

Update using the $set update modifier

Usage

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

@Override
public ResponseDo updateUserActivity(JSONObject json, String activityId) throws ApiException {

    Update update = new Update();
    try {// w  w  w.  java2s.c  o m

        if (json.containsKey("destination") && StringUtils.isNotEmpty(json.getString("destination"))) {
            update.set("destination", JSONObject.toBean(json.getJSONObject("establish"), Address.class));
        }
        if (json.containsKey("destPoint") && StringUtils.isNotEmpty(json.getString("destination"))) {
            update.set("destPoint", JSONObject.toBean(json.getJSONObject("destPoint"), Landmark.class));
        }
        update.set("establish", JSONObject.toBean(json.getJSONObject("establish"), Address.class));
        update.set("estabPoint", JSONObject.toBean(json.getJSONObject("estabPoint"), Landmark.class));
        update.set("majorType", json.getString("majorType"));
        update.set("type", json.getString("type"));
        update.set("pay", json.getString("pay"));
        update.set("transfer", json.getBoolean("transfer"));
    } catch (Exception e) {
        LOG.error(e.getMessage(), e);
        throw new ApiException("?");
    }
    Activity toFind = activityDao.findById(activityId);
    if (null == toFind) {
        throw new ApiException("id?");
    }
    activityDao.update(activityId, update);
    return ResponseDo.buildSuccessResponse();

}

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

public WriteResult upsertAlarm(Alarm alarm) {
    WriteResult wr = null;/*from   w  w  w .  j  a  v a  2 s .c o m*/

    try {
        Update update = new Update();
        Query query = new Query(Criteria.where(ALARM_REG_DATE).is(alarm.getReg_date()));
        query.addCriteria(Criteria.where(ALARM_CONFIRM).is(alarm.getConfirm()));
        query.addCriteria(Criteria.where(ALARM_DEVICECODE).is(alarm.getDeviceCode()));
        query.addCriteria(Criteria.where(ALARM_TYPE).is(alarm.getType()));
        query.addCriteria(Criteria.where(ALARM_CRI_TYPE).is(alarm.getCri_type()));
        query.addCriteria(Criteria.where(ALARM_GROUPBIND).is(alarm.getGroupBind()));

        Alarm alarmInfo = readAlarmInfo(query);
        if (alarmInfo == null) {
            int idx = indexDao.createIdx(COLL_ALARM);
            update.set(IDX, idx);
            update.set(ALARM_REG_DATE, alarm.getReg_date());
            update.set(ALARM_REG_TIME, alarm.getReg_time());
        }

        update.set(ALARM_GROUPCODE, alarm.getGroupCode());
        update.set(ALARM_IP, alarm.getIp());
        update.set(ALARM_PORT, alarm.getPort());
        update.set(ALARM_CRI_VALUE, alarm.getCri_value());
        update.set(ALARM_FIGURE, alarm.getFigure());
        update.set(ALARM_REAL_CRI_VALUE, alarm.getReal_cri_value());
        update.set(ALARM_REAL_FIGURE, alarm.getReal_figure());
        update.set(ALARM_UP_DATE, alarm.getUp_date());
        update.set(ALARM_UP_TIME, alarm.getUp_time());
        update.set(ALARM_ALARM, alarm.getAlarm());
        //      update.set(ALARM_GROUPBIND, alarm.getGroupBind());
        update.set(ALARM_SUBLST, alarm.getSubLst());
        update.inc(ALARM_COUNT, 1);

        wr = operations.updateMulti(query, update, COLL_ALARM, true);

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

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

/**
 * ??/*w  w w.j  av  a2 s  .co  m*/
 *
 * @param userId Id
 * @return ?Token
 * @throws ApiException
 */
private String refreshUserToken(String userId) throws ApiException {
    UserToken userToken = cacheManager.getUserToken(userId);
    String token = CodeGenerator.generatorId();
    if (null == userToken) {
        LOG.warn("Fail to get token and expire info from userToken, new a token");
        userToken = new UserToken();
        userToken.setUserId(userId);
        userToken.setToken(token);
        userToken.setExpire(DateUtil.addTime(DateUtil.getDate(), Calendar.DATE,
                PropertiesUtil.getProperty("carplay.token.over.date", 7)));
        userTokenDao.save(userToken);
    } else {
        userToken.setToken(token);
        userToken.setExpire(DateUtil.addTime(DateUtil.getDate(), Calendar.DATE,
                PropertiesUtil.getProperty("carplay.token.over.date", 7)));

        Update update = new Update();
        update.set("token", userToken.getToken());
        update.set("expire", userToken.getExpire());
        UserToken toFind = userTokenDao.findById(userToken.getId());
        //TODO
        if (null == toFind) {
            userToken = new UserToken();
            userToken.setId(null);
            userToken.setUserId(userId);
            userToken.setToken(token);
            userToken.setExpire(DateUtil.addTime(DateUtil.getDate(), Calendar.DATE,
                    PropertiesUtil.getProperty("carplay.token.over.date", 7)));
            userTokenDao.save(userToken);
        } else {
            userTokenDao.update(userToken.getId(), update);
        }
    }
    cacheManager.setUserToken(userToken);

    return token;
}

From source file:net.cit.tetrad.resource.ManagementResource.java

/**
 * Global ? -   idx    ?//w  w w .  j a  v a2  s.  c o  m
 * @param dto
 * @return
 * @throws Exception
 */
@RequestMapping("/insertGlobal.do")
public ModelAndView insertGlobal(CommonDto dto) throws Exception {
    log.debug("start - insertGlobal()");
    String tablenm = TABLENAME[dto.getDival()];
    Class<?> classname = managementDao.getDtoClassNm(tablenm);
    Query query = new Query();
    try {
        String[] essentialGlobalVariable = Config.getConfig("essentialGlobalVariable").split(";");
        String mainRefreshPeriodMinute = essentialGlobalVariable[1];
        String versionStr = essentialGlobalVariable[4];
        String hostNameStr = essentialGlobalVariable[5];
        String dateStr = DateUtil.getTime();

        query = setUid(mainRefreshPeriodMinute);
        Update update = new Update();
        update.set("value", dto.getMainRefreshPeriodMinute() * 1000);
        update.set("up_date", dateStr);
        monadService.update(query, update, classname);

        query = setUid(hostNameStr);
        update = new Update();
        update.set("value", dto.getHostname());
        update.set("up_date", dateStr);
        monadService.update(query, update, classname);

        query = setUid(versionStr);
        update = new Update();
        update.set("value", dto.getMongo_version());
        update.set("up_date", dateStr);
        monadService.update(query, update, classname);
    } catch (Exception e) {
        log.error(e, e);
        dto.setMessage("?  ? ?");
    }
    log.debug("end - insertGlobal()");
    return listManagement(dto);
}

From source file:net.cit.tetrad.resource.ManagementResource.java

/**
 * ? ?./*from   www .  j a  v a  2  s.c o  m*/
 * @param dto
 */
public void updateCritical(CommonDto dto) {
    Update update = new Update();
    Query query = new Query();
    update.set("groupCode", dto.getGroupCode());
    query = setDeviceCode(dto.getIdx());
    Object obj = monadService.getFind(query, Critical.class);//?? name  ?
    if (obj != null)
        monadService.updateMulti(query, update, MAV_CRITICAL);
}

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

@Override
public ResponseDo alterUserInfo(String userId, String token, JSONObject json) throws ApiException {
    LOG.debug("Begin alert user info");

    checker.checkUserInfo(userId, token);

    Update update = new Update();
    if (!CommonUtil.isEmpty(json, "nickname")) {
        update.set("nickname", json.getString("nickname"));
    }// w  w  w.j a va 2 s  . com

    if (!CommonUtil.isEmpty(json, "birthday")) {
        update.set("birthday", json.getLong("birthday"));
    }

    if (!CommonUtil.isEmpty(json, "idle")) {
        update.set("idle", json.getBoolean("idle"));
    }
    userDao.update(Query.query(Criteria.where("userId").is(userId)), update);

    return ResponseDo.buildSuccessResponse();
}

From source file:net.cit.tetrad.resource.ManagementResource.java

@RequestMapping("/deviceBatchUpdate.do")
public void deviceBatchUpdate(HttpServletRequest request, HttpServletResponse response, CommonDto paramDTO)
        throws Exception {
    log.debug("start - deviceBatchUpdate()");
    String tablenm = "device";
    Class<?> classname = managementDao.getDtoClassNm(tablenm);
    Query query = new Query();
    boolean isExistValue = true;
    try {//from w  ww  .  j av  a  2 s.  c o m
        int hddBatchStr = Integer.parseInt(Utility.isNullNumber(paramDTO.getBatchHddSize()));
        int memoryBatchStr = Integer.parseInt(Utility.isNullNumber(paramDTO.getBatchMemorySize()));
        int[] idxLst = paramDTO.getIdxLst();

        Update update = new Update();
        if (hddBatchStr != 0)
            update.set("hddsize", hddBatchStr);
        if (memoryBatchStr != 0)
            update.set("memorysize", memoryBatchStr);
        if (hddBatchStr == 0 && memoryBatchStr == 0)
            isExistValue = false;

        if (isExistValue) {
            for (int idx : idxLst) {
                query = setIdx(idx);
                monadService.update(query, update, classname);

                Device deviceInfo = (Device) monadService.getFind(query, classname);
                DeviceInMemory.updateDeviceMap(deviceInfo);
                Thread.sleep(100);
            }
        }
    } catch (Exception e) {
        log.error(e, e);
    }
    log.debug("end - deviceBatchUpdate()");
}

From source file:net.cit.tetrad.resource.ManagementResource.java

@RequestMapping(value = "/popup_event.do")
public ModelAndView popup_event_update(HttpServletRequest request, HttpServletResponse response,
        CommonDto dto) {/*  w w w . j ava  2s .  c om*/
    log.debug("start - popup_event");

    ModelAndView mav = new ModelAndView();

    String groupText = dto.getGroupText();
    String[] strLst = request.getParameter("Lst").split("&");
    int[] idxLst = new int[strLst.length];

    for (int i = 0; i < strLst.length; i++) {
        String[] temp = strLst[i].split("=");
        idxLst[i] = Integer.valueOf(temp[1]);
    }

    Query query = new Query();
    Update update = new Update();

    int idx = 0;

    for (int i = 0; i < idxLst.length; i++) {
        idx = idxLst[i];
        query = setIdx(idx);
        update.set("idx", idx).set("groupBind", groupText).set("groupCnt", idxLst.length);
        monadService.update(query, update, Critical.class);
    }

    mav.addObject("groupName", groupText);
    mav.setViewName(PATH_MANAGEMEMT + "popup_event");
    log.debug("end - popup_event param : groupBind");
    return mav;
}

From source file:net.cit.tetrad.resource.ManagementResource.java

/**
 *    update/*from www. j av  a2s .  com*/
 * @param dto
 * @return
 * @throws Exception
 */
public boolean update(Device dto) throws Exception {
    log.debug("start - update(Device dto)");
    boolean isUpdated = false;
    String name;
    String tablenm = TABLENAME[1];
    Class<?> classname = managementDao.getDtoClassNm(tablenm);

    Query query = new Query();
    Update update = new Update();
    Object obj = new Object();
    try {

        query = setIpPort(dto.getIp(), dto.getPort(), dto.getIdx());
        obj = monadService.getFind(query, classname);//??ip,port  ?
        query = notIdxsetUid(dto.getIdx(), dto.getUid());

        update.set("isFinishedInitailRrd", dto.isFinishedInitailRrd());
        query = setIdx(dto.getIdx());
        monadService.update(query, update, classname);

        isUpdated = true;

    } catch (Exception e) {
        log.error(e, e);
    }
    log.debug("end - update(Device dto)");
    return isUpdated;
}

From source file:net.cit.tetrad.resource.SubResource.java

/**
 * confirm ?//from w ww . j ava2s  .  c o  m
 * @param dto
 * @return
 * @throws Exception
 */
@RequestMapping("/confirmCheck.do")
public ModelAndView confirmCheck(CommonDto dto) throws Exception {
    log.debug("start - confirmCheck()");
    ModelAndView mav = new ModelAndView();
    Query query = new Query();
    Update update = new Update();
    Alarm adto = new Alarm();
    try {
        query = setIdx(dto.getIdx());// confirm  idx   

        if (dto.getDival() == 1) {// confirm? ,,,  ?
            adto = (Alarm) monadService.getFind(query, Alarm.class);
            query = new Query();
            query = setConfirm(adto.getGroupCode(), adto.getDeviceCode(), adto.getCri_type(), adto.getAlarm(),
                    adto.getGroupBind());
        }
        List<Object> lst = monadService.getList(query, Alarm.class);
        for (int i = 0; i < lst.size(); i++) {
            Confirm cdto = new Confirm();
            Alarm alarm = (Alarm) lst.get(i);
            cdto.setAlarmCode(alarm.getIdx());

            cdto.setDate(DateUtil.getTime());
            cdto.setMemo(dto.getMemo());
            cdto.setUserCode(dto.getUserCode());
            monadService.add(cdto, Confirm.class);// ? ?  insert
        }
        update.set("confirm", 1);
        update.set("userCode", dto.getUserCode());
        monadService.updateMulti(query, update, "alarm");// ? confirm update

        dto.setMessage("? ?.");
    } catch (Exception e) {
        log.error(e, e);
    }
    log.debug("end - confirmCheck()");

    mav.setViewName("alarm_popup");
    mav.addObject("comm", dto);
    return mav;
}