Source:
public PagedList<models.ebean.Alert> createAlertQuery(final AlertQuery query) { if (query.getOrganization() == null) { throw new IllegalArgumentException("Query must have organization specified"); } ExpressionList<models.ebean.Alert> ebeanExpressionList = Ebean.find(models.ebean.Alert.class).where(); ebeanExpressionList = ebeanExpressionList.eq("organization.uuid", query.getOrganization().getId()); if (query.getCluster().isPresent()) { ebeanExpressionList = ebeanExpressionList.eq("cluster", query.getCluster().get()); } if (query.getContext().isPresent()) { ebeanExpressionList = ebeanExpressionList.eq("context", query.getContext().get().toString()); } if (query.getService().isPresent()) { ebeanExpressionList = ebeanExpressionList.eq("service", query.getService().get()); } if (query.getContains().isPresent()) { final Junction<models.ebean.Alert> junction = ebeanExpressionList.disjunction(); ebeanExpressionList = junction.contains("name", query.getContains().get()); if (!query.getCluster().isPresent()) { ebeanExpressionList = junction.contains("cluster", query.getContains().get()); } if (!query.getService().isPresent()) { ebeanExpressionList = junction.contains("service", query.getContains().get()); } ebeanExpressionList = junction.contains("metric", query.getContains().get()); ebeanExpressionList = junction.contains("statistic", query.getContains().get()); ebeanExpressionList = junction.contains("operator", query.getContains().get()); ebeanExpressionList = ebeanExpressionList.endJunction(); } final Query<models.ebean.Alert> ebeanQuery = ebeanExpressionList.query(); int pageOffset = 0; if (query.getOffset().isPresent()) { pageOffset = query.getOffset().get() / query.getLimit(); } return ebeanQuery.findPagedList(pageOffset, query.getLimit()); }

Target:
public PagedList<models.ebean.Alert> createAlertQuery(final AlertQuery query) { ExpressionList<models.ebean.Alert> ebeanExpressionList = Ebean.find(models.ebean.Alert.class).where(); ebeanExpressionList = ebeanExpressionList.eq("organization.uuid", query.getOrganization().getId()); if (query.getCluster().isPresent()) { ebeanExpressionList = ebeanExpressionList.eq("cluster", query.getCluster().get()); } if (query.getContext().isPresent()) { ebeanExpressionList = ebeanExpressionList.eq("context", query.getContext().get().toString()); } if (query.getService().isPresent()) { ebeanExpressionList = ebeanExpressionList.eq("service", query.getService().get()); } if (query.getContains().isPresent()) { final Junction<models.ebean.Alert> junction = ebeanExpressionList.disjunction(); ebeanExpressionList = junction.contains("name", query.getContains().get()); if (!query.getCluster().isPresent()) { ebeanExpressionList = junction.contains("cluster", query.getContains().get()); } if (!query.getService().isPresent()) { ebeanExpressionList = junction.contains("service", query.getContains().get()); } ebeanExpressionList = junction.contains("metric", query.getContains().get()); ebeanExpressionList = junction.contains("statistic", query.getContains().get()); ebeanExpressionList = junction.contains("operator", query.getContains().get()); ebeanExpressionList = ebeanExpressionList.endJunction(); } final Query<models.ebean.Alert> ebeanQuery = ebeanExpressionList.query(); int pageOffset = 0; if (query.getOffset().isPresent()) { pageOffset = query.getOffset().get() / query.getLimit(); } return ebeanQuery.findPagedList(pageOffset, query.getLimit()); }