Changeset 5140


Ignore:
Timestamp:
Nov 22, 2018, 10:45:03 AM (5 months ago)
Author:
Nicklas Nordborg
Message:

References #1081: The release exporter should export more data

Added option to exclude histology images. This would be useful when testing.

Location:
extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/plugins/release
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/plugins/release/ReleaseExporterPlugin.java

    r5117 r5140  
    109109     
    110110      ReleaseWriterOptions options = new ReleaseWriterOptions(list);
     111      options.setSkipHistologyImages(Boolean.TRUE.equals(job.getValue("skipHistologyImages")));
    111112
    112113      if ("Remote".equals(releaseType))
     
    281282        storeValue(job, request, ri.getParameter("saveTo"));
    282283        storeValue(job, request, ri.getParameter("overwrite"));
     284       
     285        // Export options
     286        storeValue(job, request, ri.getParameter("skipHistologyImages"));
    283287
    284288        response.setSuggestedJobName("Local release export for '" + list.getName() + "'");
     
    350354        storeValue(job, request, ri.getParameter("releaseVersion"));
    351355        storeValue(job, request, ri.getParameter("overwrite"));
     356       
     357        // Export options
     358        storeValue(job, request, ri.getParameter("skipHistologyImages"));
    352359        job.getJob().setDescription("Specify release version '" + releaseVersion + "' when importing on the remote server.");
    353360
     
    444451
    445452      parameters.add(new PluginParameter<String>(
     453        "saveToSection", "Save to", "Options affecting where the export is saved.", null
     454        ));
     455
     456      parameters.add(new PluginParameter<String>(
    446457        "saveTo", "Save to", "Select the location where files should be saved",
    447458        new PathParameterType(Path.Type.DIRECTORY, null, true)
     
    452463        new BooleanParameterType(null, false)
    453464      ));
     465     
     466      addExportOptionsParameters(parameters, false);
    454467
    455468      configureExportLocal = new RequestInformation
     
    474487      {
    475488        dc = sc.newDbControl();
     489       
     490        parameters.add(new PluginParameter<String>(
     491          "saveToSection", "Save to", "Options affecting where the export is saved.", null
     492          ));
    476493       
    477494        ItemQuery<FileServer> query = FileServer.getQuery();
     
    502519          new BooleanParameterType(null, false)
    503520        ));
     521       
     522        addExportOptionsParameters(parameters, true);
    504523             
    505524      }
     
    519538    return configureExportRemote;
    520539  }
     540 
     541  private void addExportOptionsParameters(List<PluginParameter<?>> parameters, boolean remote)
     542  {
     543    parameters.add(new PluginParameter<String>(
     544      "optionsSection", "Export options", "Options affecting what to export.", null
     545      ));
     546   
     547    parameters.add(new PluginParameter<Boolean>(
     548      "skipHistologyImages", "Skip histology images", "If this option is enabled histology images are not exported. "
     549          + "This will save time during testing.",
     550      new BooleanParameterType(remote ? null : true, false)
     551      ));
     552   
     553  }
    521554
    522555}
  • extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/plugins/release/ReleaseWriterOptions.java

    r5089 r5140  
    1515  private String version;
    1616  private boolean exportFileSyncScripts;
     17  private boolean skipHistologyImages;
    1718 
    1819  public ReleaseWriterOptions(ItemList list)
     
    6465  }
    6566 
     67  /**
     68    Do not copy histology images if this option is enabled.
     69    @since 4.21
     70  */
     71  public boolean skipHistologyImages()
     72  {
     73    return skipHistologyImages;
     74  }
    6675
     76  /**
     77    @since 4.21
     78  */
     79  public void setSkipHistologyImages(boolean skip)
     80  {
     81    this.skipHistologyImages = skip;
     82  }
    6783}
  • extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/plugins/release/SpecimenWriter.java

    r5117 r5140  
    6161    if (specimens.size() == 0) return null;
    6262    DbControl dc = item.getDbControl();
     63    ReleaseWriterOptions options = getOptions();
    6364   
    6465    JSONArray json = new JSONArray();
     
    135136          jsonAnnotations.add(item.createAnnotationJSON("HisScoreNormal", item.getAnnotationValue(Annotationtype.SCORE_NORMAL, goodStain)));
    136137         
    137           // Handle the image of the histology slide
    138           // On the Relax server they should be located in the top-level folder for the specimen
    139           // and have a name based on the HisName annotation
    140           String releaseDataFilesFolder = "/" + specimen.getExternalId();
    141           String imageName = hisName + ".jpg";
    142           String imagePath = releaseDataFilesFolder + "/" + imageName;
    143          
    144           // Check if the image already exists in the release archive
    145           String releasedInVersion = location.findReleasedFile(imagePath);
    146          
    147           JSONObject jsonImage = new FilteredJSONObject(new NotNullFilter<>(false));
    148           jsonImage.put("link", imageName);
    149           jsonImage.put("name", imageName);
    150           JSONArray jsonFiles = new JSONArray();
    151           if (releasedInVersion != null)
     138          if (!options.skipHistologyImages())
    152139          {
    153             // We can safely let the script writer handle this since it should create a symbolic link
    154             jsonFiles.add(jsonImage);
    155             script.addLinkToExistingFile(releaseDataFilesFolder, imageName, releasedInVersion);
    156           }
    157           else
    158           {
    159             // We need to copy the images from the BASE file system to the release archive
    160             // BUT!!! we also get here if there is no image at all in which case we will get
    161             // exception and doesn't export any files at all
    162             InputStream imageIn = null;
    163             ExportOutputStream imageOut = null;
    164             try
     140            String releaseDataFilesFolder = "/" + specimen.getExternalId();
     141            JSONArray jsonFiles = exportHistologyImage(dc, goodStain, releaseDataFilesFolder, hisName + ".jpg");
     142            if (jsonFiles.size() > 0)
    165143            {
    166               // The image should be linked from the 'goodStain' sample via the name 'image'
    167               AnyToAny imageLink = AnyToAny.getByName(dc, goodStain, "image");
    168               File image = (File)imageLink.getTo();
    169               imageIn = image.getDownloadStream(0);
    170               imageOut = location.getOutputStream(imagePath, false);
    171               imageOut.setMimeType(image.getMimeType());
    172               FileUtil.copy(imageIn, imageOut);
    173               // We should copy the metadata as well
    174               jsonImage.put("size", image.getSize());
    175               jsonImage.put("mimeType", image.getMimeType());
    176               jsonImage.put("characterSet", image.getCharacterSet());
    177               jsonFiles.add(jsonImage);
    178             }
    179             catch (ItemNotFoundException | IOException ex)
    180             {} // Ignore since not all histology items have images yet
    181             finally
    182             {
    183               FileUtil.close(imageIn);
    184               FileUtil.close(imageOut);
     144              jsonAnnotations.add(item.createAnnotationJSON("DataFilesFolder", releaseDataFilesFolder));
     145              jsonSp.put("files", jsonFiles);
    185146            }
    186147          }
    187           if (jsonFiles.size() > 0)
    188           {
    189             jsonAnnotations.add(item.createAnnotationJSON("DataFilesFolder", releaseDataFilesFolder));
    190             jsonSp.put("files", jsonFiles);
    191           }
    192148        }
    193149      }
     
    198154   
    199155    return json;
     156  }
     157 
     158  /**
     159    Exports the Histology image to the release archive. If the same image already exists
     160    in an earlier release a symbolic link is added to the ScriptWriter, otherwise the
     161    image is copied to the final position. If the goodStain sample doesn't have any
     162    image nothing is done and an empty array is returned.
     163  */
     164  @SuppressWarnings("unchecked")
     165  private JSONArray exportHistologyImage(DbControl dc, Sample goodStain, String releaseDataFilesFolder, String imageName)
     166  {
     167    // Handle the image of the histology slide
     168    // On the Relax server they should be located in the top-level folder for the specimen
     169    // and have a name based on the HisName annotation
     170    String imagePath = releaseDataFilesFolder + "/" + imageName;
     171   
     172    // Check if the image already exists in the release archive
     173    String releasedInVersion = location.findReleasedFile(imagePath);
     174   
     175    JSONObject jsonImage = new FilteredJSONObject(new NotNullFilter<>(false));
     176    jsonImage.put("link", imageName);
     177    jsonImage.put("name", imageName);
     178    JSONArray jsonFiles = new JSONArray();
     179    if (releasedInVersion != null)
     180    {
     181      // We can safely let the script writer handle this since it should create a symbolic link
     182      jsonFiles.add(jsonImage);
     183      script.addLinkToExistingFile(releaseDataFilesFolder, imageName, releasedInVersion);
     184    }
     185    else
     186    {
     187      // We need to copy the images from the BASE file system to the release archive
     188      // BUT!!! we also get here if there is no image at all in which case we will get
     189      // exception and doesn't export any files at all
     190      InputStream imageIn = null;
     191      ExportOutputStream imageOut = null;
     192      try
     193      {
     194        // The image should be linked from the 'goodStain' sample via the name 'image'
     195        AnyToAny imageLink = AnyToAny.getByName(dc, goodStain, "image");
     196        File image = (File)imageLink.getTo();
     197        imageIn = image.getDownloadStream(0);
     198        imageOut = location.getOutputStream(imagePath, false);
     199        imageOut.setMimeType(image.getMimeType());
     200        FileUtil.copy(imageIn, imageOut);
     201        // We should copy the metadata as well
     202        jsonImage.put("size", image.getSize());
     203        jsonImage.put("mimeType", image.getMimeType());
     204        jsonImage.put("characterSet", image.getCharacterSet());
     205        jsonFiles.add(jsonImage);
     206      }
     207      catch (ItemNotFoundException | IOException ex)
     208      {} // Ignore since not all histology items have images yet
     209      finally
     210      {
     211        FileUtil.close(imageIn);
     212        FileUtil.close(imageOut);
     213      }
     214    }
     215    return jsonFiles;
    200216  }
    201217 
Note: See TracChangeset for help on using the changeset viewer.