Calendar calcCal = Calendar.getInstance();
calcCal.setTimeInMillis(System.currentTimeMillis());
calcCal.add(Calendar.WEEK_OF_YEAR, -1);
Timestamp oneWeekAgo = new Timestamp(calcCal.getTimeInMillis());
EntityListIterator eli = null;
try {
eli = delegator.find("OrderPaymentPreference",
EntityCondition.makeCondition(EntityCondition.makeCondition("needsNsfRetry", EntityOperator.EQUALS, "Y"), EntityOperator.AND, EntityCondition.makeCondition(ModelEntity.STAMP_FIELD, EntityOperator.LESS_THAN_EQUAL_TO, oneWeekAgo)),
null, null, UtilMisc.toList("orderId"), null);
List<String> processList = FastList.newInstance();
if (eli != null) {
Debug.logInfo("Processing failed order re-auth(s)", module);
GenericValue value = null;
while (((value = eli.next()) != null)) {
String orderId = value.getString("orderId");
if (!processList.contains(orderId)) { // just try each order once
try {
// each re-try is independent of each other; if one fails it should not effect the others
dispatcher.runAsync("retryFailedOrderAuth", UtilMisc.<String, Object>toMap("orderId", orderId, "userLogin", userLogin));
processList.add(orderId);
} catch (GenericServiceException e) {
Debug.logError(e, module);
}
}
}
}
} catch (GenericEntityException e) {
Debug.logError(e, module);
} finally {
if (eli != null) {
try {
eli.close();
} catch (GenericEntityException e) {
Debug.logError(e, module);
}
}
}