use of org.alfresco.util.schemacomp.ValidationResult in project alfresco-repository by Alfresco.
the class NameValidator method validate.
@Override
public void validate(DbObject reference, DbObject target, DiffContext ctx) {
String name = target.getName();
if (log.isDebugEnabled()) {
log.debug("Validating: pattern: [" + pattern + "], reference: " + reference + ", target: " + target);
}
if (pattern != null && !pattern.matcher(name).matches()) {
if (log.isDebugEnabled()) {
log.debug("Pattern [" + pattern + "] not matched.");
}
String message = I18NUtil.getMessage("system.schema_comp.name_validator", pattern);
ValidationResult result = new ValidationResult(new DbProperty(target, "name"), message);
ctx.getComparisonResults().add(result);
} else {
if (log.isDebugEnabled()) {
log.debug("Pattern [" + pattern + "] matched OK.");
}
}
}
use of org.alfresco.util.schemacomp.ValidationResult in project alfresco-repository by Alfresco.
the class IndexColumnsValidator method validate.
@Override
public void validate(DbObject reference, DbObject target, DiffContext ctx) {
if (!(target instanceof Index)) {
throw new AlfrescoRuntimeException("IndexColumnsValidator could be used only in context of index object but was: " + target.toString());
}
List<String> referenceColumnNames = ((Index) reference).getColumnNames();
List<String> targetColumnNames = ((Index) target).getColumnNames();
for (int i = 0; i < targetColumnNames.size(); i++) {
String columnName = targetColumnNames.get(i);
if (getPattern() != null && !getPattern().matcher(columnName).matches()) {
if (log.isDebugEnabled()) {
log.debug("Pattern [" + getPattern() + "] not matched.");
}
String message = I18NUtil.getMessage("system.schema_comp.name_validator", getPattern());
ValidationResult result = new ValidationResult(new DbProperty(target, "columnNames", i), message);
ctx.getComparisonResults().add(result);
} else {
if (log.isDebugEnabled()) {
log.debug("Pattern [" + getPattern() + "] matched OK.");
}
}
}
if (targetColumnNames.size() != referenceColumnNames.size()) {
if (log.isDebugEnabled()) {
log.debug("Number of columns in index " + target.getName() + "doesn't match expected result");
}
String message = I18NUtil.getMessage("system.schema_comp.index_columns_validator", targetColumnNames.size(), referenceColumnNames.size());
ValidationResult result = new ValidationResult(new DbProperty(target, "columnNames"), message);
ctx.getComparisonResults().add(result);
} else {
if (log.isDebugEnabled()) {
log.debug("Number of columns is equivalent.");
}
}
}
use of org.alfresco.util.schemacomp.ValidationResult in project alfresco-repository by Alfresco.
the class TypeNameOnlyValidator method validate.
@Override
public void validate(DbObject reference, DbObject target, DiffContext ctx) {
if (!(target instanceof Column)) {
throw new AlfrescoRuntimeException("TypeNameOnlyValidator could be used only in context of column object but was: " + target.toString());
}
String referenceTypeName = ((Column) reference).getType();
String targetTypeName = ((Column) target).getType();
if (referenceTypeName.contains(TYPE_SIZE_SPLITTER)) {
referenceTypeName = referenceTypeName.substring(0, referenceTypeName.indexOf(TYPE_SIZE_SPLITTER));
}
if (targetTypeName.contains(TYPE_SIZE_SPLITTER)) {
targetTypeName = targetTypeName.substring(0, targetTypeName.indexOf(TYPE_SIZE_SPLITTER));
}
if (!referenceTypeName.equals(targetTypeName)) {
String message = I18NUtil.getMessage("system.schema_comp.column_names_validator", targetTypeName, referenceTypeName);
ValidationResult result = new ValidationResult(new DbProperty(target, "type"), message);
ctx.getComparisonResults().add(result);
}
}
use of org.alfresco.util.schemacomp.ValidationResult in project alfresco-repository by Alfresco.
the class SchemaVersionValidator method validate.
@Override
public void validate(DbObject referenceObj, DbObject targetObj, DiffContext ctx) {
Schema reference = (Schema) referenceObj;
Schema target = (Schema) targetObj;
if (target.getVersion() < reference.getVersion()) {
DbProperty targetProperty = new DbProperty(target, "version");
String message = I18NUtil.getMessage("system.schema_comp.schema_version_validator", reference.getVersion());
ctx.getComparisonResults().add(new ValidationResult(targetProperty, message));
}
}
use of org.alfresco.util.schemacomp.ValidationResult in project alfresco-repository by Alfresco.
the class SchemaVersionValidatorTest method validateWhenTargetVersionPredatesReference.
@Test
public void validateWhenTargetVersionPredatesReference() {
reference = schemaWithVersion(501);
target = schemaWithVersion(500);
validator.validate(reference, target, ctx);
assertEquals(1, results.size());
ValidationResult result = (ValidationResult) results.get(0);
assertEquals(500, result.getValue());
assertEquals("version", result.getDbProperty().getPropertyName());
assertSame(target, result.getDbProperty().getDbObject());
}
Aggregations