List of usage examples for org.springframework.data.mongodb.core.query Update Update
Update
From source file:com.traffitruck.service.MongoDAO.java
public void enableViewingLoads(String username) { Query query = new Query().addCriteria(Criteria.where("username").is(username)); Update update = new Update(); update.set("allowLoadDetails", Boolean.TRUE); mongoTemplate.upsert(query, update, LoadsUser.class); }
From source file:net.cit.tetrad.rrd.dao.DataAccessObjectForMongoImpl.java
/** * key? ? ?./*from w w w .java 2 s .c o m*/ * @param key * @return */ // private int readGlobalValue(String key) { // int globalValue = -1; // // try { // Query query = new Query(Criteria.where(GLOBAL_SEARCH_KEY).is(key)); // Global global = operations.findOne(query, Global.class); // if (global != null && global.getValue() != 0) // globalValue = global.getValue(); // } catch (Exception e) { // e.printStackTrace(); // } // // return globalValue; // } public void insertTotalDaemonInfo(Map<String, Object> totalInfo) { try { Update update = new Update(); QueryUtils.getUpdate(update, totalInfo); operations.updateMulti(new Query(), update, COLL_TOTALMONGODINFO, true); } catch (Exception e) { e.printStackTrace(); } }
From source file:net.cit.tetrad.rrd.dao.DataAccessObjectForMongoImpl.java
public WriteResult upsertAlarm(Alarm alarm) { WriteResult wr = null;//w w w . j a v a 2 s. c om 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
@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")); }/*from ww w .ja va 2s . c o m*/ 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: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. j a va 2 s . co 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.resource.SubResource.java
/** * confirm ?/*from w ww. j a va 2 s. 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; }
From source file:com.gongpingjia.carplay.service.impl.UserServiceImpl.java
@Override public ResponseDo bindingPhone(String uid, String channel, String snsPassword, String phone, String code) throws ApiException { LOG.debug("begin parameter check"); if (!CommonUtil.isPhoneNumber(phone)) { LOG.warn("Phone number is not correct format"); throw new ApiException("??"); }//from w ww. j av a 2 s .co m if (!Constants.Channel.CHANNEL_LIST.contains(channel)) { LOG.warn("Input channel:{} is not in the channel list", channel); throw new ApiException("?"); } String buildPassword = buildSnsPassword(uid, channel); if (!buildPassword.equals(snsPassword)) { LOG.warn("Input password is not correct by system compute"); throw new ApiException("?"); } checker.checkPhoneVerifyCode(phone, code); User user = userDao.findOne(Query.query(Criteria.where("phone").is(phone))); if (user == null) { LOG.warn("User with phone number:{} is not exit in the system", phone); throw new ApiException("??"); } //?????Channel????? List<SnsChannel> channelList = user.getSnsChannels(); if (channelList != null) { for (SnsChannel item : channelList) { if (channel.equals(item.getChannel())) { LOG.warn("User phone:{} has already bingding to an exist channel:{}", phone, channel); throw new ApiException("???"); } } } User snsUser = userDao.findOne( Query.query(Criteria.where("snsChannels.uid").is(uid).and("snsChannels.channel").is(channel))); if (snsUser != null) { LOG.warn("uid:{} and channel:{} is already bind by other user"); throw new ApiException("???"); } LOG.debug("binding user phone:{} with uid:{} ", phone, uid); SnsChannel snsChannel = new SnsChannel(); snsChannel.setChannel(channel); snsChannel.setUid(uid); snsChannel.setPassword(snsPassword); userDao.update(Query.query(Criteria.where("userId").is(user.getUserId())), new Update().addToSet("snsChannels", snsChannel)); User responseUser = userDao.findById(user.getUserId()); UserToken userToken = userTokenDao.findOne(Query.query(Criteria.where("userId").is(user.getUserId()))); Map<String, Object> map = responseUser.buildFullUserMap(); User.appendToken(map, userToken.getToken()); return ResponseDo.buildSuccessResponse(map); }
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 {/*w w w .j a va 2 s . c om*/ 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
/** * Global ? - idx ?//from ww w .j a v a2 s .com * @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
/** * - ? jsp ?? idx ? // w w w .ja va 2 s . c om * @param ddto * @return * @throws Exception */ @RequestMapping("/update.do") public ModelAndView update(HttpServletRequest request, CommonDto dto) throws Exception { log.debug("start - update()"); String name; String tablenm = TABLENAME[dto.getDival()]; Class<?> classname = managementDao.getDtoClassNm(tablenm); if (tablenm.equals("user")) { name = new String(request.getParameter("username").getBytes("8859_1"), "utf-8"); dto.setUsername(name); } Query query = new Query(); Update update = new Update(); Object obj = new Object(); try { //? jsp ?? idx ? if (tablenm.equals("device")) { query = setIpPort(StringUtils.getEncStr(dto.getIp()), StringUtils.getEncStr(dto.getPort()), dto.getIdx()); obj = monadService.getFind(query, classname);//??ip,port ? if (obj == null) {//?? ip,port ? query = notIdxsetUid(dto.getIdx(), StringUtils.getEncStr(dto.getUid())); } } else { query = notIdxsetUid(dto.getIdx(), dto.getUid()); } obj = monadService.getFind(query, classname);//?? name ? if (tablenm.equals("critical")) obj = null;//? ? ? ? ? ?? ? . if (obj == null) { if (tablenm.equals("device") && dto.getGroupText() != "") makeGroupCode(dto);// ? if (Utility.isNull(dto.getMessage()).equals("")) { if (tablenm.equals("device")) { Device devInfo = (Device) monadService.getFind(setIdx(dto.getIdx()), classname); dto.setFinishedInitailRrd(devInfo.isFinishedInitailRrd()); } update = managementDao.setUpdate(tablenm, dto); query = setIdx(dto.getIdx()); monadService.update(query, update, classname); if (tablenm.equals("device")) { updateDevice(); updateGroup(); if (!dto.getType().equals("config")) updateCritical(dto); Device rrdDeviceInfo = (Device) monadService .getFind(new Query(Criteria.where(IDX).is(dto.getIdx())), Device.class); DeviceInMemory.updateDeviceMap(rrdDeviceInfo); MongoInMemory.updateMongoMap(rrdDeviceInfo); } else if (tablenm.equals("group")) { updateGroup(); dto.setDival(1); } } } else { dto.setMessage("? ? ?."); } } catch (Exception e) { log.error(e, e); dto.setMessage("? ? ?"); } log.debug("end - update()"); return listManagement(dto); }