Changeset 3905


Ignore:
Timestamp:
Apr 29, 2016, 1:20:57 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 "Linked specimen wizard".

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

Legend:

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

    r3481 r3905  
    2626    url += '&cmd=UpdateAllLinkedSpecimenAnnotations';
    2727   
    28     Wizard.showLoadingAnimation('Updating LinkedSpecimen annotation...');
     28    Wizard.showLoadingAnimation('Updating LinkedSpecimen annotation...', 'linked-specimen-progress');
    2929    Wizard.asyncJsonRequest(url, ls.linkedSpecimenDone, 'POST');
    3030  }
  • extensions/net.sf.basedb.reggie/trunk/resources/batch/linked-specimen.jsp

    r3481 r3905  
    8181
    8282  <div id="wizard-status"></div>
     83  <div id="wizard-progress"></div>
    8384
    8485  <table id="update-results" style="display: none; margin-top: 1em;">
  • extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/servlet/ExportServlet.java

    r3904 r3905  
    530530    {
    531531      if (dc != null) dc.close();
    532       if (progressName != null)
     532      if (progressName != null && sc != null)
    533533      {
    534534        sc.setSessionSetting(progressName, null);
  • extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/servlet/LinkedSpecimenServlet.java

    r3481 r3905  
    55import java.util.HashMap;
    66import java.util.HashSet;
     7import java.util.Iterator;
    78import java.util.Map;
    89import java.util.Set;
     
    2324import net.sf.basedb.core.Sample;
    2425import net.sf.basedb.core.SessionControl;
     26import net.sf.basedb.core.SimpleProgressReporter;
    2527import net.sf.basedb.core.query.Hql;
    2628import net.sf.basedb.core.query.Orders;
     
    105107
    106108        ReggieRole.checkPermission(dc, "'" + cmd + "' wizard", ReggieRole.PREP_CURATOR, ReggieRole.ADMINISTRATOR);
     109       
     110        SimpleProgressReporter progress = new SimpleProgressReporter(null);
     111        sc.setSessionSetting("linked-specimen-progress", progress);
     112        progress.display(1, "Loading samples...");
     113       
    107114        SnapshotManager snapshot = new SnapshotManager();
    108115
     
    120127        // Load all patients and cases that have at least one
    121128        // specimen/nospecimen without creation date
    122         ItemQuery<Sample> query = Sample.getQuery();
    123         query.setIncludes(Reggie.INCLUDE_IN_CURRENT_PROJECT);
    124         query.restrict(
     129        ItemQuery<Sample> queryNoDate = Sample.getQuery();
     130        queryNoDate.setIncludes(Reggie.INCLUDE_IN_CURRENT_PROJECT);
     131        queryNoDate.restrict(
    125132          Restrictions.or(
    126133            Subtype.SPECIMEN.restriction(dc, null),
    127134            Subtype.NO_SPECIMEN.restriction(dc, null)
    128135          ));
    129         query.join(Hql.innerJoin(null, "parent", "c", null, true));
    130         query.join(Hql.innerJoin("c", "parent", "pat", null, true));
    131         query.join(Hql.innerJoin("creationEvent", "ce"));
     136        queryNoDate.join(Hql.innerJoin(null, "parent", "c", null, true));
     137        queryNoDate.join(Hql.innerJoin("c", "parent", "pat", null, true));
     138        queryNoDate.join(Hql.innerJoin("creationEvent", "ce"));
    132139       
    133140        // creation date == null
    134         query.restrict(Restrictions.eq(Hql.property("ce", "eventDate"), null));
     141        queryNoDate.restrict(Restrictions.eq(Hql.property("ce", "eventDate"), null));
     142       
     143        // Load all specimen/nospecimen with a known creation date
     144        // IMPORTANT!! Sort by oldest first
     145        ItemQuery<Sample> queryHasDate = Sample.getQuery();
     146        queryHasDate.setIncludes(Reggie.INCLUDE_IN_CURRENT_PROJECT);
     147        queryHasDate.restrict(
     148          Restrictions.or(
     149            Subtype.SPECIMEN.restriction(dc, null),
     150            Subtype.NO_SPECIMEN.restriction(dc, null)
     151          ));
     152        queryHasDate.join(Hql.innerJoin(null, "parent", "c", null, true));
     153        queryHasDate.join(Hql.innerJoin("c", "parent", "pat", null, true));
     154        queryHasDate.join(Hql.innerJoin(null, "creationEvent", "ce", null, true));
     155       
     156        queryHasDate.restrict(Restrictions.neq(Hql.property("ce", "eventDate"), null));
     157        queryHasDate.order(Orders.asc(Hql.property("ce", "eventDate")));
     158       
     159        long totalCount = queryNoDate.count(dc) + queryHasDate.count(dc);
     160        long count = 0;
    135161       
    136162        // All patients and cases with a specimen that is missing creation date
    137         Set<BioMaterial> unknownDate = new HashSet<BioMaterial>();       
    138         for (Sample specimen : query.list(dc))
     163        Set<BioMaterial> unknownDate = new HashSet<BioMaterial>();
     164        Iterator<Sample> it = queryNoDate.iterate(dc);
     165        while (it.hasNext())
    139166        {
     167          if (count % 100 == 0)
     168          {
     169            progress.display(5 + (int)((95 * count) / totalCount), count + " of " + totalCount + " done");
     170          }
     171          count++;
     172         
     173          Sample specimen = it.next();
    140174          Sample theCase = (Sample)specimen.getParent();
    141175          BioSource patient = (BioSource)theCase.getParent();
     
    159193        }
    160194       
    161         // Load all specimen/nospecimen with a known creation date
    162         // IMPORTANT!! Sort by oldest first
    163         query = Sample.getQuery();
    164         query.setIncludes(Reggie.INCLUDE_IN_CURRENT_PROJECT);
    165         query.restrict(
    166           Restrictions.or(
    167             Subtype.SPECIMEN.restriction(dc, null),
    168             Subtype.NO_SPECIMEN.restriction(dc, null)
    169           ));
    170         query.join(Hql.innerJoin(null, "parent", "c", null, true));
    171         query.join(Hql.innerJoin("c", "parent", "pat", null, true));
    172         query.join(Hql.innerJoin(null, "creationEvent", "ce", null, true));
    173        
    174         query.restrict(Restrictions.neq(Hql.property("ce", "eventDate"), null));
    175         query.order(Orders.asc(Hql.property("ce", "eventDate")));
    176195       
    177196       
     
    179198        Map<BioMaterial, LinkedSpecimenInfo> info = new HashMap<BioMaterial, LinkedSpecimenInfo>();
    180199       
    181         for (Sample specimen : query.list(dc))
     200        it = queryHasDate.iterate(dc);
     201        while (it.hasNext())
    182202        {
     203          if (count % 100 == 0)
     204          {
     205            progress.display(5 + (int)((95 * count) / totalCount), count + " of " + totalCount + " done");
     206          }
     207          count++;
     208         
     209          Sample specimen = it.next();
     210         
    183211          // Load parent case and patient
    184212          Sample theCase = (Sample)specimen.getParent();
     
    290318    {
    291319      if (dc != null) dc.close();
     320      if (sc != null) sc.setSessionSetting("linked-specimen-progress", null);
    292321      json.writeJSONString(resp.getWriter());
    293322    }
Note: See TracChangeset for help on using the changeset viewer.