Search in sources :

Example 11 with DbProperty

use of org.alfresco.util.schemacomp.DbProperty in project alfresco-repository by Alfresco.

the class Column method doDiff.

@Override
protected void doDiff(DbObject right, DiffContext ctx) {
    DbProperty thisTypeProp = new DbProperty(this, "type");
    DbProperty thisNullableProp = new DbProperty(this, "nullable");
    DbProperty thisOrderProp = new DbProperty(this, "order");
    DbProperty thisAutoIncProp = new DbProperty(this, "autoIncrement");
    Column thatColumn = (Column) right;
    DbProperty thatTypeProp = new DbProperty(thatColumn, "type");
    DbProperty thatNullableProp = new DbProperty(thatColumn, "nullable");
    DbProperty thatOrderProp = new DbProperty(thatColumn, "order");
    DbProperty thatAutoIncProp = new DbProperty(thatColumn, "autoIncrement");
    comparisonUtils.compareSimple(thisTypeProp, thatTypeProp, ctx);
    comparisonUtils.compareSimple(thisNullableProp, thatNullableProp, ctx);
    if (compareOrder) {
        comparisonUtils.compareSimple(thisOrderProp, thatOrderProp, ctx);
    }
    comparisonUtils.compareSimple(thisAutoIncProp, thatAutoIncProp, ctx);
}
Also used : DbProperty(org.alfresco.util.schemacomp.DbProperty)

Example 12 with DbProperty

use of org.alfresco.util.schemacomp.DbProperty 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.");
        }
    }
}
Also used : AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) Index(org.alfresco.util.schemacomp.model.Index) ValidationResult(org.alfresco.util.schemacomp.ValidationResult) DbProperty(org.alfresco.util.schemacomp.DbProperty)

Example 13 with DbProperty

use of org.alfresco.util.schemacomp.DbProperty 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);
    }
}
Also used : Column(org.alfresco.util.schemacomp.model.Column) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) ValidationResult(org.alfresco.util.schemacomp.ValidationResult) DbProperty(org.alfresco.util.schemacomp.DbProperty)

Example 14 with DbProperty

use of org.alfresco.util.schemacomp.DbProperty 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));
    }
}
Also used : Schema(org.alfresco.util.schemacomp.model.Schema) ValidationResult(org.alfresco.util.schemacomp.ValidationResult) DbProperty(org.alfresco.util.schemacomp.DbProperty)

Example 15 with DbProperty

use of org.alfresco.util.schemacomp.DbProperty in project alfresco-repository by Alfresco.

the class AbstractDbObjectTest method diff.

@Test
public void diff() {
    ConcreteDbObject otherObject = new ConcreteDbObject("the_other_object");
    dbObject.diff(otherObject, ctx);
    InOrder inOrder = inOrder(differences);
    // The name of the object should be diffed
    inOrder.verify(differences).add(Where.IN_BOTH_BUT_DIFFERENCE, new DbProperty(dbObject, "name"), new DbProperty(otherObject, "name"));
    // Then the doDiff() method should be processed
    inOrder.verify(differences).add(Where.IN_BOTH_BUT_DIFFERENCE, new DbProperty(dbObject, "someProp"), new DbProperty(otherObject, "someProp"));
}
Also used : InOrder(org.mockito.InOrder) DbProperty(org.alfresco.util.schemacomp.DbProperty) Test(org.junit.Test)

Aggregations

DbProperty (org.alfresco.util.schemacomp.DbProperty)17 ValidationResult (org.alfresco.util.schemacomp.ValidationResult)4 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)2 Test (org.junit.Test)2 Column (org.alfresco.util.schemacomp.model.Column)1 Index (org.alfresco.util.schemacomp.model.Index)1 Schema (org.alfresco.util.schemacomp.model.Schema)1 InOrder (org.mockito.InOrder)1