Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[6.4.x] BZ1301051: Column values are deleted after changing the operator in a Guided Decision Table #658

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,14 @@ public class DTCellValue52 {
private Boolean valueBoolean;
private Date valueDate;
private Number valueNumeric;
private String valueString = "";
private DataTypes dataType = DataTypes.STRING;
private String valueString;
private DataTypes dataType;

//Does this cell represent "all other values" to those explicitly defined for the column
private boolean isOtherwise;

public DTCellValue52() {
this( "" );
}

public DTCellValue52( final DTCellValue52 sourceCell ) {
Expand Down Expand Up @@ -295,18 +296,30 @@ public DataType.DataTypes getDataType() {
}

public Boolean getBooleanValue() {
if ( !this.getDataType().equals( DataTypes.BOOLEAN ) ) {
valueBoolean = null;
}
return valueBoolean;
}

public Date getDateValue() {
if ( !this.getDataType().equals( DataTypes.DATE ) ) {
valueDate = null;
}
return valueDate;
}

public Number getNumericValue() {
if ( !isNumeric() ) {
valueNumeric = null;
}
return valueNumeric;
}

public String getStringValue() {
if ( !this.getDataType().equals( DataTypes.STRING ) ) {
valueString = null;
}
return valueString;
}

Expand Down Expand Up @@ -401,10 +414,31 @@ public boolean hasValue() {
return valueBoolean != null
|| valueDate != null
|| valueNumeric != null
|| (valueString != null && !valueString.isEmpty())
|| ( valueString != null && !valueString.isEmpty() )
|| isOtherwise;
}

private boolean isNumeric() {
if ( dataType.equals( DataTypes.NUMERIC_BIGDECIMAL ) ) {
return true;
} else if ( dataType.equals( DataTypes.NUMERIC_BIGINTEGER ) ) {
return true;
} else if ( dataType.equals( DataTypes.NUMERIC_BYTE ) ) {
return true;
} else if ( dataType.equals( DataTypes.NUMERIC_DOUBLE ) ) {
return true;
} else if ( dataType.equals( DataTypes.NUMERIC_FLOAT ) ) {
return true;
} else if ( dataType.equals( DataTypes.NUMERIC_INTEGER ) ) {
return true;
} else if ( dataType.equals( DataTypes.NUMERIC_LONG ) ) {
return true;
} else if ( dataType.equals( DataTypes.NUMERIC_SHORT ) ) {
return true;
}
return false;
}

@Override
public int hashCode() {
int hash = 0;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
/*
* Copyright 2016 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.drools.workbench.models.guided.dtable.shared.model;

import java.lang.reflect.Field;
import java.util.Calendar;
import java.util.Date;

import org.drools.workbench.models.datamodel.oracle.DataType;
import org.junit.Before;
import org.junit.Test;

import static org.junit.Assert.*;

// These tests check legacy (pre-6.4.CR1) objects that have been de-serialized can be correctly read.
// DTCellValue52.valueString was set to an empty String statically and hence when the object was de-serialized
// it was possible for instances to have both a 'valueString (=="")' and '<another>Value' for types other than
// DataTypes.DataType.TYPE_STRING. For example. valueBoolean=true, valueString="", dataType=BOOLEAN.
public class DTCellValue52Test {

private DTCellValue52 dcv;

private Field fieldBoolean;
private Field fieldDate;
private Field fieldNumeric;
private Field fieldString;
private Field fieldDataType;

private static final Date now = Calendar.getInstance().getTime();

@Before
public void setup() throws Exception {
dcv = new DTCellValue52();
final Class<?> c = dcv.getClass();
fieldBoolean = c.getDeclaredField( "valueBoolean" );
fieldDate = c.getDeclaredField( "valueDate" );
fieldNumeric = c.getDeclaredField( "valueNumeric" );
fieldString = c.getDeclaredField( "valueString" );
fieldDataType = c.getDeclaredField( "dataType" );
fieldBoolean.setAccessible( true );
fieldDate.setAccessible( true );
fieldNumeric.setAccessible( true );
fieldString.setAccessible( true );
fieldDataType.setAccessible( true );
}

@Test
public void testGetBooleanValue() throws Exception {
dcv.setBooleanValue( true );
fieldDate.set( dcv,
now );
fieldNumeric.set( dcv,
1L );
fieldString.set( dcv,
"woot" );
assertEquals( DataType.DataTypes.BOOLEAN,
dcv.getDataType() );
assertTrue( dcv.getBooleanValue() );
assertNull( dcv.getDateValue() );
assertNull( dcv.getNumericValue() );
assertNull( dcv.getStringValue() );
}

@Test
public void testGetDateValue() throws Exception {
fieldBoolean.set( dcv,
true );
dcv.setDateValue( now );
fieldNumeric.set( dcv,
1L );
fieldString.set( dcv,
"woot" );
assertEquals( DataType.DataTypes.DATE,
dcv.getDataType() );
assertNull( dcv.getBooleanValue() );
assertEquals( now,
dcv.getDateValue() );
assertNull( dcv.getNumericValue() );
assertNull( dcv.getStringValue() );
}

@Test
public void testGetNumericValue() throws Exception {
fieldBoolean.set( dcv,
true );
fieldDate.set( dcv,
now );
dcv.setNumericValue( 1L );
fieldString.set( dcv,
"woot" );
assertEquals( DataType.DataTypes.NUMERIC_LONG,
dcv.getDataType() );
assertNull( dcv.getBooleanValue() );
assertNull( dcv.getDateValue() );
assertEquals( 1L,
dcv.getNumericValue() );
assertNull( dcv.getStringValue() );
}

@Test
public void testGetStringValue() throws Exception {
fieldBoolean.set( dcv,
true );
fieldDate.set( dcv,
now );
fieldNumeric.set( dcv,
1L );
dcv.setStringValue( "woot" );
assertEquals( DataType.DataTypes.STRING,
dcv.getDataType() );
assertNull( dcv.getBooleanValue() );
assertNull( dcv.getDateValue() );
assertNull( dcv.getNumericValue() );
assertEquals( "woot",
dcv.getStringValue() );
}

}