Changeset 6199
- Timestamp:
- Apr 8, 2021, 1:44:41 PM (2 years ago)
- 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 82 82 { 83 83 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>'; 85 94 } 86 95 } -
extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/counter/CounterService.java
r6198 r6199 49 49 import net.sf.basedb.reggie.dao.Subtype; 50 50 import net.sf.basedb.reggie.pdf.GeneReportWorker; 51 import net.sf.basedb.reggie.plugins.FutureSpecimenImporter; 52 import net.sf.basedb.reggie.plugins.FutureSpecimenImporter.JsonFile; 51 import net.sf.basedb.reggie.plugins.cmd.JsonFile; 53 52 import net.sf.basedb.reggie.query.AnyToAnyRestriction; 54 53 import net.sf.basedb.reggie.servlet.AdminServlet; … … 1474 1473 try 1475 1474 { 1476 importFiles = FutureSpecimenImporter.getJSONFiles(dc, Fileserver.IMPORT_ARCHIVE.load(dc), false);1475 importFiles = JsonFile.findJsonFiles(dc, Fileserver.IMPORT_ARCHIVE.load(dc), false); 1477 1476 } 1478 1477 catch (RuntimeException ex) -
extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/plugins/FutureSpecimenImporter.java
r6198 r6199 1 1 package net.sf.basedb.reggie.plugins; 2 2 3 4 import java.io.InputStream;5 import java.util.ArrayList;6 3 import java.util.Date; 7 4 import java.util.HashMap; 8 5 import java.util.List; 9 6 import java.util.Map; 10 import java.util.regex.Matcher;11 import java.util.regex.Pattern;12 13 import org.json.simple.JSONArray;14 7 import org.json.simple.JSONObject; 15 import org.json.simple.parser.JSONParser;16 8 17 9 import net.sf.basedb.core.BioMaterialEvent; … … 21 13 import net.sf.basedb.core.DerivedBioAssay; 22 14 import net.sf.basedb.core.Extract; 23 import net.sf.basedb.core.FileServer;24 15 import net.sf.basedb.core.ItemQuery; 25 16 import net.sf.basedb.core.PhysicalBioAssay; 26 17 import net.sf.basedb.core.Sample; 18 import net.sf.basedb.core.data.PlateCoordinate; 27 19 import net.sf.basedb.core.query.Annotations; 28 20 import net.sf.basedb.core.query.Expressions; 29 21 import net.sf.basedb.core.query.Hql; 30 22 import 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;38 23 import net.sf.basedb.reggie.Reggie; 39 24 import net.sf.basedb.reggie.dao.Annotationtype; … … 45 30 import net.sf.basedb.reggie.dao.Pipeline; 46 31 import net.sf.basedb.reggie.dao.PooledLibrary; 32 import net.sf.basedb.reggie.dao.ReactionPlate; 47 33 import net.sf.basedb.reggie.dao.Rna; 48 34 import net.sf.basedb.reggie.dao.SequencingRun; 49 35 import net.sf.basedb.reggie.dao.SpecimenTube; 50 36 import net.sf.basedb.reggie.dao.Subtype; 51 import net.sf.basedb.reggie.grid.ScriptUtil; 37 import net.sf.basedb.reggie.plugins.cmd.JsonFile; 38 import net.sf.basedb.reggie.plugins.cmd.JsonSection; 39 import net.sf.basedb.reggie.plugins.cmd.LibraryInfo; 40 import net.sf.basedb.reggie.plugins.cmd.PoolInfo; 52 41 import net.sf.basedb.util.Coordinate; 53 import net.sf.basedb.util.FileUtil;54 42 55 43 /** … … 69 57 { 70 58 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 SSH76 RemoteHost host = new RemoteHost(new ConnectionInfo(fs));77 String rootPath = ScriptUtil.checkValidPath(fs.getRootPath(), true, false);78 RemoteSession session = null;79 try80 {81 82 session = host.connect(5);83 // The 'find' command will find all *.json files. Output:84 // 0: filename without path85 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 finally105 {106 OpenGrid.close(session);107 }108 109 return importFiles;110 }111 59 112 60 private JsonFile currentFile; … … 130 78 void addWarningMessage(String msg) 131 79 { 132 this.currentFile.addWarningMessage("[Warning] " +msg);80 currentFile.addWarningMessage(msg); 133 81 } 134 82 135 83 void addErrorMessage(String msg) 136 84 { 137 this.currentFile.addErrorMessage("[Error] " +msg);85 currentFile.addErrorMessage(msg); 138 86 } 139 87 140 88 void addDebugMessage(String msg) 141 89 { 142 this.currentFile.addDebugMessage("[Debug] "+msg);90 currentFile.addDebugMessage(msg); 143 91 } 144 92 … … 152 100 JSONObject json = jsonFile.getJSON(); 153 101 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 162 111 JSONObject jsonSeq = (JSONObject)json.get("sequencing"); 163 164 112 JSONObject jsonDemux = (JSONObject)json.get("demux"); 165 113 … … 174 122 Rna rna = createRNA(dc, lysate, jsonRNA); 175 123 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); 181 129 182 130 if (jsonSeq == null) return; … … 195 143 } 196 144 197 private SpecimenTube importToSpecimen(DbControl dc, Sample specimen, J SONObjectjsonSpecimen)145 private SpecimenTube importToSpecimen(DbControl dc, Sample specimen, JsonSection jsonSpecimen) 198 146 { 199 147 if (Subtype.FUTURE_SPECIMEN.get(dc).equals(specimen.getItemSubtype())) … … 212 160 } 213 161 214 private Lysate createLysate(DbControl dc, SpecimenTube specimen, J SONObjectjsonLysate)162 private Lysate createLysate(DbControl dc, SpecimenTube specimen, JsonSection jsonLysate) 215 163 { 216 164 Extract lysate = Extract.getNew(dc); … … 226 174 } 227 175 228 private Rna createRNA(DbControl dc, Lysate lysate, J SONObjectjsonRNA)176 private Rna createRNA(DbControl dc, Lysate lysate, JsonSection jsonRNA) 229 177 { 230 178 Extract rna = Extract.getNew(dc); … … 240 188 } 241 189 242 private Library createLibrary(DbControl dc, Rna rna, JSONObject jsonLib)190 private Library createLibrary(DbControl dc, Rna rna, LibraryInfo info) 243 191 { 244 192 Extract lib = Extract.getNew(dc); … … 249 197 creationEvent.setSource(rna.getItem()); 250 198 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 251 211 dc.saveItem(lib); 252 212 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) 269 223 { 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+"]"); 272 229 } 273 230 else 274 231 { 275 addErrorMessage("Well is not empty: " + pos);276 // ERROR232 lib.setBioWell(well); 233 addDebugMessage("Using well: "+libPlate.getName()+"["+ coordinate+"; ref="+info.plateId+"]"); 277 234 } 278 }279 else280 {281 addErrorMessage("Invalid well: " + pos);282 // ERROR283 235 } 284 236 } … … 288 240 } 289 241 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 314 247 BioPlate plate = libPlateCache.get(plateId); 315 248 if (plate == null) … … 323 256 if (list.size() > 1) 324 257 { 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) 328 263 { 329 264 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+"]"); 331 287 } 332 288 return plate; 333 289 } 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 364 297 Extract pool = poolCache.get(poolId); 365 298 if (pool == null) … … 373 306 if (list.size() > 1) 374 307 { 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) 378 313 { 379 314 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 385 348 private SequencingRun getOrCreateSequencing(DbControl dc, PooledLibrary pool, JSONObject jsonSeq) 386 349 { … … 529 492 } 530 493 531 532 public static class JsonFile533 {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 try638 {639 session.downloadFile(path, download);640 }641 catch (Exception ex)642 {643 addErrorMessage("Could not download '"+ name + "': " + ex.getMessage());644 return;645 }646 try647 {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 try687 {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 finally698 {699 FileUtil.close(tmp);700 }701 return fq;702 }703 }704 705 public static class FastqFile706 {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 }752 494 } -
extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/servlet/FutureSpecimenServlet.java
r6198 r6199 2 2 3 3 import java.io.IOException; 4 import java.util.ArrayList; 5 import java.util.Collections; 4 6 import java.util.List; 5 7 … … 34 36 import net.sf.basedb.reggie.grid.ScriptUtil; 35 37 import net.sf.basedb.reggie.plugins.FutureSpecimenImporter; 36 import net.sf.basedb.reggie.plugins. FutureSpecimenImporter.JsonFile;38 import net.sf.basedb.reggie.plugins.cmd.JsonFile; 37 39 import net.sf.basedb.util.error.ThrowableUtil; 38 40 … … 67 69 dc = sc.newDbControl(); 68 70 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); 70 72 71 73 ItemQuery<Sample> query = Sample.getQuery(); … … 168 170 RemoteHost host = new RemoteHost(new ConnectionInfo(fs)); 169 171 session = host.connect(5); 170 FutureSpecimenImporter importer = new FutureSpecimenImporter();171 172 172 173 for (int itemNo = 0; itemNo < jsonItems.size(); itemNo++) … … 181 182 if (!jsonFile.hasError()) 182 183 { 184 FutureSpecimenImporter importer = new FutureSpecimenImporter(); 183 185 importer.doImport(dc, specimen, jsonFile); 184 186 } … … 186 188 if (jsonFile.hasError()) 187 189 { 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())); 190 192 } 191 193 else … … 194 196 } 195 197 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(); 198 204 } 199 205 … … 203 209 OpenGrid.close(session); 204 210 } 205 206 // TODO -- no commit yet!207 //dc.commit();208 211 } 209 212 … … 226 229 } 227 230 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 228 245 }
Note: See TracChangeset
for help on using the changeset viewer.