From: <jbo...@li...> - 2006-03-01 20:05:13
|
Author: wrzep Date: 2006-03-01 15:05:06 -0500 (Wed, 01 Mar 2006) New Revision: 2702 Added: trunk/forge/portal-extensions/forge-status/src/java/org/jboss/forge/status/PluginValueNotFoundException.java Modified: trunk/forge/portal-extensions/forge-status/src/java/org/jboss/forge/status/HistoricalScoresManager.java trunk/forge/portal-extensions/forge-status/src/java/org/jboss/forge/status/Plugins.java trunk/forge/portal-extensions/forge-status/src/java/org/jboss/forge/status/PluginsValues.java trunk/forge/portal-extensions/forge-status/src/java/org/jboss/forge/status/Status.java Log: http://jira.jboss.com/jira/browse/JBLAB-619 Comments and cleanup. -Pawel Modified: trunk/forge/portal-extensions/forge-status/src/java/org/jboss/forge/status/HistoricalScoresManager.java =================================================================== --- trunk/forge/portal-extensions/forge-status/src/java/org/jboss/forge/status/HistoricalScoresManager.java 2006-03-01 17:40:07 UTC (rev 2701) +++ trunk/forge/portal-extensions/forge-status/src/java/org/jboss/forge/status/HistoricalScoresManager.java 2006-03-01 20:05:06 UTC (rev 2702) @@ -22,14 +22,15 @@ package org.jboss.forge.status; +import java.util.Calendar; +import java.util.Date; +import java.text.SimpleDateFormat; + import java.io.IOException; import java.io.InputStream; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.OutputStream; -import java.text.SimpleDateFormat; -import java.util.Calendar; -import java.util.Date; import org.jboss.forge.common.projects.Projects; @@ -43,17 +44,15 @@ import org.jboss.shotoku.exceptions.ResourceDoesNotExist; import org.jboss.shotoku.exceptions.SaveException; - /** -* @author Pawel Wrzeszcz -* TODO Comments -* TODO exceptions log messages +* @author Pawel Wrzeszcz (paw...@gm...) */ public class HistoricalScoresManager { private static Logger log = Logger.getLogger(HistoricalScoresManager.class); + /** Shotoku directory to store historical scores */ private static final String SHOTOKU_STATUS_DIR = "status"; @Inject @@ -81,6 +80,19 @@ return save(dir, values, projects); } + /** + * Returns historical scores from the given date in the past + * TODO If scores from specified are not available, + * next available scores are returned. + * TODO So far only current scores are returned, date is not considered. + * + * Notice that only year, month and day matter in passed <code>date</code>. + * + * @param date + * @return PluginsValues from specified day + * or the closest follwing day when requested data was saved + * or null if no data is above search failed. + */ public static PluginsValues getValues(Date date) { if (date == null) { @@ -98,6 +110,12 @@ return getValues(dir); } + /** + * Returns historical scores from the specified directory. + * + * @param dir Directory to read scores from + * @return + */ private static PluginsValues getValues(Directory dir) { Node node = getNode(dir, getCurrentNodeName(), false); @@ -153,6 +171,21 @@ } + /** + * Gets shotoku Node with name <code>nodeName</code> from specified + * shotoku Directory. + * If <code>createIdNotExist</code> flag is set, + * when node does not exist it is created. + * + * @param dir Directory where search will be performed + * @param nodeName name of searched Node + * @param createIfNotExist If this flag is set, new Node is created, + * when node with specified name does not exist. + * @return Node with the given name + * or null if such Node does not exist + * and <code>createIfNotExist</code> was not set. + * Null is also returned when creating Node failed. + */ private static Node getNode(Directory dir, String nodeName, boolean createIfNotExist) { @@ -170,6 +203,13 @@ return node; } + /** + * Creates new shotoku Node. + * + * @param dir Directory in which new Node will be created + * @param nodeName name of new Node + * @return Node or null if errors occured + */ private static Node createNode(Directory dir, String nodeName) { Node node = null; @@ -185,6 +225,16 @@ return node; } + /** + * Gets shotoku Directory with name <code>dirName</code> + * from specified shotoku Directory. + * If requested Directory does not exist it is created. + * + * @param rootDir Directory where search will be performed + * @param dirName name of searched Directory + * @return Directory with the given name + * or null when creating Directory failed. + */ private static Directory getDir(Directory rootDir, String dirName) { Directory dir = null; @@ -201,6 +251,13 @@ return dir; } + /** + * Creates new shotoku Directory. + * + * @param rootDir Directory in which new subdirectory will be created + * @param dirName name of new Directory + * @return Directory or null if errors occured + */ private static Directory createDir(Directory rootDir, String dirName) { Directory dir = null; @@ -216,6 +273,13 @@ return dir; } + /** + * Gets name of Node containing saved data from specified datestamp. + * Notice that only year, month and day matter in passed <code>date</code>. + * + * @param date datestamp + * @return Node name + */ private static String getNodeName(Date date) { SimpleDateFormat df = new SimpleDateFormat("yyyy-mm-dd"); @@ -223,6 +287,9 @@ return df.format(date); } + /** + * @return name of Node containging data saved today + */ private static String getCurrentNodeName() { Calendar cal = Calendar.getInstance(); Added: trunk/forge/portal-extensions/forge-status/src/java/org/jboss/forge/status/PluginValueNotFoundException.java =================================================================== --- trunk/forge/portal-extensions/forge-status/src/java/org/jboss/forge/status/PluginValueNotFoundException.java 2006-03-01 17:40:07 UTC (rev 2701) +++ trunk/forge/portal-extensions/forge-status/src/java/org/jboss/forge/status/PluginValueNotFoundException.java 2006-03-01 20:05:06 UTC (rev 2702) @@ -0,0 +1,38 @@ +/* + * 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; + +/** +* @author Pawel Wrzeszcz (paw...@gm...) +* Indicates that searching for value stored in PluginsValues failed. +*/ + +public class PluginValueNotFoundException extends Exception { + + private static final long serialVersionUID = 1L; + + public PluginValueNotFoundException() { + super(); + } + +} Modified: trunk/forge/portal-extensions/forge-status/src/java/org/jboss/forge/status/Plugins.java =================================================================== --- trunk/forge/portal-extensions/forge-status/src/java/org/jboss/forge/status/Plugins.java 2006-03-01 17:40:07 UTC (rev 2701) +++ trunk/forge/portal-extensions/forge-status/src/java/org/jboss/forge/status/Plugins.java 2006-03-01 20:05:06 UTC (rev 2702) @@ -23,7 +23,6 @@ package org.jboss.forge.status; import java.util.HashMap; -import java.util.HashSet; import java.util.Map; import java.util.Collection; import java.util.Properties; @@ -39,14 +38,12 @@ import org.jboss.logging.Logger; -import org.jboss.shotoku.Directory; - import org.w3c.dom.Node; import org.w3c.dom.NodeList; /** * @author Pawel Wrzeszcz -* A class storing plugins used by the Status Matrix. +* A class storing plugins that occur in the Status Matrix. */ public class Plugins {; @@ -74,7 +71,8 @@ * @param projects Projects present in the Status Matrix * @param scorePlugins flag indicating whether plugins are ScorePlugins */ - public Plugins(Node pluginsNode, String portalName, Projects projects, boolean scorePlugins) { + public Plugins(Node pluginsNode, String portalName, + Projects projects, boolean scorePlugins) { this.projects = projects; @@ -90,17 +88,22 @@ * For the given Node, describing the Plugin, returns Plugin instance. * * @param pluginNode Node with Plugin definition - * @param scorePlugin flag indicating whether plugin should be ScorePlugin + * @param scorePlugin flag indicating whether plugin + * should be ScorePlugin + * * @return Plugin defined in the <code>pluginNode</code> */ - public Plugin getPlugin(Node pluginNode, String portalName, boolean scorePlugin) { + public Plugin getPlugin(Node pluginNode, String portalName, + boolean scorePlugin) { // Get plugin info from pluginNode String pluginClassString = - XmlTools.getChildNodeValue(pluginNode, StatusTags.PLUGIN_CLASS_ELEMENT); + XmlTools.getChildNodeValue(pluginNode, + StatusTags.PLUGIN_CLASS_ELEMENT); String pluginId = - XmlTools.getChildNodeValue(pluginNode, StatusTags.PLUGIN_ID_ELEMENT); + XmlTools.getChildNodeValue(pluginNode, + StatusTags.PLUGIN_ID_ELEMENT); if ((pluginClassString == null) || (pluginId == null)) return null; @@ -117,8 +120,9 @@ // Get plugin properties Node pluginPropertiesNode = XmlTools.getFirstNodeWithName(pluginNode, - StatusTags.PLUGIN_PROPERTIES_ELEMENT); - Properties pluginProperties = getPluginProperties(pluginPropertiesNode); + StatusTags.PLUGIN_PROPERTIES_ELEMENT); + Properties pluginProperties = + getPluginProperties(pluginPropertiesNode); // Get plugin instance; Plugin plugin = null; @@ -126,16 +130,19 @@ plugin = (Plugin) pluginClass.newInstance(); if (scorePlugin) { - ((ScorePlugin) plugin).init(pluginId, statusPlugins, projects, pluginProperties); + ((ScorePlugin) plugin).init(pluginId, statusPlugins, + projects, pluginProperties); } else { /* status plugin */ - ((StatusPlugin) plugin).init(pluginId, portalName, projects, pluginProperties); + ((StatusPlugin) plugin).init(pluginId, portalName, + projects, pluginProperties); } } catch (InvalidPluginPropertiesException e) { log.warn(e); return null; } catch (Exception e) { - log.error("Plugin class: " + pluginClassString + ". Instantination failed.", e); + log.error("Plugin class: " + pluginClassString + + ". Instantination failed.", e); return null; } @@ -164,8 +171,10 @@ if ((node.getNodeType() == Node.ELEMENT_NODE) && (node.getNodeName() == "property")){ - String propertyName = XmlTools.getChildNodeValue(node, "name"); - String propertyValue = XmlTools.getChildNodeValue(node, "value"); + String propertyName = + XmlTools.getChildNodeValue(node, "name"); + String propertyValue = + XmlTools.getChildNodeValue(node, "value"); if ((propertyName != null) && (propertyValue != null)) { props.setProperty(propertyName, propertyValue); @@ -194,7 +203,8 @@ * @param portalName portal name * @param scorePlugins flag indicating whether plugins are ScorePlugins */ - public void addAll(Node pluginsNode, String portalName, boolean scorePlugins) { + public void addAll(Node pluginsNode, String portalName, + boolean scorePlugins) { NodeList pluginNodes = pluginsNode.getChildNodes(); @@ -215,17 +225,6 @@ } } } - - public void save(Directory dir) { - - try { - org.jboss.shotoku.Node n = dir.newNode("testNode"); - n.setContent("abcd"); - n.save("create"); - } catch (Exception e) { - log.error("Error while creating shotoku node: ", e); - } - } public Collection<Plugin> getPlugins() { Modified: trunk/forge/portal-extensions/forge-status/src/java/org/jboss/forge/status/PluginsValues.java =================================================================== --- trunk/forge/portal-extensions/forge-status/src/java/org/jboss/forge/status/PluginsValues.java 2006-03-01 17:40:07 UTC (rev 2701) +++ trunk/forge/portal-extensions/forge-status/src/java/org/jboss/forge/status/PluginsValues.java 2006-03-01 20:05:06 UTC (rev 2702) @@ -22,30 +22,42 @@ package org.jboss.forge.status; -import java.io.Serializable; +import java.util.Calendar; +import java.util.Date; import java.util.Map; import java.util.HashMap; import java.util.Set; +import java.io.Serializable; + import org.jboss.forge.common.projects.Projects; import org.jboss.forge.common.projects.permissions.NullPermissionsChecker; + import org.jboss.forge.status.plugins.Plugin; /** -* @author Pawel Wrzeszcz +* @author Pawel Wrzeszcz (paw...@gm...) +* A class used to store plugins values in shotoku. */ public class PluginsValues implements Serializable { private static final long serialVersionUID = 1L; - - /** pluginId -> projectId -> value */ + + /** Map : pluginId -> projectId -> value */ private Map<String,Map<String,Long>> values; - //TODO comments in a whole file + /** Creation date */ + private Date date; + /** + * @param projects Projects present in the Status Matrix + * @param plugins Plugins which values will be stored + */ public PluginsValues(Projects projects, Plugins plugins) { + date = Calendar.getInstance().getTime(); + values = new HashMap<String,Map<String,Long>>(); Set<String> projectIds = @@ -61,17 +73,51 @@ } } - private void fillPluginValues(HashMap<String, Long> pluginValues, - Plugin plugin, Set<String> projectIds) { + /** + * Fills given Map with plugin values + * + * @param pluginValues Map to fill + * @param plugin Plugin which values will be stored in the Map + * @param projectIds Set of project id for which values will be stored + */ + private void fillPluginValues(Map<String, Long> pluginValues, + Plugin plugin, Set<String> projectIds) { for (String projectId : projectIds) { pluginValues.put(projectId, plugin.getValue(projectId)); } } - public long getPluginValue(String pluginId, String projectId) { + /** + * For the given plugin and project ids returns stored value. + * + * @param pluginId plugin id + * @param projectId project id + * @return stored plugin value for specified project + * @throws PluginValueNotFoundException + * Thrown when requested value was not found + */ + public long getPluginValue(String pluginId, String projectId) + throws PluginValueNotFoundException { - return values.get(pluginId).get(projectId); + Long val = null; + Map<String,Long> pluginValues = values.get(pluginId); + + if (pluginValues != null) { + val = pluginValues.get(projectId); + } + + if (val == null) { + throw new PluginValueNotFoundException(); + } + + return val; } + /** + * @return creation date + */ + public Date getDate() { + return date; + } } 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 2006-03-01 17:40:07 UTC (rev 2701) +++ trunk/forge/portal-extensions/forge-status/src/java/org/jboss/forge/status/Status.java 2006-03-01 20:05:06 UTC (rev 2702) @@ -35,12 +35,10 @@ import org.jboss.portal.common.context.DelegateContext; -import org.jboss.shotoku.Directory; - import org.w3c.dom.Node; /** -* @author Pawel Wrzeszcz +* @author Pawel Wrzeszcz (paw...@gm...) * A class which handles Status Matrix information managment. */ public class Status { @@ -76,7 +74,12 @@ // <debug> HistoricalScoresManager.save(projects, plugins); PluginsValues values = HistoricalScoresManager.getValues(null); - System.out.println("Saved value: " + values.getPluginValue("downloads", "jbosswiki")); + try { + System.out.println("Saved value: " + values.getPluginValue("downloads", "jbosswiki")); + } catch (PluginValueNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } // </debug> // Get columns to display on the main page @@ -102,11 +105,15 @@ } /** - * @return Map binding project ids with DelegateContexts containing project information + * Returns Map binding project ids with DelegateContexts + * containing project information + * + * @return Map : project id -> DelegateContext */ public Map<String, DelegateContext> getProjectContexts() { - Map<String, DelegateContext> prjMap = new HashMap<String, DelegateContext>(); + Map<String, DelegateContext> prjMap = + new HashMap<String, DelegateContext>(); Set<String> projectIdsSet = projects.getProjectIds( (PermissionsChecker) new NullPermissionsChecker(), null); @@ -122,10 +129,18 @@ return prjMap; } + /** + * Returns Map, which has set as a key set. + * For each plugin id the resulting Map contains DelegateContext + * with information about plugin scores for all projects. + * + * @return Map : plugin id -> DelegateContext + */ public Map<String, DelegateContext> getColumnContexts() { - Map<String, DelegateContext> colMap = new HashMap<String, DelegateContext>(); - //TODO include all cells?? + Map<String, DelegateContext> colMap + = new HashMap<String, DelegateContext>(); + for (Column col : mainPageColumns.getColumns()) { DelegateContext context = new DelegateContext(); @@ -137,7 +152,4 @@ return colMap; } - public void save(Directory dir) { - plugins.save(dir); - } } \ No newline at end of file |