// Create statement text to select all draft and pending orders that
// haven't ended and aren't archived.
String statementText =
"WHERE status IN ('" + OrderStatus.DRAFT + "','" + OrderStatus.PENDING_APPROVAL
+ "') AND endDateTime >= :today AND isArchived = FALSE LIMIT 500";
Statement filterStatement =
new StatementBuilder(statementText).putValue("today",
DATE_TIME_FORMAT.format(new Date())).toStatement();
// Set defaults for page and offset.
OrderPage page = new OrderPage();
int offset = 0;
int i = 0;
List<Long> orderIds = new ArrayList<Long>();
do {
// Create a statement to page through draft orders.
filterStatement.setQuery(statementText + " OFFSET " + offset);
// Get orders by statement.
page = orderService.getOrdersByStatement(filterStatement);
if (page.getResults() != null) {
for (Order order : page.getResults()) {
System.out.println(i + ") Order with ID \""
+ order.getId() + "\", name \"" + order.getName()
+ "\", and status \"" + order.getStatus()
+ "\" will be approved.");
orderIds.add(order.getId());
i++;
}
}
offset += 500;
} while (offset < page.getTotalResultSetSize());
System.out.println("Number of orders to be approved: " + orderIds.size());
if (orderIds.size() > 0) {
// Modify statement for action.
filterStatement.setQuery("WHERE id IN (" + StringUtils.join(orderIds, ",") + ")");
// Create action.
ApproveAndOverbookOrders action = new ApproveAndOverbookOrders();
// Perform action.