From: <jbo...@li...> - 2005-12-17 01:20:10
|
Author: unibrew Date: 2005-12-16 20:20:01 -0500 (Fri, 16 Dec 2005) New Revision: 1828 Modified: trunk/forge/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/Poll.java trunk/forge/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/PollDescriptor.java trunk/forge/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/PollTools.java trunk/forge/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/PollsDescriptor.java trunk/forge/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/PollsWatcher.java trunk/forge/portal-extensions/polls/src/java/org/jboss/forge/polls/PollsPortlet.java Log: [JBLAB-407] Updating Polls' sources. Modified: trunk/forge/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/Poll.java =================================================================== --- trunk/forge/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/Poll.java 2005-12-16 23:31:19 UTC (rev 1827) +++ trunk/forge/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/Poll.java 2005-12-17 01:20:01 UTC (rev 1828) @@ -1,45 +1,57 @@ package org.jboss.forge.common.projects; +import java.util.Hashtable; +import java.util.Map; +import java.util.Set; + public class Poll { private String question; - private long positive; - private long negative; private String pollId; + private Map<String,Integer> votes; - public Poll (long positive, long negative, String question, String pollId) { - this.positive = positive; - this.negative = negative; + public Poll (Set<String>answers,String question, String pollId) { + votes = new Hashtable<String,Integer>(answers.size()); + for (String answer : answers){ + votes.put(answer,new Integer(0)); + } this.question = question; this.pollId = pollId; } + public Poll (Map<String,Integer>votes,String question, String pollId) { + this.votes = votes; + if (votes==null) this.votes = new Hashtable<String,Integer>(); + this.question = question; + this.pollId = pollId; + } + public Poll (String question) { this.question = question; this.pollId= Integer.toString((int)(Math.random()*Integer.MAX_VALUE)); } - public void incrementPositive () { - positive++; + public void incrementAnswer (String answer) { + if (votes.get(answer)!=null) { + votes.put(answer,votes.get(answer)+1); + } } - - public void incrementNegative () { - negative++; - } @Override public boolean equals(Object obj) { - return ((Poll)obj).getQuestion().equals(question); + Poll poll = ((Poll)obj); + if (poll.getQuestion().equals(question) + && poll.getAnswers().containsAll(votes.keySet()) + && votes.keySet().containsAll(poll.getAnswers()) ) { + return true; + } + return false; } - public long getNegative() { - return negative; + public Integer getAnswerVotes (String answer) { + return votes.get(answer); } - public long getPositive() { - return positive; - } - public String getQuestion() { return question; } @@ -48,6 +60,23 @@ return pollId; } + public Set<String> getAnswers(){ + return votes.keySet(); + } + public void vote (String answer) { + if (votes.containsKey(answer)) { + votes.put(answer,votes.get(answer)+1); + } + } + public String toString() { + StringBuffer sb = new StringBuffer(); + sb.append("POLLID: "+this.getPollId()); + sb.append("QUESTION: "+this.getQuestion()); + for (String answer :this.getAnswers()) { + sb.append("ANSWER "+answer); + } + return sb.toString(); + } } Modified: trunk/forge/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/PollDescriptor.java =================================================================== --- trunk/forge/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/PollDescriptor.java 2005-12-16 23:31:19 UTC (rev 1827) +++ trunk/forge/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/PollDescriptor.java 2005-12-17 01:20:01 UTC (rev 1828) @@ -25,8 +25,11 @@ import java.io.IOException; import java.io.InputStream; +import java.util.HashSet; import java.util.LinkedList; import java.util.List; +import java.util.Random; +import java.util.Set; import org.apache.xerces.parsers.DOMParser; import org.jboss.forge.common.XmlTools; @@ -50,6 +53,11 @@ public static final String QUESTION = "question"; /** + * Name of tag in poll.xml containing one poll's answers. + */ + public static final String ANSWER = "answer"; + + /** * Name of tag in poll.xml containing poll. */ public static final String POLL = "poll"; @@ -70,22 +78,41 @@ polls = new LinkedList<Poll>(); for (int i = 0; i < nodes.getLength(); i++) { n = nodes.item(i); - if (n.getNodeType() == Node.ELEMENT_NODE) { + if (n.getNodeType() == Node.ELEMENT_NODE) { + String tempQuestion = null; + Set<String> tempAnswers = new HashSet<String>(); + System.out.println("[POLLSDESCRIPTOR] IN POLLS"); if (n.getNodeName().equals(POLL)) { + System.out.println("[POLLSDESCRIPTOR] IN POLL"); NodeList counterProps = n.getChildNodes(); for (int j=0;j< counterProps.getLength() ; j++) { + System.out.println("[POLLSDESCRIPTOR] IN CHILDREN OF POLL"); property = counterProps.item(j); if (property.getNodeType()== Node.ELEMENT_NODE){ + System.out.println("[POLLSDESCRIPTOR] IN ELEMENT OF POLL"); if (property.getNodeName().equals(QUESTION) && XmlTools.unmarshallText(property) != null && !XmlTools.unmarshallText(property).trim().equals("")) { - polls.add(new Poll(XmlTools.unmarshallText(property).trim())); + + tempQuestion = XmlTools.unmarshallText(property).trim(); + System.out.println("[POLLSDESCRIPTOR] IN QUESTION: "+tempQuestion); + } else if (property.getNodeName().equals(ANSWER) && XmlTools.unmarshallText(property) != null + && !XmlTools.unmarshallText(property).trim().equals("")) { + tempAnswers.add(XmlTools.unmarshallText(property).trim()); + System.out.println("[POLLSDESCRIPTOR] IN answer: "+XmlTools.unmarshallText(property).trim()); } } } + if (tempQuestion!=null && !tempQuestion.equals("") && tempAnswers.size()>0) { + System.out.println ("ADDING A POLL TO THE POLLS"); + polls.add(new Poll(tempAnswers,tempQuestion,Integer.toString((int)(Math.random()*99999999)))); + } } } } - + System.out.println ("Displaying Polls from PollDescriptor just after reading it."); + for (Poll poll : polls) { + System.out.println (poll); + } } /** Modified: trunk/forge/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/PollTools.java =================================================================== --- trunk/forge/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/PollTools.java 2005-12-16 23:31:19 UTC (rev 1827) +++ trunk/forge/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/PollTools.java 2005-12-17 01:20:01 UTC (rev 1828) @@ -24,6 +24,7 @@ package org.jboss.forge.common.projects; import java.io.File; +import java.util.Collection; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; @@ -40,9 +41,35 @@ import org.jboss.portlet.JBossRenderResponse; import org.jboss.shotoku.ContentManager; +/** + * This class is used for creating context for PollsPortlet and is + * serving many different static methods and final variables used in Polls project. + * @author Ryszard Kozmik + * + */ public class PollTools { /** + * Name of the request parameter which tells if user voted. + */ + public static final String VOTED_PARAMETER_NAME = "voted"; + + /** + * Value of request parameter for false. + */ + public static final String FALSE = "false"; + + /** + * Value of request parameter for true. + */ + public static final String TRUE = "true"; + + /** + * Name of the request parameter which tells that user requested details page. + */ + public static final String DETAILED_VIEW_REQUEST="details"; + + /** * Dir in portal where the JSP view file is. */ public static final String POLLS_DIR="polls"; @@ -76,7 +103,7 @@ * @param portalName * @return Path to polls descriptor. */ - public static String getMainXmlPath (String portalName) { + public static String getMainXmlPath (final String portalName) { return portalName + File.separator + ProjectsHelper.MEMBERS_DIR + File.separator + ProjectsHelper.POLLS_DESC; } @@ -88,15 +115,29 @@ * Project id name for which the poll descriptor path will be constructed. * @return Path to project's poll descriptor. */ - public static String getProjectXmlPath(String portalName,String projectId) { + public static String getProjectXmlPath(final String portalName,final String projectId) { return portalName+File.separator+ProjectsHelper.MEMBERS_DIR+File.separator+projectId+ File.separator+ProjectsHelper.POLL_DESC; } + /** + * This method returns PollsDescriptor received from Cache. If there is no object + * in the cache it creates new one, puts it into Cache and returns the object. + * @param portalName + * Name of the portal. + * @param contentManager + * ContentManager object used for access to cms. + * @return + * PollsDescriptor object. + */ public static PollsDescriptor getDesc(final String portalName,ContentManager contentManager) { + + // Trying to get descriptor from the Cache. PollsDescriptor desc = (PollsDescriptor) ForgeHelper .getForgeManagement().getFromCache(portalName, PollsDescriptor.class.getName()); + + // If descriptor doesn't exist - create new one. if (desc==null) { desc = (PollsDescriptor) ForgeHelper.getForgeManagement() .addNodeWatcher(portalName, @@ -139,8 +180,23 @@ return POLLS_DIR + File.separator + POLLS_VOTING_JSP; } - public static Context getInfoContext (String portalName,String projectId, + /** + * This method produces conten context for JSP view file showing + * information about voting. + * @param portalName + * Just portal name. + * @param projectId + * Project Id name from which request for context is comming. + * @param cm + * ContentManager object used for access to cms. + * @param response + * JBossRenderResponse object which is used for creating urls. + * @return + * Content context for information JSP page. + */ + public static Context getInfoContext (final String portalName,final String projectId, ContentManager cm,JBossRenderResponse response) { + // If the projectId is null method returns empty DelegateContext object. if (projectId==null) { return new DelegateContext(); @@ -166,6 +222,20 @@ Map<String,Poll> values = desc.getPollsStatsForProject(projectId); // Filling the context for portlet. + /** + * Context structure: + * <polls>ONE + * <poll>MANY + * <question />ONE + * <renderUrl/>ONE + * <renderUrlDetailed />ONE + * <answers>MANY + * <votes />ONE + * <text />ONE + * </answers> + * </poll> + * </polls> + */ DelegateContext polls = ctx.next("polls"); Poll temporary=null; for (String pollId:values.keySet()) { @@ -177,15 +247,35 @@ url.setParameter("pollId",pollId); url.setParameter("details","true"); poll.put("renderUrlDetailed",url.toString()); - poll.put("positive",Long.toString(temporary.getPositive())); - poll.put("negative",Long.toString(temporary.getNegative())); + + for (String tempAnswer : temporary.getAnswers()) { + DelegateContext answers = poll.next("answers"); + answers.put("votes",temporary.getAnswerVotes(tempAnswer)); + answers.put("text",tempAnswer); + } } return ctx; - } - public static Context getDetailsContext (String portalName,String projectId,String pollId, + /** + * This method produces conten context for JSP view file showing + * detailed information about voting. + * @param portalName + * Just portal name. + * @param projectId + * Project Id name from which request for context is comming. + * @param pollId + * Id of a Poll for which the detailed information context must be produced. + * @param cm + * ContentManager object used for access to cms. + * @param response + * JBossRenderResponse object which is used for creating urls. + * @return + * Content context for detailed information JSP page. + */ + public static Context getDetailsContext (final String portalName,final String projectId,final String pollId, ContentManager cm,JBossRenderResponse response) { + // If the projectId is null method returns empty DelegateContext object. if (projectId==null) { return new DelegateContext(); @@ -209,41 +299,69 @@ // Getting the polls for given projectId. Map<String,String> values = desc.getDetailStatsForPoll(pollId); + Collection<String> answersRedundant = values.values(); - //Sumarizing negative and positive votes to separate lists. - Set<String> positiveVotes = new HashSet<String>(); - Set<String> negativeVotes = new HashSet<String>(); - for (String userId : values.keySet()) { - if (values.get(userId).equals(PollsDescriptor.POSITIVE_VOTE)) { - positiveVotes.add(userId); - } else if (values.get(userId).equals(PollsDescriptor.NEGATIVE_VOTE)) { - negativeVotes.add(userId); - } - } + // Getting possible answers + Set<String> answers = new HashSet<String>(); + answers.addAll(answersRedundant); // Filling the context for portlet. + /** + * Context structure: + * <poll>ONE + * <question />ONE + * <renderUrlVoting />ONE + * <renderUrlInfo />ONE + * <answer>MANY + * <text />ONE + * <user>MANY + * <id />ONE + * </user> + * </answer> + * </poll> + */ DelegateContext poll = ctx.next("poll"); Poll tempPoll = desc.getPoll(projectId,pollId); poll.put("question",tempPoll!=null?tempPoll.getQuestion():""); - poll.put("renderUrl",response.createRenderURL().toString()); + PortletURL url = response.createRenderURL(); + poll.put("renderUrlVoting",url.toString()); + url.setParameter(VOTED_PARAMETER_NAME,TRUE); + poll.put("renderUrlInfo",url.toString()); - Iterator posIt = positiveVotes.iterator(); - Iterator negIt = negativeVotes.iterator(); - - while (posIt.hasNext() || negIt.hasNext()) { - DelegateContext votes = poll.next("votes"); - votes.put("positiveUser",posIt.hasNext()?(String)posIt.next():""); - votes.put("negativeUser",negIt.hasNext()?(String)negIt.next():""); + for (String answer : answers) { + DelegateContext answerCtx = poll.next("answer"); + answerCtx.put("text",answer); + for (String user : values.keySet()) { + if (values.get(user).equals(answer)) { + DelegateContext userCtx = answerCtx.next("user"); + userCtx.put("id",user); + } + } + } - + return ctx; } - + /** + * This method produces conten context for JSP view file showing + * detailed information about voting. + * @param portalName + * Just portal name. + * @param projectId + * Project Id name from which request for context is comming. + * @param cm + * ContentManager object used for access to cms. + * @param response + * JBossRenderResponse object which is used for creating urls. + * @return + * Content context for detailed information JSP page. + */ public static Context getVotingContext (String portalName, String projectId, ContentManager cm,JBossRenderResponse response) { + // If the projectId is null method returns empty DelegateContext object. if (projectId==null) { return new DelegateContext(); @@ -265,18 +383,44 @@ return ctx; } + /* // Getting the polls for given projectId. Map<String,String> values = desc.getPollsInfoForProject(projectId); + Collection<String> answersRedundant = values.values(); + // Getting possible answers + Set<String> answers = new HashSet<String>(); + answers.addAll(answersRedundant);*/ + + List<Poll> pollDesc = desc.getPollsInfoForProject(projectId); + // Filling the context for portlet. + /** + * Context structure: + * <polls>ONE + * <poll>MANY + * <question>ONE + * <actionUrl>ONE + * <pollId>ONE + * <answer>MANY + * <text />ONE + * </answer> + * </poll> + * </polls> + */ DelegateContext polls = ctx.next("polls"); - for (String pollId:values.keySet()) { + for (Poll pollObj : pollDesc) { DelegateContext poll = polls.next("poll"); - poll.put("question",values.get(pollId)); + poll.put("question",pollObj.getQuestion()); poll.put("actionUrl",response.createActionURL().toString()); - poll.put("pollId",pollId); + poll.put("pollId",pollObj.getPollId()); + + for (String answer : pollObj.getAnswers()) { + DelegateContext answerCtx = poll.next("answer"); + answerCtx.put("text",answer); + } } return ctx; } Modified: trunk/forge/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/PollsDescriptor.java =================================================================== --- trunk/forge/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/PollsDescriptor.java 2005-12-16 23:31:19 UTC (rev 1827) +++ trunk/forge/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/PollsDescriptor.java 2005-12-17 01:20:01 UTC (rev 1828) @@ -46,24 +46,19 @@ /** - * Name of tag in polls descriptor containing poll's value of positive votes. + * Name of tag in polls descriptor containing votes for poll's answer. */ - public static final String POSITIVE_VOTES = "positive"; + public static final String VOTES = "votes"; /** - * Name of tag in polls descriptor containing poll's value of negative votes. + * Name of tag in polls descriptor containing one of poll's answers. */ - public static final String NEGATIVE_VOTES = "negative"; + public static final String ANSWER = "answer"; /** - * String which describes positive vote. + * Name of tag in polls descriptor containing text of one of poll's answer. */ - public static final String POSITIVE_VOTE = "1"; - - /** - * String which describes negative vote. - */ - public static final String NEGATIVE_VOTE = "0"; + public static final String TEXT = "text"; /** * Name of tag in polls descriptor containing poll's question. @@ -151,14 +146,17 @@ // projects' poll descriptors. synchronizePolls(descriptors); + System.out.println ("PollsDescriptor created successfuly"); } catch (Exception e) { e.printStackTrace(); } } - public synchronized Map<String,String> getPollsInfoForProject(String projectId) { + public synchronized List<Poll> getPollsInfoForProject(String projectId) { List<Poll> polls = getProjectPolls(projectId); - Hashtable<String,String> values = null; + List<Poll> pollsCopy = new ArrayList<Poll>(polls.size()); + pollsCopy.addAll(polls); + /*Map<String,String> values = null; if (polls!=null) { values = new Hashtable<String,String>(polls.size()); for (Poll poll:polls) { @@ -168,7 +166,8 @@ } else { values = new Hashtable<String,String>(); } - return values; + return values;*/ + return pollsCopy; } public synchronized Map<String,Poll> getPollsStatsForProject(String projectId) { @@ -420,24 +419,36 @@ Node newQuestion = doc.createElement(QUESTION); Node newQuestionText = doc.createTextNode(poll.getQuestion()); newQuestion.appendChild(newQuestionText); - - Node newPositiveVotes = doc.createElement(POSITIVE_VOTES); - Node newPositiveVotesText = doc.createTextNode(Long.toString(poll.getPositive())); - newPositiveVotes.appendChild(newPositiveVotesText); - - Node newNegativeVotes = doc.createElement(NEGATIVE_VOTES); - Node newNegativeVotesText = doc.createTextNode(Long.toString(poll.getNegative())); - newNegativeVotes.appendChild(newNegativeVotesText); + newPoll.appendChild(newQuestion); + + Node newPollId = doc.createElement(POLL_ID); Node newPollIdText = doc.createTextNode(poll.getPollId()); newPollId.appendChild(newPollIdText); - newPoll.appendChild(newQuestion); - newPoll.appendChild(newPositiveVotes); - newPoll.appendChild(newNegativeVotes); newPoll.appendChild(newPollId); + + for (String answer : poll.getAnswers()) { + Node newAnswer = doc.createElement(ANSWER); + + Node newAnswerText = doc.createElement(TEXT); + Node newAnswerTextText = doc.createTextNode(answer); + newAnswerText.appendChild(newAnswerTextText); + + newAnswer.appendChild(newAnswerText); + + Node newAnswerVotes = doc.createElement(VOTES); + Node newAnswerVotesText = doc.createTextNode(poll.getAnswerVotes(answer).toString()); + newAnswerVotes.appendChild(newAnswerVotesText); + + newAnswer.appendChild(newAnswerVotes); + + + newPoll.appendChild(newAnswer); + } + newProject.appendChild(newPoll); } @@ -445,9 +456,14 @@ } } + + /** GOTOWA!!! - * Method simply just increments the positive counter value for - * given in parameters <code>projectId question</code>. + * Method simply just increments the counter value for + * <code>answer</code> for given in parameters <code>projectId</code> + * and <code>pollId</code> + * @param answer + * Answer for which user gives his vote. * @param userId * User login name. * @param pollId @@ -455,7 +471,7 @@ * @param projectId * Project id name for which is this question. */ - synchronized public boolean votePositive (String pollId,String userId, String projectId) { + synchronized public boolean vote (String answer,String pollId,String userId, String projectId) { System.out.println ("TRYING TO VOTE"); List<Poll> projectPolls = polls.get(projectId); if (projectPolls!=null) { @@ -466,59 +482,22 @@ break; } } - if (!database.votedOnPoll(pollId,userId,POSITIVE_VOTE)) { + if (!database.votedOnPoll(pollId,userId,answer)) { return false; } if (poll!=null) { System.out.println ("VOTING AND CHANGING STATUS"); // Status change to inform about counters modification. changeStatus=true; - poll.incrementPositive(); + poll.vote(answer); return true; } } return false; } + /** GOTOWA!!! - * Method simply just increments the negative counter value for - * given in parameters <code>projectId question</code>. - * - * @param userId - * User login name. - * @param pollId - * Poll's id number. - * @param projectId - * Project id name for which is this question. - */ - synchronized public boolean voteNegative (String pollId,String userId,String projectId) { - System.out.println ("TRYING TO VOTE"); - List<Poll> projectPolls = polls.get(projectId); - if (projectPolls!=null) { - Poll poll = null; - for (Poll p : projectPolls) { - if (p.getPollId().equals(pollId)) { - poll = p; - break; - } - } - if (!database.votedOnPoll(pollId,userId,NEGATIVE_VOTE)) { - return false; - } - if (poll!=null) { - System.out.println ("VOTING AND CHANGING STATUS"); - // Status change to inform about counters modification. - changeStatus=true; - poll.incrementNegative(); - return true; - } - } - return false; - } - - - - /** GOTOWA!!! * This method returns true if there is at least one poll, * connected with given in parameter <projectId>, defined. * If not method returns false. @@ -562,13 +541,12 @@ if (projectNode.getNodeType() == Node.ELEMENT_NODE && projectNode.getNodeName().equals(PROJECT)) { NodeList pollNodes = projectNode.getChildNodes(); String tempProjectId = XmlTools.getAttributeValue(projectNode,PROJECT_ID); - String tempQuestion = null; - String tempPositiveVotes = null; - String tempNegativeVotes = null; - String tempPollId = null; for (int j=0;j< pollNodes.getLength() ; j++) { pollNode = pollNodes.item(j); - if (pollNode.getNodeType()== Node.ELEMENT_NODE && pollNode.getNodeName().equals(POLL)){ + String tempQuestion = null; + Map<String,Integer> answerVotes = new Hashtable<String,Integer>(); + String tempPollId = null; + if (pollNode.getNodeType()== Node.ELEMENT_NODE && pollNode.getNodeName().equals(POLL)) { NodeList properties = pollNode.getChildNodes(); for (int k=0;k< properties.getLength() ; k++) { property = properties.item(k); @@ -576,32 +554,43 @@ String nodeTextCnt = XmlTools.unmarshallText(property); if (property.getNodeName().equals(QUESTION) && nodeTextCnt != null && !nodeTextCnt.trim().equals("")) { tempQuestion = nodeTextCnt.trim(); - } else if (property.getNodeName().equals(POSITIVE_VOTES) && nodeTextCnt !=null && !nodeTextCnt.trim().equals("")) { - tempPositiveVotes = nodeTextCnt.trim(); - } else if (property.getNodeName().equals(NEGATIVE_VOTES) && nodeTextCnt !=null && !nodeTextCnt.trim().equals("")) { - tempNegativeVotes = nodeTextCnt.trim(); + } else if (property.getNodeName().equals(ANSWER)) { + NodeList answerProperties = property.getChildNodes(); + String answerText=null; + Integer answerVotesValue=null; + for (int l=0;l<answerProperties.getLength();l++){ + Node answerProp = answerProperties.item(l); + if (answerProp.getNodeType()==Node.ELEMENT_NODE) { + String nodeContent = XmlTools.unmarshallText(answerProp); + if (answerProp.getNodeName().equals(TEXT) && nodeContent != null && !nodeContent.trim().equals("")) { + answerText = nodeContent.trim(); + } else if (answerProp.getNodeName().equals(VOTES) && nodeContent != null && !nodeContent.trim().equals("")) { + answerVotesValue = new Integer(nodeContent.trim()); + } + } + } + if (answerVotesValue!=null && answerText!=null) { + answerVotes.put(answerText,answerVotesValue); + } } else if (property.getNodeName().equals(POLL_ID) && nodeTextCnt !=null && !nodeTextCnt.trim().equals("")) { tempPollId = nodeTextCnt.trim(); } } } } - } - if (tempProjectId!=null && tempQuestion!=null && tempPositiveVotes!=null - && tempNegativeVotes!=null && tempPollId!=null) { - if (values.get(tempProjectId)==null) { - values.put(tempProjectId,new ArrayList<Poll>()); - } - values.get(tempProjectId).add( - new Poll(Long.valueOf(tempPositiveVotes), - Long.valueOf(tempNegativeVotes),tempQuestion,tempPollId)); - System.out.println ("JESTEM PRZED CREATE"); - if (!database.checkForPollFile(tempPollId)) { - System.out.println ("JESTEM W CREATE"); - database.createNewPollFile(tempPollId); - } - System.out.println ("JESTEM PO CREATE"); - } + if (tempProjectId!=null && tempQuestion!=null && tempPollId!=null && answerVotes.size()>0 ) { + if (values.get(tempProjectId)==null) { + values.put(tempProjectId,new ArrayList<Poll>()); + } + values.get(tempProjectId).add(new Poll(answerVotes,tempQuestion,tempPollId)); + System.out.println ("JESTEM PRZED CREATE"); + if (!database.checkForPollFile(tempPollId)) { + System.out.println ("JESTEM W CREATE"); + database.createNewPollFile(tempPollId); + } + System.out.println ("JESTEM PO CREATE"); + } + } } } return values; Modified: trunk/forge/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/PollsWatcher.java =================================================================== --- trunk/forge/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/PollsWatcher.java 2005-12-16 23:31:19 UTC (rev 1827) +++ trunk/forge/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/PollsWatcher.java 2005-12-17 01:20:01 UTC (rev 1828) @@ -67,7 +67,7 @@ new PollsDescriptor(portalName, contentManager); rw = new ResourceWatcher(contentManager); // Registering ResourceWatcher to watch for main polls descriptor file change. - rw.watchResource(PollTools.getMainXmlPath(portalName)); + //rw.watchResource(PollTools.getMainXmlPath(portalName)); // Getting the project ids names where are poll descriptors. pollDescriptors = descriptor.getPollDescriptors(portalName).keySet(); @@ -86,8 +86,13 @@ */ public Object nodeUpdate(String portalName, Object currentValue) { System.out.println ("IN UPDATE CHANGE STATUS: "+((PollsDescriptor)currentValue).hasChanged()); - if (currentValue==null || rw.checkResources() - || !checkForNewResources((PollsDescriptor)currentValue,portalName)) { + boolean resources = rw.checkResources(); + boolean descriptors = false; + if (currentValue!=null) descriptors = checkForNewResources((PollsDescriptor)currentValue,portalName); + System.out.println ("CHECKING RESOURCES: "+resources); + System.out.println ("DESCRITPROS: "+descriptors); + if (currentValue==null || resources//rw.checkResources() + || !descriptors){//checkForNewResources((PollsDescriptor)currentValue,portalName)) { System.out.println("CREATING NEW DESCRIPTOR OBJECT."); return getDescriptor(portalName); } else if (((PollsDescriptor)currentValue).hasChanged()){ Modified: trunk/forge/portal-extensions/polls/src/java/org/jboss/forge/polls/PollsPortlet.java =================================================================== --- trunk/forge/portal-extensions/polls/src/java/org/jboss/forge/polls/PollsPortlet.java 2005-12-16 23:31:19 UTC (rev 1827) +++ trunk/forge/portal-extensions/polls/src/java/org/jboss/forge/polls/PollsPortlet.java 2005-12-17 01:20:01 UTC (rev 1828) @@ -29,10 +29,7 @@ */ public class PollsPortlet extends JBossPortlet { - public static final String VOTED_PARAMETER_NAME = "org.jboss.forge.polls.voted"; - public static final String FALSE = "false"; - public static final String TRUE = "true"; - public static final String DETAILED_VIEW_REQUEST="details"; + @Inject ContentManager contentManager; @@ -55,10 +52,10 @@ } else { System.out.println ("USER IS NULL"); } - String voted = request.getParameter(VOTED_PARAMETER_NAME); + String voted = request.getParameter(PollTools.VOTED_PARAMETER_NAME); Context pollContext=null; PortletRequestDispatcher rd = null; - if (voted!=null && voted.compareTo(TRUE)==0) { + if (voted!=null && voted.compareTo(PollTools.TRUE)==0) { System.out.println ("USER VOTED"); // Getting the poll context. pollContext = PollTools.getInfoContext(portalName,projectId,contentManager,response); @@ -66,8 +63,8 @@ ForgeHelper.createRepoAccessPath(portalName, PollTools .getInfoJsp())); - } else if (request.getParameter(DETAILED_VIEW_REQUEST)!=null && - request.getParameter(DETAILED_VIEW_REQUEST).compareTo(TRUE)==0 ) { + } else if (request.getParameter(PollTools.DETAILED_VIEW_REQUEST)!=null && + request.getParameter(PollTools.DETAILED_VIEW_REQUEST).compareTo(PollTools.TRUE)==0 ) { System.out.println ("DETAILED VIEW"); @@ -99,7 +96,7 @@ String pollId = request.getParameter("pollId"); PortletURL url=response.createRenderURL(); System.out.println ("HELLO I'M IN POLLPORTLET VOTE: "+vote); - String userId = request.getUser()==null?Integer.toString((int)(Math.random()*100000)):request.getUser().getUserName(); + String userId = request.getUser()==null?"user"+Integer.toString((int)(Math.random()*100000)):request.getUser().getUserName(); // Getting name of the project on which the download counter is used. String projectId = ProjectsHelper.getSelectedProjectId(request); @@ -113,24 +110,13 @@ } if (vote != null && !vote.equals("")) { - System.out.println ("USER VOTE"); - response.setRenderParameter(VOTED_PARAMETER_NAME,TRUE); - if (vote.equals(TRUE)){ - System.out.println ("VOTING POSITIVLY"); - System.out.println ("POLLID:"+pollId+" userId:"+userId+" PROJECTID: "+projectId); - if (PollTools.getDesc(portalName,contentManager).votePositive(pollId,userId,projectId)) { - System.out.println ("ZAGŁOSOWANO"); - } else { - System.out.println ("GŁOS ODRZUCONO"); - } - } else if (vote.equals(FALSE)){ - System.out.println("VOTING NEGATIVLY"); - System.out.println ("POLLID:"+pollId+" userId:"+userId+" PROJECTID: "+projectId); - if (PollTools.getDesc(portalName,contentManager).voteNegative(pollId,userId,projectId)) { - System.out.println ("ZAGŁOSOWANO"); - } else { - System.out.println ("GŁOS ODRZUCONO"); - } + response.setRenderParameter(PollTools.VOTED_PARAMETER_NAME,PollTools.TRUE); + System.out.println ("VOTING"); + System.out.println ("VOTE: "+vote+"POLLID:"+pollId+" userId:"+userId+" PROJECTID: "+projectId); + if (PollTools.getDesc(portalName,contentManager).vote(vote,pollId,userId,projectId)) { + System.out.println ("ZAGŁOSOWANO"); + } else { + System.out.println ("GŁOS ODRZUCONO"); } } else { System.out.println ("USER ZONK"); |