use of org.motechproject.mds.query.RestrictionProperty in project motech by motech.
the class AbstractSearchExecution method execute.
@Override
public T execute(Query query, InstanceSecurityRestriction restriction) {
List<Property> properties = new ArrayList<>();
Range<DateTime> deliveryTimeRange = criteria.getDeliveryTimeRange();
boolean dateRangeUsed = isUsableRange(deliveryTimeRange);
if (dateRangeUsed) {
properties.add(new RangeProperty<>("deliveryTime", deliveryTimeRange, DateTime.class.getName()));
}
Set<DeliveryStatus> deliveryStatuses = criteria.getDeliveryStatuses();
if (deliveryStatuses.isEmpty()) {
deliveryStatuses = new HashSet<>(Arrays.asList(DeliveryStatus.values()));
}
properties.add(new SetProperty<>("deliveryStatus", deliveryStatuses, DeliveryStatus.class.getName()));
StringBuilder queryBuilder = new StringBuilder(initialQuery(dateRangeUsed));
int initialLength = queryBuilder.length();
if (StringUtils.isNotEmpty(criteria.getToAddress())) {
properties.add(new MatchesProperty("toAddress", criteria.getToAddress()));
extendQueryWithOrClause(queryBuilder, initialLength);
}
if (StringUtils.isNotEmpty(criteria.getFromAddress())) {
properties.add(new MatchesProperty("fromAddress", criteria.getFromAddress()));
extendQueryWithOrClause(queryBuilder, initialLength);
}
if (StringUtils.isNotEmpty(criteria.getMessage())) {
properties.add(new MatchesProperty("message", criteria.getMessage()));
extendQueryWithOrClause(queryBuilder, initialLength);
}
if (StringUtils.isNotEmpty(criteria.getSubject())) {
properties.add(new MatchesProperty("subject", criteria.getSubject()));
extendQueryWithOrClause(queryBuilder, initialLength);
}
closeQuery(queryBuilder, initialLength);
if (restriction != null && !restriction.isEmpty()) {
properties.add(new RestrictionProperty(restriction, SecurityUtil.getUsername()));
queryBuilder.append(" && %s");
}
QueryUtil.useFilterFromPattern(query, queryBuilder.toString(), properties);
return execute(query, properties);
}
Aggregations