Skip to content

Instantly share code, notes, and snippets.

@tiennv90
Last active December 23, 2015 04:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tiennv90/6581830 to your computer and use it in GitHub Desktop.
Save tiennv90/6581830 to your computer and use it in GitHub Desktop.
private SubscriberList perSubscriberCriteria (String identifier, boolean negate) {
// For example if comparison identifier is "firstname", type is equalsTo and value is "Tien"
// Get all subscribers whose firstname is tien
Object fromValue = rule.getEqualToStr() != null && !rule.getEqualToStr().isEmpty() ? rule.getEqualToStr() : null;
RangeCondition operator = rule.getRangeCondition();
Object toValue = null;
if (fromValue == null) {
if ( operator.equals( RangeCondition.EQ ) ) {
fromValue = rule.getEqualTo();
} else if ( operator.equals( RangeCondition.LT ) ){
fromValue = rule.getLessThan();
} else if ( operator.equals( RangeCondition.GT ) ) {
fromValue = rule.getGreaterThan();
} else if ( operator.equals( RangeCondition.GE ) ) {
fromValue = rule.getGreaterOrEqual();
} else {
fromValue = rule.getBetweenFrom();
toValue = rule.getBetweenTo();
}
}
List<DySubscriber> list = null;
if (negate) {
if ( operator.equals(RangeCondition.LT) ) {
operator = RangeCondition.GT;
} else if ( operator.equals(RangeCondition.GT) ) {
operator = RangeCondition.LT;
} else if ( operator.equals(RangeCondition.GE) ) {
operator = RangeCondition.LE;
} else {
operator = RangeCondition.NE;
}
}
if ( rule.getEqualToStr() == null ) {
if (toValue == null) {
list = DySubscriberDAO.findByIdentifier( identifier, (Float) fromValue, operator );
} else {
if ( negate && operator.equals(RangeCondition.BW) ) {
list = DySubscriberDAO.findByIdentifier( identifier, (Float) fromValue, RangeCondition.LT );
list.addAll( DySubscriberDAO.findByIdentifier( identifier, (Float) toValue, RangeCondition.GT ) );
} else {
list = DySubscriberDAO.findByIdentifier( identifier, (Float) fromValue, (Float) toValue, operator );
}
}
} else {
list = DySubscriberDAO.findByIdentifier( identifier, fromValue, RangeCondition.EQ );
}
if (list != null && !list.isEmpty()) {
SubscriberList subscribers = DySubscriberDAO.toSubscriberList(wid, list);
return subscribers;
}
return null;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment