Added:
/minimark/src/main/java/com/benfante/minimark/MinimarkExceptionResolver.java
Modified:
/minimark/src/main/java/com/benfante/minimark/po/ClosedQuestionFilling.java
/minimark/src/main/java/com/benfante/minimark/po/FixedAnswerFilling.java
/minimark/src/main/webapp/META-INF/context.xml
/minimark/src/main/webapp/WEB-INF/parancoe-servlet.xml
/minimark/src/test/java/com/benfante/minimark/blo/ResultCalculationBoTest.java
=======================================
--- /dev/null
+++
/minimark/src/main/java/com/benfante/minimark/MinimarkExceptionResolver.java
Tue Jan 12 23:35:00 2010
@@ -0,0 +1,82 @@
+/**
+ * Copyright (C) 2009 Lucio Benfante <lucio.b...@gmail.com>
+ *
+ * This file is part of minimark Web Application.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.benfante.minimark;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import org.apache.log4j.Logger;
+import org.parancoe.web.ExceptionResolver;
+import org.springframework.web.HttpSessionRequiredException;
+import org.springframework.web.multipart.MultipartException;
+import org.springframework.web.multipart.commons.CommonsMultipartResolver;
+import org.springframework.web.servlet.ModelAndView;
+
+/**
+ * Ovverride ExceptionResolver to define custom web application Exception.
+ * Should be mapped in parancoe-servlet.xml
+ * @author Lucio Benfante <lucio.b...@gmail.com>
+ */
+public class MinimarkExceptionResolver extends ExceptionResolver {
+
+ private static final Logger logger =
+ Logger.getLogger(MinimarkExceptionResolver.class);
+ private CommonsMultipartResolver multipartResolver;
+
+ public CommonsMultipartResolver getMultipartResolver() {
+ return multipartResolver;
+ }
+
+ public void setMultipartResolver(CommonsMultipartResolver
multipartResolver) {
+ this.multipartResolver = multipartResolver;
+ }
+
+ @Override
+ public ModelAndView resolveException(HttpServletRequest req,
+ HttpServletResponse res, Object object, Exception e) {
+ try {
+ if (!interceptedWithMinimalLogging(e)) {
+ logger.error("Unexpected exception", e);
+ }
+ logger.info("Exception requesting URL: " + req.getRequestURL().
+ toString());
+ logger.info(" request from " + req.getRemoteHost() + "(" +
req.
+ getRemoteAddr() + ")");
+ return super.resolveException(req, res, object, e);
+ } catch (Exception ex) {
+ logger.error("Error resolving exception", ex);
+ }
+ return new ModelAndView("redirect:/home/500page.html");
+ }
+
+ private boolean interceptedWithMinimalLogging(Exception e) {
+ boolean intercepted = false;
+ // Discarding too generic exception, with unuseful stacktrace...so
minimal log output.
+ // Maybe some could be moved to the base class.
+ if ((e instanceof HttpSessionRequiredException)
+ || (e instanceof MultipartException)) {
+ if (logger.isDebugEnabled()) {
+ logger.debug(e.getLocalizedMessage(), e);
+ } else {
+ logger.error("[" + e.getClass().getName() + "] " + e.
+ getLocalizedMessage());
+ }
+ intercepted = true;
+ }
+ return intercepted;
+ }
+}
=======================================
---
/minimark/src/main/java/com/benfante/minimark/po/ClosedQuestionFilling.java
Wed Sep 23 09:43:07 2009
+++
/minimark/src/main/java/com/benfante/minimark/po/ClosedQuestionFilling.java
Tue Jan 12 23:35:00 2010
@@ -80,7 +80,7 @@
BigDecimal result = BigDecimal.ZERO;
for (FixedAnswerFilling fixedAnswer : getFixedAnswers()) {
if (fixedAnswer.getCorrect() != null &&
fixedAnswer.getCorrect()) {
- result = result.add(fixedAnswer.getWeight());
+ result = result.add(fixedAnswer.getNotNullWeight());
}
}
return result;
@@ -91,7 +91,7 @@
for (FixedAnswerFilling fixedAnswer : getFixedAnswers()) {
if ((fixedAnswer.getCorrect() != null &&
fixedAnswer.getCorrect())
&& (fixedAnswer.getSelected() != null &&
fixedAnswer.getSelected())) {
- result = result.add(fixedAnswer.getWeight());
+ result = result.add(fixedAnswer.getNotNullWeight());
}
}
return result;
@@ -101,7 +101,7 @@
BigDecimal result = BigDecimal.ZERO;
for (FixedAnswerFilling fixedAnswer : getFixedAnswers()) {
if (fixedAnswer.getCorrect() == null |
| !fixedAnswer.getCorrect()) {
- result = result.add(fixedAnswer.getWeight());
+ result = result.add(fixedAnswer.getNotNullWeight());
}
}
return result;
@@ -112,7 +112,7 @@
for (FixedAnswerFilling fixedAnswer : getFixedAnswers()) {
if ((fixedAnswer.getCorrect() == null |
| !fixedAnswer.getCorrect())
&& (fixedAnswer.getSelected() != null &&
fixedAnswer.getSelected())) {
- result = result.add(fixedAnswer.getWeight());
+ result = result.add(fixedAnswer.getNotNullWeight());
}
}
return result;
=======================================
---
/minimark/src/main/java/com/benfante/minimark/po/FixedAnswerFilling.java
Fri Sep 4 00:37:53 2009
+++
/minimark/src/main/java/com/benfante/minimark/po/FixedAnswerFilling.java
Tue Jan 12 23:35:00 2010
@@ -26,12 +26,13 @@
import org.parancoe.persistence.po.hibernate.EntityBase;
/**
- * A fixed answer
+ * A fixed answer.
*
* @author lucio
*/
@Entity
public class FixedAnswerFilling extends EntityBase {
+
protected String content;
protected String contentFilter;
protected BigDecimal weight;
@@ -107,4 +108,9 @@
return TextFilterUtils.formatText(this.content,
this.contentFilter);
}
-}
+ @Transient
+ public BigDecimal getNotNullWeight() {
+ // return this.getWeight();
+ return this.getWeight() != null ? this.getWeight() :
BigDecimal.ZERO;
+ }
+}
=======================================
--- /minimark/src/main/webapp/META-INF/context.xml Fri Sep 4 00:37:53 2009
+++ /minimark/src/main/webapp/META-INF/context.xml Tue Jan 12 23:35:00 2010
@@ -30,5 +30,5 @@
url="jdbc:hsqldb:mem:minimark"
maxActive="5"/>
-->
- <Resource auth="Container" driverClassName="org.postgresql.Driver"
maxActive="25" name="jdbc/minimarkDS" password="minimark"
type="javax.sql.DataSource" url="jdbc:postgresql://localhost:5432/minimark"
username="minimark"/>
+ <Resource auth="Container" driverClassName="org.postgresql.Driver"
maxActive="25" name="jdbc/minimarkDS" password="minimark"
type="javax.sql.DataSource" url="jdbc:postgresql://localhost:5434/minimark"
username="minimark"/>
</Context>
=======================================
--- /minimark/src/main/webapp/WEB-INF/parancoe-servlet.xml Mon Sep 7
21:04:55 2009
+++ /minimark/src/main/webapp/WEB-INF/parancoe-servlet.xml Tue Jan 12
23:35:00 2010
@@ -39,6 +39,10 @@
</property>
</bean>
+ <!-- override bean definition in parancoe-servlet.xml -->
+ <!-- sends exceptions to genericError.jsp -->
+ <bean id="exceptionResolver"
class="com.benfante.minimark.MinimarkExceptionResolver" autowire="byType"/>
+
<!-- begin security section -->
<bean name="pluginSecurityFilterDefinitions" class="java.lang.String">
<constructor-arg>
=======================================
---
/minimark/src/test/java/com/benfante/minimark/blo/ResultCalculationBoTest.java
Sun Dec 20 01:03:43 2009
+++
/minimark/src/test/java/com/benfante/minimark/blo/ResultCalculationBoTest.java
Tue Jan 12 23:35:00 2010
@@ -273,6 +273,37 @@
assertNotNull(question.getMark());
assertEquals(new BigDecimal("-0.25"), question.getMark());
}
+
+ public void testEvaluateClosedQuestion8() {
+ Assessment assessment = new Assessment();
+
assessment.setEvaluationClosedType(Assessment.EVALUATION_CLOSED_SUM_CORRECT_MINUS_WRONG_ANSWERS);
+ AssessmentFilling assessmentFilling = new AssessmentFilling();
+ assessmentFilling.setAssessment(assessment);
+ ClosedQuestionFilling question = new ClosedQuestionFilling();
+ question.setAssessmentFilling(assessmentFilling);
+ question.setWeight(null);
+ List<FixedAnswerFilling> fixedAnswers =
+ new LinkedList<FixedAnswerFilling>();
+ FixedAnswerFilling fixedAnswer = new FixedAnswerFilling();
+ fixedAnswer.setWeight(null);
+ fixedAnswer.setCorrect(Boolean.TRUE);
+ fixedAnswer.setSelected(Boolean.FALSE);
+ fixedAnswers.add(fixedAnswer);
+ fixedAnswer = new FixedAnswerFilling();
+ fixedAnswer.setWeight(null);
+ fixedAnswer.setCorrect(Boolean.FALSE);
+ fixedAnswer.setSelected(Boolean.FALSE);
+ fixedAnswers.add(fixedAnswer);
+ fixedAnswer = new FixedAnswerFilling();
+ fixedAnswer.setWeight(null);
+ fixedAnswer.setCorrect(Boolean.FALSE);
+ fixedAnswer.setSelected(Boolean.FALSE);
+ fixedAnswers.add(fixedAnswer);
+ question.setFixedAnswers(fixedAnswers);
+ resultCalculationBo.evaluateQuestion(question,
BigDecimal.valueOf(-0.25));
+ assertNotNull(question.getMark());
+ assertEquals(new BigDecimal("0.00"), question.getMark());
+ }
public void testEvaluateBlankClosedQuestion() {
Assessment assessment = new Assessment();