[jboss-svn-commits] JBL Code SVN: r6703 - in labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status: common/protocol/conf common/tools portlet portlet/conf service/impl service/impl/db service/impl/db/protocol service/impl/shotoku service/impl/shotoku/protocol

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Mon Oct 9 07:40:35 EDT 2006


Author: wrzep
Date: 2006-10-09 07:40:28 -0400 (Mon, 09 Oct 2006)
New Revision: 6703

Added:
   labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/portlet/conf/
   labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/portlet/conf/PluginConfImpl.java
   labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/portlet/conf/ServiceConfImpl.java
   labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/impl/db/
   labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/impl/db/DBScoresRepositoryManager.java
   labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/impl/db/DBServiceImpl.java
   labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/impl/db/protocol/
   labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/impl/db/protocol/DBScoresFactory.java
   labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/impl/db/protocol/PluginValuesEntity.java
   labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/impl/db/protocol/PluginsValuesEntity.java
   labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/impl/db/protocol/ScoresEntity.java
   labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/impl/db/protocol/ValueEntity.java
   labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/impl/shotoku/
   labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/impl/shotoku/ShotokuScoresRepositoryManager.java
   labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/impl/shotoku/protocol/
   labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/impl/shotoku/protocol/PluginValuesImpl.java
   labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/impl/shotoku/protocol/PluginsValuesImpl.java
   labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/impl/shotoku/protocol/ShotokuScoresFactory.java
Removed:
   labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/common/protocol/conf/SaveRequest.java
   labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/impl/DBScoresRepositoryManager.java
   labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/impl/DBServiceImpl.java
   labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/impl/ShotokuScoresRepositoryManager.java
   labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/impl/protocol/
Modified:
   labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/common/tools/Tools.java
   labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/portlet/StatusDescriptor.java
Log:
http://jira.jboss.com/jira/browse/JBLAB-781
Pawel


Deleted: labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/common/protocol/conf/SaveRequest.java
===================================================================
--- labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/common/protocol/conf/SaveRequest.java	2006-10-09 10:59:54 UTC (rev 6702)
+++ labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/common/protocol/conf/SaveRequest.java	2006-10-09 11:40:28 UTC (rev 6703)
@@ -1,39 +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.common.protocol.conf;
-
-import java.io.Serializable;
-import java.util.List;
-
-import org.jboss.forge.common.projects.Projects;
-
-/**
-* @author Pawel Wrzeszcz
-*/
-public interface SaveRequest extends Serializable {
-	
-	public List<PluginConf> getPluginsConf();
-	
-	public Projects getProjects();
-
-}
\ No newline at end of file

Modified: labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/common/tools/Tools.java
===================================================================
--- labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/common/tools/Tools.java	2006-10-09 10:59:54 UTC (rev 6702)
+++ labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/common/tools/Tools.java	2006-10-09 11:40:28 UTC (rev 6703)
@@ -18,7 +18,7 @@
 import org.jboss.forge.status.common.tools.test.TestProject;
 import org.jboss.forge.status.portlet.StatusConfWatcher;
 import org.jboss.forge.status.portlet.StatusDescriptor;
-import org.jboss.forge.status.service.impl.protocol.PluginConfImpl;
+import org.jboss.forge.status.portlet.conf.PluginConfImpl;
 import org.jboss.logging.Logger;
 
 import org.jboss.shotoku.ContentManager;

Modified: labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/portlet/StatusDescriptor.java
===================================================================
--- labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/portlet/StatusDescriptor.java	2006-10-09 10:59:54 UTC (rev 6702)
+++ labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/portlet/StatusDescriptor.java	2006-10-09 11:40:28 UTC (rev 6703)
@@ -35,10 +35,10 @@
 import org.jboss.forge.status.common.protocol.conf.ScoresFactory;
 import org.jboss.forge.status.common.protocol.conf.ServiceConf;
 import org.jboss.forge.status.common.tools.Tools;
-import org.jboss.forge.status.service.impl.DBScoresRepositoryManager;
+import org.jboss.forge.status.portlet.conf.ServiceConfImpl;
 import org.jboss.forge.status.service.impl.ServiceScoresManager;
-import org.jboss.forge.status.service.impl.protocol.ServiceConfImpl;
-import org.jboss.forge.status.service.impl.protocol.db.DBScoresFactory;
+import org.jboss.forge.status.service.impl.db.DBScoresRepositoryManager;
+import org.jboss.forge.status.service.impl.db.protocol.DBScoresFactory;
 import org.jboss.logging.Logger;
 import org.jboss.portal.common.context.DelegateContext;
 

Added: labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/portlet/conf/PluginConfImpl.java
===================================================================
--- labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/portlet/conf/PluginConfImpl.java	2006-10-09 10:59:54 UTC (rev 6702)
+++ labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/portlet/conf/PluginConfImpl.java	2006-10-09 11:40:28 UTC (rev 6703)
@@ -0,0 +1,81 @@
+/*
+ * 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.portlet.conf;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+
+import org.jboss.forge.common.XmlTools;
+import org.jboss.forge.status.common.Tags;
+import org.jboss.forge.status.common.exceptions.InvalidPluginsConfigurationException;
+import org.jboss.forge.status.common.protocol.conf.PluginConf;
+import org.w3c.dom.Node;
+
+/**
+* @author Pawel Wrzeszcz
+*/
+public class PluginConfImpl implements PluginConf {
+	
+	private static final long serialVersionUID = 8598887068548048511L;
+
+	private Map<String,String> fields = new HashMap<String,String>();
+	private Properties properties;
+	
+	public PluginConfImpl(Node pluginNode)
+						throws InvalidPluginsConfigurationException {
+		
+		// Parse plugin configuration
+		parseField(pluginNode, Tags.PLUGIN_ID_ELEMENT);
+		parseField(pluginNode, Tags.PLUGIN_CLASS_ELEMENT);
+		
+		// Parse plugin properties
+		Node pluginPropertiesNode =
+				XmlTools.getFirstNodeWithName(pluginNode,
+						Tags.PLUGIN_PROPERTIES_ELEMENT);
+		
+		properties = XmlTools.parseProperties(pluginPropertiesNode); 
+	}
+	
+	public String getFieldValue(String fieldName) {
+		return fields.get(fieldName);
+	}
+	
+	public Properties getProperties() {
+		return properties;
+	}
+	
+	private void parseField(Node pluginNode, String fieldName)
+							throws InvalidPluginsConfigurationException {
+		
+		String fieldValue =
+			XmlTools.getChildNodeValue(pluginNode, fieldName);
+
+		if (fieldValue == null) {
+			throw new InvalidPluginsConfigurationException(
+									"Missing field: " + fieldName);
+		}
+		
+		fields.put(fieldName, fieldValue);
+	}
+}
\ No newline at end of file

Added: labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/portlet/conf/ServiceConfImpl.java
===================================================================
--- labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/portlet/conf/ServiceConfImpl.java	2006-10-09 10:59:54 UTC (rev 6702)
+++ labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/portlet/conf/ServiceConfImpl.java	2006-10-09 11:40:28 UTC (rev 6703)
@@ -0,0 +1,157 @@
+/*
+ * 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.portlet.conf;
+
+import java.util.Properties;
+
+import org.jboss.forge.status.common.Constants;
+import org.jboss.forge.status.common.Tags;
+import org.jboss.forge.status.common.protocol.conf.ServiceConf;
+import org.jboss.shotoku.Node;
+
+/**
+* @author Pawel Wrzeszcz (pawel.wrzeszcz [at] gmail.com)
+*/
+public class ServiceConfImpl implements ServiceConf {
+	
+	private boolean remoteService;
+	
+	private Properties properties;
+	
+	private int firstUpdate;
+	private int updateInterval;
+	private int updateStartHour;
+	private int updateStartMinute;
+	
+	
+	public ServiceConfImpl(Node serviceNode) {
+		
+		Properties allProperties = parseProperties(serviceNode, null);
+		
+		setServiceProperties(allProperties);
+		
+		properties = parseProperties(serviceNode,
+											Tags.SERVICE_PROPERTIES_PREFIX);
+	}
+
+	private void setServiceProperties(Properties properties) {
+		
+		String remoteString = (String) properties.get(
+											Tags.SERVICE_REMOTE_ELEMENT);
+		
+		remoteService = (remoteString == null) ? false : remoteString.equals("true");
+		
+		firstUpdate = parseIntProperty(properties,
+								Tags.SERVICE_FIRST_UPDATE_ELEMENT,
+								Constants.FIRST_UPDATE_INTERVAL_DEFAULT);
+		
+		updateInterval = parseIntProperty(properties,
+								Tags.SERVICE_UPDATE_INTERVAL_ELEMENT,
+								Constants.SCORES_UPDATE_INTERVAL_DEFAULT);
+		
+		updateStartHour = parseIntProperty(properties,
+								Tags.SERVICE_UPDATE_START_HOUR_ELEMENT,
+								Constants.UPDATE_START_HOUR_DEFAULT);
+		
+		updateStartMinute = parseIntProperty(properties,
+								Tags.SERVICE_UPDATE_START_MINUTE_ELEMENT,
+								Constants.UPDATE_START_MINUTE_DEFAULT);
+		
+	}
+
+	private static int parseIntProperty(Properties properties, String element,
+														int defaultValue) {
+		
+		String string = (String) properties.get(element);
+
+		if (string != null) {
+			
+			try {
+
+				return Integer.parseInt(string);
+
+			} catch (NumberFormatException e) {
+				
+				// Do nothing
+			}
+		}
+				
+		return defaultValue;
+	}
+
+	public boolean isRemote() {
+		return remoteService;
+	}
+	
+	public Properties getProperties() {
+		return properties;
+	}
+
+	private Properties parseProperties(Node serviceNode,
+											String excludePrefix) {
+		
+		Properties props = new Properties();
+		
+		if (serviceNode == null) {
+			return props;
+		}
+		
+		String propsString = serviceNode.getContent();
+		String[] propsArr = propsString.split("\n");
+		
+		for (String propString : propsArr) {
+			
+			String[] propArr = propString.split("=");
+			
+			if ((propArr != null) && (propArr.length == 2) && 
+					((excludePrefix == null) ||
+								(!propArr[0].startsWith(excludePrefix)))) {
+				
+				props.put(propArr[0], propArr[1]);
+			}
+					
+		}
+		
+		return props;
+	}
+
+	public int getFirstUpdate() {
+		
+		return firstUpdate;
+	}
+
+	public int getUpdateInterval() {
+		
+		return updateInterval;
+	}
+
+	public int getUpdateStartHour() {
+		
+		return updateStartHour;
+	}
+
+	public int getUpdateStartMinute() {
+		
+		return updateStartMinute;
+	}	
+}
\ No newline at end of file

Deleted: labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/impl/DBScoresRepositoryManager.java
===================================================================
--- labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/impl/DBScoresRepositoryManager.java	2006-10-09 10:59:54 UTC (rev 6702)
+++ labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/impl/DBScoresRepositoryManager.java	2006-10-09 11:40:28 UTC (rev 6703)
@@ -1,123 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2006, 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.service.impl;
-
-import java.util.Calendar;
-
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
-import javax.rmi.PortableRemoteObject;
-
-import org.jboss.forge.status.common.Constants;
-import org.jboss.forge.status.common.exceptions.GetScoresException;
-import org.jboss.forge.status.common.exceptions.ScoresSaveException;
-import org.jboss.forge.status.common.protocol.DBService;
-import org.jboss.forge.status.common.protocol.ScoresRepositoryManager;
-import org.jboss.forge.status.common.protocol.conf.PluginValues;
-import org.jboss.forge.status.common.protocol.conf.PluginsValues;
-
-
-/**
-* @author Pawel Wrzeszcz (pawel.wrzeszcz [at] gmail.com)
-*/
-
-public class DBScoresRepositoryManager 
-									implements ScoresRepositoryManager {
-	
-	
-	private DBService service;
-	
-	public DBScoresRepositoryManager() throws NamingException {
-		
-		service = getService();
-	};
-	
-	public void save(PluginsValues pluginsValues) throws ScoresSaveException {
-	
-		try {
-			service.save(pluginsValues);
-		} catch (Exception e) {
-			throw new ScoresSaveException(e);
-		}
-	}
-
-	public PluginsValues get(Calendar cal) throws GetScoresException {
-		
-		PluginsValues pv = null;	
-		
-		try {
-			pv = service.get(cal);
-		} catch (Exception e) {
-			throw new GetScoresException(e);
-		}
-		
-		return pv;
-	}
-
-	private DBService getService() throws NamingException {
-			
-		Context context = new InitialContext();
-		
-		//	Perform look up using JNDI name of ejb object
-		Object ref = context.lookup(Constants.DB_SERVICE);
-		
-		// Narrow the reference of the object returned by lookup() method
-		DBService service = 
-			(DBService) PortableRemoteObject.narrow( ref, DBService.class);
-		
-		return service;
-	}
-
-	public long getValue(String pluginId, String projectId, Calendar cal)
-													throws GetScoresException {
-
-		if (!service.hasValue(pluginId, projectId, cal)) {
-			throw new GetScoresException("Value not available.");
-		}
-
-		return service.getValue(pluginId, projectId, cal);
-	}
-
-	public PluginValues getPluginValues(String pluginId, Calendar cal)
-													throws GetScoresException {
-
-		if (!service.hasPluginValues(pluginId, cal)) {
-			throw new GetScoresException("PluginValues not available.");
-		}
-
-		return service.getPluginValues(pluginId, cal);
-	}
-
-	public long getValue(String pluginId, String projectId,
-							Calendar start, Calendar end) throws GetScoresException {
-		
-		
-		if (!service.hasValue(pluginId, projectId, start, end)) {
-			throw new GetScoresException("Value not available.");
-		}
-		
-		return service.getValue(pluginId, projectId, start, end);
-		
-	}
-}

Deleted: labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/impl/DBServiceImpl.java
===================================================================
--- labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/impl/DBServiceImpl.java	2006-10-09 10:59:54 UTC (rev 6702)
+++ labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/impl/DBServiceImpl.java	2006-10-09 11:40:28 UTC (rev 6703)
@@ -1,187 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2006, 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.service.impl;
-
-import java.util.Calendar;
-import java.util.List;
-
-import javax.ejb.Local;
-import javax.ejb.Stateless;
-import javax.ejb.TransactionAttribute;
-import javax.ejb.TransactionAttributeType;
-import javax.persistence.EntityManager;
-import javax.persistence.PersistenceContext;
-import javax.persistence.Query;
-import javax.persistence.TemporalType;
-
-import org.jboss.annotation.ejb.LocalBinding;
-
-import org.jboss.forge.status.common.Constants;
-import org.jboss.forge.status.common.protocol.DBService;
-import org.jboss.forge.status.common.protocol.conf.PluginValues;
-import org.jboss.forge.status.common.protocol.conf.PluginsValues;
-import org.jboss.forge.status.common.tools.Tools;
-
-
-/**
-* @author Pawel Wrzeszcz (pawel.wrzeszcz [at] gmail.com)
-*/
-
- at Stateless
- at Local(DBService.class)
- at LocalBinding(jndiBinding=Constants.DB_SERVICE)
-public class DBServiceImpl implements DBService {
-
-	@PersistenceContext (unitName="scores")
-    protected EntityManager em;
-	
-	@TransactionAttribute(TransactionAttributeType.REQUIRED)
-	public void save(PluginsValues toSave) {
-				
-		System.out.println("save: " + toSave.getDate());
-		
-		PluginsValues pv = get(toSave.getDate());
-		
-		if ((pv != null) && 
-				(pv.getDate().equals(toSave.getDate()))) {
-			
-			em.remove(pv);
-		}
-		
-		em.persist(toSave);
-	}
-
-	public PluginsValues get(Calendar date) {
-		
-		Tools.truncate(date);
-		Calendar nextDay = Tools.nextDay(date);
-	
-		List list = null;
-		
-		Query query = em.createQuery(
-				" SELECT c FROM PluginsValuesEntity c " +
-				" LEFT JOIN FETCH c.values cv " +
-				" LEFT JOIN FETCH cv.values " +
-				" WHERE (:date <= c.date) AND (c.date < :nextDay)");
-		
-		query.setParameter("date", date, TemporalType.DATE);
-		query.setParameter("nextDay", nextDay, TemporalType.DATE);
-
-		list = query.getResultList();
-		
-		return (list.size() == 0 ? null : (PluginsValues) list.get(0));
-	}
-
-	public long getValue(String pluginId, String projectId, Calendar date) {
-		
-		Tools.truncate(date);
-		Calendar nextDay = Tools.nextDay(date);
-		
-		Query query = em.createQuery(
-				" SELECT c.value FROM ValueEntity c " +
-				" WHERE c.projectId = :projectId " +
-				  " AND c.pluginValues.pluginId = :pluginId " +
-				  " AND (:date <= c.pluginValues.pluginsValues.date)" +
-				  " AND (c.pluginValues.pluginsValues.date < :nextDay) ");
-		
-		query.setParameter("projectId", projectId);
-		query.setParameter("pluginId", pluginId);
-		query.setParameter("date", date, TemporalType.DATE);
-		query.setParameter("nextDay", nextDay, TemporalType.DATE);
-		
-		return (Long) query.getSingleResult();
-	}
-
-	public boolean hasValue(String pluginId, String projectId, Calendar date) {
-		
-		try {
-			getValue(pluginId, projectId, date);
-		} catch (Exception e) {
-			return false;
-		}
-		
-		return true;
-	}
-
-	public PluginValues getPluginValues(String pluginId, Calendar date) {
-		
-		Tools.truncate(date);
-		Calendar nextDay = Tools.nextDay(date);
-		
-		Query query = em.createQuery(
-				" SELECT c.value FROM PluginValuesEntity c " +
-				" WHERE c.pluginId = :pluginId " +
-				  " AND (:date <= c.pluginsValues.date)" +
-				  " AND (c.pluginsValues.date < :nextDay) ");
-		
-		query.setParameter("pluginId", pluginId);
-		query.setParameter("date", date, TemporalType.DATE);
-		query.setParameter("nextDay", nextDay, TemporalType.DATE);
-		
-		return (PluginValues) query.getSingleResult();
-	}
-
-	public boolean hasPluginValues(String pluginId, Calendar date) {
-		
-		try {
-			getPluginValues(pluginId, date);
-		} catch (Exception e) {
-			return false;
-		}
-		
-		return true;
-	}
-
-	public long getValue(String pluginId, String projectId,
-											Calendar start, Calendar end) {
-		
-		Query query = em.createQuery(
-				" SELECT c.value FROM ValueEntity c " +
-				" WHERE c.projectId = :projectId " +
-				"   AND c.pluginValues.pluginId = :pluginId " +
-				"   AND c.pluginValues.pluginsValues.date >= :start " +
-				"   AND c.pluginValues.pluginsValues.date <= :end " +
-				" ORDER BY c.pluginValues.pluginsValues.date ");
-		
-		query.setParameter("projectId", projectId);
-		query.setParameter("pluginId", pluginId);
-		query.setParameter("start", start, TemporalType.DATE);
-		query.setParameter("end", end, TemporalType.DATE);
-		
-		return (Long) query.getResultList().get(0);
-		
-	}
-
-	public boolean hasValue(String pluginId, String projectId,
-											Calendar start, Calendar end) {
-		
-		try {
-			getValue(pluginId, projectId, start, end);
-		} catch (Exception e) {
-			return false;
-		}
-		
-		return true;
-	}	
-	
-}

Deleted: labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/impl/ShotokuScoresRepositoryManager.java
===================================================================
--- labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/impl/ShotokuScoresRepositoryManager.java	2006-10-09 10:59:54 UTC (rev 6702)
+++ labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/impl/ShotokuScoresRepositoryManager.java	2006-10-09 11:40:28 UTC (rev 6703)
@@ -1,357 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2006, 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.service.impl;
-
-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 java.util.HashMap;
-import java.util.Map;
-
-import org.jboss.forge.status.common.Locations;
-import org.jboss.forge.status.common.exceptions.GetScoresException;
-import org.jboss.forge.status.common.exceptions.ScoresSaveException;
-import org.jboss.forge.status.common.protocol.ScoresRepositoryManager;
-import org.jboss.forge.status.common.protocol.conf.PluginValues;
-import org.jboss.forge.status.common.protocol.conf.PluginsValues;
-import org.jboss.logging.Logger;
-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.ResourceDoesNotExist;
-
-/**
-* @author Pawel Wrzeszcz (pawel.wrzeszcz [at] gmail.com)
-*/
-
-public class ShotokuScoresRepositoryManager 
-									implements ScoresRepositoryManager {
-
-	private Logger log = Logger.getLogger(this.getClass());
-	
-	private Map<String,PluginsValues> values
-										= new HashMap<String,PluginsValues>();
-
-	private String portalName;
-	
-	@Inject
-	private ContentManager cm;
-	
-	public ShotokuScoresRepositoryManager(String portalName) {
-		
-		this.portalName = portalName;
-	};
-	
-	public void save(PluginsValues pluginsValues)
-										throws ScoresSaveException {
-		
-		// Get directory where we store historical scores
-		Directory rootDir = cm.getRootDirectory();
-		String dirName = Locations.getShotokuStatusPath(portalName);
-		Directory dir = getDir(rootDir, dirName);
-		
-		// Get node to store scores
-		String nodeName = getCurrentNodeName();
-		Node node = null;
-		
-		log.info("Getting shotoku node...");
-		
-		try {
-			node = dir.getNode(nodeName);
-		} catch (RepositoryException e) {
-			log.error("Error while getting shotoku node: " +
-					dir.getFullName() + "/" + nodeName, e);
-		} catch (ResourceDoesNotExist e) {
-			node = createNode(dir, nodeName);
-		}
-		
-		// Save values and store then in cache
-		values.put(getCurrentNodeName(), pluginsValues);
-		save(node, pluginsValues);
-		
-		log.info("Saved succesfully");
-		/*
-		ScoresEntity se = new ScoresEntity("tttest");
-		em.persist(se);
-		log.info("Saved in DB");*/
-	}
-
-	public PluginsValues get(Calendar cal) throws GetScoresException {
-		
-		String key = getNodeName(cal);
-		log.info("Returning plugins values (" + key + ") ...");
-		
-		// null date means today
-		if (cal == null) {
-			cal = Calendar.getInstance();
-		}
-		
-		PluginsValues v = values.get(key);
-		
-		if (v == null) { // Not in cache => get value and store it
-			
-			log.info("Value not in cache...");
-			Directory rootDir = cm.getRootDirectory();
-			
-			Directory dir;
-			try {
-				dir = rootDir.getDirectory(Locations.
-											getShotokuStatusPath(portalName));	
-			} catch (RepositoryException e) {
-				throw new GetScoresException(e);
-			} catch (ResourceDoesNotExist e) {
-				throw new GetScoresException(e);
-			}
-
-			if (dir != null) {
-				v = getPluginsValues(dir, cal);
-				log.info("Finished.");
-				values.put(key,v);
-			}
-		} else {
-			log.info("Returned cached value.");
-		}
-			
-		return v;
-	}
-	
-	/**
-	 * Saves plugins values in the given Directory.
-	 * 
-	 * @param dir Directory to save values
-	 * @param pluginsValues PluginsValues to save
-	 * @throws ScoresSaveException 
-	 */
-	private synchronized void save(Node node, PluginsValues pluginsValues)
-										throws ScoresSaveException {
-		
-		try {
-			OutputStream os = node.getOutputStream();
-			ObjectOutputStream oos = new ObjectOutputStream(os);
-			oos.writeObject((PluginsValues) pluginsValues);
-			oos.close(); 
-			node.save("update"); /* os is closed inside save() */
-			
-		} catch (Exception e) {
-			log.error("Error while saving shotoku node: " +
-					node.getFullName(), e);
-			throw new ScoresSaveException(e);
-		}
-	}
-	
-	/**
-	 * Creates new shotoku Node.
-	 * 
-	 * @param dir Directory in which new Node will be created
-	 * @param nodeName name of new Node
-	 * @return Node
-	 * @throws ScoresSaveException 
-	 */
-	private Node createNode(Directory dir, String nodeName)
-											throws ScoresSaveException {
-		
-		Node node = null;
-		
-		try {
-			node = dir.newNode(nodeName);
-			node.save("create");
-		} catch (Exception e) {
-			log.error("Error while creating shotoku node: " +
-					dir.getFullName() + "/" + nodeName, e);
-			throw new ScoresSaveException(e);
-		}
-		
-		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.  
-	 * @throws ScoresSaveException 
-	 */
-	private Directory getDir(Directory rootDir, String dirName)
-										throws ScoresSaveException {
-		
-		Directory dir = null;
-			
-		try {
-			dir = rootDir.getDirectory(dirName);
-		} catch (RepositoryException e) {
-			log.error("Error while getting shotoku directory " +
-					rootDir.getFullName() + "/" + dirName);
-			throw new ScoresSaveException(e);
-		} catch (ResourceDoesNotExist e) {
-			dir = createDir(rootDir, dirName);
-		}
-			
-		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
-	 * @throws ScoresSaveException 
-	 */
-	private Directory createDir(Directory rootDir, String dirName)
-												throws ScoresSaveException {
-		
-		Directory dir = null;
-		
-		try {
-			dir = rootDir.newDirectory(dirName);
-			dir.save("create");
-		} catch (Exception e) {
-			log.error("Error while creating shotoku directory: " +
-					rootDir.getFullName() + "/" + dirName, e);
-			throw new ScoresSaveException(e);
-		}
-		
-		return dir;
-	}
-
-	/**
-	 * Gets name of Node containing saved data from specified datestamp.
-	 * Notice that only year, month and day matter in passed <code>cal</code>.
-	 * 
-	 * @return Node name
-	 */
-	private String getNodeName(Calendar cal) {
-		
-		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
-		
-		Date date = cal.getTime();
-		
-		return df.format(date);
-	}
-	
-	/**
-	 * @return name of Node containging data saved today
-	 */
-	private String getCurrentNodeName() {
-		
-		Calendar today = Calendar.getInstance();
-		
-		return getNodeName(today); 
-	}
-	
-	/**
-	 * Returns historical scores from the specified directory.
-	 * 
-	 * @param dir Directory to read scores from
-	 * @return
-	 * @throws GetScoresException 
-	 */
-	private PluginsValues getPluginsValues(Directory dir, Calendar cal)
-												throws GetScoresException {
-		
-		// Get appropriate node
-		Node node = null;
-		String nodeName = getNodeName(cal);
-		
-		try {
-			node = dir.getNode(nodeName);
-		} catch (Exception e) {
-			log.info("Unable to get shotoku node " +
-					dir.getFullName() + "/" + nodeName);
-			throw new GetScoresException(e);
-		}
-		
-		// Restore values
-		PluginsValues values = null;
-		try {
-			InputStream is = node.getContentInputStream();
-			ObjectInputStream ois = new ObjectInputStream(is);
-			values = (PluginsValues) ois.readObject();
-			ois.close();
-			is.close();
-		} catch (Exception e) {
-			log.error("Error while restoring scores from shotoku node " +
-					dir.getFullName() + "/" + nodeName);
-			throw new GetScoresException(e);
-		}
-		
-		return values;
-	}
-
-	public long getValue(String pluginId, String projectId, Calendar cal)
-												throws GetScoresException {
-		
-		PluginValues pluginValues = getPluginValues(pluginId, cal);
-		
-		if (pluginValues == null) {
-			throw new GetScoresException();
-		}
-		
-		return pluginValues.getValue(projectId);
-	}
-
-	public PluginValues getPluginValues(String pluginId, Calendar cal)
-												throws GetScoresException {
-		
-		PluginsValues pluginsValues = get(cal);
-		
-		if (pluginsValues == null) {
-			throw new GetScoresException();
-		}
-		
-		return pluginsValues.getPluginValues(pluginId);
-	}
-
-	public long getValue(String pluginId, String projectId,
-					Calendar start, Calendar end) throws GetScoresException {
-		
-		long value;
-		Calendar cal = start;
-		
-		for (;;) {
-			
-			if (cal.after(end)) {
-				throw new GetScoresException();
-			}
-			
-			try {
-				value = getValue(pluginId, projectId, cal);
-				return value;
-			} catch (GetScoresException e) {
-				// try next
-				cal.add(Calendar.DAY_OF_MONTH, 1);
-			}	
-		}
-	}
-	
-}

Added: labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/impl/db/DBScoresRepositoryManager.java
===================================================================
--- labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/impl/db/DBScoresRepositoryManager.java	2006-10-09 10:59:54 UTC (rev 6702)
+++ labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/impl/db/DBScoresRepositoryManager.java	2006-10-09 11:40:28 UTC (rev 6703)
@@ -0,0 +1,123 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, 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.service.impl.db;
+
+import java.util.Calendar;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import javax.rmi.PortableRemoteObject;
+
+import org.jboss.forge.status.common.Constants;
+import org.jboss.forge.status.common.exceptions.GetScoresException;
+import org.jboss.forge.status.common.exceptions.ScoresSaveException;
+import org.jboss.forge.status.common.protocol.DBService;
+import org.jboss.forge.status.common.protocol.ScoresRepositoryManager;
+import org.jboss.forge.status.common.protocol.conf.PluginValues;
+import org.jboss.forge.status.common.protocol.conf.PluginsValues;
+
+
+/**
+* @author Pawel Wrzeszcz (pawel.wrzeszcz [at] gmail.com)
+*/
+
+public class DBScoresRepositoryManager 
+									implements ScoresRepositoryManager {
+	
+	
+	private DBService service;
+	
+	public DBScoresRepositoryManager() throws NamingException {
+		
+		service = getService();
+	};
+	
+	public void save(PluginsValues pluginsValues) throws ScoresSaveException {
+	
+		try {
+			service.save(pluginsValues);
+		} catch (Exception e) {
+			throw new ScoresSaveException(e);
+		}
+	}
+
+	public PluginsValues get(Calendar cal) throws GetScoresException {
+		
+		PluginsValues pv = null;	
+		
+		try {
+			pv = service.get(cal);
+		} catch (Exception e) {
+			throw new GetScoresException(e);
+		}
+		
+		return pv;
+	}
+
+	private DBService getService() throws NamingException {
+			
+		Context context = new InitialContext();
+		
+		//	Perform look up using JNDI name of ejb object
+		Object ref = context.lookup(Constants.DB_SERVICE);
+		
+		// Narrow the reference of the object returned by lookup() method
+		DBService service = 
+			(DBService) PortableRemoteObject.narrow( ref, DBService.class);
+		
+		return service;
+	}
+
+	public long getValue(String pluginId, String projectId, Calendar cal)
+													throws GetScoresException {
+
+		if (!service.hasValue(pluginId, projectId, cal)) {
+			throw new GetScoresException("Value not available.");
+		}
+
+		return service.getValue(pluginId, projectId, cal);
+	}
+
+	public PluginValues getPluginValues(String pluginId, Calendar cal)
+													throws GetScoresException {
+
+		if (!service.hasPluginValues(pluginId, cal)) {
+			throw new GetScoresException("PluginValues not available.");
+		}
+
+		return service.getPluginValues(pluginId, cal);
+	}
+
+	public long getValue(String pluginId, String projectId,
+							Calendar start, Calendar end) throws GetScoresException {
+		
+		
+		if (!service.hasValue(pluginId, projectId, start, end)) {
+			throw new GetScoresException("Value not available.");
+		}
+		
+		return service.getValue(pluginId, projectId, start, end);
+		
+	}
+}

Added: labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/impl/db/DBServiceImpl.java
===================================================================
--- labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/impl/db/DBServiceImpl.java	2006-10-09 10:59:54 UTC (rev 6702)
+++ labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/impl/db/DBServiceImpl.java	2006-10-09 11:40:28 UTC (rev 6703)
@@ -0,0 +1,187 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, 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.service.impl.db;
+
+import java.util.Calendar;
+import java.util.List;
+
+import javax.ejb.Local;
+import javax.ejb.Stateless;
+import javax.ejb.TransactionAttribute;
+import javax.ejb.TransactionAttributeType;
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+import javax.persistence.Query;
+import javax.persistence.TemporalType;
+
+import org.jboss.annotation.ejb.LocalBinding;
+
+import org.jboss.forge.status.common.Constants;
+import org.jboss.forge.status.common.protocol.DBService;
+import org.jboss.forge.status.common.protocol.conf.PluginValues;
+import org.jboss.forge.status.common.protocol.conf.PluginsValues;
+import org.jboss.forge.status.common.tools.Tools;
+
+
+/**
+* @author Pawel Wrzeszcz (pawel.wrzeszcz [at] gmail.com)
+*/
+
+ at Stateless
+ at Local(DBService.class)
+ at LocalBinding(jndiBinding=Constants.DB_SERVICE)
+public class DBServiceImpl implements DBService {
+
+	@PersistenceContext (unitName="scores")
+    protected EntityManager em;
+	
+	@TransactionAttribute(TransactionAttributeType.REQUIRED)
+	public void save(PluginsValues toSave) {
+				
+		System.out.println("save: " + toSave.getDate());
+		
+		PluginsValues pv = get(toSave.getDate());
+		
+		if ((pv != null) && 
+				(pv.getDate().equals(toSave.getDate()))) {
+			
+			em.remove(pv);
+		}
+		
+		em.persist(toSave);
+	}
+
+	public PluginsValues get(Calendar date) {
+		
+		Tools.truncate(date);
+		Calendar nextDay = Tools.nextDay(date);
+	
+		List list = null;
+		
+		Query query = em.createQuery(
+				" SELECT c FROM PluginsValuesEntity c " +
+				" LEFT JOIN FETCH c.values cv " +
+				" LEFT JOIN FETCH cv.values " +
+				" WHERE (:date <= c.date) AND (c.date < :nextDay)");
+		
+		query.setParameter("date", date, TemporalType.DATE);
+		query.setParameter("nextDay", nextDay, TemporalType.DATE);
+
+		list = query.getResultList();
+		
+		return (list.size() == 0 ? null : (PluginsValues) list.get(0));
+	}
+
+	public long getValue(String pluginId, String projectId, Calendar date) {
+		
+		Tools.truncate(date);
+		Calendar nextDay = Tools.nextDay(date);
+		
+		Query query = em.createQuery(
+				" SELECT c.value FROM ValueEntity c " +
+				" WHERE c.projectId = :projectId " +
+				  " AND c.pluginValues.pluginId = :pluginId " +
+				  " AND (:date <= c.pluginValues.pluginsValues.date)" +
+				  " AND (c.pluginValues.pluginsValues.date < :nextDay) ");
+		
+		query.setParameter("projectId", projectId);
+		query.setParameter("pluginId", pluginId);
+		query.setParameter("date", date, TemporalType.DATE);
+		query.setParameter("nextDay", nextDay, TemporalType.DATE);
+		
+		return (Long) query.getSingleResult();
+	}
+
+	public boolean hasValue(String pluginId, String projectId, Calendar date) {
+		
+		try {
+			getValue(pluginId, projectId, date);
+		} catch (Exception e) {
+			return false;
+		}
+		
+		return true;
+	}
+
+	public PluginValues getPluginValues(String pluginId, Calendar date) {
+		
+		Tools.truncate(date);
+		Calendar nextDay = Tools.nextDay(date);
+		
+		Query query = em.createQuery(
+				" SELECT c.value FROM PluginValuesEntity c " +
+				" WHERE c.pluginId = :pluginId " +
+				  " AND (:date <= c.pluginsValues.date)" +
+				  " AND (c.pluginsValues.date < :nextDay) ");
+		
+		query.setParameter("pluginId", pluginId);
+		query.setParameter("date", date, TemporalType.DATE);
+		query.setParameter("nextDay", nextDay, TemporalType.DATE);
+		
+		return (PluginValues) query.getSingleResult();
+	}
+
+	public boolean hasPluginValues(String pluginId, Calendar date) {
+		
+		try {
+			getPluginValues(pluginId, date);
+		} catch (Exception e) {
+			return false;
+		}
+		
+		return true;
+	}
+
+	public long getValue(String pluginId, String projectId,
+											Calendar start, Calendar end) {
+		
+		Query query = em.createQuery(
+				" SELECT c.value FROM ValueEntity c " +
+				" WHERE c.projectId = :projectId " +
+				"   AND c.pluginValues.pluginId = :pluginId " +
+				"   AND c.pluginValues.pluginsValues.date >= :start " +
+				"   AND c.pluginValues.pluginsValues.date <= :end " +
+				" ORDER BY c.pluginValues.pluginsValues.date ");
+		
+		query.setParameter("projectId", projectId);
+		query.setParameter("pluginId", pluginId);
+		query.setParameter("start", start, TemporalType.DATE);
+		query.setParameter("end", end, TemporalType.DATE);
+		
+		return (Long) query.getResultList().get(0);
+		
+	}
+
+	public boolean hasValue(String pluginId, String projectId,
+											Calendar start, Calendar end) {
+		
+		try {
+			getValue(pluginId, projectId, start, end);
+		} catch (Exception e) {
+			return false;
+		}
+		
+		return true;
+	}	
+	
+}

Added: labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/impl/db/protocol/DBScoresFactory.java
===================================================================
--- labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/impl/db/protocol/DBScoresFactory.java	2006-10-09 10:59:54 UTC (rev 6702)
+++ labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/impl/db/protocol/DBScoresFactory.java	2006-10-09 11:40:28 UTC (rev 6703)
@@ -0,0 +1,49 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, 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.service.impl.db.protocol;
+
+import java.util.Set;
+
+import org.jboss.forge.common.projects.Projects;
+
+import org.jboss.forge.status.common.protocol.conf.PluginValues;
+import org.jboss.forge.status.common.protocol.conf.PluginsValues;
+import org.jboss.forge.status.common.protocol.conf.ScoresFactory;
+import org.jboss.forge.status.common.tools.Plugins;
+import org.jboss.forge.status.service.plugins.Plugin;
+
+
+/**
+* @author Pawel Wrzeszcz
+*/
+public class DBScoresFactory implements ScoresFactory {
+	
+	public PluginsValues createPluginsValues(Projects projects, Plugins plugins) {
+		return new PluginsValuesEntity(projects, plugins);
+	}
+	
+	public PluginValues createPluginValues(Plugin plugin, Set<String> projectIds) {
+		return new PluginValuesEntity(plugin, projectIds, null);
+	}
+	
+}
\ No newline at end of file

Added: labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/impl/db/protocol/PluginValuesEntity.java
===================================================================
--- labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/impl/db/protocol/PluginValuesEntity.java	2006-10-09 10:59:54 UTC (rev 6702)
+++ labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/impl/db/protocol/PluginValuesEntity.java	2006-10-09 11:40:28 UTC (rev 6703)
@@ -0,0 +1,158 @@
+
+ /*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2006, 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.service.impl.db.protocol;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+import javax.persistence.CascadeType;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.JoinColumn;
+import javax.persistence.ManyToOne;
+import javax.persistence.MapKey;
+import javax.persistence.OneToMany;
+import javax.persistence.Table;
+
+import org.jboss.forge.status.common.protocol.conf.PluginValues;
+import org.jboss.forge.status.service.plugins.Plugin;
+
+/**
+ * @author Pawel Wrzeszcz (pawel.wrzeszcz [at] gmail.com)
+ */
+ at Entity
+ at Table(name = "jblab_jmm_plugin_values")
+public class PluginValuesEntity extends ScoresEntity implements PluginValues
+{
+
+	private static final long serialVersionUID = 6211914842083801542L;
+	
+	private long id;
+    private String pluginId;
+    private String linkName;
+    private PluginsValuesEntity pluginsValues;
+    
+    private Map<String, ValueEntity> values = new HashMap<String, ValueEntity>();
+   
+    /**
+     * Default constructor
+     */
+    public PluginValuesEntity () {}
+        
+    public PluginValuesEntity(Plugin plugin, Set<String> projectIds,
+    								PluginsValuesEntity pluginsValues) {
+    	
+		// Get plugin properties
+		pluginId = plugin.getId();
+		linkName = plugin.getLinkName();
+		
+		// Get plugin values
+		for (String projectId : projectIds) {
+			
+			ValueEntity value = new ValueEntity(projectId,
+												plugin.getValue(projectId),
+											    plugin.getRate(projectId),
+											    plugin.getLink(projectId),
+											    this);
+			values.put(projectId, value);
+		}
+		
+		this.pluginsValues = pluginsValues;
+    }
+
+	@Id
+    @GeneratedValue
+    @Column(name = "id")
+    public long getId() {
+		return id;
+	}
+    
+    protected void setId(long id) {
+    	this.id = id;
+    }
+
+	@Column(name = "pluginId")
+	public String getPluginId() {
+		return pluginId;
+	}
+
+	public void setPluginId(String pluginId) {
+		this.pluginId = pluginId;
+	}
+	
+	@Column(name = "linkName")
+	public String getLinkName() {
+		return linkName;
+	}
+
+	protected void setLinkName(String linkName) {
+		this.linkName = linkName;
+	}
+
+	@OneToMany(mappedBy="pluginValues",cascade={CascadeType.ALL})
+	@MapKey(name="projectId") 
+	public Map<String, ValueEntity> getValues() {
+		return values;
+	}
+
+	public void setValues(Map<String, ValueEntity> values) {
+		this.values = values;
+	}
+	
+	@ManyToOne(cascade={CascadeType.ALL})
+    @JoinColumn(name="plugins_values_id")
+	public PluginsValuesEntity getPluginsValues() {
+		return pluginsValues;
+	}
+
+	public void setPluginsValues(PluginsValuesEntity pluginsValues) {
+		this.pluginsValues = pluginsValues;
+	}
+	
+	/* Non-DB methods */	
+
+	public long getValue(String projectId) {
+		
+		ValueEntity valueEntity = values.get(projectId);
+		
+		return (valueEntity == null ? 0 : valueEntity.getValue());
+	}
+
+	public int getRate(String projectId) {
+		
+		ValueEntity valueEntity = values.get(projectId);
+		
+		return (valueEntity == null ? 0 : valueEntity.getRate());
+	}
+	
+	public String getLink(String projectId) {
+
+		ValueEntity valueEntity = values.get(projectId);
+		
+		return (valueEntity == null ? "" : valueEntity.getLink());
+	}
+}

Added: labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/impl/db/protocol/PluginsValuesEntity.java
===================================================================
--- labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/impl/db/protocol/PluginsValuesEntity.java	2006-10-09 10:59:54 UTC (rev 6702)
+++ labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/impl/db/protocol/PluginsValuesEntity.java	2006-10-09 11:40:28 UTC (rev 6703)
@@ -0,0 +1,133 @@
+
+ /*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2006, 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.service.impl.db.protocol;
+
+import java.util.Calendar;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+import javax.persistence.CascadeType;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.MapKey;
+import javax.persistence.OneToMany;
+import javax.persistence.Table;
+import javax.persistence.Temporal;
+import javax.persistence.TemporalType;
+
+import org.jboss.forge.common.projects.Projects;
+import org.jboss.forge.common.projects.permissions.NullPermissionsChecker;
+import org.jboss.forge.status.common.protocol.conf.PluginValues;
+import org.jboss.forge.status.common.protocol.conf.PluginsValues;
+import org.jboss.forge.status.common.tools.Plugins;
+import org.jboss.forge.status.service.plugins.Plugin;
+
+/**
+ *
+ * @author Pawel Wrzeszcz (pawel.wrzeszcz [at] gmail.com)
+ *
+ * EJB3 Entity used to persist in database all
+ * project scores for Status Matrix.
+ */
+ at Entity
+ at Table(name = "jblab_jmm_plugins_values")
+public class PluginsValuesEntity extends ScoresEntity implements PluginsValues
+{
+
+	private static final long serialVersionUID = 1299912767177909726L;
+
+	private long id;
+	
+	@Temporal(TemporalType.DATE)
+    private Calendar date;
+    
+	/** Map : pluginId -> pluginValue */
+	private Map<String,PluginValuesEntity> values;
+	
+    /**
+     * Default constructor
+     */
+    public PluginsValuesEntity () {}
+    
+	/**
+	 * @param projects Projects present in the Status Matrix
+	 * @param plugins Plugins which values will be stored
+	 */
+	public PluginsValuesEntity(Projects projects, Plugins plugins) {
+		
+		date = Calendar.getInstance();
+		
+		values = new HashMap<String,PluginValuesEntity>();
+		
+		Set<String> projectIds =
+			projects.getProjectIds(new NullPermissionsChecker(), null);
+		
+		for (Plugin plugin : plugins.getPlugins()) {
+			
+			PluginValuesEntity pluginValues =
+							new PluginValuesEntity(plugin, projectIds, this);
+			
+			values.put(plugin.getId(), pluginValues);
+		}
+	}
+	
+    @Id
+    @GeneratedValue
+    @Column(name = "id")
+    public long getId() {
+		return id;
+	}
+    
+	protected void setId(long id) {
+    	this.id = id;
+    }
+
+	@Column(name = "date")
+	public Calendar getDate() {
+		return date;
+	}
+
+	public void setDate(Calendar date) {
+		this.date = date;
+	}
+
+	@OneToMany(mappedBy="pluginsValues",cascade={CascadeType.ALL})
+	@MapKey(name="pluginId") 
+	public Map<String, PluginValuesEntity> getValues() {
+		return values;
+	}
+
+	public void setValues(Map<String, PluginValuesEntity> values) {
+		this.values = values;
+	}
+
+	public PluginValues getPluginValues(String pluginId) {
+		return values.get(pluginId);
+	}
+	
+	
+}

Added: labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/impl/db/protocol/ScoresEntity.java
===================================================================
--- labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/impl/db/protocol/ScoresEntity.java	2006-10-09 10:59:54 UTC (rev 6702)
+++ labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/impl/db/protocol/ScoresEntity.java	2006-10-09 11:40:28 UTC (rev 6703)
@@ -0,0 +1,36 @@
+
+ /*
+  * 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.service.impl.db.protocol;
+
+
+
+
+/**
+ * @author Pawel Wrzeszcz (pawel.wrzeszcz [at] gmail.com)
+ */
+
+public abstract class ScoresEntity
+{
+
+}

Added: labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/impl/db/protocol/ValueEntity.java
===================================================================
--- labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/impl/db/protocol/ValueEntity.java	2006-10-09 10:59:54 UTC (rev 6702)
+++ labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/impl/db/protocol/ValueEntity.java	2006-10-09 11:40:28 UTC (rev 6703)
@@ -0,0 +1,120 @@
+
+ /*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2006, 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.service.impl.db.protocol;
+
+import javax.persistence.CascadeType;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.JoinColumn;
+import javax.persistence.ManyToOne;
+import javax.persistence.Table;
+
+
+/**
+ * @author Pawel Wrzeszcz (pawel.wrzeszcz [at] gmail.com)
+ */
+ at Entity
+ at Table(name = "jblab_jmm_scores")
+public class ValueEntity extends ScoresEntity
+{
+
+	private long id;
+	
+	private String projectId;
+	private long value;
+	private int rate;
+	private String link;
+	private PluginValuesEntity pluginValues;
+	
+	public ValueEntity() {}
+
+	public ValueEntity(String projectId, long value, int rate, String link,
+							PluginValuesEntity pluginValues) {
+		
+		this.projectId = projectId;
+		this.value = value;
+		this.rate = rate;
+		this.link = link;
+		this.pluginValues = pluginValues;
+	}
+
+	@Id
+    @GeneratedValue
+    @Column(name = "id")
+	public long getId() {
+		return id;
+	}
+	
+	protected void setId(long id) {
+		this.id = id;
+	}
+	
+	@Column(name = "projectId")
+	public String getProjectId() {
+		return projectId;
+	}
+
+	public void setProjectId(String projectId) {
+		this.projectId = projectId;
+	}
+
+	@Column(name = "link")
+	public String getLink() {
+		return link;
+	}
+
+	public void setLink(String link) {
+		this.link = link;
+	}
+
+	@Column(name = "rate")
+	public int getRate() {
+		return rate;
+	}
+
+	public void setRate(int rate) {
+		this.rate = rate;
+	}
+
+	@Column(name = "value")
+	public long getValue() {
+		return value;
+	}
+
+	public void setValue(long value) {
+		this.value = value;
+	}
+
+	@ManyToOne(cascade={CascadeType.ALL})
+    @JoinColumn(name="plugin_values_id")
+	public PluginValuesEntity getPluginValues() {
+		return pluginValues;
+	}
+
+	public void setPluginValues(PluginValuesEntity pluginValues) {
+		this.pluginValues = pluginValues;
+	}
+}
\ No newline at end of file

Added: labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/impl/shotoku/ShotokuScoresRepositoryManager.java
===================================================================
--- labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/impl/shotoku/ShotokuScoresRepositoryManager.java	2006-10-09 10:59:54 UTC (rev 6702)
+++ labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/impl/shotoku/ShotokuScoresRepositoryManager.java	2006-10-09 11:40:28 UTC (rev 6703)
@@ -0,0 +1,357 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, 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.service.impl.shotoku;
+
+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 java.util.HashMap;
+import java.util.Map;
+
+import org.jboss.forge.status.common.Locations;
+import org.jboss.forge.status.common.exceptions.GetScoresException;
+import org.jboss.forge.status.common.exceptions.ScoresSaveException;
+import org.jboss.forge.status.common.protocol.ScoresRepositoryManager;
+import org.jboss.forge.status.common.protocol.conf.PluginValues;
+import org.jboss.forge.status.common.protocol.conf.PluginsValues;
+import org.jboss.logging.Logger;
+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.ResourceDoesNotExist;
+
+/**
+* @author Pawel Wrzeszcz (pawel.wrzeszcz [at] gmail.com)
+*/
+
+public class ShotokuScoresRepositoryManager 
+									implements ScoresRepositoryManager {
+
+	private Logger log = Logger.getLogger(this.getClass());
+	
+	private Map<String,PluginsValues> values
+										= new HashMap<String,PluginsValues>();
+
+	private String portalName;
+	
+	@Inject
+	private ContentManager cm;
+	
+	public ShotokuScoresRepositoryManager(String portalName) {
+		
+		this.portalName = portalName;
+	};
+	
+	public void save(PluginsValues pluginsValues)
+										throws ScoresSaveException {
+		
+		// Get directory where we store historical scores
+		Directory rootDir = cm.getRootDirectory();
+		String dirName = Locations.getShotokuStatusPath(portalName);
+		Directory dir = getDir(rootDir, dirName);
+		
+		// Get node to store scores
+		String nodeName = getCurrentNodeName();
+		Node node = null;
+		
+		log.info("Getting shotoku node...");
+		
+		try {
+			node = dir.getNode(nodeName);
+		} catch (RepositoryException e) {
+			log.error("Error while getting shotoku node: " +
+					dir.getFullName() + "/" + nodeName, e);
+		} catch (ResourceDoesNotExist e) {
+			node = createNode(dir, nodeName);
+		}
+		
+		// Save values and store then in cache
+		values.put(getCurrentNodeName(), pluginsValues);
+		save(node, pluginsValues);
+		
+		log.info("Saved succesfully");
+		/*
+		ScoresEntity se = new ScoresEntity("tttest");
+		em.persist(se);
+		log.info("Saved in DB");*/
+	}
+
+	public PluginsValues get(Calendar cal) throws GetScoresException {
+		
+		String key = getNodeName(cal);
+		log.info("Returning plugins values (" + key + ") ...");
+		
+		// null date means today
+		if (cal == null) {
+			cal = Calendar.getInstance();
+		}
+		
+		PluginsValues v = values.get(key);
+		
+		if (v == null) { // Not in cache => get value and store it
+			
+			log.info("Value not in cache...");
+			Directory rootDir = cm.getRootDirectory();
+			
+			Directory dir;
+			try {
+				dir = rootDir.getDirectory(Locations.
+											getShotokuStatusPath(portalName));	
+			} catch (RepositoryException e) {
+				throw new GetScoresException(e);
+			} catch (ResourceDoesNotExist e) {
+				throw new GetScoresException(e);
+			}
+
+			if (dir != null) {
+				v = getPluginsValues(dir, cal);
+				log.info("Finished.");
+				values.put(key,v);
+			}
+		} else {
+			log.info("Returned cached value.");
+		}
+			
+		return v;
+	}
+	
+	/**
+	 * Saves plugins values in the given Directory.
+	 * 
+	 * @param dir Directory to save values
+	 * @param pluginsValues PluginsValues to save
+	 * @throws ScoresSaveException 
+	 */
+	private synchronized void save(Node node, PluginsValues pluginsValues)
+										throws ScoresSaveException {
+		
+		try {
+			OutputStream os = node.getOutputStream();
+			ObjectOutputStream oos = new ObjectOutputStream(os);
+			oos.writeObject((PluginsValues) pluginsValues);
+			oos.close(); 
+			node.save("update"); /* os is closed inside save() */
+			
+		} catch (Exception e) {
+			log.error("Error while saving shotoku node: " +
+					node.getFullName(), e);
+			throw new ScoresSaveException(e);
+		}
+	}
+	
+	/**
+	 * Creates new shotoku Node.
+	 * 
+	 * @param dir Directory in which new Node will be created
+	 * @param nodeName name of new Node
+	 * @return Node
+	 * @throws ScoresSaveException 
+	 */
+	private Node createNode(Directory dir, String nodeName)
+											throws ScoresSaveException {
+		
+		Node node = null;
+		
+		try {
+			node = dir.newNode(nodeName);
+			node.save("create");
+		} catch (Exception e) {
+			log.error("Error while creating shotoku node: " +
+					dir.getFullName() + "/" + nodeName, e);
+			throw new ScoresSaveException(e);
+		}
+		
+		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.  
+	 * @throws ScoresSaveException 
+	 */
+	private Directory getDir(Directory rootDir, String dirName)
+										throws ScoresSaveException {
+		
+		Directory dir = null;
+			
+		try {
+			dir = rootDir.getDirectory(dirName);
+		} catch (RepositoryException e) {
+			log.error("Error while getting shotoku directory " +
+					rootDir.getFullName() + "/" + dirName);
+			throw new ScoresSaveException(e);
+		} catch (ResourceDoesNotExist e) {
+			dir = createDir(rootDir, dirName);
+		}
+			
+		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
+	 * @throws ScoresSaveException 
+	 */
+	private Directory createDir(Directory rootDir, String dirName)
+												throws ScoresSaveException {
+		
+		Directory dir = null;
+		
+		try {
+			dir = rootDir.newDirectory(dirName);
+			dir.save("create");
+		} catch (Exception e) {
+			log.error("Error while creating shotoku directory: " +
+					rootDir.getFullName() + "/" + dirName, e);
+			throw new ScoresSaveException(e);
+		}
+		
+		return dir;
+	}
+
+	/**
+	 * Gets name of Node containing saved data from specified datestamp.
+	 * Notice that only year, month and day matter in passed <code>cal</code>.
+	 * 
+	 * @return Node name
+	 */
+	private String getNodeName(Calendar cal) {
+		
+		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
+		
+		Date date = cal.getTime();
+		
+		return df.format(date);
+	}
+	
+	/**
+	 * @return name of Node containging data saved today
+	 */
+	private String getCurrentNodeName() {
+		
+		Calendar today = Calendar.getInstance();
+		
+		return getNodeName(today); 
+	}
+	
+	/**
+	 * Returns historical scores from the specified directory.
+	 * 
+	 * @param dir Directory to read scores from
+	 * @return
+	 * @throws GetScoresException 
+	 */
+	private PluginsValues getPluginsValues(Directory dir, Calendar cal)
+												throws GetScoresException {
+		
+		// Get appropriate node
+		Node node = null;
+		String nodeName = getNodeName(cal);
+		
+		try {
+			node = dir.getNode(nodeName);
+		} catch (Exception e) {
+			log.info("Unable to get shotoku node " +
+					dir.getFullName() + "/" + nodeName);
+			throw new GetScoresException(e);
+		}
+		
+		// Restore values
+		PluginsValues values = null;
+		try {
+			InputStream is = node.getContentInputStream();
+			ObjectInputStream ois = new ObjectInputStream(is);
+			values = (PluginsValues) ois.readObject();
+			ois.close();
+			is.close();
+		} catch (Exception e) {
+			log.error("Error while restoring scores from shotoku node " +
+					dir.getFullName() + "/" + nodeName);
+			throw new GetScoresException(e);
+		}
+		
+		return values;
+	}
+
+	public long getValue(String pluginId, String projectId, Calendar cal)
+												throws GetScoresException {
+		
+		PluginValues pluginValues = getPluginValues(pluginId, cal);
+		
+		if (pluginValues == null) {
+			throw new GetScoresException();
+		}
+		
+		return pluginValues.getValue(projectId);
+	}
+
+	public PluginValues getPluginValues(String pluginId, Calendar cal)
+												throws GetScoresException {
+		
+		PluginsValues pluginsValues = get(cal);
+		
+		if (pluginsValues == null) {
+			throw new GetScoresException();
+		}
+		
+		return pluginsValues.getPluginValues(pluginId);
+	}
+
+	public long getValue(String pluginId, String projectId,
+					Calendar start, Calendar end) throws GetScoresException {
+		
+		long value;
+		Calendar cal = start;
+		
+		for (;;) {
+			
+			if (cal.after(end)) {
+				throw new GetScoresException();
+			}
+			
+			try {
+				value = getValue(pluginId, projectId, cal);
+				return value;
+			} catch (GetScoresException e) {
+				// try next
+				cal.add(Calendar.DAY_OF_MONTH, 1);
+			}	
+		}
+	}
+	
+}

Added: labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/impl/shotoku/protocol/PluginValuesImpl.java
===================================================================
--- labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/impl/shotoku/protocol/PluginValuesImpl.java	2006-10-09 10:59:54 UTC (rev 6702)
+++ labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/impl/shotoku/protocol/PluginValuesImpl.java	2006-10-09 11:40:28 UTC (rev 6703)
@@ -0,0 +1,82 @@
+/*
+ * 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.service.impl.shotoku.protocol;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+import org.jboss.forge.status.common.protocol.conf.PluginValues;
+import org.jboss.forge.status.service.plugins.Plugin;
+
+/**
+* @author Pawel Wrzeszcz (pawel.wrzeszcz [at] gmail.com)
+* A class used to store plugin values in shotoku.
+*/
+
+public class PluginValuesImpl implements PluginValues {
+	
+	private static final long serialVersionUID = 5196364802717262757L;
+	
+	private String pluginId;
+	private String linkName;
+	
+	private Map<String,Long> values = new HashMap<String,Long>();
+	private Map<String,Integer> rates = new HashMap<String,Integer>();
+	private Map<String,String> links = new HashMap<String,String>();
+		
+	public PluginValuesImpl(Plugin plugin, Set<String> projectIds) {
+	
+		// Get plugin properties
+		pluginId = plugin.getId();
+		linkName = plugin.getLinkName();
+		
+		// Get plugin values
+		for (String projectId : projectIds) {
+			
+			values.put(projectId, plugin.getValue(projectId));
+			rates.put(projectId, new Integer(plugin.getRate(projectId)));
+			links.put(projectId, plugin.getLink(projectId));
+		}
+	}
+
+	public String getPluginId() {
+		return pluginId;
+	}
+	
+	public long getValue(String projectId) {
+		return values.get(projectId);
+	}
+
+	public int getRate(String projectId) {
+		return rates.get(projectId);
+	}
+	
+	public String getLink(String projectId) {
+		return links.get(projectId);
+	}
+	
+	public String getLinkName() {
+		return linkName;
+	}
+}

Added: labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/impl/shotoku/protocol/PluginsValuesImpl.java
===================================================================
--- labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/impl/shotoku/protocol/PluginsValuesImpl.java	2006-10-09 10:59:54 UTC (rev 6702)
+++ labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/impl/shotoku/protocol/PluginsValuesImpl.java	2006-10-09 11:40:28 UTC (rev 6703)
@@ -0,0 +1,84 @@
+/*
+ * 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.service.impl.shotoku.protocol;
+
+import java.util.Calendar;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.Set;
+
+import org.jboss.forge.common.projects.Projects;
+import org.jboss.forge.common.projects.permissions.NullPermissionsChecker;
+
+import org.jboss.forge.status.common.protocol.conf.PluginValues;
+import org.jboss.forge.status.common.protocol.conf.PluginsValues;
+import org.jboss.forge.status.common.tools.Plugins;
+import org.jboss.forge.status.service.plugins.Plugin;
+
+/**
+* @author Pawel Wrzeszcz (pawel.wrzeszcz [at] gmail.com)
+* A class used to store plugins values in shotoku.
+*/
+
+public class PluginsValuesImpl implements PluginsValues {
+
+	private static final long serialVersionUID = -1669515339062166738L;
+
+	/** Map : pluginId -> pluginValue */
+	private Map<String,PluginValues> values;
+	
+	/** Creation date */
+	private Calendar cal;
+	
+	/**
+	 * @param projects Projects present in the Status Matrix
+	 * @param plugins Plugins which values will be stored
+	 */
+	public PluginsValuesImpl(Projects projects, Plugins plugins) {
+		
+		cal = Calendar.getInstance();
+		
+		values = new HashMap<String,PluginValues>();
+		
+		Set<String> projectIds =
+			projects.getProjectIds(new NullPermissionsChecker(), null);
+		
+		for (Plugin plugin : plugins.getPlugins()) {
+			
+			PluginValuesImpl pluginValues = new PluginValuesImpl(plugin, projectIds);
+			
+			values.put(plugin.getId(), pluginValues);
+		}
+	}
+	
+	/**
+	 * @return creation date
+	 */
+	public Calendar getDate() {
+		return cal;
+	}
+	
+	public PluginValues getPluginValues(String pluginId) {
+		return values.get(pluginId);
+	}
+}

Added: labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/impl/shotoku/protocol/ShotokuScoresFactory.java
===================================================================
--- labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/impl/shotoku/protocol/ShotokuScoresFactory.java	2006-10-09 10:59:54 UTC (rev 6702)
+++ labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/impl/shotoku/protocol/ShotokuScoresFactory.java	2006-10-09 11:40:28 UTC (rev 6703)
@@ -0,0 +1,49 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, 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.service.impl.shotoku.protocol;
+
+import java.util.Set;
+
+import org.jboss.forge.common.projects.Projects;
+
+import org.jboss.forge.status.common.protocol.conf.PluginValues;
+import org.jboss.forge.status.common.protocol.conf.PluginsValues;
+import org.jboss.forge.status.common.protocol.conf.ScoresFactory;
+import org.jboss.forge.status.common.tools.Plugins;
+import org.jboss.forge.status.service.plugins.Plugin;
+
+
+/**
+* @author Pawel Wrzeszcz
+*/
+public class ShotokuScoresFactory implements ScoresFactory {
+	
+	public PluginsValues createPluginsValues(Projects projects, Plugins plugins) {
+		return new PluginsValuesImpl(projects, plugins);
+	}
+	
+	public PluginValues createPluginValues(Plugin plugin, Set<String> projectIds) {
+		return new PluginValuesImpl(plugin, projectIds);
+	}
+	
+}
\ No newline at end of file




More information about the jboss-svn-commits mailing list