use of org.apache.ofbiz.entity.util.EntityListIterator in project ofbiz-framework by apache.
the class PaymentGatewayServices method retryFailedAuths.
public static Map<String, Object> retryFailedAuths(DispatchContext dctx, Map<String, ? extends Object> context) {
Delegator delegator = dctx.getDelegator();
LocalDispatcher dispatcher = dctx.getDispatcher();
GenericValue userLogin = (GenericValue) context.get("userLogin");
EntityQuery eq = EntityQuery.use(delegator).from("OrderPaymentPreference").where(EntityCondition.makeCondition("statusId", EntityOperator.EQUALS, "PAYMENT_NOT_AUTH"), EntityCondition.makeCondition("processAttempt", EntityOperator.GREATER_THAN, Long.valueOf(0))).orderBy("orderId");
try (EntityListIterator eli = eq.queryIterator()) {
List<String> processList = new LinkedList<>();
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);
}
return ServiceUtil.returnSuccess();
}
use of org.apache.ofbiz.entity.util.EntityListIterator in project ofbiz-framework by apache.
the class FindServices method performFindItem.
/**
* Returns the first generic item of the service 'performFind'
* Same parameters as performFind service but returns a single GenericValue
*
* @param dctx
* @param context
* @return returns the first item
*/
public static Map<String, Object> performFindItem(DispatchContext dctx, Map<String, Object> context) {
context.put("viewSize", 1);
context.put("viewIndex", 0);
Map<String, Object> result = org.apache.ofbiz.common.FindServices.performFind(dctx, context);
List<GenericValue> list = null;
GenericValue item = null;
try (EntityListIterator it = (EntityListIterator) result.get("listIt")) {
// list starts at '1'
list = it.getPartialList(1, 1);
if (UtilValidate.isNotEmpty(list)) {
item = list.get(0);
}
} catch (ClassCastException | NullPointerException | GenericEntityException e) {
Debug.logInfo("Problem getting list Item" + e, module);
}
if (UtilValidate.isNotEmpty(item)) {
result.put("item", item);
}
result.remove("listIt");
if (result.containsKey("listSize")) {
result.remove("listSize");
}
return result;
}
use of org.apache.ofbiz.entity.util.EntityListIterator in project ofbiz-framework by apache.
the class FindServices method executeFind.
/**
* executeFind
*
* This is a generic method that returns an EntityListIterator.
*/
public static Map<String, Object> executeFind(DispatchContext dctx, Map<String, ?> context) {
String entityName = (String) context.get("entityName");
EntityConditionList<EntityCondition> entityConditionList = UtilGenerics.cast(context.get("entityConditionList"));
List<String> orderByList = checkList(context.get("orderByList"), String.class);
boolean noConditionFind = "Y".equals(context.get("noConditionFind"));
boolean distinct = "Y".equals(context.get("distinct"));
List<String> fieldList = UtilGenerics.checkList(context.get("fieldList"));
Locale locale = (Locale) context.get("locale");
Set<String> fieldSet = null;
if (fieldList != null) {
fieldSet = UtilMisc.makeSetWritable(fieldList);
}
Integer maxRows = (Integer) context.get("maxRows");
maxRows = maxRows != null ? maxRows : -1;
Delegator delegator = dctx.getDelegator();
// Retrieve entities - an iterator over all the values
EntityListIterator listIt = null;
int listSize = 0;
try {
if (noConditionFind || (entityConditionList != null && entityConditionList.getConditionListSize() > 0)) {
listIt = EntityQuery.use(delegator).select(fieldSet).from(entityName).where(entityConditionList).orderBy(orderByList).cursorScrollInsensitive().maxRows(maxRows).distinct(distinct).queryIterator();
listSize = listIt.getResultsSizeAfterPartialList();
}
} catch (GenericEntityException e) {
return ServiceUtil.returnError(UtilProperties.getMessage(resource, "CommonFindErrorRunning", UtilMisc.toMap("entityName", entityName, "errorString", e.getMessage()), locale));
}
Map<String, Object> results = ServiceUtil.returnSuccess();
results.put("listIt", listIt);
results.put("listSize", listSize);
return results;
}
use of org.apache.ofbiz.entity.util.EntityListIterator in project ofbiz-framework by apache.
the class EntityTestSuite method testEntityListIterator.
/*
* This test will use the large number of unique items from above and test the EntityListIterator looping through the list
*/
public void testEntityListIterator() throws Exception {
try {
List<GenericValue> newValues = new LinkedList<>();
for (int i = 0; i < TEST_COUNT; i++) {
newValues.add(delegator.makeValue("Testing", "testingId", getTestId("T3-", i)));
}
delegator.storeAll(newValues);
List<GenericValue> newlyCreatedValues = EntityQuery.use(delegator).from("Testing").where(EntityCondition.makeCondition("testingId", EntityOperator.LIKE, "T3-%")).orderBy("testingId").queryList();
assertEquals("Test to create " + TEST_COUNT + " and store all at once", TEST_COUNT, newlyCreatedValues.size());
boolean beganTransaction = false;
try {
beganTransaction = TransactionUtil.begin();
EntityListIterator iterator = EntityQuery.use(delegator).from("Testing").where(EntityCondition.makeCondition("testingId", EntityOperator.LIKE, "T3-%")).orderBy("testingId").queryIterator();
assertNotNull("Test if EntityListIterator was created: ", iterator);
int i = 0;
GenericValue item = iterator.next();
while (item != null) {
assertEquals("Testing if iterated data matches test data (row " + i + "): ", getTestId("T3-", i), item.getString("testingId"));
item = iterator.next();
i++;
}
assertEquals("Test if EntitlyListIterator iterates exactly " + TEST_COUNT + " times: ", TEST_COUNT, i);
iterator.close();
} catch (GenericEntityException e) {
TransactionUtil.rollback(beganTransaction, "GenericEntityException occurred while iterating with EntityListIterator", e);
assertTrue("GenericEntityException:" + e.toString(), false);
return;
} finally {
TransactionUtil.commit(beganTransaction);
}
} finally {
List<GenericValue> entitiesToRemove = EntityQuery.use(delegator).from("Testing").where(EntityCondition.makeCondition("testingId", EntityOperator.LIKE, "T3-%")).queryList();
delegator.removeAll(entitiesToRemove);
}
}
use of org.apache.ofbiz.entity.util.EntityListIterator in project ofbiz-framework by apache.
the class EntityQueryTestSuite method testQueryIterator.
/*
* queryIterator(): This method is used to get iterator object over the entity.
* assert: Compared first record of both the iterator.
*/
public void testQueryIterator() throws GenericEntityException {
List<GenericValue> testingTypes = new LinkedList<>();
testingTypes.add(delegator.makeValue("TestingType", "testingTypeId", "queryIterator-1", "description", "Value One"));
testingTypes.add(delegator.makeValue("TestingType", "testingTypeId", "queryIterator-2", "description", "Value Two"));
testingTypes.add(delegator.makeValue("TestingType", "testingTypeId", "queryIterator-3", "description", "Value Three"));
delegator.storeAll(testingTypes);
boolean transactionStarted = false;
try {
transactionStarted = TransactionUtil.begin();
EntityListIterator eliByEntityEngine = null;
EntityListIterator eliByEntityQuery = null;
eliByEntityEngine = delegator.find("TestingType", null, null, null, null, null);
eliByEntityQuery = EntityQuery.use(delegator).from("TestingType").queryIterator();
GenericValue recordByEntityEngine = eliByEntityEngine.next();
GenericValue recordByEntityQuery = eliByEntityQuery.next();
assertEquals("queryIterator(): Value of first record pointed by both iterators matched", recordByEntityEngine, recordByEntityQuery);
eliByEntityEngine.close();
eliByEntityQuery.close();
TransactionUtil.commit(transactionStarted);
} catch (GenericEntityException e) {
TransactionUtil.rollback(transactionStarted, "Transaction is Rolled Back", e);
}
}
Aggregations