Auto-add extension to files without them when not zipping them up for upload. Added...
authormccreedy@NIH.GOV <mccreedy@NIH.GOV@ba61647d-9d00-f842-95cd-605cb4296b96>
Wed, 7 Mar 2018 21:57:14 +0000 (21:57 +0000)
committermccreedy@NIH.GOV <mccreedy@NIH.GOV@ba61647d-9d00-f842-95cd-605cb4296b96>
Wed, 7 Mar 2018 21:57:14 +0000 (21:57 +0000)
git-svn-id: https://citdcbmipav.cit.nih.gov/repos-pub/mipav/trunk@15404 ba61647d-9d00-f842-95cd-605cb4296b96

mipav/src/plugins/PlugInDialogFITBIR.java

index a0bf45c..2ded15b 100644 (file)
@@ -42,6 +42,7 @@ import javax.swing.filechooser.FileNameExtensionFilter;
 import javax.swing.table.*;\r
 \r
 import org.apache.commons.io.FileUtils;\r
+import org.apache.commons.io.FilenameUtils;\r
 import org.apache.commons.lang3.text.WordUtils;\r
 import org.apache.cxf.jaxrs.client.WebClient;\r
 import org.apache.cxf.transport.http.HTTPConduit;\r
@@ -2158,19 +2159,9 @@ public class PlugInDialogFITBIR extends JFrame implements ActionListener, Change
             } else if (fileFormatString[i].equalsIgnoreCase("mat")) {\r
                 fileFormatString[i] = "matlab";\r
             }\r
-\r
-            // if no modality, try to guess from structure being used\r
-            if (modality[i] == FileInfoBase.UNKNOWN_MODALITY) {\r
-                upperStructureName[i] = dataStructureName.toUpperCase();\r
-                if (upperStructureName[i].endsWith("IMAGINGMR")) {\r
-                    modality[i] = FileInfoBase.MAGNETIC_RESONANCE;\r
-                } else if (upperStructureName[i].endsWith("IMAGINGCT")) {\r
-                    modality[i] = FileInfoBase.COMPUTED_TOMOGRAPHY;\r
-                } else if (upperStructureName[i].endsWith("IMAGINGDIFFUSION")) {\r
-                    modality[i] = FileInfoBase.MAGNETIC_RESONANCE;\r
-                }\r
-                modalityString[i] = FileInfoBase.getModalityStr(modality[i]);\r
-            }\r
+            \r
+            modality[i] = determineModality(modality[i], dataStructureName);\r
+            modalityString[i] = FileInfoBase.getModalityStr(modality[i]);\r
 \r
             sliceThickness[i] = img[i].getFileInfo(0).getSliceThickness();\r
             orient[i] = img[i].getFileInfo(0).getImageOrientation();\r
@@ -3769,7 +3760,21 @@ public class PlugInDialogFITBIR extends JFrame implements ActionListener, Change
                     // the image is just one file, so don't zip. copy to output dir\r
                     try {\r
                         final File srcFile = new File(imgFileInfo.getOrigFiles().get(0));\r
-                        final File destFile = new File(outputSubDir + outputFileNameBase + "_" + srcFile.getName());\r
+                        File destFile;\r
+                        \r
+                        // make sure the single file we're copying over has an extension.  \r
+                        // a bug in the validation tool requires that 'Triplanar' type data elements have an extension\r
+                        if (FilenameUtils.getExtension(srcFile.getName()).equals("")) {\r
+                            String ext = FileTypeTable.getFileTypeInfo(imgFileInfo.getFileFormat()).getDefaultExtension();\r
+                            if (ext == null || ext.equals("")) {\r
+                                ext = ".ima";\r
+                            }\r
+                            \r
+                            destFile = new File(outputSubDir + outputFileNameBase + "_" + srcFile.getName() + ext);\r
+                        } else {\r
+                            destFile = new File(outputSubDir + outputFileNameBase + "_" + srcFile.getName());\r
+                        }\r
+                        \r
                         printlnToLog("Copying original image file into output directory:\t" + destFile.getAbsolutePath());\r
                         FileUtils.copyFile(srcFile, destFile);\r
                         imagePath = destFile.getAbsolutePath();\r
@@ -5023,6 +5028,35 @@ public class PlugInDialogFITBIR extends JFrame implements ActionListener, Change
 \r
         return "";\r
     }\r
+    \r
+    private static final int determineModality(int curModality, String structName) {\r
+        int newModality = curModality;\r
+        \r
+        final String upperStructureName = structName.toUpperCase();\r
+        \r
+        // if no modality, try to guess from structure being used\r
+        if (curModality == FileInfoBase.UNKNOWN_MODALITY) {\r
+            \r
+            if (upperStructureName.endsWith("IMAGINGMR")) {\r
+                newModality = FileInfoBase.MAGNETIC_RESONANCE;\r
+            } else if (upperStructureName.endsWith("IMAGINGCT")) {\r
+                newModality = FileInfoBase.COMPUTED_TOMOGRAPHY;\r
+            } else if (upperStructureName.endsWith("IMAGINGDIFFUSION")) {\r
+                newModality = FileInfoBase.MAGNETIC_RESONANCE;\r
+            } else if (upperStructureName.endsWith("IMAGINGFUNCTIONALMR")) {\r
+                newModality = FileInfoBase.MAGNETIC_RESONANCE;\r
+            } else if (upperStructureName.endsWith("IMAGINGPET")) {\r
+                newModality = FileInfoBase.POSITRON_EMISSION_TOMOGRAPHY;\r
+            } else if (upperStructureName.endsWith("IMAGINGSPECT")) {\r
+                newModality = FileInfoBase.SINGLE_PHOTON_EMISSION_COMPUTED_TOMOGRAPHY;\r
+            }\r
+        } else if (curModality == FileInfoBase.NUCLEAR_MEDICINE && upperStructureName.endsWith("IMAGINGSPECT")) {\r
+            // some PDBP/LBP SPECT data reports as the dicom modality "nuclear medicine"\r
+            newModality = FileInfoBase.SINGLE_PHOTON_EMISSION_COMPUTED_TOMOGRAPHY;\r
+        }\r
+        \r
+        return newModality;\r
+    }\r
 \r
     /**\r
      * Converts a magnetic field strength number to the format used by BRICS (for example 3.0T or 1.5T).\r
@@ -6684,13 +6718,13 @@ public class PlugInDialogFITBIR extends JFrame implements ActionListener, Change
                     previewImages.set(selectedRow, previewImg);\r
                     previewImages.get(selectedRow).setSliceBrightness(previewImgBrightness, previewImgContrast);\r
                     structRowImgFileInfoList.set(selectedRow, new ImgFileInfo(origSrcFile.getAbsolutePath(), isMultifile,\r
-                            FileUtility.getFileNameList(srcImage), createThumbnailDataForWriting(thumbnailImage)));\r
+                            FileUtility.getFileNameList(srcImage), srcImage.getFileInfo(0).getFileFormat(), createThumbnailDataForWriting(thumbnailImage)));\r
                 } else {\r
                     final int size = previewImages.size();\r
                     previewImages.set(size - 1, previewImg);\r
                     previewImages.get(size - 1).setSliceBrightness(previewImgBrightness, previewImgContrast);\r
                     structRowImgFileInfoList.set(size - 1, new ImgFileInfo(origSrcFile.getAbsolutePath(), isMultifile, FileUtility.getFileNameList(srcImage),\r
-                            createThumbnailDataForWriting(thumbnailImage)));\r
+                            srcImage.getFileInfo(0).getFileFormat(), createThumbnailDataForWriting(thumbnailImage)));\r
                 }\r
 \r
                 // cleanup thumbnail modelimage\r
@@ -7204,19 +7238,9 @@ public class PlugInDialogFITBIR extends JFrame implements ActionListener, Change
 \r
             final int fileFormatInt = img.getFileInfo(0).getFileFormat();\r
             final String fileFormatString = FileUtility.getFileTypeStr(fileFormatInt);\r
-\r
-            // if no modality, try to guess from structure being used\r
-            if (modality == FileInfoBase.UNKNOWN_MODALITY) {\r
-                final String upperStructureName = dataStructureName.toUpperCase();\r
-                if (upperStructureName.endsWith("IMAGINGMR")) {\r
-                    modality = FileInfoBase.MAGNETIC_RESONANCE;\r
-                } else if (upperStructureName.endsWith("IMAGINGCT")) {\r
-                    modality = FileInfoBase.COMPUTED_TOMOGRAPHY;\r
-                } else if (upperStructureName.endsWith("IMAGINGDIFFUSION")) {\r
-                    modality = FileInfoBase.MAGNETIC_RESONANCE;\r
-                }\r
-                modalityString = FileInfoBase.getModalityStr(modality);\r
-            }\r
+            \r
+            modality = determineModality(modality, dataStructureName);\r
+            modalityString = FileInfoBase.getModalityStr(modality);\r
 \r
             final ArrayList<String> csvFList = new ArrayList<String>();\r
             final ArrayList<String> csvPList = new ArrayList<String>();\r
@@ -7822,19 +7846,9 @@ public class PlugInDialogFITBIR extends JFrame implements ActionListener, Change
             } else if (fileFormatString.equalsIgnoreCase("mat")) {\r
                 fileFormatString = "matlab";\r
             }\r
-\r
-            // if no modality, try to guess from structure being used\r
-            if (modality == FileInfoBase.UNKNOWN_MODALITY) {\r
-                final String upperStructureName = dataStructureName.toUpperCase();\r
-                if (upperStructureName.endsWith("IMAGINGMR")) {\r
-                    modality = FileInfoBase.MAGNETIC_RESONANCE;\r
-                } else if (upperStructureName.endsWith("IMAGINGCT")) {\r
-                    modality = FileInfoBase.COMPUTED_TOMOGRAPHY;\r
-                } else if (upperStructureName.endsWith("IMAGINGDIFFUSION")) {\r
-                    modality = FileInfoBase.MAGNETIC_RESONANCE;\r
-                }\r
-                modalityString = FileInfoBase.getModalityStr(modality);\r
-            }\r
+            \r
+            modality = determineModality(modality, dataStructureName);\r
+            modalityString = FileInfoBase.getModalityStr(modality);\r
 \r
             final float sliceThickness = img.getFileInfo(0).getSliceThickness();\r
             final int orient = img.getFileInfo(0).getImageOrientation();\r
@@ -8246,17 +8260,16 @@ public class PlugInDialogFITBIR extends JFrame implements ActionListener, Change
                     final JFileChooser chooser = fileChooser.getFileChooser();\r
                     chooser.setCurrentDirectory(new File(ViewUserInterface.getReference().getDefaultDirectory()));\r
 \r
-                    // default to TECH filter\r
-                    int filter = ViewImageFileFilter.TECH;\r
-\r
-                    try {\r
-                        filter = Integer.parseInt(Preferences.getProperty(Preferences.PREF_FILENAME_FILTER));\r
-                    } catch (final NumberFormatException nfe) {\r
-\r
-                        // an invalid value was set in preferences -- so don't\r
-                        // use it!\r
-                        filter = -1;\r
-                    }\r
+                    int filter = ViewImageFileFilter.ALL;\r
+                    \r
+//                    try {\r
+//                        filter = Integer.parseInt(Preferences.getProperty(Preferences.PREF_FILENAME_FILTER));\r
+//                    } catch (final NumberFormatException nfe) {\r
+//\r
+//                        // an invalid value was set in preferences -- so don't\r
+//                        // use it!\r
+//                        filter = -1;\r
+//                    }\r
 \r
                     chooser.addChoosableFileFilter(new ViewImageFileFilter(ViewImageFileFilter.GEN));\r
                     chooser.addChoosableFileFilter(new ViewImageFileFilter(ViewImageFileFilter.TECH));\r
@@ -8326,7 +8339,7 @@ public class PlugInDialogFITBIR extends JFrame implements ActionListener, Change
                                 previewImages.get(selectedRow).setSliceBrightness(previewImgBrightness, previewImgContrast);\r
 \r
                                 ImgFileInfo imgInfo = new ImgFileInfo(file.getAbsolutePath(), isMultiFile, FileUtility.getFileNameList(srcImage),\r
-                                        createThumbnailDataForWriting(thumbnailImage));\r
+                                        srcImage.getFileInfo(0).getFileFormat(), createThumbnailDataForWriting(thumbnailImage));\r
 \r
                                 structRowImgFileInfoList.set(selectedRow, imgInfo);\r
                             } else {\r
@@ -8335,7 +8348,7 @@ public class PlugInDialogFITBIR extends JFrame implements ActionListener, Change
                                 previewImages.get(size - 1).setSliceBrightness(previewImgBrightness, previewImgContrast);\r
 \r
                                 ImgFileInfo imgInfo = new ImgFileInfo(file.getAbsolutePath(), isMultiFile, FileUtility.getFileNameList(srcImage),\r
-                                        createThumbnailDataForWriting(thumbnailImage));\r
+                                        srcImage.getFileInfo(0).getFileFormat(), createThumbnailDataForWriting(thumbnailImage));\r
 \r
                                 structRowImgFileInfoList.set(size - 1, imgInfo);\r
                             }\r
@@ -9405,19 +9418,22 @@ public class PlugInDialogFITBIR extends JFrame implements ActionListener, Change
         public boolean isMultifile;\r
 \r
         public String imgFilePath;\r
+        \r
+        public int fileFormat;\r
 \r
-        public ImgFileInfo(final String imgFilePath, final boolean isMultifile) {\r
+/*        public ImgFileInfo(final String imgFilePath, final boolean isMultifile) {\r
             super();\r
             this.isMultifile = isMultifile;\r
             this.imgFilePath = imgFilePath;\r
-        }\r
+        }*/\r
 \r
-        public ImgFileInfo(final String imgFilePath, final boolean isMultifile, final List<String> origFiles, final MemoryImageSource thumbnailImgData) {\r
+        public ImgFileInfo(final String imgFilePath, final boolean isMultifile, final List<String> origFiles, final int format, final MemoryImageSource thumbnailImgData) {\r
             super();\r
             this.origFiles = origFiles;\r
             this.thumbnailImgData = thumbnailImgData;\r
             this.isMultifile = isMultifile;\r
             this.imgFilePath = imgFilePath;\r
+            this.fileFormat = format;\r
         }\r
 \r
         public List<String> getOrigFiles() {\r
@@ -9451,5 +9467,17 @@ public class PlugInDialogFITBIR extends JFrame implements ActionListener, Change
         public void setImgFilePath(final String imgFilePath) {\r
             this.imgFilePath = imgFilePath;\r
         }\r
+        \r
+        public int getFileFormat() {\r
+            return fileFormat;\r
+        }\r
+        \r
+        public void setFileFormat(final int format) {\r
+            fileFormat = format;\r
+        }\r
+        \r
+        public String getFileFormatString() {\r
+            return FileUtility.getFileTypeStr(fileFormat);\r
+        }\r
     }\r
 }\r