Changeset 6199


Ignore:
Timestamp:
Apr 8, 2021, 1:44:41 PM (2 years ago)
Author:
Nicklas Nordborg
Message:

References #1295: Registration of specimen handled by external lab

Another big re-factoring to separate validation of the JSON file from actual import and errors that can happen there. So far, only code for Library and Pool have been implemented.

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

Legend:

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

    r6198 r6199  
    8282        {
    8383          var fq = jsonFile.fastq[fqNo];
    84           html += Strings.encodeTags(fq.name) + '; ' + Numbers.formatBytes(fq.size)+'; '+Reggie.reformatDate(fq.lastModified)+'<br>';
     84          html += Strings.encodeTags(fq.name);
     85          if (fq.size > 0)
     86          {
     87            html += '; ' + Numbers.formatBytes(fq.size)+'; '+Reggie.reformatDate(fq.lastModified);
     88          }
     89          else
     90          {
     91            html += ' (missing)';
     92          }
     93          html += '<br>';
    8594        }
    8695      }
  • extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/counter/CounterService.java

    r6198 r6199  
    4949import net.sf.basedb.reggie.dao.Subtype;
    5050import net.sf.basedb.reggie.pdf.GeneReportWorker;
    51 import net.sf.basedb.reggie.plugins.FutureSpecimenImporter;
    52 import net.sf.basedb.reggie.plugins.FutureSpecimenImporter.JsonFile;
     51import net.sf.basedb.reggie.plugins.cmd.JsonFile;
    5352import net.sf.basedb.reggie.query.AnyToAnyRestriction;
    5453import net.sf.basedb.reggie.servlet.AdminServlet;
     
    14741473    try
    14751474    {
    1476       importFiles = FutureSpecimenImporter.getJSONFiles(dc, Fileserver.IMPORT_ARCHIVE.load(dc), false);
     1475      importFiles = JsonFile.findJsonFiles(dc, Fileserver.IMPORT_ARCHIVE.load(dc), false);
    14771476    }
    14781477    catch (RuntimeException ex)
  • extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/plugins/FutureSpecimenImporter.java

    r6198 r6199  
    11package net.sf.basedb.reggie.plugins;
    22
    3 
    4 import java.io.InputStream;
    5 import java.util.ArrayList;
    63import java.util.Date;
    74import java.util.HashMap;
    85import java.util.List;
    96import java.util.Map;
    10 import java.util.regex.Matcher;
    11 import java.util.regex.Pattern;
    12 
    13 import org.json.simple.JSONArray;
    147import org.json.simple.JSONObject;
    15 import org.json.simple.parser.JSONParser;
    168
    179import net.sf.basedb.core.BioMaterialEvent;
     
    2113import net.sf.basedb.core.DerivedBioAssay;
    2214import net.sf.basedb.core.Extract;
    23 import net.sf.basedb.core.FileServer;
    2415import net.sf.basedb.core.ItemQuery;
    2516import net.sf.basedb.core.PhysicalBioAssay;
    2617import net.sf.basedb.core.Sample;
     18import net.sf.basedb.core.data.PlateCoordinate;
    2719import net.sf.basedb.core.query.Annotations;
    2820import net.sf.basedb.core.query.Expressions;
    2921import net.sf.basedb.core.query.Hql;
    3022import net.sf.basedb.core.query.Restrictions;
    31 import net.sf.basedb.opengrid.CmdResult;
    32 import net.sf.basedb.opengrid.OpenGrid;
    33 import net.sf.basedb.opengrid.RemoteHost;
    34 import net.sf.basedb.opengrid.RemoteSession;
    35 import net.sf.basedb.opengrid.config.ConnectionInfo;
    36 import net.sf.basedb.opengrid.filetransfer.ByteArrayDownloadTarget;
    37 import net.sf.basedb.opengrid.filetransfer.FileMetaData;
    3823import net.sf.basedb.reggie.Reggie;
    3924import net.sf.basedb.reggie.dao.Annotationtype;
     
    4530import net.sf.basedb.reggie.dao.Pipeline;
    4631import net.sf.basedb.reggie.dao.PooledLibrary;
     32import net.sf.basedb.reggie.dao.ReactionPlate;
    4733import net.sf.basedb.reggie.dao.Rna;
    4834import net.sf.basedb.reggie.dao.SequencingRun;
    4935import net.sf.basedb.reggie.dao.SpecimenTube;
    5036import net.sf.basedb.reggie.dao.Subtype;
    51 import net.sf.basedb.reggie.grid.ScriptUtil;
     37import net.sf.basedb.reggie.plugins.cmd.JsonFile;
     38import net.sf.basedb.reggie.plugins.cmd.JsonSection;
     39import net.sf.basedb.reggie.plugins.cmd.LibraryInfo;
     40import net.sf.basedb.reggie.plugins.cmd.PoolInfo;
    5241import net.sf.basedb.util.Coordinate;
    53 import net.sf.basedb.util.FileUtil;
    5442
    5543/**
     
    6957{
    7058 
    71   public static List<JsonFile> getJSONFiles(DbControl dc, FileServer fs, boolean downloadAndParse)
    72   {
    73     List<JsonFile> importFiles = new ArrayList<>();
    74 
    75     // Get the import archive and connect to it via SSH
    76     RemoteHost host = new RemoteHost(new ConnectionInfo(fs));
    77     String rootPath = ScriptUtil.checkValidPath(fs.getRootPath(), true, false);
    78     RemoteSession session = null;
    79     try
    80     {
    81 
    82       session = host.connect(5);
    83       // The 'find' command will find all *.json files. Output:
    84       // 0: filename without path
    85      
    86       String findCmd = "find " + rootPath + " -maxdepth 1 -type f -name *.json -printf '%f\\n'";
    87       CmdResult<String> find = session.executeCmd(findCmd, 60);
    88       find.throwExceptionIfNonZeroExitStatus();
    89      
    90       String[] lines = find.getStdout().split("\\n");
    91      
    92       for (String line : lines)
    93       {
    94         JsonFile file = new JsonFile(line);
    95        
    96         if (downloadAndParse)
    97         {
    98           file.downloadAndParse(session, rootPath);
    99         }
    100        
    101         importFiles.add(file);
    102       }
    103     }
    104     finally
    105     {
    106       OpenGrid.close(session);
    107     }
    108    
    109     return importFiles;
    110   }
    11159
    11260  private JsonFile currentFile;
     
    13078  void addWarningMessage(String msg)
    13179  {
    132     this.currentFile.addWarningMessage("[Warning] " + msg);
     80    currentFile.addWarningMessage(msg);
    13381  }
    13482 
    13583  void addErrorMessage(String msg)
    13684  {
    137     this.currentFile.addErrorMessage("[Error] " + msg);
     85    currentFile.addErrorMessage(msg);
    13886  }
    13987
    14088  void addDebugMessage(String msg)
    14189  {
    142     this.currentFile.addDebugMessage("[Debug] "+msg);
     90    currentFile.addDebugMessage(msg);
    14391  }
    14492 
     
    152100    JSONObject json = jsonFile.getJSON();
    153101   
    154     JSONObject jsonSpecimen = (JSONObject)json.get("specimen");
    155     JSONObject jsonLysate = (JSONObject)json.get("lysate");
    156     JSONObject jsonRNA = (JSONObject)json.get("rna");
    157     JSONObject jsonDNA = (JSONObject)json.get("dna");
    158     JSONObject jsonFT = (JSONObject)json.get("ft");
    159    
    160     JSONObject jsonLib = (JSONObject)json.get("library");
    161     JSONObject jsonPool = (JSONObject)json.get("pool");
     102    JsonSection jsonSpecimen = jsonFile.getRequiredSection("Specimen");
     103    JsonSection jsonLysate = jsonFile.getRequiredSection("Lysate");
     104    JsonSection jsonRNA = jsonFile.getRequiredSection("RNA");
     105    JsonSection jsonDNA = jsonFile.getRequiredSection("DNA");
     106    JsonSection jsonFT = jsonFile.getRequiredSection("FlowThrough");
     107   
     108    LibraryInfo libInfo = jsonFile.getLibrary();
     109    PoolInfo poolInfo = jsonFile.getPool();
     110   
    162111    JSONObject jsonSeq = (JSONObject)json.get("sequencing");
    163 
    164112    JSONObject jsonDemux = (JSONObject)json.get("demux");
    165113
     
    174122    Rna rna = createRNA(dc, lysate, jsonRNA);
    175123   
    176     if (jsonLib == null) return;
    177     Library lib = createLibrary(dc, rna, jsonLib);
    178    
    179     if (jsonPool == null) return;
    180     PooledLibrary pool = getOrCreatePool(dc, lib, jsonPool);
     124    if (rna == null || !libInfo.valid) return;
     125    Library lib = createLibrary(dc, rna, libInfo);
     126   
     127    if (lib == null || !poolInfo.valid) return;
     128    PooledLibrary pool = getOrCreatePool(dc, lib, poolInfo);
    181129   
    182130    if (jsonSeq == null) return;   
     
    195143  }
    196144 
    197   private SpecimenTube importToSpecimen(DbControl dc, Sample specimen, JSONObject jsonSpecimen)
     145  private SpecimenTube importToSpecimen(DbControl dc, Sample specimen, JsonSection jsonSpecimen)
    198146  {
    199147    if (Subtype.FUTURE_SPECIMEN.get(dc).equals(specimen.getItemSubtype()))
     
    212160  }
    213161 
    214   private Lysate createLysate(DbControl dc, SpecimenTube specimen, JSONObject jsonLysate)
     162  private Lysate createLysate(DbControl dc, SpecimenTube specimen, JsonSection jsonLysate)
    215163  {
    216164    Extract lysate = Extract.getNew(dc);
     
    226174  }
    227175 
    228   private Rna createRNA(DbControl dc, Lysate lysate, JSONObject jsonRNA)
     176  private Rna createRNA(DbControl dc, Lysate lysate, JsonSection jsonRNA)
    229177  {
    230178    Extract rna = Extract.getNew(dc);
     
    240188  }
    241189 
    242   private Library createLibrary(DbControl dc, Rna rna, JSONObject jsonLib)
     190  private Library createLibrary(DbControl dc, Rna rna, LibraryInfo info)
    243191  {
    244192    Extract lib = Extract.getNew(dc);
     
    249197    creationEvent.setSource(rna.getItem());
    250198
     199    // Library annotations
     200    Date libDate = info.libDate;
     201    creationEvent.setEventDate(libDate);
     202    creationEvent.setProtocol(null);  // TODO
     203    creationEvent.setHardware(null);
     204   
     205    Annotationtype.QUBIT_CONC.setAnnotationValue(dc, lib, info.qubitConc);
     206    Annotationtype.LIBRARY_SIZE_EST.setAnnotationValue(dc, lib, info.libSize);
     207    Annotationtype.LIBRARY_MOLARITY_EST.setAnnotationValue(dc, lib, info.libMolarity);
     208   
     209    Annotationtype.EXTERNAL_OPERATOR.setAnnotationValue(dc, lib, info.operator);
     210   
    251211    dc.saveItem(lib);
    252212   
    253     BioPlate libPlate = getOrCreateLibPlate(dc, jsonLib);
    254     if (libPlate == null)
    255     {
    256       // ERROR
    257     }
    258     else
    259     {
    260       String pos = (String)jsonLib.get("pos");
    261       Pattern p = Pattern.compile("([A-H])([0-9])+");
    262       Matcher m = p.matcher(pos);
    263       if (m.matches())
    264       {
    265         int row = Coordinate.alphaToNumeric(m.group(1));
    266         int col = Integer.parseInt(m.group(2))-1;
    267         BioWell well = libPlate.getBioWell(row, col);
    268         if (well.isEmpty())
     213    // Library plate
     214    BioPlate libPlate = getOrCreateLibPlate(dc, info);
     215    if (libPlate != null)
     216    {
     217      PlateCoordinate pos = info.well;
     218      if (pos != null)
     219      {
     220        String coordinate = Coordinate.numericToAlpha(pos.getRow()+1)+(pos.getColumn()+1);
     221        BioWell well = libPlate.getBioWell(pos);
     222        if (well == null)
    269223        {
    270           lib.setBioWell(well);
    271           addDebugMessage("Using well: " + pos);
     224          addErrorMessage("Well not found: "+libPlate.getName()+"["+ coordinate+"; ref="+info.plateId+"]");
     225        }
     226        else if (!well.isEmpty())
     227        {
     228          addErrorMessage("Well is not empty: "+libPlate.getName()+"["+ coordinate+"; ref="+info.plateId+"]");
    272229        }
    273230        else
    274231        {
    275           addErrorMessage("Well is not empty: " + pos);
    276           // ERROR
     232          lib.setBioWell(well);
     233          addDebugMessage("Using well: "+libPlate.getName()+"["+ coordinate+"; ref="+info.plateId+"]");
    277234        }
    278       }
    279       else
    280       {
    281         addErrorMessage("Invalid well: " + pos);
    282         // ERROR
    283235      }
    284236    }
     
    288240  }
    289241 
    290   private BioPlate getOrCreateLibPlate(DbControl dc, JSONObject jsonLib)
    291   {
    292     String plateId = (String)jsonLib.get("plate");
    293     BioPlate plate = findLibPlateByRef(dc, plateId);
    294     if (plate == null)
    295     {
    296       BioplateType plateType = BioplateType.EXTERNAL_LIBRARY;
    297       plate = BioPlate.getNew(dc, plateType.getPlateGeometry(dc), plateType.get(dc));
    298       plate.setName(plateType.getNextPlateName(dc, true));
    299       Annotationtype.EXTERNAL_REF.setAnnotationValue(dc, plate, plateId);
    300       dc.saveItem(plate);
    301       libPlateCache.put(plateId, plate);
    302       addDebugMessage("Created: "+ plate.getName() + "[ref="+plateId+"]");
    303     }
    304     else
    305     {
    306       addDebugMessage("Found: "+plate.getName());
    307     }
    308    
    309     return plate;
    310   }
    311  
    312   private BioPlate findLibPlateByRef(DbControl dc, String plateId)
    313   {
     242  private BioPlate getOrCreateLibPlate(DbControl dc, LibraryInfo info)
     243  {
     244    String plateId = info.plateId;
     245    if (plateId == null) return null;
     246   
    314247    BioPlate plate = libPlateCache.get(plateId);
    315248    if (plate == null)
     
    323256      if (list.size() > 1)
    324257      {
    325         // ERROR
    326       }
    327       else if (list.size() == 1)
     258        addErrorMessage("Found "+list.size()+" library plates with ExternalRef="+plateId);
     259        return null;
     260      }
     261     
     262      if (list.size() == 1)
    328263      {
    329264        plate = list.get(0);
    330       }
     265        addDebugMessage("Found: "+plate.getName()+"[ref="+plateId+"]");
     266      }
     267      else
     268      {
     269        BioplateType plateType = BioplateType.EXTERNAL_LIBRARY;
     270        plate = BioPlate.getNew(dc, plateType.getPlateGeometry(dc), plateType.get(dc));
     271        plate.setName(plateType.getNextPlateName(dc, true));
     272        Annotationtype.EXTERNAL_REF.setAnnotationValue(dc, plate, plateId);
     273        plate.setEventDate(info.libDate);
     274
     275        Annotationtype.EXTERNAL_OPERATOR.setAnnotationValue(dc, plate, info.operator);
     276        Annotationtype.PLATE_PROCESS_RESULT.setAnnotationValue(dc, plate, ReactionPlate.PROCESS_SUCCESSFUL);
     277        // TODO -- more libplate annotations?
     278       
     279        dc.saveItem(plate);
     280        addDebugMessage("Created: "+plate.getName()+"[ref="+plateId+"]");
     281      }
     282      libPlateCache.put(plateId, plate);
     283    }
     284    else
     285    {
     286      addDebugMessage("Found: "+plate.getName()+"[ref="+plateId+"]");
    331287    }
    332288    return plate;
    333289  }
    334 
    335  
    336   private PooledLibrary getOrCreatePool(DbControl dc, Library lib, JSONObject jsonPool)
    337   {
    338     String poolId = (String)jsonPool.get("poolId");
    339     Extract pool = findPoolByRef(dc, poolId);
    340     if (pool == null)
    341     {
    342       pool = Extract.getNew(dc);
    343       pool.setItemSubtype(Subtype.POOLED_LIBRARY.get(dc));
    344       pool.setName(PooledLibrary.getNextNames(dc, 1).get(0));
    345       Annotationtype.PIPELINE.setAnnotationValue(dc, pool, Pipeline.RNA_SEQ.getName());
    346       Annotationtype.EXTERNAL_REF.setAnnotationValue(dc, pool, poolId);
    347       dc.saveItem(pool);
    348       poolCache.put(poolId, pool);
    349      
    350       addDebugMessage("Created: "+ pool.getName() + "[ref="+poolId+"]");
    351     }
    352     else
    353     {
    354       addDebugMessage("Found: "+pool.getName());
    355     }
    356    
    357     pool.getCreationEvent().addSource(lib.getItem());
    358    
    359     return PooledLibrary.get(pool);
    360   }
    361  
    362   private Extract findPoolByRef(DbControl dc, String poolId)
    363   {
     290 
     291 
     292  private PooledLibrary getOrCreatePool(DbControl dc, Library lib, PoolInfo info)
     293  {
     294    String poolId = info.poolId;
     295    if (poolId == null) return null;
     296
    364297    Extract pool = poolCache.get(poolId);
    365298    if (pool == null)
     
    373306      if (list.size() > 1)
    374307      {
    375         // ERROR
    376       }
    377       else if (list.size() == 1)
     308        addErrorMessage("Found "+list.size()+" pools with ExternalRef="+poolId);
     309        return null;
     310      }
     311     
     312      if (list.size() == 1)
    378313      {
    379314        pool = list.get(0);
    380       }
    381     }
    382     return pool;
    383   }
    384  
     315        addDebugMessage("Found: "+pool.getName()+"[ref="+poolId+"]");
     316      }
     317      else
     318      {
     319       
     320        pool = Extract.getNew(dc);
     321        pool.setItemSubtype(Subtype.POOLED_LIBRARY.get(dc));
     322        pool.setName(PooledLibrary.getNextNames(dc, 1).get(0));
     323        Pipeline.RNA_SEQ.setAnnotation(dc, pool);
     324        Annotationtype.EXTERNAL_REF.setAnnotationValue(dc, pool, poolId);
     325        Annotationtype.POOL_DATE.setAnnotationValue(dc, pool, info.poolDate);
     326        Annotationtype.POOL_OPERATOR.setAnnotationValue(dc, pool, info.operator);
     327       
     328        BioMaterialEvent poolEvent = pool.getCreationEvent();
     329        poolEvent.setEventDate(info.poolDate);
     330        poolEvent.setProtocol(null); // To avoid that a 'project default' is used
     331        poolEvent.setHardware(null);
     332       
     333        dc.saveItem(pool);
     334        addDebugMessage("Created: "+pool.getName()+"[ref="+poolId+"]");
     335      }
     336      poolCache.put(poolId, pool);
     337    }
     338    else
     339    {
     340      addDebugMessage("Found: "+pool.getName()+"[ref="+poolId+"]");
     341    }
     342       
     343    pool.getCreationEvent().addSource(lib.getItem());
     344    return PooledLibrary.get(pool);
     345  }
     346 
     347
    385348  private SequencingRun getOrCreateSequencing(DbControl dc, PooledLibrary pool, JSONObject jsonSeq)
    386349  {
     
    529492  }
    530493
    531  
    532   public static class JsonFile
    533   {
    534 
    535     private final String name;
    536     private final List<String> errorMessages;
    537     private final List<String> warningMessages;
    538     private final List<String> debugMessages;
    539 
    540     private JSONObject json;
    541     private FastqFile[] fastq;
    542 
    543     public JsonFile(String name)
    544     {
    545       this.name = name;
    546       this.errorMessages = new ArrayList<String>();
    547       this.warningMessages = new ArrayList<String>();
    548       this.debugMessages = new ArrayList<String>();
    549     }
    550    
    551     public String getName()
    552     {
    553       return name;
    554     }
    555    
    556     public boolean hasWarning()
    557     {
    558       return warningMessages.size() > 0;
    559     }
    560     public List<String> getWarningMessages()
    561     {
    562       return warningMessages;
    563     }
    564     public void addWarningMessage(String msg)
    565     {
    566       this.warningMessages.add(msg);
    567     }
    568    
    569     public boolean hasError()
    570     {
    571       return errorMessages.size() > 0;
    572     }
    573     public List<String> getErrorMessages()
    574     {
    575       return errorMessages;
    576     }
    577     public void addErrorMessage(String msg)
    578     {
    579       this.errorMessages.add(msg);
    580     }
    581 
    582     public boolean hasDebug()
    583     {
    584       return debugMessages.size() > 0;
    585     }
    586     public List<String> getDebugMessages()
    587     {
    588       return debugMessages;
    589     }
    590     public void addDebugMessage(String msg)
    591     {
    592       this.debugMessages.add(msg);
    593     }
    594    
    595     public JSONObject asJSONObject()
    596     {
    597       JSONObject j = new JSONObject();
    598       j.put("name", name);
    599      
    600       if (fastq != null)
    601       {
    602         JSONArray jsonFq = new JSONArray();
    603         j.put("fastq", jsonFq);
    604         for (FastqFile fq : fastq)
    605         {
    606           jsonFq.add(fq.asJSONObject());
    607         }
    608       }
    609      
    610       if (hasError())
    611       {
    612         JSONArray jsonErrors = new JSONArray();
    613         jsonErrors.addAll(errorMessages);
    614         j.put("errors", jsonErrors);
    615       }
    616       if (hasWarning())
    617       {
    618         JSONArray jsonWarnings = new JSONArray();
    619         jsonWarnings.addAll(warningMessages);
    620         j.put("warnings", jsonWarnings);
    621       }
    622      
    623       return j;
    624     }
    625    
    626     public JSONObject getJSON()
    627     {
    628       return json;
    629     }
    630    
    631     public void downloadAndParse(RemoteSession session, String rootDir)
    632     {
    633       if (!rootDir.endsWith("/")) rootDir += "/";
    634       String path = rootDir + name;
    635 
    636       ByteArrayDownloadTarget download = new ByteArrayDownloadTarget(path);
    637       try
    638       {
    639         session.downloadFile(path, download);
    640       }
    641       catch (Exception ex)
    642       {
    643         addErrorMessage("Could not download '"+ name + "': " + ex.getMessage());
    644         return;
    645       }
    646       try
    647       {
    648         String data = download.getString("UTF-8");
    649         if (data == null || data.length() == 0)
    650         {
    651           addErrorMessage("Could not parse '"+name+"': File is empty");
    652           return;
    653         }
    654         json = (JSONObject)new JSONParser().parse(data);
    655        
    656         JSONObject jsonFastq = (JSONObject)json.get("fastq");
    657         if (jsonFastq == null)
    658         {
    659           addErrorMessage("No 'fastq' section in file '"+name+"'");
    660           return;
    661         }
    662        
    663         String r1 = (String)jsonFastq.get("R1");
    664         String r2 = (String)jsonFastq.get("R2");
    665         if (r1 == null) addErrorMessage("No 'fastq.R1' entry in file '"+name+"'");
    666         if (r2 == null) addErrorMessage("No 'fastq.R2' entry in file '"+name+"'");
    667         if (hasError()) return;
    668        
    669         fastq = new FastqFile[2];
    670         fastq[0] = getFastqFile(session, rootDir, r1);
    671         fastq[1] = getFastqFile(session, rootDir, r2);
    672        
    673       }
    674       catch (Exception ex)
    675       {
    676         addErrorMessage("Could not parse '"+name+"': " + ex.getMessage());
    677         return;
    678       }
    679     }
    680    
    681    
    682     FastqFile getFastqFile(RemoteSession session, String rootDir, String name)
    683     {
    684       FastqFile fq = new FastqFile(name);
    685       InputStream tmp = null;
    686       try
    687       {
    688         FileMetaData info = new FileMetaData();
    689         tmp = session.readFile(rootDir+name, info);
    690         fq.setSize(info.getSize());
    691         fq.setLastModified(info.getLastModifiedTime());
    692       }
    693       catch (Exception ex)
    694       {
    695         addErrorMessage("Could not stat FASTQ file '"+name+"': " + ex.getMessage());
    696       }
    697       finally
    698       {
    699         FileUtil.close(tmp);
    700       }
    701       return fq;
    702     }
    703   }
    704  
    705   public static class FastqFile
    706   {
    707    
    708     private final String name;
    709     private long size;
    710     private long lastModified;
    711    
    712     public FastqFile(String name)
    713     {
    714       this.name = name;
    715     }
    716    
    717     public String getName()
    718     {
    719       return name;
    720     }
    721 
    722     public long getSize()
    723     {
    724       return size;
    725     }
    726    
    727     public long getLastModified()
    728     {
    729       return lastModified;
    730     }
    731    
    732     void setSize(long size)
    733     {
    734       this.size = size;
    735     }
    736    
    737     void setLastModified(long lastModified)
    738     {
    739       this.lastModified = lastModified;
    740     }
    741    
    742     public JSONObject asJSONObject()
    743     {
    744       JSONObject j = new JSONObject();
    745       j.put("name", name);
    746       j.put("size", size);
    747       j.put("lastModified", Reggie.CONVERTER_DATETIME_TO_STRING_WITH_SEPARATOR.convert(new Date(lastModified)));
    748       return j;
    749     }
    750 
    751   }
    752494}
  • extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/servlet/FutureSpecimenServlet.java

    r6198 r6199  
    22
    33import java.io.IOException;
     4import java.util.ArrayList;
     5import java.util.Collections;
    46import java.util.List;
    57
     
    3436import net.sf.basedb.reggie.grid.ScriptUtil;
    3537import net.sf.basedb.reggie.plugins.FutureSpecimenImporter;
    36 import net.sf.basedb.reggie.plugins.FutureSpecimenImporter.JsonFile;
     38import net.sf.basedb.reggie.plugins.cmd.JsonFile;
    3739import net.sf.basedb.util.error.ThrowableUtil;
    3840
     
    6769        dc = sc.newDbControl();
    6870       
    69         List<JsonFile> files = FutureSpecimenImporter.getJSONFiles(dc, Fileserver.IMPORT_ARCHIVE.load(dc), true);
     71        List<JsonFile> files = JsonFile.findJsonFiles(dc, Fileserver.IMPORT_ARCHIVE.load(dc), true);
    7072       
    7173        ItemQuery<Sample> query = Sample.getQuery();
     
    168170          RemoteHost host = new RemoteHost(new ConnectionInfo(fs));
    169171          session = host.connect(5);
    170           FutureSpecimenImporter importer = new FutureSpecimenImporter();
    171172         
    172173          for (int itemNo = 0; itemNo < jsonItems.size(); itemNo++)
     
    181182            if (!jsonFile.hasError())
    182183            {
     184              FutureSpecimenImporter importer = new FutureSpecimenImporter();
    183185              importer.doImport(dc, specimen, jsonFile);
    184186            }
     
    186188            if (jsonFile.hasError())
    187189            {
    188               jsonMessages.add("[Error] Import failed. See below for more information.");
    189               jsonMessages.addAll(jsonFile.getErrorMessages());
     190              jsonMessages.add("[Error]["+jsonFile.getName()+"] Import failed (see below for more information)");
     191              jsonMessages.addAll(prefix("[Error]["+jsonFile.getName()+"] ", jsonFile.getErrorMessages()));
    190192            }
    191193            else
     
    194196            }
    195197           
    196             jsonMessages.addAll(jsonFile.getWarningMessages());
    197             jsonMessages.addAll(jsonFile.getDebugMessages());
     198            jsonMessages.addAll(prefix("[Warning]["+jsonFile.getName()+"] ", jsonFile.getWarningMessages()));
     199            jsonMessages.addAll(prefix("[Debug]["+jsonFile.getName()+"] ", jsonFile.getDebugMessages()));
     200
     201            // TODO -- we should import each file in a separate transaction
     202            // dc.commit()
     203            // dc = sc.newDbControl();
    198204          }
    199205
     
    203209          OpenGrid.close(session);
    204210        }
    205        
    206         // TODO -- no commit yet!
    207         //dc.commit();
    208211      }
    209212
     
    226229  }
    227230 
     231  /**
     232    Add a prefix to all messages.
     233  */
     234  private List<String> prefix(String prefix, List<String> messages)
     235  {
     236    if (messages.size() == 0) return Collections.emptyList();
     237    List<String> out = new ArrayList<>(messages.size());
     238    for (String m : messages)
     239    {
     240      out.add(prefix+m);
     241    }
     242    return out;
     243  }
     244 
    228245}
Note: See TracChangeset for help on using the changeset viewer.