00001 package cedar.jetweb.servlet; 00002 00003 import javax.servlet.http.HttpServletRequest; 00004 00005 import java.io.PrintWriter; 00006 import java.io.File; 00007 00008 import java.util.Vector; 00009 import java.util.Collection; 00010 import java.util.HashMap; 00011 import java.util.Map; 00012 import java.util.Map.Entry; 00013 import java.util.Iterator; 00014 import java.util.List; 00015 import java.util.Set; 00016 import java.util.Arrays; 00017 import java.util.Scanner; 00018 00019 import cedar.jetweb.*; 00020 00021 import cedar.jetweb.model.*; 00022 import cedar.jetweb.model.plots.*; 00023 import cedar.jetweb.model.fit.Fit; 00024 import cedar.jetweb.model.paper.Paper; 00025 import cedar.jetweb.model.paper.PaperBank; 00026 00027 import cedar.jetweb.html.*; 00028 00029 import cedar.jetweb.job.*; 00030 00031 import cedar.jetweb.batch.SubmitScriptHandler; 00032 00033 import cedar.jetweb.xml.JetWebPlotReader; 00034 import cedar.jetweb.xml.JetWebPlotReaderFactory; 00035 import cedar.jetweb.hist.JetWebHist; 00036 00037 import cedar.jetweb.generator.Generator; 00038 00039 import com.oreilly.servlet.multipart.*; 00040 00046 public abstract class ServletUtils { 00047 00048 private static boolean initCuts_ = true; 00049 private static HashMap<String, String> allowedCuts_ = 00050 new HashMap<String, String>(); 00051 00059 public static ResultSearchPattern makePattern(HttpServletRequest request) 00060 throws JetWebException { 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 } 00124 00125 00126 00130 public static PlotSelection makePlotSelection(HttpServletRequest request) { 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 } 00161 public static void performResultSearch(ResultSearchPattern pattern, 00162 PrintWriter out, 00163 String servletPath, 00164 PlotSelection selection, 00165 HttpServletRequest request){ 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 } 00205 00209 public static void updateConfig(HttpServletRequest request){ 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 } 00243 00247 public static void editFit(HttpServletRequest request, PrintWriter out, 00248 String servletPath) 00249 throws JetWebException{ 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 } 00318 00319 00320 00324 public static void changePaper(HttpServletRequest request,PrintWriter out){ 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 } 00350 00355 public static void modifyPlots(HashMap<String,String> parameters, 00356 Paper paper) throws JetWebException { 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 } 00463 public static void addPlot(HashMap<String,String> parameters, Paper paper,String inKey) throws JetWebException { 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 } 00622 00623 public static void generatorDefaults(HttpServletRequest request){ 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 } 00655 00656 00657 private static void decodeSwitch(HashMap<String,String> parameters, 00658 PlotSwitch ps, 00659 String label){ 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 } 00719 00724 public static Vector<MCProcessType> makeMCProcessList(HttpServletRequest request) 00725 throws JetWebException { 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 } 00769 00773 public static void getGeneratorParameters(HttpServletRequest request, 00774 Generator gen) 00775 throws JetWebException { 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 } 00838 00839 00840 private static void getCuts(HttpServletRequest request, Generator gen){ 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 } 00861 00862 private static void initCuts(){ 00863 if(initCuts_){ 00864 initCuts_ = false; 00865 allowedCuts_.put("GENPTMIN", "PTMin"); 00866 } 00867 return; 00868 } 00869 00874 public static void deletePlots(HashMap<String,String> parameters, 00875 Paper paper) throws JetWebException { 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 } 00897 00902 public static void deletePaper(HttpServletRequest request) 00903 throws JetWebException { 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 } 00912 00917 public static MCProcessType buildProc(HttpServletRequest request) throws JetWebException { 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 } 00973 }
Generated Wed Jan 17 09:14:27 GMT 2007