List of usage examples for org.springframework.data.mongodb.core.query Criteria and
public Criteria and(String key)
From source file:com.trenako.repositories.mongo.MongoSearchCriteria.java
/** * Builds a MongoDB criteria for the provided {@code SearchCriteria}. * * @param sc the search criteria// w w w .j a v a 2s . c o m * @return a MongoDB criteria */ public static Criteria buildCriteria(SearchCriteria sc) { Criteria c = new Criteria(); if (sc.hasBrand()) { c.and("brand.slug").is(sc.getBrand()); } if (sc.hasEra()) { c.and("era").is(sc.getEra()); } if (sc.hasRailway()) { c.and("railway.slug").is(sc.getRailway()); } if (sc.hasScale()) { c.and("scale.slug").is(sc.getScale()); } if (sc.hasCat()) { Cat cat = Cat.parseString(sc.getCat()); c.and("category").is(cat.category()).and("powerMethod").is(cat.powerMethod()); } if (!sc.hasCat() && sc.hasPowerMethod()) { c.and("powerMethod").is(sc.getPowerMethod()); } if (!sc.hasCat() && sc.hasCategory()) { c.and("category").is(sc.getCategory()); } return c; }
From source file:com.trenako.repositories.mongo.RollingStockQueryBuilder.java
/** * Builds a new query applying the range request to the * provided selection criteria./*from w ww . j a v a 2s .c om*/ * * @param criteria the selection {@code Criteria} * @param range the range information * @return a {@code Query} */ public static Query buildQuery(Criteria criteria, RangeRequest range) { String prop = range.getSortProperty(); if (range.getSince() != null && range.getMax() != null) { criteria.and(prop).lt(range.getSince()).gt(range.getMax()); } else if (range.getSince() != null) { criteria.and(prop).lt(range.getSince()); } else if (range.getMax() != null) { criteria.and(prop).gt(range.getMax()); } final Query q = query(criteria); q.limit(range.getSize() + 1); q.with(range.getSort()); return q; }
From source file:eu.trentorise.smartcampus.profileservice.storage.ProfileStorage.java
public List<ExtendedProfile> findExtendedProfiles(String userId) { Criteria criteria = new Criteria(); criteria = Criteria.where("content.userId").is(userId); criteria.and("type").is(ExtendedProfile.class.getCanonicalName()); criteria.and("deleted").is(false); List<ExtendedProfile> profiles = find(Query.query(criteria), ExtendedProfile.class); return profiles; }
From source file:eu.trentorise.smartcampus.communicatorservice.manager.UserAccountManager.java
public List<UserAccount> findUserAccounts(String appId) { Criteria criteria = new Criteria(); criteria = criteria.and("appId").is(appId); return db.find(Query.query(criteria), UserAccount.class); }
From source file:eu.trentorise.smartcampus.communicatorservice.manager.UserAccountManager.java
/** * retrieves all the {@link UserAccount} of a given user * // w ww . j av a 2s . co m * @param uid * id of the owner of user storage accounts * @return a list of UserAccount of the given user id */ public List<UserAccount> findBy(long userid) { Criteria criteria = new Criteria(); criteria = criteria.and("userId").is(userid); return db.find(Query.query(criteria), UserAccount.class); }
From source file:eu.trentorise.smartcampus.communicatorservice.manager.UserAccountManager.java
/** * retrieves all the {@link UserAccount} for a given appId * //from w ww. j ava 2 s . com * @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 List<UserAccount> findByAppName(String appId) { Criteria criteria = new Criteria(); criteria = criteria.and("appId").is(appId); return db.find(Query.query(criteria), UserAccount.class); }
From source file:eu.trentorise.smartcampus.communicatorservice.manager.UserAccountManager.java
/** * retrieves all the {@link UserAccount} of a given user * //from ww w . j a v a 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:eu.trentorise.smartcampus.profileservice.storage.ProfileStorage.java
public void deleteExtendedProfile(String userId, String profileId) throws DataException { Criteria criteria = new Criteria(); criteria = Criteria.where("content.userId").is(userId).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); if (!profiles.isEmpty()) { deleteObject(profiles.get(0));/* ww w . j a v a 2 s . c o m*/ } }
From source file:eu.trentorise.smartcampus.profileservice.storage.ProfileStorage.java
/** * @param entityId/*from w w w .j a va 2 s.c o 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:eu.trentorise.smartcampus.profileservice.storage.ProfileStorage.java
public ExtendedProfile findExtendedProfile(String userId, String profileId) { Criteria criteria = new Criteria(); criteria = Criteria.where("content.userId").is(userId).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); if (!profiles.isEmpty()) { return profiles.get(0); } else {/*from w ww. j a v a 2s. c o m*/ return null; } }