String filterCiteria = "";
Double minPrice = Double.MIN_VALUE * -1;
Double maxPrice = Double.MAX_VALUE;
for (ContentFilterBean contentFilterBean : contentFilterBeans) {
if (contentFilterBean.getSystemRecord() == Constants.VALUE_YES) {
CustomAttribute customAttribute = CustomAttributeDAO.load(siteDomain.getSite().getSiteId(), contentFilterBean.getCustomAttribId());
PriceRange priceRange = getAttributePriceRange(customAttribute, contentFilterBean.getCustomAttribOptionId());
minPrice = Double.valueOf(priceRange.getMinPrice());
maxPrice = Double.valueOf(priceRange.getMaxprice());
}
else {
String categoryAttributeSubquery = NamedQuery.getInstance().getQuery("category.attribute.subquery");
categoryAttributeSubquery = categoryAttributeSubquery.replaceFirst(":customAttribOptionId", contentFilterBean.getCustomAttribOptionId().toString());
filterCiteria += " " + categoryAttributeSubquery;
}
}
String sql = "";
if (siteDomain.getSite().getShareInventory() == Constants.VALUE_YES) {
sql = NamedQuery.getInstance().getQuery("category.item.language");
}
else {
sql = NamedQuery.getInstance().getQuery("category.item.language.noshare");
}
sql += " and category.catId = :catId ";
sql += " " + filterCiteria;
sql += " " + NamedQuery.getInstance().getQuery("category.item.language.suffix");
switch (sortByValue) {
case Constants.SECTION_SORT_DESC_ASC:
sql += " order by itemDescSearch.itemShortDesc";
break;
case Constants.SECTION_SORT_DESC_DSC:
sql += " order by itemDescSearch.itemShortDesc desc";
break;
case Constants.SECTION_SORT_PRICE_ASC:
sql += " order by sum(itemPriceSearch.itemPrice)";
break;
case Constants.SECTION_SORT_PRICE_DSC:
sql += " order by sum(itemPriceSearch.itemPrice) desc";
break;
}
Vector<DataInfo> dataVector = new Vector<DataInfo>();
Query query = em.createQuery(sql);
query.setParameter("siteId", siteDomain.getSite().getSiteId());
if (siteDomain.getSite().getShareInventory() != Constants.VALUE_YES) {
query.setParameter("siteDomainId", siteDomain.getSiteDomainId());
}
query.setParameter("catId", category.getCatId());
query.setParameter("siteProfileClassId", contentBean.getContentSessionKey().getSiteProfileClassId());
query.setParameter("siteCurrencyClassId", contentBean.getContentSessionKey().getSiteCurrencyClassId());
query.setParameter("minPrice", minPrice);
query.setParameter("maxPrice", maxPrice);
query.setParameter("exchangeRate", contentBean.getContentSessionBean().getSiteCurrency().getExchangeRate() - 1);
List<?> list = query.getResultList();
int totalCount = 0;
int itemSize = list.size();
totalCount += itemSize;
Iterator<?> sqlIterator = list.iterator();
while (sqlIterator.hasNext()) {
Long itemId = (Long) sqlIterator.next();
if (index >= itemStart && index <= itemEnd) {
Item item = ItemDAO.load(siteDomain.getSite().getSiteId(), itemId);
ItemInfo itemInfo = formatItem(item);
dataVector.add(itemInfo);
}
index++;
if (index > itemEnd) {
break;
}
}
sql = NamedQuery.getInstance().getQuery("category.content.language");
switch (sortByValue) {
case Constants.SECTION_SORT_DESC_ASC:
sql += " order by contentDescSearch.contentTitle";
break;
case Constants.SECTION_SORT_DESC_DSC:
sql += " order by contentDescSearch.contentTitle desc";
break;
case Constants.SECTION_SORT_PRICE_ASC:
sql += " order by contentDescSearch.contentTitle";
break;
case Constants.SECTION_SORT_PRICE_DSC:
sql += " order by contentDescSearch.contentTitle";
break;
}
query = em.createQuery(sql);
query.setParameter("siteId", siteDomain.getSite().getSiteId());
query.setParameter("catId", category.getCatId());
query.setParameter("siteProfileClassId", contentBean.getContentSessionKey().getSiteProfileClassId());
list = query.getResultList();
totalCount += list.size();
sqlIterator = list.iterator();
while (sqlIterator.hasNext()) {
Long contentId = (Long) sqlIterator.next();
if (index >= itemStart && index <= itemEnd) {
Content content = ContentDAO.load(siteDomain.getSite().getSiteId(), contentId);
ContentInfo contentInfo = formatContent(content);
dataVector.add(contentInfo);
}
index++;
if (index > itemEnd) {
break;
}
}
int midpoint = pageNavCount / 2;
int recordCount = totalCount;
int pageTotal = recordCount / pageSize;
if (recordCount % pageSize > 0) {
pageTotal++;
}
categoryInfo.setPageTotal(pageTotal);
categoryInfo.setPageNum(pageNum);
int pageStart = pageNum - midpoint;
if (pageStart < 1) {
pageStart = 1;
}
int pageEnd = pageStart + pageNavCount - 1;
if (pageEnd > pageTotal) {
pageEnd = pageTotal;
if (pageEnd - pageStart + 1 < pageNavCount) {
pageStart = pageEnd - pageNavCount + 1;
if (pageStart < 1) {
pageStart = 1;
}
}
}
categoryInfo.setPageStart(pageStart);
categoryInfo.setPageEnd(pageEnd);
Object categoryDatas[] = new Object[dataVector.size()];
dataVector.copyInto(categoryDatas);
categoryInfo.setCategoryDatas(categoryDatas);
/*
* Extract filtering information
*/
Vector<CategoryCustomAttributeInfo> categoryCustomAttributeVector = new Vector<CategoryCustomAttributeInfo>();
for (CustomAttribute customAttribute : category.getCustomAttributes()) {
boolean isFilterAttribute = false;
ContentFilterBean contentFilterBean = null;
for (ContentFilterBean bean : contentFilterBeans) {
if (bean.getCustomAttribId().equals(customAttribute.getCustomAttribId())) {
contentFilterBean = bean;
isFilterAttribute = true;
break;
}
}
CategoryCustomAttributeInfo categoryCustomAttributeInfo = new CategoryCustomAttributeInfo();
SiteProfileClass siteProfileClass = contentBean.getContentSessionBean().getSiteProfile().getSiteProfileClass();
if (isFilterAttribute) {
CategoryCustomAttributeOptionInfo optionInfo = new CategoryCustomAttributeOptionInfo();
optionInfo.setCustomAttribOptionId(contentFilterBean.getCustomAttribOptionId().toString());
CustomAttributeOption customAttribOption = CustomAttributeOptionDAO.load(siteDomain.getSite().getSiteId(), contentFilterBean.getCustomAttribOptionId());
if (customAttribute.getSystemRecord() == Constants.VALUE_YES) {
PriceRange priceRange = getAttributePriceRange(customAttribute, customAttribOption.getCustomAttribOptionId());
String rangeValue = formatter.formatCurrency(priceRange.getMinPrice().floatValue()) +
" - " +
formatter.formatCurrency(priceRange.getMaxprice().floatValue());
optionInfo.setCustomAttribValue(rangeValue);
}
else {
optionInfo.setCustomAttribValue(customAttribOption.getCustomAttributeOptionLanguage().getCustomAttribValue());
if (!contentBean.getContentSessionBean().isSiteProfileClassDefault()) {
for (CustomAttributeOptionLanguage customAttributeOptionLanguage : customAttribOption.getCustomAttributeOptionLanguages()) {
if (!customAttributeOptionLanguage.getSiteProfileClass().getSiteProfileClassId().equals(siteProfileClass.getSiteProfileClassId())) {
continue;
}
if (customAttributeOptionLanguage.getCustomAttribValue() != null) {
optionInfo.setCustomAttribValue(customAttributeOptionLanguage.getCustomAttribValue());
break;
}
}
}
}
String customAttribUrl = categoryUrl + "?sortBy" + sortBy;
for (ContentFilterBean bean : contentFilterBeans) {
if (bean.getCustomAttribId().equals(customAttribute.getCustomAttribId())) {
continue;
}
customAttribUrl += "&filter=" + bean.getCustomAttribId() + "," + bean.getCustomAttribOptionId();
}
optionInfo.setCustomAttribUrl(customAttribUrl);
categoryCustomAttributeInfo.setCustomAttribId(customAttribute.getCustomAttribId().toString());
categoryCustomAttributeInfo.setCustomAttribDesc(customAttribute.getCustomAttributeLanguage().getCustomAttribDesc());
categoryCustomAttributeInfo.setSelected(true);
categoryCustomAttributeInfo.setSelectedCustomAttribOptionInfo(optionInfo);
if (!contentBean.getContentSessionBean().isSiteProfileClassDefault()) {
for (CustomAttributeLanguage customAttributeLanguage : customAttribute.getCustomAttributeLanguages()) {
if (!customAttributeLanguage.getSiteProfileClass().getSiteProfileClassId().equals(siteProfileClass.getSiteProfileClassId())) {
continue;
}
if (customAttributeLanguage.getCustomAttribDesc() != null) {
categoryCustomAttributeInfo.setCustomAttribDesc(customAttributeLanguage.getCustomAttribDesc());
break;
}
}
}
}
else {
Vector<CategoryCustomAttributeOptionInfo> categoryCustomAttributeOptionVector = new Vector<CategoryCustomAttributeOptionInfo>();
if (customAttribute.getSystemRecord() == Constants.VALUE_YES) {
for (CustomAttributeOption customAttributeOption : customAttribute.getCustomAttributeOptions()) {
long count = getDataInAttributeOptionCount(category, customAttribute, customAttributeOption, contentFilterBeans);
CategoryCustomAttributeOptionInfo optionInfo = new CategoryCustomAttributeOptionInfo();
optionInfo.setCustomAttribOptionId(customAttributeOption.getCustomAttribOptionId().toString());
PriceRange priceRange = getAttributePriceRange(customAttribute, customAttributeOption.getCustomAttribOptionId());
String rangeValue = formatter.formatCurrency(priceRange.getMinPrice().floatValue()) +
" - " +
formatter.formatCurrency(priceRange.getMaxprice().floatValue());
optionInfo.setCustomAttribValue(rangeValue);
optionInfo.setDataCount((int) count);
String customAttribUrl = categoryUrl + "?sortBy=" + sortBy;
for (ContentFilterBean bean : contentFilterBeans) {
customAttribUrl += "&filter=" + bean.getCustomAttribId() + "," + bean.getCustomAttribOptionId();
}
customAttribUrl += "&filter=" + customAttribute.getCustomAttribId() + "," + customAttributeOption.getCustomAttribOptionId();
optionInfo.setCustomAttribUrl(customAttribUrl);
categoryCustomAttributeOptionVector.add(optionInfo);
}
}
else {
for (CustomAttributeOption customAttributeOption : customAttribute.getCustomAttributeOptions()) {
long count = getDataInAttributeOptionCount(category, customAttribute, customAttributeOption, contentFilterBeans);
CategoryCustomAttributeOptionInfo optionInfo = new CategoryCustomAttributeOptionInfo();
optionInfo.setCustomAttribOptionId(customAttributeOption.getCustomAttribOptionId().toString());
optionInfo.setCustomAttribValue(customAttributeOption.getCustomAttributeOptionLanguage().getCustomAttribValue());
optionInfo.setDataCount((int) count);
if (!contentBean.getContentSessionBean().isSiteProfileClassDefault()) {
for (CustomAttributeOptionLanguage customAttributeOptionLanguage : customAttributeOption.getCustomAttributeOptionLanguages()) {
if (!customAttributeOptionLanguage.getSiteProfileClass().getSiteProfileClassId().equals(siteProfileClass.getSiteProfileClassId())) {
continue;
}
if (customAttributeOptionLanguage.getCustomAttribValue() != null) {
optionInfo.setCustomAttribValue(customAttributeOptionLanguage.getCustomAttribValue());
break;
}
}
}
String customAttribUrl = categoryUrl + "?sortBy=" + sortBy;
for (ContentFilterBean bean : contentFilterBeans) {
customAttribUrl += "&filter=" + bean.getCustomAttribId() + "," + bean.getCustomAttribOptionId();
}
customAttribUrl += "&filter=" + customAttribute.getCustomAttribId() + "," + customAttributeOption.getCustomAttribOptionId();
optionInfo.setCustomAttribUrl(customAttribUrl);
categoryCustomAttributeOptionVector.add(optionInfo);
}
}
categoryCustomAttributeInfo.setCustomAttribId(customAttribute.getCustomAttribId().toString());
categoryCustomAttributeInfo.setCustomAttribDesc(customAttribute.getCustomAttributeLanguage().getCustomAttribDesc());
categoryCustomAttributeInfo.setSelected(false);
if (!contentBean.getContentSessionBean().isSiteProfileClassDefault()) {
for (CustomAttributeLanguage customAttributeLanguage : customAttribute.getCustomAttributeLanguages()) {
if (!customAttributeLanguage.getSiteProfileClass().getSiteProfileClassId().equals(siteProfileClass.getSiteProfileClassId())) {
continue;
}
if (customAttributeLanguage.getCustomAttribDesc() != null) {
categoryCustomAttributeInfo.setCustomAttribDesc(customAttributeLanguage.getCustomAttribDesc());