Main Page | Packages | Class Hierarchy | Class List | Directories | File List | Class Members | Related Pages

ServletUtils Class Reference

List of all members.

Detailed Description

Utilities for servlet access to the data base and for job submission (via JobRequest).
Author:
Jon & Susanna Butterworth

Definition at line 46 of file ServletUtils.java.


Static Public Member Functions

ResultSearchPattern makePattern (HttpServletRequest request) throws JetWebException
PlotSelection makePlotSelection (HttpServletRequest request)
void performResultSearch (ResultSearchPattern pattern, PrintWriter out, String servletPath, PlotSelection selection, HttpServletRequest request)
void updateConfig (HttpServletRequest request)
void editFit (HttpServletRequest request, PrintWriter out, String servletPath) throws JetWebException
void changePaper (HttpServletRequest request, PrintWriter out)
void modifyPlots (HashMap< String, String > parameters, Paper paper) throws JetWebException
void addPlot (HashMap< String, String > parameters, Paper paper, String inKey) throws JetWebException
void generatorDefaults (HttpServletRequest request)
Vector< MCProcessTypemakeMCProcessList (HttpServletRequest request) throws JetWebException
void getGeneratorParameters (HttpServletRequest request, Generator gen) throws JetWebException
void deletePlots (HashMap< String, String > parameters, Paper paper) throws JetWebException
void deletePaper (HttpServletRequest request) throws JetWebException
MCProcessType buildProc (HttpServletRequest request) throws JetWebException

Static Private Member Functions

void decodeSwitch (HashMap< String, String > parameters, PlotSwitch ps, String label)
void getCuts (HttpServletRequest request, Generator gen)
void initCuts ()

Static Private Attributes

boolean initCuts_ = true
HashMap< String, String > allowedCuts_

Member Function Documentation

void addPlot HashMap< String, String >  parameters,
Paper  paper,
String  inKey
throws JetWebException [static]
 

Add a plot which has parameters matching the given key to the given Paper .

Definition at line 463 of file ServletUtils.java.

References DataPlot.addSwitch(), JetWebPlotReader.fillPlot(), DataPlot.getId(), DataPlot.getNumber(), DataPlot.setCollisionId(), DataPlot.setDefaultSum(), JetWebPlotReader.setDirectory(), DataPlot.setLogarithmic(), PlotSwitch.setMCProcessTypeId(), DataPlot.setNumber(), PlotSwitch.setPlotId(), RealPlot.setScale(), DataPlot.setShape(), DataPlot.setTitle(), DataPlot.setXLabel(), DataPlot.setYLabel(), PlotSwitch.store(), and RealPlot.store().

00463                                                                                                                    {
00464         
00465 
00466     System.out.println("Adding plot to paper "+paper.getId());
00467 
00468     String key = "-" + inKey;
00469 
00470     int newPlotId = paper.getNPlots();
00471     //RealPlot plot = new RealPlot(newPlotId,paper.getId());        
00472 
00473     String title = parameters.get("TITLE"+key);
00474     String hzsteerPlotId = parameters.get("HZSTEERPLOTID");
00475     String hzsteerPlotName = parameters.get("HZSTEERPLOT");
00476     String mcPlotId = parameters.get("HZMCPLOTID");
00477 
00478     RealPlot plot;
00479 
00480     Integer mcid = -1;
00481 
00482     if(hzsteerPlotId!=null &&
00483        !hzsteerPlotId.equals("")){
00484 
00485         Integer hpid;
00486         try{
00487         hpid = Integer.parseInt(hzsteerPlotId);
00488         if(mcPlotId!=null || !mcPlotId.equals("")){
00489             mcid = Integer.parseInt(mcPlotId);
00490         }else{
00491             mcid = -hpid;
00492             System.out.println
00493             ("Warning: plot id for MC plot not specified - " + 
00494              "assuming the negative of the data plot id");
00495         }
00496         }catch(NumberFormatException err){
00497         throw new JetWebException(err);
00498         }
00499 
00500         System.out.println("Using plot id " + hpid +
00501                    " for paper "+paper.getId());
00502 
00503         plot = new RealPlot(hpid, paper.getId());
00504     }else{
00505         System.out.println("Using plot id " + newPlotId +
00506                    " for paper "+paper.getId());
00507         plot = new RealPlot(newPlotId,paper.getId());
00508     }
00509     if (title != null){
00510 
00511         plot.setTitle(title);
00512         plot.setXLabel(parameters.get("XLABEL"+key));
00513         plot.setYLabel(parameters.get("YLABEL"+key));
00514         PlotSwitch pSwitch = new PlotSwitch();
00515         try {
00516         double scaleFactor 
00517             = Double.parseDouble(parameters.get("SCALE"+key));
00518         plot.setScale(scaleFactor);
00519         
00520         boolean tf = 
00521             (Boolean.valueOf(parameters.get("DEFSUM"+key))).booleanValue();
00522         plot.setDefaultSum(tf);
00523         
00524         tf = (Boolean.valueOf(parameters.get("ISSHAPE"+key))).booleanValue();;
00525         plot.setShape(tf);
00526         
00527         tf = (Boolean.valueOf(parameters.get("ISLOG"+key))).booleanValue();;
00528         plot.setLogarithmic(tf);
00529         
00530         //int procId = Integer.parseInt(parameters.get("DEFPROC"+key));
00531         //plot.setMCProcessType(new MCProcessType(procId));
00532             // Should be done via swtich.
00533         
00534         } catch (Exception e) {
00535         throw new JetWebException(e,"Error parsing plot parameters");
00536         }
00537 
00538         String path = JetWebConfig.rootDirectory+"/"+JetWebConfig.plotCacheDirName
00539         +"/"+paper.getDirName();
00540 
00541         try {
00542         System.out.println("Paper Directory is:"+paper.getDirName());
00543         File xmlFile = new File(path+"/plot-"+key+".xml");
00544         String xmlFileString = path + "/plot" + 
00545             plot.getNumber()+"."+JetWebConfig.graphicsType;
00546 
00547         System.out.println(parameters);
00548         System.out.println("hzsteerPlotId = "+hzsteerPlotId);
00549         System.out.println("hzsteerPlotName = "+hzsteerPlotName);
00550 
00551         if (!xmlFile.exists()) {
00552 
00553             if(hzsteerPlotId!=null &&
00554                !hzsteerPlotId.equals("") &&
00555                hzsteerPlotName!=null && 
00556                !hzsteerPlotName.equals("")){
00557             xmlFile = new File(hzsteerPlotName);
00558             xmlFileString = hzsteerPlotName.
00559                 substring(0, hzsteerPlotName.lastIndexOf("/"));
00560             xmlFileString = xmlFileString + 
00561                 "/plot" + hzsteerPlotId + ".aida";
00562             }else{
00563 
00564             System.out.println("Cannot find plot file " +
00565                        xmlFile.getPath());
00566 
00567             throw new JetWebException
00568                 (xmlFile.getPath(),"File does not exist");
00569             }
00570         }
00571 
00572         File standardXML = new File(xmlFileString);
00573         xmlFile.renameTo(standardXML); 
00574 
00575         
00576         //      plot.readPointsFromXML();
00577         System.out.println("Trying to read "+xmlFileString);
00578         JetWebPlotReader reader = 
00579             JetWebPlotReaderFactory.getNewPlotReader(xmlFileString);
00580         //JetWebPlotReader reader = 
00581         //  JetWebPlotReaderFactory.getNewPlotReader(hzsteerPlotName);
00582         reader.setDirectory(paper.getDirName());
00583         reader.fillPlot(plot);
00584         plot.setNumber(mcid);
00585         String colIdString = parameters.get("COLL"+key);
00586         System.out.println("colIdString = "+colIdString);
00587         if(colIdString!=null && !colIdString.equals("")){
00588             int colId = Integer.parseInt(colIdString);
00589             System.out.println("Setting plot collision id to "+colId);
00590             plot.setCollisionId(colId);
00591         }
00592         //plot.setDataPoints(reader.getDataPoints());
00593         } catch (Exception e){
00594         throw new 
00595             JetWebException(e, "Corrupt XML file: plot not updated."+
00596                     "Paper: "+paper.getId()+": plot "+plot.getNumber());
00597         }
00598 
00599         try {
00600         plot.store();
00601         pSwitch.setPlotId(plot.getId());
00602         System.out.println("PROCNEW"+key);
00603         String procnew = parameters.get("PROCNEW"+key);
00604         Integer pid = 0;
00605         if(procnew!=null){
00606             pid = Integer.parseInt(procnew);
00607         
00608             
00609             pSwitch.setMCProcessTypeId(pid);
00610             pSwitch.store();
00611             plot.addSwitch(pSwitch);
00612         }
00613         System.out.println("back from plot.store()");
00614         } catch (JetWebException jwdb){
00615         throw new JetWebException(jwdb,"Error adding plot");
00616         }
00617 
00618         JetWebHist.writeGraphics(plot,path);
00619     }
00620     return;
00621     }

MCProcessType buildProc HttpServletRequest  request  )  throws JetWebException [static]
 

Build an MCProcessType from a servlet request.

Definition at line 917 of file ServletUtils.java.

References MCProcessType.setCollision(), MCProcessType.setCompatibleProcesses(), MCProcessType.setId(), MCProcessType.setIsValid(), and MCProcessType.setMCProcessName().

00917                                                                                              {
00918 
00919     MCProcessType proc = new MCProcessType();
00920  
00921     try {
00922         String[] tmp = request.getParameterValues("PROCESSID");
00923         Integer id = Integer.parseInt(tmp[0]);
00924         proc.setId(id);
00925     } catch (Exception e){
00926         throw new JetWebException(e,"proc id");
00927     }
00928 
00929     try {
00930         String[] tmp = request.getParameterValues("COLLISIONID");
00931         Collision coll = new Collision(Integer.parseInt(tmp[0]));
00932         proc.setCollision(coll);
00933     } catch (Exception e){
00934         throw new JetWebException(e,"collision");
00935     }
00936 
00937     try {
00938         String[] tmp = request.getParameterValues("ISVALID");       
00939         proc.setIsValid(Boolean.parseBoolean(tmp[0]));
00940     } catch (Exception e){
00941         throw new JetWebException(e,"valid");
00942     }
00943 
00944 
00945     try {
00946         String[] tmp = request.getParameterValues("PROCNAME");
00947         proc.setMCProcessName(tmp[0]);
00948     } catch (Exception e){
00949         throw new JetWebException(e,"process name");
00950     }
00951 
00952     // Now parse the string of compatible process types
00953     try {
00954         String[] tmp = request.getParameterValues("PLIST");
00955         //System.out.println(tmp[0]);
00956         Vector<Integer> plist = new Vector<Integer>();
00957 
00958         Scanner sc = new Scanner(tmp[0]).useDelimiter(":");
00959         while (sc.hasNextInt()){
00960         plist.add(sc.nextInt());
00961         }
00962         sc.close(); 
00963         proc.setCompatibleProcesses(plist);
00964 
00965     } catch (Exception e){
00966         throw new JetWebException(e,"compatible proc list");
00967     }
00968 
00969 
00970     return proc;
00971 
00972     }

void changePaper HttpServletRequest  request,
PrintWriter  out
[static]
 

Update a paper in the DB using the information in the servlet request.

Definition at line 324 of file ServletUtils.java.

References Paper.setAccelerator(), Paper.setCodeAuthor(), Paper.setCollaboration(), Paper.setContact(), Paper.setDirName(), Paper.setIRN(), Paper.setReference(), Paper.setTitle(), and Paper.store().

00324                                                                               {
00325 
00326     System.out.println("Changing paper!");
00327 
00328     try {
00329         int paperId= Integer.parseInt(request.getParameter("PAPERID"));     
00330         Paper paper = new Paper(paperId);
00331 
00332         paper.setTitle(request.getParameter("TITLE").trim());
00333         paper.setIRN(Integer.parseInt(request.getParameter("IRN").trim()));
00334         paper.setReference(request.getParameter("REFERENCE").trim());
00335         paper.setCollaboration(request.getParameter("COLLABORATION").trim());
00336         paper.setContact(request.getParameter("CONTACT").trim());
00337         paper.setCodeAuthor(request.getParameter("CODEAUTHOR").trim());
00338         paper.setAccelerator(request.getParameter("ACCELERATOR").trim());
00339         paper.setDirName(request.getParameter("DIRECTORY").trim());
00340 
00341         boolean existed = !paper.store();
00342 
00343     } catch (NumberFormatException e){
00344         e.printStackTrace(System.out);
00345     } catch (JetWebException jwe){
00346         HTMLErrorWriter.write(out,jwe);
00347 
00348     }
00349     }

void decodeSwitch HashMap< String, String >  parameters,
PlotSwitch  ps,
String  label
[static, private]
 

Definition at line 657 of file ServletUtils.java.

References PlotSwitch.setGeneratorName(), PlotSwitch.setGeneratorVersion(), PlotSwitch.setMCProcessTypeId(), PlotSwitch.setParameterName(), PlotSwitch.setParameterValueHigh(), and PlotSwitch.setParameterValueLow().

00659                                   {
00660     
00661     String proca = parameters.get("PROC"+label);
00662     if (proca != null && !proca.trim().equals("undefined")) {
00663 
00664         ps.setMCProcessTypeId(Integer.parseInt(proca));
00665 
00666         try {
00667         String name = parameters.get("PARMNAME"+label);
00668         if (!name.trim().equals("undefined") 
00669             && !name.trim().equalsIgnoreCase("undefined/any")
00670             && !name.trim().equalsIgnoreCase("null")){
00671             ps.setParameterName(name);
00672         } else {
00673             ps.setParameterName(null);
00674         }
00675         
00676         try {
00677             ps.setParameterValueHigh(Double.parseDouble(parameters.get("PARMVALH"
00678                                            +label)));
00679         } catch (Exception e){
00680             // do nothing
00681         }
00682         try {
00683             ps.setParameterValueLow(Double.parseDouble(parameters.get("PARMVALL"
00684                                           +label)));
00685         } catch (Exception e){
00686             // Do nothing.
00687         }
00688         } catch (Exception e){
00689         // Do nothing
00690         }
00691         
00692 
00693 
00694         try {
00695         String name = parameters.get("GEN"+label);
00696         if (!name.trim().equalsIgnoreCase("undefined") 
00697             && !name.trim().equalsIgnoreCase("undefined/any")
00698             && !name.trim().equalsIgnoreCase("null")){
00699             ps.setGeneratorName(name);
00700             //System.out.println("Name: "+name);
00701         } else {
00702             ps.setGeneratorName(null);
00703         }
00704         } catch (Exception e){
00705         // Do nothing.
00706         }
00707         
00708         
00709         try {
00710         ps.setGeneratorVersion(Double.parseDouble(parameters.get("VAL"+label)));
00711         } catch (Exception e){
00712         // Do nothing.
00713         }
00714         
00715 
00716     }
00717 
00718     }

void deletePaper HttpServletRequest  request  )  throws JetWebException [static]
 

Delete the paper and all plots associated with it, based on the parameters passed.

Definition at line 902 of file ServletUtils.java.

References Paper.delete(), and Paper.getId().

00903                            {
00904     
00905     int paperId= Integer.parseInt(request.getParameter("PAPERID"));     
00906     Paper paper = new Paper(paperId);
00907         
00908     System.out.println("Requested deletion of paper "+paper.getId());
00909     paper.delete();
00910 
00911     }

void deletePlots HashMap< String, String >  parameters,
Paper  paper
throws JetWebException [static]
 

Delete the plots associated with a paper based on the parameters passed.

Definition at line 874 of file ServletUtils.java.

References RealPlot.delete().

00875                                                        {
00876     
00877     Vector<DataPlot> togo = new Vector<DataPlot>();
00878     Collection<? extends DataPlot> plotList = paper.getPlots();
00879 
00880     for (DataPlot plot : plotList){
00881         
00882         int num = plot.getNumber();
00883         
00884         String deleteMe = parameters.get("DELETEPLOT"+num);
00885         if (deleteMe != null){
00886         
00887         System.out.println("Requested deletion of plot "
00888                    +plot.getNumber()+", id "+plot.getId()
00889                    +", paper "+paper.getId());
00890         RealPlot rplot = (RealPlot)plot;
00891         rplot.delete();
00892         togo.add(plot);
00893         }
00894     }
00895     plotList.removeAll(togo);
00896     }

void editFit HttpServletRequest  request,
PrintWriter  out,
String  servletPath
throws JetWebException [static]
 

Edit/delete/force update for fit.

Definition at line 247 of file ServletUtils.java.

References HTMLWriter.close(), HTMLFitWriter.display(), HTMLWriter.setVerbose(), and Fit.update().

00249                           {
00250 
00251     int fitId   = Integer.parseInt(request.getParameter("FITID"));
00252     
00253     if (request.getParameter("FITACTION").equals("REDO")){
00254         
00255         System.out.println("Redoing Fit "+fitId);
00256         Fit fit = new Fit(fitId);
00257         fit.update(true);
00258         HTMLFitWriter op = new HTMLFitWriter(out,servletPath);
00259         op.setVerbose(true);
00260         op.display(fit);
00261         op.close();
00262     }
00263     /*      
00264     } else if (request.getParameter("FITACTION").equals("ZERO")){
00265         
00266         // Zero the chi2 etc for the fit, and the data for all the
00267         // predicted and fitted plots.  Remove the index file.
00268         // Then move the input log and aida files into the run/edit
00269         // directory.  Optionally, then regenerate the fit
00270         // immediately.
00271         
00272         // Force an update of the fit.
00273         // (turn off plots first)
00274         boolean temp = JetWebConfig.writePlots;
00275         JetWebConfig.writePlots=false;
00276         Fit fit = new Fit(fitId);
00277         JetWebConfig.writePlots=temp;
00278         
00279         Model model = fit.getModel();
00280         MCProcessType proc = new MCProcessType();
00281 
00282         // Zero the data associated with this fit.
00283         if (request.getParameter("REMOVEEE")!=null) {
00284         proc.setParticle1(Collision.ELECTRON);
00285         proc.setParticle2(Collision.POSITRON);
00286         model.zero(proc);
00287         }
00288         
00289         if (request.getParameter("REMOVEEP")!=null) {
00290         proc.setParticle1(Collision.ELECTRON);
00291         proc.setParticle2(Collision.PROTON);
00292         model.zero(proc);
00293         }
00294         
00295         if (request.getParameter("REMOVEPP")!=null) {
00296         proc.setParticle1(Collision.PROTON);
00297         proc.setParticle2(Collision.ANTIPROTON);
00298         model.zero(proc);
00299         }
00300 
00301         // Zero all the fitted stuff.
00302         fit.zero();
00303         
00304         HTMLWriter op = new HTMLWriter(out,servletPath);
00305         op.forwardTo(JetWebConfig.getHTMLRoot()
00306              +"/"+JetWebConfig.plotCacheDirName
00307              +"/"+fitId+"/index.html");
00308         
00309     } else if (request.getParameter("FITACTION").equals("REMOVE")){
00310         
00311         Fit.delete(fitId);
00312         HTMLUtils.writeControlScreen("Remove Fit "+fitId,null,null,out,
00313                    servletPath);
00314         
00315     }
00316     */
00317     }

void generatorDefaults HttpServletRequest  request  )  [static]
 

Definition at line 623 of file ServletUtils.java.

00623                                                                     {
00624 
00625     System.out.println("called generatorDefaults");
00626     
00627     try{
00628 
00629     MultipartParser mp = 
00630         new MultipartParser(request, 10*1024*1024); // 10MB
00631     
00632     Part part;
00633     while ((part = mp.readNextPart()) != null) {
00634 
00635         String name = part.getName();
00636 
00637         if (part.isFile()) {
00638     
00639         String destDirName = 
00640             "/home/jmonk/Cedar/Java/tomcat50-jwsdp/mouse/";
00641         
00642         File destDir = new File(destDirName);
00643         
00644         FilePart filePart = (FilePart) part;
00645         
00646         filePart.writeTo(destDir);
00647         
00648         }
00649     }
00650     }catch (Throwable e){
00651         System.out.println(e.getMessage());
00652     }
00653     return;
00654     }

void getCuts HttpServletRequest  request,
Generator  gen
[static, private]
 

Definition at line 840 of file ServletUtils.java.

00840                                                                           {
00841     
00842     initCuts();
00843 
00844     for(Map.Entry entry: allowedCuts_.entrySet()){
00845 
00846         String HTMLName = (String)entry.getKey();
00847         String CutName = (String) entry.getValue();
00848         //String[] tmp = request.getParameterValues("GENPTMIN");
00849         String[] tmp = request.getParameterValues(HTMLName);
00850         if(tmp!=null && tmp.length==1){
00851         Cut cut = new Cut(CutName, Double.parseDouble(tmp[0]));
00852         gen.addCut(cut);
00853         }else{
00854         System.out.println("Using " +
00855                    CutName + 
00856                    " from generator defaults");
00857         }
00858     }
00859     return;
00860     }

void getGeneratorParameters HttpServletRequest  request,
Generator  gen
throws JetWebException [static]
 

Get the parameters for the generator from the servlet request.

Definition at line 773 of file ServletUtils.java.

00775                            {
00776 
00777     if (gen==null) return;
00778     
00779     // We already know the generator, so lets loop over the
00780     // generator parameters and look for appropriate settings
00781     Set<Map.Entry<String,Integer>> intParameters;
00782     Set<Map.Entry<String,Double>>  realParameters;
00783     Set<Map.Entry<String,HashMap<Integer,Integer>>> intArrays;
00784     Set<Map.Entry<String,HashMap<Integer,Double>>> realArrays;
00785 
00786     String[] tmp;
00787 
00788     // Set the integer parameters.
00789     Set<String> names = gen.getIntNames(); 
00790     for (String pname : names){
00791         tmp = request.getParameterValues(pname);
00792         if (tmp!=null && !tmp[0].trim().equals("")) {
00793         gen.setParameter(pname,Integer.parseInt(tmp[0].trim()));
00794         }
00795     } 
00796 
00797     // Now the real parameters.
00798     names = gen.getRealNames(); 
00799     for (String pname : names){
00800         tmp = request.getParameterValues(pname);
00801         if (tmp!=null && !tmp[0].trim().equals("")) {
00802         gen.setParameter(pname,Double.parseDouble(tmp[0].trim()));
00803         }
00804     } 
00805     
00806     // Now the integer arrays.
00807     intArrays = gen.getIntParameterArrays().entrySet(); 
00808     names = gen.getIntArrayNames();
00809     String pname;
00810     for (String aname : names){
00811 
00812         for (int i=gen.getMinIndex(aname); i<gen.getMaxIndex(aname);i++){
00813         pname = aname+"-"+i;
00814         tmp = request.getParameterValues(pname);
00815         if (tmp!=null && !tmp[0].trim().equals("")) {
00816             gen.setIntElement(aname,i,Integer.parseInt(tmp[0].trim()));
00817         }
00818         }
00819     }
00820 
00821     // Now the real arrays.
00822     realArrays = gen.getRealParameterArrays().entrySet(); 
00823     names = gen.getRealArrayNames();
00824     for (String aname : names){
00825 
00826         for (int i=gen.getMinIndex(aname); i<gen.getMaxIndex(aname);i++){
00827         pname = aname+"-"+i;
00828         tmp = request.getParameterValues(pname);
00829         if (tmp!=null && !tmp[0].trim().equals("")) {
00830             gen.setRealElement(aname,i,Double.parseDouble(tmp[0].trim()));
00831         }
00832         }
00833     }
00834     
00835     getCuts(request, gen);
00836     return;
00837     }

void initCuts  )  [static, private]
 

Definition at line 862 of file ServletUtils.java.

00862                                   {
00863     if(initCuts_){
00864         initCuts_ = false;
00865         allowedCuts_.put("GENPTMIN", "PTMin");
00866     }
00867     return;
00868     }

Vector<MCProcessType> makeMCProcessList HttpServletRequest  request  )  throws JetWebException [static]
 

Return a Vector full of MCProcessTypes made from the servlet request.

Definition at line 724 of file ServletUtils.java.

References MCProcessType.isValid().

00725                            {
00726     
00727     Vector<MCProcessType> processList = new Vector<MCProcessType>();
00728 
00729     String[] procList = request.getParameterValues("SELECTEDPROCESSID");
00730 
00731     if (procList!=null){
00732         try { 
00733         for (int i=0; i<procList.length;i++){   
00734             
00735             MCProcessType proc 
00736             = new MCProcessType(Integer.parseInt(procList[i]));
00737 
00738             if(proc.isValid()){// html page shouldn't even offer
00739                            // the possibility to generate a 
00740                            // non-valid proc, no harm in checking!
00741 
00742             /* no - just generate the main processes as single runs.
00743             Vector<Integer> compatProcIds = 
00744                 proc.getCompatibleProcesses();
00745 
00746             for(Integer id: compatProcIds){
00747                 
00748                 MCProcessType componentProc = 
00749                 new MCProcessType(id);
00750 
00751 
00752                 if (!processList.contains(componentProc)){
00753                 processList.add(componentProc);
00754                 }
00755             */
00756             if (!processList.contains(proc)){
00757                 processList.add(proc);
00758             }
00759             }
00760         }
00761         } catch (NumberFormatException e){
00762         throw new JetWebException(e,"Failed to build list of processTypes");
00763         }       
00764     }
00765 
00766     return processList;
00767 
00768     }

ResultSearchPattern makePattern HttpServletRequest  request  )  throws JetWebException [static]
 

Make a ResultSearchPattern based upon a HTTP servlet request.

Parameters:
request 
Returns:
resultSearchPattern
Exceptions:
JetWebException 

Definition at line 59 of file ServletUtils.java.

References ResultSearchPattern.getGenerator(), ResultSearchPattern.getGeneratorList(), ResultSearchPattern.getPhotonPDFList(), ResultSearchPattern.getProtonPDFList(), PDF.isPhoton(), PDF.isProton(), and ResultSearchPattern.setDescription().

00060                            {
00061 
00062     ResultSearchPattern pattern;
00063 
00064     if(request.getParameterValues("MOREDATA")!=null ||
00065        request.getParameterValues("SIMILARDATA")!=null ||
00066        request.getParameterValues("FINDDATA")!=null 
00067        ){
00068 
00069         // Build a result search pattern from the model Id.
00070         String[] tmp = request.getParameterValues("MODELID");
00071         try {
00072         int modelId = Integer.parseInt(tmp[0]);
00073         pattern = new Model(modelId);
00074 
00075         } catch (NumberFormatException e) {
00076         System.out.println(e);
00077         pattern = new ResultSearchPattern();
00078         }       
00079         
00080         getCuts(request, pattern.getGenerator());
00081 
00082         return pattern;
00083     }
00084 
00085     pattern = new ResultSearchPattern();
00086     
00087     String[] tmp = request.getParameterValues("DESCRIPTION");
00088     if(tmp!=null&&tmp.length!=0){
00089         pattern.setDescription(tmp[0]);
00090     }
00091     // Generator
00092     tmp = request.getParameterValues("GENERATOR");
00093     try {
00094         for (int i=0; i<tmp.length;i++){
00095         // generator properies should be of the format name-version
00096         //int id = Integer.parseInt(tmp[i]);
00097         String name = tmp[i].substring(0,tmp[i].indexOf("-")); 
00098         String version = tmp[i].substring(tmp[i].indexOf("-")+1);
00099         //System.out.println("adding "+name+" "+version);
00100         pattern.getGeneratorList().add(Generator.Maker(name,version));
00101         }
00102         
00103     } catch (NullPointerException e){}
00104 
00105 
00106 
00107     try {
00108         Vector<String> pdfs = new Vector<String>();
00109         pdfs.addAll(Arrays.asList(request.getParameterValues("PHOTONPDF")));
00110         pdfs.addAll(Arrays.asList(request.getParameterValues("PROTONPDF")));
00111 
00112         for(String pdfStr: pdfs){
00113 
00114         PDF pdf = new PDF(pdfStr);
00115         if(pdf.isPhoton()) pattern.getPhotonPDFList().add(pdf);
00116         if(pdf.isProton()) pattern.getProtonPDFList().add(pdf);
00117         }
00118 
00119     } catch (NullPointerException e){}
00120     
00121     getGeneratorParameters(request,pattern.getGenerator());
00122     return pattern;
00123     }

PlotSelection makePlotSelection HttpServletRequest  request  )  [static]
 

Build a PlotSelection from a servlet request.

Definition at line 130 of file ServletUtils.java.

References PlotSelection.getFitPlots(), and PlotSelection.getSumPlots().

00130                                                                               {
00131 
00132     PlotSelection selection = new PlotSelection();
00133 
00134     String[] sumplots = request.getParameterValues("SUMPLOT");
00135     String[] fitplots = request.getParameterValues("FITPLOT");
00136 
00137     try {
00138 
00139         if (sumplots!=null){
00140         for (int i=0; i<sumplots.length;i++){
00141             DataPlot plot = PaperBank.getPlot(Integer.parseInt(sumplots[i]));
00142             selection.getSumPlots().add(plot);
00143         }
00144         }
00145         if (fitplots!=null){
00146         for (int i=0; i<fitplots.length;i++){
00147             DataPlot plot = PaperBank.getPlot(Integer.parseInt(fitplots[i]));
00148             selection.getFitPlots().add(plot);
00149         }
00150         }
00151     } catch (Exception e){
00152         e.printStackTrace(System.out);
00153     }
00154 
00155     return selection;
00156         
00157     }

void modifyPlots HashMap< String, String >  parameters,
Paper  paper
throws JetWebException [static]
 

Modify the plots associated with a paper based on the parameters passed.

Definition at line 355 of file ServletUtils.java.

References CutCollection.addCut(), DataPlot.addSwitch(), DataPlot.deleteSwitch(), JetWebPlotReader.fillPlot(), DataPlot.getCollisionId(), RealPlot.getCutCollection(), DataPlot.getId(), PlotSwitch.getId(), PlotSwitch.getMCProcessTypeId(), DataPlot.getNumber(), DataPlot.getSwitches(), DataPlot.setCollisionId(), DataPlot.setDefaultSum(), DataPlot.setLogarithmic(), PlotSwitch.setPlotId(), RealPlot.setScale(), DataPlot.setShape(), DataPlot.setTitle(), DataPlot.setXLabel(), DataPlot.setYLabel(), and RealPlot.store().

00356                                                        {
00357     
00358     System.out.println("Modifying plots");
00359     if (paper.getPlots()==null) {
00360         return;
00361     }
00362 
00363     //Iterator<DataPlot> plotlist = paper.getPlots().iterator(); 
00364     //while (plotlist.hasNext()){
00365     for (DataPlot dPlot : paper.getPlots()){
00366 
00367         RealPlot plot = (RealPlot)dPlot;        
00368         
00369         int num = plot.getNumber();
00370         
00371         String title = parameters.get("TITLE"+num);
00372         if (title != null){
00373         
00374         plot.setTitle(title);
00375         plot.setXLabel(parameters.get("XLABEL"+num));
00376         plot.setYLabel(parameters.get("YLABEL"+num));
00377     
00378         String cutValueString = parameters.get("CUTVALUE"+num);
00379 
00380         String cutName = parameters.get("CUTNAME"+num);
00381         if(cutValueString!=null && 
00382            cutName!=null &&
00383            cutValueString.length()!=0){
00384             Double cutValue = Double.parseDouble(cutValueString);
00385             Cut cut = new Cut(cutName, cutValue);
00386             plot.getCutCollection().addCut(cut);
00387             }
00388         try {
00389             double scaleFactor 
00390             = Double.parseDouble(parameters.get("SCALE"+num));
00391             plot.setScale(scaleFactor);
00392             
00393             boolean tf = 
00394             (Boolean.valueOf(parameters.get("DEFSUM"+num))).booleanValue();
00395             plot.setDefaultSum(tf);
00396             
00397             tf = (Boolean.valueOf(parameters.get("ISSHAPE"+num))).booleanValue();;
00398             plot.setShape(tf);
00399             
00400             tf = (Boolean.valueOf(parameters.get("ISLOG"+num))).booleanValue();;
00401             plot.setLogarithmic(tf);
00402             
00403             plot.setCollisionId(Integer.parseInt(parameters.get("COLL"+num)));
00404             
00405             //Collision collision = new Collision(plot.getCollisionId());
00406             Iterator<PlotSwitch> switches = plot.getSwitches();
00407             while (switches.hasNext()){
00408             PlotSwitch ps = (PlotSwitch)switches.next();
00409             decodeSwitch(parameters,ps,String.valueOf(ps.getId()));
00410             if (!MCProcessType.checkCollision(plot.getCollisionId(),ps.getMCProcessTypeId())){
00411                 plot.deleteSwitch(ps);
00412             }
00413             }
00414             
00415             // Decode the new switch, if there is one.
00416             PlotSwitch newps = new PlotSwitch();
00417             decodeSwitch(parameters,newps,num+"-new");
00418             newps.setPlotId(plot.getId());
00419             if (MCProcessType.checkCollision(plot.getCollisionId(),newps.getMCProcessTypeId())){
00420             plot.addSwitch(newps); 
00421             }
00422 
00423         } catch (Exception e) {
00424             System.out.println(e);
00425             throw new JetWebException(e,"Error parsing plot parameters");
00426         }
00427 
00428         String path = JetWebConfig.rootDirectory+"/"+JetWebConfig.plotCacheDirName
00429             +"/"+paper.getDirName();
00430 
00431         // Reread the XML for plots which have new files upload.
00432         if ( parameters.get("UPDATED"+num)!=null ){
00433 
00434             try {
00435             System.out.println("Paper Directory is:"+paper.getDirName());
00436             String xmlFile = path+"/plot"+plot.getNumber()+"."+JetWebConfig.graphicsType;
00437             System.out.println("Trying to read "+xmlFile);
00438             JetWebPlotReader reader = JetWebPlotReaderFactory.getNewPlotReader(xmlFile);
00439             reader.fillPlot(plot);
00440             //plot.setDataPoints(reader.getDataPoints());
00441 
00442             } catch (Exception e){
00443             throw new 
00444                 JetWebException(e, "Corrupt XML file: plot not updated."+
00445                         "Paper: "+paper.getId()+": plot "+plot.getNumber());
00446             }
00447         }
00448 
00449         try {
00450             plot.store();
00451             System.out.println("Stored plot");
00452         } catch (JetWebException jwdb){
00453             throw new JetWebException(jwdb,"Error modifying plots");
00454         }
00455 
00456         JetWebHist.writeGraphics(plot,path);
00457         }
00458     }
00459     }

void performResultSearch ResultSearchPattern  pattern,
PrintWriter  out,
String  servletPath,
PlotSelection  selection,
HttpServletRequest  request
[static]
 

Perform a result search query and return the results.

Definition at line 161 of file ServletUtils.java.

00165                                                   {
00166 
00167     try {
00168         String sort = request.getParameter("SORT");
00169         if (sort==null) {
00170         sort = HTMLUtils.DATE;
00171         }
00172         int nMatches = 0;
00173         
00174         if (request.getParameter("GETFITS")!=null) {
00175         List<Fit> list = Fit.getFits(pattern,selection,sort);
00176         nMatches = list.size();
00177         if (list.size()!=0) {
00178             HTMLUtils.displayList(out,servletPath,false,list);
00179             return;
00180         }
00181         } else {
00182         List<Model> list = Model.getModels(pattern,sort);
00183         if (list.size()!=0) {
00184             HTMLUtils.displayList(out,servletPath,false,list);
00185             return;
00186         }
00187         }
00188         
00189         StringBuffer message = new StringBuffer("<p>Insufficient data currently exist in the database matching the parameters you specified.</p> <p>Submit the form below to request generation of this data.</p>");
00190         if (request.getParameter("GETFITS")!=null){
00191         message.append("<div class='actionbuttons'>");
00192         message.append("<p>There may be models in the databse matching these parameters, but without the full dataset available. You can find these by searching for models rather than fits using the button below.</p>");
00193         message.append(HTMLUtils.writeSubmitButton("GETMODELS",
00194                                "Search for models matching the criteria specified",
00195                                "Get Models"));
00196         message.append("</div>");
00197         }
00198         HTMLUtils.writeJobRequestForm(message.toString(),pattern,selection,out,servletPath);
00199         
00200 
00201     } catch (JetWebException e){
00202         HTMLErrorWriter.write(out,e);
00203     }
00204     }

void updateConfig HttpServletRequest  request  )  [static]
 

Update the servlet configuration.

Definition at line 209 of file ServletUtils.java.

00209                                                                {
00210 
00211     String[] tmp;
00212 
00213     tmp = request.getParameterValues("RUNSUBDIR");
00214     if (tmp!=null){
00215         if (tmp.length>0){
00216         if (tmp[0]!=""){
00217             if (!tmp[0].startsWith("/") && tmp[0]!="") {tmp[0] = "/"+tmp[0];}
00218             JetWebConfig.jobOutDirName = tmp[0];
00219         }
00220         }
00221     }
00222 
00223     tmp = request.getParameterValues("BATCHFAC");
00224     if (tmp.length>0) {
00225         try {
00226         SubmitScriptHandler.BATCHFACILITY = Integer.parseInt(tmp[0]);
00227         } catch (NumberFormatException e) {
00228         System.out.println("Invalid batch facility: "+tmp[0]+" : should be an integer");
00229         }
00230     }
00231 
00232     tmp = request.getParameterValues("PLOTS");
00233     if (tmp!=null){
00234         if (tmp.length>0){
00235         JetWebConfig.writePlots=true;
00236         } else {
00237         JetWebConfig.writePlots=false;
00238         }
00239     } else {
00240         JetWebConfig.writePlots=false;
00241     }
00242     }


Member Data Documentation

HashMap<String, String> allowedCuts_ [static, private]
 

Initial value:

 
    new HashMap<String String>()

Definition at line 49 of file ServletUtils.java.

boolean initCuts_ = true [static, private]
 

Definition at line 48 of file ServletUtils.java.


The documentation for this class was generated from the following file:

Generated Wed Jan 17 09:14:27 GMT 2007