[jboss-svn-commits] JBL Code SVN: r13166 - in labs/jbosslabs/trunk/portal-extensions/forge-kosmos-portlets/src/java/org/jboss/forge/kosmos: jira and 1 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Fri Jul 6 12:26:51 EDT 2007
Author: wrzep
Date: 2007-07-06 12:26:51 -0400 (Fri, 06 Jul 2007)
New Revision: 13166
Added:
labs/jbosslabs/trunk/portal-extensions/forge-kosmos-portlets/src/java/org/jboss/forge/kosmos/KosmosException.java
labs/jbosslabs/trunk/portal-extensions/forge-kosmos-portlets/src/java/org/jboss/forge/kosmos/KosmosPreferences.java
Modified:
labs/jbosslabs/trunk/portal-extensions/forge-kosmos-portlets/src/java/org/jboss/forge/kosmos/MetricsPortlet.java
labs/jbosslabs/trunk/portal-extensions/forge-kosmos-portlets/src/java/org/jboss/forge/kosmos/jira/LabsKosmosJiraDescriptor.java
labs/jbosslabs/trunk/portal-extensions/forge-kosmos-portlets/src/java/org/jboss/forge/kosmos/jira/LabsKosmosJiraWatcher.java
labs/jbosslabs/trunk/portal-extensions/forge-kosmos-portlets/src/java/org/jboss/forge/kosmos/svn/LabsKosmosSvnDescriptor.java
labs/jbosslabs/trunk/portal-extensions/forge-kosmos-portlets/src/java/org/jboss/forge/kosmos/svn/LabsKosmosSvnWatcher.java
Log:
JBLAB-868 last issues concerning kosmos portlet
Added: labs/jbosslabs/trunk/portal-extensions/forge-kosmos-portlets/src/java/org/jboss/forge/kosmos/KosmosException.java
===================================================================
--- labs/jbosslabs/trunk/portal-extensions/forge-kosmos-portlets/src/java/org/jboss/forge/kosmos/KosmosException.java (rev 0)
+++ labs/jbosslabs/trunk/portal-extensions/forge-kosmos-portlets/src/java/org/jboss/forge/kosmos/KosmosException.java 2007-07-06 16:26:51 UTC (rev 13166)
@@ -0,0 +1,38 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, Red Hat Middleware LLC 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.kosmos;
+
+public class KosmosException extends Exception {
+
+ private static final long serialVersionUID = 1144423456629953322L;
+
+ public KosmosException() {}
+
+ public KosmosException(String message) {
+ super(message);
+ }
+
+ public KosmosException(String message, Throwable e) {
+ super(message, e);
+ }
+}
Added: labs/jbosslabs/trunk/portal-extensions/forge-kosmos-portlets/src/java/org/jboss/forge/kosmos/KosmosPreferences.java
===================================================================
--- labs/jbosslabs/trunk/portal-extensions/forge-kosmos-portlets/src/java/org/jboss/forge/kosmos/KosmosPreferences.java (rev 0)
+++ labs/jbosslabs/trunk/portal-extensions/forge-kosmos-portlets/src/java/org/jboss/forge/kosmos/KosmosPreferences.java 2007-07-06 16:26:51 UTC (rev 13166)
@@ -0,0 +1,87 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, Red Hat Middleware LLC 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.kosmos;
+
+import java.util.Enumeration;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import javax.portlet.PortletPreferences;
+
+/**
+ * @author Pawel Wrzeszcz (pwrzeszcz [at] jboss . org)
+ */
+public class KosmosPreferences {
+
+ private static final String JIRA_ASSIGNEE = "showJIRAIssuesByAssignee";
+ private static final String JIRA_STATUS = "showJIRAIssuesByStatus";
+ private static final String JIRA_PRIORITY = "showJIRAIssuesByPriority";
+
+ private static final String SVN_COMMIT = "showCommitHistory";
+ private static final String SVN_COMMITERS = "showMostActiveCommiters";
+ private static final String SVN_ENTRIES = "showRepositoryEntryHistory";
+ private static final String SVN_FILE_TYPE = "showFilesByFileType";
+ private static final String SVN_FILES = "showMostActiveFiles";
+
+ @SuppressWarnings("unchecked")
+ public static boolean svnEnabled(PortletPreferences portletPreferences) {
+
+ Set<String> preferences = getPreferences(portletPreferences);
+
+ return preferences.contains(SVN_COMMIT) ||
+ preferences.contains(SVN_COMMITERS) ||
+ preferences.contains(SVN_ENTRIES) ||
+ preferences.contains(SVN_FILE_TYPE) ||
+ preferences.contains(SVN_FILES);
+ }
+
+ @SuppressWarnings("unchecked")
+ public static boolean jiraEnabled(PortletPreferences portletPreferences) {
+
+ Set<String> preferences = getPreferences(portletPreferences);
+
+ return preferences.contains(JIRA_ASSIGNEE) ||
+ preferences.contains(JIRA_STATUS) ||
+ preferences.contains(JIRA_PRIORITY);
+ }
+
+ @SuppressWarnings("unchecked")
+ private static Set<String> getPreferences(
+ PortletPreferences portletPreferences) {
+
+ Set<String> preferences = new HashSet<String>();
+
+ for (Enumeration e = portletPreferences.getNames(); e.hasMoreElements();) {
+
+ String pref = (String) e.nextElement();
+
+ if (portletPreferences.getValue(pref, "true").equals("true")) {
+ preferences.add(pref);
+ }
+ }
+
+ return preferences;
+ }
+
+ private KosmosPreferences() {}
+}
\ No newline at end of file
Modified: labs/jbosslabs/trunk/portal-extensions/forge-kosmos-portlets/src/java/org/jboss/forge/kosmos/MetricsPortlet.java
===================================================================
--- labs/jbosslabs/trunk/portal-extensions/forge-kosmos-portlets/src/java/org/jboss/forge/kosmos/MetricsPortlet.java 2007-07-06 15:49:25 UTC (rev 13165)
+++ labs/jbosslabs/trunk/portal-extensions/forge-kosmos-portlets/src/java/org/jboss/forge/kosmos/MetricsPortlet.java 2007-07-06 16:26:51 UTC (rev 13166)
@@ -24,6 +24,7 @@
import javax.portlet.GenericPortlet;
import javax.portlet.PortletConfig;
import javax.portlet.PortletException;
+import javax.portlet.PortletPreferences;
import javax.portlet.PortletRequestDispatcher;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
@@ -70,14 +71,35 @@
String projectId = ProjectsHelper.getSelectedProjectId(request);
- LabsKosmosJiraDescriptor jiraDesc = jiraWatcher.get(new Pair<String, String>(projectId,serviceUrl));
- jiraDesc.fillContext(getPortletContext());
+ @SuppressWarnings("unchecked")
+ PortletPreferences preferences = request.getPreferences();
- LabsKosmosSvnDescriptor svnDesc = svnWatcher.get(new Pair<String, String>(projectId,serviceUrl));
- svnDesc.fillContext(getPortletContext());
+ if (KosmosPreferences.jiraEnabled(preferences)) {
+ LabsKosmosJiraDescriptor jiraDesc = jiraWatcher.get(new Pair<String, String>(projectId,serviceUrl));
+ getPortletContext().setAttribute("jiraStats", true);
+ if (jiraDesc == null) {
+ getPortletContext().setAttribute("jiraStatsAvailable", false);
+ } else {
+ jiraDesc.fillContext(getPortletContext());
+ }
+ } else {
+ getPortletContext().setAttribute("jiraStats", false);
+ }
- getPortletContext().setAttribute("pref", request.getPreferences().getMap());
+ if (KosmosPreferences.svnEnabled(preferences)) {
+ LabsKosmosSvnDescriptor svnDesc = svnWatcher.get(new Pair<String, String>(projectId,serviceUrl));
+ getPortletContext().setAttribute("svnStats", true);
+ if (svnDesc == null) {
+ getPortletContext().setAttribute("svnStatsAvailable", false);
+ } else {
+ svnDesc.fillContext(getPortletContext());
+ }
+ } else {
+ getPortletContext().setAttribute("svnStats", false);
+ }
+ getPortletContext().setAttribute("pref", preferences.getMap());
+
response.setContentType("text/html");
PortletRequestDispatcher rd = getPortletContext().getRequestDispatcher(
Modified: labs/jbosslabs/trunk/portal-extensions/forge-kosmos-portlets/src/java/org/jboss/forge/kosmos/jira/LabsKosmosJiraDescriptor.java
===================================================================
--- labs/jbosslabs/trunk/portal-extensions/forge-kosmos-portlets/src/java/org/jboss/forge/kosmos/jira/LabsKosmosJiraDescriptor.java 2007-07-06 15:49:25 UTC (rev 13165)
+++ labs/jbosslabs/trunk/portal-extensions/forge-kosmos-portlets/src/java/org/jboss/forge/kosmos/jira/LabsKosmosJiraDescriptor.java 2007-07-06 16:26:51 UTC (rev 13166)
@@ -5,7 +5,7 @@
* 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
+ * under the terms of the GNU Lesser General Public Licaense as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
@@ -34,8 +34,7 @@
import org.jboss.forge.common.exceptions.ServiceRetrievalException;
import org.jboss.forge.common.projects.project.IssueTracker;
import org.jboss.forge.common.projects.project.rw.IssueTrackerTypeRW;
-import org.jboss.logging.Logger;
-
+import org.jboss.forge.kosmos.KosmosException;
import com.caucho.hessian.client.HessianProxyFactory;
/**
@@ -43,8 +42,6 @@
* @author <a href="mailto:aron.gombas at midori.hu">Aron Gombas</a>
*/
public class LabsKosmosJiraDescriptor {
-
- protected final static Logger log = Logger.getLogger(LabsKosmosJiraDescriptor.class);
private static final String JIRA_SERVICE = "jira-service";
@@ -52,7 +49,7 @@
private Date timestamp;
- public LabsKosmosJiraDescriptor(String projectId, String serviceUrl) {
+ public LabsKosmosJiraDescriptor(String projectId, String serviceUrl) throws KosmosException {
JiraService service = getService(serviceUrl + JIRA_SERVICE);
@@ -67,7 +64,7 @@
projects = service.getProjects(monitoredUrl);
timestamp = service.getTimestamp();
} catch (Exception e) {
- log.warn("Unable to get project from service " +
+ throw new KosmosException("Unable to get project from service " +
"(projectId: " + projectId + ")", e);
}
}
@@ -75,7 +72,7 @@
if ((projects != null) && (projects.size() > 0)) {
jiraProject = projects.get(0);
} else {
- log.warn("Failed to download JIRA project: " + monitoredUrl +
+ throw new KosmosException("Failed to download JIRA project: " + monitoredUrl +
" (projectId:" + projectId + ")");
}
}
@@ -83,28 +80,30 @@
public boolean fillContext(PortletContext portletContext) {
if (jiraProject == null) {
+ portletContext.setAttribute("jiraStatsAvailable", false);
return false;
}
+ portletContext.setAttribute("jiraStatsAvailable", true);
portletContext.setAttribute("project", jiraProject);
portletContext.setAttribute("timestamp", timestamp);
return true;
}
- private JiraService getService(String serviceUrl) {
+ private JiraService getService(String serviceUrl) throws KosmosException {
JiraService service = null;
HessianProxyFactory factory = new HessianProxyFactory();
try {
service = (JiraService)factory.create(JiraService.class, serviceUrl);
} catch (MalformedURLException ex) {
- log.warn("Unable to connect to the service\n" + ex.getMessage());
+ throw new KosmosException("Unable to connect to the service", ex);
}
return service;
}
- private String getProjectJira(String projectId) {
+ private String getProjectJira(String projectId) throws KosmosException {
try {
IssueTracker it =
@@ -115,7 +114,7 @@
}
} catch (ServiceRetrievalException e) {
- log.warn("Unable to get project " + projectId +"\n" + e.getMessage());
+ throw new KosmosException("Unable to get project " + projectId, e);
}
return null;
Modified: labs/jbosslabs/trunk/portal-extensions/forge-kosmos-portlets/src/java/org/jboss/forge/kosmos/jira/LabsKosmosJiraWatcher.java
===================================================================
--- labs/jbosslabs/trunk/portal-extensions/forge-kosmos-portlets/src/java/org/jboss/forge/kosmos/jira/LabsKosmosJiraWatcher.java 2007-07-06 15:49:25 UTC (rev 13165)
+++ labs/jbosslabs/trunk/portal-extensions/forge-kosmos-portlets/src/java/org/jboss/forge/kosmos/jira/LabsKosmosJiraWatcher.java 2007-07-06 16:26:51 UTC (rev 13166)
@@ -23,6 +23,8 @@
import java.util.Map;
+import org.jboss.forge.kosmos.KosmosException;
+import org.jboss.logging.Logger;
import org.jboss.shotoku.cache.ChangeType;
import org.jboss.shotoku.cache.ShotokuResourceWatcher;
import org.jboss.shotoku.tools.Pair;
@@ -32,23 +34,49 @@
*/
public class LabsKosmosJiraWatcher extends ShotokuResourceWatcher<Pair<String,String>,LabsKosmosJiraDescriptor> {
+ protected final static Logger log = Logger.getLogger(LabsKosmosJiraWatcher.class);
+
public LabsKosmosJiraWatcher(long interval) {
super(interval);
}
@Override
public LabsKosmosJiraDescriptor init(Pair<String,String> key) {
- return getDesc(key);
+ try {
+ return getDesc(key);
+ } catch (Exception e) {
+ log.warn("Unable to init", e);
+ return null;
+ }
}
@Override
protected void update(Pair<String,String> key, LabsKosmosJiraDescriptor currentObject,
Map<String, ChangeType> changes) {
- put(key, getDesc(key));
+
+ updateDesc(key);
}
- private LabsKosmosJiraDescriptor getDesc(Pair<String,String> key) {
+ @Override
+ public void update(Pair<String, String> key,
+ LabsKosmosJiraDescriptor currentObject) {
+
+ updateDesc(key);
+ }
+
+ private void updateDesc(Pair<String, String> key) {
+ LabsKosmosJiraDescriptor desc;
+ try {
+ desc = getDesc(key);
+ put(key, desc);
+ } catch (KosmosException e) {
+ log.warn("Unable to update", e);
+ }
+ }
+
+ private LabsKosmosJiraDescriptor getDesc(Pair<String,String> key) throws KosmosException {
+
String projectId = key.getFirst();
String serviceUrl = key.getSecond();
Modified: labs/jbosslabs/trunk/portal-extensions/forge-kosmos-portlets/src/java/org/jboss/forge/kosmos/svn/LabsKosmosSvnDescriptor.java
===================================================================
--- labs/jbosslabs/trunk/portal-extensions/forge-kosmos-portlets/src/java/org/jboss/forge/kosmos/svn/LabsKosmosSvnDescriptor.java 2007-07-06 15:49:25 UTC (rev 13165)
+++ labs/jbosslabs/trunk/portal-extensions/forge-kosmos-portlets/src/java/org/jboss/forge/kosmos/svn/LabsKosmosSvnDescriptor.java 2007-07-06 16:26:51 UTC (rev 13166)
@@ -32,9 +32,7 @@
import org.jboss.forge.common.ejb3.LabsServices;
import org.jboss.forge.common.exceptions.ServiceRetrievalException;
import org.jboss.forge.common.projects.project.rw.RepoTypeRW;
-import org.jboss.forge.kosmos.jira.LabsKosmosJiraDescriptor;
-import org.jboss.logging.Logger;
-
+import org.jboss.forge.kosmos.KosmosException;
import com.caucho.hessian.client.HessianProxyFactory;
/**
@@ -42,15 +40,13 @@
* @author Pawel Wrzeszcz (pwrzeszcz [at] jboss . org)
*/
public class LabsKosmosSvnDescriptor {
-
- protected final static Logger log = Logger.getLogger(LabsKosmosJiraDescriptor.class);
-
+
private static final String SVN_SERVICE = "svn-service";
private SvnRepository repository;
private Date timestamp;
- public LabsKosmosSvnDescriptor(String projectId, String serviceUrl) {
+ public LabsKosmosSvnDescriptor(String projectId, String serviceUrl) throws KosmosException {
SvnService service = getService(serviceUrl + SVN_SERVICE);
@@ -65,7 +61,7 @@
repositories = service.getRepositories(monitoredUrl);
timestamp = service.getTimestamp();
} catch (Exception e) {
- log.warn("Unable to get repository stats from service " +
+ throw new KosmosException("Unable to get repository stats from service " +
"(projectId: " + projectId + ", " +
"URL: " + monitoredUrl +
"Service URL: " + serviceUrl + ")", e);
@@ -75,7 +71,7 @@
if ((repositories != null) && (repositories.size() > 0)) {
repository = repositories.get(0);
} else {
- log.warn("Failed to download SVN repository: " + monitoredUrl +
+ throw new KosmosException("Failed to download SVN repository: " + monitoredUrl +
" (projectId:" + projectId + ")");
}
}
@@ -83,28 +79,30 @@
public boolean fillContext(PortletContext portletContext) {
if (repository == null) {
+ portletContext.setAttribute("svnStatsAvailable", false);
return false;
}
+ portletContext.setAttribute("svnStatsAvailable", true);
portletContext.setAttribute("repository", repository);
portletContext.setAttribute("timestamp", timestamp);
return true;
}
- private static SvnService getService(String serviceUrl) {
+ private static SvnService getService(String serviceUrl) throws KosmosException {
SvnService service = null;
HessianProxyFactory factory = new HessianProxyFactory();
try {
service = (SvnService)factory.create(SvnService.class, serviceUrl);
} catch (MalformedURLException ex) {
- log.error("Unable to connect to the service", ex);
+ throw new KosmosException("Unable to connect to the service", ex);
}
return service;
}
- private static String getProjectSvn(String projectId) {
+ private static String getProjectSvn(String projectId) throws KosmosException {
try {
@@ -115,7 +113,7 @@
}
} catch (ServiceRetrievalException e) {
- log.warn("Unable to get project " + projectId, e);
+ throw new KosmosException("Unable to get project " + projectId, e);
}
return null;
Modified: labs/jbosslabs/trunk/portal-extensions/forge-kosmos-portlets/src/java/org/jboss/forge/kosmos/svn/LabsKosmosSvnWatcher.java
===================================================================
--- labs/jbosslabs/trunk/portal-extensions/forge-kosmos-portlets/src/java/org/jboss/forge/kosmos/svn/LabsKosmosSvnWatcher.java 2007-07-06 15:49:25 UTC (rev 13165)
+++ labs/jbosslabs/trunk/portal-extensions/forge-kosmos-portlets/src/java/org/jboss/forge/kosmos/svn/LabsKosmosSvnWatcher.java 2007-07-06 16:26:51 UTC (rev 13166)
@@ -23,6 +23,8 @@
import java.util.Map;
+import org.jboss.forge.kosmos.KosmosException;
+import org.jboss.logging.Logger;
import org.jboss.shotoku.cache.ChangeType;
import org.jboss.shotoku.cache.ShotokuResourceWatcher;
import org.jboss.shotoku.tools.Pair;
@@ -32,23 +34,46 @@
*/
public class LabsKosmosSvnWatcher extends ShotokuResourceWatcher<Pair<String,String>,LabsKosmosSvnDescriptor> {
+ protected final static Logger log = Logger.getLogger(LabsKosmosSvnWatcher.class);
+
public LabsKosmosSvnWatcher(long interval) {
super(interval);
}
@Override
public LabsKosmosSvnDescriptor init(Pair<String,String> key) {
- return getDesc(key);
+ try {
+ return getDesc(key);
+ } catch (KosmosException e) {
+ log.warn("Unable to init", e);
+ return null;
+ }
}
@Override
protected void update(Pair<String,String> key, LabsKosmosSvnDescriptor currentObject,
Map<String, ChangeType> changes) {
- put(key, getDesc(key));
+ updateDesc(key);
}
- private LabsKosmosSvnDescriptor getDesc(Pair<String,String> key) {
+ @Override public void update(Pair<String, String> key,
+ LabsKosmosSvnDescriptor currentObject) {
+ updateDesc(key);
+ }
+
+ private void updateDesc(Pair<String, String> key) {
+ LabsKosmosSvnDescriptor desc;
+ try {
+ desc = getDesc(key);
+ put(key, desc);
+ } catch (Exception e) {
+ log.warn("Unable to update", e);
+ }
+ }
+
+ private LabsKosmosSvnDescriptor getDesc(Pair<String,String> key) throws KosmosException {
+
String projectId = key.getFirst();
String serviceUrl = key.getSecond();
More information about the jboss-svn-commits
mailing list