agave-notifications/notifications-core/src/main/java/org/iplantc/service/notification/dao/FailedNotificationAttemptQueue.java
/**
	 * Finds matching 
	 * 
	 * @param notificationId notification uuid
	 * @return the {@link NotificationAttempt} at the top of the queue or null if the queue is empty.
	 * @throws NotificationException if unable to fetch attempts
	 */
Finds matching

@param notificationId notification uuid
@return the  NotificationAttempt at the top of the queue or null if the queue is empty.
@throws NotificationException if unable to fetch attempts
Finds matching @param notificationId notification uuid @return the NotificationAttempt at the top of the queue or null if the queue is empty . @throws NotificationException if unable to fetch attempts
public List<NotificationAttempt> findMatching(String notificationId, Map<SearchTerm, Object> searchCriteria, int limit, int offset)  
	throws NotificationException
	{
		List<NotificationAttempt> attempts = new ArrayList<>();
		try {
			SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.ENGLISH);
			SimpleDateFormat beforeFormatter = new SimpleDateFormat("yyyy-MM-dd'T'00:00:00'Z'", Locale.ENGLISH);
			SimpleDateFormat afterFormatter = new SimpleDateFormat("yyyy-MM-dd'T'23:59:59'Z'", Locale.ENGLISH);
			MongoCollection<NotificationAttempt> cappedCollection = getOrCreateCappedCollection(notificationId);
			List<Bson> filterList = new ArrayList<Bson>();
			filterList.add(eq("notificationId", notificationId));
			for (SearchTerm searchTerm: searchCriteria.keySet()) {
				if (searchTerm.getOperator() == SearchTerm.Operator.EQ) {
					filterList.add(eq(searchTerm.getSearchField(), searchCriteria.get(searchTerm)));
				} 
				else if (searchTerm.getOperator() == SearchTerm.Operator.NEQ) {
					filterList.add(ne(searchTerm.getSearchField(), searchCriteria.get(searchTerm)));
				} 
				else if (searchTerm.getOperator() == SearchTerm.Operator.GT) {
					filterList.add(gt(searchTerm.getSearchField(), searchCriteria.get(searchTerm)));
				} 
				else if (searchTerm.getOperator() == SearchTerm.Operator.GTE) {
					filterList.add(gte(searchTerm.getSearchField(), searchCriteria.get(searchTerm)));
				} 
				else if (searchTerm.getOperator() == SearchTerm.Operator.LT) {
					filterList.add(lt(searchTerm.getSearchField(), searchCriteria.get(searchTerm)));
				} 
				else if (searchTerm.getOperator() == SearchTerm.Operator.LTE) {
					filterList.add(lte(searchTerm.getSearchField(), searchCriteria.get(searchTerm)));
				}
				else if (searchTerm.getOperator() == SearchTerm.Operator.IN) {
					filterList.add(in(searchTerm.getSearchField(), (List<Object>)searchCriteria.get(searchTerm)));
				}
				else if (searchTerm.getOperator() == SearchTerm.Operator.ON) {
					filterList.add(or(
							gte(searchTerm.getSearchField(), afterFormatter.format((Date)searchCriteria.get(searchTerm))),
							lte(searchTerm.getSearchField(), beforeFormatter.format((Date)searchCriteria.get(searchTerm)))));
				}
				else if (searchTerm.getOperator() == SearchTerm.Operator.AFTER) {
					filterList.add(gt(searchTerm.getSearchField(), formatter.format((Date)searchCriteria.get(searchTerm))));
				}
				else if (searchTerm.getOperator() == SearchTerm.Operator.BEFORE) {
					filterList.add(gt(searchTerm.getSearchField(), formatter.format((Date)searchCriteria.get(searchTerm))));
				}
			}
			MongoCursor<NotificationAttempt> cursor = cappedCollection
					.find(and(filterList))
					.skip(offset)
					.limit(limit).cursor();
			List<NotificationAttempt> resultList = new ArrayList<>();
			while (cursor.hasNext()) {
				resultList.add(cursor.next());
			}
			return resultList;
		}
		catch (MongoException e) {
			log.error("Failed to fetch last failed notification attempt for " + notificationId, e);
		}
		catch (Exception e) {
			log.error("Unexpected server error while fetching last failed notification attempt for " + 
					notificationId, e);
		}
		return attempts;
	}
public List < NotificationAttempt > findMatching ( String notificationId , Map < SearchTerm , Object > searchCriteria , int limit , int offset ) throws NotificationException { List < NotificationAttempt > attempts = new ArrayList < > ( ) ; try { SimpleDateFormat formatter = new SimpleDateFormat ( "yyyy-MM-dd'T'HH:mm:ss'Z'" , Locale . ENGLISH ) ; SimpleDateFormat beforeFormatter = new SimpleDateFormat ( "yyyy-MM-dd'T'00:00:00'Z'" , Locale . ENGLISH ) ; SimpleDateFormat afterFormatter = new SimpleDateFormat ( "yyyy-MM-dd'T'23:59:59'Z'" , Locale . ENGLISH ) ; MongoCollection < NotificationAttempt > cappedCollection = getOrCreateCappedCollection ( notificationId ) ; List < Bson > filterList = new ArrayList < Bson > ( ) ; filterList . add ( eq ( "notificationId" , notificationId ) ) ; for ( SearchTerm searchTerm : searchCriteria . keySet ( ) ) { if ( searchTerm . getOperator ( ) == SearchTerm . Operator . EQ ) { filterList . add ( eq ( searchTerm . getSearchField ( ) , searchCriteria . get ( searchTerm ) ) ) ; } else if ( searchTerm . getOperator ( ) == SearchTerm . Operator . NEQ ) { filterList . add ( ne ( searchTerm . getSearchField ( ) , searchCriteria . get ( searchTerm ) ) ) ; } else if ( searchTerm . getOperator ( ) == SearchTerm . Operator . GT ) { filterList . add ( gt ( searchTerm . getSearchField ( ) , searchCriteria . get ( searchTerm ) ) ) ; } else if ( searchTerm . getOperator ( ) == SearchTerm . Operator . GTE ) { filterList . add ( gte ( searchTerm . getSearchField ( ) , searchCriteria . get ( searchTerm ) ) ) ; } else if ( searchTerm . getOperator ( ) == SearchTerm . Operator . LT ) { filterList . add ( lt ( searchTerm . getSearchField ( ) , searchCriteria . get ( searchTerm ) ) ) ; } else if ( searchTerm . getOperator ( ) == SearchTerm . Operator . LTE ) { filterList . add ( lte ( searchTerm . getSearchField ( ) , searchCriteria . get ( searchTerm ) ) ) ; } else if ( searchTerm . getOperator ( ) == SearchTerm . Operator . IN ) { filterList . add ( in ( searchTerm . getSearchField ( ) , ( List < Object > ) searchCriteria . get ( searchTerm ) ) ) ; } else if ( searchTerm . getOperator ( ) == SearchTerm . Operator . ON ) { filterList . add ( or ( gte ( searchTerm . getSearchField ( ) , afterFormatter . format ( ( Date ) searchCriteria . get ( searchTerm ) ) ) , lte ( searchTerm . getSearchField ( ) , beforeFormatter . format ( ( Date ) searchCriteria . get ( searchTerm ) ) ) ) ) ; } else if ( searchTerm . getOperator ( ) == SearchTerm . Operator . AFTER ) { filterList . add ( gt ( searchTerm . getSearchField ( ) , formatter . format ( ( Date ) searchCriteria . get ( searchTerm ) ) ) ) ; } else if ( searchTerm . getOperator ( ) == SearchTerm . Operator . BEFORE ) { filterList . add ( gt ( searchTerm . getSearchField ( ) , formatter . format ( ( Date ) searchCriteria . get ( searchTerm ) ) ) ) ; } } MongoCursor < NotificationAttempt > cursor = cappedCollection . find ( and ( filterList ) ) . skip ( offset ) . limit ( limit ) . cursor ( ) ; List < NotificationAttempt > resultList = new ArrayList < > ( ) ; while ( cursor . hasNext ( ) ) { resultList . add ( cursor . next ( ) ) ; } return resultList ; } catch ( MongoException e ) { log . error ( "Failed to fetch last failed notification attempt for " + notificationId , e ) ; } catch ( Exception e ) { log . error ( "Unexpected server error while fetching last failed notification attempt for " + notificationId , e ) ; } return attempts ; }
Finds matching
Finds matching
// now make the query and get the range result set // convert to a list and deserialized objects and return