Commits

Anonymous committed f1cf875

Progress in ENCUESTAME-267

  • Participants
  • Parent commits 919b7f7

Comments (0)

Files changed (7)

File encuestame-persistence/src/main/java/org/encuestame/persistence/dao/IDashboardDao.java

  */
 package org.encuestame.persistence.dao;
 
+import java.util.List;
+
+import org.encuestame.persistence.domain.dashboard.Dashboard;
+import org.encuestame.persistence.domain.dashboard.Gadget;
+import org.encuestame.persistence.domain.security.UserAccount;
+
 /**
  * Dashboard Interface.
  * @author Morales,Diana Paola paolaATencuestame.org
  */
 public interface IDashboardDao extends IBaseDao {
 
+	/**
+	 * Get dashboard by id.
+	 * @param boardId
+	 * @return
+	 */
+	Dashboard getDashboardbyId(final Long boardId);
+
+	/**
+	 * Retrieve dashboards by id and user.
+	 * @param userBoard
+	 * @return
+	 */
+	List<Dashboard> retrieveDashboards(final UserAccount userBoard);
+
+	/**
+	 * Retrieve favorites dashboards.
+	 * @param userId
+	 * @param maxResults
+	 * @param start
+	 * @return
+	 */
+	List<Dashboard> retrieveFavouritesDashboards(
+	            final Long userId,
+	            final Integer maxResults,
+	            final Integer start);
+
+	/**
+	 * Get gadget by id.
+	 * @param gadgetId
+	 * @return
+	 */
+	Gadget getGadgetbyId(final Long gadgetId);
+
+	/**
+	 * Get gadget by keyword.
+	 * @param keyword
+	 * @param maxResults
+	 * @param start
+	 * @return
+	 */
+	List<Gadget> getGadgetbyKeyword(final String keyword, final Integer maxResults, final Integer start);
 }

File encuestame-persistence/src/main/java/org/encuestame/persistence/dao/imp/DashboardDao.java

  */
 package org.encuestame.persistence.dao.imp;
 
+import java.util.List;
 import org.encuestame.persistence.dao.IDashboardDao;
+import org.encuestame.persistence.domain.dashboard.Dashboard;
+import org.encuestame.persistence.domain.dashboard.Gadget;
+import org.encuestame.persistence.domain.security.UserAccount;
+import org.hibernate.SessionFactory;
+import org.hibernate.criterion.DetachedCriteria;
+import org.hibernate.criterion.MatchMode;
+import org.hibernate.criterion.Restrictions;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Repository;
 
 /**
  * Dashboard Dao.
  * @author Morales,Diana Paola paolaATencuestame.org
  * @since July 27, 2011
  */
+@Repository("dashboardDao")
 public class DashboardDao extends AbstractHibernateDaoSupport implements IDashboardDao {
 
+	@Autowired
+	public DashboardDao(SessionFactory sessionFactory) {
+		setSessionFactory(sessionFactory);
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * @see org.encuestame.persistence.dao.IDashboardDao#getDashboardbyId(java.lang.Long)
+	 */
+	public Dashboard getDashboardbyId(final Long boardId){
+	 		return (Dashboard) getHibernateTemplate().get(Dashboard.class, boardId);
+	 }
+
+	/*
+	 * (non-Javadoc)
+	 * @see org.encuestame.persistence.dao.IDashboardDao#retrieveDashboards(java.lang.Long, org.encuestame.persistence.domain.security.UserAccount)
+	 */
+	@SuppressWarnings("unchecked")
+	public List<Dashboard> retrieveDashboards(final UserAccount userBoard){
+		final DetachedCriteria criteria = DetachedCriteria.forClass(Dashboard.class);
+			criteria.createAlias("userBoard", "userBoard");
+	        criteria.add(Restrictions.eq("userBoard", userBoard));
+	        return getHibernateTemplate().findByCriteria(criteria);
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * @see org.encuestame.persistence.dao.IDashboardDao#retrieveFavouritesDashboards(java.lang.Long, java.lang.Integer, java.lang.Integer)
+	 */
+	@SuppressWarnings("unchecked")
+	public List<Dashboard> retrieveFavouritesDashboards(
+			final Long userId,
+	        final Integer maxResults,
+	        final Integer start){
+	        final DetachedCriteria criteria = DetachedCriteria.forClass(Dashboard.class);
+	        criteria.createAlias("userBoard","userBoard");
+	        criteria.add(Restrictions.eq("favorite", Boolean.TRUE));
+	        criteria.add(Restrictions.eq("userBoard.uid", userId));
+	        return (List<Dashboard>) filterByMaxorStart(criteria, maxResults, start);
+	    }
+
+	/*
+	 * (non-Javadoc)
+	 * @see org.encuestame.persistence.dao.IDashboardDao#getGadgetbyId(java.lang.Long)
+	 */
+	public Gadget getGadgetbyId(final Long gadgetId){
+ 		return (Gadget) getHibernateTemplate().get(Gadget.class, gadgetId);
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * @see org.encuestame.persistence.dao.IDashboardDao#getGadgetbyKeyword(java.lang.String, java.lang.Integer, java.lang.Integer)
+	 */
+	@SuppressWarnings("unchecked")
+	public List<Gadget> getGadgetbyKeyword(final String keyword, final Integer maxResults, final Integer start){
+		  final DetachedCriteria criteria = DetachedCriteria.forClass(Gadget.class);
+	        criteria.createAlias("gadgetName","gadgetName");
+	        criteria.add(Restrictions.like("gadgetName", keyword, MatchMode.ANYWHERE));
+	        return (List<Gadget>) filterByMaxorStart(criteria, maxResults, start);
+	    }
 }

File encuestame-persistence/src/main/java/org/encuestame/persistence/domain/dashboard/Dashboard.java

 import javax.persistence.ManyToMany;
 import javax.persistence.ManyToOne;
 import javax.persistence.Table;
-
-import org.encuestame.persistence.domain.security.Permission;
 import org.encuestame.persistence.domain.security.UserAccount;
 
 /**
     /** {@link UserAccount} **/
     private UserAccount userBoard;
 
-    private Set<Gadget> widgetDashboard = new HashSet<Gadget>();
+    private Set<Gadget> gadgetDashboard = new HashSet<Gadget>();
 
     /**
     * @return the boardId
     @ManyToMany(cascade=CascadeType.ALL)
     @JoinTable(name="dashboard_gadget",
                joinColumns={@JoinColumn(name="dashboardId")},
-               inverseJoinColumns={@JoinColumn(name="widgetId")})
-    public Set<Gadget> getWidgetDashboard() {
-        return widgetDashboard;
+               inverseJoinColumns={@JoinColumn(name="gadgetId")})
+    public Set<Gadget> getGadgetDashboard() {
+        return gadgetDashboard;
     }
 
     /**
     * @param widgetDashboard the widgetDashboard to set
     */
-    public void setWidgetDashboard(Set<Gadget> widgetDashboard) {
-        this.widgetDashboard = widgetDashboard;
+    public void setGadgetDashboard(Set<Gadget> gadgetDashboard) {
+        this.gadgetDashboard = gadgetDashboard;
     }
 }

File encuestame-persistence/src/main/java/org/encuestame/persistence/domain/dashboard/Gadget.java

  */
 package org.encuestame.persistence.domain.dashboard;
 
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.persistence.CascadeType;
 import javax.persistence.Column;
 import javax.persistence.Entity;
 import javax.persistence.GeneratedValue;
 import javax.persistence.GenerationType;
 import javax.persistence.Id;
+import javax.persistence.ManyToMany;
 import javax.persistence.Table;
 
 /**
     /** Widget type**/
     private String gadgetType;
 
+    /** {@link Dashboard} **/
+    private Set<Dashboard> dashboard = new HashSet<Dashboard>();
+
     /**
     * @return the widgetId
     */
     public void setGadgetType(final String gadgetType) {
         this.gadgetType = gadgetType;
     }
+
+	/**
+	 * @return the dashboard
+	 */
+    @ManyToMany(cascade = CascadeType.ALL)
+	public Set<Dashboard> getDashboard() {
+		return dashboard;
+	}
+
+	/**
+	 * @param dashboard the dashboard to set
+	 */
+	public void setDashboard(final Set<Dashboard> dashboard) {
+		this.dashboard = dashboard;
+	}
 }

File encuestame-persistence/src/main/java/org/encuestame/persistence/domain/dashboard/GadgetProperties.java

     * @return the widget
     */
     @ManyToOne()
-    public Gadget getWidget() {
+    public Gadget getGadget() {
         return gadget;
     }
 
     /**
     * @param widget the widget to set
     */
-    public void setWidget(Gadget widget) {
-        this.gadget = widget;
+    public void setGadget(Gadget gadget) {
+        this.gadget = gadget;
     }
 
     /**

File encuestame-persistence/src/test/java/org/encuestame/test/persistence/dao/TestDashboardDao.java

+/*
+ ************************************************************************************
+ * Copyright (C) 2001-2011 encuestame: system online surveys Copyright (C) 2009
+ * encuestame Development Team.
+ * Licensed under the Apache Software License version 2.0
+ * 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.encuestame.test.persistence.dao;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import java.util.List;
+import org.encuestame.persistence.dao.IDashboardDao;
+import org.encuestame.persistence.domain.dashboard.Dashboard;
+import org.encuestame.persistence.domain.dashboard.Gadget;
+import org.encuestame.persistence.domain.security.Account;
+import org.encuestame.persistence.domain.security.UserAccount;
+import org.encuestame.test.config.AbstractBase;
+import org.junit.Before;
+import org.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+
+/**
+ * Test Dashboard Dao.
+ * @author Morales,Diana Paola paola@encuestame.org
+ * @since  July 28, 2011
+ */
+public class TestDashboardDao extends AbstractBase {
+
+	 /** {@link IDashboardDao} **/
+	@Autowired
+	IDashboardDao dashboard;
+
+	/** {@link UserAccount} **/
+	private UserAccount userAccount;
+
+	/** {@link Account} **/
+	private Account account;
+
+	/** {@link Dashboard} **/
+	private Dashboard board;
+
+	/** {@link Gadget} **/
+	private Gadget gadget;
+
+	@Before
+    public void initService(){
+		this.account = createUser("testEncuesta", "testEncuesta123");
+        this.userAccount = createUserAccount("diana", this.account);
+        this.board = createDashboard("First board", Boolean.TRUE, this.userAccount);
+        createDashboard("Second board", Boolean.TRUE, this.userAccount);
+	    createDashboard("Third board", Boolean.TRUE, this.userAccount);
+	    this.gadget = createGadgetDefault();
+	    createGadget("gadget 1", "P");
+	    createGadget("gadget 2", "P");
+	}
+
+	/**
+	 * Test retrieve dashboard by id.
+	 */
+	@Test
+	public void testGetDashboardbyId(){
+		final Dashboard dashboard = getDashboardDao().getDashboardbyId(this.board.getBoardId());
+		  assertNotNull(dashboard);
+		  assertEquals("Should be equals", dashboard.getBoardId(), this.board.getBoardId());
+	}
+
+	/**
+	 * Test retrieve dashboard pages.
+	 */
+	@Test
+	public void testRetrieveDashboardsPage(){
+		final List<Dashboard> boardPages = getDashboardDao().retrieveDashboards(this.userAccount);
+	    assertEquals("Should be equals", boardPages.size(), 3);
+	}
+
+	/**
+	 * Test Retrieve favorite dashboards.
+	 */
+	@Test
+	public void testRetrieveFavouritesDashboards(){
+		final List<Dashboard> favoriteBoards = getDashboardDao().retrieveFavouritesDashboards(this.userAccount.getUid(), 10, 0);
+		assertEquals("Should be equals", favoriteBoards.size(), 3);
+	}
+
+	/**
+	 * Test Retrieve gadgets by keyword.
+	 */
+	@Test
+	public void testGetGadgetbyKeyword(){
+		final List<Gadget> gadgets = getDashboardDao().getGadgetbyKeyword("gadget", 10, 0);
+		assertEquals("Should be equals", gadgets.size(), 2);
+	}
+
+	/**
+	 * Test get gadget by id.
+	 */
+	@Test
+	public void testGetGadgetbyId(){
+		final Gadget gad = getDashboardDao().getGadgetbyId(this.gadget.getGadgetId());
+		assertEquals("Should be equals", gad.getGadgetId(), this.gadget.getGadgetId());
+	}
+}

File encuestame-persistence/src/test/java/org/encuestame/test/persistence/domain/TestHibernateDomains.java

 import java.util.Date;
 
 import org.apache.commons.lang.RandomStringUtils;
-import org.encuestame.persistence.dao.IDashboardDao;
 import org.encuestame.persistence.domain.GeoPointType;
 import org.encuestame.persistence.domain.Client;
 import org.encuestame.persistence.domain.EmailList;
 import org.encuestame.persistence.domain.Status;
 import org.encuestame.persistence.domain.dashboard.Dashboard;
 import org.encuestame.persistence.domain.dashboard.Gadget;
+import org.encuestame.persistence.domain.dashboard.GadgetProperties;
 import org.encuestame.persistence.domain.question.CatQuestionCategory;
 import org.encuestame.persistence.domain.question.Question;
 import org.encuestame.persistence.domain.question.QuestionAnswer;
      }
 
      /** Dashboard domain. **/
+     @Test
      public void testDashboard(){
         final Dashboard board = new Dashboard();
-        board.setPageBoardName("");
-        board.setDescription("");
+        board.setPageBoardName("First dashboard");
+        board.setDescription("My first dashboard");
         board.setFavorite(Boolean.TRUE);
         board.setFavoriteCounter(1);
         board.setPageLayout("AAA");
         board.setBoardSequence(1);
         board.setUserBoard(createUserAccount("juan carlos", createAccount()));
-        board.getWidgetDashboard().add(createGadgetDefault());
+        board.getGadgetDashboard().add(createGadgetDefault());
         getDashboardDao().saveOrUpdate(board);
       }
 
      /** Gadget domain **/
+     @Test
      public void testGadget(){
         final Gadget gadget = new Gadget();
         gadget.setGadgetName("Notifications");
         gadget.setGadgetType("Poll");
         getDashboardDao().saveOrUpdate(gadget);
      }
+
+     /** Gadget Properties **/
+     @Test
+     public void testGadgetProperties(){
+    	 final GadgetProperties gadgetProp = new GadgetProperties();
+    	 gadgetProp.setGadgetPropName("maxResults");
+    	 gadgetProp.setGadgetPropValue("10");
+    	 gadgetProp.setUserAccount(createUserAccount("diana paola", createAccount()));
+    	 gadgetProp.setGadget(createGadgetDefault());
+    	 getDashboardDao().saveOrUpdate(gadgetProp);
+     }
 }