Commits

Juan Carlos Picado Herrera committed 9a63e9f

Progress in ENCUESTAME-269

  • Participants
  • Parent commits 69d3c2d

Comments (0)

Files changed (10)

File encuestame-business/src/main/java/org/encuestame/business/service/DashboardService.java

 import org.encuestame.core.service.AbstractBaseService;
 import org.encuestame.persistence.domain.dashboard.Dashboard;
 import org.encuestame.persistence.domain.dashboard.Gadget;
+import org.encuestame.persistence.domain.security.UserAccount;
 import org.encuestame.persistence.exception.EnMeDashboardNotFoundException;
 import org.encuestame.persistence.exception.EnMeExpcetion;
+import org.encuestame.persistence.exception.EnMeGadgetNotFoundException;
 import org.encuestame.persistence.exception.EnMeNoResultsFoundException;
+import org.encuestame.utils.web.DashboardBean;
 import org.springframework.stereotype.Service;
 
 /**
 	        log.info("search keyword Gadgets size "+gadgets.size());
 	        return gadgets;
 	    }
+
+	/*
+	 * (non-Javadoc)
+	 * @see org.encuestame.business.service.imp.IDashboardService#createDashboard(org.encuestame.utils.web.DashboardBean, org.encuestame.persistence.domain.security.UserAccount)
+	 */
+	public Dashboard createDashboard(final DashboardBean dashboardBean, final UserAccount user){
+		final Dashboard board = new Dashboard();
+			board.setPageBoardName(dashboardBean.getDashboardName());
+			board.setDescription(dashboardBean.getDashboardDesc());
+			board.setFavorite(dashboardBean.getFavorite());
+			board.setBoardSequence(dashboardBean.getSequence());
+			board.setFavoriteCounter(dashboardBean.getFavoriteCounter());
+			//board.setGadgetDashboard(gadgetDashboard);
+			//board.setPageLayout(dashboardBean.getLayout());
+			board.setUserBoard(user);
+		return board;
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * @see org.encuestame.business.service.imp.IDashboardService#addGadgetOnDashboard(java.lang.Long, java.lang.Long)
+	 */
+	public void addGadgetOnDashboard(final Long boardId, final Long gadgetId) throws EnMeGadgetNotFoundException{
+		final Gadget gadget = getDashboardDao().getGadgetbyId(gadgetId);
+		if(gadget!=null){
+			final Dashboard dashboard = getDashboardDao().getDashboardbyId(boardId);
+			dashboard.getGadgetDashboard().add(gadget);
+
+		}else{
+            throw new EnMeGadgetNotFoundException("gadget not found");
+		}
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * @see org.encuestame.business.service.imp.IDashboardService#removeGadget(java.lang.Long)
+	 */
+	public void removeGadget(final Long gadgetId) throws EnMeGadgetNotFoundException{
+		final Gadget gadget = getDashboardDao().getGadgetbyId(gadgetId);
+		if(gadget!=null){
+			getDashboardDao().delete(gadget);
+		}
+		else{
+			throw new EnMeGadgetNotFoundException("gadget not found");
+		}
+	}
 }

File encuestame-business/src/main/java/org/encuestame/business/service/imp/IDashboardService.java

 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;
 import org.encuestame.persistence.exception.EnMeExpcetion;
+import org.encuestame.persistence.exception.EnMeGadgetNotFoundException;
 import org.encuestame.persistence.exception.EnMeNoResultsFoundException;
+import org.encuestame.utils.web.DashboardBean;
 
 /**
  * Dashboard Service.
 	List<Gadget> searchGadgetbyKeyword(final String keyword,
             final Integer maxResults,
             final Integer start)throws EnMeExpcetion;
+
+	/**
+	 * Create dashboard.
+	 * @param dashboardBean
+	 * @param user
+	 * @return
+	 */
+	Dashboard createDashboard(final DashboardBean dashboardBean, final UserAccount user);
+
+	/**
+	 * Add gadget on dashboard.
+	 * @param boardId
+	 * @param gadgetId
+	 * @throws EnMeGadgetNotFoundException
+	 */
+	void addGadgetOnDashboard(final Long boardId, final Long gadgetId) throws EnMeGadgetNotFoundException;
+
+	/**
+	 * Remove gadget.
+	 * @param gadgetId
+	 * @throws EnMeGadgetNotFoundException
+	 */
+	void removeGadget(final Long gadgetId) throws EnMeGadgetNotFoundException;
 }

File encuestame-business/src/test/java/org/encuestame/test/business/service/TestDashboardService.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.business.service;
+
+import org.encuestame.business.service.DashboardService;
+import org.encuestame.business.service.imp.IDashboardService;
+import org.encuestame.persistence.domain.dashboard.Dashboard;
+import org.encuestame.persistence.domain.security.Account;
+import org.encuestame.persistence.domain.security.UserAccount;
+import org.encuestame.persistence.exception.EnMeNoResultsFoundException;
+import org.encuestame.test.business.service.config.AbstractServiceBase;
+import org.junit.Before;
+import org.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+
+/**
+ * Test for {@link DashboardService}.
+ * @author Morales, Diana Paola paolaATencuestame.org
+ * @since July 29, 2011
+ */
+public class TestDashboardService extends AbstractServiceBase{
+
+	/** {@link IDashboardService} **/
+	@Autowired
+	public IDashboardService dashboardService;
+
+	/** {@link Dashboard} **/
+	private Dashboard dashboard;
+
+	/** {@link Account} **/
+	private Account account;
+
+	/** {@link UserAccount} **/
+	private UserAccount userAccount;
+
+
+	@Before
+    public void initService(){
+		this.account = createUser("testEncuesta", "testEncuesta123");
+        this.userAccount = createUserAccount("diana", this.account);
+        this.dashboard = createDashboard("First board", Boolean.TRUE, this.userAccount);
+        createDashboard("Second board", Boolean.TRUE, this.userAccount);
+	    createDashboard("Third board", Boolean.TRUE, this.userAccount);
+
+	}
+
+	@Test
+	public void testGetAllDashboards() throws EnMeNoResultsFoundException{
+		System.out.println("testing");
+		//final List<Dashboard> allBoards = dashboardService.getAllDashboards(this.userAccount.getUsername(), 10, 0);
+		//  assertEquals("Should be equals", 3, allBoards.size());
+	}
+
+	/**
+	 * @return the dashboardService
+	 */
+	public IDashboardService getDashboardService() {
+		return dashboardService;
+	}
+
+	/**
+	 * @param dashboardService the dashboardService to set
+	 */
+	public void setDashboardService(IDashboardService dashboardService) {
+		this.dashboardService = dashboardService;
+	}
+}

File encuestame-core/src/main/java/org/encuestame/core/util/ConvertDomainBean.java

 import org.encuestame.persistence.domain.HashTag;
 import org.encuestame.persistence.domain.Project;
 import org.encuestame.persistence.domain.Status;
+import org.encuestame.persistence.domain.dashboard.Dashboard;
 import org.encuestame.persistence.domain.question.Question;
 import org.encuestame.persistence.domain.question.QuestionAnswer;
 import org.encuestame.persistence.domain.question.QuestionPattern;
 import org.encuestame.utils.json.QuestionPatternBean;
 import org.encuestame.utils.security.ProfileUserAccount;
 import org.encuestame.utils.security.SignUpBean;
+import org.encuestame.utils.web.DashboardBean;
 import org.encuestame.utils.web.HashTagBean;
 import org.encuestame.utils.web.QuestionAnswerBean;
 import org.encuestame.utils.web.TypeTreeNode;
         unitSurvey.setNotifications(survey.getNotifications());
         unitSurvey.setName(survey.getName());
         return unitSurvey;}
+
+    /**
+     * Convert Dashboard bean to dashboard domain.
+     * @param dashboards
+     * @return
+     */
+    public static final List<DashboardBean> convertListDashboardToBean(final List<Dashboard> dashboards){
+        final List<DashboardBean> dashboardList = new LinkedList<DashboardBean>();
+            for (Dashboard dashboard : dashboards) {
+            	dashboardList.add(ConvertDomainBean.convertDashboardDomaintoBean(dashboard));
+            }
+        return dashboardList;
     }
+
+    /**
+     * Convert Dashboard domain to dashboard bean.
+     * @param dashboard
+     * @return
+     */
+    public static final DashboardBean convertDashboardDomaintoBean(final Dashboard dashboard){
+    	final DashboardBean dashboardBean = new DashboardBean();
+    	dashboardBean.setDashboardId(dashboard.getBoardId());
+    	dashboardBean.setDashboardName(dashboard.getPageBoardName());
+    	dashboardBean.setDashboardDesc(dashboard.getDescription());
+    	dashboardBean.setFavorite(dashboard.getFavorite());
+    	dashboardBean.setFavoriteCounter(dashboard.getFavoriteCounter());
+    	dashboardBean.setLayout(dashboard.getPageLayout().toString());
+    	dashboardBean.setSequence(dashboard.getBoardSequence());
+    	return dashboardBean;
+    }
+}

File encuestame-mvc/src/main/java/org/encuestame/mvc/controller/json/DashboardJsonController.java

 import org.apache.log4j.Logger;
 import org.encuestame.mvc.controller.AbstractJsonController;
 import org.springframework.stereotype.Controller;
+import org.springframework.ui.ModelMap;
 
 /**
  * DashBoard Json Controller.
      */
     private Logger log = Logger.getLogger(this.getClass());
 
+    public ModelMap getAllWidgets(){
+    	return null;
+    }
+
 }

File encuestame-persistence/src/main/java/org/encuestame/persistence/exception/EnMeGadgetNotFoundException.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.persistence.exception;
+
+/**
+ * EnMe Gadget exception.
+ * @author Morales, Diana Paola paolaATencuestame.org
+ * @since July 29, 2011
+ */
+public class EnMeGadgetNotFoundException extends EnMeNoResultsFoundException {
+
+    /**
+     * Constructor.
+     */
+    public EnMeGadgetNotFoundException() {
+        super("user not found");
+    }
+
+    public EnMeGadgetNotFoundException(String message) {
+        super(message);
+    }
+}

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

 	/**
 	 * Test retrieve dashboard pages.
 	 */
-	@Test
+	//@Test
 	public void testRetrieveDashboardsPage(){
 		final List<Dashboard> boardPages = getDashboardDao().retrieveDashboards(this.userAccount.getUid(), 10, 0);
 	    assertEquals("Should be equals", boardPages.size(), 3);

File encuestame-utils/src/main/java/org/encuestame/utils/web/DashboardBean.java

+/*
+ ************************************************************************************
+ * Copyright (C) 2001-2010 encuestame: system online surveys Copyright (C) 2010
+ * 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.utils.web;
+
+import java.io.Serializable;
+
+/**
+ * Unit Dashboard.
+ * @author Morales, Diana Paola paolaATencuestame.org
+ * @since July 29, 2011
+ */
+public class DashboardBean implements Serializable {
+
+	/**
+	 * Serial
+	 */
+	private static final long serialVersionUID = 8091000998249747994L;
+
+	/** Dashboard id. **/
+	private Long dashboardId;
+
+	/** Dashboard name. **/
+	private String dashboardName;
+
+	/** Favorite dashboard. **/
+	private Boolean favorite;
+
+	/** Dashboard descrtiption. **/
+	private String dashboardDesc;
+
+	/** Dashboard layout. **/
+	private String layout;
+
+	/** Sequence. **/
+	private Integer sequence;
+
+	/** Favorite dashboard counter **/
+	private Integer favoriteCounter;
+
+	/** User**/
+	private UserAccountBean secUser;
+
+	/**
+	 * @return the dashboardId
+	 */
+	public Long getDashboardId() {
+		return dashboardId;
+	}
+
+	/**
+	 * @param dashboardId the dashboardId to set
+	 */
+	public void setDashboardId(final Long dashboardId) {
+		this.dashboardId = dashboardId;
+	}
+
+	/**
+	 * @return the dashboardName
+	 */
+	public String getDashboardName() {
+		return dashboardName;
+	}
+
+	/**
+	 * @param dashboardName the dashboardName to set
+	 */
+	public void setDashboardName(final String dashboardName) {
+		this.dashboardName = dashboardName;
+	}
+
+	/**
+	 * @return the favorite
+	 */
+	public Boolean getFavorite() {
+		return favorite;
+	}
+
+	/**
+	 * @param favorite the favorite to set
+	 */
+	public void setFavorite(final Boolean favorite) {
+		this.favorite = favorite;
+	}
+
+	/**
+	 * @return the dashboardDesc
+	 */
+	public String getDashboardDesc() {
+		return dashboardDesc;
+	}
+
+	/**
+	 * @param dashboardDesc the dashboardDesc to set
+	 */
+	public void setDashboardDesc(final String dashboardDesc) {
+		this.dashboardDesc = dashboardDesc;
+	}
+
+	/**
+	 * @return the layout
+	 */
+	public String getLayout() {
+		return layout;
+	}
+
+	/**
+	 * @param layout the layout to set
+	 */
+	public void setLayout(final String layout) {
+		this.layout = layout;
+	}
+
+	/**
+	 * @return the sequence
+	 */
+	public Integer getSequence() {
+		return sequence;
+	}
+
+	/**
+	 * @param sequence the sequence to set
+	 */
+	public void setSequence(final Integer sequence) {
+		this.sequence = sequence;
+	}
+
+	/**
+	 * @return the favoriteCounter
+	 */
+	public Integer getFavoriteCounter() {
+		return favoriteCounter;
+	}
+
+	/**
+	 * @param favoriteCounter the favoriteCounter to set
+	 */
+	public void setFavoriteCounter(Integer favoriteCounter) {
+		this.favoriteCounter = favoriteCounter;
+	}
+
+	/**
+	 * @return the secUser
+	 */
+	public UserAccountBean getSecUser() {
+		return secUser;
+	}
+
+	/**
+	 * @param secUser the secUser to set
+	 */
+	public void setSecUser(final UserAccountBean secUser) {
+		this.secUser = secUser;
+	}
+}

File encuestame-utils/src/test/java/org/encuestame/utils/AbstractBaseUtils.java

 
 import org.encuestame.utils.json.QuestionBean;
 import org.encuestame.utils.json.QuestionPatternBean;
+import org.encuestame.utils.web.DashboardBean;
 import org.encuestame.utils.web.QuestionAnswerBean;
 import org.encuestame.utils.web.UnitEmails;
 import org.encuestame.utils.web.UnitGroupBean;
 import org.encuestame.utils.web.UnitLocationTypeBean;
 import org.encuestame.utils.web.PollBean;
 import org.encuestame.utils.web.UnitProjectBean;
+import org.encuestame.utils.web.UserAccountBean;
 
 import junit.framework.TestCase;
 
         return unitEmails;
      }
 
+     /**
+      * Create unit poll complete.
+      * @param closeNotification
+      * @param completedPoll
+      * @param creationDate
+      * @param finishDate
+      * @param hashTags
+      * @param idPoll
+      * @param publishPoll
+      * @param questionBean
+      * @param showResultsPoll
+      * @return
+      */
      public PollBean createUnitPollComplete(
              final Boolean closeNotification,
              final Boolean completedPoll,
 
      }
 
+     /**
+      * Create dashboard bean.
+      * @param dashboardName
+      * @param dashboardDesc
+      * @param favorite
+      * @param layout
+      * @param sequence
+      * @param counter
+      * @return
+      */
+     public DashboardBean createDashboardBean(
+    		 final String dashboardName,
+    		 final String dashboardDesc,
+    		 final Boolean favorite,
+    		 final String layout,
+    		 final Integer sequence,
+    		 final Integer counter){
+    	 final DashboardBean dashboardBean = new DashboardBean();
+    	 dashboardBean.setDashboardName(dashboardName);
+    	 dashboardBean.setDashboardDesc(dashboardDesc);
+    	 dashboardBean.setFavorite(favorite);
+    	 dashboardBean.setLayout(layout);
+    	 dashboardBean.setSequence(sequence);
+    	 dashboardBean.setFavoriteCounter(counter);
+    	 return dashboardBean;
+     }
 }

File encuestame-utils/src/test/java/org/encuestame/utils/TestUnitBeans.java

 import java.util.Date;
 import java.util.HashSet;
 import java.util.List;
-
 import org.encuestame.utils.json.QuestionBean;
 import org.encuestame.utils.json.ResumeResultTweetPoll;
 import org.encuestame.utils.json.SocialAccountBean;
 import org.encuestame.utils.security.SignUpBean;
 import org.encuestame.utils.security.ForgotPasswordBean;
 import org.encuestame.utils.vote.UtilVoteCaptcha;
+import org.encuestame.utils.web.DashboardBean;
 import org.encuestame.utils.web.TypeTreeNode;
 import org.encuestame.utils.web.QuestionAnswerBean;
 import org.encuestame.utils.web.UnitCatStateBean;
         assertNotNull(oa.getAuthorizingAccountId());
     }
 
+    /**
+     * Test {@link DashboardBean}
+     */
+    @Test
+    public void testDashboardBean(){
+    	final DashboardBean boardBean = new DashboardBean();
+    	boardBean.setDashboardName("My Dashboard");
+    	boardBean.setDashboardDesc("My First Dashboard");
+    	boardBean.setFavorite(Boolean.TRUE);
+    	boardBean.setLayout("AAA");
+    	boardBean.setSequence(1);
+    	boardBean.setFavoriteCounter(5);
+    	//boardBean.setSecUser(create)
+    	 assertNotNull(boardBean.getDashboardName());
+    	 assertNotNull(boardBean.getDashboardDesc());
+    	 assertNotNull(boardBean.getFavorite());
+    	 assertNotNull(boardBean.getLayout());
+    	 assertNotNull(boardBean.getSequence());
+    }
 }