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

Issue 11689 save non default datatypes from legacy ui #11690

Merged
merged 3 commits into from
May 24, 2017
Merged
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 @@ -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