rave-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ja...@apache.org
Subject svn commit: r1160600 - in /incubator/rave/trunk/rave-portal/src: main/java/org/apache/rave/portal/model/ main/java/org/apache/rave/portal/repository/ main/java/org/apache/rave/portal/repository/impl/ main/java/org/apache/rave/portal/service/ main/java/...
Date Tue, 23 Aug 2011 09:52:13 GMT
Author: jasha
Date: Tue Aug 23 09:52:12 2011
New Revision: 1160600

URL: http://svn.apache.org/viewvc?rev=1160600&view=rev
Log:
RAVE-77 Widgets can be hidden from users until they have been flagged as approved by the site
owner
WidgetStore only shows PUBLISHED items.

Added:
    incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/model/WidgetStatus.java
    incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/portal/model/WidgetTest.java
    incubator/rave/trunk/rave-portal/src/test/resources/portal_test_data.sql
Modified:
    incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/model/Widget.java
    incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/repository/WidgetRepository.java
    incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/repository/impl/JpaWidgetRepository.java
    incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/service/WidgetService.java
    incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/service/impl/DefaultWidgetService.java
    incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/web/controller/WidgetStoreController.java
    incubator/rave/trunk/rave-portal/src/main/resources/initial_data.sql
    incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/portal/repository/JpaWidgetRepositoryTest.java
    incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/portal/service/WidgetServiceTest.java
    incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/portal/web/controller/WidgetStoreControllerTest.java
    incubator/rave/trunk/rave-portal/src/test/resources/portal-test-applicationContext.xml

Modified: incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/model/Widget.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/model/Widget.java?rev=1160600&r1=1160599&r2=1160600&view=diff
==============================================================================
--- incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/model/Widget.java
(original)
+++ incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/model/Widget.java
Tue Aug 23 09:52:12 2011
@@ -23,6 +23,8 @@ import java.io.Serializable;
 import javax.persistence.Basic;
 import javax.persistence.Column;
 import javax.persistence.Entity;
+import javax.persistence.EnumType;
+import javax.persistence.Enumerated;
 import javax.persistence.GeneratedValue;
 import javax.persistence.GenerationType;
 import javax.persistence.Id;
@@ -40,14 +42,40 @@ import org.apache.rave.persistence.Basic
 @Table(name="widget")
 @SequenceGenerator(name="widgetIdSeq", sequenceName = "widget_id_seq")
 @NamedQueries({
-        @NamedQuery(name = "Widget.getAll", query = "SELECT w from Widget w"),
-        @NamedQuery(name = "Widget.countAll", query = "SELECT count(w) FROM Widget w"),
-        @NamedQuery(name = "Widget.getByFreeText", query = "SELECT w FROM Widget w WHERE
lower(w.title) LIKE :searchTerm OR w.description LIKE :description"),
-        @NamedQuery(name = "Widget.countByFreeText", query = "SELECT count(w) FROM Widget
w WHERE lower(w.title) LIKE :searchTerm OR w.description LIKE :description")
+        @NamedQuery(name = Widget.WIDGET_GET_ALL, query = "SELECT w from Widget w"),
+        @NamedQuery(name = Widget.WIDGET_COUNT_ALL, query = "SELECT count(w) FROM Widget
w"),
+        @NamedQuery(name = Widget.WIDGET_GET_BY_FREE_TEXT,
+                query = "SELECT w FROM Widget w WHERE lower(w.title) LIKE :searchTerm OR
w.description LIKE :description"),
+        @NamedQuery(name = Widget.WIDGET_COUNT_BY_FREE_TEXT,
+                query = "SELECT count(w) FROM Widget w WHERE lower(w.title) LIKE :searchTerm
OR w.description LIKE :description"),
+
+        @NamedQuery(name = Widget.WIDGET_GET_BY_STATUS,
+                query = "SELECT w from Widget w WHERE w.widgetStatus = :widgetStatus"),
+        @NamedQuery(name = Widget.WIDGET_COUNT_BY_STATUS,
+                query = "SELECT count(w) FROM Widget w WHERE w.widgetStatus = :widgetStatus"),
+        @NamedQuery(name = Widget.WIDGET_GET_BY_STATUS_AND_FREE_TEXT,
+                query = "SELECT w FROM Widget w WHERE w.widgetStatus = :widgetStatus AND
lower(w.title) LIKE :searchTerm OR w.description LIKE :description"),
+        @NamedQuery(name = Widget.WIDGET_COUNT_BY_STATUS_AND_FREE_TEXT,
+                query = "SELECT count(w) FROM Widget w WHERE w.widgetStatus = :widgetStatus
AND lower(w.title) LIKE :searchTerm OR w.description LIKE :description")
+
 })
 public class Widget implements BasicEntity, Serializable {
     private static final long serialVersionUID = 1L;
-    
+
+    public static final String PARAM_SEARCH_TERM = "searchTerm";
+    public static final String PARAM_STATUS = "widgetStatus";
+
+    public static final String WIDGET_GET_ALL = "Widget.getAll";
+    public static final String WIDGET_COUNT_ALL = "Widget.countAll";
+    public static final String WIDGET_GET_BY_FREE_TEXT = "Widget.getByFreeText";
+    public static final String WIDGET_COUNT_BY_FREE_TEXT = "Widget.countByFreeText";
+    public static final String WIDGET_GET_BY_STATUS = "Widget.getByStatus";
+    public static final String WIDGET_COUNT_BY_STATUS = "Widget.countByStatus";
+    public static final String WIDGET_GET_BY_STATUS_AND_FREE_TEXT =
+            "Widget.getByStatusAndFreeText";
+    public static final String WIDGET_COUNT_BY_STATUS_AND_FREE_TEXT =
+            "Widget.countByStatusAndFreeText";
+
     @Id @Column(name="id")
     @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "widgetIdSeq")
     private Long id;
@@ -78,6 +106,11 @@ public class Widget implements BasicEnti
     @Basic @Column(name = "description")
     private String description;
 
+    @Basic @Column(name = "widget_status")
+    @Enumerated(EnumType.STRING)
+    private WidgetStatus widgetStatus;
+
+
     public Widget() {
     }
 
@@ -167,6 +200,14 @@ public class Widget implements BasicEnti
         this.url = url;
     }
 
+    public WidgetStatus getWidgetStatus() {
+        return widgetStatus;
+    }
+
+    public void setWidgetStatus(WidgetStatus widgetStatus) {
+        this.widgetStatus = widgetStatus;
+    }
+
     @Override
     public boolean equals(Object obj) {
         if (obj == null) {
@@ -191,6 +232,16 @@ public class Widget implements BasicEnti
 
     @Override
     public String toString() {
-        return "Widget{" + "id=" + id + ", title=" + title + ", url=" + url + ", thumbnailUrl="
+ thumbnailUrl + ", screenshotUrl=" + screenshotUrl + ", type=" + type + ", author=" + author
+ ", description=" + description + '}';
+        return "Widget{" +
+                "id=" + id +
+                ", title='" + title + '\'' +
+                ", url='" + url + '\'' +
+                ", thumbnailUrl='" + thumbnailUrl + '\'' +
+                ", screenshotUrl='" + screenshotUrl + '\'' +
+                ", type='" + type + '\'' +
+                ", author='" + author + '\'' +
+                ", description='" + description + '\'' +
+                ", widgetStatus=" + widgetStatus +
+                '}';
     }
 }
\ No newline at end of file

Added: incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/model/WidgetStatus.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/model/WidgetStatus.java?rev=1160600&view=auto
==============================================================================
--- incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/model/WidgetStatus.java
(added)
+++ incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/model/WidgetStatus.java
Tue Aug 23 09:52:12 2011
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.rave.portal.model;
+
+/**
+ * (Workflow) status of a Widget.
+ */
+public enum WidgetStatus {
+    PUBLISHED("published"),
+    PREVIEW("preview");
+
+    private String widgetStatus;
+
+    WidgetStatus(String widgetStatus) {
+        this.widgetStatus = widgetStatus;
+    }
+
+    public String getWidgetStatus() {
+        return widgetStatus;
+    }
+
+    @Override
+    public String toString() {
+        return widgetStatus;
+    }
+}

Modified: incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/repository/WidgetRepository.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/repository/WidgetRepository.java?rev=1160600&r1=1160599&r2=1160600&view=diff
==============================================================================
--- incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/repository/WidgetRepository.java
(original)
+++ incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/repository/WidgetRepository.java
Tue Aug 23 09:52:12 2011
@@ -22,6 +22,7 @@ import java.util.List;
 
 import org.apache.rave.persistence.Repository;
 import org.apache.rave.portal.model.Widget;
+import org.apache.rave.portal.model.WidgetStatus;
 
 public interface WidgetRepository extends Repository<Widget> {
     /**
@@ -64,4 +65,44 @@ public interface WidgetRepository extend
      */
     int getCountFreeTextSearch(String searchTerm);
 
+    /**
+     * Gets a List of {@link Widget}'s in the repository by {@link WidgetStatus}
+     *
+     * @param widgetStatus status of the widget (PREVIEW, PUBLISHED etc)
+     * @param offset       start point within the total resultset
+     * @param pageSize     maximum number of items to be returned (for paging)
+     * @return valid list of widgets, can be empty
+     */
+    List<Widget> getByStatus(WidgetStatus widgetStatus, int offset, int pageSize);
+
+    /**
+     * Counts the total number of {@link Widget}'s filtering on status. Useful for paging.
+     *
+     * @param widgetStatus status of the widget (PREVIEW, PUBLISHED etc)
+     * @return total number of {@link Widget}'s that match the search term
+     */
+    int getCountByStatus(WidgetStatus widgetStatus);
+
+    /**
+     * Gets a List of {@link Widget}'s by performing a free text search filtering on status
+     *
+     * @param widgetStatus status of the widget (PREVIEW, PUBLISHED etc)
+     * @param searchTerm   free text search term
+     * @param offset       start point within the resultset (for paging)
+     * @param pageSize     maximum number of items to be returned (for paging)
+     * @return valid list of widgets, can be empty
+     */
+    List<Widget> getByStatusAndFreeTextSearch(WidgetStatus widgetStatus, String searchTerm,
+                                              int offset, int pageSize);
+
+
+    /**
+     * Counts the total number of {@link Widget}'s by performing a free text search filtering
+     * on status. Useful for paging.
+     *
+     * @param widgetStatus status of the widget (PREVIEW, PUBLISHED etc)
+     * @param searchTerm   free text search term
+     * @return total number of {@link Widget}'s that match the search criteria
+     */
+    int getCountByStatusAndFreeText(WidgetStatus widgetStatus, String searchTerm);
 }
\ No newline at end of file

Modified: incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/repository/impl/JpaWidgetRepository.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/repository/impl/JpaWidgetRepository.java?rev=1160600&r1=1160599&r2=1160600&view=diff
==============================================================================
--- incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/repository/impl/JpaWidgetRepository.java
(original)
+++ incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/repository/impl/JpaWidgetRepository.java
Tue Aug 23 09:52:12 2011
@@ -27,6 +27,7 @@ import javax.persistence.TypedQuery;
 
 import org.apache.rave.persistence.jpa.AbstractJpaRepository;
 import org.apache.rave.portal.model.Widget;
+import org.apache.rave.portal.model.WidgetStatus;
 import org.apache.rave.portal.repository.WidgetRepository;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -46,32 +47,84 @@ public class JpaWidgetRepository extends
     @Override
     public List<Widget> getAll() {
         log.warn("Requesting potentially large resultset of Widget. No pagesize set.");
-        TypedQuery<Widget> query = manager.createNamedQuery("Widget.getAll", Widget.class);
+        TypedQuery<Widget> query = manager.createNamedQuery(Widget.WIDGET_GET_ALL,
Widget.class);
         return query.getResultList();
     }
 
     @Override
     public List<Widget> getLimitedList(int offset, int pageSize) {
-        TypedQuery<Widget> query = manager.createNamedQuery("Widget.getAll", Widget.class);
-        query.setFirstResult(offset);
-        if (pageSize >= LARGE_PAGESIZE) {
-            log.warn("Requesting potentially large resultset of Widgets. Pagesize is {}",
pageSize);
-        }
-        query.setMaxResults(pageSize);
-        return query.getResultList();
+        TypedQuery<Widget> query = manager.createNamedQuery(Widget.WIDGET_GET_ALL,
Widget.class);
+        return getPagedResult(query, offset, pageSize);
     }
 
     @Override
     public int getCountAll() {
-        Query query = manager.createNamedQuery("Widget.countAll");
+        Query query = manager.createNamedQuery(Widget.WIDGET_COUNT_ALL);
         Number countResult = (Number) query.getSingleResult();
         return countResult.intValue();
     }
 
     @Override
     public List<Widget> getByFreeTextSearch(String searchTerm, int offset, int pageSize)
{
-        TypedQuery<Widget> query = manager.createNamedQuery("Widget.getByFreeText",
Widget.class);
-        query.setParameter("searchTerm", "%" + searchTerm.toLowerCase() + "%");
+        TypedQuery<Widget> query = manager.createNamedQuery(Widget.WIDGET_GET_BY_FREE_TEXT,
+                Widget.class);
+        setFreeTextSearchTerm(query, searchTerm);
+        return getPagedResult(query, offset, pageSize);
+    }
+
+    @Override
+    public int getCountFreeTextSearch(String searchTerm) {
+        Query query = manager.createNamedQuery(Widget.WIDGET_COUNT_BY_FREE_TEXT);
+        setFreeTextSearchTerm(query, searchTerm);
+        Number countResult = (Number) query.getSingleResult();
+        return countResult.intValue();
+    }
+
+    @Override
+    public List<Widget> getByStatus(WidgetStatus widgetStatus, int offset, int pageSize)
{
+        TypedQuery<Widget> query = manager.createNamedQuery(Widget.WIDGET_GET_BY_STATUS,
+                Widget.class);
+        query.setParameter(Widget.PARAM_STATUS, widgetStatus);
+        return getPagedResult(query, offset, pageSize);
+    }
+
+    @Override
+    public int getCountByStatus(WidgetStatus widgetStatus) {
+        Query query = manager.createNamedQuery(Widget.WIDGET_COUNT_BY_STATUS);
+        query.setParameter(Widget.PARAM_STATUS, widgetStatus);
+        Number countResult = (Number) query.getSingleResult();
+        return countResult.intValue();
+    }
+
+    @Override
+    public List<Widget> getByStatusAndFreeTextSearch(WidgetStatus widgetStatus, String
searchTerm,
+                                                     int offset, int pageSize) {
+        TypedQuery<Widget> query = manager.createNamedQuery(
+                Widget.WIDGET_GET_BY_STATUS_AND_FREE_TEXT, Widget.class);
+        query.setParameter(Widget.PARAM_STATUS, widgetStatus);
+        setFreeTextSearchTerm(query, searchTerm);
+        return getPagedResult(query, offset, pageSize);
+    }
+
+    @Override
+    public int getCountByStatusAndFreeText(WidgetStatus widgetStatus, String searchTerm)
{
+        Query query = manager.createNamedQuery(Widget.WIDGET_COUNT_BY_STATUS_AND_FREE_TEXT);
+        query.setParameter(Widget.PARAM_STATUS, widgetStatus);
+        setFreeTextSearchTerm(query, searchTerm);
+        Number countResult = (Number) query.getSingleResult();
+        return countResult.intValue();
+    }
+
+
+    /**
+     * Performs a query with a limit and offset
+     *
+     * @param query    {@link TypedQuery}
+     * @param offset   start point within the resultset (for paging)
+     * @param pageSize maximum number of items to be returned
+     * @return valid list of widgets, can be empty
+     */
+    protected List<Widget> getPagedResult(TypedQuery<Widget> query, int offset,
int pageSize) {
         if (pageSize >= LARGE_PAGESIZE) {
             log.warn("Requesting potentially large resultset of Widgets. Pagesize is {}",
pageSize);
         }
@@ -80,11 +133,13 @@ public class JpaWidgetRepository extends
         return query.getResultList();
     }
 
-    @Override
-    public int getCountFreeTextSearch(String searchTerm) {
-        Query query = manager.createNamedQuery("Widget.countByFreeText");
-        query.setParameter("searchTerm", "%" + searchTerm.toLowerCase() + "%");
-        Number countResult = (Number) query.getSingleResult();
-        return countResult.intValue();
+    /**
+     * Sets input as free text search term to a query
+     *
+     * @param query      {@link javax.persistence.Query}
+     * @param searchTerm free text
+     */
+    protected void setFreeTextSearchTerm(Query query, final String searchTerm) {
+        query.setParameter(Widget.PARAM_SEARCH_TERM, "%" + searchTerm.toLowerCase() + "%");
     }
 }

Modified: incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/service/WidgetService.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/service/WidgetService.java?rev=1160600&r1=1160599&r2=1160600&view=diff
==============================================================================
--- incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/service/WidgetService.java
(original)
+++ incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/service/WidgetService.java
Tue Aug 23 09:52:12 2011
@@ -38,10 +38,11 @@ public interface WidgetService {
 
 
     /**
-     * Gets a limited {@link SearchResult} for {@link Widget}'s  that a user can add to their
context.
+     * Gets a limited {@link SearchResult} for {@link Widget}'s that a user can add to their
+     * context.
      *
-     * @param offset start point within the resultset (for paging)
-     * @param pageSize   maximum number of items to be returned (for paging)
+     * @param offset   start point within the resultset (for paging)
+     * @param pageSize maximum number of items to be returned (for paging)
      * @return SearchResult
      */
     SearchResult<Widget> getLimitedListOfWidgets(int offset, int pageSize);
@@ -63,4 +64,24 @@ public interface WidgetService {
      * @return a valid widget if one exists for the given id; null otherwise
      */
     Widget getWidget(long id);
+
+    /**
+     * Gets a {@link SearchResult} for {@link Widget}'s that are published
+     *
+     * @param offset   start point within the resultset (for paging)
+     * @param pageSize maximum number of items to be returned (for paging)
+     * @return SearchResult
+     */
+    SearchResult<Widget> getPublishedWidgets(int offset, int pageSize);
+
+    /**
+     * Gets a SearchResult for published {@link Widget}'s by performing a free text search
+     *
+     * @param searchTerm free text search term
+     * @param offset     start point within the resultset (for paging)
+     * @param pageSize   maximum number of items to be returned (for paging)
+     * @return SearchResult
+     */
+    SearchResult<Widget> getPublishedWidgetsByFreeTextSearch(String searchTerm,
+                                                             int offset, int pageSize);
 }

Modified: incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/service/impl/DefaultWidgetService.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/service/impl/DefaultWidgetService.java?rev=1160600&r1=1160599&r2=1160600&view=diff
==============================================================================
--- incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/service/impl/DefaultWidgetService.java
(original)
+++ incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/service/impl/DefaultWidgetService.java
Tue Aug 23 09:52:12 2011
@@ -23,6 +23,7 @@ import java.util.List;
 
 import org.apache.commons.lang.StringUtils;
 import org.apache.rave.portal.model.Widget;
+import org.apache.rave.portal.model.WidgetStatus;
 import org.apache.rave.portal.model.util.SearchResult;
 import org.apache.rave.portal.repository.WidgetRepository;
 import org.apache.rave.portal.service.WidgetService;
@@ -56,13 +57,15 @@ public class DefaultWidgetService implem
     }
 
     @Override
-    public SearchResult<Widget> getWidgetsByFreeTextSearch(String searchTerm, int offset,
int pageSize) {
+    public SearchResult<Widget> getWidgetsByFreeTextSearch(String searchTerm,
+                                                           int offset, int pageSize) {
         if (StringUtils.isBlank(searchTerm)) {
             return getLimitedListOfWidgets(offset, pageSize);
         }
 
         final int count = widgetRepository.getCountFreeTextSearch(searchTerm);
-        final List<Widget>widgets = widgetRepository.getByFreeTextSearch(searchTerm,
offset, pageSize);
+        final List<Widget> widgets = widgetRepository.getByFreeTextSearch(searchTerm,
+                offset, pageSize);
 
         final SearchResult<Widget> searchResult = new SearchResult<Widget>(widgets,
count);
         searchResult.setPageSize(pageSize);
@@ -73,4 +76,32 @@ public class DefaultWidgetService implem
     public Widget getWidget(long id) {
         return widgetRepository.get(id);
     }
+
+    @Override
+    public SearchResult<Widget> getPublishedWidgets(int offset, int pageSize) {
+        final int count = widgetRepository.getCountByStatus(WidgetStatus.PUBLISHED);
+        final List<Widget> widgets = widgetRepository.getByStatus(WidgetStatus.PUBLISHED,
+                offset, pageSize);
+        final SearchResult<Widget> searchResult = new SearchResult<Widget>(widgets,
count);
+        searchResult.setPageSize(pageSize);
+        return searchResult;
+    }
+
+    @Override
+    public SearchResult<Widget> getPublishedWidgetsByFreeTextSearch(String searchTerm,
+                                                                    int offset, int pageSize)
{
+
+        if (StringUtils.isBlank(searchTerm)) {
+            return getPublishedWidgets(offset, pageSize);
+        }
+
+        final int count = widgetRepository.getCountByStatusAndFreeText(WidgetStatus.PUBLISHED,
+                searchTerm);
+        final List<Widget> widgets = widgetRepository.getByStatusAndFreeTextSearch(
+                WidgetStatus.PUBLISHED, searchTerm, offset, pageSize);
+
+        final SearchResult<Widget> searchResult = new SearchResult<Widget>(widgets,
count);
+        searchResult.setPageSize(pageSize);
+        return searchResult;
+    }
 }

Modified: incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/web/controller/WidgetStoreController.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/web/controller/WidgetStoreController.java?rev=1160600&r1=1160599&r2=1160600&view=diff
==============================================================================
--- incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/web/controller/WidgetStoreController.java
(original)
+++ incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/web/controller/WidgetStoreController.java
Tue Aug 23 09:52:12 2011
@@ -56,7 +56,7 @@ public class WidgetStoreController {
     public String view(Model model, @RequestParam long referringPageId,
                        @RequestParam(required = false, defaultValue = "0") int offset) {
         model.addAttribute(ModelKeys.WIDGETS,
-                widgetService.getLimitedListOfWidgets(offset, MAXIMUM_WIDGETS_PER_PAGE));
+                widgetService.getPublishedWidgets(offset, MAXIMUM_WIDGETS_PER_PAGE));
         model.addAttribute(ModelKeys.REFERRING_PAGE_ID, referringPageId);
         return ViewNames.STORE;
     }
@@ -90,7 +90,7 @@ public class WidgetStoreController {
                                    @RequestParam String searchTerm,
                                    @RequestParam(required = false, defaultValue = "0") int
offset) {
         model.addAttribute(ModelKeys.WIDGETS,
-                widgetService.getWidgetsByFreeTextSearch(searchTerm, offset,
+                widgetService.getPublishedWidgetsByFreeTextSearch(searchTerm, offset,
                         MAXIMUM_WIDGETS_PER_PAGE));
         model.addAttribute(ModelKeys.REFERRING_PAGE_ID, referringPageId);
         model.addAttribute(ModelKeys.SEARCH_TERM, searchTerm);

Modified: incubator/rave/trunk/rave-portal/src/main/resources/initial_data.sql
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal/src/main/resources/initial_data.sql?rev=1160600&r1=1160599&r2=1160600&view=diff
==============================================================================
--- incubator/rave/trunk/rave-portal/src/main/resources/initial_data.sql (original)
+++ incubator/rave/trunk/rave-portal/src/main/resources/initial_data.sql Tue Aug 23 09:52:12
2011
@@ -58,29 +58,29 @@ values (set(@user_id_12, next value for 
 
 --- gadget data ---
 -- wikipedia widget
-insert into widget (id, title, url, type, description, author)
-values(set(@wikipedia_widget_id, next value for widget_id_seq), 'Wikipedia','http://www.widget-dico.com/wikipedia/google/wikipedia.xml',
'OpenSocial', 'A Wikipedia Search and Go widget. Language choice.', 'WidgetMe');
+insert into widget (id, title, url, type, description, author, widget_status)
+values(set(@wikipedia_widget_id, next value for widget_id_seq), 'Wikipedia','http://www.widget-dico.com/wikipedia/google/wikipedia.xml',
'OpenSocial', 'A Wikipedia Search and Go widget. Language choice.', 'WidgetMe', 'PUBLISHED');
 
 -- translate widget
-insert into widget (id, title, url, type, description, author)
-values(set(@translate_widget_id, next value for widget_id_seq), 'Translate Gadget', 'http://www.gstatic.com/ig/modules/dictionary/dictionary.xml','OpenSocial'
, 'Google Translation gadget.', 'Google Taiwan');
+insert into widget (id, title, url, type, description, author, widget_status)
+values(set(@translate_widget_id, next value for widget_id_seq), 'Translate Gadget', 'http://www.gstatic.com/ig/modules/dictionary/dictionary.xml','OpenSocial'
, 'Google Translation gadget.', 'Google Taiwan', 'PUBLISHED');
 
 -- nytimes widget
-insert into widget (id, title, url, type)
-values(set(@nyt_widget_id, next value for widget_id_seq), 'NYTimes.com - Top Stories', 'http://widgets.nytimes.com/packages/html/igoogle/topstories.xml',
'OpenSocial');
+insert into widget (id, title, url, type, widget_status)
+values(set(@nyt_widget_id, next value for widget_id_seq), 'NYTimes.com - Top Stories', 'http://widgets.nytimes.com/packages/html/igoogle/topstories.xml',
'OpenSocial', 'PUBLISHED');
 
 -- google tabbed news widget
-insert into widget (id, title, url, type)
-values(set(@tabnews_widget_id, next value for widget_id_seq), 'Google News Gadget', 'http://www.gstatic.com/ig/modules/tabnews/tabnews.xml',
'OpenSocial');
+insert into widget (id, title, url, type, widget_status)
+values(set(@tabnews_widget_id, next value for widget_id_seq), 'Google News Gadget', 'http://www.gstatic.com/ig/modules/tabnews/tabnews.xml',
'OpenSocial', 'PUBLISHED');
 -- end widget data ----
 
 -- hamster widget
-insert into widget (id, title, url, type)
-values(set(@hamster_widget_id, next value for widget_id_seq), 'Pet Hamster', 'http://hosting.gmodules.com/ig/gadgets/file/112581010116074801021/hamster.xml',
'OpenSocial');
+insert into widget (id, title, url, type, widget_status)
+values(set(@hamster_widget_id, next value for widget_id_seq), 'Pet Hamster', 'http://hosting.gmodules.com/ig/gadgets/file/112581010116074801021/hamster.xml',
'OpenSocial', 'PUBLISHED');
 
 -- slideshare widget
-insert into widget (id, title, url, type)
-values(set(@gifts_widget_id, next value for widget_id_seq), 'Gifts', 'http://opensocial-resources.googlecode.com/svn/samples/tutorial/tags/api-0.8/gifts_1_friends.xml',
'OpenSocial');
+insert into widget (id, title, url, type, widget_status)
+values(set(@gifts_widget_id, next value for widget_id_seq), 'Gifts', 'http://opensocial-resources.googlecode.com/svn/samples/tutorial/tags/api-0.8/gifts_1_friends.xml',
'OpenSocial', 'PUBLISHED');
 -- end widget data ----
 
 --- start page layout data ---

Added: incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/portal/model/WidgetTest.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/portal/model/WidgetTest.java?rev=1160600&view=auto
==============================================================================
--- incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/portal/model/WidgetTest.java
(added)
+++ incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/portal/model/WidgetTest.java
Tue Aug 23 09:52:12 2011
@@ -0,0 +1,84 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.rave.portal.model;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import static junit.framework.Assert.assertEquals;
+
+/**
+Test for {@link Widget}
+ */
+public class WidgetTest {
+    private Widget widget;
+    private Long id;
+    private String title;
+    private String url;
+    private String thumbnailUrl;
+    private String screenshotUrl;
+    private String type;
+    private String author;
+    private String description;
+    private WidgetStatus status;
+
+    @Before
+    public void setUp() throws Exception {
+        widget= new Widget();
+        id = 3511L;
+        title = "Test Widget";
+        url = "http://example.com/widget.xml";
+        thumbnailUrl = "http://example.com/widget_thumbnail.png";
+        screenshotUrl = "http://example.com/widget_screenshot.png";
+        type = "OpenSocial";
+        author = "John Doe";
+        description = "This is a test widget";
+        status = WidgetStatus.PREVIEW;
+
+        widget.setId(id);
+        widget.setTitle(title);
+        widget.setUrl(url);
+        widget.setThumbnailUrl(thumbnailUrl);
+        widget.setScreenshotUrl(screenshotUrl);
+        widget.setType(type);
+        widget.setAuthor(author);
+        widget.setDescription(description);
+        widget.setWidgetStatus(status);
+    }
+
+    @Test
+    public void testAccessorMethods() {
+        assertEquals(id, widget.getId());
+        assertEquals(title, widget.getTitle());
+        assertEquals(url, widget.getUrl());
+        assertEquals(thumbnailUrl, widget.getThumbnailUrl());
+        assertEquals(screenshotUrl, widget.getScreenshotUrl());
+        assertEquals(type, widget.getType());
+        assertEquals(author, widget.getAuthor());
+        assertEquals(description, widget.getDescription());
+        assertEquals(status, widget.getWidgetStatus());
+    }
+
+    @After
+    public void tearDown() throws Exception {
+        widget = null;
+    }
+}

Modified: incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/portal/repository/JpaWidgetRepositoryTest.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/portal/repository/JpaWidgetRepositoryTest.java?rev=1160600&r1=1160599&r2=1160600&view=diff
==============================================================================
--- incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/portal/repository/JpaWidgetRepositoryTest.java
(original)
+++ incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/portal/repository/JpaWidgetRepositoryTest.java
Tue Aug 23 09:52:12 2011
@@ -19,12 +19,14 @@
 
 package org.apache.rave.portal.repository;
 
+import java.util.ArrayList;
 import java.util.List;
 
 import javax.persistence.EntityManager;
 import javax.persistence.PersistenceContext;
 
 import org.apache.rave.portal.model.Widget;
+import org.apache.rave.portal.model.WidgetStatus;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -46,7 +48,8 @@ import static org.junit.Assert.assertTha
  */
 @Transactional
 @RunWith(SpringJUnit4ClassRunner.class)
-@ContextConfiguration(locations = {"classpath:portal-test-dataContext.xml", "classpath:portal-test-applicationContext.xml"})
+@ContextConfiguration(locations = {"classpath:portal-test-dataContext.xml",
+        "classpath:portal-test-applicationContext.xml"})
 public class JpaWidgetRepositoryTest {
 
     @PersistenceContext
@@ -100,4 +103,52 @@ public class JpaWidgetRepositoryTest {
         int count = repository.getCountAll();
         assertTrue(count > 4);
     }
+
+    @Test
+    public void getByStatus() {
+        final int pageSize = 999;
+        List<Widget> published = repository.getByStatus(WidgetStatus.PUBLISHED, 0,
pageSize);
+        assertNotNull(published);
+        assertTrue(published.size() > 0);
+
+        List<Widget> preview = repository.getByStatus(WidgetStatus.PREVIEW, 0, pageSize);
+        assertNotNull(preview);
+        assertTrue(preview.size() > 0);
+
+        List<Widget> shouldBeEmpty = new ArrayList<Widget>();
+        for (Widget previewWidget : preview) {
+            if (published.contains(previewWidget)) {
+                // should not happen
+                shouldBeEmpty.add(previewWidget);
+            }
+        }
+        assertEquals(0, shouldBeEmpty.size());
+    }
+
+    @Test
+    public void countByStatus() {
+        int publishedCount = repository.getCountByStatus(WidgetStatus.PUBLISHED);
+        assertTrue(publishedCount > 0);
+    }
+
+    @Test
+    public void getByStatusAndFreeText() {
+        final String searchTerm = "gAdGet";
+        List<Widget> widgets = repository.getByStatusAndFreeTextSearch(WidgetStatus.PUBLISHED,
+                searchTerm, 0, 1);
+        assertEquals(1, widgets.size());
+
+        List<Widget> preview = repository.getByStatusAndFreeTextSearch(WidgetStatus.PREVIEW,
+                searchTerm, 0, 1);
+        assertEquals(0, preview.size());
+    }
+
+    @Test
+    public void countByStatusAndFreeText() {
+        final String searchTerm = "gAdGet";
+        int publishedCount = repository.getCountByStatusAndFreeText(WidgetStatus.PUBLISHED,
+                searchTerm);
+        assertTrue(publishedCount >= 2);
+    }
+
 }

Modified: incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/portal/service/WidgetServiceTest.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/portal/service/WidgetServiceTest.java?rev=1160600&r1=1160599&r2=1160600&view=diff
==============================================================================
--- incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/portal/service/WidgetServiceTest.java
(original)
+++ incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/portal/service/WidgetServiceTest.java
Tue Aug 23 09:52:12 2011
@@ -23,6 +23,7 @@ import java.util.ArrayList;
 import java.util.List;
 
 import org.apache.rave.portal.model.Widget;
+import org.apache.rave.portal.model.WidgetStatus;
 import org.apache.rave.portal.model.util.SearchResult;
 import org.apache.rave.portal.repository.WidgetRepository;
 import org.apache.rave.portal.service.impl.DefaultWidgetService;
@@ -81,6 +82,24 @@ public class WidgetServiceTest {
     }
 
     @Test
+    public void getPublishedWidgets() {
+        Widget widget1 = new Widget(1L,"http://example.com/widget1.xml");
+        widget1.setWidgetStatus(WidgetStatus.PUBLISHED);
+        Widget widget2 = new Widget(2L,"http://example.com/widget2.xml");
+        widget2.setWidgetStatus(WidgetStatus.PUBLISHED);
+        List<Widget> widgets = new ArrayList<Widget>();
+        widgets.add(widget1);
+        widgets.add(widget2);
+        final int pageSize = 10;
+        expect(repository.getByStatus(WidgetStatus.PUBLISHED, 0, pageSize)).andReturn(widgets);
+        replay(repository);
+
+        SearchResult<Widget> result = service.getPublishedWidgets(0, pageSize);
+        assertEquals(pageSize, result.getPageSize());
+        assertSame(widgets, result.getResultSet());
+    }
+
+    @Test
     public void getWidget() {
         Widget w = new Widget();
         expect(repository.get(1L)).andReturn(w);
@@ -93,9 +112,9 @@ public class WidgetServiceTest {
 
     @Test
     public void getWidgetsForSearchTerm() {
-        String searchTerm = "gAdGet";
+        final String searchTerm = "gAdGet";
         int offset = 0;
-        int pagesize = 10;
+        int pageSize = 10;
         int totalResults = 2;
         Widget widget = new Widget();
         widget.setId(1L);
@@ -103,14 +122,39 @@ public class WidgetServiceTest {
         widgets.add(widget);
         
         expect(repository.getCountFreeTextSearch(searchTerm)).andReturn(totalResults);
-        expect(repository.getByFreeTextSearch(searchTerm, offset, pagesize)).andReturn(widgets);
+        expect(repository.getByFreeTextSearch(searchTerm, offset, pageSize)).andReturn(widgets);
         replay(repository);
 
-        SearchResult<Widget> result = service.getWidgetsByFreeTextSearch(searchTerm,
offset, pagesize);
+        SearchResult<Widget> result = service.getWidgetsByFreeTextSearch(searchTerm,
offset, pageSize);
         assertEquals(widget, result.getResultSet().get(0));
         assertEquals(totalResults, result.getTotalResults());
-        assertEquals(pagesize, result.getPageSize());
+        assertEquals(pageSize, result.getPageSize());
+    }
 
+
+    @Test
+    public void getPublishedWidgetsForSearchTerm() {
+        final String searchTerm = "gAdGet";
+        int offset = 0;
+        int pageSize = 10;
+        int totalResults = 2;
+        Widget widget = new Widget();
+        widget.setWidgetStatus(WidgetStatus.PUBLISHED);
+        widget.setId(1L);
+        List<Widget> widgets = new ArrayList<Widget>();
+        widgets.add(widget);
+
+        expect(repository.getCountByStatusAndFreeText(WidgetStatus.PUBLISHED, searchTerm))
+                .andReturn(totalResults);
+        expect(repository.getByStatusAndFreeTextSearch(WidgetStatus.PUBLISHED, searchTerm,
+                offset, pageSize)).andReturn(widgets);
+        replay(repository);
+
+        SearchResult<Widget> result = service.getPublishedWidgetsByFreeTextSearch(searchTerm,
+                offset, pageSize);
+        assertEquals(widget, result.getResultSet().get(0));
+        assertEquals(totalResults, result.getTotalResults());
+        assertEquals(pageSize, result.getPageSize());
     }
 
     @Test

Modified: incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/portal/web/controller/WidgetStoreControllerTest.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/portal/web/controller/WidgetStoreControllerTest.java?rev=1160600&r1=1160599&r2=1160600&view=diff
==============================================================================
--- incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/portal/web/controller/WidgetStoreControllerTest.java
(original)
+++ incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/portal/web/controller/WidgetStoreControllerTest.java
Tue Aug 23 09:52:12 2011
@@ -67,7 +67,7 @@ public class WidgetStoreControllerTest {
         List<Widget> widgets = new ArrayList<Widget>();
         SearchResult<Widget> emptyResult = new SearchResult<Widget>(widgets,
0);
 
-        expect(widgetService.getLimitedListOfWidgets(0, 10)).andReturn(emptyResult);
+        expect(widgetService.getPublishedWidgets(0, 10)).andReturn(emptyResult);
         replay(widgetService);
 
         String view = controller.view(model, REFERRER_ID, 0);
@@ -111,7 +111,8 @@ public class WidgetStoreControllerTest {
         SearchResult<Widget> result = new SearchResult<Widget>(widgets, totalResults);
         result.setPageSize(pagesize);
 
-        expect(widgetService.getWidgetsByFreeTextSearch(searchTerm, offset, pagesize)).andReturn(result);
+        expect(widgetService.getPublishedWidgetsByFreeTextSearch(searchTerm, offset, pagesize))
+                .andReturn(result);
         replay(widgetService);
 
         String view = controller.viewSearchResult(model,REFERRER_ID, searchTerm, offset);

Modified: incubator/rave/trunk/rave-portal/src/test/resources/portal-test-applicationContext.xml
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal/src/test/resources/portal-test-applicationContext.xml?rev=1160600&r1=1160599&r2=1160600&view=diff
==============================================================================
--- incubator/rave/trunk/rave-portal/src/test/resources/portal-test-applicationContext.xml
(original)
+++ incubator/rave/trunk/rave-portal/src/test/resources/portal-test-applicationContext.xml
Tue Aug 23 09:52:12 2011
@@ -58,6 +58,7 @@
         <property name="scriptLocations">
             <list>
                 <value>classpath:initial_data.sql</value>
+                <value>classpath:portal_test_data.sql</value>
             </list>
         </property>
     </bean>

Added: incubator/rave/trunk/rave-portal/src/test/resources/portal_test_data.sql
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal/src/test/resources/portal_test_data.sql?rev=1160600&view=auto
==============================================================================
--- incubator/rave/trunk/rave-portal/src/test/resources/portal_test_data.sql (added)
+++ incubator/rave/trunk/rave-portal/src/test/resources/portal_test_data.sql Tue Aug 23 09:52:12
2011
@@ -0,0 +1,22 @@
+ -- Licensed to the Apache Software Foundation (ASF) under one
+ -- or more contributor license agreements.  See the NOTICE file
+ -- distributed with this work for additional information
+ -- regarding copyright ownership.  The ASF licenses this file
+ -- to you under the Apache License, Version 2.0 (the
+ -- "License"); you may not use this file except in compliance
+ -- with the License.  You may obtain a copy of the License at
+
+ --   http://www.apache.org/licenses/LICENSE-2.0
+
+ -- Unless required by applicable law or agreed to in writing,
+ -- software distributed under the License is distributed on an
+ -- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ -- KIND, either express or implied.  See the License for the
+ -- specific language governing permissions and limitations
+ -- under the License.
+
+--- gadget data ---
+-- useless knowledge widget
+insert into widget (id, title, url, type, widget_status)
+values(set(@useless_knowledge_widget_id, next value for widget_id_seq), 'Useless Knowledge',
'http://www.great-goofy-gadgets.com/humor/uselessknowledge/uselessknowledge.xml', 'OpenSocial',
'PREVIEW');
+-- end widget data ----
\ No newline at end of file



Mime
View raw message