|
From: <jbo...@li...> - 2006-06-15 13:42:45
|
Author: wrzep
Date: 2006-06-15 09:42:31 -0400 (Thu, 15 Jun 2006)
New Revision: 4768
Added:
labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/exceptions/ScoresException.java
Modified:
labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/Status.java
labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/StatusDescriptor.java
labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/exceptions/GetScoresException.java
labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/exceptions/ScoresSaveException.java
labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/tools/ScoresManager.java
Log:
JBLAB-599
bug fix (NPE when recent scores were not available)
Pawel
Modified: labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/Status.java
===================================================================
--- labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/Status.java 2006-06-15 12:29:40 UTC (rev 4767)
+++ labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/Status.java 2006-06-15 13:42:31 UTC (rev 4768)
@@ -39,6 +39,7 @@
import org.jboss.forge.status.common.Tags;
import org.jboss.forge.status.exceptions.InvalidPluginsConfigurationException;
import org.jboss.forge.status.exceptions.GetScoresException;
+import org.jboss.forge.status.exceptions.ScoresException;
import org.jboss.forge.status.exceptions.ScoresSaveException;
import org.jboss.forge.status.service.impl.protocol.PluginConfImpl;
import org.jboss.forge.status.service.impl.protocol.ServiceConfImpl;
@@ -84,7 +85,8 @@
* @param pluginsRoot Node defining Plugins used in the Matrix
*/
public Status(String portalName, Node statusRoot, Node pluginsRoot,
- org.jboss.shotoku.Node serviceNode) {
+ org.jboss.shotoku.Node serviceNode)
+ throws ScoresException {
log = Logger.getLogger(this.getClass());
@@ -96,6 +98,7 @@
ScoresManagerSync.init(portalName, serviceConf);
PluginsValues pluginsValues;
+
try {
// Get latest available scores
ScoresManager.init(portalName, serviceConf);
@@ -107,10 +110,10 @@
} catch (ScoresSaveException e) {
log.error("Saving scores failed ", e);
- return;
+ throw e;
} catch (GetScoresException e) {
log.error("Getting computed scores failed ", e);
- return;
+ throw e;
}
// Get columns to display on the main page
Modified: labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/StatusDescriptor.java
===================================================================
--- labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/StatusDescriptor.java 2006-06-15 12:29:40 UTC (rev 4767)
+++ labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/StatusDescriptor.java 2006-06-15 13:42:31 UTC (rev 4768)
@@ -22,10 +22,12 @@
package org.jboss.forge.status;
+import java.util.HashMap;
import java.util.Map;
import java.io.IOException;
import org.jboss.forge.status.common.Locations;
+import org.jboss.forge.status.exceptions.ScoresException;
import org.jboss.portal.common.context.DelegateContext;
import org.jboss.shotoku.ContentManager;
@@ -44,14 +46,28 @@
*/
public class StatusDescriptor {
- private DelegateContext context;
- private Map<String,DelegateContext> projectContexts;
- private Map<String,DelegateContext> columnContexts;
+ private DelegateContext context = new DelegateContext();
+ private Map<String,DelegateContext> projectContexts
+ = new HashMap<String,DelegateContext>();
+ private Map<String,DelegateContext> columnContexts
+ = new HashMap<String,DelegateContext>();
+
+ private String portalName;
+ private ContentManager cm;
+
private Status status;
public StatusDescriptor(String portalName, ContentManager cm) {
+ this.portalName = portalName;
+ this.cm = cm;
+
+ init();
+ }
+
+ private void init() {
+
try {
String statusPath = Locations.getXmlCmPath(portalName);
Node statusRoot = getRoot(cm , statusPath);
@@ -67,19 +83,22 @@
fillContext();
+ } catch (ScoresException e){
+ // do nothing
} catch (Exception e) {
e.printStackTrace();
}
}
private void fillContext() {
-
- context = new DelegateContext();
- status.fillContext(context);
- projectContexts = status.getProjectContexts();
- columnContexts = status.getColumnContexts();
-
+ if (status != null) {
+
+ status.fillContext(context);
+
+ projectContexts = status.getProjectContexts();
+ columnContexts = status.getColumnContexts();
+ }
}
public DelegateContext getContext() {
@@ -107,7 +126,11 @@
public void update() {
- if (status.needsUpdate()) {
+ if (status == null) {
+ init();
+ }
+
+ if ((status != null) && (status.needsUpdate())) {
fillContext();
}
}
Modified: labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/exceptions/GetScoresException.java
===================================================================
--- labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/exceptions/GetScoresException.java 2006-06-15 12:29:40 UTC (rev 4767)
+++ labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/exceptions/GetScoresException.java 2006-06-15 13:42:31 UTC (rev 4768)
@@ -27,7 +27,7 @@
* Indicates that searching for saved scores failed.
*/
-public class GetScoresException extends Exception {
+public class GetScoresException extends ScoresException {
private static final long serialVersionUID = 7291136165537810321L;
@@ -38,5 +38,9 @@
public GetScoresException(Exception e) {
super(e);
}
+
+ public GetScoresException(String msg) {
+ super(msg);
+ }
}
Added: labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/exceptions/ScoresException.java
===================================================================
--- labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/exceptions/ScoresException.java 2006-06-15 12:29:40 UTC (rev 4767)
+++ labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/exceptions/ScoresException.java 2006-06-15 13:42:31 UTC (rev 4768)
@@ -0,0 +1,44 @@
+/*
+ * 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.exceptions;
+
+/**
+* @author Pawel Wrzeszcz (paw...@gm...)
+*/
+
+public class ScoresException extends Exception {
+
+ private static final long serialVersionUID = -8228803296975062691L;
+
+ public ScoresException() {
+ super();
+ }
+
+ public ScoresException(Exception e) {
+ super(e);
+ }
+
+ public ScoresException(String msg) {
+ super(msg);
+ }
+}
Modified: labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/exceptions/ScoresSaveException.java
===================================================================
--- labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/exceptions/ScoresSaveException.java 2006-06-15 12:29:40 UTC (rev 4767)
+++ labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/exceptions/ScoresSaveException.java 2006-06-15 13:42:31 UTC (rev 4768)
@@ -27,7 +27,7 @@
* Indicates that computing or saving scores failed.
*/
-public class ScoresSaveException extends Exception {
+public class ScoresSaveException extends ScoresException {
private static final long serialVersionUID = 7291136165537810321L;
Modified: labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/tools/ScoresManager.java
===================================================================
--- labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/tools/ScoresManager.java 2006-06-15 12:29:40 UTC (rev 4767)
+++ labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/tools/ScoresManager.java 2006-06-15 13:42:31 UTC (rev 4768)
@@ -93,7 +93,9 @@
}
if ((attempts++) == Constants.MAX_ATTEMPTS) {
- return null;
+ throw new GetScoresException(
+ "Can not find any recently saved scores. " +
+ "Gave up after " + attempts + " attempts.");
}
cal.add(Calendar.DAY_OF_MONTH, -1);
|