Package com.jada.jpa.entity

Examples of com.jada.jpa.entity.Category


  public CategoryInfo getCategory(String catNaturalKey, String topCatNaturalKey, int pageSize, int pageNavCount, int pageNum, String sortBy, ContentFilterBean contentFilterBeans[]) throws Exception {
    CategoryInfo categoryInfo = new CategoryInfo();
    EntityManager em = JpaConnection.getInstance().getCurrentEntityManager();
    String key = Utility.reEncode(catNaturalKey);
    String topKey = Utility.reEncode(topCatNaturalKey);
        Category category = dataApi.getCategory(siteDomain.getSite().getSiteId(), key);
        if (category == null) {
          return null;
        }
        categoryInfo.setCatNaturalKey(catNaturalKey);
        categoryInfo.setCatId(category.getCatId().toString());
        categoryInfo.setTopCatId(null);
        categoryInfo.setTopCatNaturalKey(topCatNaturalKey);
        categoryInfo.setCatShortTitle(category.getCategoryLanguage().getCatShortTitle());
        categoryInfo.setCatTitle(category.getCategoryLanguage().getCatTitle());
        categoryInfo.setCatDesc(category.getCategoryLanguage().getCatDesc());
        categoryInfo.setDataCount(getDataInCategoryCounts(category.getCatId()));
        if (!contentBean.getContentSessionKey().isSiteProfileClassDefault()) {
          for (CategoryLanguage language : category.getCategoryLanguages()) {
            if (language.getSiteProfileClass().getSiteProfileClassId().equals(contentBean.getContentSessionKey().getSiteProfileClassId())) {
              if (language.getCatShortTitle() != null) {
                categoryInfo.setCatShortTitle(language.getCatShortTitle());
              }
              if (language.getCatTitle() != null) {
                categoryInfo.setCatTitle(language.getCatTitle());
              }
              if (language.getCatDesc() != null) {
                categoryInfo.setCatDesc(language.getCatDesc());
              }          
            }
          }
        }

        String categoryUrl = "/" + ApplicationGlobal.getContextPath() +
           Constants.FRONTEND_URL_PREFIX +
           "/" + contentBean.getContentSessionBean().getSiteDomain().getSiteDomainPrefix() +
            "/" + contentBean.getContentSessionBean().getSiteProfile().getSiteProfileClass().getSiteProfileClassName() +
           "/" + Constants.FRONTEND_URL_SECTION +
           "/" +
           topKey +  // topCategory
             "/" +
             category.getCatNaturalKey()// category
        String filterUrl = "";
        for (ContentFilterBean contentFilterBean : contentFilterBeans) {
          filterUrl += "&filter=" + contentFilterBean.getCustomAttribId() + "," + contentFilterBean.getCustomAttribOptionId();
        }
        categoryInfo.setCategoryBasicUrl(categoryUrl);
        categoryInfo.setFilterUrl(filterUrl);
        categoryInfo.setSortBy(sortBy == null ? "" : sortBy);
        categoryInfo.setCategoryUrl(categoryUrl + "?sortBy" + sortBy + filterUrl);
        
      int itemStart = (pageNum - 1) * pageSize;
      int itemEnd = itemStart + pageSize - 1;
      int index = 0;
     
      String value = sortBy;
      if (value == null || value.length() == 0) {
        value = String.valueOf(Constants.SECTION_SORT_DESC_ASC);
      }
      char sortByValue = value.charAt(0);
     
    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;
View Full Code Here


  }
 
  public CategoryInfo[] getCategoryTitles(String catNaturalKey, String topCatNaturalKey) throws Exception {
    String key = Utility.reEncode(catNaturalKey);
    String topKey = Utility.reEncode(topCatNaturalKey);
        Category category = dataApi.getCategory(siteDomain.getSite().getSiteId(), key);
        if (category == null) {
          return null;
        }

        Vector<CategoryInfo> titleCategoryVector = new Vector<CategoryInfo>();
      Category parent = category.getCategoryParent();
        while (true) {
            if (key.equals(topKey)) {
              break;
            }
            key = Utility.reEncode(parent.getCatNaturalKey());
            CategoryInfo categoryTitleInfo = new CategoryInfo();
            categoryTitleInfo.setCatNaturalKey(parent.getCatNaturalKey());
            categoryTitleInfo.setCatId(Format.getLong(parent.getCatId()));
            categoryTitleInfo.setCatShortTitle(parent.getCategoryLanguage().getCatShortTitle());
            categoryTitleInfo.setCatTitle(parent.getCategoryLanguage().getCatTitle());
            categoryTitleInfo.setCatDesc(parent.getCategoryLanguage().getCatDesc());
        String url = "/" + ApplicationGlobal.getContextPath() +
           Constants.FRONTEND_URL_PREFIX +
          "/" + contentBean.getContentSessionBean().getSiteDomain().getSiteDomainPrefix() +
          "/" + contentBean.getContentSessionBean().getSiteProfile().getSiteProfileClass().getSiteProfileClassName() +
            "/" + Constants.FRONTEND_URL_SECTION +
            "/" +
            topCatNaturalKey +  // topCategory
              "/" +
            parent.getCatNaturalKey()// category
            categoryTitleInfo.setCategoryUrl(url);
            if (!contentBean.getContentSessionKey().isSiteProfileClassDefault()) {
              for (CategoryLanguage language : parent.getCategoryLanguages()) {
                if (language.getSiteProfileClass().getSiteProfileClassId().equals(contentBean.getContentSessionKey().getSiteProfileClassId())) {
                  if (language.getCatShortTitle() != null) {
                    categoryTitleInfo.setCatShortTitle(language.getCatShortTitle());
                  }
                  if (language.getCatTitle() != null) {
                    categoryTitleInfo.setCatTitle(language.getCatTitle());
                  }
                  if (language.getCatDesc() != null) {
                    categoryTitleInfo.setCatDesc(language.getCatDesc());
                  }          
                }
              }
            }
            titleCategoryVector.add(categoryTitleInfo);
            parent = parent.getCategoryParent();
            if (parent == null) {
              break;
            }
        }
        // Reverse sequence order
View Full Code Here

        return categoryTitleInfos;
  }
 
  public CategoryInfo[] getCategoryChildren(String catNaturalKey, String topCatNaturalKey) throws Exception {
    String key = Utility.reEncode(catNaturalKey);
        Category category = dataApi.getCategory(siteDomain.getSite().getSiteId(), key);
        if (category == null) {
          return null;
        }

      Vector<Object> vector = new Vector<Object>();
      for (Category childCategory : category.getCategoryChildren()) {
        if (childCategory.getPublished() != Constants.VALUE_YES) {
          continue;
        }
        CategoryInfo childCategoryInfo = new CategoryInfo();
        childCategoryInfo.setCatId(Format.getLong(childCategory.getCatId()));
View Full Code Here

      JSONEscapeObject jsonResult = new JSONEscapeObject();
      jsonResult.put("status", Constants.WEBSERVICE_STATUS_SUCCESS);
      java.util.Iterator<Category> iterator = coupon.getCategories().iterator();
      Vector<JSONEscapeObject> categories = new Vector<JSONEscapeObject>();
      while (iterator.hasNext()) {
        Category category = (Category) iterator.next();
        JSONEscapeObject object = new JSONEscapeObject();
        object.put("catId", category.getCatId());
        object.put("catShortTitle", category.getCategoryLanguage().getCatShortTitle());
        categories.add(object);
      }
      jsonResult.put("categories", categories);
      result = jsonResult.toHtmlString();
      return result;
View Full Code Here

        }
      }
    }
    Iterator<?> iterator = removeList.iterator();
    while (iterator.hasNext()) {
      Category category = (Category) iterator.next();
      coupon.getCategories().remove(category);
    }
    String result = getJSONCategoryList(coupon);
    streamWebService(response, result);
    return null;
View Full Code Here

    MessageResources resources = this.getResources(request);
    Coupon coupon = CouponDAO.load(siteId, Format.getLong(form.getCouponId()));
    boolean found = false;
    java.util.Iterator<Category> iterator = coupon.getCategories().iterator();
    while (iterator.hasNext()) {
      Category category = (Category) iterator.next();
      if (category.getCatId().equals(Format.getLong(form.getCatId()))) {
        found = true;
        break;
      }
    }
    if (found) {
      JSONEscapeObject jsonResult = new JSONEscapeObject();
      jsonResult.put("status", Constants.WEBSERVICE_STATUS_FAILED);
      jsonResult.put("message", resources.getMessage("error.record.duplicate"));
      streamWebService(response, jsonResult.toHtmlString());
    }
    Category category = CategoryDAO.load(siteId, Format.getLong(form.getCatId()));
    if (category == null) {
      JSONEscapeObject jsonResult = new JSONEscapeObject();
      jsonResult.put("status", Constants.WEBSERVICE_STATUS_FAILED);
      jsonResult.put("message", resources.getMessage("error.category.notexist"));
      streamWebService(response, jsonResult.toHtmlString());
View Full Code Here

        sql = "from Category category where category.site.siteId = :siteId)";
        query = em.createQuery(sql);
        query.setParameter("siteId", site.getSiteId());
        iterator = query.getResultList().iterator();
        while (iterator.hasNext()) {
          Category category = (Category) iterator.next();
          category.setCategoryLanguage(null);
          for (CategoryLanguage categoryLanguage : category.getCategoryLanguages()) {
            em.remove(categoryLanguage);
          }
          em.remove(category);
        }
View Full Code Here

        String sql = "from Category where siteId = :siteId";
        Query query = em.createQuery(sql);
        query.setParameter("siteId", Constants.SITE_SYSTEM);
        Iterator<?> iterator = query.getResultList().iterator();
        while (iterator.hasNext()) {
          Category master = (Category) iterator.next();
          Category category = new Category();
          category.setCatNaturalKey(master.getCatNaturalKey());
          category.setSeqNum(master.getSeqNum());
          category.setPublished(master.getPublished());
          category.setSite(site);
          category.setCatId(null);
          category.setRecUpdateBy(userId);
          category.setRecUpdateDatetime(new Date(System.currentTimeMillis()));
          category.setRecCreateBy(userId);
          category.setRecCreateDatetime(new Date(System.currentTimeMillis()));
          category.setMenus(null);
          category.setCategoryLanguages(null);
          em.persist(category);
        }
  }
View Full Code Here

    Content content = new Content();
    content = ContentDAO.load(site.getSiteId(), Format.getLong(contentId));
    String catIds[] = form.getAddCategories();
    if (catIds != null) {
      for (String catId : catIds) {
        Category category = CategoryDAO.load(site.getSiteId(), Format.getLong(catId));
        content.getCategories().add(category);
        content.setRecUpdateBy(adminBean.getUser().getUserId());
        content.setRecUpdateDatetime(new Date(System.currentTimeMillis()));
      }
    }
View Full Code Here

    content = ContentDAO.load(site.getSiteId(), Format.getLong(form.getContentId()));
   
    String catIds[] = form.getRemoveCategories();
    if (catIds != null) {
      for (String catId : catIds) {
        Category category = CategoryDAO.load(site.getSiteId(), Format.getLong(catId));
        content.getCategories().remove(category);
      }
    }
   
    content.setRecUpdateBy(adminBean.getUser().getUserId());
View Full Code Here

TOP

Related Classes of com.jada.jpa.entity.Category

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.