rave-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From carlu...@apache.org
Subject svn commit: r1244751 - in /incubator/rave/trunk/rave-components/rave-core/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/servi...
Date Wed, 15 Feb 2012 21:59:28 GMT
Author: carlucci
Date: Wed Feb 15 21:59:27 2012
New Revision: 1244751

URL: http://svn.apache.org/viewvc?rev=1244751&view=rev
Log:
Fixed logic of deleting a user.  There was a lot of cross-repository work happening in the UserRepository that has been moved to the UserService#deleteUser method.

Added:
    incubator/rave/trunk/rave-components/rave-core/src/test/java/org/apache/rave/portal/repository/impl/JpaWidgetCommentRepositoryTest.java
      - copied, changed from r1244603, incubator/rave/trunk/rave-components/rave-core/src/test/java/org/apache/rave/portal/repository/impl/JpaWidgetRatingRepositoryTest.java
Modified:
    incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/model/Page.java
    incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/model/Widget.java
    incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/model/WidgetComment.java
    incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/model/WidgetRating.java
    incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/repository/PageRepository.java
    incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/repository/UserRepository.java
    incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/repository/WidgetCommentRepository.java
    incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/repository/WidgetRatingRepository.java
    incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/repository/WidgetRepository.java
    incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/repository/impl/JpaPageRepository.java
    incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/repository/impl/JpaUserRepository.java
    incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/repository/impl/JpaWidgetCommentRepository.java
    incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/repository/impl/JpaWidgetRatingRepository.java
    incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/repository/impl/JpaWidgetRepository.java
    incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/service/PageService.java
    incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/service/WidgetCommentService.java
    incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/service/WidgetRatingService.java
    incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/service/impl/DefaultPageService.java
    incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/service/impl/DefaultUserService.java
    incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/service/impl/DefaultWidgetCommentService.java
    incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/service/impl/DefaultWidgetRatingService.java
    incubator/rave/trunk/rave-components/rave-core/src/test/java/org/apache/rave/portal/repository/impl/JpaPageRepositoryTest.java
    incubator/rave/trunk/rave-components/rave-core/src/test/java/org/apache/rave/portal/repository/impl/JpaUserRepositoryTest.java
    incubator/rave/trunk/rave-components/rave-core/src/test/java/org/apache/rave/portal/repository/impl/JpaWidgetRatingRepositoryTest.java
    incubator/rave/trunk/rave-components/rave-core/src/test/java/org/apache/rave/portal/repository/impl/JpaWidgetRepositoryTest.java
    incubator/rave/trunk/rave-components/rave-core/src/test/java/org/apache/rave/portal/service/impl/DefaultPageServiceTest.java
    incubator/rave/trunk/rave-components/rave-core/src/test/java/org/apache/rave/portal/service/impl/DefaultUserServiceTest.java
    incubator/rave/trunk/rave-components/rave-core/src/test/java/org/apache/rave/portal/service/impl/DefaultWidgetCommentServiceTest.java
    incubator/rave/trunk/rave-components/rave-core/src/test/java/org/apache/rave/portal/service/impl/DefaultWidgetRatingServiceTest.java

Modified: incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/model/Page.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/model/Page.java?rev=1244751&r1=1244750&r2=1244751&view=diff
==============================================================================
--- incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/model/Page.java (original)
+++ incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/model/Page.java Wed Feb 15 21:59:27 2012
@@ -46,13 +46,15 @@ import java.util.List;
 @XmlAccessorType(XmlAccessType.NONE)
 @Table(name="page", uniqueConstraints={@UniqueConstraint(columnNames={"owner_id","name"})})
 @NamedQueries({
-        @NamedQuery(name = Page.GET_BY_USER_ID_AND_PAGE_TYPE_ID, query="SELECT p FROM Page p WHERE p.owner.entityId = :userId and p.pageType.entityId = :pageTypeId ORDER BY p.renderSequence")
+        @NamedQuery(name = Page.GET_BY_USER_ID_AND_PAGE_TYPE_ID, query="SELECT p FROM Page p WHERE p.owner.entityId = :userId and p.pageType.entityId = :pageTypeId ORDER BY p.renderSequence"),
+        @NamedQuery(name = Page.DELETE_BY_USER_ID_AND_PAGE_TYPE_ID, query="DELETE FROM Page p WHERE p.owner.entityId = :userId and p.pageType.entityId = :pageTypeId")
 })
 @Access(AccessType.FIELD)
 public class Page implements BasicEntity, Serializable {
     private static final long serialVersionUID = 1L;
     
     public static final String GET_BY_USER_ID_AND_PAGE_TYPE_ID = "Page.getByUserIdAndPageTypeId";
+    public static final String DELETE_BY_USER_ID_AND_PAGE_TYPE_ID = "Page.deleteByUserIdAndPageTypeId";
      
     @XmlAttribute(name="id")
     @Id @Column(name="entity_id")

Modified: incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/model/Widget.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/model/Widget.java?rev=1244751&r1=1244750&r2=1244751&view=diff
==============================================================================
--- incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/model/Widget.java (original)
+++ incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/model/Widget.java Wed Feb 15 21:59:27 2012
@@ -55,7 +55,8 @@ import java.util.List;
         @NamedQuery(name = Widget.WIDGET_GET_BY_URL, query = Widget.SELECT_W_FROM_WIDGET_W + Widget.WHERE_CLAUSE_URL) ,
 
         @NamedQuery(name = Widget.WIDGET_GET_BY_TAG, query = Widget.SELECT_W_FROM_WIDGET_W + Widget.JOIN_TAGS+Widget.ORDER_BY_TITLE_ASC),
-        @NamedQuery(name = Widget.WIDGET_COUNT_BY_TAG, query = Widget.SELECT_COUNT_W_FROM_WIDGET_W + Widget.JOIN_TAGS)
+        @NamedQuery(name = Widget.WIDGET_COUNT_BY_TAG, query = Widget.SELECT_COUNT_W_FROM_WIDGET_W + Widget.JOIN_TAGS),
+        @NamedQuery(name = Widget.WIDGET_UNASSIGN_OWNER, query = "UPDATE Widget w SET w.owner = null WHERE w.owner.entityId = :owner")
 })
 public class Widget implements BasicEntity, Serializable {
     private static final long serialVersionUID = 1L;
@@ -77,6 +78,7 @@ public class Widget implements BasicEnti
     public static final String WIDGET_GET_BY_URL = "Widget.getByUrl";
     public static final String WIDGET_GET_BY_TAG = "Widget.getByTag";
     public static final String WIDGET_COUNT_BY_TAG = "Widget.countByTag";
+    public static final String WIDGET_UNASSIGN_OWNER = "Widget.unassignOwner";
 
     static final String SELECT_W_FROM_WIDGET_W = "SELECT w FROM Widget w ";
     static final String SELECT_COUNT_W_FROM_WIDGET_W = "SELECT count(w) FROM Widget w ";

Modified: incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/model/WidgetComment.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/model/WidgetComment.java?rev=1244751&r1=1244750&r2=1244751&view=diff
==============================================================================
--- incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/model/WidgetComment.java (original)
+++ incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/model/WidgetComment.java Wed Feb 15 21:59:27 2012
@@ -17,19 +17,7 @@ package org.apache.rave.portal.model;
 
 import org.apache.rave.persistence.BasicEntity;
 
-import javax.persistence.Basic;
-import javax.persistence.Column;
-import javax.persistence.Entity;
-import javax.persistence.FetchType;
-import javax.persistence.GeneratedValue;
-import javax.persistence.GenerationType;
-import javax.persistence.Id;
-import javax.persistence.JoinColumn;
-import javax.persistence.Lob;
-import javax.persistence.OneToOne;
-import javax.persistence.Table;
-import javax.persistence.TableGenerator;
-import javax.persistence.Temporal;
+import javax.persistence.*;
 import javax.xml.bind.annotation.XmlRootElement;
 import java.io.Serializable;
 import java.util.Date;
@@ -39,9 +27,13 @@ import java.util.Date;
  */
 @Entity
 @Table(name = "widget_comment")
+@NamedQueries({
+        @NamedQuery(name = WidgetComment.DELETE_ALL_BY_USER,
+                query="DELETE FROM WidgetComment wc WHERE wc.user.entityId = :userId")
+})
 @XmlRootElement
 public class WidgetComment implements BasicEntity, Serializable {
-
+    public static final String DELETE_ALL_BY_USER = "WidgetComment.deleteAllByUserId";
 
     @Id
     @Column(name = "entity_id")

Modified: incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/model/WidgetRating.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/model/WidgetRating.java?rev=1244751&r1=1244750&r2=1244751&view=diff
==============================================================================
--- incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/model/WidgetRating.java (original)
+++ incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/model/WidgetRating.java Wed Feb 15 21:59:27 2012
@@ -52,7 +52,9 @@ import java.io.Serializable;
         @NamedQuery(name = WidgetRating.WIDGET_RATING_BY_WIDGET_AND_USER,
                 query = "SELECT wr FROM WidgetRating wr WHERE wr.widgetId = :widgetId AND wr.userId = :userId"),
         @NamedQuery(name = WidgetRating.WIDGET_USER_RATING,
-                query = "SELECT wr.score FROM WidgetRating wr WHERE wr.widgetId = :widgetId AND wr.userId = :userId")
+                query = "SELECT wr.score FROM WidgetRating wr WHERE wr.widgetId = :widgetId AND wr.userId = :userId"),
+        @NamedQuery(name = WidgetRating.DELETE_ALL_BY_USER,
+                query="DELETE FROM WidgetRating wr WHERE wr.userId = :userId")
 })
 @XmlRootElement
 public class WidgetRating implements BasicEntity, Serializable {
@@ -64,6 +66,7 @@ public class WidgetRating implements Bas
     public static final String WIDGET_ALL_USER_RATINGS = "widget_all_user_ratings";
     public static final String WIDGET_RATING_BY_WIDGET_AND_USER = "widget_rating_by_widget_and_user";
     public static final String WIDGET_USER_RATING = "widget_user_rating";
+    public static final String DELETE_ALL_BY_USER = "delete_all_for_user";
 
     public static final String PARAM_WIDGET_ID = "widgetId";
     public static final String PARAM_USER_ID = "userId";

Modified: incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/repository/PageRepository.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/repository/PageRepository.java?rev=1244751&r1=1244750&r2=1244751&view=diff
==============================================================================
--- incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/repository/PageRepository.java (original)
+++ incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/repository/PageRepository.java Wed Feb 15 21:59:27 2012
@@ -36,4 +36,12 @@ public interface PageRepository extends 
      * @return a list of all the Page objects owned by userId of type pageTypeId
      */
     List<Page> getAllPages(Long userId, Long pageTypeId);
+
+    /**
+     * Delete all pages for a userId of the supplied pageTypeId
+     * @param userId
+     * @param pageTypeId
+     * @return the number of pages deleted
+     */
+    int deletePages(Long userId, Long pageTypeId);
 }
\ No newline at end of file

Modified: incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/repository/UserRepository.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/repository/UserRepository.java?rev=1244751&r1=1244750&r2=1244751&view=diff
==============================================================================
--- incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/repository/UserRepository.java (original)
+++ incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/repository/UserRepository.java Wed Feb 15 21:59:27 2012
@@ -74,13 +74,6 @@ public interface UserRepository extends 
     int getCountByUsernameOrEmail(String searchTerm);
 
     /**
-     * Deletes the User and all its trails in the database
-     *
-     * @param user {@link User} to delete
-     */
-    void removeUser(User user);
-
-    /**
      * List of users whom have added the supplied widget to one or more pages
      *
      * @param widgetId the entityId of the Widget to search

Modified: incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/repository/WidgetCommentRepository.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/repository/WidgetCommentRepository.java?rev=1244751&r1=1244750&r2=1244751&view=diff
==============================================================================
--- incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/repository/WidgetCommentRepository.java (original)
+++ incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/repository/WidgetCommentRepository.java Wed Feb 15 21:59:27 2012
@@ -18,10 +18,12 @@ package org.apache.rave.portal.repositor
 import org.apache.rave.persistence.Repository;
 import org.apache.rave.portal.model.WidgetComment;
 
-/**
- *
- * @author ISIS
- */
 public interface WidgetCommentRepository extends Repository<WidgetComment> {
-    
+    /**
+     * Delete all Widget Comments for a userId
+     *
+     * @param userId
+     * @return count of comments deleted
+     */
+    int deleteAll(Long userId);
 }

Modified: incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/repository/WidgetRatingRepository.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/repository/WidgetRatingRepository.java?rev=1244751&r1=1244750&r2=1244751&view=diff
==============================================================================
--- incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/repository/WidgetRatingRepository.java (original)
+++ incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/repository/WidgetRatingRepository.java Wed Feb 15 21:59:27 2012
@@ -32,4 +32,12 @@ public interface WidgetRatingRepository 
      * @return {@link WidgetRating} if it exists, otherwise {@literal null}
      */
     WidgetRating getByWidgetIdAndUserId(Long widgetId, Long userId);
+
+    /**
+     * Delete all Widget Ratings for a userId
+     *
+     * @param userId
+     * @return count of ratings deleted
+     */
+    int deleteAll(Long userId);
 }

Modified: incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/repository/WidgetRepository.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/repository/WidgetRepository.java?rev=1244751&r1=1244750&r2=1244751&view=diff
==============================================================================
--- incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/repository/WidgetRepository.java (original)
+++ incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/repository/WidgetRepository.java Wed Feb 15 21:59:27 2012
@@ -168,4 +168,11 @@ public interface WidgetRepository extend
      */
      int getCountByTag(String tagKeyword);
 
+    /**
+     * Sets the widget owner to null for any widgets owned by the supplied userId
+     *
+     * @param userId the widget owner to unassign
+     * @return the number of widgets updated
+     */
+     int unassignWidgetOwner(long userId);
 }
\ No newline at end of file

Modified: incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/repository/impl/JpaPageRepository.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/repository/impl/JpaPageRepository.java?rev=1244751&r1=1244750&r2=1244751&view=diff
==============================================================================
--- incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/repository/impl/JpaPageRepository.java (original)
+++ incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/repository/impl/JpaPageRepository.java Wed Feb 15 21:59:27 2012
@@ -24,6 +24,7 @@ import org.apache.rave.portal.model.Page
 import org.apache.rave.portal.model.PageType;
 import org.apache.rave.portal.repository.PageRepository;
 import org.springframework.stereotype.Repository;
+import org.springframework.transaction.annotation.Transactional;
 
 import javax.persistence.TypedQuery;
 import java.util.List;
@@ -42,4 +43,12 @@ public class JpaPageRepository extends A
         query.setParameter("pageTypeId", pageTypeId);
         return query.getResultList();
     }
+
+    @Override
+    public int deletePages(Long userId, Long pageTypeId) {
+        TypedQuery<Page> query = manager.createNamedQuery(Page.DELETE_BY_USER_ID_AND_PAGE_TYPE_ID, Page.class);
+        query.setParameter("userId", userId);
+        query.setParameter("pageTypeId", pageTypeId);
+        return query.executeUpdate();
+    }
 }
\ No newline at end of file

Modified: incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/repository/impl/JpaUserRepository.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/repository/impl/JpaUserRepository.java?rev=1244751&r1=1244750&r2=1244751&view=diff
==============================================================================
--- incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/repository/impl/JpaUserRepository.java (original)
+++ incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/repository/impl/JpaUserRepository.java Wed Feb 15 21:59:27 2012
@@ -86,59 +86,9 @@ public class JpaUserRepository extends A
     }
 
     @Override
-    public void removeUser(User user) {
-        // TODO: this logic should not be here - it should be in the deleteUser service method so we can utilize
-        // the other model object's repositories instead of accessing other models from this repository
-        deletePages(user);
-        deleteWidgetComments(user);
-        deleteWidgetRatings(user);
-        removeUserFromWidget(user);
-
-        this.delete(user);
-    }
-
-    @Override
     public List<User> getAllByAddedWidget(long widgetId) {
         TypedQuery<User> query = manager.createNamedQuery(User.USER_GET_ALL_FOR_ADDED_WIDGET, User.class);
         query.setParameter(User.PARAM_WIDGET_ID, widgetId);
         return query.getResultList();
     }
-
-    private void deletePages(User user) {
-        TypedQuery<Page> pageQuery = manager.createNamedQuery(Page.GET_BY_USER_ID_AND_PAGE_TYPE_ID, Page.class);
-        pageQuery.setParameter("userId", user.getEntityId());
-        // TODO unhardcode this
-        pageQuery.setParameter("pageTypeId", 1L);
-        final List<Page> resultList = pageQuery.getResultList();
-        for (Page p : resultList) {
-            // removing Page removes Region removes RegionWidget removes RegionWidgetPreference
-            manager.remove(p);
-        }
-    }
-
-    private void deleteWidgetRatings(User user) {
-        TypedQuery<WidgetRating> widgetRatingQuery = manager.createNamedQuery(WidgetRating.WIDGET_ALL_USER_RATINGS,
-                WidgetRating.class);
-        widgetRatingQuery.setParameter(WidgetRating.PARAM_USER_ID, user.getEntityId());
-        final List<WidgetRating> resultList = widgetRatingQuery.getResultList();
-        for (WidgetRating widgetRating : resultList) {
-            manager.remove(widgetRating);
-        }
-    }
-
-    private void deleteWidgetComments(User user) {
-        TypedQuery<WidgetComment>widgetCommentQuery =
-                manager.createQuery("SELECT wc FROM WidgetComment wc WHERE wc.user = :user", WidgetComment.class);
-        widgetCommentQuery.setParameter("user", user);
-        final List<WidgetComment> resultList = widgetCommentQuery.getResultList();
-        for (WidgetComment widgetComment : resultList) {
-            manager.remove(widgetComment);
-        }
-    }
-
-    private void removeUserFromWidget(User user) {
-        Query query = manager.createQuery("UPDATE Widget w SET w.owner = null WHERE w.owner = :user");
-        query.setParameter("user", user);
-        query.executeUpdate();
-    }
 }

Modified: incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/repository/impl/JpaWidgetCommentRepository.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/repository/impl/JpaWidgetCommentRepository.java?rev=1244751&r1=1244750&r2=1244751&view=diff
==============================================================================
--- incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/repository/impl/JpaWidgetCommentRepository.java (original)
+++ incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/repository/impl/JpaWidgetCommentRepository.java Wed Feb 15 21:59:27 2012
@@ -20,10 +20,19 @@ import org.apache.rave.portal.model.Widg
 import org.apache.rave.portal.repository.WidgetCommentRepository;
 import org.springframework.stereotype.Repository;
 
+import javax.persistence.TypedQuery;
+
 @Repository
 public class JpaWidgetCommentRepository extends AbstractJpaRepository<WidgetComment> implements WidgetCommentRepository {
     
-    JpaWidgetCommentRepository() {
+    public JpaWidgetCommentRepository() {
         super(WidgetComment.class);
     }
+
+    @Override
+    public int deleteAll(Long userId) {
+        TypedQuery<WidgetComment> query = manager.createNamedQuery(WidgetComment.DELETE_ALL_BY_USER, WidgetComment.class);
+        query.setParameter("userId", userId);
+        return query.executeUpdate();
+    }
 }

Modified: incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/repository/impl/JpaWidgetRatingRepository.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/repository/impl/JpaWidgetRatingRepository.java?rev=1244751&r1=1244750&r2=1244751&view=diff
==============================================================================
--- incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/repository/impl/JpaWidgetRatingRepository.java (original)
+++ incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/repository/impl/JpaWidgetRatingRepository.java Wed Feb 15 21:59:27 2012
@@ -35,7 +35,7 @@ import static org.apache.rave.persistenc
 @Repository
 public class JpaWidgetRatingRepository extends AbstractJpaRepository<WidgetRating> implements WidgetRatingRepository {
 
-    protected JpaWidgetRatingRepository() {
+    public JpaWidgetRatingRepository() {
         super(WidgetRating.class);
     }
 
@@ -48,4 +48,11 @@ public class JpaWidgetRatingRepository e
         final List<WidgetRating> resultList = query.getResultList();
         return getSingleResult(resultList);
     }
-}
+
+    @Override
+    public int deleteAll(Long userId) {
+        TypedQuery<WidgetRating> query = manager.createNamedQuery(WidgetRating.DELETE_ALL_BY_USER, WidgetRating.class);
+        query.setParameter("userId", userId);
+        return query.executeUpdate();
+    }
+}
\ No newline at end of file

Modified: incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/repository/impl/JpaWidgetRepository.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/repository/impl/JpaWidgetRepository.java?rev=1244751&r1=1244750&r2=1244751&view=diff
==============================================================================
--- incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/repository/impl/JpaWidgetRepository.java (original)
+++ incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/repository/impl/JpaWidgetRepository.java Wed Feb 15 21:59:27 2012
@@ -270,6 +270,13 @@ public class JpaWidgetRepository extends
         return countResult.intValue();
     }
 
+    @Override
+    public int unassignWidgetOwner(long userId) {
+        Query query = manager.createNamedQuery(Widget.WIDGET_UNASSIGN_OWNER);
+        query.setParameter(Widget.PARAM_OWNER, userId);
+        return query.executeUpdate();
+    }
+
     /**
      * Sets input as free text search term to a query
      *

Modified: incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/service/PageService.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/service/PageService.java?rev=1244751&r1=1244750&r2=1244751&view=diff
==============================================================================
--- incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/service/PageService.java (original)
+++ incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/service/PageService.java Wed Feb 15 21:59:27 2012
@@ -19,6 +19,7 @@
 package org.apache.rave.portal.service;
 
 import org.apache.rave.portal.model.Page;
+import org.apache.rave.portal.model.PageType;
 import org.apache.rave.portal.model.Region;
 import org.apache.rave.portal.model.RegionWidget;
 
@@ -100,6 +101,15 @@ public interface PageService {
      */
     @PreAuthorize("hasPermission(#pageId, 'org.apache.rave.portal.model.Page', 'delete')") 
     void deletePage(long pageId);
+
+    /**
+     * Deletes all pages of the supplied pageTypeId for the userId
+     *
+     * @param userId
+     * @param pageTypeId
+     */
+    @PreAuthorize("hasPermission(new org.apache.rave.portal.security.impl.RaveSecurityContext(#userId, 'org.apache.rave.portal.model.User'), 'org.apache.rave.portal.model.Page', 'delete')")
+    int deletePages(long userId, long pageTypeId);
     
     /**
      * Moves a Region widget's position in a region or across regions
@@ -174,5 +184,19 @@ public interface PageService {
      * @return the updated Page object containing its new render sequence
      */
     @PreAuthorize("hasPermission(#pageId, 'org.apache.rave.portal.model.Page', 'update')") 
-    Page movePageToDefault(long pageId);  
+    Page movePageToDefault(long pageId);
+
+    /**
+     * Returns the PageType object representing User pages
+     *
+     * @return  the User PageType object
+     */
+    PageType getUserPageType();
+
+    /**
+     * Returns the PageType object representing Person Profile pages
+     *
+     * @return  the Person Profile PageType object
+     */
+    PageType getPersonProfilePageType();
 }
\ No newline at end of file

Modified: incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/service/WidgetCommentService.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/service/WidgetCommentService.java?rev=1244751&r1=1244750&r2=1244751&view=diff
==============================================================================
--- incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/service/WidgetCommentService.java (original)
+++ incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/service/WidgetCommentService.java Wed Feb 15 21:59:27 2012
@@ -30,4 +30,12 @@ public interface WidgetCommentService {
     @PreAuthorize("hasPermission(#id, 'org.apache.rave.portal.model.WidgetComment', 'delete')") 
     void removeWidgetComment(Long id);
 
+    /**
+     * Deletes all Widget Comments for a userId
+     *
+     * @param userId
+     * @return number of comments deleted
+     */
+    @PreAuthorize("hasPermission(new org.apache.rave.portal.security.impl.RaveSecurityContext(#userId, 'org.apache.rave.portal.model.User'), 'org.apache.rave.portal.model.WidgetComment', 'delete')")
+    int deleteAll(Long userId);
 }

Modified: incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/service/WidgetRatingService.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/service/WidgetRatingService.java?rev=1244751&r1=1244750&r2=1244751&view=diff
==============================================================================
--- incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/service/WidgetRatingService.java (original)
+++ incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/service/WidgetRatingService.java Wed Feb 15 21:59:27 2012
@@ -63,4 +63,12 @@ public interface WidgetRatingService {
     @PreAuthorize("hasPermission(new org.apache.rave.portal.security.impl.RaveSecurityContext(#userId, 'org.apache.rave.portal.model.User'), 'org.apache.rave.portal.model.WidgetRating', 'delete')")
     void removeWidgetRating(Long widgetId, Long userId);
 
+    /**
+     * Removes all widget ratings for a userId, for all widgets
+     *
+     * @param userId
+     * @return the number of widget ratings deleted
+     */
+    @PreAuthorize("hasPermission(new org.apache.rave.portal.security.impl.RaveSecurityContext(#userId, 'org.apache.rave.portal.model.User'), 'org.apache.rave.portal.model.WidgetRating', 'delete')")
+    int removeAllWidgetRatings(Long userId);
 }

Modified: incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/service/impl/DefaultPageService.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/service/impl/DefaultPageService.java?rev=1244751&r1=1244750&r2=1244751&view=diff
==============================================================================
--- incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/service/impl/DefaultPageService.java (original)
+++ incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/service/impl/DefaultPageService.java Wed Feb 15 21:59:27 2012
@@ -20,12 +20,7 @@
 package org.apache.rave.portal.service.impl;
 
 import org.apache.rave.persistence.Repository;
-import org.apache.rave.portal.model.Page;
-import org.apache.rave.portal.model.PageLayout;
-import org.apache.rave.portal.model.Region;
-import org.apache.rave.portal.model.RegionWidget;
-import org.apache.rave.portal.model.User;
-import org.apache.rave.portal.model.Widget;
+import org.apache.rave.portal.model.*;
 import org.apache.rave.portal.repository.*;
 import org.apache.rave.portal.service.PageService;
 import org.apache.rave.portal.service.UserService;
@@ -127,7 +122,13 @@ public class DefaultPageService implemen
         //TODO RAVE-237:  return values in the correct order.  We only need to update sequences when there is a change in order
         List<Page> pages = pageRepository.getAllPages(user.getEntityId(), USER_PAGE_TYPE_ID);
         updatePageRenderSequences(pages);
-    }    
+    }
+
+    @Override
+    @Transactional
+    public int deletePages(long userId, long pageTypeId) {
+        return pageRepository.deletePages(userId, pageTypeId);
+    }
     
     @Override
     @Transactional
@@ -192,6 +193,16 @@ public class DefaultPageService implemen
     }
 
     @Override
+    public PageType getUserPageType() {
+        return pageTypeRepository.getUserPageType();
+    }
+
+    @Override
+    public PageType getPersonProfilePageType() {
+        return pageTypeRepository.getPersonProfilePageType();
+    }
+
+    @Override
     @Transactional
     public Page updatePage(long pageId, String name, String pageLayoutCode) {
         Page page = pageRepository.get(pageId);
@@ -343,7 +354,7 @@ public class DefaultPageService implemen
         page.setRenderSequence(renderSequence);
         page.setRegions(regions);
         // set this as a "user" page type
-        page.setPageType(pageTypeRepository.get(USER_PAGE_TYPE_ID));
+        page.setPageType(pageTypeRepository.getUserPageType());
         pageRepository.save(page);
         
         return page;

Modified: incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/service/impl/DefaultUserService.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/service/impl/DefaultUserService.java?rev=1244751&r1=1244750&r2=1244751&view=diff
==============================================================================
--- incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/service/impl/DefaultUserService.java (original)
+++ incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/service/impl/DefaultUserService.java Wed Feb 15 21:59:27 2012
@@ -22,7 +22,7 @@ package org.apache.rave.portal.service.i
 import org.apache.rave.portal.model.Person;
 import org.apache.rave.portal.model.User;
 import org.apache.rave.portal.model.util.SearchResult;
-import org.apache.rave.portal.repository.UserRepository;
+import org.apache.rave.portal.repository.*;
 import org.apache.rave.portal.service.UserService;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -49,10 +49,25 @@ public class DefaultUserService implemen
     private static final Logger log = LoggerFactory.getLogger(DefaultUserService.class);
 
     private final UserRepository userRepository;
+    private final PageRepository pageRepository;
+    private final PageTypeRepository pageTypeRepository;
+    private final WidgetRatingRepository widgetRatingRepository;
+    private final WidgetCommentRepository widgetCommentRepository;
+    private final WidgetRepository widgetRepository;
 
     @Autowired
-    public DefaultUserService(UserRepository userRepository) {
+    public DefaultUserService(UserRepository userRepository,
+                              PageRepository pageRepository,
+                              PageTypeRepository pageTypeRepository,
+                              WidgetRatingRepository widgetRatingRepository,
+                              WidgetCommentRepository widgetCommentRepository,
+                              WidgetRepository widgetRepository) {
         this.userRepository = userRepository;
+        this.pageRepository = pageRepository;
+        this.pageTypeRepository = pageTypeRepository;
+        this.widgetRatingRepository = widgetRatingRepository;
+        this.widgetCommentRepository = widgetCommentRepository;
+        this.widgetRepository = widgetRepository;
     }
 
     @Override
@@ -162,11 +177,28 @@ public class DefaultUserService implemen
     @Transactional
     // TODO RAVE-300: add security check that is is called by admin or the user itself
     public void deleteUser(Long userId) {
+        log.info("about to delete userId: " + userId);
         User user = userRepository.get(userId);
         if (user == null) {
+            log.warn("unable to find userId " + userId + " to delete");
             return;
         }
-        userRepository.removeUser(user);
+        
+        final String username = user.getUsername();
+
+        // delete all User type pages
+        int numDeletedPages = pageRepository.deletePages(userId, pageTypeRepository.getUserPageType().getEntityId());        
+        // delete all the widget comments
+        int numWidgetComments = widgetCommentRepository.deleteAll(userId);
+        // delete all the widget ratings
+        int numWidgetRatings = widgetRatingRepository.deleteAll(userId);
+        // unassign the user from any widgets where they were the owner
+        int numWidgetsOwned = widgetRepository.unassignWidgetOwner(userId);
+        // finally delete the user
+        userRepository.delete(user);
+        log.info("Deleted user [" + userId + "," + username + "] - numPages: " + numDeletedPages +
+                 ", numWidgetComments: " + numWidgetComments + ", numWidgetRatings: " + numWidgetRatings +
+                 ", numWidgetsOwned: " + numWidgetsOwned);
     }
 
     @Override

Modified: incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/service/impl/DefaultWidgetCommentService.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/service/impl/DefaultWidgetCommentService.java?rev=1244751&r1=1244750&r2=1244751&view=diff
==============================================================================
--- incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/service/impl/DefaultWidgetCommentService.java (original)
+++ incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/service/impl/DefaultWidgetCommentService.java Wed Feb 15 21:59:27 2012
@@ -49,5 +49,10 @@ public class DefaultWidgetCommentService
     public void removeWidgetComment(Long id) {
         widgetCommentRepository.delete(getWidgetComment(id));
     }
-        
+
+    @Override
+    @Transactional
+    public int deleteAll(Long userId) {
+        return widgetCommentRepository.deleteAll(userId);
+    }
 }

Modified: incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/service/impl/DefaultWidgetRatingService.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/service/impl/DefaultWidgetRatingService.java?rev=1244751&r1=1244750&r2=1244751&view=diff
==============================================================================
--- incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/service/impl/DefaultWidgetRatingService.java (original)
+++ incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/service/impl/DefaultWidgetRatingService.java Wed Feb 15 21:59:27 2012
@@ -71,4 +71,10 @@ public class DefaultWidgetRatingService 
         }
         repository.delete(widgetRating);
     }
+
+    @Override
+    @Transactional
+    public int removeAllWidgetRatings(Long userId) {
+        return repository.deleteAll(userId);
+    }
 }

Modified: incubator/rave/trunk/rave-components/rave-core/src/test/java/org/apache/rave/portal/repository/impl/JpaPageRepositoryTest.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-components/rave-core/src/test/java/org/apache/rave/portal/repository/impl/JpaPageRepositoryTest.java?rev=1244751&r1=1244750&r2=1244751&view=diff
==============================================================================
--- incubator/rave/trunk/rave-components/rave-core/src/test/java/org/apache/rave/portal/repository/impl/JpaPageRepositoryTest.java (original)
+++ incubator/rave/trunk/rave-components/rave-core/src/test/java/org/apache/rave/portal/repository/impl/JpaPageRepositoryTest.java Wed Feb 15 21:59:27 2012
@@ -19,9 +19,11 @@
 package org.apache.rave.portal.repository.impl;
 
 import org.apache.rave.portal.model.Page;
+import org.hamcrest.CoreMatchers;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.test.annotation.Rollback;
 import org.springframework.test.context.ContextConfiguration;
 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
 import org.springframework.transaction.annotation.Transactional;
@@ -31,13 +33,10 @@ import javax.persistence.PersistenceCont
 import java.util.List;
 
 import org.apache.rave.portal.repository.PageRepository;
-import static org.hamcrest.CoreMatchers.equalTo;
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.CoreMatchers.notNullValue;
-import static org.hamcrest.CoreMatchers.nullValue;
-import static org.junit.Assert.assertThat;
+import static org.hamcrest.CoreMatchers.*;
+import static org.junit.Assert.*;
 
-@Transactional
+@Transactional(readOnly=true)
 @RunWith(SpringJUnit4ClassRunner.class)
 @ContextConfiguration(locations = {"classpath:test-dataContext.xml", "classpath:test-applicationContext.xml"})
 public class JpaPageRepositoryTest {
@@ -95,5 +94,15 @@ public class JpaPageRepositoryTest {
         assertThat(p, is(nullValue()));
     }
 
-
+    @Test
+    @Transactional(readOnly=false)
+    @Rollback(true)
+    public void deletePages_userPageType() {
+        int numPages = repository.getAllPages(USER_ID, USER_PAGE_TYPE_ID).size();
+        assertThat(numPages > 0, is(true));
+        int deletedPages = repository.deletePages(USER_ID, USER_PAGE_TYPE_ID);
+        assertThat(deletedPages, is(numPages));
+        // ensure pages are deleted
+        assertThat(repository.getAllPages(USER_ID, USER_PAGE_TYPE_ID).isEmpty(), is(true));
+    }
 }

Modified: incubator/rave/trunk/rave-components/rave-core/src/test/java/org/apache/rave/portal/repository/impl/JpaUserRepositoryTest.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-components/rave-core/src/test/java/org/apache/rave/portal/repository/impl/JpaUserRepositoryTest.java?rev=1244751&r1=1244750&r2=1244751&view=diff
==============================================================================
--- incubator/rave/trunk/rave-components/rave-core/src/test/java/org/apache/rave/portal/repository/impl/JpaUserRepositoryTest.java (original)
+++ incubator/rave/trunk/rave-components/rave-core/src/test/java/org/apache/rave/portal/repository/impl/JpaUserRepositoryTest.java Wed Feb 15 21:59:27 2012
@@ -167,24 +167,6 @@ public class JpaUserRepositoryTest {
     }
 
     @Test
-    public void removeUser() {
-        User user = repository.get(USER_ID);
-        assertNotNull(user);
-        final TypedQuery<Page> pageQuery = manager.createNamedQuery(Page.GET_BY_USER_ID_AND_PAGE_TYPE_ID, Page.class);
-        pageQuery.setParameter("userId", USER_ID);
-        pageQuery.setParameter("pageTypeId", 1L);
-        List<Page> pages = pageQuery.getResultList();
-        assertFalse("User has pages", pages.isEmpty());
-
-        repository.removeUser(user);
-
-        user = repository.get(USER_ID);
-        assertNull(user);
-        pages = pageQuery.getResultList();
-        assertTrue("User has no pages", pages.isEmpty());
-    }
-
-    @Test
     public void getAllByAddedWidget() {
         String searchTerm = "Doe";
         List<User> users = repository.getAllByAddedWidget(VALID_WIDGET_ID);

Copied: incubator/rave/trunk/rave-components/rave-core/src/test/java/org/apache/rave/portal/repository/impl/JpaWidgetCommentRepositoryTest.java (from r1244603, incubator/rave/trunk/rave-components/rave-core/src/test/java/org/apache/rave/portal/repository/impl/JpaWidgetRatingRepositoryTest.java)
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-components/rave-core/src/test/java/org/apache/rave/portal/repository/impl/JpaWidgetCommentRepositoryTest.java?p2=incubator/rave/trunk/rave-components/rave-core/src/test/java/org/apache/rave/portal/repository/impl/JpaWidgetCommentRepositoryTest.java&p1=incubator/rave/trunk/rave-components/rave-core/src/test/java/org/apache/rave/portal/repository/impl/JpaWidgetRatingRepositoryTest.java&r1=1244603&r2=1244751&rev=1244751&view=diff
==============================================================================
--- incubator/rave/trunk/rave-components/rave-core/src/test/java/org/apache/rave/portal/repository/impl/JpaWidgetRatingRepositoryTest.java (original)
+++ incubator/rave/trunk/rave-components/rave-core/src/test/java/org/apache/rave/portal/repository/impl/JpaWidgetCommentRepositoryTest.java Wed Feb 15 21:59:27 2012
@@ -19,10 +19,11 @@
 
 package org.apache.rave.portal.repository.impl;
 
-import org.apache.rave.portal.model.WidgetRating;
+import org.apache.rave.portal.repository.WidgetCommentRepository;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.test.annotation.Rollback;
 import org.springframework.test.context.ContextConfiguration;
 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
 import org.springframework.transaction.annotation.Transactional;
@@ -30,38 +31,28 @@ import org.springframework.transaction.a
 import javax.persistence.EntityManager;
 import javax.persistence.PersistenceContext;
 
-import org.apache.rave.portal.repository.WidgetRatingRepository;
-import static junit.framework.Assert.assertEquals;
-import static junit.framework.Assert.assertNull;
+import static org.hamcrest.CoreMatchers.*;
+import static org.junit.Assert.*;
 
 /**
- * Test for {@link org.apache.rave.portal.repository.impl.JpaWidgetRatingRepository}
+ * Test for {@link JpaWidgetCommentRepository}
  */
-@Transactional
+@Transactional(readOnly=true)
 @RunWith(SpringJUnit4ClassRunner.class)
 @ContextConfiguration(locations = {"classpath:test-dataContext.xml", "classpath:test-applicationContext.xml"})
-public class JpaWidgetRatingRepositoryTest {
-
+public class JpaWidgetCommentRepositoryTest {
+    private Long VALID_USER_ID = 1L;
+    
     @PersistenceContext
     private EntityManager sharedManager;
 
     @Autowired
-    private WidgetRatingRepository repository;
-
-    @Test
-    public void getByWidgetIdAndUserId_found() {
-        Long widgetId = 1L;
-        Long userId = 1L;
-        WidgetRating widgetRating = repository.get(1L);
-        WidgetRating byWidgetAndUser = repository.getByWidgetIdAndUserId(widgetId, userId);
-        assertEquals(widgetRating, byWidgetAndUser);
-    }
+    private WidgetCommentRepository repository;
 
     @Test
-    public void getByWidgetIdAndUserId_missing() {
-        Long widgetId = 123L;
-        Long userId = 234L;
-        WidgetRating byWidgetAndUser = repository.getByWidgetIdAndUserId(widgetId, userId);
-        assertNull("Don't expect a WidgetRating for widgetId 123 and userId 234", byWidgetAndUser);
+    @Transactional(readOnly=false)
+    @Rollback(true)
+    public void deleteAll() {
+        assertThat(repository.deleteAll(VALID_USER_ID), is(2));
     }
-}
+}
\ No newline at end of file

Modified: incubator/rave/trunk/rave-components/rave-core/src/test/java/org/apache/rave/portal/repository/impl/JpaWidgetRatingRepositoryTest.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-components/rave-core/src/test/java/org/apache/rave/portal/repository/impl/JpaWidgetRatingRepositoryTest.java?rev=1244751&r1=1244750&r2=1244751&view=diff
==============================================================================
--- incubator/rave/trunk/rave-components/rave-core/src/test/java/org/apache/rave/portal/repository/impl/JpaWidgetRatingRepositoryTest.java (original)
+++ incubator/rave/trunk/rave-components/rave-core/src/test/java/org/apache/rave/portal/repository/impl/JpaWidgetRatingRepositoryTest.java Wed Feb 15 21:59:27 2012
@@ -23,6 +23,7 @@ import org.apache.rave.portal.model.Widg
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.test.annotation.Rollback;
 import org.springframework.test.context.ContextConfiguration;
 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
 import org.springframework.transaction.annotation.Transactional;
@@ -31,17 +32,23 @@ import javax.persistence.EntityManager;
 import javax.persistence.PersistenceContext;
 
 import org.apache.rave.portal.repository.WidgetRatingRepository;
-import static junit.framework.Assert.assertEquals;
-import static junit.framework.Assert.assertNull;
+import static org.junit.Assert.*;
+import static org.hamcrest.CoreMatchers.*;
 
 /**
  * Test for {@link org.apache.rave.portal.repository.impl.JpaWidgetRatingRepository}
  */
-@Transactional
+@Transactional(readOnly=true)
 @RunWith(SpringJUnit4ClassRunner.class)
 @ContextConfiguration(locations = {"classpath:test-dataContext.xml", "classpath:test-applicationContext.xml"})
 public class JpaWidgetRatingRepositoryTest {
-
+    private Long VALID_WIDGET_ID = 1L;
+    private Long VALID_USER_ID = 1L;
+    private Long VALID_WIDGET_RATING_ID = 1L;
+
+    private Long INVALID_WIDGET_ID = 123L;
+    private Long INVALID_USER_ID = 234L;
+    
     @PersistenceContext
     private EntityManager sharedManager;
 
@@ -50,18 +57,18 @@ public class JpaWidgetRatingRepositoryTe
 
     @Test
     public void getByWidgetIdAndUserId_found() {
-        Long widgetId = 1L;
-        Long userId = 1L;
-        WidgetRating widgetRating = repository.get(1L);
-        WidgetRating byWidgetAndUser = repository.getByWidgetIdAndUserId(widgetId, userId);
-        assertEquals(widgetRating, byWidgetAndUser);
+        assertThat(repository.get(VALID_WIDGET_RATING_ID), is(repository.getByWidgetIdAndUserId(VALID_WIDGET_ID, VALID_USER_ID)));
     }
 
     @Test
     public void getByWidgetIdAndUserId_missing() {
-        Long widgetId = 123L;
-        Long userId = 234L;
-        WidgetRating byWidgetAndUser = repository.getByWidgetIdAndUserId(widgetId, userId);
-        assertNull("Don't expect a WidgetRating for widgetId 123 and userId 234", byWidgetAndUser);
+        assertThat(repository.getByWidgetIdAndUserId(INVALID_WIDGET_ID, INVALID_USER_ID), is(nullValue(WidgetRating.class)));       
+    }
+
+    @Test
+    @Transactional(readOnly=false)
+    @Rollback(true)
+    public void deleteAll() {
+        assertThat(repository.deleteAll(VALID_USER_ID), is(2));
     }
 }

Modified: incubator/rave/trunk/rave-components/rave-core/src/test/java/org/apache/rave/portal/repository/impl/JpaWidgetRepositoryTest.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-components/rave-core/src/test/java/org/apache/rave/portal/repository/impl/JpaWidgetRepositoryTest.java?rev=1244751&r1=1244750&r2=1244751&view=diff
==============================================================================
--- incubator/rave/trunk/rave-components/rave-core/src/test/java/org/apache/rave/portal/repository/impl/JpaWidgetRepositoryTest.java (original)
+++ incubator/rave/trunk/rave-components/rave-core/src/test/java/org/apache/rave/portal/repository/impl/JpaWidgetRepositoryTest.java Wed Feb 15 21:59:27 2012
@@ -27,6 +27,7 @@ import org.junit.runner.RunWith;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.test.annotation.Rollback;
 import org.springframework.test.context.ContextConfiguration;
 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
 import org.springframework.transaction.annotation.Transactional;
@@ -46,7 +47,7 @@ import static org.junit.Assert.assertTru
 /**
  * Test class for {@link org.apache.rave.portal.repository.impl.JpaWidgetRepository}
  */
-@Transactional
+@Transactional(readOnly = true)
 @RunWith(SpringJUnit4ClassRunner.class)
 @ContextConfiguration(locations = {"classpath:test-dataContext.xml", "classpath:test-applicationContext.xml"})
 public class JpaWidgetRepositoryTest {
@@ -186,6 +187,8 @@ public class JpaWidgetRepositoryTest {
     }
 
     @Test
+    @Transactional(readOnly = false)
+    @Rollback
     public void saveWidgetWithLongDescription() {
         final String url = "http://example.com/doesnotexistyet";
         final String longDescription = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc dictum sodales erat consequat pulvinar. Pellentesque ut massa mi, sit amet imperdiet diam. Morbi nec magna quis nisi bibendum dignissim. Fusce et rhoncus turpis. Integer mollis magna sit amet nulla convallis placerat dignissim lorem blandit. Nulla magna justo, cursus ac semper sed, pulvinar in turpis. Donec ultricies nibh sed nulla congue ullamcorper. Fusce commodo ultrices nunc, interdum lacinia elit faucibus at. Fusce laoreet ultricies volutpat. ";
@@ -288,6 +291,8 @@ public class JpaWidgetRepositoryTest {
     }
 
     @Test
+    @Transactional(readOnly = false)
+    @Rollback    
     public void addWidgetRating() {
         Widget widget = repository.get(3L);
         assertNotNull(widget.getRatings());
@@ -311,6 +316,8 @@ public class JpaWidgetRepositoryTest {
     }
 
     @Test
+    @Transactional(readOnly = false)
+    @Rollback    
     public void updateWidgetRating() {
         Widget widget = repository.get(4L);
         assertNotNull(widget.getRatings());
@@ -382,6 +389,8 @@ public class JpaWidgetRepositoryTest {
     }
 
     @Test
+    @Transactional(readOnly = false)
+    @Rollback    
     public void addWidgetCategory() {
         final long WIDGET_ID = 1L;
         final User user = new User(1L);
@@ -418,6 +427,8 @@ public class JpaWidgetRepositoryTest {
     }
 
     @Test
+    @Transactional(readOnly = false)
+    @Rollback    
     public void removeWidgetCategory() {
         final long WIDGET_ID = 1L;
 
@@ -430,5 +441,21 @@ public class JpaWidgetRepositoryTest {
         Widget reloadedWidget = repository.get(WIDGET_ID);
         assertThat(reloadedWidget.getCategories().size(), is(1));
         assertThat(reloadedWidget.getCategories().get(0).getEntityId(), is(4L));
-    }    
+    }
+
+    @Test
+    @Transactional(readOnly = false)
+    @Rollback
+    public void unassignWidgetOwner() {
+        final long WIDGET_ID = 2L;
+        final long USER_ID = 1L;
+        final int NUM_WIDGETS_OWNED_BY_USER = 11;
+        
+        Widget widget = repository.get(WIDGET_ID);
+        assertThat(widget.getOwner().getEntityId(), is(USER_ID));        
+        assertThat(repository.unassignWidgetOwner(USER_ID), is(NUM_WIDGETS_OWNED_BY_USER));
+        sharedManager.flush();
+        sharedManager.refresh(widget);
+        assertThat(widget.getOwner(), is(nullValue(User.class)));
+    }
 }

Modified: incubator/rave/trunk/rave-components/rave-core/src/test/java/org/apache/rave/portal/service/impl/DefaultPageServiceTest.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-components/rave-core/src/test/java/org/apache/rave/portal/service/impl/DefaultPageServiceTest.java?rev=1244751&r1=1244750&r2=1244751&view=diff
==============================================================================
--- incubator/rave/trunk/rave-components/rave-core/src/test/java/org/apache/rave/portal/service/impl/DefaultPageServiceTest.java (original)
+++ incubator/rave/trunk/rave-components/rave-core/src/test/java/org/apache/rave/portal/service/impl/DefaultPageServiceTest.java Wed Feb 15 21:59:27 2012
@@ -54,6 +54,7 @@ public class DefaultPageServiceTest {
     private final Long VALID_REGION_WIDGET_ID = 1L;
     private final Long INVALID_REGION_WIDGET_ID = 100L;
     private final Long USER_PAGE_TYPE_ID = 1L;
+    private final Long VALID_USER_ID = 9876L;
             
     private Region targetRegion;
     private Region originalRegion;
@@ -128,7 +129,6 @@ public class DefaultPageServiceTest {
 
     @Test
     public void getAllPages() {
-        final Long VALID_USER_ID = 1L;
         final List<Page> VALID_PAGES = new ArrayList<Page>();
 
         expect(pageRepository.getAllPages(VALID_USER_ID, userPageType.getEntityId())).andReturn(VALID_PAGES);
@@ -214,7 +214,7 @@ public class DefaultPageServiceTest {
         expect(pageLayoutRepository.getByPageLayoutCode(PAGE_LAYOUT_CODE)).andReturn(pageLayout);
         expect(pageRepository.save(expectedPage)).andReturn(expectedPage);
         expect(pageRepository.getAllPages(user.getEntityId(), userPageType.getEntityId())).andReturn(new ArrayList<Page>());
-        expect(pageTypeRepository.get(USER_PAGE_TYPE_ID)).andReturn(userPageType);
+        expect(pageTypeRepository.getUserPageType()).andReturn(userPageType);
         replay(userService, pageLayoutRepository, pageRepository, pageTypeRepository);
 
         Page newPage = pageService.addNewDefaultUserPage(user.getEntityId());
@@ -264,8 +264,18 @@ public class DefaultPageServiceTest {
         pageService.deletePage(INVALID_PAGE_ID);
         verify(userService);
         verify(pageRepository);
+    }
+
+    @Test
+    public void deletePages() {                      
+        final int EXPECTED_DELETED_PAGE_COUNT = 7;
+        expect(pageRepository.deletePages(VALID_USER_ID, USER_PAGE_TYPE_ID)).andReturn(EXPECTED_DELETED_PAGE_COUNT);     
+        replay(pageRepository);
+        assertThat(pageService.deletePages(VALID_USER_ID, USER_PAGE_TYPE_ID), is(EXPECTED_DELETED_PAGE_COUNT));
+        verify(pageRepository);
     }    
     
+    
     @Test
     public void moveRegionWidget_validMiddle() {
         final int newPosition = 0;
@@ -891,4 +901,20 @@ public class DefaultPageServiceTest {
 
         pageService.moveRegionWidgetToPage(VALID_REGION_WIDGET_ID, TO_PAGE_ID);
     }
+    
+    @Test
+    public void getUserPageType() {
+        expect(pageTypeRepository.getUserPageType()).andReturn(userPageType);
+        replay(pageTypeRepository);
+        assertThat(pageService.getUserPageType(), is(userPageType));
+        verify(pageTypeRepository);
+    }
+
+    @Test
+    public void getPersonProfilePageType() {
+        expect(pageTypeRepository.getPersonProfilePageType()).andReturn(personProfilePageType);
+        replay(pageTypeRepository);
+        assertThat(pageService.getPersonProfilePageType(), is(personProfilePageType));
+        verify(pageTypeRepository);
+    }
 }

Modified: incubator/rave/trunk/rave-components/rave-core/src/test/java/org/apache/rave/portal/service/impl/DefaultUserServiceTest.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-components/rave-core/src/test/java/org/apache/rave/portal/service/impl/DefaultUserServiceTest.java?rev=1244751&r1=1244750&r2=1244751&view=diff
==============================================================================
--- incubator/rave/trunk/rave-components/rave-core/src/test/java/org/apache/rave/portal/service/impl/DefaultUserServiceTest.java (original)
+++ incubator/rave/trunk/rave-components/rave-core/src/test/java/org/apache/rave/portal/service/impl/DefaultUserServiceTest.java Wed Feb 15 21:59:27 2012
@@ -19,17 +19,15 @@
 
 package org.apache.rave.portal.service.impl;
 
-import org.apache.rave.portal.model.Authority;
-import org.apache.rave.portal.model.Page;
-import org.apache.rave.portal.model.Person;
-import org.apache.rave.portal.model.User;
+import org.apache.rave.portal.model.*;
 import org.apache.rave.portal.model.util.SearchResult;
-import org.apache.rave.portal.repository.UserRepository;
+import org.apache.rave.portal.repository.*;
 import org.apache.rave.portal.service.UserService;
+import org.apache.rave.portal.service.WidgetCommentService;
+import org.apache.rave.portal.service.WidgetRatingService;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
-import org.springframework.dao.IncorrectResultSizeDataAccessException;
 import org.springframework.security.authentication.AbstractAuthenticationToken;
 import org.springframework.security.core.GrantedAuthority;
 import org.springframework.security.core.context.SecurityContext;
@@ -50,14 +48,28 @@ public class DefaultUserServiceTest {
     private static final Long USER_ID = 1234L;
     private UserService service;
     private UserRepository userRepository;
+    private PageRepository pageRepository;
+    private PageTypeRepository pageTypeRepository;
+    private WidgetCommentRepository widgetCommentRepository;
+    private WidgetRatingRepository widgetRatingRepository;
+    private WidgetRepository widgetRepository;
+
     private static final String USER_NAME = "1234";
     private static final String USER_EMAIL = "test@test.com";
     private static final Long VALID_WIDGET_ID = 1L;
+    private static final Long USER_PAGE_TYPE_ID = 33L;
+    private static final Long INVALID_USER_ID = -9999L;
 
     @Before
     public void setup() {
         userRepository = createMock(UserRepository.class);
-        service = new DefaultUserService(userRepository);
+        pageRepository = createMock(PageRepository.class);
+        pageTypeRepository = createMock(PageTypeRepository.class);
+        widgetCommentRepository = createMock(WidgetCommentRepository.class);
+        widgetRatingRepository = createMock(WidgetRatingRepository.class);
+        widgetRepository = createMock(WidgetRepository.class);
+
+        service = new DefaultUserService(userRepository, pageRepository, pageTypeRepository, widgetRatingRepository, widgetCommentRepository, widgetRepository);
     }
 
     @After
@@ -246,20 +258,39 @@ public class DefaultUserServiceTest {
     }
 
     @Test
-    public void deleteUserProfile() {
+    public void deleteUser() {
+        PageType userPageType = new PageType(USER_PAGE_TYPE_ID);
+        final int NUM_COMMENTS = 33;
+        final int NUM_RATINGS = 99;
+        final int NUM_WIDGETS_OWNED = 4;
         User user = new User(USER_ID, USER_NAME);
         Page page = new Page(1L, user);
         List<Page> pages = new ArrayList<Page>();
         pages.add(page);
-        expect(userRepository.get(USER_ID)).andReturn(user).times(1);
-        userRepository.removeUser(user);
+        
+        expect(userRepository.get(USER_ID)).andReturn(user);     
+        expect(pageTypeRepository.getUserPageType()).andReturn(userPageType);
+        expect(pageRepository.deletePages(USER_ID, USER_PAGE_TYPE_ID)).andReturn(pages.size());      
+        expect(widgetCommentRepository.deleteAll(USER_ID)).andReturn(NUM_COMMENTS);
+        expect(widgetRatingRepository.deleteAll(USER_ID)).andReturn(NUM_RATINGS);       
+        expect(widgetRepository.unassignWidgetOwner(USER_ID)).andReturn( NUM_WIDGETS_OWNED);       
+        userRepository.delete(user);
         expectLastCall();
-        replay(userRepository);
+        replay(userRepository, pageTypeRepository, pageRepository, widgetCommentRepository, widgetRatingRepository, widgetRepository);
 
         service.deleteUser(USER_ID);
-        verify(userRepository);
 
-        assertTrue("Deleted", true);
+        verify(userRepository, pageTypeRepository, pageRepository, widgetCommentRepository, widgetRatingRepository, widgetRepository);
+    }
+
+    @Test
+    public void deleteUser_invalidUserId() {
+        expect(userRepository.get(INVALID_USER_ID)).andReturn(null);
+        replay(userRepository, pageTypeRepository, pageRepository, widgetCommentRepository, widgetRatingRepository, widgetRepository);
+
+        service.deleteUser(INVALID_USER_ID);
+
+        verify(userRepository, pageTypeRepository, pageRepository, widgetCommentRepository, widgetRatingRepository, widgetRepository);
     }
 
     @Test

Modified: incubator/rave/trunk/rave-components/rave-core/src/test/java/org/apache/rave/portal/service/impl/DefaultWidgetCommentServiceTest.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-components/rave-core/src/test/java/org/apache/rave/portal/service/impl/DefaultWidgetCommentServiceTest.java?rev=1244751&r1=1244750&r2=1244751&view=diff
==============================================================================
--- incubator/rave/trunk/rave-components/rave-core/src/test/java/org/apache/rave/portal/service/impl/DefaultWidgetCommentServiceTest.java (original)
+++ incubator/rave/trunk/rave-components/rave-core/src/test/java/org/apache/rave/portal/service/impl/DefaultWidgetCommentServiceTest.java Wed Feb 15 21:59:27 2012
@@ -19,7 +19,9 @@ import static org.easymock.EasyMock.crea
 import static org.easymock.EasyMock.expect;
 import static org.easymock.EasyMock.replay;
 import static org.easymock.EasyMock.verify;
+import static org.hamcrest.CoreMatchers.is;
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThat;
 
 import org.apache.rave.portal.model.WidgetComment;
 import org.apache.rave.portal.repository.WidgetCommentRepository;
@@ -72,4 +74,15 @@ public class DefaultWidgetCommentService
         widgetCommentService.removeWidgetComment(1L);
         verify(widgetCommentRepository);
     }
-}
+
+    @Test
+    public void deleteAll() {
+        final Long USER_ID = 33L;
+        final int EXPECTED_COUNT = 43;
+
+        expect(widgetCommentRepository.deleteAll(USER_ID)).andReturn(EXPECTED_COUNT);
+        replay(widgetCommentRepository);
+        assertThat(widgetCommentService.deleteAll(USER_ID), is(EXPECTED_COUNT));
+        verify(widgetCommentRepository);
+    }
+}
\ No newline at end of file

Modified: incubator/rave/trunk/rave-components/rave-core/src/test/java/org/apache/rave/portal/service/impl/DefaultWidgetRatingServiceTest.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-components/rave-core/src/test/java/org/apache/rave/portal/service/impl/DefaultWidgetRatingServiceTest.java?rev=1244751&r1=1244750&r2=1244751&view=diff
==============================================================================
--- incubator/rave/trunk/rave-components/rave-core/src/test/java/org/apache/rave/portal/service/impl/DefaultWidgetRatingServiceTest.java (original)
+++ incubator/rave/trunk/rave-components/rave-core/src/test/java/org/apache/rave/portal/service/impl/DefaultWidgetRatingServiceTest.java Wed Feb 15 21:59:27 2012
@@ -25,12 +25,9 @@ import org.apache.rave.portal.service.Wi
 import org.junit.Before;
 import org.junit.Test;
 
-import static junit.framework.Assert.assertEquals;
-import static org.easymock.EasyMock.createMock;
-import static org.easymock.EasyMock.expect;
-import static org.easymock.EasyMock.expectLastCall;
-import static org.easymock.EasyMock.replay;
-import static org.easymock.EasyMock.verify;
+import static org.junit.Assert.*;
+import static org.easymock.EasyMock.*;
+import static org.hamcrest.CoreMatchers.*;
 
 /**
  * Test for {@link org.apache.rave.portal.service.impl.DefaultWidgetRatingService}
@@ -53,6 +50,7 @@ public class DefaultWidgetRatingServiceT
         replay(repository);
         final WidgetRating rating = service.getByWidgetIdAndUserId(2L, 3L);
         assertEquals("Score is 5", Integer.valueOf(5), rating.getScore());
+        verify(repository);
     }
 
     @Test
@@ -111,15 +109,26 @@ public class DefaultWidgetRatingServiceT
         replay(repository);
 
         service.removeWidgetRating(1L, 1L);
+        verify(repository);
     }
 
     @Test
     public void removeWidgetRating_notExisting() {
-
         expect(repository.getByWidgetIdAndUserId(1L, 2L)).andReturn(null);
         expectLastCall();
         replay(repository);
-
         service.removeWidgetRating(1L, 2L);
+        verify(repository);
+    }
+    
+    @Test
+    public void deleteAll() {
+        final Long USER_ID = 33L;
+        final int EXPECTED_COUNT = 43;
+        
+        expect(repository.deleteAll(USER_ID)).andReturn(EXPECTED_COUNT);
+        replay(repository);
+        assertThat(service.removeAllWidgetRatings(USER_ID), is(EXPECTED_COUNT));
+        verify(repository);
     }
 }



Mime
View raw message