From: <jbo...@li...> - 2005-12-09 22:09:42
|
Author: unibrew Date: 2005-12-09 17:09:34 -0500 (Fri, 09 Dec 2005) New Revision: 1770 Added: trunk/forge/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/PollVotesDatabase.java 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/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/forge-common/src/java/org/jboss/forge/common/projects/ProjectsHelper.java Log: [JBLAB-407] Updating files for PollsPortlet. 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-09 22:08:33 UTC (rev 1769) +++ trunk/forge/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/Poll.java 2005-12-09 22:09:34 UTC (rev 1770) @@ -2,18 +2,21 @@ public class Poll { - String question; - long positive; - long negative; + private String question; + private long positive; + private long negative; + private String pollId; - public Poll (long positive, long negative, String question) { + public Poll (long positive, long negative, String question, String pollId) { this.positive = positive; this.negative = negative; 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 () { @@ -40,6 +43,10 @@ public String getQuestion() { return question; } + + public String getPollId() { + return pollId; + } 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-09 22:08:33 UTC (rev 1769) +++ trunk/forge/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/PollTools.java 2005-12-09 22:09:34 UTC (rev 1770) @@ -24,8 +24,16 @@ package org.jboss.forge.common.projects; import java.io.File; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.LinkedList; import java.util.List; +import java.util.Map; +import java.util.Set; +import javax.portlet.PortletURL; + import org.jboss.forge.common.ForgeHelper; import org.jboss.portal.common.context.Context; import org.jboss.portal.common.context.DelegateContext; @@ -50,6 +58,11 @@ public static final String POLLS_VOTING_JSP="polls_voting.jsp"; /** + * Name of JSP view file prepared for displaying detailed voting stats. + */ + public static final String POLLS_DETAILS_JSP="polls_details.jsp"; + + /** * Private constructor made in order to prevent from creating * PollTools object. */ @@ -106,6 +119,17 @@ /** * Method constructs path to the PollPortlet JSP view file containing + * detailed information about who and how has voted on specified poll. + * + * @param portalName + * @return Path to the PollPortlet's JSP voting detailed info view file. + */ + public static String getDetailsJsp() { + return POLLS_DIR + File.separator + POLLS_DETAILS_JSP; + } + + /** + * Method constructs path to the PollPortlet JSP view file containing * voting question. * * @param portalName @@ -117,13 +141,110 @@ public static Context getInfoContext (String portalName,String projectId, ContentManager cm,JBossRenderResponse response) { + // If the projectId is null method returns empty DelegateContext object. + if (projectId==null) { + return new DelegateContext(); + } - return new DelegateContext(); + // Creating new empty context. + DelegateContext ctx = new DelegateContext(); + + // Getting the PollsDescriptor object containing counters. + PollsDescriptor desc = getDesc(portalName,cm); + + // If there isn't a descriptor in cache, return empty context. + if (desc==null) { + return ctx; + } + + // If there is no tracked link for projectId return empty context. + if (!desc.checkForProjectPolls(projectId)) { + return ctx; + } + + // Getting the polls for given projectId. + Map<String,Poll> values = desc.getPollsStatsForProject(projectId); + + // Filling the context for portlet. + DelegateContext polls = ctx.next("polls"); + Poll temporary=null; + for (String pollId:values.keySet()) { + PortletURL url = response.createRenderURL(); + DelegateContext poll = polls.next("poll"); + temporary = values.get(pollId); + poll.put("question",temporary.getQuestion()); + poll.put("renderUrl",url.toString()); + 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())); + } + return ctx; + } + public static Context getDetailsContext (String portalName,String projectId,String pollId, + ContentManager cm,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(); + + // Getting the PollsDescriptor object containing counters. + PollsDescriptor desc = getDesc(portalName,cm); + + // If there isn't a descriptor in cache, return empty context. + if (desc==null) { + return ctx; + } + + // If there is no tracked link for projectId return empty context. + if (!desc.checkForProjectPolls(projectId)) { + return ctx; + } + + // Getting the polls for given projectId. + Map<String,String> values = desc.getDetailStatsForPoll(pollId); + + //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); + } + } + + // Filling the context for portlet. + DelegateContext poll = ctx.next("poll"); + + Poll tempPoll = desc.getPoll(projectId,pollId); + poll.put("question",tempPoll!=null?tempPoll.getQuestion():""); + poll.put("renderUrl",response.createRenderURL().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():""); + } + + return ctx; + + } + + public static Context getVotingContext (String portalName, String projectId, ContentManager cm,JBossRenderResponse response) { -// If the projectId is null method returns empty DelegateContext object. + // If the projectId is null method returns empty DelegateContext object. if (projectId==null) { return new DelegateContext(); } @@ -145,19 +266,17 @@ } // Getting the polls for given projectId. - List<Poll> values = desc.getPollsMap().get(projectId); + Map<String,String> values = desc.getPollsInfoForProject(projectId); // Filling the context for portlet. DelegateContext polls = ctx.next("polls"); - for (Poll pollElem:values) { + for (String pollId:values.keySet()) { DelegateContext poll = polls.next("poll"); - - // Resolving the question - String question = pollElem.getQuestion(); - - poll.put("question",question); - poll.put("actionurl",response.createActionURL().toString()); + + poll.put("question",values.get(pollId)); + poll.put("actionUrl",response.createActionURL().toString()); + poll.put("pollId",pollId); } return ctx; } Added: trunk/forge/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/PollVotesDatabase.java =================================================================== --- trunk/forge/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/PollVotesDatabase.java 2005-12-09 22:08:33 UTC (rev 1769) +++ trunk/forge/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/PollVotesDatabase.java 2005-12-09 22:09:34 UTC (rev 1770) @@ -0,0 +1,113 @@ +package org.jboss.forge.common.projects; + +import java.util.Hashtable; +import java.util.Map; + +import org.jboss.shotoku.ContentManager; +import org.jboss.shotoku.Directory; +import org.jboss.shotoku.Node; +import org.jboss.shotoku.aop.Inject; +import org.jboss.shotoku.exceptions.RepositoryException; +import org.jboss.shotoku.exceptions.ResourceAlreadyExists; +import org.jboss.shotoku.exceptions.ResourceDoesNotExist; + +public class PollVotesDatabase { + + public static final String DATABASE_LOCATION = "default/polls/database/"; + + Directory databaseDir; + + @Inject + ContentManager contentManager; + + public PollVotesDatabase() throws ResourceDoesNotExist { + databaseDir =contentManager.getDirectory(DATABASE_LOCATION); + } + + public void createNewPollFile (String fileName) { + try { + System.out.println ("POLLVOTESDATABASE CREATENEWPOLL"); + Node node = databaseDir.newNode(fileName); + node.save("[Polls] Creating new poll's database file."); + } catch (ResourceAlreadyExists e) { + System.out.println ("[POLLPORTLET] Database file for poll already exists!"); + e.printStackTrace(); + } catch (RepositoryException e2) { + System.out.println ("[POLLPORTLET] Problem with creating data file for poll!"); + e2.printStackTrace(); + } + } + + + public boolean checkForPollFile(String pollId) { + try { + databaseDir.getNode(pollId); + } catch (ResourceDoesNotExist e) { + return false; + } + return true; + } + + public boolean votedOnPoll (String pollId, String userId, String vote) { + System.out.println ("SETTING PROPERTY FOR FILE"); + Node pollFile=null; + try { + pollFile = databaseDir.getNode(pollId); + String voteValue = pollFile.getProperty(userId); + if (voteValue!= null && !voteValue.equals("")) + return false; + } catch (RepositoryException e) { + System.out.println ("[POLLS] RepositoryException while getting properties for Node."); + e.printStackTrace(); + return false; + } catch (ResourceDoesNotExist e2) { + System.out.println("[POLLPORTLET] Database file for poll didn't exist!"); + e2.printStackTrace(); + try { + databaseDir.newNode(pollId); + } catch (ResourceAlreadyExists e3) { + e3.printStackTrace(); + } + } + pollFile.setProperty(userId,vote); + pollFile.save("[Polls] Saving property for poll's database file."); + return true; + } + + public Map<String,String> getUserVotesForPollFile (String pollId) { + Map<String,String> userVotes = null; + if (pollId==null) return new Hashtable<String,String>(0); + try { + Node pollFile = databaseDir.getNode(pollId); + userVotes = pollFile.getProperties(); + System.out.println ("I'M BEFORE DISPLAYING FILE PROPERTIES."); + for (String first:userVotes.keySet()){ + System.out.println("PROPERTY: "+first+" VALUE: "+userVotes.get(first)); + } + } catch (RepositoryException e) { + System.out.println ("[POLLS] RepositoryException while getting properties for Node."); + e.printStackTrace(); + return new Hashtable<String,String>(0); + } catch (ResourceDoesNotExist e2) { + System.out.println("[POLLPORTLET] Database file for poll didn't exist!"); + e2.printStackTrace(); + return new Hashtable<String,String>(0); + } + return userVotes; + } + + public void removePollDataFile (String pollId) { + try { + Node pollFile = databaseDir.getNode(pollId); + pollFile.delete(); + } catch (ResourceDoesNotExist e2) { + System.out.println ("[PRIMATESPORTLET] Poll's data file was already deleted."); + e2.printStackTrace(); + } + catch (RepositoryException e) { + System.out.println ("[POLLPORTLET] Problem while deleting poll's data file."); + e.printStackTrace(); + } + } + +} 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-09 22:08:33 UTC (rev 1769) +++ trunk/forge/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/PollsDescriptor.java 2005-12-09 22:09:34 UTC (rev 1770) @@ -56,6 +56,16 @@ public static final String NEGATIVE_VOTES = "negative"; /** + * String which describes positive vote. + */ + public static final String POSITIVE_VOTE = "1"; + + /** + * String which describes negative vote. + */ + public static final String NEGATIVE_VOTE = "0"; + + /** * Name of tag in polls descriptor containing poll's question. */ public static final String QUESTION = "question"; @@ -76,6 +86,11 @@ public static final String POLL = "poll"; /** + * Name of a tag containing unique id of a poll. + */ + public static final String POLL_ID = "id"; + + /** * This Map contains all polls for the portal. * Keys are project id names and values are Lists of polls defined for that project. */ @@ -86,6 +101,8 @@ */ private ContentManager contentManager; + private PollVotesDatabase database; + /** * This boolean variable turns to true if one of the polls * has been incremented. If value is true the polls Map @@ -114,6 +131,9 @@ this.contentManager = contentManager; try { + + // Constructing object used for getting to Poll's database. + database = new PollVotesDatabase(); // Parsing main download counters descriptor. DOMParser parser = new DOMParser(); @@ -136,15 +156,39 @@ } } - /** GOTOWA!!! - * Method only returns all polls. - * @return Returns a Map containing polls. - */ - public Map<String,List<Poll>> getPollsMap () { - return polls; + public synchronized Map<String,String> getPollsInfoForProject(String projectId) { + List<Poll> polls = getProjectPolls(projectId); + Hashtable<String,String> values = null; + if (polls!=null) { + values = new Hashtable<String,String>(polls.size()); + for (Poll poll:polls) { + values.put(poll.getPollId(),poll.getQuestion()); + } + + } else { + values = new Hashtable<String,String>(); + } + return values; } + public synchronized Map<String,Poll> getPollsStatsForProject(String projectId) { + List<Poll> polls = getProjectPolls(projectId); + Map<String,Poll> values = null; + if (polls!=null) { + values = new Hashtable<String,Poll>(polls.size()); + for (Poll poll:polls){ + values.put(poll.getPollId(),poll); + } + } else { + values = new Hashtable<String,Poll>(); + } + return values; + } + public Map<String,String> getDetailStatsForPoll (String pollId) { + return database.getUserVotesForPollFile(pollId); + } + /** GOTOWA!!! * This method searches through projects direcories in order to find all poll descriptors. * Method returns Map containing pairs of String projectId and @@ -198,6 +242,10 @@ */ 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 links for them. + removeNotTrackedProjects(projectPolls.keySet()); + // Iterating through projects nodes containing poll descriptors. for (String projectId:projectPolls.keySet()){ try { @@ -208,6 +256,10 @@ // Getting list of polls from polls Map for a given projectId name. List<Poll> xmlProjectPolls = getProjectPolls(projectId); + if (xmlProjectPolls==null) { + xmlProjectPolls= new LinkedList<Poll>(); + } + // Getting the list of polls from project's poll descriptor. List<Poll> descPolls = pollDesc.getPolls(); @@ -241,6 +293,24 @@ changeStatus=false; } + private synchronized void removeNotTrackedProjects(Set<String> projectIds) { + polls.keySet().retainAll(projectIds); + } + + public synchronized Poll getPoll (String projectId,String pollId) { + if (projectId!=null && pollId!=null && + !projectId.equals("") && !pollId.equals("") && polls!=null) { + List<Poll> list = polls.get(projectId); + if (list==null) return null; + for (Poll poll : list) { + if (poll.getPollId().equals(pollId)) { + return poll; + } + } + } + return null; + } + /** GOTOWA!!! * Method removes polls specified in <code>pollsToDelete</code> * from tracking their votes. @@ -251,6 +321,7 @@ private synchronized void removePollsFromVoting (List<Poll> pollsToDelete) { // Removing polls which shouldn't be tracked any more. for (Poll poll:pollsToDelete) { + database.removePollDataFile(poll.getPollId()); polls.remove(poll); } } @@ -271,6 +342,7 @@ for (Poll poll:newPolls) { if (!polls.get(projectId).contains(poll)){ polls.get(projectId).add(poll); + database.createNewPollFile(poll.getPollId()); } } } @@ -295,7 +367,7 @@ public void synchronizeWithFile(String portalName) { String pathToPollsXml = File.separator + PollTools.getMainXmlPath(portalName); - + System.out.println ("SYNCHRONIZING MAIN XML FILE"); try { DOMParser parser = new DOMParser(); @@ -320,7 +392,7 @@ org.jboss.shotoku.Node xmlFile = contentManager.getNode(pathToPollsXml); xmlFile.setContent(xmlString); xmlFile.save ("[Polls] Main xml descriptor file update."); - + System.out.println ("AFTER SYNCHRONIZING MAIN XML FILE"); } catch (Exception e) { e.printStackTrace(); } @@ -339,7 +411,9 @@ Node newProject = doc.createElement(PROJECT); Node projectAttribute = doc.createAttribute(PROJECT_ID); projectAttribute.appendChild(doc.createTextNode(projectId)); - newProject.appendChild(projectAttribute); + //newProject.appendChild(projectAttribute); + newProject.getAttributes().setNamedItem(projectAttribute); + for (Poll poll:polls.get(projectId)) { Node newPoll = doc.createElement(POLL); @@ -354,11 +428,16 @@ Node newNegativeVotes = doc.createElement(NEGATIVE_VOTES); Node newNegativeVotesText = doc.createTextNode(Long.toString(poll.getNegative())); newNegativeVotes.appendChild(newNegativeVotesText); - + + 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); + newProject.appendChild(newPoll); } @@ -369,43 +448,72 @@ /** GOTOWA!!! * Method simply just increments the positive counter value for * given in parameters <code>projectId question</code>. - * - * @param question - * Poll's question. + * @param userId + * User login name. + * @param pollId + * Poll's id number. * @param projectId * Project id name for which is this question. */ - synchronized public void incrementPositive (String question,String projectId) { + synchronized public boolean votePositive (String pollId,String userId, String projectId) { + System.out.println ("TRYING TO VOTE"); List<Poll> projectPolls = polls.get(projectId); if (projectPolls!=null) { - int position = projectPolls.indexOf(new Poll(question)); - if (position!=-1) { + Poll poll = null; + for (Poll p : projectPolls) { + if (p.getPollId().equals(pollId)) { + poll = p; + break; + } + } + if (!database.votedOnPoll(pollId,userId,POSITIVE_VOTE)) { + return false; + } + if (poll!=null) { + System.out.println ("VOTING AND CHANGING STATUS"); // Status change to inform about counters modification. changeStatus=true; - projectPolls.get(position).incrementPositive(); + poll.incrementPositive(); + return true; } } + return false; } /** GOTOWA!!! * Method simply just increments the negative counter value for * given in parameters <code>projectId question</code>. * - * @param question - * Poll's question. + * @param userId + * User login name. + * @param pollId + * Poll's id number. * @param projectId * Project id name for which is this question. */ - synchronized public void incrementNegative (String question,String projectId) { + 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) { - int position = projectPolls.indexOf(new Poll(question)); - if (position!=-1) { + 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; - projectPolls.get(position).incrementNegative(); + poll.incrementNegative(); + return true; } } + return false; } @@ -442,7 +550,7 @@ * @return * Map<String,List<Poll>> containing polls read from the xml nodes. */ - private static Map<String,List<Poll>> getValuesFromNodes (NodeList nodes) { + private Map<String,List<Poll>> getValuesFromNodes (NodeList nodes) { Map<String,List<Poll>> values = new Hashtable<String,List<Poll>>(); // Temporary variables used for parsing. @@ -457,6 +565,7 @@ 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)){ @@ -471,16 +580,27 @@ tempPositiveVotes = nodeTextCnt.trim(); } else if (property.getNodeName().equals(NEGATIVE_VOTES) && nodeTextCnt !=null && !nodeTextCnt.trim().equals("")) { tempNegativeVotes = nodeTextCnt.trim(); + } else if (property.getNodeName().equals(POLL_ID) && nodeTextCnt !=null && !nodeTextCnt.trim().equals("")) { + tempPollId = nodeTextCnt.trim(); } } } } } - if (tempProjectId!=null && tempQuestion!=null && tempPositiveVotes!=null && tempNegativeVotes!=null) { + 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(tempQuestion)); + 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"); } } } 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-09 22:08:33 UTC (rev 1769) +++ trunk/forge/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/PollsWatcher.java 2005-12-09 22:09:34 UTC (rev 1770) @@ -24,6 +24,7 @@ package org.jboss.forge.common.projects; import java.util.Collection; +import java.util.Set; import org.jboss.forge.common.service.NodeWatcher; import org.jboss.forge.common.service.ResourceWatcher; @@ -36,6 +37,11 @@ ResourceWatcher rw; /** + * This Collection contains names of projects which contain poll.xml descriptors. + */ + Set<String> pollDescriptors; + + /** * Simple constructor saving ContentManager given in parameter * <code>conentManager</code> * @param contentManager @@ -61,14 +67,14 @@ new PollsDescriptor(portalName, contentManager); rw = new ResourceWatcher(contentManager); // Registering ResourceWatcher to watch for main polls descriptor file change. - rw.watchResource(DownloadCounterTools.getMainXmlPath(portalName)); + rw.watchResource(PollTools.getMainXmlPath(portalName)); // Getting the project ids names where are poll descriptors. - Collection<String> projects = descriptor.getPollDescriptors(portalName).keySet(); + pollDescriptors = descriptor.getPollDescriptors(portalName).keySet(); // Adding found project poll descriptors to the ResourceWatcher to watch // for their changes. - for (String id:projects) { + for (String id:pollDescriptors) { rw.watchResource(PollTools.getProjectXmlPath(portalName,id)); } return descriptor; @@ -79,17 +85,26 @@ * If the object is changed the method returns new object if not returns null. */ public Object nodeUpdate(String portalName, Object currentValue) { - if (currentValue==null || rw.checkResources()) { + System.out.println ("IN UPDATE CHANGE STATUS: "+((PollsDescriptor)currentValue).hasChanged()); + if (currentValue==null || rw.checkResources() + || !checkForNewResources((PollsDescriptor)currentValue,portalName)) { + System.out.println("CREATING NEW DESCRIPTOR OBJECT."); return getDescriptor(portalName); } else if (((PollsDescriptor)currentValue).hasChanged()){ + System.out.println ("I'M IN POLLWATCHER MAIN XML UPDATE."); PollsDescriptor descriptor = (PollsDescriptor)currentValue; descriptor.synchronizeWithFile(portalName); + System.out.println ("I'M IN POLLWATCHER AFTER MAIN XML UPDATE."); return null; } + System.out.println ("AT THE END OF NODEUPDATE"); return null; } + private boolean checkForNewResources (PollsDescriptor desc, String portalName) { + return pollDescriptors.containsAll(desc.getPollDescriptors(portalName).keySet()); + } } Modified: trunk/forge/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/ProjectsHelper.java =================================================================== --- trunk/forge/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/ProjectsHelper.java 2005-12-09 22:08:33 UTC (rev 1769) +++ trunk/forge/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/ProjectsHelper.java 2005-12-09 22:09:34 UTC (rev 1770) @@ -25,7 +25,9 @@ import java.util.Map; import org.jboss.forge.common.ForgeHelper; +import org.jboss.forge.common.projects.permissions.ActionRequestPermissionsChecker; import org.jboss.forge.common.projects.permissions.RenderRequestPermissionsChecker; +import org.jboss.portlet.JBossActionRequest; import org.jboss.portlet.JBossRenderRequest; /** @@ -159,6 +161,46 @@ return projectId; } + + /** + * Equivalent to <code>getSelectedProjectId(request, false)</code>. + * @param request + * A request object from which the selected project name will be + * read. + * @return Selected project's id, or null, if no project is selected (never + * the default project, as it cannot be selected). + */ + public static String getSelectedProjectId(JBossActionRequest request) { + return getSelectedProjectId(request, false); + } + + /** + * @param request + * A request object from which the selected project name will be + * read. + * @param withDefault + * True if default project name should be returned if no project + * is selected. False if null should be returned in such case. + * @return Selected project's id, or the default project's id/ null, depending + * on <code>withDefault</code>, if no project is selected. + */ + public static String getSelectedProjectId(JBossActionRequest request, + boolean withDefault) { + String projectId = request.getParameter(PROJECT_URL_PARAM); + + if ((withDefault) && (projectId == null)) { + projectId = DEFAULT_PROJECT; + } else if ((!withDefault) && (DEFAULT_PROJECT.equals(projectId))) { + projectId = null; + } else if ((!DEFAULT_PROJECT.equals(projectId)) && + (getProjects(ForgeHelper.getPortalName(request)).getProjectContext( + new ActionRequestPermissionsChecker(request), projectId) == null)) { + // No project context --> project does not exist. + projectId = null; + } + + return projectId; + } /** * Prepares a request object for generating a JSP. PROJECT_NAME and |