-
Notifications
You must be signed in to change notification settings - Fork 7
Support field type conversion for Multi Choice fields #7356
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
Changes from 20 commits
a066d53
fc22b72
cbb199b
98f19f2
beefa2a
9fa7270
e717afa
4c4d519
b8a163d
5a79008
6d55319
002fe51
1837728
0674ec9
4273019
3bb0c5f
f6a4e81
d205e32
6aa0ee7
e75c688
dc1bd5d
4934b5e
2a293ed
daff069
e3d9a7c
646a3bf
4e66d33
79863e8
bd11124
4a5a3e1
901cd43
c34f952
c0b4c59
b5df9c3
51d9fd2
1e2d8ee
2030ab1
2bc2ff7
0d8a398
3c6ec8e
156969e
adc4b4a
66ad632
37cf9c4
2974700
7714466
4a95b50
48ad37a
dc315d6
8039bd0
76795c4
a24910a
fa527fa
aacb456
7a0e443
4cd42ea
c19b7af
4e71006
482f94e
195dac8
b9667d4
8d2df4c
b685f9d
6a52b48
a2c8deb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,7 @@ | |
| import org.apache.commons.collections4.iterators.ArrayIterator; | ||
| import org.junit.Assert; | ||
| import org.junit.Test; | ||
| import org.labkey.api.exp.PropertyType; | ||
| import org.labkey.api.query.FieldKey; | ||
|
|
||
| import java.util.HashMap; | ||
|
|
@@ -113,6 +114,13 @@ public Object get(Object key) | |
| if (getFieldMap() != null) | ||
| { | ||
| ColumnInfo columnInfo = getFieldMap().get(key); | ||
| if (columnInfo != null && columnInfo.getPropertyType() == PropertyType.MULTI_CHOICE && value instanceof String strVal) | ||
| { | ||
| // Multi-choice values array is converted to string: "{value1,value2,...}", so strip off the braces before converting | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are these comma separated or semi-colon separated?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This '{a, b}' format is what's returned by MVFK when casting array to string |
||
| if (strVal.startsWith("{") && strVal.endsWith("}")) | ||
| return ConvertUtils.convert(strVal.substring(1, strVal.length() - 1), columnInfo.getJavaClass()); | ||
| // TODO: return columnInfo.convert(strVal.substring(1, strVal.length() - 1)); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this TODO for later? Or can it be removed?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is to be updated after merging in the related branch that refactored ConverterUtil. |
||
| } | ||
| // The value was concatenated with others, so it's become a string. | ||
| // Do conversion to switch it back to the expected type. | ||
| if (value != null && columnInfo != null && !columnInfo.getJavaClass().isInstance(value)) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,6 +20,7 @@ | |
| import org.labkey.api.data.PropertyStorageSpec.Index; | ||
| import org.labkey.api.data.TableInfo.IndexDefinition; | ||
| import org.labkey.api.exp.PropertyDescriptor; | ||
| import org.labkey.api.exp.PropertyType; | ||
| import org.labkey.api.exp.property.Domain; | ||
| import org.labkey.api.exp.property.DomainKind; | ||
| import org.labkey.api.util.logging.LogHelper; | ||
|
|
@@ -58,6 +59,7 @@ public class TableChange | |
| private Collection<Constraint> _constraints; | ||
| private Set<String> _indicesToBeDroppedByName; | ||
| private IndexSizeMode _sizeMode = IndexSizeMode.Auto; | ||
| private Map<String, PropertyType> _oldPropTypes; | ||
|
|
||
| /** In most cases, domain knows the storage table name **/ | ||
| public TableChange(Domain domain, ChangeType changeType) | ||
|
|
@@ -329,6 +331,11 @@ public void setForeignKeys(Collection<PropertyStorageSpec.ForeignKey> foreignKey | |
| _foreignKeys = foreignKeys; | ||
| } | ||
|
|
||
| public Map<String, PropertyType> getOldPropTypes() | ||
| { | ||
| return _oldPropTypes; | ||
| } | ||
|
|
||
| public final List<PropertyStorageSpec> toSpecs(Collection<String> columnNames) | ||
| { | ||
| final Domain domain = _domain; | ||
|
|
@@ -349,6 +356,11 @@ public final List<PropertyStorageSpec> toSpecs(Collection<String> columnNames) | |
| .collect(Collectors.toList()); | ||
| } | ||
|
|
||
| public void setOldPropertyTypes(Map<String, PropertyType> oldPropTypes) | ||
| { | ||
| _oldPropTypes = oldPropTypes; | ||
| } | ||
|
Comment on lines
+359
to
+362
|
||
|
|
||
| public enum ChangeType | ||
| { | ||
| CreateTable, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like "arrays" would be the more general term (vs. "Multi Choices") since these operators could be used in other scenarios. But I see that "Multi Choices" is what we're using in all the existing CompareTypes, so I guess it's fine.