Changeset 6208


Ignore:
Timestamp:
Apr 12, 2021, 4:08:17 PM (2 years ago)
Author:
Nicklas Nordborg
Message:

References #1295: Registration of specimen handled by external lab

Added a download link so that it is possible to inspect the JSON file.

Location:
extensions/net.sf.basedb.reggie/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • extensions/net.sf.basedb.reggie/trunk/resources/batch/import-external-specimen.js

    r6206 r6208  
    7575      html += '<td>'+(Strings.encodeTags(item.itemType) || '-')+'</td>';
    7676      html += '<td class="dottedleft">'+(Strings.encodeTags(item.name) || '-')+'</td>';
    77       html += '<td class="dottedleft">'+(jsonFile ? Strings.encodeTags(jsonFile.name) : '-')+'</td>';
     77      html += '<td class="dottedleft">';
     78      if (jsonFile)
     79      {
     80        html += Strings.encodeTags(jsonFile.name);
     81        html += '<span class="link download-file" data-file-no="'+itemNo+'" title="Download and view this file"><img src="../images/download.png"></span>';
     82      }
     83      html += '</td>';
    7884      html += '<td class="fastq">';
    7985      if (jsonFile && jsonFile.fastq)
     
    131137    Doc.element('itemTable').innerHTML = html;
    132138   
     139    var downloadable = document.getElementsByClassName('download-file');
     140    for (var fileNo = 0; fileNo < downloadable.length; fileNo++)
     141    {
     142      Events.addEventHandler(downloadable[fileNo], 'click', specimen.downloadJsonFile);
     143    }
     144
     145   
    133146    Doc.show('step-1');
    134147    Doc.show('gonext');
     148  }
     149
     150  specimen.downloadJsonFile = function(event)
     151  {
     152    var itemNo = Data.get(event.currentTarget, 'file-no');
     153    var file = importItems[itemNo].jsonFile;
     154
     155    var url = '../FutureSpecimen.servlet?ID='+App.getSessionId();
     156    url += '&cmd=DownloadJsonFile';
     157    url += '&file='+encodeURIComponent(file.name);
     158   
     159    Dialogs.openPopup(url, file.name, 800, 800);
    135160  }
    136161
  • extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/servlet/FutureSpecimenServlet.java

    r6201 r6208  
    2525import net.sf.basedb.opengrid.RemoteSession;
    2626import net.sf.basedb.opengrid.config.ConnectionInfo;
     27import net.sf.basedb.opengrid.filetransfer.ServletResponseDownloadTarget;
    2728import net.sf.basedb.opengrid.service.OpenGridService;
    2829import net.sf.basedb.reggie.JsonUtil;
     
    110111        json.put("importItems", jsonImportItems);
    111112      }
     113      else if ("DownloadJsonFile".equals(cmd))
     114      {
     115        json = null; // No regular JSON output
     116        dc = sc.newDbControl();
     117       
     118        FileServer server = Fileserver.IMPORT_ARCHIVE.load(dc);
     119        FileServer fs = Fileserver.IMPORT_ARCHIVE.load(dc);
     120        String rootPath = ScriptUtil.checkValidPath(fs.getRootPath(), true, false);
     121        String file = ScriptUtil.checkValidFilename(req.getParameter("file"));
     122       
     123        RemoteSession session = null;
     124        try
     125        {
     126          RemoteHost host = new RemoteHost(new ConnectionInfo(fs));
     127          session = host.connect(5);
     128         
     129          //resp.setHeader("Content-Disposition", "attachment; filename=" + fileName);
     130          resp.setContentType("application/json");
     131
     132          session.downloadFile(rootPath+"/"+file, new ServletResponseDownloadTarget(resp, file));
     133        }
     134        finally
     135        {
     136          OpenGrid.close(session);
     137        }
     138
     139       
     140      }
    112141    }
    113142    catch (Throwable t)
    114143    {
    115144      t.printStackTrace();
    116       json.clear();
    117       json.put("status", "error");
    118       json.put("message", t.getMessage());
    119       json.put("stacktrace", ThrowableUtil.stackTraceToString(t));
     145      if (json != null)
     146      {
     147        json.clear();
     148        json.put("status", "error");
     149        json.put("message", t.getMessage());
     150        json.put("stacktrace", ThrowableUtil.stackTraceToString(t));
     151      }
     152      else
     153      {
     154        resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, t.getMessage());
     155      }
    120156    }
    121157    finally
    122158    {
    123159      if (dc != null) dc.close();
    124       json.writeJSONString(resp.getWriter());
     160      if (json != null) json.writeJSONString(resp.getWriter());
    125161    }
    126162   
Note: See TracChangeset for help on using the changeset viewer.