Skip to content
Snippets Groups Projects
Commit a3d306f9 authored by kaloyane's avatar kaloyane
Browse files

minor: managed properties batch upload - strip off details from the error message

SVN: 19992
parent e13308ab
No related branches found
No related tags found
No related merge requests found
...@@ -72,7 +72,7 @@ class PropertiesBatchEvaluationErrors ...@@ -72,7 +72,7 @@ class PropertiesBatchEvaluationErrors
ScriptPE script) ScriptPE script)
{ {
totalFailedRowsNumber++; totalFailedRowsNumber++;
String errorMessage = evaluationError.getMessage(); String errorMessage = getErrorMessage(evaluationError);
if (shouldSkipDetailsAccumulation(errorMessage)) if (shouldSkipDetailsAccumulation(errorMessage))
{ {
return; return;
...@@ -90,6 +90,26 @@ class PropertiesBatchEvaluationErrors ...@@ -90,6 +90,26 @@ class PropertiesBatchEvaluationErrors
errorDetails.put(errorMessage, details); errorDetails.put(errorMessage, details);
} }
private String getErrorMessage(EvaluatorException evaluationError)
{
String result = null;
if (evaluationError.getCause() != null)
{
return evaluationError.getCause().getMessage();
} else
{
result = evaluationError.getMessage();
}
if (result == null)
{
// do not return null
return "";
}
return result;
}
/** /**
* @return <code>true</code> when the memory is full and no more errors should be * @return <code>true</code> when the memory is full and no more errors should be
* accumulated. * accumulated.
...@@ -118,14 +138,29 @@ class PropertiesBatchEvaluationErrors ...@@ -118,14 +138,29 @@ class PropertiesBatchEvaluationErrors
message.append(totalRowsNumber); message.append(totalRowsNumber);
message.append(" rows."); message.append(" rows.");
int numDisplayErrors = Math.min(errorDetails.size(), MAX_ERRORS_IN_USER_MESSAGE); // construct a mapping between message line and failed rows
List<ErrorDetail> formatDetails = sortErrorDetailsByRow().subList(0, numDisplayErrors); List<String> errorMessageLines = new ArrayList<String>();
for (ErrorDetail errDetail : formatDetails) Map<String, List<Integer>> failedRows = new HashMap<String, List<Integer>>();
for (ErrorDetail errDetails : errorDetails.values())
{
String msgLine = createUserFailureMsgLine(errDetails);
if (errorMessageLines.contains(msgLine))
{
List<Integer> accumulatedRows = failedRows.get(msgLine);
accumulatedRows.addAll(errDetails.rows);
} else
{
errorMessageLines.add(msgLine);
failedRows.put(msgLine, new ArrayList<Integer>(errDetails.rows));
}
}
for (String msgLine : errorMessageLines)
{ {
message.append("\n"); message.append("\n");
appendErrorDetails(message, errDetail, false); List<Integer> rows = failedRows.get(msgLine);
message.append(": "); message.append(formatRows(rows));
message.append(errDetail.evaluationError.getMessage()); message.append(msgLine);
} }
message.append("\n"); message.append("\n");
...@@ -153,6 +188,7 @@ class PropertiesBatchEvaluationErrors ...@@ -153,6 +188,7 @@ class PropertiesBatchEvaluationErrors
for (ErrorDetail errDetail : sortErrorDetailsByRow()) for (ErrorDetail errDetail : sortErrorDetailsByRow())
{ {
message.append("\n\n"); message.append("\n\n");
message.append(formatRows(errDetail.rows));
appendErrorDetails(message, errDetail, true); appendErrorDetails(message, errDetail, true);
message.append(": "); message.append(": ");
StringWriter sw = new StringWriter(); StringWriter sw = new StringWriter();
...@@ -176,10 +212,16 @@ class PropertiesBatchEvaluationErrors ...@@ -176,10 +212,16 @@ class PropertiesBatchEvaluationErrors
return result; return result;
} }
private String createUserFailureMsgLine(ErrorDetail details)
{
StringBuilder builder = new StringBuilder();
appendErrorDetails(builder, details, false);
return builder.toString();
}
private void appendErrorDetails(StringBuilder message, ErrorDetail errDetail, private void appendErrorDetails(StringBuilder message, ErrorDetail errDetail,
boolean includeFullRegistratorDetails) boolean includeFullRegistratorDetails)
{ {
message.append(formatRows(errDetail.rows));
message.append(" failed due to the property '"); message.append(" failed due to the property '");
message.append(errDetail.propertyCode); message.append(errDetail.propertyCode);
message.append("' causing a malfuction in the script (name = '"); message.append("' causing a malfuction in the script (name = '");
......
...@@ -16,7 +16,6 @@ ...@@ -16,7 +16,6 @@
package ch.systemsx.cisd.openbis.generic.server.business; package ch.systemsx.cisd.openbis.generic.server.business;
import static ch.systemsx.cisd.openbis.generic.server.business.PropertiesBatchEvaluationErrors.MAX_ERRORS_IN_USER_MESSAGE;
import static ch.systemsx.cisd.openbis.generic.server.business.PropertiesBatchEvaluationErrors.MAX_ERROR_DETAILS_KEPT; import static ch.systemsx.cisd.openbis.generic.server.business.PropertiesBatchEvaluationErrors.MAX_ERROR_DETAILS_KEPT;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
...@@ -40,6 +39,8 @@ public class PropertiesBatchEvaluationErrorsTest extends AssertJUnit ...@@ -40,6 +39,8 @@ public class PropertiesBatchEvaluationErrorsTest extends AssertJUnit
private final int totalRows = 100; private final int totalRows = 100;
private final int totalErrors = totalRows / 2;
private PropertiesBatchEvaluationErrors errors; private PropertiesBatchEvaluationErrors errors;
private ScriptPE script; private ScriptPE script;
...@@ -55,16 +56,16 @@ public class PropertiesBatchEvaluationErrorsTest extends AssertJUnit ...@@ -55,16 +56,16 @@ public class PropertiesBatchEvaluationErrorsTest extends AssertJUnit
@Test @Test
public void testAllRowsFailWithTheSameErrorMessage() public void testAllRowsFailWithTheSameErrorMessage()
{ {
for (int i = 1; i <= totalRows; i++) for (int i = 1; i <= totalErrors; i++)
{ {
errors.accumulateError(i, new EvaluatorException(ERROR_TEXT), CODE, script); errors.accumulateError(i, new EvaluatorException(ERROR_TEXT), CODE, script);
} }
assertTrue(errors.hasErrors()); assertTrue(errors.hasErrors());
assertEquals( assertEquals(
"Script malfunction in 100 out of 100 rows.\n" "Script malfunction in 50 out of 100 rows.\n"
+ "100 rows including [1, 2, 3] have failed due to the property 'propcode' causing a malfuction in the script " + "50 rows including [1, 2, 3] have failed due to the property 'propcode' causing a malfuction in the script "
+ "(name = 'script.py', registrator = 'admin@vip.net'): errtext\n" + "(name = 'script.py', registrator = 'admin@vip.net')\n"
+ "A detailed error report has been sent to your system administrator.", + "A detailed error report has been sent to your system administrator.",
errors.constructUserFailureMessage()); errors.constructUserFailureMessage());
...@@ -73,14 +74,15 @@ public class PropertiesBatchEvaluationErrorsTest extends AssertJUnit ...@@ -73,14 +74,15 @@ public class PropertiesBatchEvaluationErrorsTest extends AssertJUnit
assertEquals(1, StringUtils.countMatches(email, ERROR_TEXT)); assertEquals(1, StringUtils.countMatches(email, ERROR_TEXT));
String pattern = String pattern =
"100 rows including [1, 2, 3] have failed due to the property 'propcode' causing a malfuction"; totalErrors
+ " rows including [1, 2, 3] have failed due to the property 'propcode' causing a malfuction";
assertEquals(1, StringUtils.countMatches(email, pattern)); assertEquals(1, StringUtils.countMatches(email, pattern));
} }
@Test @Test
public void testAllRowsFailWithADifferentErrorMessage() public void testAllRowsFailWithADifferentErrorMessage()
{ {
for (int i = 1; i <= totalRows; i++) for (int i = 1; i <= totalErrors; i++)
{ {
errors.accumulateError(i, new EvaluatorException(ERROR_TEXT + i), CODE, script); errors.accumulateError(i, new EvaluatorException(ERROR_TEXT + i), CODE, script);
} }
...@@ -88,8 +90,7 @@ public class PropertiesBatchEvaluationErrorsTest extends AssertJUnit ...@@ -88,8 +90,7 @@ public class PropertiesBatchEvaluationErrorsTest extends AssertJUnit
assertTrue(errors.hasErrors()); assertTrue(errors.hasErrors());
String errorMessage = errors.constructUserFailureMessage(); String errorMessage = errors.constructUserFailureMessage();
// not more than 3 messages shown to the user assertEquals(1, StringUtils.countMatches(errorMessage, "script.py"));
assertEquals(MAX_ERRORS_IN_USER_MESSAGE, StringUtils.countMatches(errorMessage, ERROR_TEXT));
String email = errors.constructErrorReportEmail(); String email = errors.constructErrorReportEmail();
// only the first 10 stack traces are included // only the first 10 stack traces are included
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment