From: <jbo...@li...> - 2005-12-09 16:26:53
|
Author: wrzep Date: 2005-12-09 11:26:35 -0500 (Fri, 09 Dec 2005) New Revision: 1754 Added: trunk/forge/portal-extensions/forge-status/src/java/org/jboss/forge/status/plugins/ScorePlugin.java trunk/forge/portal-extensions/forge-status/src/java/org/jboss/forge/status/plugins/WeightedScorePlugin.java Removed: trunk/forge/portal-extensions/forge-status/src/java/org/jboss/forge/status/ScoreAlgorithmFactory.java trunk/forge/portal-extensions/forge-status/src/java/org/jboss/forge/status/WeightedScoreAlgorithmFactory.java Modified: trunk/forge/portal-extensions/forge-status/src/java/org/jboss/forge/status/Status.java trunk/forge/portal-extensions/forge-status/src/java/org/jboss/forge/status/StatusDescriptor.java Log: computing project score is now done in score plugins http://jira.jboss.com/jira/browse/JBLAB-415 Pawel Deleted: trunk/forge/portal-extensions/forge-status/src/java/org/jboss/forge/status/ScoreAlgorithmFactory.java =================================================================== --- trunk/forge/portal-extensions/forge-status/src/java/org/jboss/forge/status/ScoreAlgorithmFactory.java 2005-12-09 15:21:18 UTC (rev 1753) +++ trunk/forge/portal-extensions/forge-status/src/java/org/jboss/forge/status/ScoreAlgorithmFactory.java 2005-12-09 16:26:35 UTC (rev 1754) @@ -1,35 +0,0 @@ -/* - * 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.status; - -import java.util.Collection; - -import org.jboss.forge.status.plugins.Plugin; - -/** -* @author Pawel Wrzeszcz -*/ -public abstract class ScoreAlgorithmFactory { - - public abstract int calculateScore(String projectId, Collection<Plugin> plugins); -} Modified: trunk/forge/portal-extensions/forge-status/src/java/org/jboss/forge/status/Status.java =================================================================== --- trunk/forge/portal-extensions/forge-status/src/java/org/jboss/forge/status/Status.java 2005-12-09 15:21:18 UTC (rev 1753) +++ trunk/forge/portal-extensions/forge-status/src/java/org/jboss/forge/status/Status.java 2005-12-09 16:26:35 UTC (rev 1754) @@ -45,6 +45,7 @@ //import org.jboss.forge.status.plugins.InvalidPluginPropertiesException; import org.jboss.forge.status.plugins.InvalidPluginPropertiesException; import org.jboss.forge.status.plugins.Plugin; +import org.jboss.forge.status.plugins.ScorePlugin; import org.jboss.forge.status.plugins.StatusPlugin; import org.jboss.logging.Logger; @@ -63,18 +64,19 @@ private final static String PLUGIN_PROPERTIES_ELEMENT = "properties"; private String portalName; - private ScoreAlgorithmFactory scoreAlgorithm; private Projects projects; - private List<Plugin> plugins; + private List<Plugin> statusPlugins; + private List<Plugin> scorePlugins; + private List<Plugin> allPlugins; private Logger log; private HashSet<String> pluginsElements; - Status(String portalName, Node statusRoot, Node pluginsRoot, ScoreAlgorithmFactory scoreAlgorithm) { + Status(String portalName, Node statusRoot, Node pluginsRoot) { this.portalName = portalName; - this.scoreAlgorithm = scoreAlgorithm; + log = Logger.getLogger(this.getClass()); initPluginElements(); @@ -82,14 +84,27 @@ // Get the projects projects = ProjectsHelper.getProjects(portalName); - // Get the plugins + // Get the status plugins + Set<Node> statusPluginsNodes = getPluginsNodes(pluginsRoot, STATUS_PLUGIN_ELEMENT); + statusPlugins = getPlugins(statusPluginsNodes); + + // Get the score plugins + Set<Node> scorePluginsNodes = getPluginsNodes(pluginsRoot, SCORE_PLUGIN_ELEMENT); + scorePlugins = getPlugins(scorePluginsNodes); + + allPlugins = new ArrayList<Plugin>(); + allPlugins.addAll(statusPlugins); + allPlugins.addAll(scorePlugins); + } + + private Set<Node> getPluginsNodes(Node pluginsRoot, String pluginElement) { HashSet<String> pluginElementSet = new HashSet<String>(); - pluginElementSet.add(STATUS_PLUGIN_ELEMENT); - pluginElementSet.add(SCORE_PLUGIN_ELEMENT); + pluginElementSet.add(pluginElement); Set<Node> pluginsNodes = getChildNodesSet(pluginsRoot, pluginElementSet); - plugins = getPlugins(pluginsNodes); + + return pluginsNodes; } - + private void initPluginElements() { pluginsElements = new HashSet<String>(); @@ -110,8 +125,8 @@ public void fillContext(DelegateContext context) { // Set collumns names - for (Iterator iter = plugins.iterator(); iter.hasNext();) { - StatusPlugin plugin = (StatusPlugin) iter.next(); + for (Iterator iter = allPlugins.iterator(); iter.hasNext();) { + Plugin plugin = (Plugin) iter.next(); DelegateContext collumnContext = new DelegateContext(); collumnContext.put("name", plugin.getName()); @@ -148,15 +163,12 @@ projectContext.put("name", projects.getProjectName(projectId)); projectContext.put("link", projects.getProjectLink(projectId)); - int projectScore = calculateScore(projectId); - projectContext.put("score", projectScore); - - fillEntries(projectContext, projectId); + fillEntries(projectContext, allPlugins, projectId);; } - private void fillEntries(DelegateContext projectContext, String projectId) { + private void fillEntries(DelegateContext projectContext, List<Plugin> plugins, String projectId) { for (Iterator iter = plugins.iterator(); iter.hasNext();) { - StatusPlugin plugin = (StatusPlugin) iter.next(); + Plugin plugin = (Plugin) iter.next(); DelegateContext entryContext = new DelegateContext(); entryContext.put("value", plugin.getValue(projectId)); @@ -214,8 +226,8 @@ if (pluginType == STATUS_PLUGIN_ELEMENT) { ((StatusPlugin) plugin).init(pluginName, pluginId, projects, pluginSpecificPropertiesMap); - } else { - + } else { /* score plugin */ + ((ScorePlugin) plugin).init(pluginName, pluginId, statusPlugins, pluginSpecificPropertiesMap); } } catch (InvalidPluginPropertiesException e) { @@ -246,10 +258,6 @@ return ret; } - private int calculateScore(String projectId) { - return scoreAlgorithm.calculateScore(projectId, plugins); - } - /** * For the given Node, computes Set of it's child Nodes. * Only child Nodes with names included in <code>nodesNames</code> Set Modified: trunk/forge/portal-extensions/forge-status/src/java/org/jboss/forge/status/StatusDescriptor.java =================================================================== --- trunk/forge/portal-extensions/forge-status/src/java/org/jboss/forge/status/StatusDescriptor.java 2005-12-09 15:21:18 UTC (rev 1753) +++ trunk/forge/portal-extensions/forge-status/src/java/org/jboss/forge/status/StatusDescriptor.java 2005-12-09 16:26:35 UTC (rev 1754) @@ -55,7 +55,7 @@ if ((root.getNodeType() == Node.ELEMENT_NODE) && (root.getNodeName().equals("projects"))) {}*/ - status = new Status(portalName, statusRoot, pluginsRoot, new WeightedScoreAlgorithmFactory()); + status = new Status(portalName, statusRoot, pluginsRoot); fillContext(); Deleted: trunk/forge/portal-extensions/forge-status/src/java/org/jboss/forge/status/WeightedScoreAlgorithmFactory.java =================================================================== --- trunk/forge/portal-extensions/forge-status/src/java/org/jboss/forge/status/WeightedScoreAlgorithmFactory.java 2005-12-09 15:21:18 UTC (rev 1753) +++ trunk/forge/portal-extensions/forge-status/src/java/org/jboss/forge/status/WeightedScoreAlgorithmFactory.java 2005-12-09 16:26:35 UTC (rev 1754) @@ -1,47 +0,0 @@ -/* - * 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.status; - -import java.util.Collection; -import java.util.Iterator; -import org.jboss.forge.status.plugins.Plugin; - -/** -* @author Pawel Wrzeszcz -*/ -public class WeightedScoreAlgorithmFactory extends ScoreAlgorithmFactory { - - public WeightedScoreAlgorithmFactory() {} - - public int calculateScore(String projectId, Collection<Plugin> plugins) { - int total = 0; - - for (Iterator iter = plugins.iterator(); iter.hasNext();) { - Plugin plugin = (Plugin) iter.next(); - - total += plugin.getValue(projectId); // TODO weights - } - - return total; - } -} Added: trunk/forge/portal-extensions/forge-status/src/java/org/jboss/forge/status/plugins/ScorePlugin.java =================================================================== --- trunk/forge/portal-extensions/forge-status/src/java/org/jboss/forge/status/plugins/ScorePlugin.java 2005-12-09 15:21:18 UTC (rev 1753) +++ trunk/forge/portal-extensions/forge-status/src/java/org/jboss/forge/status/plugins/ScorePlugin.java 2005-12-09 16:26:35 UTC (rev 1754) @@ -0,0 +1,40 @@ +/* + * 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.status.plugins; + +import java.util.Map; +import java.util.List; + +/** +* @author Pawel Wrzeszcz +*/ + +public abstract class ScorePlugin extends Plugin { + + protected List<Plugin> plugins; + + public void init(String name, String id, List<Plugin> plugins, Map<String,String> properties) throws InvalidPluginPropertiesException { + this.plugins = plugins; + init(name, id, properties); + } +} Added: trunk/forge/portal-extensions/forge-status/src/java/org/jboss/forge/status/plugins/WeightedScorePlugin.java =================================================================== --- trunk/forge/portal-extensions/forge-status/src/java/org/jboss/forge/status/plugins/WeightedScorePlugin.java 2005-12-09 15:21:18 UTC (rev 1753) +++ trunk/forge/portal-extensions/forge-status/src/java/org/jboss/forge/status/plugins/WeightedScorePlugin.java 2005-12-09 16:26:35 UTC (rev 1754) @@ -0,0 +1,49 @@ +/* + * 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.status.plugins; + +import java.util.Iterator; + +/** +* @author Pawel Wrzeszcz +*/ + +public class WeightedScorePlugin extends ScorePlugin { + + public WeightedScorePlugin() { + super(); + } + + public int getValue(String projectId) { + int total = 0; + + for (Iterator iter = plugins.iterator(); iter.hasNext();) { + Plugin plugin = (Plugin) iter.next(); + + total += plugin.getValue(projectId); // TODO weights + } + + return total; + } + +} |