mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
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:
@@ -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
|
||||
|
@@ -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());
|
||||
}
|
||||
}
|
||||
|
@@ -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();
|
||||
}
|
||||
|
||||
|
@@ -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()
|
||||
{
|
||||
|
@@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -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());
|
||||
}
|
||||
}
|
||||
|
@@ -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);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user