[pal-cvs 2847] [592] added category list.

svnno****@sourc***** svnno****@sourc*****
2007年 9月 28日 (金) 14:59:44 JST


Revision: 592
          http://svn.sourceforge.jp/cgi-bin/viewcvs.cgi?root=pal&view=rev&rev=592
Author:   shinsuke
Date:     2007-09-28 14:59:44 +0900 (Fri, 28 Sep 2007)

Log Message:
-----------
added category list.

Modified Paths:
--------------
    pompei/portlets/pompei-core/trunk/src/main/java/jp/sf/pal/pompei/PompeiConstants.java
    pompei/portlets/pompei-core/trunk/src/main/java/jp/sf/pal/pompei/dxo/CategoryDxo.java
    pompei/portlets/pompei-core/trunk/src/main/java/jp/sf/pal/pompei/service/CategoryService.java
    pompei/portlets/pompei-core/trunk/src/main/java/jp/sf/pal/pompei/service/impl/CategoryServiceImpl.java
    pompei/portlets/pompei-core/trunk/src/main/webapp/WEB-INF/db/insert_data.sql
    pompei/portlets/pompei-core/trunk/src/main/webapp/view/index.html

Added Paths:
-----------
    pompei/portlets/pompei-core/trunk/src/main/java/jp/sf/pal/pompei/web/user/product/CategoryListAction.java
    pompei/portlets/pompei-core/trunk/src/main/java/jp/sf/pal/pompei/web/user/product/CategoryListPage.java
    pompei/portlets/pompei-core/trunk/src/main/webapp/view/user/product/categoryList.html


-------------- next part --------------
Modified: pompei/portlets/pompei-core/trunk/src/main/java/jp/sf/pal/pompei/PompeiConstants.java
===================================================================
--- pompei/portlets/pompei-core/trunk/src/main/java/jp/sf/pal/pompei/PompeiConstants.java	2007-09-28 05:55:25 UTC (rev 591)
+++ pompei/portlets/pompei-core/trunk/src/main/java/jp/sf/pal/pompei/PompeiConstants.java	2007-09-28 05:59:44 UTC (rev 592)
@@ -72,4 +72,8 @@
     public static final BigDecimal DEFAULT_CURRENCY_ID = new BigDecimal(1);
 
     public static final BigDecimal DEFAULT_DELIVERY_PRICE = new BigDecimal(0);
+
+    public static final String CATEGORY_BREADCRUMB = "CategoryBreadcrumb";
+
+    public static final String CURRENT_CATEGORY_ID = "CurrentCategoryId";
 }

Modified: pompei/portlets/pompei-core/trunk/src/main/java/jp/sf/pal/pompei/dxo/CategoryDxo.java
===================================================================
--- pompei/portlets/pompei-core/trunk/src/main/java/jp/sf/pal/pompei/dxo/CategoryDxo.java	2007-09-28 05:55:25 UTC (rev 591)
+++ pompei/portlets/pompei-core/trunk/src/main/java/jp/sf/pal/pompei/dxo/CategoryDxo.java	2007-09-28 05:59:44 UTC (rev 592)
@@ -13,10 +13,16 @@
 public interface CategoryDxo extends Serializable {
 
     @ConversionRule("sortOrder : category.sortOrder" + ",name : name"
-            + ",categoryId : categoryId" + ",image : category.image")
+            + ",description : description" + ",categoryId : categoryId"
+            + ",parentId : category.parentId" + ",image : category.image")
     public void convert(List<CategoryDescription> category,
             List<Map<String, Object>> list);
 
+    @ConversionRule("sortOrder : category.sortOrder" + ",name : name"
+            + ",description : description" + ",categoryId : categoryId"
+            + ",parentId : category.parentId" + ",image : category.image")
+    public List<Map<String, Object>> convert(List<CategoryDescription> category);
+
     CategoryDescription convert(CategoryEditPage page);
 
     public void convert(CategoryEditPage page, CategoryDescription entity);

Modified: pompei/portlets/pompei-core/trunk/src/main/java/jp/sf/pal/pompei/service/CategoryService.java
===================================================================
--- pompei/portlets/pompei-core/trunk/src/main/java/jp/sf/pal/pompei/service/CategoryService.java	2007-09-28 05:55:25 UTC (rev 591)
+++ pompei/portlets/pompei-core/trunk/src/main/java/jp/sf/pal/pompei/service/CategoryService.java	2007-09-28 05:59:44 UTC (rev 592)
@@ -29,4 +29,7 @@
     public void deleteCategory(BigDecimal id);
 
     public void updateCategoryDescription(CategoryDescription d);
+
+    public List<CategoryDescription> getCategoryDescriptionBreadcrumb(
+            BigDecimal categoryId);
 }

Modified: pompei/portlets/pompei-core/trunk/src/main/java/jp/sf/pal/pompei/service/impl/CategoryServiceImpl.java
===================================================================
--- pompei/portlets/pompei-core/trunk/src/main/java/jp/sf/pal/pompei/service/impl/CategoryServiceImpl.java	2007-09-28 05:55:25 UTC (rev 591)
+++ pompei/portlets/pompei-core/trunk/src/main/java/jp/sf/pal/pompei/service/impl/CategoryServiceImpl.java	2007-09-28 05:59:44 UTC (rev 592)
@@ -4,8 +4,10 @@
 import java.sql.Timestamp;
 import java.util.Date;
 import java.util.Iterator;
+import java.util.LinkedList;
 import java.util.List;
 
+import jp.sf.pal.pompei.PompeiConstants;
 import jp.sf.pal.pompei.cbean.CategoryCB;
 import jp.sf.pal.pompei.cbean.CategoryDescriptionCB;
 import jp.sf.pal.pompei.exbhv.CategoryBhv;
@@ -28,42 +30,32 @@
 
     private transient CategoryDescriptionBhv categoryDescriptionBhv;
 
-    /**
-     * @return languageService
-     */
-    public LanguageService getLanguageService() {
-        return languageService;
+    public List<CategoryDescription> getCategoryDescriptionBreadcrumb(
+            BigDecimal categoryId) {
+        List<CategoryDescription> cdList = new LinkedList<CategoryDescription>();
+        while (categoryId != null) {
+            CategoryDescription cd = getCategoryDescription(categoryId);
+            if (cd != null) {
+                categoryId = cd.getCategory().getParentId();
+                cdList.add(0, cd);
+            } else {
+                categoryId = null;
+            }
+        }
+        return cdList;
     }
 
-    /**
-     * @param languageService 設定する languageService
-     */
-    public void setLanguageService(LanguageService languageService) {
-        this.languageService = languageService;
+    public CategoryDescription getCategoryDescription(BigDecimal categoryId) {
+        CategoryDescription cd = getCategoryDescription(categoryId,
+                getLanguageService().getCurrentLanguage().getLanguageId());
+        if (cd != null) {
+            return cd;
+        }
+        // language fallback
+        return getCategoryDescription(categoryId, getLanguageService()
+                .getDefaultLanguage().getLanguageId());
     }
 
-    public CategoryBhv getCategoryBhv() {
-        return categoryBhv;
-    }
-
-    public void setCategoryBhv(CategoryBhv categoriesBhv) {
-        this.categoryBhv = categoriesBhv;
-    }
-
-    public CategoryDescriptionBhv getCategoryDescriptionBhv() {
-        return categoryDescriptionBhv;
-    }
-
-    public void setCategoryDescriptionBhv(
-            CategoryDescriptionBhv categoriesDescriptionBhv) {
-        this.categoryDescriptionBhv = categoriesDescriptionBhv;
-    }
-
-    public CategoryDescription getCategoryDescription(BigDecimal categoriesId) {
-        return getCategoryDescription(categoriesId, getLanguageService()
-                .getCurrentLanguage().getLanguageId());
-    }
-
     public CategoryDescription getCategoryDescription(BigDecimal categoriesId,
             BigDecimal languagesId) {
         CategoryDescriptionCB cb = new CategoryDescriptionCB();
@@ -84,12 +76,12 @@
         cb.query().queryCategory().setParentId_Equal(id);
         cb.query().queryCategory().addOrderBy_SortOrder_Asc();
 
-        List<CategoryDescription> list = categoryDescriptionBhv
-                .selectList(cb);
+        List<CategoryDescription> list = categoryDescriptionBhv.selectList(cb);
         return list;
     }
 
     public List<CategoryDescription> getSubCategoryDescriptionList(BigDecimal id) {
+        //TODO fallback
         return getSubCategoryDescriptionList(id, getLanguageService()
                 .getCurrentLanguage().getLanguageId());
     }
@@ -126,8 +118,7 @@
         // delete CategoryDescription
         CategoryDescriptionCB cb = new CategoryDescriptionCB();
         cb.query().setCategoryId_Equal(id);
-        List<CategoryDescription> list = categoryDescriptionBhv
-                .selectList(cb);
+        List<CategoryDescription> list = categoryDescriptionBhv.selectList(cb);
         for (Iterator<CategoryDescription> itr = list.iterator(); itr.hasNext();) {
             categoryDescriptionBhv.delete(itr.next());
         }
@@ -151,4 +142,35 @@
         categoryDescriptionBhv.update(d);
     }
 
+    /**
+     * @return languageService
+     */
+    public LanguageService getLanguageService() {
+        return languageService;
+    }
+
+    /**
+     * @param languageService 設定する languageService
+     */
+    public void setLanguageService(LanguageService languageService) {
+        this.languageService = languageService;
+    }
+
+    public CategoryBhv getCategoryBhv() {
+        return categoryBhv;
+    }
+
+    public void setCategoryBhv(CategoryBhv categoriesBhv) {
+        this.categoryBhv = categoriesBhv;
+    }
+
+    public CategoryDescriptionBhv getCategoryDescriptionBhv() {
+        return categoryDescriptionBhv;
+    }
+
+    public void setCategoryDescriptionBhv(
+            CategoryDescriptionBhv categoriesDescriptionBhv) {
+        this.categoryDescriptionBhv = categoriesDescriptionBhv;
+    }
+
 }

Added: pompei/portlets/pompei-core/trunk/src/main/java/jp/sf/pal/pompei/web/user/product/CategoryListAction.java
===================================================================
--- pompei/portlets/pompei-core/trunk/src/main/java/jp/sf/pal/pompei/web/user/product/CategoryListAction.java	2007-09-28 05:55:25 UTC (rev 591)
+++ pompei/portlets/pompei-core/trunk/src/main/java/jp/sf/pal/pompei/web/user/product/CategoryListAction.java	2007-09-28 05:59:44 UTC (rev 592)
@@ -0,0 +1,135 @@
+package jp.sf.pal.pompei.web.user.product;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import jp.sf.pal.pompei.PompeiConstants;
+import jp.sf.pal.pompei.dxo.CategoryDxo;
+import jp.sf.pal.pompei.service.CategoryService;
+import jp.sf.pal.pompei.util.SessionUtil;
+
+public class CategoryListAction implements Serializable {
+
+    /**
+     * 
+     */
+    private static final long serialVersionUID = 8175924737246519774L;
+
+    /**
+     * 
+     */
+    private CategoryListPage categoryListPage;
+
+    private CategoryService categoryService;
+
+    private CategoryDxo categoryDxo;
+
+    public Class<?> initialize() {
+        return null;
+    }
+
+    public Class<?> prerender() {
+        BigDecimal currentCategoryId = (BigDecimal) SessionUtil
+                .getFromApplicationScope(PompeiConstants.CURRENT_CATEGORY_ID);
+        // current category
+        if (getCategoryListPage().getCategoryId() == null) {
+            getCategoryListPage().setCategoryId(currentCategoryId);
+            if (getCategoryListPage().getCategoryId() == null) {
+                getCategoryListPage().setCategoryId(
+                        PompeiConstants.ROOT_CATEGORY_ID);
+            }
+            //  refresh breadcrumb
+            List<Map<String, Object>> breadcrumbItems = new ArrayList<Map<String, Object>>();
+            getCategoryDxo().convert(
+                    getCategoryService().getCategoryDescriptionBreadcrumb(
+                            getCategoryListPage().getCategoryId()),
+                    breadcrumbItems);
+            getCategoryListPage().setBreadcrumbItems(breadcrumbItems);
+
+            // set current id
+            SessionUtil.putToApplicationScope(
+                    PompeiConstants.CURRENT_CATEGORY_ID, getCategoryListPage()
+                            .getCategoryId());
+        } else if (!getCategoryListPage().getCategoryId().equals(
+                currentCategoryId)) {
+            //  refresh breadcrumb
+            List<Map<String, Object>> breadcrumbItems = new ArrayList<Map<String, Object>>();
+            getCategoryDxo().convert(
+                    getCategoryService().getCategoryDescriptionBreadcrumb(
+                            getCategoryListPage().getCategoryId()),
+                    breadcrumbItems);
+            getCategoryListPage().setBreadcrumbItems(breadcrumbItems);
+
+            // set current id
+            SessionUtil.putToApplicationScope(
+                    PompeiConstants.CURRENT_CATEGORY_ID, getCategoryListPage()
+                            .getCategoryId());
+
+        }
+
+        // category breadcrumb
+        if (getCategoryListPage().getBreadcrumbItems() == null) {
+            //  refresh breadcrumb
+            List<Map<String, Object>> breadcrumbItems = new ArrayList<Map<String, Object>>();
+            getCategoryDxo().convert(
+                    getCategoryService().getCategoryDescriptionBreadcrumb(
+                            getCategoryListPage().getCategoryId()),
+                    breadcrumbItems);
+            getCategoryListPage().setBreadcrumbItems(breadcrumbItems);
+        }
+
+        // set sub categories
+        getCategoryListPage().setCategoryItems(
+                getCategoryDxo().convert(
+                        getCategoryService().getSubCategoryDescriptionList(
+                                getCategoryListPage().getCategoryId())));
+
+        return null;
+    }
+
+    /**
+     * @return categoryListPage
+     */
+    public CategoryListPage getCategoryListPage() {
+        return categoryListPage;
+    }
+
+    /**
+     * @param categoryListPage 設定する categoryListPage
+     */
+    public void setCategoryListPage(CategoryListPage categoryListPage) {
+        this.categoryListPage = categoryListPage;
+    }
+
+    /**
+     * @return categoryService
+     */
+    public CategoryService getCategoryService() {
+        return categoryService;
+    }
+
+    /**
+     * @param categoryService 設定する categoryService
+     */
+    public void setCategoryService(CategoryService categoryService) {
+        this.categoryService = categoryService;
+    }
+
+    /**
+     * @return categoryDxo
+     */
+    public CategoryDxo getCategoryDxo() {
+        return categoryDxo;
+    }
+
+    /**
+     * @param categoryDxo 設定する categoryDxo
+     */
+    public void setCategoryDxo(CategoryDxo categoryDxo) {
+        this.categoryDxo = categoryDxo;
+    }
+
+}


Property changes on: pompei/portlets/pompei-core/trunk/src/main/java/jp/sf/pal/pompei/web/user/product/CategoryListAction.java
___________________________________________________________________
Name: svn:eol-style
   + native

Added: pompei/portlets/pompei-core/trunk/src/main/java/jp/sf/pal/pompei/web/user/product/CategoryListPage.java
===================================================================
--- pompei/portlets/pompei-core/trunk/src/main/java/jp/sf/pal/pompei/web/user/product/CategoryListPage.java	2007-09-28 05:55:25 UTC (rev 591)
+++ pompei/portlets/pompei-core/trunk/src/main/java/jp/sf/pal/pompei/web/user/product/CategoryListPage.java	2007-09-28 05:59:44 UTC (rev 592)
@@ -0,0 +1,83 @@
+package jp.sf.pal.pompei.web.user.product;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+import java.util.List;
+import java.util.Map;
+
+public class CategoryListPage implements Serializable {
+
+    /**
+     * 
+     */
+    private static final long serialVersionUID = 501037888822535712L;
+
+    private int breadcrumbIndex;
+
+    private List<Map<String, Object>> breadcrumbItems;
+
+    private int categoryIndex;
+
+    private List<Map<String, Object>> categoryItems;
+
+    private String name;
+
+    private BigDecimal categoryId;
+
+    public int getBreadcrumbIndex() {
+        return breadcrumbIndex;
+    }
+
+    public void setBreadcrumbIndex(int breadcrumbIndex) {
+        this.breadcrumbIndex = breadcrumbIndex;
+    }
+
+    public List<Map<String, Object>> getBreadcrumbItems() {
+        return breadcrumbItems;
+    }
+
+    public void setBreadcrumbItems(List<Map<String, Object>> breadcrumbItems) {
+        this.breadcrumbItems = breadcrumbItems;
+    }
+
+    public int getCategoryIndex() {
+        return categoryIndex;
+    }
+
+    public void setCategoryIndex(int categoryIndex) {
+        this.categoryIndex = categoryIndex;
+    }
+
+    public List<Map<String, Object>> getCategoryItems() {
+        return categoryItems;
+    }
+
+    public void setCategoryItems(List<Map<String, Object>> categoryItems) {
+        this.categoryItems = categoryItems;
+    }
+
+    public String getDepth() {
+        StringBuilder sb = new StringBuilder();
+        for (int i = 0; i < getBreadcrumbIndex(); i++) {
+            sb.append("&nbsp;");
+        }
+        return sb.toString();
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public BigDecimal getCategoryId() {
+        return categoryId;
+    }
+
+    public void setCategoryId(BigDecimal parentId) {
+        this.categoryId = parentId;
+    }
+
+}


Property changes on: pompei/portlets/pompei-core/trunk/src/main/java/jp/sf/pal/pompei/web/user/product/CategoryListPage.java
___________________________________________________________________
Name: svn:eol-style
   + native

Modified: pompei/portlets/pompei-core/trunk/src/main/webapp/WEB-INF/db/insert_data.sql
===================================================================
--- pompei/portlets/pompei-core/trunk/src/main/webapp/WEB-INF/db/insert_data.sql	2007-09-28 05:55:25 UTC (rev 591)
+++ pompei/portlets/pompei-core/trunk/src/main/webapp/WEB-INF/db/insert_data.sql	2007-09-28 05:59:44 UTC (rev 592)
@@ -28,3 +28,6 @@
 
 INSERT INTO CATEGORY VALUES (1, '', null, 1, '2007-01-01 00:00:00', '2007-01-01 00:00:00');
 
+INSERT INTO CATEGORY_DESCRIPTION VALUES (1,1,'すべてのカテゴリ','');
+
+

Modified: pompei/portlets/pompei-core/trunk/src/main/webapp/view/index.html
===================================================================
--- pompei/portlets/pompei-core/trunk/src/main/webapp/view/index.html	2007-09-28 05:55:25 UTC (rev 591)
+++ pompei/portlets/pompei-core/trunk/src/main/webapp/view/index.html	2007-09-28 05:59:44 UTC (rev 592)
@@ -22,6 +22,7 @@
 ユーザー向けメニュー
 <ul>
 <li><a href="./user/product/productList.html">商品一覧</a></li>
+<li><a href="./user/product/categoryList.html">カテゴリリスト</a></li>
 <li><a href="./user/cart/productList.html">カート確認</a></li>
 <li><a href="./user/checkout/userInfoEdit.html">注文</a></li>
 </ul>

Added: pompei/portlets/pompei-core/trunk/src/main/webapp/view/user/product/categoryList.html
===================================================================
--- pompei/portlets/pompei-core/trunk/src/main/webapp/view/user/product/categoryList.html	2007-09-28 05:55:25 UTC (rev 591)
+++ pompei/portlets/pompei-core/trunk/src/main/webapp/view/user/product/categoryList.html	2007-09-28 05:59:44 UTC (rev 592)
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xmlns:pal="http://pal.sourceforge.jp/jsf4portlet"
+xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:te="http://www.seasar.org/teeda/extension">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+<title id="title-head">カテゴリ一覧画面</title>
+</head>
+<body>
+<form id="categoryForm">
+<input type="hidden" id="categoryId" />
+<div id="breadcrumbItems">
+<span id="depth" te:escape="false"> </span><a id="goCategoryList-breadcrmb" href="./categoryList.html?categoryId=0"><span id="name">カテゴリ</span></a><br/>
+</div>
+<div id="categoryItems">
+<span id="depth" te:escape="false"> </span><a id="goCategoryList" href="./categoryList.html?categoryId=1"><span id="name">スニーカー</span></a><br/>
+</div>
+</form>
+</body>
+</html>


pal-cvs メーリングリストの案内