List of usage examples for org.springframework.data.mongodb.core.query Criteria Criteria
public Criteria()
From source file:eu.trentorise.smartcampus.mobility.service.SmartPlannerService.java
private Map<String, PlanningPolicy> getStoredPolicies(Boolean draft) { Map<String, PlanningPolicy> result = Maps.newTreeMap(); Criteria criteria = new Criteria(); if (draft != null) { criteria.and("draft").is(draft); }//from w ww . j a v a2 s . com List<CompilablePolicyData> compilable = storage.searchDomainObjects(criteria, CompilablePolicyData.class); for (CompilablePolicyData policy : compilable) { result.put(policy.getPolicyId(), new CompilablePolicy(policy)); } return result; }
From source file:eu.trentorise.smartcampus.communicatorservice.storage.CommunicatorStorage.java
public Notification getObjectByIdAndApp(String id, String capp, Class<Notification> class1) throws NotFoundException { Criteria criteria = new Criteria(); criteria = criteria.and("id").is(id); if (capp != null && capp.compareTo("") != 0) { criteria.and("content.type").is(capp); }//from ww w . j a v a2 s. co m criteria = criteria.and("deleted").is(false); List<Notification> x = find(Query.query(criteria), Notification.class); if (x.isEmpty()) throw new NotFoundException(); return x.get(FIRST); }
From source file:com.epam.ta.reportportal.database.dao.UserRepositoryCustomImpl.java
@Override public Page<User> searchForUser(String term, Pageable pageable) { final String regex = "(?i).*" + Pattern.quote(term.toLowerCase()) + ".*"; Criteria email = where(User.EMAIL).regex(regex); Criteria login = where(LOGIN).regex(regex); Criteria fullName = where(FULLNAME_DB_FIELD).regex(regex); Criteria criteria = new Criteria().orOperator(email, login, fullName); Query query = query(criteria).with(pageable); List<User> users = mongoOperations.find(query, User.class); return new PageImpl<>(users, pageable, mongoOperations.count(query, User.class)); }
From source file:eu.trentorise.smartcampus.communicatorservice.storage.CommunicatorStorage.java
public Notification getObjectByIdAndUser(String id, String userId, Class<Notification> class1) throws NotFoundException { Criteria criteria = new Criteria(); criteria = criteria.and("id").is(id); if (userId != null && userId.compareTo("") != 0) { criteria.and("content.user").is(userId); }/*www.ja v a 2 s.com*/ criteria = criteria.and("deleted").is(false); List<Notification> x = find(Query.query(criteria), Notification.class); if (x.isEmpty()) throw new NotFoundException(); return x.get(FIRST); }
From source file:com.epam.ta.reportportal.database.dao.UserRepositoryCustomImpl.java
@Override public Page<User> searchForUserLogin(String term, Pageable pageable) { final String regex = "(?i).*" + Pattern.quote(term.toLowerCase()) + ".*"; Criteria login = where(LOGIN).regex(regex); Criteria fullName = where(FULLNAME_DB_FIELD).regex(regex); Criteria criteria = new Criteria().orOperator(login, fullName); Query query = query(criteria).with(pageable); query.fields().include(LOGIN);/* www . j a v a 2s .c o m*/ query.fields().include(FULLNAME_DB_FIELD); List<User> users = mongoOperations.find(query, User.class); return new PageImpl<>(users, pageable, mongoOperations.count(query, User.class)); }
From source file:net.cit.tetrad.utility.QueryUtils.java
public static Query sortDate(int auth, int userCode, String tablenm) { Query query = new Query(); if (tablenm.equals("user")) { Criteria c = new Criteria(); c.orOperator(Criteria.where("idx").is(userCode), Criteria.where("authority").lt(auth)); query.addCriteria(c);//from w w w.j a v a2 s . c o m query.sort().on("authority", Order.DESCENDING); } query.sort().on("reg_date", Order.DESCENDING); query.sort().on("groupCode", Order.ASCENDING); query.sort().on("deviceCode", Order.ASCENDING); query.sort().on("reg_date", Order.DESCENDING); return query; }
From source file:io.cos.cas.adaptors.mongodb.OpenScienceFrameworkAuthenticationHandler.java
/** * Authenticates a Open Science Framework credential. * * @param credential the credential object bearing the username, password, etc... * * @return HandlerResult resolved from credential on authentication success or null if no principal could be resolved * from the credential./* w w w.ja v a 2 s . co m*/ * * @throws GeneralSecurityException On authentication failure. * @throws PreventedException On the indeterminate case when authentication is prevented. */ protected final HandlerResult authenticateInternal(final OpenScienceFrameworkCredential credential) throws GeneralSecurityException, PreventedException { final String username = credential.getUsername().toLowerCase(); final String plainTextPassword = credential.getPassword(); final String verificationKey = credential.getVerificationKey(); final String oneTimePassword = credential.getOneTimePassword(); final OpenScienceFrameworkUser user = this.mongoTemplate.findOne(new Query(new Criteria() .orOperator(Criteria.where("emails").is(username), Criteria.where("username").is(username))), OpenScienceFrameworkUser.class); if (user == null) { throw new AccountNotFoundException(username + " not found with query"); } Boolean validPassphrase = Boolean.FALSE; if (credential.isRemotePrincipal()) { // remote principal's are already verified by a third party (in our case a third party SAML authentication). validPassphrase = Boolean.TRUE; } else if (verificationKey != null && verificationKey.equals(user.verificationKey)) { // verification key can substitute as a temporary password. validPassphrase = Boolean.TRUE; } else if (BCrypt.checkpw(plainTextPassword, user.password)) { validPassphrase = Boolean.TRUE; } if (!validPassphrase) { throw new FailedLoginException(username + " invalid verification key or password"); } final TimeBasedOneTimePassword timeBasedOneTimePassword = this.mongoTemplate.findOne(new Query(Criteria .where("owner").is(user.id).and("isConfirmed").is(Boolean.TRUE).and("deleted").is(Boolean.FALSE)), TimeBasedOneTimePassword.class); if (timeBasedOneTimePassword != null && timeBasedOneTimePassword.totpSecret != null) { if (oneTimePassword == null) { throw new OneTimePasswordRequiredException("Time-based One Time Password required"); } try { final Long longOneTimePassword = Long.valueOf(oneTimePassword); if (!TotpUtils.checkCode(timeBasedOneTimePassword.getTotpSecretBase32(), longOneTimePassword, TOTP_INTERVAL, TOTP_WINDOW)) { throw new OneTimePasswordFailedLoginException( username + " invalid time-based one time password"); } } catch (final Exception e) { throw new OneTimePasswordFailedLoginException(username + " invalid time-based one time password"); } } // Validate basic information such as username/password and a potential One-Time Password before // providing any indication of account status. if (!user.isRegistered) { throw new LoginNotAllowedException(username + " is not registered"); } if (!user.isClaimed) { throw new LoginNotAllowedException(username + " is not claimed"); } if (user.isMerged()) { throw new LoginNotAllowedException("Cannot log in to a merged user " + username); } if (user.isDisabled()) { throw new AccountDisabledException(username + " is disabled"); } if (!user.isActive()) { throw new LoginNotAllowedException(username + " is not active"); } final Map<String, Object> attributes = new HashMap<>(); attributes.put("username", user.username); attributes.put("givenName", user.givenName); attributes.put("familyName", user.familyName); return createHandlerResult(credential, this.principalFactory.createPrincipal(user.id, attributes), null); }
From source file:com.gongpingjia.carplay.official.service.impl.OfficialApproveServiceImpl.java
/** * ?//from ww w .j av a 2 s. c o m * * @param type * @param status * @param start * @param end * @return */ private Query buildQueryParam(String type, String status, Long start, Long end, String applyUserId) { Criteria criteria = new Criteria(); if (!StringUtils.isEmpty(applyUserId)) { criteria.and("applyUserId").is(applyUserId); } if (StringUtils.isNotEmpty(type)) { criteria.and("type").is(type); } if (StringUtils.isNotEmpty(status)) { criteria.and("status").is(status); } if (start != null && end != null) { criteria.and("applyTime").gte(start).lt(end + Constants.DAY_MILLISECONDS); } else if (end != null) { criteria.and("applyTime").lt(end + Constants.DAY_MILLISECONDS); } else if (start != null) { criteria.and("applyTime").gte(start); } Query query = Query.query(criteria); // query.with(new Sort(new Sort.Order(Sort.Direction.ASC, "status"))); query.with(new Sort(new Sort.Order(Sort.Direction.ASC, "applyTime"))); return query; }