List of usage examples for org.springframework.data.mongodb.core.query Query Query
public Query(CriteriaDefinition criteriaDefinition)
From source file:org.craftercms.commerce.server.QueryConverter.java
public Query toSpringMongoQuery(String ccQuery) { Criteria criteria = null;//from w w w. ja v a 2 s. c o m // parse query into elements QueryElements qe = new QueryConverter().new QueryElements(ccQuery); String field = qe.getField(); String comparisonOperator = qe.getComparisonOperator(); String value = qe.getValue().replaceAll("(^'|'$)", ""); //String remainder = qe.getRemainder(); // TODO: allow boolean conditions by parsing remainder if (comparisonOperator.equals("=")) { criteria = Criteria.where(field).is(value); } else if (comparisonOperator.equals(">")) { criteria = Criteria.where(field).gt(value); } else if (comparisonOperator.equals("<")) { criteria = Criteria.where(field).lt(value); } else if (comparisonOperator.equals("<>")) { criteria = Criteria.where(field).ne(value); } else { throw new IllegalArgumentException("Unsupported comparison operator: " + comparisonOperator); } return new Query(criteria); }
From source file:org.cbioportal.session_service.domain.internal.SessionRepositoryImpl.java
public List<Session> findBySourceAndTypeAndQuery(String source, String type, String field, String value) { return this.mongoTemplate.find( new Query(Criteria.where("source").is(source).and("type").is(type).and(field).is(value)), Session.class, type); }
From source file:uk.gov.nationalarchives.discovery.taxonomy.common.service.impl.IAViewServiceImpl.java
public List<MongoInformationAssetView> findUntaggedDocumentsBySeriesMongo(String seriesIaid, Integer limit, Integer offset) {/*from www . j a v a2 s .c om*/ Query query = Query.query(Criteria.where("series").is(seriesIaid).and("categories").size(0)); query.limit(limit); query.skip(offset); query.with(new Sort(Sort.Direction.ASC, "_id")); return mongoTemplate.find(query, MongoInformationAssetView.class); }
From source file:com.epam.ta.reportportal.database.dao.ProjectRepositoryCustomImpl.java
@Override public synchronized void clearExternalSystems(String projectId) { Query query = Query.query(Criteria.where(PROJECT_ID).is(projectId)); Project first = mongoTemplate.findOne(query, Project.class); first.getConfiguration().setExternalSystem(Collections.emptyList()); mongoTemplate.save(first);/*from ww w . j a va 2 s . co m*/ }
From source file:eu.trentorise.smartcampus.communicatorservice.manager.UserAccountManager.java
/** * retrieves all the {@link UserAccount} of a given user * //from www.java 2 s . c om * @param uid * id of the owner of user storage accounts * @param appName * * @return a list of UserAccount of the given user id and appName */ public UserAccount findByUserIdAndAppName(String userid, String appId) { Criteria criteria = new Criteria(); criteria = criteria.and("userId").is(userid); criteria = criteria.and("appId").is(appId); return db.findOne(Query.query(criteria), UserAccount.class); }
From source file:quanlyhocvu.api.mongodb.DAO.AuthorityDAO.java
/** * generate password and user by class default: user = MaObj, pass = 'admin' * * @param cls/* w ww . ja v a 2s .co m*/ */ public void generateUserByType(Class cls) { if (cls == GiaoVienDTO.class) { List<GiaoVienDTO> giaoviens = mongoOperation.findAll(GiaoVienDTO.class); if (giaoviens != null) { for (GiaoVienDTO giaovien : giaoviens) { if (giaovien.getmaGiaoVien() != null) { UserDTO user = new UserDTO(giaovien.getmaGiaoVien(), MD5.getMD5("admin"), giaovien.getid()); user.getRoles() .add(mongoOperation.findOne( Query.query(Criteria.where("rolename").is(Authorities.TEACHER.toString())), RoleDTO.class)); try { this.insertUser(user); } catch (Exception ex) { } } } } } else if (cls == StaffDTO.class) { List<StaffDTO> staffs = mongoOperation.findAll(StaffDTO.class); if (staffs != null) { for (StaffDTO staff : staffs) { if (staff.getManhanvien() != null) { UserDTO user = new UserDTO(staff.getManhanvien(), MD5.getMD5("admin"), staff.getid()); user.getRoles() .add(mongoOperation.findOne( Query.query(Criteria.where("rolename").is(Authorities.STAFF.toString())), RoleDTO.class)); try { this.insertUser(user); } catch (Exception ex) { } } } } } else if (cls == HocSinhDTO.class) { List<HocSinhDTO> hocsinhs = mongoOperation.findAll(HocSinhDTO.class); if (hocsinhs != null) { for (HocSinhDTO hocsinh : hocsinhs) { if (hocsinh.getmaHocSinh() != null) { UserDTO user = new UserDTO(hocsinh.getmaHocSinh(), MD5.getMD5("admin"), hocsinh.getid()); user.getRoles() .add(mongoOperation.findOne( Query.query(Criteria.where("rolename").is(Authorities.STUDENT.toString())), RoleDTO.class)); try { this.insertUser(user); } catch (Exception ex) { } } } } } }
From source file:eu.trentorise.smartcampus.profileservice.storage.ProfileStorage.java
/** * @param entityId/*from ww w . j a v a 2 s. co m*/ */ public ExtendedProfile getObjectByEntityId(Long entityId, String profileId) { Criteria criteria = new Criteria(); criteria = Criteria.where("content.socialId").is(entityId); if (profileId != null) criteria.and("content.profileId").is(profileId); criteria.and("type").is(ExtendedProfile.class.getCanonicalName()); criteria.and("deleted").is(false); List<ExtendedProfile> profiles = find(Query.query(criteria), ExtendedProfile.class); return profiles == null || profiles.isEmpty() ? null : profiles.get(0); }
From source file:com.epam.ta.reportportal.database.dao.ShareableRepositoryImpl.java
@SuppressWarnings("unchecked") @Override//from w w w . j a v a 2 s.c o m public List<T> findByProject(String projectName) { if (null == projectName) { return new ArrayList<>(); } Query query = Query.query(Criteria.where("projectName").is(projectName)); Class<T> entityType = getEntityInformation().getJavaType(); return getMongoOperations().find(query, entityType); }
From source file:io.github.microcks.repository.DailyStatisticRepositoryImpl.java
@Override public List<DailyStatistic> findTopStatistics(String day, int limit) { // Build a query selecting and sorting / limiting. Query query = new Query(Criteria.where("day").is(day)) .with(new Sort(new Order(Direction.DESC, "dailyCount"))).limit(limit); return template.find(query, DailyStatistic.class); }
From source file:com.epam.ta.reportportal.database.dao.UserFilterRepositoryCustomImpl.java
@Override public List<UserFilter> findAvailableFilters(String projectName, String[] ids, String userName) { //where ID from provided array AND it's shared on project Query q = Query.query(where(ID).in(Arrays.asList(ids)) .andOperator(new Criteria().orOperator(where(OWNER).is(userName), where(PROJECT).is(projectName), where(ENTRIES).elemMatch(where("projectId").is(projectName))))); return mongoTemplate.find(q, UserFilter.class); }