From: <jbo...@li...> - 2005-11-27 22:22:25
|
Author: unibrew Date: 2005-11-27 17:22:15 -0500 (Sun, 27 Nov 2005) New Revision: 1654 Modified: trunk/forge/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/DownloadCountersDescriptor.java trunk/forge/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/DownloadCountersWatcher.java Log: [JBLAB-543] DownloadCounters sources update. Modified: trunk/forge/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/DownloadCountersDescriptor.java =================================================================== --- trunk/forge/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/DownloadCountersDescriptor.java 2005-11-27 16:00:20 UTC (rev 1653) +++ trunk/forge/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/DownloadCountersDescriptor.java 2005-11-27 22:22:15 UTC (rev 1654) @@ -25,6 +25,7 @@ import java.io.File; import java.io.InputStream; +import java.util.HashSet; import java.util.Hashtable; import java.util.LinkedList; import java.util.List; @@ -156,7 +157,8 @@ try { membersDir = contentManager.getDirectory(portalName+File.separator+ProjectsHelper.MEMBERS_DIR); } catch (ResourceDoesNotExist e) { - // TODO + e.printStackTrace(); + System.out.println ("[DOWNLOADCOUNTERSDESCRIPTOR] Members directory not exists."); return null; } @@ -171,8 +173,7 @@ try { counter = projectDir.getNode(ProjectsHelper.DOWNLOADCOUNTER_DESC); } catch (ResourceDoesNotExist e) { - // TODO - return null; + break; } String projectId = projectDir.getName(); nodes.put(projectId,counter); @@ -194,6 +195,14 @@ */ private void synchronizeCounters (Map<String,org.jboss.shotoku.Node> counters) { + // Checking if tracked projects still have their counter.xml descriptors. + // If not deleting all tracked links for them. + Set<String> projects = getTrackedProjects(); + if (!counters.keySet().containsAll(projects)) { + projects.removeAll(counters.keySet()); + removeLinksForProjects (projects); + } + // Iterating through projects nodes containing download counter descriptors. for (String projectId:counters.keySet()){ try { @@ -266,6 +275,25 @@ } } + private synchronized void removeLinksForProjects (Set<String> projects) { + Set<String> countersLinks = downloadCounters.keySet(); + List<String> linksForRemoval = new LinkedList<String>(); + for (String link: countersLinks) { + if (projects.contains(downloadCounters.get(link).getProjectId())){ + linksForRemoval.add(new String(link)); + } + } + downloadCounters.keySet().removeAll(linksForRemoval); + } + + private synchronized Set<String> getTrackedProjects () { + Set<String> projects = new HashSet<String>(); + for (String link:downloadCounters.keySet()) { + projects.add(downloadCounters.get(link).getProjectId()); + } + return projects; + } + /** * This method returns a List<String> of links which * are now tracked for project given by <projectId> parameter. @@ -277,7 +305,7 @@ private synchronized List<String> getProjectLinks (String projectId) { List<String> links = new LinkedList<String>(); for (String link:downloadCounters.keySet()) { - if (link.indexOf(File.separator+projectId+File.separator)!=-1) { + if (downloadCounters.get(link).getProjectId().equals(projectId)) { links.add(new String(link)); } } @@ -383,7 +411,7 @@ */ public synchronized boolean checkForProjectCounters(String projectId) { for (String link:downloadCounters.keySet()) { - if (link.indexOf(File.separator+projectId+File.separator)!=-1) { + if (downloadCounters.get(link).getProjectId().equals(projectId)) { return true; } } Modified: trunk/forge/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/DownloadCountersWatcher.java =================================================================== --- trunk/forge/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/DownloadCountersWatcher.java 2005-11-27 16:00:20 UTC (rev 1653) +++ trunk/forge/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/DownloadCountersWatcher.java 2005-11-27 22:22:15 UTC (rev 1654) @@ -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; @@ -41,8 +42,12 @@ ContentManager contentManager; ResourceWatcher rw; - + /** + * This Collection contains names of projects which contain counter.xml descriptors. + */ + Set<String> counterDescriptors; + /** * Simple constructor saving ContentManager given in parameter * <code>conentManager</code> * @param contentManager @@ -71,11 +76,10 @@ rw.watchResource(DownloadCounterTools.getMainXmlPath(portalName)); // Getting the project ids names where are project download counter descriptors. - Collection<String> projects = descriptor.getDownloadDescriptors(portalName).keySet(); - + counterDescriptors = descriptor.getDownloadDescriptors(portalName).keySet(); // Adding found project download counter descriptors to the ResourceWatcher to watch // for their changes. - for (String id:projects) { + for (String id:counterDescriptors) { rw.watchResource(DownloadCounterTools.getProjectXmlPath(portalName,id)); } return descriptor; @@ -86,7 +90,8 @@ * 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()) { + if (currentValue==null || rw.checkResources() + || !checkForNewResources((DownloadCountersDescriptor)currentValue,portalName)) { return getDescriptor(portalName); } else if (((DownloadCountersDescriptor)currentValue).hasChanged()){ DownloadCountersDescriptor descriptor = @@ -97,6 +102,9 @@ return null; } + private boolean checkForNewResources (DownloadCountersDescriptor desc, String portalName) { + return counterDescriptors.containsAll(desc.getDownloadDescriptors(portalName).keySet()); + } } |