viewSize = Integer.valueOf((String) context.get("viewSizeString")).intValue();
} catch (Exception e) {
viewSize = defaultViewSize;
}
GenericValue productCategory = null;
try {
productCategory = delegator.findByPrimaryKeyCache("ProductCategory", UtilMisc.toMap("productCategoryId", productCategoryId));
} catch (GenericEntityException e) {
Debug.logWarning(e.getMessage(), module);
productCategory = null;
}
int listSize = 0;
int lowIndex = 0;
int highIndex = 0;
if (limitView) {
// get the indexes for the partial list
lowIndex = (((viewIndex - 1) * viewSize) + 1);
highIndex = viewIndex * viewSize;
} else {
lowIndex = 0;
highIndex = 0;
}
List<GenericValue> productCategoryMembers = null;
if (productCategory != null) {
try {
if (useCacheForMembers) {
productCategoryMembers = delegator.findByAndCache(entityName, UtilMisc.toMap("productCategoryId", productCategoryId), orderByFields);
if (activeOnly) {
productCategoryMembers = EntityUtil.filterByDate(productCategoryMembers, true);
}
List<EntityCondition> filterConditions = FastList.newInstance();
if (introductionDateLimit != null) {
EntityCondition condition = EntityCondition.makeCondition(EntityCondition.makeCondition("introductionDate", EntityOperator.EQUALS, null), EntityOperator.OR, EntityCondition.makeCondition("introductionDate", EntityOperator.LESS_THAN_EQUAL_TO, introductionDateLimit));
filterConditions.add(condition);
}
if (releaseDateLimit != null) {
EntityCondition condition = EntityCondition.makeCondition(EntityCondition.makeCondition("releaseDate", EntityOperator.EQUALS, null), EntityOperator.OR, EntityCondition.makeCondition("releaseDate", EntityOperator.LESS_THAN_EQUAL_TO, releaseDateLimit));
filterConditions.add(condition);
}
if (!filterConditions.isEmpty()) {
productCategoryMembers = EntityUtil.filterByCondition(productCategoryMembers, EntityCondition.makeCondition(filterConditions, EntityOperator.AND));
}
// filter out the view allow before getting the sublist
if (UtilValidate.isNotEmpty(viewProductCategoryId)) {
productCategoryMembers = CategoryWorker.filterProductsInCategory(delegator, productCategoryMembers, viewProductCategoryId);
listSize = productCategoryMembers.size();
}
// set the index and size
listSize = productCategoryMembers.size();
if (highIndex > listSize) {
highIndex = listSize;
}
// get only between low and high indexes
if (limitView) {
if (UtilValidate.isNotEmpty(productCategoryMembers)) {
productCategoryMembers = productCategoryMembers.subList(lowIndex-1, highIndex);
}
} else {
lowIndex = 1;
highIndex = listSize;
}
} else {
List<EntityCondition> mainCondList = FastList.newInstance();
mainCondList.add(EntityCondition.makeCondition("productCategoryId", EntityOperator.EQUALS, productCategory.getString("productCategoryId")));
if (activeOnly) {
mainCondList.add(EntityCondition.makeCondition("fromDate", EntityOperator.LESS_THAN_EQUAL_TO, nowTimestamp));
mainCondList.add(EntityCondition.makeCondition(EntityCondition.makeCondition("thruDate", EntityOperator.EQUALS, null), EntityOperator.OR, EntityCondition.makeCondition("thruDate", EntityOperator.GREATER_THAN, nowTimestamp)));
}
if (introductionDateLimit != null) {
mainCondList.add(EntityCondition.makeCondition(EntityCondition.makeCondition("introductionDate", EntityOperator.EQUALS, null), EntityOperator.OR, EntityCondition.makeCondition("introductionDate", EntityOperator.LESS_THAN_EQUAL_TO, introductionDateLimit)));
}
if (releaseDateLimit != null) {
mainCondList.add(EntityCondition.makeCondition(EntityCondition.makeCondition("releaseDate", EntityOperator.EQUALS, null), EntityOperator.OR, EntityCondition.makeCondition("releaseDate", EntityOperator.LESS_THAN_EQUAL_TO, releaseDateLimit)));
}
EntityCondition mainCond = EntityCondition.makeCondition(mainCondList, EntityOperator.AND);
// set distinct on
EntityFindOptions findOpts = new EntityFindOptions(true, EntityFindOptions.TYPE_SCROLL_INSENSITIVE, EntityFindOptions.CONCUR_READ_ONLY, false);
findOpts.setMaxRows(highIndex);
// using list iterator
EntityListIterator pli = delegator.find(entityName, mainCond, null, null, orderByFields, findOpts);
// get the partial list for this page
if (limitView) {
if (viewProductCategoryId != null) {
// do manual checking to filter view allow
productCategoryMembers = FastList.newInstance();
GenericValue nextValue;
int chunkSize = 0;
listSize = 0;
while ((nextValue = pli.next()) != null) {
String productId = nextValue.getString("productId");
if (CategoryWorker.isProductInCategory(delegator, productId, viewProductCategoryId)) {
if (listSize + 1 >= lowIndex && chunkSize < viewSize) {
productCategoryMembers.add(nextValue);
chunkSize++;
}