From: <jbo...@li...> - 2006-03-08 07:37:17
|
Author: wrzep Date: 2006-03-08 02:37:09 -0500 (Wed, 08 Mar 2006) New Revision: 2809 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/Status.java Log: http://jira.jboss.com/jira/browse/JBLAB-619 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-08 06:32:25 UTC (rev 2808) +++ trunk/forge/portal-extensions/forge-status/src/java/org/jboss/forge/status/HistoricalScoresManager.java 2006-03-08 07:37:09 UTC (rev 2809) @@ -40,7 +40,6 @@ import org.jboss.shotoku.Directory; import org.jboss.shotoku.Node; import org.jboss.shotoku.aop.Inject; -import org.jboss.shotoku.exceptions.DeleteException; import org.jboss.shotoku.exceptions.RepositoryException; import org.jboss.shotoku.exceptions.ResourceDoesNotExist; import org.jboss.shotoku.exceptions.SaveException; @@ -75,56 +74,31 @@ return false; } - // Get plugin values and save them + // Get plugin values and save them in proper node PluginsValues values = new PluginsValues(projects, plugins); - // <debug> - Calendar cal = Calendar.getInstance(); - - cal.set(2006,01,01); - Node n = getNode(dir, getNodeName(cal.getTime()), true); - save(n,values); - - cal.set(2006,02,01); - n = getNode(dir, getNodeName(cal.getTime()), true); - save(n,values); - - cal.set(2006,02,02); - n = getNode(dir, getNodeName(cal.getTime()), true); - save(n,values); - - cal.set(2006,02,03); - n = getNode(dir, getNodeName(cal.getTime()), true); - save(n,values); - // </debug> - Node node = getNode(dir, getCurrentNodeName(), true); - log.info("Node: " + node.getFullName()); - return save(node, values); } /** - * 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. + * Returns historical scores from the given date in the past. + * If scores from specified day are not available, + * the next available scores saved at the day before or equal + * to <code>toDate</code> are returned. * - * Notice that only year, month and day matter in passed <code>date</code>. + * Notice that only year, month and day matter in passed dates. * * @param date + * @param toDate * @return PluginsValues from specified day - * or the closest follwing day when requested data was saved - * or null if no data is above search failed. + * or the closest day between <code>date</code> and <code>toDate</code> + * when requested data was saved + * or null if above search failed. */ - public static PluginsValues getValues(Date date) { - - if (date == null) { - Calendar cal = Calendar.getInstance(); - date = cal.getTime(); - } - + public static PluginsValues getValues(Date date, Date toDate) { + // Get directory where we store historical scores Directory dir = getDir(cm.getRootDirectory(), SHOTOKU_STATUS_DIR); @@ -132,23 +106,46 @@ return null; } + /* log.info("Nodes inside status directory: "); for (Node n : dir.getNodes()) { log.info("- " + n.getFullName()); } + */ - return getValues(dir, date); + return getValues(dir, date, toDate); } /** + * Returns historical scores from the given date in the past. + * + * Notice that only year, month and day matter in passed dates. + * + * @param date Specifies day in the past. + * Date can be set to null to get currently saved scores. + * @return PluginsValues from specified day + * or null if scores from this day are not available. + */ + public static PluginsValues getValues(Date date) { + + if (date == null) { + Calendar cal = Calendar.getInstance(); + date = cal.getTime(); + } + + return getValues(date, date); + } + + /** * Returns historical scores from the specified directory. * * @param dir Directory to read scores from * @return */ - private static PluginsValues getValues(Directory dir, Date date) { + private static PluginsValues getValues(Directory dir, + Date date, Date toDate) { - Node node = getNode(dir, getNodeName(date), false); + Node node = getNode(dir, date, toDate); if (node == null) { return null; } @@ -198,9 +195,45 @@ return true; } - /** + * Returns Node containing historical scores from the given day. + * If scores from specified day are not available, + * the Node with next available scores saved at the day before or equal + * to <code>toDate</code> is returned. + * + * Notice that only year, month and day matter in passed dates. + * + * @param dir Directory where search will be performed + * @param date + * @param toDate + * @return Node with historical scores + */ + private static Node getNode(Directory dir, Date date, Date toDate) { + + if (toDate.before(date)) { + return null; + } + + Node node = null; + + Calendar cal = Calendar.getInstance(); + cal.setTime(date); + + for (Date d = date; (!d.after(toDate)); + cal.add(Calendar.DAY_OF_MONTH,1), d=cal.getTime()) { + + node = getNode(dir, getNodeName(d), false); + + if (node != null) { + break; + } + } + + return node; + } + + /** * Gets shotoku Node with name <code>nodeName</code> from specified * shotoku Directory. * If <code>createIdNotExist</code> flag is set, @@ -229,9 +262,6 @@ if (createIfNotExist) { node = createNode(dir, nodeName); - } else { - log.error("Failed to get shotoku node: " + - dir.getFullName() + "/" + nodeName, e); } } 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-08 06:32:25 UTC (rev 2808) +++ trunk/forge/portal-extensions/forge-status/src/java/org/jboss/forge/status/Status.java 2006-03-08 07:37:09 UTC (rev 2809) @@ -22,7 +22,6 @@ package org.jboss.forge.status; -import java.util.Calendar; import java.util.HashMap; import java.util.Map; import java.util.Set; @@ -72,30 +71,13 @@ plugins = new Plugins(statusPluginsRoot, portalName, projects, false); plugins.addAll(scorePluginsRoot, portalName, true); - // <debug> + boolean status = HistoricalScoresManager.save(projects, plugins); if (status) { - PluginsValues values = HistoricalScoresManager.getValues(null); - if (values != null) { - try { - System.out.println("Saved value: " + values.getPluginValue("downloads", "jbosswiki")); - - Calendar cal = Calendar.getInstance(); - cal.set(2006,02,01); - values = HistoricalScoresManager.getValues(cal.getTime()); - - if (values != null) { - System.out.println("Saved value from " + cal.getTime() + " : " + - values.getPluginValue("downloads", "jbosswiki")); - } - - } catch (PluginValueNotFoundException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } + System.out.println("Scores saved"); + } else { + System.out.println("Falied to save scores"); } - // </debug> // Get columns to display on the main page Node mainPageRoot = |