List of usage examples for org.springframework.data.mongodb.core.query Criteria where
public static Criteria where(String key)
From source file:com.appleframework.monitor.model.Project.java
/** * /*from w ww . j av a 2 s .co m*/ * * @param metricName * @return */ public MetricValue findLastMetric(String metricName) { Query query = BasicQuery.query(Criteria.where("name").is(metricName)); //query.sort().on(Constants.TIME_STAMP_FIELD_NAME, Order.DESCENDING); query.with(new Sort(Direction.DESC, Constants.TIME_STAMP_FIELD_NAME)); return fetchMongoTemplate().findOne(query, MetricValue.class, metricCollection); }
From source file:br.com.ezequieljuliano.argos.persistence.LoggerDAO.java
public List<LoggerLevelCount> groupByLevelUsingUserAndOccurrence(User user, Date startDate, Date endDate) { Criteria criteria = Criteria.where("entity._id").in(findEntityObjectIdsByUser(user)).andOperator( Criteria.where("occurrence").lte(endDate), Criteria.where("occurrence").gte(startDate)); GroupByResults<LoggerLevelCount> results = getMongoOperations().group(criteria, Logger.COLLECTION_NAME, GroupBy.key("level").initialDocument("{ count: 0 }") .reduceFunction("function(doc, prev) { prev.count += 1 }"), LoggerLevelCount.class); List<LoggerLevelCount> counts = new ArrayList<LoggerLevelCount>(); for (LoggerLevelCount level : results) { counts.add(level);/*from ww w . ja v a 2 s . c o m*/ } return counts; }
From source file:org.oncoblocks.centromere.mongodb.GenericMongoRepository.java
/** * {@link RepositoryOperations#delete} */ public void delete(ID id) { mongoOperations.findAndRemove(Query.query(Criteria.where("_id").is(id)), model); }
From source file:com.traffitruck.service.MongoDAO.java
public List<Load> getLoadsForUser(String username) { Query findByUsername = new Query().addCriteria(Criteria.where("username").is(username)); findByUsername.with(new Sort(Direction.DESC, "creationDate")); return mongoTemplate.find(findByUsername, Load.class); }
From source file:it.smartcommunitylab.tocati.controller.UserAuthController.java
@RequestMapping("/{ownerId}/userloginevway") public @ResponseBody UserData loginEVWay(@PathVariable String ownerId, @RequestParam String email, @RequestParam String password, @RequestParam String language, HttpServletRequest request, HttpServletResponse response) throws IOException, UnauthorizedException { // if(!Utils.validateAPIRequest(request, dataSetSetup, storageManager)) { // throw new UnauthorizedException("Unauthorized Exception: token not valid"); // }//ww w . ja v a 2 s . co m if (logger.isInfoEnabled()) { logger.info(String.format("loginEVWay[%s] login: %s", ownerId, email)); } try { UserData userData = evwayAuth.login(email, password, language); if (userData == null) { response.setStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR); return null; } userData.setOwnerId(ownerId); userData.setDisplayName(email); Criteria criteria = Criteria.where("userId").is(userData.getUserId()); UserData userDB = storageManager.findOneData(UserData.class, criteria, userData.getOwnerId()); if (userDB == null) { userData.setObjectId(Utils.getUUID()); userData = storageManager.addUser(userData); } else { userData = userDB; } LoginData loginData = new LoginData(email, userData.getUserId(), null); UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(email, loginData, AppUserDetails.TOCATI_AUTHORITIES); token.setDetails(new WebAuthenticationDetails(request)); Authentication authenticatedUser = authenticationManager.authenticate(token); SecurityContextHolder.getContext().setAuthentication(authenticatedUser); return userData; } catch (Exception e) { response.setStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR); } return null; }
From source file:com.gongpingjia.carplay.official.service.impl.OfficialApproveServiceImpl.java
@Override public ResponseDo getAuthApplicationList(String userId, String type, String status, Long start, Long end, String phone) {// ww w . j av a2 s . c o m LOG.debug("getAuthApplicationList start"); String applyUserId = null; if (StringUtils.isNotEmpty(phone)) { User queryUser = userDao.findOne(Query.query(Criteria.where("phone").is(phone))); if (queryUser == null) { LOG.debug("No auth applications with user phone:{}", phone); return ResponseDo.buildSuccessResponse(new ArrayList<>(0)); } applyUserId = queryUser.getUserId(); } Query query = buildQueryParam(type, status, start, end, applyUserId); List<AuthApplication> authApplicationList = authApplicationDao.find(query); Map<String, User> userMap = buildUserMap(authApplicationList); LOG.debug("Query apply user information"); for (AuthApplication application : authApplicationList) { User applyUser = userMap.get(application.getApplyUserId()); if (applyUser == null) { continue; } application.setApplyUser(applyUser.buildCommonUserMap()); } return ResponseDo.buildSuccessResponse(authApplicationList); }
From source file:it.smartcommunitylab.climb.contextstore.controller.ChildController.java
@RequestMapping(value = "/api/image/download/{imageType}/{ownerId}/{objectId}", method = RequestMethod.GET) public @ResponseBody HttpEntity<byte[]> downloadImage(@PathVariable String imageType, @PathVariable String ownerId, @PathVariable String objectId, HttpServletRequest request, HttpServletResponse response) throws Exception { Criteria criteria = Criteria.where("objectId").is(objectId); Child child = storage.findOneData(Child.class, criteria, ownerId); if (!validateAuthorizationByExp(ownerId, child.getInstituteId(), child.getSchoolId(), null, "ALL", request)) {//from ww w . j a v a 2 s. co m throw new UnauthorizedException("Unauthorized Exception: token not valid"); } String name = objectId + "." + imageType; String path = imageUploadDir + "/" + name; if (logger.isInfoEnabled()) { logger.info("downloadImage:" + name); } FileInputStream in = new FileInputStream(new File(path)); byte[] image = IOUtils.toByteArray(in); HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.IMAGE_PNG); if (imageType.toLowerCase().equals("png")) { headers.setContentType(MediaType.IMAGE_PNG); } else if (imageType.toLowerCase().equals("gif")) { headers.setContentType(MediaType.IMAGE_GIF); } else if (imageType.toLowerCase().equals("jpg")) { headers.setContentType(MediaType.IMAGE_JPEG); } else if (imageType.toLowerCase().equals("jpeg")) { headers.setContentType(MediaType.IMAGE_JPEG); } headers.setContentLength(image.length); return new HttpEntity<byte[]>(image, headers); }
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)); }//from w w w. j a va 2 s .c om query.fields().exclude("vehicleLicensePhoto"); query.fields().exclude("truckPhoto"); query.with(new Sort("creationDate")); return mongoTemplate.find(query, Truck.class); }
From source file:it.smartcommunitylab.climb.domain.controller.ChildController.java
@RequestMapping(value = "/api/child/{ownerId}/{objectId}", method = RequestMethod.DELETE) public @ResponseBody String deleteChild(@PathVariable String ownerId, @PathVariable String objectId, HttpServletRequest request, HttpServletResponse response) throws Exception { Criteria criteria = Criteria.where("objectId").is(objectId).and("ownerId").is(ownerId); Child child = storage.findOneData(Child.class, criteria, ownerId); if (child == null) { throw new EntityNotFoundException("child not found"); }/*ww w . ja va 2 s. c o m*/ if (!validateAuthorization(ownerId, child.getInstituteId(), child.getSchoolId(), null, null, Const.AUTH_RES_Child, Const.AUTH_ACTION_DELETE, request)) { throw new UnauthorizedException("Unauthorized Exception: token not valid"); } if (child.isActiveForGame()) { String instituteId = child.getInstituteId(); String schoolId = child.getSchoolId(); deletePlayer(child, ownerId, instituteId, schoolId); } storage.removeChild(ownerId, objectId); if (logger.isInfoEnabled()) { logger.info(String.format("deleteChild[%s]:%s", ownerId, objectId)); } return "{\"status\":\"OK\"}"; }
From source file:com.gongpingjia.carplay.service.impl.UserServiceImpl.java
public void pushNearbyActivity(String receivedUserId, String emchatName, Landmark landmark) throws ApiException { LOG.debug("push user nearby activity"); Activity activity = activityDao.findOne(Query.query( Criteria.where("estabPoint").near(new Point(landmark.getLongitude(), landmark.getLatitude())))); if (activity == null) { //???//from www. jav a 2 s .com return; } PushInfo info = new PushInfo(); info.setSendUserId(activity.getUserId()); info.setReceivedUserId(receivedUserId); info.setCreateTime(DateUtil.getTime()); info.setActivityId(activity.getActivityId()); pushInfoDao.save(info); User organizer = userDao.findById(activity.getUserId()); Map<String, Object> ext = new HashMap<>(1); ext.put("avatar", CommonUtil.getLocalPhotoServer() + organizer.getAvatar()); String message = MessageFormat.format( PropertiesUtil.getProperty("dynamic.format.interest", "{0}{1}"), organizer.getNickname(), activity.getType()); JSONObject result = chatThirdService.sendUserGroupMessage(chatCommonService.getChatToken(), Constants.EmchatAdmin.NEARBY, Arrays.asList(emchatName), message, ext); LOG.info("Push result:{}", result); }