Changeset 3916


Ignore:
Timestamp:
May 2, 2016, 1:41:13 PM (7 years ago)
Author:
Nicklas Nordborg
Message:

References #883: Add support for progress reporting to the Reggie wizard API

Added progress reporter to the 'Import frozen tissue data' wizard. Also changed this importer to use the batch annotation importer.

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

Legend:

Unmodified
Added
Removed
  • extensions/net.sf.basedb.reggie/trunk/resources/batch/frozen-tissue-date.js

    r3488 r3916  
    3737    url += '&cmd=ImportFrozenTissueDate';
    3838    url += '&file='+encodeURIComponent(frm.importfile.value);
     39    url += '&progressbar=import-frozen-tissue-progress';
    3940   
    40     Wizard.showLoadingAnimation('Importing FrozenTissueDate...');
     41    Wizard.showLoadingAnimation('Importing FrozenTissueDate...', 'import-frozen-tissue-progress');
    4142    Wizard.asyncJsonRequest(url, ftd.submissionResults, 'POST');
    4243  }
  • extensions/net.sf.basedb.reggie/trunk/resources/batch/frozen-tissue-date.jsp

    r3488 r3916  
    9898
    9999  <div id="wizard-status"></div>
     100  <div id="wizard-progress"></div>
    100101
    101102  <div id="not-found" style="display: none;" class="bg-filled-100 fullborder"></div>
  • extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/servlet/ImportServlet.java

    r3488 r3916  
    33import java.io.BufferedReader;
    44import java.io.IOException;
    5 import java.io.InputStream;
    65import java.io.InputStreamReader;
     6import java.util.Collections;
    77import java.util.Date;
    88
     
    1616
    1717import net.sf.basedb.clients.web.util.HTML;
     18import net.sf.basedb.core.AnnotationBatcher;
     19import net.sf.basedb.core.AnnotationBatcher.Change;
     20import net.sf.basedb.core.AnnotationType;
    1821import net.sf.basedb.core.Application;
    1922import net.sf.basedb.core.DbControl;
    2023import net.sf.basedb.core.File;
     24import net.sf.basedb.core.Item;
    2125import net.sf.basedb.core.Path;
    2226import net.sf.basedb.core.Sample;
    2327import net.sf.basedb.core.SessionControl;
     28import net.sf.basedb.core.SimpleProgressReporter;
    2429import net.sf.basedb.reggie.JsonUtil;
    2530import net.sf.basedb.reggie.counter.CounterService;
     
    2833import net.sf.basedb.reggie.dao.ReggieRole;
    2934import net.sf.basedb.util.FileUtil;
     35import net.sf.basedb.util.InputStreamTracker;
    3036import net.sf.basedb.util.error.ThrowableUtil;
    3137
     
    5359   
    5460    JSONArray jsonMessages = new JSONArray();
    55  
    5661    final SessionControl sc = Application.getSessionControl(ID, req.getRemoteAddr());
     62    String progressName = req.getParameter("progressbar");
     63    SimpleProgressReporter progress = null;
     64    if (progressName != null)
     65    {
     66      progress = new SimpleProgressReporter(null);
     67      sc.setSessionSetting(progressName, progress);
     68    }
     69   
    5770    DbControl dc = null;
    5871    try
     
    7285        if (charset == null) charset = "UTF-8";
    7386       
    74         InputStream in = null;
     87        InputStreamTracker in = null;
    7588        BufferedReader reader = null;
    7689        Date frozenTissueDate = new Date();
     
    7891        int numUpdated = 0;
    7992        int numCreated = 0;
     93        int noChange = 0;
    8094        int lineNo = 1;
    8195       
    8296        try
    8397        {
    84           in = f.getDownloadStream(0);
     98          in = new InputStreamTracker(f.getDownloadStream(0));
     99          long fileSize = f.getSize();
    85100          reader = new BufferedReader(new InputStreamReader(in, charset));
     101         
     102          AnnotationType frozenDate = Annotationtype.FROZEN_TISSUE_DATE.get(dc);
     103         
     104          AnnotationBatcher batcher = new AnnotationBatcher(dc, Item.SAMPLE);
     105          batcher.addAnnotationTypes(Collections.singleton(frozenDate));
     106
    86107          String scanbId = reader.readLine();
    87          
    88108          while (scanbId != null)
    89109          {
     110            if (lineNo % 100 == 0 && progress != null)
     111            {
     112              progress.display((int)((95* in.getNumRead()) / fileSize), "Processing " + f.getName() + " (" + lineNo + " lines)...");
     113            }
    90114            Case theCase = Case.findByName(dc, scanbId);
    91115           
     
    97121            {
    98122              Sample s = theCase.getItem();
    99               if (Annotationtype.FROZEN_TISSUE_DATE.hasAnnotation(dc, s))
     123              batcher.setCurrentItem(s);
     124              AnnotationBatcher.Change change = batcher.setValue(frozenDate, frozenTissueDate, null, false);
     125              if (change == Change.ADDED)
     126              {
     127                numCreated++;
     128              }
     129              else if (change == Change.UPDATED)
    100130              {
    101131                numUpdated++;
     
    103133              else
    104134              {
    105                 numCreated++;
     135                noChange++;
    106136              }
    107               Annotationtype.FROZEN_TISSUE_DATE.setAnnotationValue(dc, s, frozenTissueDate);
    108137            }
    109138           
     
    120149        jsonMessages.add("Created FrozenTissueDate annotation on " + numCreated + " cases");
    121150        jsonMessages.add("Updated FrozenTissueDate annotation on " + numUpdated + " cases");
     151        jsonMessages.add("No change on " + noChange + " cases");
    122152        if (jsonNotFound.size() > 0)
    123153        {
     
    126156        }
    127157         
     158        if (progress != null)
     159        {
     160          progress.display(100, "Done; " + lineNo + " lines was processed.");
     161        }
    128162        dc.commit();
    129163      }
     
    142176    {
    143177      if (dc != null) dc.close();
     178      if (progressName != null && sc != null)
     179      {
     180        sc.setSessionSetting(progressName, null);
     181      }
    144182      json.writeJSONString(resp.getWriter());
    145183    }
Note: See TracChangeset for help on using the changeset viewer.