List of usage examples for org.springframework.data.mongodb.core.query Criteria andOperator
public Criteria andOperator(Criteria... criteria)
From source file:com.github.rutledgepaulv.qbuilders.visitors.MongoVisitor.java
@Override protected Criteria visit(AndNode node) { Criteria criteria = new Criteria(); List<Criteria> children = node.getChildren().stream().map(this::visitAny).collect(Collectors.toList()); return criteria.andOperator(children.toArray(new Criteria[children.size()])); }
From source file:com.comcast.video.dawg.controller.house.filter.TagCondition.java
/** * Converts to a mongo db Criteria to apply to a query * * @param negate// www.jav a 2s .c o m * negates the condition to do the opposite * @return criteria with tag and query */ @Override public Criteria toCriteria(boolean negate) { Criteria criteria = (!negate) ? Criteria.where(KEY_TAG).is(tag) : Criteria.where(KEY_TAG).not().is(tag); if (query != null) { String[] keys = query.toLowerCase().split(" "); List<Criteria> list = new ArrayList<Criteria>(); for (String key : keys) { list.add(Criteria.where("keys").regex(key)); } criteria.andOperator(list.toArray(new Criteria[list.size()])); } LOGGER.debug("Tag search criteria : " + criteria.getCriteriaObject()); return criteria; }
From source file:com.comcast.video.dawg.controller.house.filter.GroupCondition.java
/** * {@inheritDoc}/*w w w . j a v a2s. co m*/ */ @Override public Criteria toCriteria(boolean negate) { /** If we are negating the whole criteria then we just negate the negation... */ boolean notToUse = negate ? !not : not; Criteria crit = new Criteria(); /** When you negate a grouping, you flip the operator and then negate all the elements */ GroupOperator gop = groupOp; if (notToUse) { /** Flip operator */ gop = groupOp.equals(GroupOperator.and) ? GroupOperator.or : GroupOperator.and; } Criteria[] all = new Criteria[conditions.size()]; for (int i = 0; i < conditions.size(); i++) { all[i] = conditions.get(i).toCriteria(notToUse); } return gop.equals(GroupOperator.and) ? crit.andOperator(all) : crit.orOperator(all); }
From source file:org.starfishrespect.myconsumption.server.business.repositories.repositoriesimpl.SensorRepositoryImpl.java
@Override public Sensor insertSensor(Sensor sensor) { Criteria criteria = new Criteria("type").is(sensor.getType()); Criteria settingsCriterias = null;/* www. ja v a 2s . c o m*/ for (String key : sensor.getSensorSettings().getKeys()) { if (settingsCriterias == null) { settingsCriterias = new Criteria("sensorSettings." + key) .is(sensor.getSensorSettings().getValue(key)); } else { settingsCriterias = new Criteria("sensorSettings." + key) .is(sensor.getSensorSettings().getValue(key)).andOperator(settingsCriterias); } } if (settingsCriterias != null) { criteria.andOperator(settingsCriterias); } Query existingQuery = new Query(criteria); if (mongoOperation.exists(existingQuery, Sensor.class, COLLECTION_NAME)) { return mongoOperation.findOne(existingQuery, Sensor.class, COLLECTION_NAME); } mongoOperation.save(sensor, COLLECTION_NAME); return sensor; }
From source file:com.gongpingjia.carplay.service.impl.UserServiceImpl.java
@Override public ResponseDo getMyActivityAppointments(String userId, String token, Integer[] status, Integer limit, Integer ignore) throws ApiException { LOG.info("getMyActivityAppointments userId {}", userId); checker.checkUserInfo(userId, token); //???//from w w w . ja v a 2 s .c om Criteria criteria = new Criteria().orOperator(Criteria.where("invitedUserId").is(userId), Criteria.where("applyUserId").is(userId)); if (status != null && status.length > 0) { criteria.andOperator(Criteria.where("status").in(Arrays.asList(status))); } List<Appointment> appointments = appointmentDao.find(Query.query(criteria) .with(new Sort(new Sort.Order(Sort.Direction.DESC, "modifyTime"))).skip(ignore).limit(limit)); return ResponseDo.buildSuccessResponse(buildUserActivities(userId, appointments)); }
From source file:com.gongpingjia.carplay.service.impl.UserServiceImpl.java
@Override public ResponseDo getDynamicActivityAppointments(String userId, String token, Integer[] status, Integer limit, Integer ignore) throws ApiException { LOG.info("getDynamicActivityAppointments userId:{}", userId); checker.checkUserInfo(userId, token); //???/* w w w . j a v a2s . c om*/ Criteria criteria = Criteria.where("deleteFlag").is(false) .orOperator(Criteria.where("invitedUserId").is(userId), Criteria.where("applyUserId").is(userId)); if (status != null && status.length > 0) { criteria.andOperator(Criteria.where("status").in(Arrays.asList(status))); } List<Appointment> appointments = appointmentDao.find(Query.query(criteria) .with(new Sort(new Sort.Order(Sort.Direction.DESC, "modifyTime"))).skip(ignore).limit(limit)); return ResponseDo.buildSuccessResponse(buildUserActivities(userId, appointments)); }
From source file:org.opentestsystem.authoring.testauth.persistence.ItemRepositoryImpl.java
@Override public SearchResponse<Item> search(final ItemSearchRequest itemSearchRequest) { final Query q = itemSearchRequest.buildQuery(); final List<Criteria> locatorCriteriaList = new ArrayList<Criteria>(); addItemLocatorQueryCriteria(locatorCriteriaList, "itemGroupId", itemSearchRequest.getItemGroupId()); addItemLocatorQueryCriteria(locatorCriteriaList, "segmentId", itemSearchRequest.getSegmentId()); addItemLocatorQueryCriteria(locatorCriteriaList, "formPartitionId", itemSearchRequest.getFormPartitionId()); addItemLocatorQueryCriteria(locatorCriteriaList, "affinityGroupId", itemSearchRequest.getAffinityGroupId()); addItemLocatorQueryCriteria(locatorCriteriaList, "fieldTestItem", itemSearchRequest.getFieldTestItem() == null ? null : Boolean.valueOf(itemSearchRequest.getFieldTestItem())); addItemLocatorQueryCriteria(locatorCriteriaList, "associatedItem", itemSearchRequest.getAssociatedItem() == null ? null : Boolean.valueOf(itemSearchRequest.getAssociatedItem())); if (locatorCriteriaList.size() > 0) { final Criteria itemLocElementMatcher = new Criteria(); itemLocElementMatcher.andOperator(locatorCriteriaList.toArray(new Criteria[] {})); q.addCriteria(Criteria.where("itemLocation").elemMatch(itemLocElementMatcher)); }//from w w w . j a va 2 s .c o m final long total = this.mongoOperations.count(q, Item.class); final List<Item> results = this.mongoOperations.find(q, Item.class); return new SearchResponse<Item>(results, itemSearchRequest, total); }
From source file:org.opentestsystem.authoring.testauth.persistence.ItemRepositoryImpl.java
@Override public long searchForItemCounts(final ItemSearchRequest itemSearchRequest) { final Query query = itemSearchRequest.buildQuery(); final List<Criteria> locatorCriteriaList = new ArrayList<Criteria>(); addItemLocatorQueryCriteria(locatorCriteriaList, "itemGroupId", itemSearchRequest.getItemGroupId()); addItemLocatorQueryCriteria(locatorCriteriaList, "segmentId", itemSearchRequest.getSegmentId()); addItemLocatorQueryCriteria(locatorCriteriaList, "formPartitionId", itemSearchRequest.getFormPartitionId()); addItemLocatorQueryCriteria(locatorCriteriaList, "affinityGroupId", itemSearchRequest.getAffinityGroupId()); addItemLocatorQueryCriteria(locatorCriteriaList, "fieldTestItem", itemSearchRequest.getFieldTestItem() == null ? null : Boolean.valueOf(itemSearchRequest.getFieldTestItem())); addItemLocatorQueryCriteria(locatorCriteriaList, "associatedItem", itemSearchRequest.getAssociatedItem() == null ? null : Boolean.valueOf(itemSearchRequest.getAssociatedItem())); if (locatorCriteriaList.size() > 0) { final Criteria itemLocElementMatcher = new Criteria(); itemLocElementMatcher.andOperator(locatorCriteriaList.toArray(new Criteria[] {})); query.addCriteria(Criteria.where("itemLocation").elemMatch(itemLocElementMatcher)); }//from www .ja v a2 s . com return this.mongoOperations.count(query, Item.class); }
From source file:org.slc.sli.ingestion.transformation.EdFi2SLITransformer.java
protected Query createEntityLookupQueryFromKeyFields(SimpleEntity entity, EntityConfig entityConfig, AbstractMessageReport report, ReportStats reportStats) { Query query = new Query(); StringBuilder errorMessage = new StringBuilder(""); if (entityConfig.getKeyFields() == null || entityConfig.getKeyFields().size() == 0) { report.error(reportStats, new ElementSourceImpl(entity), CoreMessageCode.CORE_0011); } else {/*from w w w .jav a2 s. c om*/ errorMessage.append(" Entity " + entity.getType() + "\n" + " Key Fields " + entityConfig.getKeyFields() + "\n"); if (entityConfig.getReferences() != null && entityConfig.getReferences().size() > 0) { errorMessage.append(" The following collections are referenced by the key fields:" + "\n"); for (RefDef refDef : entityConfig.getReferences()) { String collectionName = ""; NeutralSchema schema = schemaRepository.getSchema(refDef.getRef().getEntityType()); if (schema != null) { AppInfo appInfo = schema.getAppInfo(); if (appInfo != null) { collectionName = appInfo.getCollectionType(); } } errorMessage.append(" collection = " + collectionName + "\n"); } } } try { for (String field : entityConfig.getKeyFields()) { Object fieldValue = PropertyUtils.getProperty(entity, field); if (fieldValue instanceof List) { @SuppressWarnings("rawtypes") List fieldValues = ((List) fieldValue); int size = fieldValues.size(); // make sure we have exactly the number of desired values Criteria criteria = Criteria.where(field).size(size); // if there are desired values, make sure we have each individual desired value if (size > 0) { Criteria[] valueCriteria = new Criteria[size]; for (int i = 0; i < size; i++) { valueCriteria[i] = Criteria.where(field).is(fieldValues.get(i)); } criteria = criteria.andOperator(valueCriteria); } query.addCriteria(criteria); // this will be insufficient if fieldValue can contain duplicates } else { query.addCriteria(Criteria.where(field).is(fieldValue)); } } ComplexKeyField complexField = entityConfig.getComplexKeyField(); if (complexField != null) { String propertyString = complexField.getListPath() + ".[0]." + complexField.getFieldPath(); Object fieldValue = PropertyUtils.getProperty(entity, propertyString); query.addCriteria(Criteria.where(complexField.getListPath() + "." + complexField.getFieldPath()) .is(fieldValue)); } } catch (Exception e) { report.error(reportStats, new ElementSourceImpl(entity), CoreMessageCode.CORE_0012, errorMessage.toString()); } return query; }