ALF-11591: Externalise diff/validation messages

system-messages.properties now contains log messages and diff/validation output messages.



git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@32236 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Matt Ward
2011-11-23 13:16:27 +00:00
parent 9be594eee2
commit f495a69ba9
9 changed files with 165 additions and 67 deletions

View File

@@ -17,6 +17,22 @@ system.config_check.err.fix_dir_root=Ensure that the ''dir.root'' property is po
system.config_check.msg.howto_index_recover=You may set 'index.recovery.mode=FULL' if you need to rebuild the indexes.
system.config_check.warn.starting_with_errors=Alfresco is starting with errors.
# Schema comparator messages
# Log messages...
system.schema_comp.debug.no_ref_file=No reference schema file, expected: {0}
system.schema_comp.debug.time_taken=Schema validation took {0} ms
system.schema_comp.info.all_ok=Compared database schema with reference schema (all OK): {0}
system.schema_comp.warn.problems_found=Schema validation found {0} potential problems, results written to: {1}
# Generic differencing, validation and redundancy messages...
system.schema_comp.diff=Difference: {0}, reference path:{1} (value: {2}), target path:{3} (value: {4})
system.schema_comp.diff.ref_only=Difference: {0}, reference path:{1} (value: {2})
system.schema_comp.diff.target_only=Difference: {0}, target path:{1} (value: {2})
system.schema_comp.redundant_obj={0} redundant items? reference: {1}, matches: {2}
system.schema_comp.redundant_obj.many_matches={0} redundant items? reference: {1}, matches: {2} and {3} more...
system.schema_comp.validation=Validation: target path:{0} (value: {1}, rule: {2})
# Specific validator (implementations) messages...
system.schema_comp.name_validator=name must match pattern ''{0}''
# OpenOffice
system.openoffice.info.connection_verified=The connection to OpenOffice has been established.
system.openoffice.err.connection_failed=An initial OpenOffice connection could not be established.

View File

@@ -154,11 +154,19 @@ public class SchemaBootstrap extends AbstractLifecycleBean
private static final String ERR_STATEMENT_VAR_ASSIGNMENT_BEFORE_SQL = "schema.update.err.statement_var_assignment_before_sql";
private static final String ERR_STATEMENT_VAR_ASSIGNMENT_FORMAT = "schema.update.err.statement_var_assignment_format";
private static final String ERR_STATEMENT_TERMINATOR = "schema.update.err.statement_terminator";
private static final String DEBUG_SCHEMA_COMP_NO_REF_FILE = "system.schema_comp.debug.no_ref_file";
private static final String INFO_SCHEMA_COMP_ALL_OK = "system.schema_comp.info.all_ok";
private static final String WARN_SCHEMA_COMP_PROBLEMS_FOUND = "system.schema_comp.warn.problems_found";
private static final String DEBUG_SCHEMA_COMP_TIME_TAKEN = "system.schema_comp.debug.time_taken";
public static final int DEFAULT_LOCK_RETRY_COUNT = 24;
public static final int DEFAULT_LOCK_RETRY_WAIT_SECONDS = 5;
public static final int DEFAULT_MAX_STRING_LENGTH = 1024;
private static volatile int maxStringLength = DEFAULT_MAX_STRING_LENGTH;
private Dialect dialect;
@@ -1638,7 +1646,8 @@ public class SchemaBootstrap extends AbstractLifecycleBean
Resource referenceResource = getDialectResource(dialect.getClass(), schemaReferenceUrl);
if (referenceResource == null || !referenceResource.exists())
{
logger.debug("No reference schema file, expected: " + referenceResource);
String resourceUrl = schemaReferenceUrl.replaceAll(PLACEHOLDER_DIALECT, dialect.getClass().getName());
LogUtil.debug(logger, DEBUG_SCHEMA_COMP_NO_REF_FILE, resourceUrl);
return;
}
@@ -1696,19 +1705,17 @@ public class SchemaBootstrap extends AbstractLifecycleBean
pw.close();
if (results.size() == 0)
{
logger.info("Compared database schema with reference schema (all OK): " + referenceResource);
{
LogUtil.info(logger, INFO_SCHEMA_COMP_ALL_OK, referenceResource);
}
else
{
int numProblems = results.size();
logger.warn("Schema validation found " + numProblems +
" potential problems, results written to: "
+ outputFile);
LogUtil.warn(logger, WARN_SCHEMA_COMP_PROBLEMS_FOUND, numProblems, outputFile);
}
Date endTime = new Date();
long durationMillis = endTime.getTime() - startTime.getTime();
logger.debug("Schema validation took " + durationMillis + "ms");
LogUtil.debug(logger, DEBUG_SCHEMA_COMP_TIME_TAKEN, durationMillis);
}
/**

View File

@@ -18,6 +18,8 @@
*/
package org.alfresco.util.schemacomp;
import org.springframework.extensions.surf.util.I18NUtil;
/**
@@ -42,6 +44,13 @@ public final class Difference extends Result
public Difference(Where where, DbProperty left, DbProperty right, Strength strength)
{
super(null);
// Sanity check parameters
if (left == null && right == null)
{
throw new IllegalArgumentException("DbProperty parameters cannot BOTH be null.");
}
this.where = where;
this.left = left;
this.right = right;
@@ -75,37 +84,30 @@ public final class Difference extends Result
@Override
public String describe()
{
StringBuffer sb = new StringBuffer();
sb.append("Difference: ")
.append(getWhere());
sb.append(" reference path:");
if (getLeft() != null)
if (getLeft() == null)
{
sb.append(getLeft().getPath());
sb.append(" (value: ")
.append(getLeft().getPropertyValue())
.append(")");
return I18NUtil.getMessage(
"system.schema_comp.diff.target_only",
getWhere(),
getRight().getPath(),
getRight().getPropertyValue());
}
else
if (getRight() == null)
{
sb.append("null");
return I18NUtil.getMessage(
"system.schema_comp.diff.ref_only",
getWhere(),
getLeft().getPath(),
getLeft().getPropertyValue());
}
sb.append(" target path:");
if (getRight() != null)
{
sb.append(getRight().getPath());
sb.append(" (value: ")
.append(getRight().getPropertyValue())
.append(")");
}
else
{
sb.append("null");
}
return sb.toString();
return I18NUtil.getMessage(
"system.schema_comp.diff",
getWhere(),
getLeft().getPath(),
getLeft().getPropertyValue(),
getRight().getPath(),
getRight().getPropertyValue());
}
@Override

View File

@@ -24,7 +24,9 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import org.alfresco.util.schemacomp.Difference.Where;
import org.junit.Before;
import org.junit.Test;
import org.springframework.extensions.surf.util.I18NUtil;
/**
* Tests for the {@link Difference} class.
@@ -33,9 +35,16 @@ import org.junit.Test;
*/
public class DifferenceTest
{
@Before
public void setUp()
{
I18NUtil.registerResourceBundle("alfresco.messages.system-messages");
}
@Test
public void describe()
{
DbProperty refDbProp = mock(DbProperty.class);
when(refDbProp.getPath()).thenReturn("alfresco.some_table.some_column.name");
when(refDbProp.getPropertyValue()).thenReturn("node_ref");
@@ -43,9 +52,38 @@ public class DifferenceTest
DbProperty targetDbProp = mock(DbProperty.class);
when(targetDbProp.getPath()).thenReturn("alfresco.some_table.some_column.name");
when(targetDbProp.getPropertyValue()).thenReturn("nood_ref");
Difference diff = new Difference(Where.ONLY_IN_REFERENCE, refDbProp, targetDbProp);
Difference diff = new Difference(Where.IN_BOTH_BUT_DIFFERENCE, refDbProp, targetDbProp);
assertEquals("Difference: ONLY_IN_REFERENCE reference path:alfresco.some_table.some_column.name (value: node_ref) " +
"target path:alfresco.some_table.some_column.name (value: nood_ref)", diff.describe());
assertEquals("Difference: IN_BOTH_BUT_DIFFERENCE, reference path:alfresco.some_table.some_column.name " +
"(value: node_ref), target path:alfresco.some_table.some_column.name (value: nood_ref)",
diff.describe());
}
@Test
public void describeRefOnly()
{
DbProperty refDbProp = mock(DbProperty.class);
when(refDbProp.getPath()).thenReturn("alfresco.some_table.some_column.name");
when(refDbProp.getPropertyValue()).thenReturn("node_ref");
Difference diff = new Difference(Where.ONLY_IN_REFERENCE, refDbProp, null);
assertEquals("Difference: ONLY_IN_REFERENCE, reference path:alfresco.some_table.some_column.name " +
"(value: node_ref)",
diff.describe());
}
@Test
public void describeTargetOnly()
{
DbProperty targetDbProp = mock(DbProperty.class);
when(targetDbProp.getPath()).thenReturn("alfresco.some_table.some_column.name");
when(targetDbProp.getPropertyValue()).thenReturn("node_ref");
Difference diff = new Difference(Where.ONLY_IN_TARGET, null, targetDbProp);
assertEquals("Difference: ONLY_IN_TARGET, target path:alfresco.some_table.some_column.name " +
"(value: node_ref)",
diff.describe());
}
}

View File

@@ -21,6 +21,7 @@ package org.alfresco.util.schemacomp;
import java.util.List;
import org.alfresco.util.schemacomp.model.DbObject;
import org.springframework.extensions.surf.util.I18NUtil;
/**
* If more than one DB item in the target schema matches a reference DB item
@@ -44,12 +45,37 @@ public class RedundantDbObject extends Result
@Override
public String describe()
{
StringBuffer sb = new StringBuffer();
sb.append(matches.size())
.append(" redundant items? reference: ")
.append(dbObject)
.append(", matches: ");
if (matches.size() > SHOW_MAX_MATCHES)
{
return I18NUtil.getMessage(
"system.schema_comp.redundant_obj.many_matches",
matches.size(),
dbObject,
describeMatches(),
matches.size() - SHOW_MAX_MATCHES);
}
else
{
return I18NUtil.getMessage(
"system.schema_comp.redundant_obj",
matches.size(),
dbObject,
describeMatches());
}
}
/**
* Produces a comma separated list of matching redundant database objects. For example:
* <pre>
* MyDbObject[name=match1], MyDbObject[name=match2], MyDbObject[name=match3]
* </pre>
* At most {@link #SHOW_MAX_MATCHES} will be included.
*
* @return String
*/
private String describeMatches()
{
StringBuilder sb = new StringBuilder();
for (int i = 0; i < matches.size() && i < SHOW_MAX_MATCHES; i++)
{
if (i > 0)
@@ -58,13 +84,6 @@ public class RedundantDbObject extends Result
}
sb.append(matches.get(i));
}
if (matches.size() > SHOW_MAX_MATCHES)
{
sb.append(" and ")
.append(matches.size() - SHOW_MAX_MATCHES).append(" more...");
}
return sb.toString();
}

View File

@@ -26,7 +26,9 @@ import java.util.List;
import org.alfresco.util.schemacomp.model.AbstractDbObject;
import org.alfresco.util.schemacomp.model.DbObject;
import org.junit.Before;
import org.junit.Test;
import org.springframework.extensions.surf.util.I18NUtil;
/**
* Tests for the {@link RedundantDbObject} class.
@@ -35,7 +37,12 @@ import org.junit.Test;
*/
public class RedundantDbObjectTest
{
@Before
public void setUp()
{
I18NUtil.registerResourceBundle("alfresco.messages.system-messages");
}
@Test
public void describe()
{

View File

@@ -18,6 +18,8 @@
*/
package org.alfresco.util.schemacomp;
import org.springframework.extensions.surf.util.I18NUtil;
/**
* Results of a validation operation.
*
@@ -26,17 +28,19 @@ package org.alfresco.util.schemacomp;
public class ValidationResult extends Result
{
private DbProperty dbProperty;
private String message;
public ValidationResult(DbProperty dbProperty)
public ValidationResult(DbProperty dbProperty, String message)
{
this(dbProperty, null);
this(dbProperty, null, message);
}
public ValidationResult(DbProperty dbProperty, Strength strength)
public ValidationResult(DbProperty dbProperty, Strength strength, String message)
{
super(strength);
this.dbProperty = dbProperty;
this.message = message;
}
@@ -60,15 +64,11 @@ public class ValidationResult extends Result
@Override
public String describe()
{
StringBuffer sb = new StringBuffer();
sb.append("Validation ")
.append("target path:")
.append(getDbProperty().getPath())
.append(" (value: ")
.append(getValue())
.append(")");
return sb.toString();
return I18NUtil.getMessage(
"system.schema_comp.validation",
getDbProperty().getPath(),
getValue(),
message);
}
/**

View File

@@ -23,7 +23,9 @@ import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import org.junit.Before;
import org.junit.Test;
import org.springframework.extensions.surf.util.I18NUtil;
/**
@@ -33,6 +35,12 @@ import org.junit.Test;
*/
public class ValidationResultTest
{
@Before
public void setUp()
{
I18NUtil.registerResourceBundle("alfresco.messages.system-messages");
}
@Test
public void describe()
{
@@ -40,9 +48,9 @@ public class ValidationResultTest
when(targetDbProp.getPath()).thenReturn("alfresco.some_table.some_index.name");
when(targetDbProp.getPropertyValue()).thenReturn("ibx_my_index");
ValidationResult validation = new ValidationResult(targetDbProp);
ValidationResult validation = new ValidationResult(targetDbProp, "value must be 'xyz'");
assertEquals("Validation target path:alfresco.some_table.some_index.name (value: ibx_my_index)",
assertEquals("Validation: target path:alfresco.some_table.some_index.name (value: ibx_my_index, rule: value must be 'xyz')",
validation.describe());
}
}

View File

@@ -27,6 +27,7 @@ import org.alfresco.util.schemacomp.DiffContext;
import org.alfresco.util.schemacomp.ValidationResult;
import org.alfresco.util.schemacomp.model.DbObject;
import org.hibernate.dialect.Dialect;
import org.springframework.extensions.surf.util.I18NUtil;
/**
* Validates the name of a DbObject using a regular expression. A regular expression
@@ -44,11 +45,11 @@ public class NameValidator implements DbValidator
public void validate(DbObject reference, DbObject target, DiffContext ctx)
{
String name = target.getName();
ValidationResult result = new ValidationResult(new DbProperty(target, "name"));
if (pattern != null && !pattern.matcher(name).matches())
{
String message = I18NUtil.getMessage("system.schema_comp.name_validator", pattern);
ValidationResult result = new ValidationResult(new DbProperty(target, "name"), message);
ctx.getComparisonResults().add(result);
}
}