[jboss-svn-commits] JBL Code SVN: r8075 - in labs/jbosslabs/trunk/portal-extensions/polls: . src src/java/org/jboss/forge/polls src/java/org/jboss/forge/polls/exceptions src/java/org/jboss/forge/polls/service

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Tue Dec 5 17:50:11 EST 2006


Author: dejp
Date: 2006-12-05 17:49:55 -0500 (Tue, 05 Dec 2006)
New Revision: 8075

Added:
   labs/jbosslabs/trunk/portal-extensions/polls/src/java/org/jboss/forge/polls/exceptions/
   labs/jbosslabs/trunk/portal-extensions/polls/src/java/org/jboss/forge/polls/exceptions/NoSuchPollAnswerException.java
   labs/jbosslabs/trunk/portal-extensions/polls/src/java/org/jboss/forge/polls/service/
   labs/jbosslabs/trunk/portal-extensions/polls/src/java/org/jboss/forge/polls/service/PollAnswerDTO.java
   labs/jbosslabs/trunk/portal-extensions/polls/src/java/org/jboss/forge/polls/service/PollAnswerEntity.java
   labs/jbosslabs/trunk/portal-extensions/polls/src/java/org/jboss/forge/polls/service/PollDTO.java
   labs/jbosslabs/trunk/portal-extensions/polls/src/java/org/jboss/forge/polls/service/PollEntity.java
   labs/jbosslabs/trunk/portal-extensions/polls/src/java/org/jboss/forge/polls/service/PollVoteEntity.java
   labs/jbosslabs/trunk/portal-extensions/polls/src/java/org/jboss/forge/polls/service/PollsService.java
   labs/jbosslabs/trunk/portal-extensions/polls/src/java/org/jboss/forge/polls/service/PollsServiceImpl.java
   labs/jbosslabs/trunk/portal-extensions/polls/src/persistence.xml
Modified:
   labs/jbosslabs/trunk/portal-extensions/polls/maven.xml
   labs/jbosslabs/trunk/portal-extensions/polls/project.properties
   labs/jbosslabs/trunk/portal-extensions/polls/project.xml
   labs/jbosslabs/trunk/portal-extensions/polls/src/java/org/jboss/forge/polls/PollDescriptor.java
   labs/jbosslabs/trunk/portal-extensions/polls/src/java/org/jboss/forge/polls/PollTools.java
   labs/jbosslabs/trunk/portal-extensions/polls/src/java/org/jboss/forge/polls/PollsDescriptor.java
   labs/jbosslabs/trunk/portal-extensions/polls/src/java/org/jboss/forge/polls/PollsPortlet.java
   labs/jbosslabs/trunk/portal-extensions/polls/src/java/org/jboss/forge/polls/PollsWatcher.java
Log:
polls in database

Modified: labs/jbosslabs/trunk/portal-extensions/polls/maven.xml
===================================================================
--- labs/jbosslabs/trunk/portal-extensions/polls/maven.xml	2006-12-05 19:51:38 UTC (rev 8074)
+++ labs/jbosslabs/trunk/portal-extensions/polls/maven.xml	2006-12-05 22:49:55 UTC (rev 8075)
@@ -7,15 +7,32 @@
 	<!-- Default war-project goals -->
 
 	<goal name="all">
-		<attainGoal name="prj-all" />
+		<!--attainGoal name="prj-all" /-->
+		<attainGoal name="clean" />
+		<attainGoal name="build" />
+		<attainGoal name="deploy" />
 	</goal>
 
 	<goal name="build">
-		<attainGoal name="prj-war-build" />
+		<!--attainGoal name="prj-war-build" /-->
+		<attainGoal name="war" />
+		
+		<ant:copy todir="target/classes/META-INF">
+			<ant:fileset dir="src">
+				<ant:filename name="persistence.xml" />
+			</ant:fileset>
+		</ant:copy>
+		<!--attainGoal name="ejb" />
+		<ant:move file="target/polls-portlet-1.0.jar"  tofile="target/polls-portlet-1.0.ejb3" /-->
+		
+		<attainGoal name="jar" />
 	</goal>
     
 	<goal name="deploy">	
-		<attainGoal name="prj-war-deploy" />
+		<!--attainGoal name="prj-war-deploy" /-->
+		<ant:copy tofile="${local.deploy.dir}/polls-commons.jar" file="target/polls-portlet-1.0.jar" />
+		<ant:copy tofile="${local.deploy.dir}/polls-portlet.war" file="target/polls-portlet.war" />
+		<!--ant:copy tofile="${local.deploy.dir}/polls.ejb3" file="target/polls-portlet-1.0.ejb3" /-->
 	</goal>
 	
 	<goal name="clean">

Modified: labs/jbosslabs/trunk/portal-extensions/polls/project.properties
===================================================================
--- labs/jbosslabs/trunk/portal-extensions/polls/project.properties	2006-12-05 19:51:38 UTC (rev 8074)
+++ labs/jbosslabs/trunk/portal-extensions/polls/project.properties	2006-12-05 22:49:55 UTC (rev 8075)
@@ -1,3 +1,7 @@
 maven.repo.remote=http://repository.atlassian.com,http://www.ibiblio.org/maven,http://dist.codehaus.org/
 maven.junit.fork=yes
 maven.war.src=${basedir}/src/web
+#maven.ejb.includes=**/service/*.class, **/META-INF/persistence.xml
+#maven.jar.excludes=**/PollsPortlet.class, **/service/*.class, **/META-INF/persistence.xml
+maven.jar.excludes=**/PollsPortlet.class
+maven.war.classes.includes=**/PollsPortlet.class
\ No newline at end of file

Modified: labs/jbosslabs/trunk/portal-extensions/polls/project.xml
===================================================================
--- labs/jbosslabs/trunk/portal-extensions/polls/project.xml	2006-12-05 19:51:38 UTC (rev 8074)
+++ labs/jbosslabs/trunk/portal-extensions/polls/project.xml	2006-12-05 22:49:55 UTC (rev 8075)
@@ -17,51 +17,51 @@
     <description></description>
     
     <dependencies>
-	<dependency>
-	    <groupId>jboss-forge</groupId>
-	    <artifactId>forge-common</artifactId>
-	    <version>1.0</version>
-	</dependency>
+		<dependency>
+	    	<groupId>jboss-forge</groupId>
+		    <artifactId>forge-common</artifactId>
+		    <version>1.0</version>
+		</dependency>
 
-	<dependency>
-	    <groupId>taglibs</groupId>
-	    <artifactId>jstl</artifactId>
-	    <version>1.0</version>
-	    <jar>jstl.jar</jar>
-	    <properties>
-	    	<war.bundle>true</war.bundle>
-	    </properties>
-	</dependency>
+		<dependency>
+	    	<groupId>taglibs</groupId>
+		    <artifactId>jstl</artifactId>
+		    <version>1.0</version>
+	    	<jar>jstl.jar</jar>
+	    	<properties>
+	    		<war.bundle>true</war.bundle>
+		    </properties>
+		</dependency>
 
-	<dependency>
-	    <groupId>taglibs</groupId>
-	    <artifactId>standard</artifactId>
-	    <version>1.0</version>
-	    <jar>standard.jar</jar>
-	    <properties>
-	    	<war.bundle>true</war.bundle>
-	    </properties>
-	</dependency>
+		<dependency>
+		    <groupId>taglibs</groupId>
+		    <artifactId>standard</artifactId>
+		    <version>1.0</version>
+		    <jar>standard.jar</jar>
+		    <properties>
+		    	<war.bundle>true</war.bundle>
+		    </properties>
+		</dependency>
 
-	<dependency>
-	    <groupId>xerces</groupId>
-	    <artifactId>xercesImpl</artifactId>
-	    <version>2.6.2</version>
-	</dependency>
+		<dependency>
+		    <groupId>xerces</groupId>
+		    <artifactId>xercesImpl</artifactId>
+		    <version>2.6.2</version>
+		</dependency>
 
-	<dependency>
-	    <groupId>xerces</groupId>
-	    <artifactId>xmlParserAPIs</artifactId>
-	    <version>2.6.2</version>
-	</dependency>
+		<dependency>
+		    <groupId>xerces</groupId>
+		    <artifactId>xmlParserAPIs</artifactId>
+		    <version>2.6.2</version>
+		</dependency>
 
-	<dependency>
-	    <groupId>xalan</groupId>
-	    <artifactId>xalan</artifactId>
-	    <version>2.6.0</version>
-	</dependency>
+		<dependency>
+		    <groupId>xalan</groupId>
+		    <artifactId>xalan</artifactId>
+		    <version>2.6.0</version>
+		</dependency>
 	
-	<dependency>
+		<dependency>
             <id>rome</id>
             <version>0.5</version>
         </dependency>
@@ -70,5 +70,68 @@
             <id>jdom</id>
             <version>1.0</version>
         </dependency>
+
+		<dependency>
+			<groupId>jboss</groupId>
+			<artifactId>ejb3-persistence</artifactId>
+			<version>3.0RC6</version>
+			<jar>ejb3-persistence.jar</jar>
+        </dependency>
+	
+		<dependency>
+			<groupId>jboss</groupId>
+			<artifactId>jboss-ejb3x</artifactId>
+			<version>3.0RC6</version>
+			<jar>jboss-ejb3x.jar</jar>
+    	</dependency>
+    
+	    <dependency>
+		    <groupId>jboss</groupId>
+		    <artifactId>jboss-j2ee</artifactId>
+		    <version></version>
+		    <jar>jboss-j2ee.jar</jar>
+    	</dependency>
+    
+	    <dependency>
+			<groupId>jboss</groupId>
+			<artifactId>jboss-annotations-ejb3</artifactId>
+			<version>1.0</version>
+			<jar>jboss-annotations-ejb3.jar</jar>
+		</dependency>
+
+    	<dependency>
+    		<groupId>jaxb</groupId>
+    		<artifactId>JAXB2</artifactId>
+    		<version>2.0</version>
+    		<jar>jaxb-api.jar</jar>
+		</dependency>
+
+        <dependency>
+   		    <groupId>jaxb</groupId>
+   		    <artifactId>JAXB2173API</artifactId>
+   		    <version>1.0</version>
+   		    <jar>jsr173_1.0_api.jar</jar>
+   	    </dependency>
+
+		<dependency>
+		    <groupId>jaxb</groupId>
+		    <artifactId>Activation</artifactId>
+	    	<version>1.0</version>
+		    <jar>activation.jar</jar>
+    	</dependency>
+    	
+	    <dependency>
+		    <groupId>jaxb</groupId>
+	    	<artifactId>JAXBIMPL</artifactId>
+		    <version>2.0</version>
+		    <jar>jaxb-impl.jar</jar>
+	    </dependency>
+    	
+	    <dependency>
+		    <groupId>jaxb</groupId>
+		    <artifactId>XJC</artifactId>
+		    <version>2.0</version>
+	    	<jar>jaxb-xjc.jar</jar>
+	    </dependency>        
     </dependencies>
 </project>

Modified: labs/jbosslabs/trunk/portal-extensions/polls/src/java/org/jboss/forge/polls/PollDescriptor.java
===================================================================
--- labs/jbosslabs/trunk/portal-extensions/polls/src/java/org/jboss/forge/polls/PollDescriptor.java	2006-12-05 19:51:38 UTC (rev 8074)
+++ labs/jbosslabs/trunk/portal-extensions/polls/src/java/org/jboss/forge/polls/PollDescriptor.java	2006-12-05 22:49:55 UTC (rev 8075)
@@ -35,6 +35,7 @@
 import org.jboss.forge.common.XmlTools;
 import org.jboss.forge.common.projects.AbstractDescriptor;
 import org.jboss.forge.common.projects.XmlInputFactory.XmlNotFoundException;
+import org.jboss.forge.polls.service.PollDTO;
 import org.w3c.dom.Document;
 import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
@@ -52,7 +53,7 @@
 	/**
 	 * This variable contains all polls containing questions from the xml descriptor.
 	 */
-	private List<Poll> polls;
+	private List<PollDTO> polls;
 	
 	/**
 	 * Name of tag in poll.xml containing poll's question.
@@ -102,7 +103,7 @@
          * 		</poll>
          * </polls>
          */
-        polls = new LinkedList<Poll>();
+        polls = new LinkedList<PollDTO>();
         for (int i = 0; i < nodes.getLength(); i++) {
             n = nodes.item(i);
             if (n.getNodeType() == Node.ELEMENT_NODE) {
@@ -128,8 +129,9 @@
                     	}
                     }
                     // Checking if all needed information was collected and then creating Poll.
-                    if (tempQuestion!=null && !tempQuestion.equals("") && tempAnswers.size()>0) {
-                    	polls.add(new Poll(tempAnswers,tempQuestion,Integer.toString((int)(Math.random()*99999999))));
+                    if (tempQuestion!=null && !tempQuestion.equals("") && tempAnswers.size() > 0) {
+                    	//polls.add(new PollDTO(tempAnswers,tempQuestion,Integer.toString((int)(Math.random()*99999999))));
+                    	polls.add(new PollDTO(tempQuestion, tempAnswers));
                     }
                 }
             }
@@ -141,7 +143,7 @@
 	 * @return
 	 * 		List<Poll> of polls achieved from the descriptor.
 	 */
-	public List<Poll> getPolls () {
+	public List<PollDTO> getPolls () {
 		return polls;
 	}
 	

Modified: labs/jbosslabs/trunk/portal-extensions/polls/src/java/org/jboss/forge/polls/PollTools.java
===================================================================
--- labs/jbosslabs/trunk/portal-extensions/polls/src/java/org/jboss/forge/polls/PollTools.java	2006-12-05 19:51:38 UTC (rev 8074)
+++ labs/jbosslabs/trunk/portal-extensions/polls/src/java/org/jboss/forge/polls/PollTools.java	2006-12-05 22:49:55 UTC (rev 8075)
@@ -24,23 +24,20 @@
 package org.jboss.forge.polls;
 
 import java.io.File;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.LinkedHashMap;
-import java.util.LinkedList;
 import java.util.List;
-import java.util.Map;
-import java.util.Random;
-import java.util.Set;
 
+import javax.management.MalformedObjectNameException;
 import javax.portlet.PortletURL;
 
 import org.jboss.forge.common.ForgeHelper;
 import org.jboss.forge.common.projects.ProjectsHelper;
+import org.jboss.forge.polls.exceptions.NoSuchPollAnswerException;
+import org.jboss.forge.polls.service.PollAnswerDTO;
+import org.jboss.forge.polls.service.PollDTO;
+import org.jboss.forge.polls.service.PollsService;
+import org.jboss.logging.Logger;
+import org.jboss.mx.util.MBeanProxyExt;
+import org.jboss.mx.util.MBeanServerLocator;
 import org.jboss.portal.common.context.DelegateContext;
 import org.jboss.portlet.JBossRenderResponse;
 import org.jboss.shotoku.ContentManager;
@@ -54,6 +51,11 @@
 public class PollTools {
 	
 	/**
+	 * Class logger.
+	 */
+	private static Logger logger = Logger.getLogger(PollTools.class);
+	
+	/**
 	 * Name of the request parameter which tells if user voted.
 	 */
 	public static final String VOTED_PARAMETER_NAME = "voted";
@@ -68,7 +70,6 @@
 	 */
 	public static final String POLLID_PARAMETER_NAME = "pollId";	
 	
-	
 	/**
 	 * Name of the request parameter which contains projectId.
 	 */
@@ -220,7 +221,7 @@
 		return POLLS_DIR + File.separator + POLLS_VOTING_JSP;
 	}
 	
-	/**
+	/*
 	 * Method adds randomly selected polls with their projectIds to the Map/
 	 * @param numberOfPolls
 	 * 		Number of polls which is requested to be received.
@@ -230,10 +231,10 @@
 	 * 		ContentManager
 	 * @return
 	 * 		Map<String,String> containing randomly selected polls.
-	 */
+	 *
 	public static Map<String,String> getRandomPolls (int numberOfPolls,String portalName,ContentManager cm) {
         
-                // In this Map I will collect randomly selected pollId:projectId pairs.
+        // In this Map I will collect randomly selected pollId:projectId pairs.
 		Map<String,String> randomPolls = new HashMap<String,String>();
 		
 		PollsDescriptor desc = getDesc(portalName,cm);
@@ -267,8 +268,16 @@
                         projectIdsForPollIds.remove(item);
 		}
 		return randomPolls;
-	}
+	}*/
 	
+	/*public static Map<String,String> getRandomPolls(int numberOfPolls) throws MalformedObjectNameException {
+
+		PollsService pollsService = (PollsService) MBeanProxyExt.create(PollsService.class, 
+				PollsService.POLLS_SERVICE, MBeanServerLocator.locate());
+		
+		return pollsService.getRandomPolls(numberOfPolls);
+	}*/
+	
 	/**
 	 * This method returns one of the projectId names which have defined polls.
 	 * @param portalName
@@ -317,7 +326,7 @@
 	 * @return
 	 * 			Content context for information JSP page.
 	 */
-	public static DelegateContext getInfoContext (final String portalName,final String projectId,
+	/*public static DelegateContext getInfoContext (final String portalName,final String projectId,
 			ContentManager cm,JBossRenderResponse response, String pollIdSpecified) {
 		
 		//	  If the projectId is null method returns empty DelegateContext object.
@@ -342,7 +351,7 @@
 		}
 		
 		// Getting the polls for given projectId.
-		Map<String,Poll> values = desc.getPollsStatsForProject(projectId);
+		Map<String,PollDTO> values = desc.getPollsStatsForProject(projectId);
 		
 		if (pollIdSpecified!=null) {
 			Set<String> retaininingPoll = new HashSet<String>(1);
@@ -365,8 +374,8 @@
 		 * 		</poll>
 		 * </polls>
 		 */
-		DelegateContext polls = ctx.next("polls");
-		Poll temporary=null;
+		/*DelegateContext polls = ctx.next("polls");
+		PollDTO temporary=null;
 		for (String pollId:values.keySet()) {
 			PortletURL url = response.createRenderURL();
 			DelegateContext poll = polls.next("poll");
@@ -385,6 +394,53 @@
 			}
 		}
 		return ctx;
+	}*/
+
+	public static DelegateContext getInfoContext(String pollIdSpecified, JBossRenderResponse response) {
+		
+		// Creating new empty context.
+		DelegateContext ctx = new DelegateContext();
+		
+		// Filling the context for portlet.
+		/**
+		 * Context structure:
+		 * <polls>1..1
+		 * 		<poll>0..*
+		 * 			<question />1..1
+		 * 			<renderUrl/>1..1
+		 * 			<renderUrlDetailed />1..1
+		 * 			<answers>0..*
+		 * 				<votes />1..1
+		 * 				<text />1..1
+		 * 			</answers>
+		 * 		</poll>
+		 * </polls>
+		 */
+		PollDTO poll = null;
+		try {
+			poll = getPollsService().getPollWithDetails(Integer.valueOf(pollIdSpecified));
+		} catch (MalformedObjectNameException e) {
+			logger.error(e.getMessage(), e);
+		}
+		
+		DelegateContext pollsCtx = ctx.next("polls");
+		if (poll != null) {
+			PortletURL url = response.createRenderURL();
+			DelegateContext pollCtx = pollsCtx.next("poll");
+			pollCtx.put("question", poll.getQuestion());
+			pollCtx.put("renderUrl", url.toString());
+			url.setParameter(POLLID_PARAMETER_NAME, poll.getPollId());
+			url.setParameter(DETAILED_VIEW_REQUEST, TRUE);
+			url.setParameter(PROJECTID_PARAMETER_NAME, poll.getProjectId());
+			pollCtx.put("renderUrlDetailed", url.toString());
+			
+			for (PollAnswerDTO answer : poll.getAnswers()) {
+				 DelegateContext answersCtx = pollCtx.next("answers");
+				 answersCtx.put("votes", answer.getVotes());
+				 answersCtx.put("text", answer.getAnswer());
+			}
+		}
+		return ctx;
 	}
 	
 	/**
@@ -403,7 +459,7 @@
 	 * @return
 	 * 			Content context for detailed information JSP page.
 	 */
-	public static DelegateContext getDetailsContext (final String portalName,final String projectId,
+	/*public static DelegateContext getDetailsContext (final String portalName,final String projectId,
 			final String pollId, ContentManager cm,JBossRenderResponse response) {
 		
 		//	  If the projectId is null method returns empty DelegateContext object.
@@ -450,9 +506,9 @@
 		 * 		</answer>
 		 * </poll>
 		 */
-		DelegateContext poll = ctx.next("poll");
+		/*DelegateContext poll = ctx.next("poll");
 		
-		Poll tempPoll = desc.getPoll(projectId,pollId);
+		PollDTO tempPoll = desc.getPoll(projectId,pollId);
 		poll.put("question",tempPoll!=null?tempPoll.getQuestion():"");
 		PortletURL url = response.createRenderURL();
 		poll.put("renderUrlVoting",url.toString());
@@ -475,6 +531,63 @@
 			
 		return ctx;
 		
+	}*/
+
+	public static DelegateContext getDetailsContext(final String projectId, 
+			final String pollId, JBossRenderResponse response) {
+		//	If the projectId is null method returns empty DelegateContext object.
+		if (projectId == null) {
+			return new DelegateContext();
+		}
+		
+		// Creating new empty context.
+		DelegateContext ctx = new DelegateContext();
+		
+		/**
+		 * Context structure:
+		 * <poll>1..1
+		 * 		<question />1..1
+		 * 		<renderUrlVoting />1..1
+		 * 		<renderUrlInfo />1..1
+		 * 		<answer>0..*
+		 * 			<text />1..1
+		 * 			<user>1..*
+		 * 				<id />1..1
+		 * 			</user>
+		 * 		</answer>
+		 * </poll>
+		 */
+		PollDTO poll = null;
+		try {
+			poll = getPollsService().getPollWithDetails(Integer.valueOf(pollId));
+		} catch (MalformedObjectNameException e) {
+			logger.error(e.getMessage(), e);
+		}
+		
+		if (poll == null) {
+			return ctx;
+		}
+		
+		DelegateContext pollCtx = ctx.next("poll");
+		
+		pollCtx.put("question", poll != null ? poll.getQuestion() : "");
+		PortletURL url = response.createRenderURL();
+		pollCtx.put("renderUrlVoting",url.toString());
+		url.setParameter(VOTED_PARAMETER_NAME, TRUE);
+		url.setParameter(POLLID_PARAMETER_NAME, pollId);
+		url.setParameter(PROJECTID_PARAMETER_NAME, projectId);
+		pollCtx.put("renderUrlInfo", url.toString());
+		
+		for (PollAnswerDTO answer : poll.getAnswers()) {
+			DelegateContext answerCtx = pollCtx.next("answer");
+			answerCtx.put("text", answer.getAnswer());
+			for (String user : answer.getUserIds()) {
+				DelegateContext userCtx = answerCtx.next("user");
+					userCtx.put("id", user);
+			}
+			
+		}
+		return ctx;
 	}
 	
 	/**
@@ -491,7 +604,7 @@
 	 * @return
 	 * 			Content context for detailed information JSP page.
 	 */
-	public static DelegateContext getVotingContext (String portalName, String projectId,
+	/*public static DelegateContext getVotingContext (String portalName, String projectId,
 			String error, ContentManager cm,JBossRenderResponse response, Map<String,String> specifiedPolls) {
 		
 		// If the projectId is null method returns empty DelegateContext object.
@@ -516,10 +629,10 @@
 			return ctx;
 		}
 			
-		List<Poll> pollDesc=null;
+		List<PollDTO> pollDesc=null;
 		
 		if (specifiedPolls!=null && specifiedPolls.size()>0) {
-			pollDesc = new LinkedList<Poll>();
+			pollDesc = new LinkedList<PollDTO>();
 			for (String pollIdString : specifiedPolls.keySet()) {
 				pollDesc.add(desc.getPoll(specifiedPolls.get(pollIdString),pollIdString));
 			}
@@ -542,16 +655,18 @@
 		 * 		</poll>
 		 * </polls>
 		 */
-		DelegateContext polls = ctx.next("polls");
+		/*DelegateContext polls = ctx.next("polls");
 		if (error!=null && !error.equals("")) {
 			polls.put("error",error);
 		}
-		for (Poll pollObj : pollDesc) {
-			
+		
+		for (PollDTO pollObj : pollDesc) {
 			DelegateContext poll = polls.next("poll");
+
 			if (specifiedPolls!=null && specifiedPolls.size()>0) {
 				projectId = specifiedPolls.get(pollObj.getPollId());
 			}
+			
 			poll.put("question",pollObj.getQuestion());
 			poll.put("actionUrl",response.createActionURL().toString());
 			PortletURL url = response.createRenderURL();
@@ -568,6 +683,109 @@
 			}
 		}
 		return ctx;
+	}*/
+
+	public static DelegateContext getVotingContext (String error, JBossRenderResponse response, List<PollDTO> specifiedPolls) {
+		// Creating new empty context.
+		DelegateContext ctx = new DelegateContext();
+		
+		// If the projectId is null method returns empty DelegateContext object.
+		if (specifiedPolls == null || (specifiedPolls != null && specifiedPolls.size() == 0)) {
+			return ctx;
+		}
+		
+		// Filling the context for portlet.
+		/**
+		 * Context structure:
+		 * <polls>1..1
+		 * 		<error>0..1
+		 * 		<poll>0..*
+		 * 			<question>1..1
+		 * 			<actionUrl>1..1
+		 * 			<pollId>1..1
+		 * 			<answer>0..*
+		 * 				<text />1..1
+		 * 			</answer>
+		 * 		</poll>
+		 * </polls>
+		 */
+		DelegateContext pollsCtx = ctx.next("polls");
+		if (error!=null && !error.equals("")) {
+			pollsCtx.put("error", error);
+		}
+		
+		String projectId;
+		for (PollDTO poll : specifiedPolls) {
+			
+			DelegateContext pollCtx = pollsCtx.next("poll");
+
+			projectId = poll.getProjectId();
+			
+			pollCtx.put("question", poll.getQuestion());
+			pollCtx.put("actionUrl", response.createActionURL().toString());
+			PortletURL url = response.createRenderURL();
+			url.setParameter(VOTED_PARAMETER_NAME, TRUE);
+			url.setParameter(POLLID_PARAMETER_NAME, poll.getPollId());
+			url.setParameter(PROJECTID_PARAMETER_NAME, projectId);
+			pollCtx.put("renderUrlInfo", url.toString());
+			pollCtx.put("pollId", poll.getPollId());
+			pollCtx.put("project", projectId);
+			
+			for (PollAnswerDTO answer : poll.getAnswers()) {
+				DelegateContext answerCtx = pollCtx.next("answer");
+				answerCtx.put("answerId", answer.getAnswerId());
+				answerCtx.put("text", answer.getAnswer());
+			}
+		}
+		return ctx;
 	}
 	
+	public static boolean voteOnPoll(String answerId, String userId) 
+		throws MalformedObjectNameException, NoSuchPollAnswerException {
+			return getPollsService().voteOnPoll(answerId, userId);
+	}
+	
+	public static List<PollDTO> getRandomPolls(int numberOfPolls) throws MalformedObjectNameException {
+		List<PollDTO> polls = null;
+		try {
+			polls = getPollsService().getRandomPolls(numberOfPolls);
+		} catch (MalformedObjectNameException e) {
+			logger.error(e.getMessage(), e);
+		}
+		
+		return polls;
+	}
+	
+	public static List<PollDTO> getAllPolls() {
+		List<PollDTO> polls = null;
+		try {
+			polls = getPollsService().getAllPolls();
+		} catch (MalformedObjectNameException e) {
+			logger.error(e.getMessage(), e);
+		}
+		
+		return polls;
+	}
+	
+	public static void addPollsForVoting(List<PollDTO> polls) {
+		try {
+			getPollsService().addPollsForVoting(polls);
+		} catch (MalformedObjectNameException e) {
+			logger.error(e.getMessage(), e);
+		}
+	}
+	
+	public static void removePollsFromVoting(List<PollDTO> polls) {
+		try {
+			getPollsService().removePollsFromVoting(polls);
+		} catch (MalformedObjectNameException e) {
+			logger.error(e.getMessage(), e);
+		}
+	}
+	
+    public static PollsService getPollsService() throws MalformedObjectNameException {
+   		return (PollsService) MBeanProxyExt.create(PollsService.class,
+			PollsService.POLLS_SERVICE, MBeanServerLocator.locate());
+    }
+    
 }

Modified: labs/jbosslabs/trunk/portal-extensions/polls/src/java/org/jboss/forge/polls/PollsDescriptor.java
===================================================================
--- labs/jbosslabs/trunk/portal-extensions/polls/src/java/org/jboss/forge/polls/PollsDescriptor.java	2006-12-05 19:51:38 UTC (rev 8074)
+++ labs/jbosslabs/trunk/portal-extensions/polls/src/java/org/jboss/forge/polls/PollsDescriptor.java	2006-12-05 22:49:55 UTC (rev 8075)
@@ -24,7 +24,6 @@
 package org.jboss.forge.polls;
 
 import java.io.File;
-import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Hashtable;
@@ -34,11 +33,11 @@
 import java.util.Map;
 import java.util.Set;
 
-import org.apache.xerces.parsers.DOMParser;
 import org.jboss.forge.common.XmlTools;
 import org.jboss.forge.common.projects.AbstractDescriptor;
-import org.jboss.forge.common.projects.DomToXmlTransformer;
 import org.jboss.forge.common.projects.ProjectsHelper;
+import org.jboss.forge.polls.service.PollAnswerDTO;
+import org.jboss.forge.polls.service.PollDTO;
 import org.jboss.logging.Logger;
 import org.jboss.shotoku.ContentManager;
 import org.jboss.shotoku.Directory;
@@ -46,7 +45,6 @@
 import org.w3c.dom.Document;
 import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
-import org.xml.sax.InputSource;
 
 /**
  * Main class for Polls project. It is an image of main Polls xml file, polls.xml.
@@ -101,7 +99,7 @@
 	 * This Map contains all polls for the portal.
 	 * Keys are project id names and values are Lists of polls defined for that project.
 	 */
-	private Map<String,List<Poll>> polls;
+	private Map<String,List<PollDTO>> polls;
 	
 	/**
 	 * ContentManager is used for getting to file resources.
@@ -135,7 +133,6 @@
 	 * @param contentManager
 	 */
 	public PollsDescriptor (final String portalName, ContentManager contentManager) {
-		
 		// Just initializing the changeStatus variable to true so that the file is saved after all modifications.
 		changeStatus=true;
 		
@@ -143,7 +140,7 @@
 		logger = Logger.getLogger(this.getClass());
 		
 		// Getting the path to main polls descriptor.
-		String pathToPollsXml = File.separator + PollTools.getMainXmlPath(portalName);
+		//String pathToPollsXml = File.separator + PollTools.getMainXmlPath(portalName);
         
 		// Saving the ContentManager.
 		this.contentManager = contentManager;
@@ -151,15 +148,15 @@
 		try {
 
 			// Constructing object used for getting to Poll's database.
-			database = new PollVotesDatabase();
+			//database = new PollVotesDatabase();
 			
 			// Parsing main download counters descriptor.
-			DOMParser parser = new DOMParser();
+			/*DOMParser parser = new DOMParser();
 			InputStream is = contentManager.getNode(pathToPollsXml).getContentInputStream();
 			parser.parse(new InputSource(is));
 			Document doc = parser.getDocument();
 			NodeList nodes = doc.getDocumentElement().getChildNodes();
-       		polls=getValuesFromNodes(nodes);
+       		polls=getValuesFromNodes(nodes);*/
        		
        		// Getting Map containing pairs of ProjectId and shotoku Node
        		// which refers to projects' poll descriptor.
@@ -169,7 +166,7 @@
        		// projects' poll descriptors. 
        		synchronizePolls(descriptors);
        		
-       		synchronizeWithFile(portalName);
+       		//synchronizeWithFile(portalName);
 
 		} catch (Exception e) {
 			logger.error ("Failed to initialize Polls.",e);
@@ -182,9 +179,9 @@
 	 * @param projectId
 	 * @return
 	 */
-	public synchronized List<Poll> getPollsInfoForProject(String projectId) {
-		List<Poll> polls = getProjectPolls(projectId);
-		List<Poll> pollsCopy = new ArrayList<Poll>(polls.size());
+	public synchronized List<PollDTO> getPollsInfoForProject(String projectId) {
+		List<PollDTO> polls = getProjectPolls(projectId);
+		List<PollDTO> pollsCopy = new ArrayList<PollDTO>(polls.size());
 		pollsCopy.addAll(polls);
 		return pollsCopy;
 	}
@@ -197,16 +194,16 @@
 	 * @return
 	 * 		Map<String,Polls> pairs of pollId:Poll.
 	 */
-	public synchronized Map<String,Poll> getPollsStatsForProject(String projectId) {
-		List<Poll> polls = getProjectPolls(projectId);
-		Map<String,Poll> values = null;
+	public synchronized Map<String,PollDTO> getPollsStatsForProject(String projectId) {
+		List<PollDTO> polls = getProjectPolls(projectId);
+		Map<String,PollDTO> values = null;
 		if (polls!=null) {
-			values = new Hashtable<String,Poll>(polls.size());
-			for (Poll poll:polls){
+			values = new Hashtable<String,PollDTO>(polls.size());
+			for (PollDTO poll:polls){
 				values.put(poll.getPollId(),poll);
 			}
 		} else {
-			values = new Hashtable<String,Poll>();
+			values = new Hashtable<String,PollDTO>();
 		}
 		return values;
 	}
@@ -275,7 +272,7 @@
 	 * 		This Map<Strin,org.jboss.shotoku.Node> contains project ids with their download
 	 * 		counter descriptor's Node.
 	 */
-	private void synchronizePolls (Map<String,org.jboss.shotoku.Node> projectPolls) {
+	/*private void synchronizePolls (Map<String,org.jboss.shotoku.Node> projectPolls) {
 		
 		// Checking if tracked projects still have their poll.xml descriptors.
 		// If not deleting all tracked polls for them.
@@ -289,21 +286,21 @@
 					new PollDescriptor(projectPolls.get(projectId));
 				
 				// Getting list of polls from polls Map for a given projectId name.
-				List<Poll> xmlProjectPolls = getProjectPolls(projectId);
+				List<PollDTO> xmlProjectPolls = getProjectPolls(projectId);
 				
 				if (xmlProjectPolls==null) {
-					xmlProjectPolls= new LinkedList<Poll>();
+					xmlProjectPolls= new LinkedList<PollDTO>();
 				}
 				
 				// Getting the list of polls from project's poll descriptor.
-				List<Poll> descPolls = pollDesc.getPolls();
+				List<PollDTO> descPolls = pollDesc.getPolls();
 				
 				// This list will be used for collecting questions which must be
 				// removed from polls Map.
-				List<Poll> pollsToDelete = new LinkedList<Poll>();
+				List<PollDTO> pollsToDelete = new LinkedList<PollDTO>();
 				
 				// Searching for polls to remove and polls which are already added.
-				for (Poll poll:xmlProjectPolls) {
+				for (PollDTO poll:xmlProjectPolls) {
 					if (descPolls.contains(poll)) {
 						descPolls.remove(poll);
 					} else {
@@ -324,7 +321,7 @@
 		// Changing status to false becouse polls Map
 		// is now synchronized with projects' polls descriptors.
 		changeStatus=false;
-	}
+	}*/
 	
 	/**
 	 * Method remmoves all Polls which are not contained in 
@@ -341,9 +338,9 @@
 			}
 		}
 		for (String projectId : projectsToDelete) {
-			List<Poll> pollObjects = polls.get(projectId);
+			List<PollDTO> pollObjects = polls.get(projectId);
 			if (pollObjects !=null && pollObjects.size()>0){
-				for (Poll poll : pollObjects ){
+				for (PollDTO poll : pollObjects ){
 					database.removePollDataFile(poll.getPollId());
 				}
 			}
@@ -374,12 +371,12 @@
 	 * @return
 	 * 		Poll object.
 	 */
-	public synchronized Poll getPoll (String projectId,String pollId) {
+	public synchronized PollDTO getPoll (String projectId,String pollId) {
 		if (projectId!=null && pollId!=null &&
 				!projectId.equals("") && !pollId.equals("") && polls!=null) {
-			List<Poll> list = polls.get(projectId);
+			List<PollDTO> list = polls.get(projectId);
 			if (list==null) return null;
-			for (Poll poll : list) {
+			for (PollDTO poll : list) {
 				if (poll.getPollId().equals(pollId)) {
 					return poll;
 				}
@@ -395,13 +392,13 @@
 	 * @param pollsToDelete
 	 * 		List<String> of polls which should be removed.
 	 */
-	private synchronized void removePollsFromVoting (List<Poll> pollsToDelete,final String projectId) {
+	/*private synchronized void removePollsFromVoting (List<PollDTO> pollsToDelete,final String projectId) {
 		// Removing polls which shouldn't be tracked any more.
-		for (Poll poll:pollsToDelete) {
+		for (PollDTO poll:pollsToDelete) {
 			database.removePollDataFile(poll.getPollId());
 			polls.get(projectId).remove(poll);
 		}
-	}
+	}*/
 	
 	/**
 	 * Method adds polls which are wished to be tracked.
@@ -411,18 +408,18 @@
 	 * @param projectId
 	 * 		Project id name for which polls containing the questions are added.
 	 */
-	private synchronized void addPollsForVoting (List<Poll> newPolls,String projectId) {
+	/*private synchronized void addPollsForVoting (List<PollDTO> newPolls,String projectId) {
 		// Adding new project id name with ArrayList<Poll> values.
 		if (polls.get(projectId)==null) {
-			polls.put(projectId,new ArrayList<Poll>());
+			polls.put(projectId,new ArrayList<PollDTO>());
 		}
-		for (Poll poll:newPolls) {
+		for (PollDTO poll:newPolls) {
 			if (!polls.get(projectId).contains(poll)){
 				polls.get(projectId).add(poll);
 				database.createNewPollFile(poll.getPollId());
 			}
 		}
-	}
+	}*/
 	
 	/**
 	 * This method returns a List<Poll> of Poll-s, which
@@ -432,7 +429,7 @@
 	 * 		Id of a project for which polls will be searched.
 	 * @return List<Poll> Containing tracked questions or null.
 	 */
-	private synchronized List<Poll> getProjectPolls (String projectId) {
+	private synchronized List<PollDTO> getProjectPolls (String projectId) {
 		return polls.get(projectId);
 	}
 	
@@ -441,7 +438,7 @@
 	 * 
 	 * @param portalName
 	 */
-	public void synchronizeWithFile(String portalName) {
+	/*public void synchronizeWithFile(String portalName) {
 		
 		String pathToPollsXml = File.separator + PollTools.getMainXmlPath(portalName);
 
@@ -474,7 +471,7 @@
 		} catch (Exception e) {
 			logger.error("Problem while synchronizing data with main xml descriptor.",e);
 		}	
-	}
+	}*/
 
 	/**
 	 * Method creates content of polls main descriptor by
@@ -491,7 +488,7 @@
 			projectAttribute.appendChild(doc.createTextNode(projectId));
 			newProject.getAttributes().setNamedItem(projectAttribute);
 			
-			for (Poll poll:polls.get(projectId)) {
+			for (PollDTO poll:polls.get(projectId)) {
 				Node newPoll = doc.createElement(POLL);
     		
 				Node newQuestion = doc.createElement(QUESTION);
@@ -508,7 +505,7 @@
 				newPoll.appendChild(newPollId);
 
 				
-				for (String answer : poll.getAnswers()) {
+				/*for (String answer : poll.getAnswers()) {
 					Node newAnswer = doc.createElement(ANSWER);
 					
 					Node newAnswerText = doc.createElement(TEXT);
@@ -525,6 +522,25 @@
 					
 					
 					newPoll.appendChild(newAnswer);
+				}*/
+				
+				for (PollAnswerDTO answer : poll.getAnswers()) {
+					Node newAnswer = doc.createElement(ANSWER);
+					
+					Node newAnswerText = doc.createElement(TEXT);
+					Node newAnswerTextText = doc.createTextNode(answer.getAnswer());
+					newAnswerText.appendChild(newAnswerTextText);
+					
+					newAnswer.appendChild(newAnswerText);
+					
+					Node newAnswerVotes = doc.createElement(VOTES);
+					Node newAnswerVotesText = doc.createTextNode(poll.getAnswerVotes(String.valueOf(answer.getVotes())).toString());
+					newAnswerVotes.appendChild(newAnswerVotesText);
+					
+					newAnswer.appendChild(newAnswerVotes);
+					
+					
+					newPoll.appendChild(newAnswer);
 				}
 				
 				newProject.appendChild(newPoll);
@@ -549,12 +565,12 @@
 	 * @param projectId
 	 * 			Project id name for which is this question.
 	 */
-	synchronized public boolean vote (String answer,String pollId,String userId, String projectId) {
+	/*synchronized public boolean vote (String answer,String pollId,String userId, String projectId) {
 
-		List<Poll> projectPolls = polls.get(projectId);
+		List<PollDTO> projectPolls = polls.get(projectId);
 		if (projectPolls!=null) {
-			Poll poll = null;
-			for (Poll p : projectPolls) {
+			PollDTO poll = null;
+			for (PollDTO p : projectPolls) {
 				if (p.getPollId().equals(pollId)) {
 					poll = p;
 					break;
@@ -571,7 +587,7 @@
 			}
 		}
 		return false;
-	}
+	}*/
 		
 	
 	/**
@@ -606,8 +622,8 @@
 	 * @return
 	 * 		Map<String,List<Poll>> containing polls read from the xml nodes.
 	 */
-	private Map<String,List<Poll>> getValuesFromNodes (NodeList nodes) {
-		Map<String,List<Poll>> values = new Hashtable<String,List<Poll>>();
+	private Map<String,List<PollDTO>> getValuesFromNodes (NodeList nodes) {
+		Map<String,List<PollDTO>> values = new Hashtable<String,List<PollDTO>>();
 		
 		//	Temporary variables used for parsing.
 		Node projectNode=null,pollNode=null,property=null;
@@ -674,9 +690,9 @@
                   	// Checking if all information was correctly read and constructing a Poll.
                   	if (tempProjectId!=null && tempQuestion!=null && tempPollId!=null && answerVotes.size()>0 ) {
                       	if (values.get(tempProjectId)==null) {
-                      		values.put(tempProjectId,new ArrayList<Poll>());
+                      		values.put(tempProjectId,new ArrayList<PollDTO>());
                       	}
-                      	values.get(tempProjectId).add(new Poll(answerVotes,tempQuestion,tempPollId));
+                      	values.get(tempProjectId).add(new PollDTO(answerVotes,tempQuestion,tempPollId));
                       	// Adding data file for saving votes if it isn't already created.
                       	if (!database.checkForPollFile(tempPollId)) {
                       		database.createNewPollFile(tempPollId);
@@ -688,4 +704,74 @@
 		return values;
 	}
 	
+	/**
+	 * Method removes polls which were disabled from working 
+	 * and adds those which was added in their project's poll descriptor.
+	 * 
+	 * @param projectPolls
+	 * 		This Map<Strin,org.jboss.shotoku.Node> contains project ids with their download
+	 * 		counter descriptor's Node.
+	 */
+	private void synchronizePolls(Map<String,org.jboss.shotoku.Node> projectPolls) {
+		// Checking if tracked projects still have their poll.xml descriptors.
+		// If not deleting all tracked polls for them.
+		//removeNotTrackedProjects(projectPolls.keySet());
+
+		List<PollDTO> polls = null;
+		try {
+			polls = PollTools.getAllPolls();
+		} catch(Exception e) {
+			logger.error(e.getMessage(), e);
+		}
+		
+		if (polls == null) {
+			polls = new LinkedList<PollDTO>();
+		}
+		
+		// Iterating through projects nodes containing poll descriptors.
+		for (String projectId : projectPolls.keySet()){
+			try {
+				// Parsing project's poll descriptor.
+				PollDescriptor pollDesc = 
+					new PollDescriptor(projectPolls.get(projectId));
+				
+				// Getting list of polls from polls Map for a given projectId name.
+				
+				// Getting the list of polls from project's poll descriptor.
+				List<PollDTO> descPolls = pollDesc.getPolls();
+				
+				for (PollDTO p : descPolls) {
+					p.setProjectId(projectId);
+				}
+					
+				// This list will be used for collecting questions which must be
+				// removed from polls Map.
+				List<PollDTO> pollsToDelete = new LinkedList<PollDTO>();
+				
+				// Searching for polls to remove and polls which are already added.
+				for (PollDTO poll : polls) {
+					if (descPolls.contains(poll)) {
+						descPolls.remove(poll);
+					} else {
+						pollsToDelete.add(poll);
+					}
+				}
+				
+				PollTools.addPollsForVoting(descPolls);
+				
+				//removePollsFromVoting(pollsToDelete,projectId);
+				
+				//addPollsForVoting (descPolls,projectId);
+				
+			} catch (Exception e) {
+				logger.error("Problem with opening project "+projectId+" poll descriptor.",e);
+			}
+			
+		}
+		
+		// Changing status to false becouse polls Map
+		// is now synchronized with projects' polls descriptors.
+		changeStatus=false;
+	}
+	
 }

Modified: labs/jbosslabs/trunk/portal-extensions/polls/src/java/org/jboss/forge/polls/PollsPortlet.java
===================================================================
--- labs/jbosslabs/trunk/portal-extensions/polls/src/java/org/jboss/forge/polls/PollsPortlet.java	2006-12-05 19:51:38 UTC (rev 8074)
+++ labs/jbosslabs/trunk/portal-extensions/polls/src/java/org/jboss/forge/polls/PollsPortlet.java	2006-12-05 22:49:55 UTC (rev 8075)
@@ -24,13 +24,16 @@
 package org.jboss.forge.polls;
 
 import java.io.IOException;
-import java.util.Map;
+import java.util.List;
 
+import javax.management.MalformedObjectNameException;
 import javax.portlet.PortletException;
 import javax.portlet.PortletRequestDispatcher;
 
 import org.jboss.forge.common.ForgeHelper;
 import org.jboss.forge.common.projects.ProjectsHelper;
+import org.jboss.forge.polls.exceptions.NoSuchPollAnswerException;
+import org.jboss.forge.polls.service.PollDTO;
 import org.jboss.logging.Logger;
 import org.jboss.portal.common.context.DelegateContext;
 import org.jboss.portal.core.servlet.jsp.PortalJsp;
@@ -42,14 +45,12 @@
 import org.jboss.shotoku.ContentManager;
 import org.jboss.shotoku.aop.Inject;
 
-
 /**
  * This class is Portlet for Polls. It manages three views - voting, info and detailed info.
  * @author Ryszard Kozmik
  *
  */
 public class PollsPortlet extends JBossPortlet {
-	
 
 	/**
 	 * Injected ContentManager object used for accessing content repository.
@@ -60,7 +61,7 @@
 	/**
 	 * Logger is used for displaying messages.
 	 */
-	private Logger logger;
+	private static Logger logger = Logger.getLogger(PollsPortlet.class);
 	
 	/**
 	 * Method displays one of three views - voting view or scores information view
@@ -68,7 +69,7 @@
 	 */
 	public void doView(JBossRenderRequest request, JBossRenderResponse response)
 	throws IOException, PortletException {
-		
+
 		response.setContentType("text/html");
 		
 		// resolving name of a portal
@@ -89,28 +90,34 @@
 		String detailedReq = request.getParameter(PollTools.DETAILED_VIEW_REQUEST);
 		
 		// This variable contains manually requested pollId to render its voting view only.
-		Map<String,String> specifiedPolls=null;
+		//Map<String,String> specifiedPolls=null;
 		
+		List<PollDTO> specifiedPolls = null;
+		
 		// It is used if an instance have defined preference in instance descriptor.
 		Object modeFromPref = request.getPreferences().getValue("random",null);
 
+		PollTools.getDesc(portalName, contentManager);
+		
 		try {
 			if (modeFromPref!=null && !modeFromPref.equals("") &&  
 					(detailedReq!=null && detailedReq.compareTo(PollTools.TRUE)==0)==false &&
 					(voted!=null && voted.compareTo(PollTools.TRUE)==0)==false ) {
 				Integer numberOfRandomPolls = Integer.parseInt((String)modeFromPref);
-				specifiedPolls = PollTools.getRandomPolls(numberOfRandomPolls,portalName,contentManager);
+				//specifiedPolls = PollTools.getRandomPolls(numberOfRandomPolls,portalName,contentManager);
+				specifiedPolls = PollTools.getRandomPolls(numberOfRandomPolls);
 			}
 		} catch (NumberFormatException e) {
-			logger =Logger.getLogger(this.getClass());
-			logger.warn("Wrong number format in instance preference.",e);
+			logger.warn("Wrong number format in instance preference.", e);
+		} catch (MalformedObjectNameException e) {
+			e.printStackTrace();
 		}
 		
 		DelegateContext pollContext=null;
 		PortletRequestDispatcher rd = null;
 		
 		// If user has voted information page with scores will be displayed.
-		if (voted!=null && voted.compareTo(PollTools.TRUE)==0) {
+		if (voted != null && voted.compareTo(PollTools.TRUE) == 0) {
 			
 			// Getting pollId about which user wants to see information.
 			String pollId = request.getParameter(PollTools.POLLID_PARAMETER_NAME);
@@ -122,7 +129,8 @@
 			}
 
 			// Getting the poll context for scores information page. 
-			pollContext = PollTools.getInfoContext(portalName,projectId,contentManager,response,pollId);
+			//pollContext = PollTools.getInfoContext(portalName,projectId,contentManager,response,pollId);
+			pollContext = PollTools.getInfoContext(pollId, response);
 			rd = getPortletContext().getRequestDispatcher(
 					ForgeHelper.createRepoAccessPath(portalName, PollTools
 							.getInfoJsp()));
@@ -140,7 +148,8 @@
 			}
 			
 			// Getting the poll context for detailed voting information on specified poll.
-			pollContext = PollTools.getDetailsContext(portalName,projectId,pollId,contentManager,response);
+			//pollContext = PollTools.getDetailsContext(portalName,projectId,pollId,contentManager,response);
+			pollContext = PollTools.getDetailsContext(projectId, pollId, response);
 			rd = getPortletContext().getRequestDispatcher(
 					ForgeHelper.createRepoAccessPath(portalName, PollTools
 							.getDetailsJsp()));
@@ -149,19 +158,20 @@
 		} else {
 			
 			// Getting the poll voting context.
-			pollContext = PollTools.getVotingContext(portalName,projectId,errorReq,contentManager,response,specifiedPolls);
+			pollContext = PollTools.getVotingContext(errorReq, response, specifiedPolls);
 			rd = getPortletContext().getRequestDispatcher(
 					ForgeHelper.createRepoAccessPath(portalName, PollTools
 							.getVotingJsp()));
 		}
 		
 		// Claring request parameters after reading them.
-		Map parameterMap = request.getParameterMap();
+
+		/*Map parameterMap = request.getParameterMap();
 		parameterMap.remove(PollTools.POLLID_PARAMETER_NAME);
 		parameterMap.remove(PollTools.PROJECTID_PARAMETER_NAME);
 		parameterMap.remove(PollTools.ERROR_PARAMETER_NAME);
 		parameterMap.remove(PollTools.VOTED_PARAMETER_NAME);
-		parameterMap.remove(PollTools.DETAILED_VIEW_REQUEST);
+		parameterMap.remove(PollTools.DETAILED_VIEW_REQUEST);*/
 		
 		// Adding content context to the request attributes.
 		request.setAttribute(PortalJsp.CTX_REQUEST, pollContext);
@@ -173,38 +183,42 @@
 	 */
 	@Override
 	public void processAction(JBossActionRequest request, JBossActionResponse response) {
-		
 		// Resolving portal name.
-		String portalName = ForgeHelper.getPortalName(request);
+		//String portalName = ForgeHelper.getPortalName(request);
 		
 		// Getting user's vote and pollId on which the vote was given.
-		String vote=request.getParameter("vote");
+		String vote = request.getParameter("vote");
 		String pollId = request.getParameter("pollId");
 		
 		// Getting name of the project on which the PollsPortlet is used.
 		String projectId = ProjectsHelper.getSelectedProjectId(request);
 		
-		String userId = request.getUser()!=null?request.getUser().getUserName():null;
-		
+		String userId = request.getUser() != null ? request.getUser().getUserName(): null;
+		userId= "user2";
 		if (userId==null) {
-			response.setRenderParameter(PollTools.ERROR_PARAMETER_NAME,"You have to login before voting.");
-		} else if (vote != null && !vote.equals("") && userId!=null) {
-						
+			response.setRenderParameter(PollTools.ERROR_PARAMETER_NAME, "You have to login before voting.");
+		} else if (vote != null && !vote.equals("") && userId != null) {
 			// Trying to vote. If it returns true it means that vote was given successfully
 			// if not it means that user has already voted on this poll.
-			if (PollTools.getDesc(portalName,contentManager).vote(vote,pollId,userId,projectId)) {
-				// Adding parameter to url which tells doView to render scores information page.
-				response.setRenderParameter(PollTools.VOTED_PARAMETER_NAME,PollTools.TRUE);
-				response.setRenderParameter(PollTools.POLLID_PARAMETER_NAME,pollId);
-				response.setRenderParameter(PollTools.PROJECTID_PARAMETER_NAME,projectId);
-
-			} else {
-				response.setRenderParameter(PollTools.ERROR_PARAMETER_NAME,"You have already voted on that poll");
+			//if (PollTools.getDesc(portalName,contentManager).vote(vote,pollId,userId,projectId)) {
+			try {
+				if (PollTools.voteOnPoll(vote, userId)) {
+					// Adding parameter to url which tells doView to render scores information page.
+					response.setRenderParameter(PollTools.VOTED_PARAMETER_NAME, PollTools.TRUE);
+					response.setRenderParameter(PollTools.POLLID_PARAMETER_NAME, pollId);
+					response.setRenderParameter(PollTools.PROJECTID_PARAMETER_NAME, projectId);
+				} else {
+					response.setRenderParameter(PollTools.ERROR_PARAMETER_NAME, "You have already voted on that poll");
+				}
+			} catch(NoSuchPollAnswerException e) {
+				response.setRenderParameter(PollTools.ERROR_PARAMETER_NAME, 
+						"Answer you voted on does not exist.");
+			} catch(Exception e) {
+				logger.error(e.getMessage(), e);
 			}
 		} else {
-			response.setRenderParameter(PollTools.ERROR_PARAMETER_NAME,"You haven't given your vote.");
+			response.setRenderParameter(PollTools.ERROR_PARAMETER_NAME, "You haven't given your vote.");
 		}
 	}
-
 	
 }

Modified: labs/jbosslabs/trunk/portal-extensions/polls/src/java/org/jboss/forge/polls/PollsWatcher.java
===================================================================
--- labs/jbosslabs/trunk/portal-extensions/polls/src/java/org/jboss/forge/polls/PollsWatcher.java	2006-12-05 19:51:38 UTC (rev 8074)
+++ labs/jbosslabs/trunk/portal-extensions/polls/src/java/org/jboss/forge/polls/PollsWatcher.java	2006-12-05 22:49:55 UTC (rev 8075)
@@ -102,7 +102,7 @@
 			// There was some change on object connected to main polls xml descriptor
 			// so we must synchronize the object with the file.
 			PollsDescriptor descriptor = (PollsDescriptor)currentValue;
-			descriptor.synchronizeWithFile(portalName);
+			//descriptor.synchronizeWithFile(portalName);
 			return null;
 		}
 
@@ -122,5 +122,4 @@
 		return pollDescriptors.containsAll(desc.getPollDescriptors(portalName).keySet());
 	}
 
-
 }

Added: labs/jbosslabs/trunk/portal-extensions/polls/src/java/org/jboss/forge/polls/exceptions/NoSuchPollAnswerException.java
===================================================================
--- labs/jbosslabs/trunk/portal-extensions/polls/src/java/org/jboss/forge/polls/exceptions/NoSuchPollAnswerException.java	2006-12-05 19:51:38 UTC (rev 8074)
+++ labs/jbosslabs/trunk/portal-extensions/polls/src/java/org/jboss/forge/polls/exceptions/NoSuchPollAnswerException.java	2006-12-05 22:49:55 UTC (rev 8075)
@@ -0,0 +1,15 @@
+package org.jboss.forge.polls.exceptions;
+
+public class NoSuchPollAnswerException extends Exception {
+
+	private static final long serialVersionUID = 1L;
+	
+	public NoSuchPollAnswerException() {
+		super();
+	}
+	
+	public NoSuchPollAnswerException(String msg) {
+		super(msg);
+	}
+	
+}

Added: labs/jbosslabs/trunk/portal-extensions/polls/src/java/org/jboss/forge/polls/service/PollAnswerDTO.java
===================================================================
--- labs/jbosslabs/trunk/portal-extensions/polls/src/java/org/jboss/forge/polls/service/PollAnswerDTO.java	2006-12-05 19:51:38 UTC (rev 8074)
+++ labs/jbosslabs/trunk/portal-extensions/polls/src/java/org/jboss/forge/polls/service/PollAnswerDTO.java	2006-12-05 22:49:55 UTC (rev 8075)
@@ -0,0 +1,71 @@
+package org.jboss.forge.polls.service;
+
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+public class PollAnswerDTO {
+
+	private String answerId;
+	
+	private String answer;
+	
+	private int votes;
+	
+	private Set<String> userIds;
+
+	public PollAnswerDTO(String answer) {
+		this.answer = answer;
+		this.votes = 0;
+	}
+	
+	public PollAnswerDTO(PollAnswerEntity pollAnswer) {
+		this.answerId = String.valueOf(pollAnswer.getPollAnswerId());
+		this.answer = pollAnswer.getAnswer();
+		this.votes = pollAnswer.getVotes();
+	}
+
+	public PollAnswerDTO(PollAnswerEntity pollAnswer, List<PollVoteEntity> pollVotes) {
+		this.answerId = String.valueOf(pollAnswer.getPollAnswerId());
+		this.answer = pollAnswer.getAnswer();
+		this.votes = pollAnswer.getVotes();
+	
+		userIds = new HashSet<String>();
+		for (PollVoteEntity pollVote : pollVotes) {
+			userIds.add(pollVote.getUserId());
+		}
+	}
+	
+	public String getAnswer() {
+		return answer;
+	}
+
+	public void setAnswer(String answer) {
+		this.answer = answer;
+	}
+
+	public int getVotes() {
+		return votes;
+	}
+
+	public void setVotes(int votes) {
+		this.votes = votes;
+	}
+
+	public Set<String> getUserIds() {
+		return userIds;
+	}
+
+	public void setUserIds(Set<String> userIds) {
+		this.userIds = userIds;
+	}
+
+	public String getAnswerId() {
+		return answerId;
+	}
+
+	public void setAnswerId(String answerId) {
+		this.answerId = answerId;
+	}
+	
+}

Added: labs/jbosslabs/trunk/portal-extensions/polls/src/java/org/jboss/forge/polls/service/PollAnswerEntity.java
===================================================================
--- labs/jbosslabs/trunk/portal-extensions/polls/src/java/org/jboss/forge/polls/service/PollAnswerEntity.java	2006-12-05 19:51:38 UTC (rev 8074)
+++ labs/jbosslabs/trunk/portal-extensions/polls/src/java/org/jboss/forge/polls/service/PollAnswerEntity.java	2006-12-05 22:49:55 UTC (rev 8075)
@@ -0,0 +1,72 @@
+package org.jboss.forge.polls.service;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.OneToMany;
+import javax.persistence.Table;
+
+ at Entity
+ at Table(name = "jblab_pollanswers")
+public class PollAnswerEntity implements Serializable {
+
+	private static final long serialVersionUID = 1L;
+	
+	private int pollAnswerId;
+	private String answer;
+	private int votes;
+	private List<PollVoteEntity> pollVotes = new ArrayList<PollVoteEntity>();
+	
+	public PollAnswerEntity() {
+		
+	}
+	
+	public PollAnswerEntity(PollAnswerDTO answer) {
+		this.answer = answer.getAnswer();
+		this.votes = answer.getVotes();
+	}
+	
+	@Id
+	@GeneratedValue
+	@Column(name = "pollanswer_id")
+	public int getPollAnswerId() {
+		return pollAnswerId;
+	}
+	
+	public void setPollAnswerId(int pollAnswerId) {
+		this.pollAnswerId = pollAnswerId;
+	}
+
+	@Column(name = "answer")
+	public String getAnswer() {
+		return answer;
+	}
+	
+	public void setAnswer(String answer) {
+		this.answer = answer;
+	}
+	
+	@Column(name = "votes")
+	public int getVotes() {
+		return votes;
+	}
+	
+	public void setVotes(int votes) {
+		this.votes = votes;
+	}
+
+	@OneToMany(mappedBy = "pollAnswer")
+	public List<PollVoteEntity> getPollVotes() {
+		return pollVotes;
+	}
+
+	public void setPollVotes(List<PollVoteEntity> pollVotes) {
+		this.pollVotes = pollVotes;
+	}
+	
+}

Added: labs/jbosslabs/trunk/portal-extensions/polls/src/java/org/jboss/forge/polls/service/PollDTO.java
===================================================================
--- labs/jbosslabs/trunk/portal-extensions/polls/src/java/org/jboss/forge/polls/service/PollDTO.java	2006-12-05 19:51:38 UTC (rev 8074)
+++ labs/jbosslabs/trunk/portal-extensions/polls/src/java/org/jboss/forge/polls/service/PollDTO.java	2006-12-05 22:49:55 UTC (rev 8075)
@@ -0,0 +1,228 @@
+
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+
+package org.jboss.forge.polls.service;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+
+/**
+ * Class which abstracts one Poll. It has all information about it and
+ * contains summary votes for answers.
+ * @author Ryszard Kozmik
+ *
+ */
+public class PollDTO {
+
+	/**
+	 * Contains poll identifycation number.
+	 */
+	private String pollId;
+	
+	/**
+	 * Contains poll's question.
+	 */
+	private String question;
+	
+	private String projectId;
+	
+	private List<PollAnswerDTO> answers;
+
+	/**
+	 * This Map<String,Integer> contains pairs where the keys are
+	 * answers and the values are summary numbers of votes.
+	 */
+	private Map<String, Integer> votes;
+	
+	/**
+	 * Simplest constructor for Poll
+	 * @param question
+	 * 		Poll's question.
+	 */
+	public PollDTO(String question, Set<String> pollAnswers) {
+		this.question = question;
+		
+		answers = new ArrayList<PollAnswerDTO>();
+		for (String pollAnswer : pollAnswers){
+			answers.add(new PollAnswerDTO(pollAnswer));
+		}
+	}
+	
+	public PollDTO(String question, String projectId, Set<String> pollAnswers) {
+		this(question, pollAnswers);
+
+		this.projectId = projectId;
+	}
+	
+	public PollDTO(PollEntity pollEntity) {
+		this.pollId = String.valueOf(pollEntity.getPollId());
+		this.question = pollEntity.getQuestion();
+		this.projectId = pollEntity.getProjectId();
+		
+		answers = new ArrayList<PollAnswerDTO>();
+		for (PollAnswerEntity pollAnswer : pollEntity.getPollAnswers()){
+			answers.add(new PollAnswerDTO(pollAnswer));
+		}
+	}
+	
+	public PollDTO(PollEntity pollEntity, List<PollAnswerEntity> pollAnswers) {
+		this.pollId = String.valueOf(pollEntity.getPollId());
+		this.question = pollEntity.getQuestion();
+		this.projectId = pollEntity.getProjectId();
+		
+		answers = new ArrayList<PollAnswerDTO>();
+		for (PollAnswerEntity pollAnswer : pollEntity.getPollAnswers()){
+			answers.add(new PollAnswerDTO(pollAnswer, pollAnswer.getPollVotes()));
+		}
+	}
+	
+	/**
+	 * Poll's constructor which initiates all variables with given parameters.
+	 * @param answers
+	 * 		Set<String> containing possible poll's answers for <code>question</code> 
+	 * @param question
+	 * 		Poll's <code>question</code>
+	 * @param pollId
+	 * 		Poll identification number.
+	 */
+	public PollDTO (Set<String>answers,String question, String pollId) {
+		votes = Collections.synchronizedMap(new LinkedHashMap<String,Integer>(answers.size()));
+		for (String answer : answers){
+			votes.put(answer,new Integer(0));
+		}
+		this.question = question;
+		this.pollId = pollId;
+	}
+	
+	/**
+	 * Poll's constructor which initiates all variables with given parameters.
+	 * @param votes
+	 * 		Map<String,Integer> containing pairs of answers and summary votes values for them.
+	 * @param question
+	 * 		Poll's question.
+	 * @param pollId
+	 * 		Poll's identification number.
+	 */
+	public PollDTO (Map<String,Integer>votes,String question, String pollId) {
+		this.votes = votes;
+		if (votes==null) this.votes = Collections.synchronizedMap(new LinkedHashMap<String,Integer>());
+		this.question = question;
+		this.pollId = pollId;
+	}
+	
+	/**
+	 * Method increments the number of votes for given in parameter <code>answer</code>.
+	 * @param answer
+	 * 		Answer on which number of votes must be incremented.
+	 */
+	public void incrementAnswer (String answer) {
+		if (votes.get(answer)!=null) {
+			votes.put(answer,votes.get(answer)+1);
+		}
+	}
+
+	/**
+	 * Overrided equals method is comparing two Polls checking if they have
+	 * the same question and the same answers.
+	 */
+	@Override
+	public boolean equals(Object obj) {
+		PollDTO poll = ((PollDTO) obj);
+		if (poll.getQuestion().equals(question) 
+				&& poll.getAnswers().containsAll(answers)
+				&& answers.containsAll(poll.getAnswers())) {
+
+			return true;
+		}
+		
+		return false;
+	}
+
+	/*public boolean equals(Object obj) {
+		PollDTO poll = ((PollDTO) obj);
+		if (poll.getQuestion().equals(question) 
+				&& poll.getAnswers().containsAll(votes.keySet())
+				&& votes.keySet().containsAll(poll.getAnswers()) ) {
+			return true;
+		}
+		return false;
+	}*/
+	
+	/**
+	 * Method returns summary number of votes for specified <code>answer</code>.
+	 * @param answer
+	 * 		Answer for which number of votes is requested.
+	 * @return
+	 * 		Number of votes for given <code>answer</code>
+	 */
+	public Integer getAnswerVotes (String answer) {
+		return votes.get(answer);
+	}
+
+	/**
+	 * Method returns Poll's identification number.
+	 * @return
+	 * 		Poll's identification number.
+	 */
+	public String getPollId() {
+		return pollId;
+	}
+
+	/**
+	 * Method returns Poll's question.
+	 * @return
+	 * 		Poll's question.
+	 */
+	public String getQuestion() {
+		return question;
+	}
+
+	public String getProjectId() {
+		return projectId;
+	}
+
+	public void setProjectId(String projectId) {
+		this.projectId = projectId;
+	}
+
+	public List<PollAnswerDTO> getAnswers() {
+		return answers;
+	}
+	
+	/**
+	 * Method is used for voting on specified in parameter <code>answer</code>.
+	 * @param answer
+	 * 		The <code>answer</code> on which the vote is given.
+	 */
+	/*public void vote (String answer) {
+		if (votes.containsKey(answer)) {
+			votes.put(answer,votes.get(answer)+1);
+		}
+	}*/
+
+}

Added: labs/jbosslabs/trunk/portal-extensions/polls/src/java/org/jboss/forge/polls/service/PollEntity.java
===================================================================
--- labs/jbosslabs/trunk/portal-extensions/polls/src/java/org/jboss/forge/polls/service/PollEntity.java	2006-12-05 19:51:38 UTC (rev 8074)
+++ labs/jbosslabs/trunk/portal-extensions/polls/src/java/org/jboss/forge/polls/service/PollEntity.java	2006-12-05 22:49:55 UTC (rev 8075)
@@ -0,0 +1,80 @@
+package org.jboss.forge.polls.service;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.persistence.CascadeType;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.JoinColumn;
+import javax.persistence.OneToMany;
+import javax.persistence.Table;
+
+ at Entity
+ at Table(name = "jblab_polls")
+public class PollEntity implements Serializable {
+
+	private static final long serialVersionUID = 1L;
+	
+	private int pollId;
+	private String question;
+	private String projectId;
+	private List<PollAnswerEntity> pollAnswers = 
+		new ArrayList<PollAnswerEntity>();
+	
+	public PollEntity() {
+		
+	}
+	
+	public PollEntity(PollDTO poll) {
+		this.question = poll.getQuestion();
+		this.projectId = poll.getProjectId();
+		
+		for (PollAnswerDTO answer : poll.getAnswers()) {
+			pollAnswers.add(new PollAnswerEntity(answer));
+		}
+	}
+	
+	@Id
+	@GeneratedValue
+	@Column(name = "poll_id")
+	public int getPollId() {
+		return pollId;
+	}
+	
+	public void setPollId(int pollId) {
+		this.pollId = pollId;
+	}
+	
+	@Column(name = "question")
+	public String getQuestion() {
+		return question;
+	}
+	
+	public void setQuestion(String question) {
+		this.question = question;
+	}
+
+	@Column(name = "project_id")
+	public String getProjectId() {
+		return projectId;
+	}
+
+	public void setProjectId(String projectId) {
+		this.projectId = projectId;
+	}
+
+	@OneToMany(cascade = {CascadeType.PERSIST, CascadeType.REMOVE})
+	@JoinColumn(name = "poll_id")
+	public List<PollAnswerEntity> getPollAnswers() {
+		return pollAnswers;
+	}
+
+	public void setPollAnswers(List<PollAnswerEntity> pollAnswers) {
+		this.pollAnswers = pollAnswers;
+	}
+	
+}

Added: labs/jbosslabs/trunk/portal-extensions/polls/src/java/org/jboss/forge/polls/service/PollVoteEntity.java
===================================================================
--- labs/jbosslabs/trunk/portal-extensions/polls/src/java/org/jboss/forge/polls/service/PollVoteEntity.java	2006-12-05 19:51:38 UTC (rev 8074)
+++ labs/jbosslabs/trunk/portal-extensions/polls/src/java/org/jboss/forge/polls/service/PollVoteEntity.java	2006-12-05 22:49:55 UTC (rev 8075)
@@ -0,0 +1,54 @@
+package org.jboss.forge.polls.service;
+
+import java.io.Serializable;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.JoinColumn;
+import javax.persistence.ManyToOne;
+import javax.persistence.Table;
+
+ at Entity
+ at Table(name = "jblab_pollvotes")
+public class PollVoteEntity implements Serializable {
+
+	private static final long serialVersionUID = 1L;
+	
+	private int pollVoteId;
+	private String userId;
+
+	private PollAnswerEntity pollAnswer;
+	
+	@Id
+	@GeneratedValue
+	@Column(name = "pollvote_id")
+	public int getPollVoteId() {
+		return pollVoteId;
+	}
+	
+	public void setPollVoteId(int pollVoteId) {
+		this.pollVoteId = pollVoteId;
+	}
+	
+	@Column(name = "user_id")
+	public String getUserId() {
+		return userId;
+	}
+	
+	public void setUserId(String userId) {
+		this.userId = userId;
+	}
+
+	@ManyToOne
+	@JoinColumn(name = "pollanswer_id")
+	public PollAnswerEntity getPollAnswer() {
+		return pollAnswer;
+	}
+
+	public void setPollAnswer(PollAnswerEntity pollAnswer) {
+		this.pollAnswer = pollAnswer;
+	}
+	
+}

Added: labs/jbosslabs/trunk/portal-extensions/polls/src/java/org/jboss/forge/polls/service/PollsService.java
===================================================================
--- labs/jbosslabs/trunk/portal-extensions/polls/src/java/org/jboss/forge/polls/service/PollsService.java	2006-12-05 19:51:38 UTC (rev 8074)
+++ labs/jbosslabs/trunk/portal-extensions/polls/src/java/org/jboss/forge/polls/service/PollsService.java	2006-12-05 22:49:55 UTC (rev 8075)
@@ -0,0 +1,30 @@
+package org.jboss.forge.polls.service;
+
+import java.util.List;
+
+import org.jboss.forge.polls.exceptions.NoSuchPollAnswerException;
+
+
+public interface PollsService {
+
+	public static final String POLLS_SERVICE = "labs:service=polls";
+	
+	public List<PollDTO> getRandomPolls(int numberOfPolls);
+	
+	public void createPoll(PollDTO poll);
+
+	public void deletePoll(int pollId);
+	
+	public void addPollsForVoting(List<PollDTO> polls);
+	
+	public void removePollsFromVoting(List<PollDTO> polls);
+	
+	public PollDTO getPoll(int pollId);
+	
+	public PollDTO getPollWithDetails(int pollId);
+
+	public List<PollDTO> getAllPolls();
+	
+	public boolean voteOnPoll(String answerId, String userId) throws NoSuchPollAnswerException;
+	
+}

Added: labs/jbosslabs/trunk/portal-extensions/polls/src/java/org/jboss/forge/polls/service/PollsServiceImpl.java
===================================================================
--- labs/jbosslabs/trunk/portal-extensions/polls/src/java/org/jboss/forge/polls/service/PollsServiceImpl.java	2006-12-05 19:51:38 UTC (rev 8074)
+++ labs/jbosslabs/trunk/portal-extensions/polls/src/java/org/jboss/forge/polls/service/PollsServiceImpl.java	2006-12-05 22:49:55 UTC (rev 8075)
@@ -0,0 +1,120 @@
+package org.jboss.forge.polls.service;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Random;
+
+import javax.ejb.TransactionAttribute;
+import javax.ejb.TransactionAttributeType;
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+
+import org.jboss.annotation.ejb.Management;
+import org.jboss.annotation.ejb.Service;
+import org.jboss.forge.polls.exceptions.NoSuchPollAnswerException;
+
+ at Service (objectName = PollsService.POLLS_SERVICE)
+ at Management(PollsService.class)
+public class PollsServiceImpl implements PollsService {
+
+	@PersistenceContext(unitName = "polls")
+	protected EntityManager em;
+
+	public List<PollDTO> getRandomPolls(int numberOfPolls) {
+		List<PollDTO> randomPolls = new ArrayList<PollDTO>(numberOfPolls);
+		List<PollEntity> results = em.createQuery("from PollEntity").getResultList();
+        
+        if (results == null) {
+        	return randomPolls;
+        }
+        
+        Random random = new Random();
+		while (numberOfPolls-- > 0 && results.size() > 0) {
+			int item = (int)(results.size() * random.nextFloat());
+			PollEntity poll = results.get(item);
+			randomPolls.add(new PollDTO(poll));
+			results.remove(item);
+		}
+		return randomPolls;
+	}
+
+	public void createPoll(PollDTO poll) {
+		PollEntity pollEntity = new PollEntity(poll);
+		em.persist(pollEntity);
+	}
+
+	public void deletePoll(int pollId) {
+		// TODO Auto-generated method stub
+		
+	}
+
+	public PollDTO getPoll(int pollId) {
+		PollEntity pollEntity = em.find(PollEntity.class, pollId);
+		
+		if (pollEntity == null) {
+			return null;
+		}
+		
+		PollDTO poll = new PollDTO(pollEntity);
+		return poll;
+	}
+	
+	public PollDTO getPollWithDetails(int pollId) {
+		PollEntity pollEntity = em.find(PollEntity.class, pollId);
+		
+		if (pollEntity == null) {
+			return null;
+		}
+		
+		PollDTO poll = new PollDTO(pollEntity, pollEntity.getPollAnswers());
+		return poll;
+	}
+
+	@TransactionAttribute(TransactionAttributeType.REQUIRED)
+	public boolean voteOnPoll(String answerId, String userId) throws NoSuchPollAnswerException {
+		PollAnswerEntity answer = em.find(PollAnswerEntity.class, Integer.valueOf(answerId));
+		
+		if (answer == null)
+			throw new NoSuchPollAnswerException();
+		
+		for (PollVoteEntity vote : answer.getPollVotes()) {
+			if (vote.getUserId().equals(userId)) {
+				return false;
+			}
+		}
+			
+		PollVoteEntity newVote = new PollVoteEntity();
+		newVote.setPollAnswer(answer);
+		newVote.setUserId(userId);
+		em.persist(newVote);
+		answer.setVotes(answer.getVotes()+1);
+			
+		return true;
+	}
+
+	public List<PollDTO> getAllPolls() {
+		List<PollDTO> polls = new ArrayList<PollDTO>();
+		List<PollEntity> results = em.createQuery("from PollEntity").getResultList();
+        
+		for (PollEntity poll : results) {
+			polls.add(new PollDTO(poll));
+		}
+		
+		return polls;
+	}
+
+	@TransactionAttribute(TransactionAttributeType.REQUIRED)
+	public void addPollsForVoting(List<PollDTO> polls) {
+		for (PollDTO poll : polls) {
+			em.persist(new PollEntity(poll));
+		}
+	}
+
+	@TransactionAttribute(TransactionAttributeType.REQUIRED)
+	public void removePollsFromVoting(List<PollDTO> polls) {
+		for (PollDTO poll : polls) {
+			em.remove(new PollEntity(poll));
+		}
+	}
+	
+}

Added: labs/jbosslabs/trunk/portal-extensions/polls/src/persistence.xml
===================================================================
--- labs/jbosslabs/trunk/portal-extensions/polls/src/persistence.xml	2006-12-05 19:51:38 UTC (rev 8074)
+++ labs/jbosslabs/trunk/portal-extensions/polls/src/persistence.xml	2006-12-05 22:49:55 UTC (rev 8075)
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<persistence>
+	<persistence-unit name="polls">
+		<jta-data-source>java:/LabsDS</jta-data-source>
+		<properties>
+			<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
+			<property name="hibernate.hbm2ddl.auto" value="update" />
+		</properties>
+	</persistence-unit>
+</persistence>




More information about the jboss-svn-commits mailing list