public void extract(AdminListingActionForm actionForm, HttpServletRequest request) throws Throwable {
ItemListingActionForm form = (ItemListingActionForm) actionForm;
EntityManager em = JpaConnection.getInstance().getCurrentEntityManager();
AdminBean adminBean = getAdminBean(request);
Site site = adminBean.getSite();
ActionMessages errors = validate(form);
if (errors.size() != 0) {
saveMessages(request, errors);
return;
}
Query query = null;
String selectedCategories[] = form.getSrSelectedCategories();
String sql = "select distinct item " +
"from Item item ";
if (selectedCategories != null) {
sql += "left join item.categories category ";
}
sql += "where item.siteId = :siteId ";
if (form.getSrItemNum() != null && form.getSrItemNum().length() > 0) {
sql += "and item.itemNum = :itemNum ";
}
if (form.getSrItemSkuCd().length() > 0) {
sql += "and item.itemSkuCd = :itemSkuCd ";
}
if (form.getSrItemUpcCd().length() > 0) {
sql += "and item.itemUpcCd = :itemUpcCd ";
}
if (form.getSrItemShortDesc().length() > 0) {
sql += "and item.itemLanguage.itemShortDesc like :itemShortDesc ";
}
if (!form.getSrPublished().equals("*")) {
sql += "and item.published = :published ";
}
sql += "and item.itemTypeCd in (";
if (form.isSrItemTypeRegular()) {
sql += "'01',";
}
if (form.isSrItemTypeTemplate()) {
sql += "'02',";
}
if (form.isSrItemTypeSku()) {
sql += "'03',";
}
if (form.isSrItemTypeStaticBundle()) {
sql += "'04',";
}
if (form.isSrItemTypeRecommandBundle()) {
sql += "'05',";
}
sql += "'') ";
sql += "and item.itemPublishOn between :itemPublishOnStart and :itemPublishOnEnd ";
sql += "and item.itemExpireOn between :itemExpireOnStart and :itemExpireOnEnd ";
if (!form.getSrUpdateBy().equals("All")) {
sql += "and item.recUpdateBy = :recUpdateBy ";
}
if (!form.getSrCreateBy().equals("All")) {
sql += "and item.recCreateBy = :recCreateBy ";
}
if (selectedCategories != null) {
sql += "and category.catId in (";
int index = 0;
for (int i = 0; i < selectedCategories.length; i++) {
Long catIds[] = Utility.getCatIdTreeList(site.getSiteId(), Format.getLong(selectedCategories[i]));
for (int j = 0; j < catIds.length; j++) {
if (index > 0) {
sql += ",";
}
sql += ":selectedCategory" + index++;
}
}
sql += ") ";
}
query = em.createQuery(sql);
Date date = null;
query.setParameter("siteId", site.getSiteId());
if (form.getSrItemSkuCd().length() > 0) {
query.setParameter("itemSkuCd", form.getSrItemSkuCd());
}
if (form.getSrItemNum().length() > 0) {
query.setParameter("itemNum", form.getSrItemNum());
}
if (form.getSrItemUpcCd().length() > 0) {
query.setParameter("itemUpcCd", form.getSrItemUpcCd());
}
if (form.getSrItemShortDesc().length() > 0) {
query.setParameter("itemShortDesc", "%" + form.getSrItemShortDesc() + "%");
}
if (!form.getSrPublished().equals("*")) {
query.setParameter("published", form.getSrPublished());
}
if (form.getSrItemPublishOnStart().length() > 0) {
date = Format.getDate(form.getSrItemPublishOnStart());
query.setParameter("itemPublishOnStart", date);
}
else {
query.setParameter("itemPublishOnStart", Format.LOWDATE);
}
if (form.getSrItemPublishOnEnd().length() > 0) {
date = Format.getDate(form.getSrItemPublishOnEnd());
query.setParameter("itemPublishOnEnd", date);
}
else {
query.setParameter("itemPublishOnEnd", Format.HIGHDATE);
}
if (form.getSrItemExpireOnStart().length() > 0) {
date = Format.getDate(form.getSrItemExpireOnStart());
query.setParameter("itemExpireOnStart", date);
}
else {
query.setParameter("itemExpireOnStart", Format.LOWDATE);
}
if (form.getSrItemExpireOnEnd().length() > 0) {
date = Format.getDate(form.getSrItemExpireOnEnd());
query.setParameter("itemExpireOnEnd", date);
}
else {
query.setParameter("itemExpireOnEnd", Format.HIGHDATE);
}
if (!form.getSrUpdateBy().equals("All")) {
query.setParameter("recUpdateBy", form.getSrUpdateBy());
}
if (!form.getSrCreateBy().equals("All")) {
query.setParameter("recCreateBy", form.getSrCreateBy());
}
if (selectedCategories != null) {
int index = 0;
for (int i = 0; i < selectedCategories.length; i++) {
Long catIds[] = Utility.getCatIdTreeList(site.getSiteId(), Format.getLong(selectedCategories[i]));
for (int j = 0; j < catIds.length; j++) {
query.setParameter("selectedCategory" + index++, catIds[j].longValue());
}
}
}