Skip to content

Commit

Permalink
BZ996944 - GDT Audit log: missing information in column update logs
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Anstis committed Jun 17, 2014
1 parent 31dae21 commit e945673
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 37 deletions.
Expand Up @@ -19,17 +19,20 @@
import java.util.Map;

public class BaseColumnFieldDiffImpl implements BaseColumnFieldDiff {

private String fieldName;
private Object oldValue;
private Object newValue;

/**
* Default no-arg constructor for errai marshalling.
* */
*/
public BaseColumnFieldDiffImpl() {
}

public BaseColumnFieldDiffImpl(String fieldName, Object oldValue, Object newValue) {
public BaseColumnFieldDiffImpl( String fieldName,
Object oldValue,
Object newValue ) {
this.fieldName = fieldName;
this.oldValue = oldValue;
this.newValue = newValue;
Expand All @@ -39,54 +42,62 @@ public String getFieldName() {
return fieldName;
}

public void setFieldName(String fieldName) {
public void setFieldName( String fieldName ) {
this.fieldName = fieldName;
}

public Object getOldValue() {
return oldValue;
}

public void setOldValue(Object oldValue) {
public void setOldValue( Object oldValue ) {
this.oldValue = oldValue;
}

public Object getValue() {
return newValue;
}

public void setValue(Object newValue) {
public void setValue( Object newValue ) {
this.newValue = newValue;
}

public static boolean hasChanged(String fieldName, List<BaseColumnFieldDiff> source) {
if (fieldName == null) return false;
if (source != null && !source.isEmpty()) {
for (BaseColumnFieldDiff diffCol : source) {
if (fieldName.equals(diffCol.getFieldName())) return true;
public static boolean hasChanged( String fieldName,
List<BaseColumnFieldDiff> source ) {
if ( fieldName == null ) {
return false;
}
if ( source != null && !source.isEmpty() ) {
for ( BaseColumnFieldDiff diffCol : source ) {
if ( fieldName.equals( diffCol.getFieldName() ) ) {
return true;
}
}
}
return false;
}

public static BaseColumnFieldDiff getDiff(String fieldName, List<BaseColumnFieldDiff> source) {
if (fieldName == null) return null;
if (source != null && !source.isEmpty()) {
for (BaseColumnFieldDiff diffCol : source) {
if (fieldName.equals(diffCol.getFieldName())) return diffCol;
public static BaseColumnFieldDiff getDiff( String fieldName,
List<BaseColumnFieldDiff> source ) {
if ( fieldName == null ) {
return null;
}
if ( source != null && !source.isEmpty() ) {
for ( BaseColumnFieldDiff diffCol : source ) {
if ( fieldName.equals( diffCol.getFieldName() ) ) {
return diffCol;
}
}
}
return null;
}

/**
* Check whether two Objects are equal or both null.
*
* @param s1 The object.
* @param s2 The other object.
* @return Whether two Objects are equal or both null
*/

public static boolean isEqualOrNull( Object s1,
Object s2 ) {
if ( s1 == null
Expand All @@ -100,14 +111,47 @@ public static boolean isEqualOrNull( Object s1,
return false;
}

/**
* Check whether two Objects are equal or both null.
* @param dcv1 The DTCellValue52.
* @param dcv2 The other DTCellValue52.
* @return Whether two DTCellValue52s are equal or both null
*/
public static boolean isEqualOrNull( final DTCellValue52 dcv1,
final DTCellValue52 dcv2 ) {
if ( dcv1 == null && dcv2 == null ) {
return true;
} else if ( !dcv1.getDataType().equals( dcv2.getDataType() ) ) {
return false;
} else {
//Both DataTypes are equal here, so just check one DCV's type
switch ( dcv1.getDataType() ) {
case BOOLEAN:
return dcv1.getBooleanValue().equals( dcv2.getBooleanValue() );
case DATE:
return dcv1.getDateValue().equals( dcv2.getDateValue() );
case NUMERIC:
case NUMERIC_BIGDECIMAL:
case NUMERIC_BIGINTEGER:
case NUMERIC_BYTE:
case NUMERIC_DOUBLE:
case NUMERIC_FLOAT:
case NUMERIC_INTEGER:
case NUMERIC_LONG:
case NUMERIC_SHORT:
return dcv1.getNumericValue().equals( dcv2.getNumericValue() );
default:
return dcv1.getStringValue().equals( dcv2.getStringValue() );
}
}
}

/**
* Check whether two List are same size or both null.
*
* @param s1 The fist list..
* @param s2 The other list.
* @return Whether two List are same size or both null
*/

public static boolean isEqualOrNull( List s1,
List s2 ) {
if ( s1 == null
Expand All @@ -123,7 +167,6 @@ public static boolean isEqualOrNull( List s1,

/**
* Check whether two Map are same size or both null.
*
* @param s1 The fist Map..
* @param s2 The other Map.
* @return Whether two Map are same size or both null
Expand Down
Expand Up @@ -19,7 +19,8 @@
import java.util.List;

public class DTColumnConfig52
implements BaseColumn, DiffColumn {
implements BaseColumn,
DiffColumn {

private static final long serialVersionUID = 510l;

Expand All @@ -34,7 +35,6 @@ public class DTColumnConfig52

public static final String FIELD_HEADER = "header";


// Legacy Default Values were String however since 5.4 they are stored in a DTCellValue52 object
public String defaultValue;

Expand All @@ -56,7 +56,9 @@ public DTCellValue52 getDefaultValue() {

public String getDefaultValueAsString() {
String result = "";
if (typedDefaultValue != null) result = typedDefaultValue.getValueAsString();
if ( typedDefaultValue != null ) {
result = typedDefaultValue.getValueAsString();
}
return result;
}

Expand All @@ -73,43 +75,72 @@ public void setDefaultValue( DTCellValue52 defaultValue ) {
}

@Override
public List<BaseColumnFieldDiff> diff(BaseColumn otherColumn) {
if (otherColumn == null) return null;
public List<BaseColumnFieldDiff> diff( BaseColumn otherColumn ) {
if ( otherColumn == null ) {
return null;
}

List<BaseColumnFieldDiff> result = new ArrayList<BaseColumnFieldDiff>();
DTColumnConfig52 other = (DTColumnConfig52) otherColumn;

// Field: hide column.
if ( this.isHideColumn() != other.isHideColumn() ) {
result.add(new BaseColumnFieldDiffImpl(FIELD_HIDE_COLUMN, this.isHideColumn(), other.isHideColumn()));
result.add( new BaseColumnFieldDiffImpl( FIELD_HIDE_COLUMN,
this.isHideColumn(),
other.isHideColumn() ) );
}

// Field: default value.
// NOTE: Compare using getDefaultValueAsString because then if data types differs it will appear as changed field.
// And data type can be changed due to legacy implementations (see ConditionPopup#makeDefaultValueWidget)
if ( !isEqualOrNull( this.getDefaultValueAsString(),
other.getDefaultValueAsString() ) ) {
result.add(new BaseColumnFieldDiffImpl(FIELD_DEFAULT_VALUE, this.getDefaultValueAsString(), other.getDefaultValueAsString()));
if ( !BaseColumnFieldDiffImpl.isEqualOrNull( this.getDefaultValue(),
other.getDefaultValue() ) ) {
result.add( new BaseColumnFieldDiffImpl( FIELD_DEFAULT_VALUE,
extractDefaultValue( this.getDefaultValue() ),
extractDefaultValue( other.getDefaultValue() ) ) );
}

// Field: width.
if ( this.getWidth() != other.getWidth() ) {
result.add(new BaseColumnFieldDiffImpl(FIELD_WIDTH, this.getWidth(), other.getWidth()));
result.add( new BaseColumnFieldDiffImpl( FIELD_WIDTH,
this.getWidth(),
other.getWidth() ) );
}

// Field: header.
if ( !isEqualOrNull( this.getHeader(),
other.getHeader() ) ) {
result.add(new BaseColumnFieldDiffImpl(FIELD_HEADER, this.getHeader(), other.getHeader()));
other.getHeader() ) ) {
result.add( new BaseColumnFieldDiffImpl( FIELD_HEADER,
this.getHeader(),
other.getHeader() ) );
}

return result;
}

private Object extractDefaultValue( final DTCellValue52 dcv ) {
switch ( dcv.getDataType() ) {
case BOOLEAN:
return dcv.getBooleanValue();
case DATE:
return dcv.getDateValue();
case NUMERIC:
case NUMERIC_BIGDECIMAL:
case NUMERIC_BIGINTEGER:
case NUMERIC_BYTE:
case NUMERIC_DOUBLE:
case NUMERIC_FLOAT:
case NUMERIC_INTEGER:
case NUMERIC_LONG:
case NUMERIC_SHORT:
return dcv.getNumericValue();
default:
return dcv.getStringValue();
}
}

// Check whether two Objects are equal or both null
public static boolean isEqualOrNull( Object s1,
Object s2 ) {
return BaseColumnFieldDiffImpl.isEqualOrNull(s1, s2);
public static boolean isEqualOrNull( final Object s1,
final Object s2 ) {
return BaseColumnFieldDiffImpl.isEqualOrNull( s1, s2 );
}

public void setHideColumn( boolean hideColumn ) {
Expand Down

0 comments on commit e945673

Please sign in to comment.