Changeset 4825


Ignore:
Timestamp:
Mar 20, 2009, 3:41:22 PM (15 years ago)
Author:
Nicklas Nordborg
Message:

References #1262: Overview and correction factor plots should use the static cache

The overview and correction factor plots now use the cache. Unless the cache API changes there is really not much more to do on this ticket.

Location:
trunk
Files:
2 edited
2 moved

Legend:

Unmodified
Added
Removed
  • trunk/src/clients/web/net/sf/basedb/clients/web/servlet/PlotServlet.java

    r4548 r4825  
    4848import net.sf.basedb.clients.web.util.HTML;
    4949import net.sf.basedb.util.BioAssaySetUtil;
     50import net.sf.basedb.util.FileUtil;
     51import net.sf.basedb.util.StaticCache;
    5052import net.sf.basedb.util.Values;
    5153import net.sf.basedb.util.formatter.Formatter;
     
    6466import javax.servlet.http.HttpServletResponse;
    6567
     68import org.apache.commons.io.output.TeeOutputStream;
    6669import org.jfree.chart.JFreeChart;
    6770import org.jfree.chart.renderer.xy.XYStepRenderer;
     
    7578import java.awt.image.BufferedImage;
    7679import java.awt.image.RenderedImage;
     80import java.io.InputStream;
    7781import java.io.OutputStream;
    7882import java.io.IOException;
     
    289293  private int defaultHeight = 400;
    290294  private String defaultFormat = "png";
    291 
     295  private String cacheBase = "plots/";
     296 
    292297  public void init()
    293298    throws ServletException
     
    299304    defaultHeight = Values.getInt(cfg.getInitParameter("defaultHeight"), defaultHeight);
    300305    defaultFormat = Values.getString(cfg.getInitParameter("defaultFormat"), defaultFormat);
     306    cacheBase = Values.getString(cfg.getInitParameter("cacheBase"), cacheBase);
    301307  }
    302308
     
    311317    final int bioAssaySetId = Values.getInt(request.getParameter("bioassayset_id"));
    312318    final String type = Values.getString(request.getParameter("type"), "scatter");
    313    
     319    String cacheKey = Values.getStringOrNull(request.getParameter("cache"));
     320
    314321    // Where to deliver the image
    315322    final boolean download = Values.getBoolean(request.getParameter("download"));
     
    358365      Values.getStringOrNull(request.getParameter("hiloAggregate"));
    359366   
    360    
     367    InputStream cachedImageIn = null;
     368    OutputStream cachedImageOut = null;
    361369    RenderedImage image = null;
    362370    DbControl dc = null;
    363 
     371    boolean wasError = false;
    364372    try
    365373    {
    366       final SessionControl sc = Application.getSessionControl(ID, request.getRemoteAddr());
    367       dc = sc.newDbControl();
    368       BioAssay ba = bioAssayId == 0 ? null : BioAssay.getById(dc, bioAssayId);
    369       BioAssaySet bas = ba == null ? BioAssaySet.getById(dc, bioAssaySetId) : ba.getBioAssaySet();
     374      if (cacheKey != null)
     375      {
     376        cacheKey = cacheBase + cacheKey;
     377        StaticCache cache = Application.getStaticCache();
     378        try
     379        {
     380          cachedImageIn = cache.read(cacheKey);
     381          if (cachedImageIn == null)
     382          {
     383            cachedImageOut = cache.write(cacheKey);
     384          }
     385        }
     386        catch (IOException ex)
     387        {
     388          ex.printStackTrace();
     389        }
     390      }
     391      try
     392      {
     393        if (cachedImageIn == null)
     394        {
     395          // Only reload the image if there is no cached version
     396          final SessionControl sc = Application.getSessionControl(ID, request.getRemoteAddr());
     397          dc = sc.newDbControl();
     398          BioAssay ba = bioAssayId == 0 ? null : BioAssay.getById(dc, bioAssayId);
     399          BioAssaySet bas = ba == null ? BioAssaySet.getById(dc, bioAssaySetId) : ba.getBioAssaySet();
     400         
     401          JFreeChart chart = null;
     402          if ("cfplot".equals(type))
     403          {
     404            chart = generateCFPlot(ba, xLabel, yLabel);
     405          }
     406          else
     407          {
     408            // Get the query
     409            DynamicSpotQuery query = ba != null ? ba.getSpotData() : bas.getSpotData();
     410            query.setAutoJoinType(JoinType.INNER);
     411   
     412            // Filter
     413            Restriction filter = filterFormula == null ?
     414              null : BioAssaySetUtil.createJepRestriction(dc, bas, filterFormula, false);
     415           
     416            // Convert formulas to Expression:s
     417            Expression[] x = xFormulas == null ? null : new Expression[xFormulas.length];
     418            Expression[] y = yFormulas == null ? null : new Expression[yFormulas.length];
     419           
     420            if (xFormulas != null)
     421            {
     422              for (int i = 0; i < xFormulas.length; ++i)
     423              {
     424                x[i] = BioAssaySetUtil.createJepExpression(dc, bas, xFormulas[i], false);
     425                if (xLog) x[i] = Expressions.log2(x[i]);
     426              }
     427            }
     428            if (yFormulas != null)
     429            {
     430              for (int i = 0; i < yFormulas.length; ++i)
     431              {
     432                y[i] = BioAssaySetUtil.createJepExpression(dc, bas, yFormulas[i], false);
     433                if (yLog) y[i] = Expressions.log2(y[i]);
     434              }
     435            }
    370436     
    371       JFreeChart chart = null;
    372       if ("cfplot".equals(type))
    373       {
    374         chart = generateCFPlot(ba, xLabel, yLabel);
    375       }
    376       else
    377       {
    378         // Get the query
    379         DynamicSpotQuery query = ba != null ? ba.getSpotData() : bas.getSpotData();
    380         query.setAutoJoinType(JoinType.INNER);
    381 
    382         // Filter
    383         Restriction filter = filterFormula == null ?
    384           null : BioAssaySetUtil.createJepRestriction(dc, bas, filterFormula, false);
    385        
    386         // Convert formulas to Expression:s
    387         Expression[] x = xFormulas == null ? null : new Expression[xFormulas.length];
    388         Expression[] y = yFormulas == null ? null : new Expression[yFormulas.length];
    389        
    390         if (xFormulas != null)
    391         {
    392           for (int i = 0; i < xFormulas.length; ++i)
    393           {
    394             x[i] = BioAssaySetUtil.createJepExpression(dc, bas, xFormulas[i], false);
    395             if (xLog) x[i] = Expressions.log2(x[i]);
    396           }
    397         }
    398         if (yFormulas != null)
    399         {
    400           for (int i = 0; i < yFormulas.length; ++i)
    401           {
    402             y[i] = BioAssaySetUtil.createJepExpression(dc, bas, yFormulas[i], false);
    403             if (yLog) y[i] = Expressions.log2(y[i]);
    404           }
    405         }
    406  
    407         // Get annotations
    408         Collection<PlotAnnotation> annotations = null;
    409         if (hasAnnotation)
    410         {
    411           annotations = new TreeSet<PlotAnnotation>();
    412           List<BioAssay> bioAssays = bas.getBioAssays().list(dc);
    413           annotationSelect = Dynamic.select(VirtualColumn.COLUMN);
    414           if ("bioassay".equals(annotation))
    415           {
    416             for (BioAssay bioAssay : bioAssays)
     437            // Get annotations
     438            Collection<PlotAnnotation> annotations = null;
     439            if (hasAnnotation)
    417440            {
    418               annotations.add(new PlotAnnotation(bioAssay.getName(),
    419                 Collections.singleton(new Integer(bioAssay.getDataCubeColumnNo()))));
    420             }
    421           }
    422           else if (annotation.matches("\\d+"))
    423           {
    424             int annotationTypeId = Values.getInt(annotation);
    425             AnnotationType at = AnnotationType.getById(dc, annotationTypeId);
    426             Map<Set<?>, List<Integer>> groups = new HashMap<Set<?>, List<Integer>>();
    427             Formatter formatter = FormatterFactory.getTypeFormatter(sc, at.getValueType());
    428             if (at.supportUnits()) formatter = at.getDefaultUnit().getFormatter(formatter);
    429             for (BioAssay bioAssay : bioAssays)
    430             {
    431               Set<?> values = BioAssaySetUtil.getAnnotationValues(dc, bioAssay, at);
    432               if (!groups.containsKey(values))
     441              annotations = new TreeSet<PlotAnnotation>();
     442              List<BioAssay> bioAssays = bas.getBioAssays().list(dc);
     443              annotationSelect = Dynamic.select(VirtualColumn.COLUMN);
     444              if ("bioassay".equals(annotation))
    433445              {
    434                 groups.put(values, new ArrayList<Integer>());
     446                for (BioAssay bioAssay : bioAssays)
     447                {
     448                  annotations.add(new PlotAnnotation(bioAssay.getName(),
     449                    Collections.singleton(new Integer(bioAssay.getDataCubeColumnNo()))));
     450                }
    435451              }
    436               groups.get(values).add((int)bioAssay.getDataCubeColumnNo());
    437             }
    438             for (Map.Entry<Set<?>, List<Integer>> entry : groups.entrySet())
    439             {
    440               String name = Values.getString(entry.getKey(), ", ", true, formatter);
    441               if (name == null || name.trim().equals("")) name = "null";
    442               annotations.add(new PlotAnnotation(name, entry.getValue()));
    443             }
    444           }
    445           else if (annotation.startsWith("="))
    446           {
    447             // JEP restriction
    448             Restriction r =
    449               BioAssaySetUtil.createJepRestriction(dc, bas, annotation.substring(1), false);
    450             Expression e = Expressions.caseWhen(Expressions.integer(0),
    451                 new WhenStatement(r, Expressions.integer(1)));
    452             annotationSelect = Selects.expression(e, "ann");
    453             annotations.add(new PlotAnnotation("", 0));
    454             annotations.add(new PlotAnnotation(annotation.substring(1), 1));
    455           }
    456           else
    457           {
    458             Map<Set<Object>, List<Integer>> groups = new HashMap<Set<Object>, List<Integer>>();
    459             for (BioAssay bioAssay : bioAssays)
    460             {
    461               Set<Object> values = BioAssaySetUtil.getParentProperties(dc, bioAssay, annotation);
    462              
    463               if (!groups.containsKey(values))
     452              else if (annotation.matches("\\d+"))
    464453              {
    465                 groups.put(values, new ArrayList<Integer>());
     454                int annotationTypeId = Values.getInt(annotation);
     455                AnnotationType at = AnnotationType.getById(dc, annotationTypeId);
     456                Map<Set<?>, List<Integer>> groups = new HashMap<Set<?>, List<Integer>>();
     457                Formatter formatter = FormatterFactory.getTypeFormatter(sc, at.getValueType());
     458                if (at.supportUnits()) formatter = at.getDefaultUnit().getFormatter(formatter);
     459                for (BioAssay bioAssay : bioAssays)
     460                {
     461                  Set<?> values = BioAssaySetUtil.getAnnotationValues(dc, bioAssay, at);
     462                  if (!groups.containsKey(values))
     463                  {
     464                    groups.put(values, new ArrayList<Integer>());
     465                  }
     466                  groups.get(values).add((int)bioAssay.getDataCubeColumnNo());
     467                }
     468                for (Map.Entry<Set<?>, List<Integer>> entry : groups.entrySet())
     469                {
     470                  String name = Values.getString(entry.getKey(), ", ", true, formatter);
     471                  if (name == null || name.trim().equals("")) name = "null";
     472                  annotations.add(new PlotAnnotation(name, entry.getValue()));
     473                }
    466474              }
    467               groups.get(values).add((int)bioAssay.getDataCubeColumnNo());
    468             }
    469             for (Map.Entry<Set<Object>, List<Integer>> entry : groups.entrySet())
    470             {
    471               String name = Values.getString(entry.getKey(), ", ", true);
    472               if (name == null || name.trim().equals("")) name = "null";
    473               annotations.add(new PlotAnnotation(name, entry.getValue()));
     475              else if (annotation.startsWith("="))
     476              {
     477                // JEP restriction
     478                Restriction r =
     479                  BioAssaySetUtil.createJepRestriction(dc, bas, annotation.substring(1), false);
     480                Expression e = Expressions.caseWhen(Expressions.integer(0),
     481                    new WhenStatement(r, Expressions.integer(1)));
     482                annotationSelect = Selects.expression(e, "ann");
     483                annotations.add(new PlotAnnotation("", 0));
     484                annotations.add(new PlotAnnotation(annotation.substring(1), 1));
     485              }
     486              else
     487              {
     488                Map<Set<Object>, List<Integer>> groups = new HashMap<Set<Object>, List<Integer>>();
     489                for (BioAssay bioAssay : bioAssays)
     490                {
     491                  Set<Object> values = BioAssaySetUtil.getParentProperties(dc, bioAssay, annotation);
     492                 
     493                  if (!groups.containsKey(values))
     494                  {
     495                    groups.put(values, new ArrayList<Integer>());
     496                  }
     497                  groups.get(values).add((int)bioAssay.getDataCubeColumnNo());
     498                }
     499                for (Map.Entry<Set<Object>, List<Integer>> entry : groups.entrySet())
     500                {
     501                  String name = Values.getString(entry.getKey(), ", ", true);
     502                  if (name == null || name.trim().equals("")) name = "null";
     503                  annotations.add(new PlotAnnotation(name, entry.getValue()));
     504                }
     505               
     506              }
    474507            }
    475508           
    476           }
    477         }
    478        
    479         if (filter != null) query.restrictPermanent(filter);
    480  
    481         if ("scatter".equals(type))
    482         {
    483           ScatterPlot plot = new ScatterPlot(xLabel, yLabel);
    484           for (int i = 0; i < x.length; ++i)
    485           {
    486             query.reset();
    487             if (annotationSelect != null)
     509            if (filter != null) query.restrictPermanent(filter);
     510     
     511            if ("scatter".equals(type))
    488512            {
    489               query.select(annotationSelect);
    490             }
    491             query.select(Selects.expression(x[i], "x"));
    492             query.select(Selects.expression(y[i], "y"));
    493             if (hasAnnotation)
    494             {
    495               plot.addData(query.iterate(dc), annotations);
     513              ScatterPlot plot = new ScatterPlot(xLabel, yLabel);
     514              for (int i = 0; i < x.length; ++i)
     515              {
     516                query.reset();
     517                if (annotationSelect != null)
     518                {
     519                  query.select(annotationSelect);
     520                }
     521                query.select(Selects.expression(x[i], "x"));
     522                query.select(Selects.expression(y[i], "y"));
     523                if (hasAnnotation)
     524                {
     525                  plot.addData(query.iterate(dc), annotations);
     526                }
     527                else
     528                {
     529                  plot.addData(query.iterate(dc), Integer.toString(i));
     530                }
     531              }
     532              chart = plot.getChart();
    496533            }
    497534            else
    498535            {
    499               plot.addData(query.iterate(dc), Integer.toString(i));
     536              HistogramPlot plot = new HistogramPlot(xLabel, yLabel,
     537                hasAnnotation ? new XYStepRenderer() : null);
     538              query.setReturnTotalCount(true);
     539              for (int i = 0; i < x.length; ++i)
     540              {
     541                query.reset();
     542                if (annotationSelect != null)
     543                {
     544                  query.select(annotationSelect);
     545                }
     546                query.select(Selects.expression(x[i], "x"));
     547                if (!isCount) query.select(Selects.expression(y[i], "y"));
     548                HistogramPlot.YAggregate ya = HistogramPlot.YAggregate.valueOf(yAggregate.toUpperCase());
     549                HistogramPlot.YAggregate hilo = hiloAggregate == null ? null :
     550                  HistogramPlot.YAggregate.valueOf(hiloAggregate.toUpperCase());
     551                if (hasAnnotation)
     552                {
     553                  plot.addData(query.iterate(dc), annotations, binSize, ya, hilo);
     554                }
     555                else
     556                {
     557                  plot.addData(query.iterate(dc), Integer.toString(i), binSize, ya, hilo);
     558                }
     559              }
     560              chart = plot.getChart();
    500561            }
    501562          }
    502           chart = plot.getChart();
    503         }
    504         else
    505         {
    506           HistogramPlot plot = new HistogramPlot(xLabel, yLabel,
    507             hasAnnotation ? new XYStepRenderer() : null);
    508           query.setReturnTotalCount(true);
    509           for (int i = 0; i < x.length; ++i)
    510           {
    511             query.reset();
    512             if (annotationSelect != null)
     563         
     564          if (title != null) chart.setTitle(title);
     565          if (!hasAnnotation) chart.removeLegend();
     566          if (subTitle != null) chart.addSubtitle(new TextTitle(subTitle));
     567          image = chart.createBufferedImage(width, height);
     568        }
     569       
     570        // Store the image in the BASE file system
     571        if (saveAs != null)
     572        {
     573          Path path = new Path(saveAs, Path.Type.FILE);
     574          File f = File.getByPath(dc, path, true);
     575          f.setMimeType("image/"+format);
     576         
     577          if (f.isInDatabase())
     578          {
     579            if (!overwrite) throw new ItemAlreadyExistsException("File[path="+saveAs+"]");
     580          }
     581          else
     582          {
     583            dc.saveItem(f);
     584          }
     585          OutputStream out = f.getUploadStream(false);
     586          if (cachedImageIn != null)
     587          {
     588            FileUtil.copy(cachedImageIn, out);
     589            cachedImageIn.close();
     590            cachedImageIn = null;
     591          }
     592          else if (image != null)
     593          {
     594            if (cachedImageOut != null)
    513595            {
    514               query.select(annotationSelect);
     596              out = new TeeOutputStream(cachedImageOut, out);
    515597            }
    516             query.select(Selects.expression(x[i], "x"));
    517             if (!isCount) query.select(Selects.expression(y[i], "y"));
    518             HistogramPlot.YAggregate ya = HistogramPlot.YAggregate.valueOf(yAggregate.toUpperCase());
    519             HistogramPlot.YAggregate hilo = hiloAggregate == null ? null :
    520               HistogramPlot.YAggregate.valueOf(hiloAggregate.toUpperCase());
    521             if (hasAnnotation)
     598            ImageIO.write(image, format, out);
     599          }
     600          out.flush();
     601          out.close();
     602          dc.commit();
     603          image = null;
     604          cachedImageOut = null;
     605        }
     606      }
     607      catch (Throwable t)
     608      {
     609        wasError = true;
     610        t.printStackTrace();
     611        if (saveAs == null)
     612        {
     613          // Generate error image
     614          try
     615          {
     616            BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
     617            Graphics2D graphics = img.createGraphics();
     618            graphics.setBackground(Color.WHITE);
     619            graphics.clearRect(0, 0, width, height);
     620            graphics.setColor(Color.RED);
     621            FontRenderContext context = graphics.getFontRenderContext();
     622 
     623            Font topFont = new Font("SansSerif", Font.BOLD, 12);
     624            Font stackTraceFont = new Font("SansSerif", Font.PLAIN, 12);
     625 
     626            float x = .0f;
     627            float y = .0f;
     628            String causedBy = "";
     629            do
    522630            {
    523               plot.addData(query.iterate(dc), annotations, binSize, ya, hilo);
    524             }
    525             else
    526             {
    527               plot.addData(query.iterate(dc), Integer.toString(i), binSize, ya, hilo);
    528             }
    529           }
    530           chart = plot.getChart();
    531         }
    532       }
    533      
    534       if (title != null) chart.setTitle(title);
    535       if (!hasAnnotation) chart.removeLegend();
    536       if (subTitle != null) chart.addSubtitle(new TextTitle(subTitle));
    537       image = chart.createBufferedImage(width, height);
    538      
    539       if (saveAs != null)
    540       {
    541         Path path = new Path(saveAs, Path.Type.FILE);
    542         File f = File.getByPath(dc, path, true);
    543         f.setMimeType("image/"+format);
    544        
    545         if (f.isInDatabase())
    546         {
    547           if (!overwrite) throw new ItemAlreadyExistsException("File[path="+saveAs+"]");
    548         }
    549         else
    550         {
    551           dc.saveItem(f);
    552         }
    553         OutputStream out = f.getUploadStream(false);
    554         ImageIO.write(image, format, out);
    555         out.flush();
    556         out.close();
    557         dc.commit();
    558         image = null;
    559       }
    560     }
    561     catch (Throwable t)
    562     {
    563       t.printStackTrace();
    564       if (saveAs == null)
    565       {
    566         // Generate error image
    567         try
    568         {
    569           BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
    570           Graphics2D graphics = img.createGraphics();
    571           graphics.setBackground(Color.WHITE);
    572           graphics.clearRect(0, 0, width, height);
    573           graphics.setColor(Color.RED);
    574           FontRenderContext context = graphics.getFontRenderContext();
    575 
    576           Font topFont = new Font("SansSerif", Font.BOLD, 12);
    577           Font stackTraceFont = new Font("SansSerif", Font.PLAIN, 12);
    578 
    579           float x = .0f;
    580           float y = .0f;
    581           String causedBy = "";
    582           do
    583           {
    584             graphics.setFont(topFont);
    585             String msg = causedBy + t.getClass().getSimpleName() + ": " + t.getMessage();
    586             x = 5.0f;
    587             Rectangle2D bounds = topFont.getStringBounds(msg, context);
    588             y += bounds.getHeight()+5;
    589             if (bounds.getWidth() > width - x)
    590             {
    591               msg = cutMiddle(msg, (width - x) / bounds.getWidth());
    592             }
    593             graphics.drawString(msg, x, y);
    594            
    595             graphics.setFont(stackTraceFont);
    596             x = 15.0f;
    597             for (StackTraceElement st : t.getStackTrace())
    598             {
    599               msg = "at " + st.getClassName() + "." + st.getMethodName() +
    600                 ":" + st.getLineNumber();
    601               bounds = stackTraceFont.getStringBounds(msg, context);
    602               y += bounds.getHeight();
     631              graphics.setFont(topFont);
     632              String msg = causedBy + t.getClass().getSimpleName() + ": " + t.getMessage();
     633              x = 5.0f;
     634              Rectangle2D bounds = topFont.getStringBounds(msg, context);
     635              y += bounds.getHeight()+5;
    603636              if (bounds.getWidth() > width - x)
    604637              {
     
    606639              }
    607640              graphics.drawString(msg, x, y);
    608             }
    609             t = t.getCause();
    610             causedBy = "Caused by: ";
    611           } while (t != null && y < height);
    612           image = img;
    613         }
    614         catch (Throwable t2)
    615         {
    616           t2.printStackTrace();
    617         }
    618       }
    619       else
    620       {
    621         // Let servlet container redirect to appropriate error page
    622         throw new ServletException(t);
    623       }
    624     }
    625     finally
     641             
     642              graphics.setFont(stackTraceFont);
     643              x = 15.0f;
     644              for (StackTraceElement st : t.getStackTrace())
     645              {
     646                msg = "at " + st.getClassName() + "." + st.getMethodName() +
     647                  ":" + st.getLineNumber();
     648                bounds = stackTraceFont.getStringBounds(msg, context);
     649                y += bounds.getHeight();
     650                if (bounds.getWidth() > width - x)
     651                {
     652                  msg = cutMiddle(msg, (width - x) / bounds.getWidth());
     653                }
     654                graphics.drawString(msg, x, y);
     655              }
     656              t = t.getCause();
     657              causedBy = "Caused by: ";
     658            } while (t != null && y < height);
     659            image = img;
     660          }
     661          catch (Throwable t2)
     662          {
     663            t2.printStackTrace();
     664          }
     665        }
     666        else
     667        {
     668          // Let servlet container redirect to appropriate error page
     669          throw new ServletException(t);
     670        }
     671      }
     672     
     673      if (image != null || cachedImageIn != null)
     674      {
     675        // Send image on HTTP response
     676        if (download)
     677        {
     678          response.setHeader("Content-Disposition", "attachment;filename="+HTML.urlEncode(title)+"." + format);
     679        }
     680        response.setContentType("image/" + format);
     681        response.setHeader("Cache-Control", "max-age=3600");
     682        OutputStream out = response.getOutputStream();
     683        if (cachedImageIn != null)
     684        {
     685          FileUtil.copy(cachedImageIn, out);       
     686        }
     687        else if (image != null)
     688        {
     689          if (cachedImageOut != null && !wasError)
     690          {
     691            out = new TeeOutputStream(out, cachedImageOut);
     692          }
     693          ImageIO.write(image, format, out);
     694        }
     695        out.flush();
     696        out.close();
     697      }
     698      else
     699      {
     700        if (saveAs != null)
     701        {
     702          // Image was save to BASE filesystem, redirect to close popup page
     703          response.sendRedirect(request.getContextPath()+"/common/close_popup.jsp?message=Plot+saved+successfully");
     704        }
     705        else
     706        {
     707          // Something went wrong when genering the error image - send redirect to a predefined image
     708          response.sendRedirect(request.getContextPath() + "/images/plot_error.gif");
     709        }
     710      }
     711    }
     712    finally
    626713    {
    627714      if (dc != null) dc.close();
    628     }
    629    
    630     if (image != null)
    631     {
    632       if (download)
    633       {
    634         response.setHeader("Content-Disposition", "attachment;filename="+HTML.urlEncode(title)+"." + format);
    635       }
    636       response.setContentType("image/" + format);
    637       response.setHeader("Cache-Control", "max-age=3600");
    638       OutputStream out = response.getOutputStream();
    639       ImageIO.write(image, format, out);     
    640       out.flush();
    641       out.close();
    642     }
    643     else
    644     {
    645       if (saveAs != null)
    646       {
    647         // Image was save to BASE filesystem, redirect to close popup page
    648         response.sendRedirect(request.getContextPath()+"/common/close_popup.jsp?message=Plot+saved+successfully");
    649       }
    650       else
    651       {
    652         // Something went wrong when genering the error image - send redirect to a predefined image
    653         response.sendRedirect(request.getContextPath() + "/images/plot_error.gif");
    654       }
     715      if (cachedImageIn != null) cachedImageIn.close();
     716      if (cachedImageOut != null) cachedImageOut.close();
    655717    }
    656718  }
  • trunk/www/views/experiments/bioassaysets/view_bioassayset.jsp

    r4669 r4825  
    524524          String url = "../plotter/plot?ID="+ID+"&bioassay_id="+bioAssay.getId();
    525525          url += "&type=scatter&width=400&height=300";
     526          url += "&cache=overview/bioassay." + bioAssay.getId() + "/maplot.png";
    526527          url += "&x="+A+"&y="+M+"&xLabel="+xLabel+"&yLabel="+yLabel;
    527528          url += "&filter="+filter;
     
    562563          String url = "../plotter/plot?ID="+ID+"&bioassay_id="+bioAssay.getId();
    563564          url += "&type=cfplot&width=400&height=300";
     565          url += "&cache=overview/bioassay." + bioAssay.getId() + "/cfplot.png";
    564566          url += "&xLabel="+xLabel+"&yLabel="+yLabel;
    565567          url += "&title="+HTML.urlEncode(bioAssay.getName());
Note: See TracChangeset for help on using the changeset viewer.