-
Notifications
You must be signed in to change notification settings - Fork 7
Issue 53498: Sample Manager: Attachment field is lost after export/import round trip #6894
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -43,6 +43,7 @@ | |
| import org.labkey.api.dataiterator.ScrollableDataIterator; | ||
| import org.labkey.api.exp.MvColumn; | ||
| import org.labkey.api.exp.MvFieldWrapper; | ||
| import org.labkey.api.exp.PropertyType; | ||
| import org.labkey.api.iterator.CloseableFilteredIterator; | ||
| import org.labkey.api.iterator.CloseableIterator; | ||
| import org.labkey.api.query.BatchValidationException; | ||
|
|
@@ -327,7 +328,7 @@ private void inferColumnInfo(@NotNull Map<String, String> renamedColumns) throws | |
| for (int f = 0; f < nCols; f++) | ||
| { | ||
| List<Class> classesToTest = new ArrayList<>(Arrays.asList(CONVERT_CLASSES)); | ||
| Class knownColumnClass = null; | ||
| Class knownColumnClass; | ||
|
|
||
| int classIndex = -1; | ||
| //NOTE: this means we have a header row | ||
|
|
@@ -337,27 +338,21 @@ private void inferColumnInfo(@NotNull Map<String, String> renamedColumns) throws | |
| { | ||
| String name = lineFields[0][f]; | ||
| name = StringUtilsLabKey.sanitizeSeparatorsAndTrim(name); | ||
| if (_columnInfoMap.containsKey(name)) | ||
| { | ||
| //preferentially use this class if it matches | ||
| knownColumnClass = _columnInfoMap.get(name).getJavaClass(); | ||
| classesToTest.add(0, knownColumnClass); | ||
| } | ||
| else if (renamedColumns.containsKey(name) && _columnInfoMap.containsKey(renamedColumns.get(name))) | ||
|
|
||
| ColumnInfo knownColumn = getKnownColumn(name, renamedColumns); | ||
|
|
||
| if (knownColumn != null) | ||
| { | ||
| knownColumnClass = _columnInfoMap.get(renamedColumns.get(name)).getJavaClass(); | ||
| knownColumnClass = knownColumn.getJavaClass(); | ||
| classesToTest.add(0, knownColumnClass); | ||
|
|
||
| // Issue 49830: if we know the column class is File based on the columnInfoMap, use it instead of trying to infer the class based on the data | ||
| if (setFileColDescriptor(colDescs[f], knownColumn)) | ||
| continue; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Issue 49830: if we know the column class is File based on the columnInfoMap, use it instead of trying to infer the class based on the data | ||
| if (File.class.equals(knownColumnClass)) | ||
| { | ||
| colDescs[f].clazz = knownColumnClass; | ||
| continue; | ||
| } | ||
|
|
||
| for (int line = inferStartLine; line < numLines; line++) | ||
| { | ||
| if (f >= lineFields[line].length) | ||
|
|
@@ -458,7 +453,8 @@ else if (renamedColumns.containsKey(name) && _columnInfoMap.containsKey(renamedC | |
| Set<String> columnNames = new HashSet<>(); | ||
| for (ColumnDescriptor colDesc : colDescs) | ||
| { | ||
| if (!columnNames.add(colDesc.name) && isThrowOnErrors()) | ||
| String name = colDesc.name; | ||
| if (!columnNames.add(name) && isThrowOnErrors()) | ||
| { | ||
| // TODO: This should be refactored to not throw this here, but rather, have the callers check themselves. It | ||
| // is not in the interest of inferring columns that we validate duplicate columns. | ||
|
|
@@ -468,11 +464,45 @@ else if (renamedColumns.containsKey(name) && _columnInfoMap.containsKey(renamedC | |
| ExceptionUtil.decorateException(e, ExceptionUtil.ExceptionInfo.SkipMothershipLogging, "true", true); | ||
| throw e; | ||
| } | ||
|
|
||
| // use File converter for known file fields even if inferTypes = false. If inferTypes, this is already done. | ||
| if (!getInferTypes()) | ||
|
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. Seems like you could leave off the if statement here for a cleaner read since setting again won't hurt, but this is slightly more efficient. |
||
| setFileColDescriptor(colDesc, getKnownColumn(name, renamedColumns)); | ||
| } | ||
|
|
||
| _columns = colDescs; | ||
| } | ||
|
|
||
| private boolean setFileColDescriptor(ColumnDescriptor colDesc, @Nullable ColumnInfo knownColumn) | ||
| { | ||
| if (knownColumn == null) | ||
| return false; | ||
|
|
||
| Class knownColumnClass = knownColumn.getJavaClass(); | ||
|
|
||
| if (File.class.equals(knownColumnClass)) | ||
| { | ||
| if (PropertyType.ATTACHMENT.equals(knownColumn.getPropertyType())) | ||
| colDesc.clazz = String.class; | ||
| else | ||
| colDesc.clazz = knownColumnClass; | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
|
|
||
| private ColumnInfo getKnownColumn(String name, @NotNull Map<String, String> renamedColumns) | ||
| { | ||
| ColumnInfo knownColumn = null; | ||
| if (_columnInfoMap.containsKey(name)) | ||
| knownColumn = _columnInfoMap.get(name); | ||
| else if (renamedColumns.containsKey(name) && _columnInfoMap.containsKey(renamedColumns.get(name))) | ||
| knownColumn = _columnInfoMap.get(renamedColumns.get(name)); | ||
| return knownColumn; | ||
| } | ||
|
|
||
| protected String getDefaultColumnName(int col) | ||
| { | ||
| return "column" + col; | ||
|
|
@@ -955,7 +985,16 @@ public DataIterator getDataIterator(final DataIteratorContext context) | |
| /** Actually create an instance of DataIterator to use, which might be subclass-specific */ | ||
| protected DataIterator createDataIterator(DataIteratorContext context) throws IOException | ||
| { | ||
| return new _DataIterator(context, getActiveColumns(), isScrollable()); | ||
| ColumnDescriptor[] columnDescriptors = getActiveColumns(); | ||
| if (context.isCrossFolderImport() || context.isCrossTypeImport()) | ||
| { | ||
| for (ColumnDescriptor columnDescriptor : columnDescriptors) | ||
| { | ||
| if (columnDescriptor.clazz.equals(File.class)) | ||
| columnDescriptor.clazz = String.class; // defer file path validation for cross type/folder import | ||
| } | ||
| } | ||
| return new _DataIterator(context, columnDescriptors, isScrollable()); | ||
| } | ||
|
|
||
| protected class _DataIterator implements ScrollableDataIterator, MapDataIterator | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 this could come before the setting of
knownColumnClass.