Long orderId = Long.parseLong("INSERT_ORDER_ID_HERE");
// Create a statement to only select line items from the specified order
// that are in the approved (needs creatives) state.
String statementText = "WHERE orderID = :orderId and status = :status LIMIT 500";
Statement filterStatement =
new StatementBuilder("")
.putValue("orderId", orderId)
.putValue("status", ComputedStatus.NEEDS_CREATIVES.toString())
.toStatement();
// Set defaults for page and offset.
LineItemPage page = new LineItemPage();
int offset = 0;
int i = 0;
List<Long> lineItemIds = new ArrayList<Long>();
do {
// Create a statement to page through approved line items.
filterStatement.setQuery(statementText + " OFFSET " + offset);
// Get line items by statement.
page = lineItemService.getLineItemsByStatement(filterStatement);
if (page.getResults() != null) {
for (LineItemSummary lineItem : page.getResults()) {
// Archived line items cannot be activated.
if (!lineItem.getIsArchived()) {
System.out.println(i + ") Line item with ID \""
+ lineItem.getId() + "\", belonging to order ID \""
+ lineItem.getOrderId() + "\", and name \"" + lineItem.getName()
+ "\" will be activated.");
lineItemIds.add(lineItem.getId());
i++;
}
}
}
offset += 500;
} while (offset < page.getTotalResultSetSize());
System.out.println("Number of line items to be activated: " + lineItemIds.size());
if (lineItemIds.size() > 0) {
// Modify statement for action.
filterStatement.setQuery("WHERE id IN (" + StringUtils.join(lineItemIds, ",") + ")");
// Create action.
ActivateLineItems action = new ActivateLineItems();
// Perform action.