@Override public List<MongoNotification> findNotificationsByTopicIdAndVersionAndStartSecNum( String topicId, int seqNumber, int sysNfVersion, int userNfVersion ) { LOG.debug("Find notifications by topic id [{}], sequence number start [{}], " + "system schema version [{}], user schema version [{}]", topicId, seqNumber, sysNfVersion, userNfVersion); return find(query(where(NF_TOPIC_ID) .is(topicId) .and(NF_SEQ_NUM) .gt(seqNumber) .orOperator(where(NF_VERSION) .is(sysNfVersion) .and(NF_TYPE) .is(SYSTEM), where(NF_VERSION) .is(userNfVersion) .and(NF_TYPE) .is(USER)))); }
/** * Find entities modified lately * * @param period * @return */ public static Query findModifiedLately(final Duration period) { return Query.query(Criteria.where(Modifiable.LAST_MODIFIED).gt(Date.from(Instant.now().minusSeconds(period.getSeconds())))); } }
break; case ComparableQueryStructureDescriptor.GT: queryStructureRestriction.gt(compareValue); break; case ComparableQueryStructureDescriptor.GE:
private Criteria followingByModificationDateAndIdCriterion(Date date, String id) { Criteria criteria = new Criteria() .orOperator( Criteria.where(PROPERTY_MODIFICATION_DATE).gt(date), new Criteria().andOperator( Criteria.where(PROPERTY_MODIFICATION_DATE).is(date), Criteria.where(F_ID).gt(id) ) ); return criteria; }
public boolean interpret(Criteria clause, CompareRule filter) { Criteria c = clause.and(filter.getPropertyId());//Criteria.where(filter.getPropertyId()); switch (filter.getCompareType()) { case Equals: c.is(filter.getValue()); break; case GreaterOrEqual: c.gte(filter.getValue()); break; case GreaterThan: c.gt(filter.getValue()); break; case LessOrEqual: c.lte(filter.getValue()); break; case LessThan: c.lt(filter.getValue()); break; } return true; } }
query.addCriteria(where("event.eventTime").gt(dateFormat.parse(from))); } catch (Exception e) { throw new BadRequestException("Not able to parse the date, it has to be in the following format: `yyyy-MM-dd hh:mm` "); query.addCriteria(where("event.eventTime").lt(dateFormat.parse(to)).gt(dateFormat.parse(from))); } catch (Exception e) { throw new BadRequestException("Not able to parse the date, it has to be in the following format: `yyyy-MM-dd hh:mm` ");
@Override protected Criteria visit(ComparisonNode node) { ComparisonOperator operator = node.getOperator(); Collection<?> values = node.getValues().stream().map(normalizer).collect(Collectors.toList()); String field = node.getField().asKey(); if(ComparisonOperator.EQ.equals(operator)) { return where(field).is(single(values)); } else if(ComparisonOperator.NE.equals(operator)) { return where(field).ne(single(values)); } else if (ComparisonOperator.EX.equals(operator)) { return where(field).exists((Boolean)single(values)); } else if (ComparisonOperator.GT.equals(operator)) { return where(field).gt(single(values)); } else if (ComparisonOperator.LT.equals(operator)) { return where(field).lt(single(values)); } else if (ComparisonOperator.GTE.equals(operator)) { return where(field).gte(single(values)); } else if (ComparisonOperator.LTE.equals(operator)) { return where(field).lte(single(values)); } else if (ComparisonOperator.IN.equals(operator)) { return where(field).in(values); } else if (ComparisonOperator.NIN.equals(operator)) { return where(field).nin(values); } else if (ComparisonOperator.RE.equals(operator)) { return where(field).regex((String)single(values)); } else if (ComparisonOperator.SUB_CONDITION_ANY.equals(operator)) { return where(field).elemMatch(condition(node)); } throw new UnsupportedOperationException("This visitor does not support the operator " + operator + "."); }
@Override public void addCondition(Criteria criteria, FilterCondition filter, CriteriaHolder criteriaHolder) { /* Validate only numbers & dates */ this.validate(criteriaHolder, filter.getValue(), filter.isNegative(), INCORRECT_FILTER_PARAMETERS); criteria.gt(this.castValue(criteriaHolder, filter.getValue(), INCORRECT_FILTER_PARAMETERS)); }
private Criteria criteria(QueryOperator operator, String field, QueryLiteral<?> value) { Criteria criteria = new Criteria(field); switch (operator) { case $ALL: return criteria.all(((ListQueryLiteral) value).getLiterals()); case $EQ: return criteria.is(value.getLiteral()); case $GT: return criteria.gt(value.getLiteral()); case $GTE: return criteria.gte(value.getLiteral()); case $IN: return criteria.in(((ListQueryLiteral) value).getLiterals()); case $NIN: return criteria.nin(((ListQueryLiteral) value).getLiterals()); case $LT: return criteria.lt(value.getLiteral()); case $LTE: return criteria.lte(value.getLiteral()); case $NE: return criteria.ne(value.getLiteral()); case $LIKE: return criteria.regex((String) value.getLiteral(), "i"); // i means case insensitive case $ELEM_MATCH: return criteria.elemMatch(getCriteriaFromResourceQuery((ResourceQuery) value.getLiteral())); case $EXISTS: return criteria.exists((Boolean) value.getLiteral()); } return criteria; }
@Cacheable(value = { CacheConfiguration.PROJECT_INFO_CACHE }) @SuppressWarnings({ "rawtypes", "unchecked" }) @Override public Map<String, Integer> findGroupedLaunchesByOwner(String projectName, String mode, Date from) { Map<String, Integer> output = new HashMap<>(); Aggregation aggregation = newAggregation(match(where(PROJECT_ID_REFERENCE).is(projectName)), match(where(MODE).is(mode)), match(where(STATUS).ne(IN_PROGRESS.name())), match(where(START_TIME).gt(from)), group("$userRef").count().as("count") ); AggregationResults<Map> result = mongoTemplate.aggregate(aggregation, Launch.class, Map.class); for (Map<String, String> entry : result.getMappedResults()) { String username = entry.get("_id"); String count = String.valueOf(entry.get("count")); output.put(username, Integer.valueOf(count)); } return output; }
private List<PersistedEntry> enhancedGetFeedPage(final String feedName, final PersistedEntry markerEntry, final PageDirection direction, final CategoryCriteriaGenerator criteriaGenerator, final int pageSize) { final LinkedList<PersistedEntry> feedPage = new LinkedList<PersistedEntry>(); final Query query = new Query(Criteria.where(FEED).is(feedName)).limit(pageSize); criteriaGenerator.enhanceCriteria(query); switch (direction) { case FORWARD: query.addCriteria(Criteria.where(DATE_LAST_UPDATED).gt(markerEntry.getCreationDate())); query.sort().on(DATE_LAST_UPDATED, Order.ASCENDING); feedPage.addAll(mongoTemplate.find(query, PersistedEntry.class, formatCollectionName(feedName))); Collections.reverse(feedPage); break; case BACKWARD: query.addCriteria(Criteria.where(DATE_LAST_UPDATED).lte(markerEntry.getCreationDate())); query.sort().on(DATE_LAST_UPDATED, Order.DESCENDING); feedPage.addAll(mongoTemplate.find(query, PersistedEntry.class, formatCollectionName(feedName))); break; } return feedPage; }
@Override public List<FlakyHistory> getFlakyItemStatusHistory(List<String> launchIds) { /* db.testItem.aggregate([ { "$match" : { $and: [ "launchRef" : { "$in" : [""]}, has_childs : false ]}}, { "$sort" : { "start_time" : 1}}, { "$group" : { "_id" : "$uniqueId" , "total" : { "$sum" : 1 }, "statusHistory" : { "$push" : { "status" : "$status", "time" : "$start_time" } }, "statusSet" : { "$addToSet" : "$status" }, "name" : {"$first" : "$name"}, }}, { "$addFields" : { "size" : {"$size" : "$statusSet" }}}, { "$match" : { "size " : {"$gt" : 1}}} ]) */ final int MINIMUM_FOR_FLAKY = 1; Aggregation aggregation = newAggregation(match(where(LAUNCH_REFERENCE).in(launchIds).and(HAS_CHILD).is(false)), sort(Sort.Direction.ASC, START_TIME), flakyItemsGroup(), addFields("size", new BasicDBObject("$size", "$statusSet")), match(where("size").gt(MINIMUM_FOR_FLAKY)) ); return mongoTemplate.aggregate(aggregation, mongoTemplate.getCollectionName(TestItem.class), FlakyHistory.class).getMappedResults(); }
@Override public Long findLaunchesQuantity(String projectId, String mode, Date from) { Query query = query(where(PROJECT_ID_REFERENCE).is(projectId)).addCriteria(where(STATUS).ne(IN_PROGRESS.name())) .addCriteria(where(MODE).is(mode)); if (null != from) { query = query.addCriteria(where(START_TIME).gt(from)); } return mongoTemplate.count(query, Launch.class); }
@Override public List<Launch> findLaunchesByProjectId(String projectId, Date from, String mode) { Query query = query(where(PROJECT_ID_REFERENCE).is(projectId)).addCriteria(where(STATUS).ne(IN_PROGRESS.name())) .addCriteria(where(MODE).is(mode)) .addCriteria(where(START_TIME).gt(from)) .with(new Sort(Sort.Direction.ASC, START_TIME)); return mongoTemplate.find(query, Launch.class); }
Sort orders = new Sort(new Sort.Order(DESC, FAILED), new Sort.Order(ASC, TOTAL)); Aggregation aggregation = newAggregation(match(where(LAUNCH_REFERENCE).in(launchIds).and(HAS_CHILD).is(false)), sort(Sort.Direction.ASC, START_TIME), mostFailedGroup(criteria), match(where(FAILED).gt(MINIMUM_FOR_FAILED)), sort(orders), limit(limit) );