Skip to content

Commit

Permalink
Issue 11689 save non default datatypes from legacy ui (#11690)
Browse files Browse the repository at this point in the history
* #11689 fixed

* #11689 added test cases

* #11689 made test cases more obvious
  • Loading branch information
wezell authored and jgambarios committed May 24, 2017
1 parent cec0a03 commit aca2d7f
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@
import com.dotcms.contenttype.model.field.ImmutableBinaryField;
import com.dotcms.contenttype.model.field.ImmutableDateTimeField;
import com.dotcms.contenttype.model.field.ImmutableFieldVariable;
import com.dotcms.contenttype.model.field.ImmutableSelectField;
import com.dotcms.contenttype.model.field.ImmutableTextAreaField;
import com.dotcms.contenttype.model.field.ImmutableTextField;
import com.dotcms.contenttype.model.field.SelectField;
import com.dotcms.contenttype.model.field.TextField;
import com.dotcms.contenttype.model.type.BaseContentType;
import com.dotcms.contenttype.model.type.ContentType;
Expand Down Expand Up @@ -156,6 +158,44 @@ public void testTextDBColumn() throws Exception {
assertThat("field2 text data type", field2.dataType() == DataTypes.TEXT);
assertThat("field2 text db column", field2.dbColumn().matches("text[0-9]+"));
}



@Test
public void testBadIntDBColumn() throws Exception {

String uu = UUID.randomUUID().toString();

TextField textField = ImmutableTextField.builder().name("test field" + uu)
.variable(TEST_VAR_PREFIX + uu).contentTypeId(Constants.NEWS).hint("my hint")
.dataType(DataTypes.INTEGER).dbColumn("bad1").build();

Field savedField = fieldFactory.save(textField);
String inode = savedField.inode();
Field field2 = fieldFactory.byId(inode);
assertThat("testBadIntDBColumn text data type", field2.dataType() == DataTypes.INTEGER);
assertThat("testBadIntDBColumn text db column", field2.dbColumn().matches("integer[0-9]+"));
}


@Test
public void testBadBoolDBColumn() throws Exception {

String uu = UUID.randomUUID().toString();

SelectField selectField = ImmutableSelectField.builder().name("test field" + uu)
.variable(TEST_VAR_PREFIX + uu).contentTypeId(Constants.NEWS).hint("my hint")
.dataType(DataTypes.BOOL).dbColumn("notreal").values("").build();

Field savedField = fieldFactory.save(selectField);
String inode = savedField.inode();
Field field2 = fieldFactory.byId(inode);
assertThat("testBadBoolDBColumn select data type", field2.dataType() == DataTypes.BOOL);
assertThat("testBadBoolDBColumn select db column", field2.dbColumn().matches("bool[0-9]+"));
}



@Test
public void testTextIntColumn() throws Exception {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import com.dotmarketing.business.APILocator;
import com.dotmarketing.business.CacheLocator;
import com.dotmarketing.business.DotStateException;
import com.dotmarketing.business.DotValidationException;
import com.dotmarketing.common.db.DotConnect;
import com.dotmarketing.db.LocalTransaction;
import com.dotmarketing.exception.DotDataException;
Expand Down Expand Up @@ -159,8 +160,8 @@ private Field normalizeData(final Field throwAwayField) throws DotDataException
FieldBuilder builder = FieldBuilder.builder(throwAwayField);
Field returnField = throwAwayField;

if("constant".equals(throwAwayField.dbColumn()) && !(throwAwayField instanceof ConstantField)) {
builder = ImmutableConstantField.builder().from(throwAwayField);
if("constant".equals(returnField.dbColumn()) && !(returnField instanceof ConstantField)) {
builder = ImmutableConstantField.builder().from(returnField);
builder.dbColumn(DataTypes.SYSTEM.value);
returnField = builder.build();
}
Expand All @@ -174,8 +175,13 @@ private Field normalizeData(final Field throwAwayField) throws DotDataException
builder.dbColumn(DataTypes.SYSTEM.value);
returnField = builder.build();
}
// if this is a new column assign a db column
if(returnField.dbColumn()==null){


// if this is a new column validate and assign a db column
try{
validateDbColumn(returnField);
}
catch(Throwable e){
builder.dbColumn(nextAvailableColumn(returnField));
returnField = builder.build();
}
Expand Down

0 comments on commit aca2d7f

Please sign in to comment.