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

Searcher Class Reference

List of all members.

Detailed Description

Read-only access to the data base, for job submission & retrieval.

Author:
Jon & Susanna Butterworth
Version:
Date
2006-09-18 15:23:05 +0100 (Mon, 18 Sep 2006)
$Version$

Definition at line 29 of file Searcher.java.


Public Member Functions

void init (ServletConfig config) throws ServletException
void destroy ()
String getServletInfo ()

Protected Member Functions

void doGet (HttpServletRequest request, HttpServletResponse response) throws ServletException, java.io.IOException
void doPost (HttpServletRequest request, HttpServletResponse response) throws ServletException, java.io.IOException

Member Function Documentation

void destroy  ) 
 

Destroys the servlet. Does nothing.

Definition at line 56 of file Searcher.java.

00056                           {
00057     }

void doGet HttpServletRequest  request,
HttpServletResponse  response
throws ServletException, java.io.IOException [protected]
 

Handles the HTTP GET method.

Parameters:
request servlet request
response servlet response

Definition at line 63 of file Searcher.java.

References HTMLWriter.close(), HTMLModelWriter.display(), HTMLFitWriter.display(), HTMLPaperWriter.display(), HTMLWriter.displayList(), HTMLPlotWriter.displaySelection(), PlotSelection.fitIsEmpty(), ResultSearchPattern.getGenerator(), ResultSearchPattern.getGeneratorList(), Fit.getId(), Paper.getPlots(), HTMLModelWriter.listDifferences(), HTMLJobWriter.listLogs(), HTMLModelWriter.listNonDefaults(), ResultSearchPattern.setDefaults(), PlotSelection.setFitDefault(), PlotSelection.setFitPlots(), ResultSearchPattern.setGenerator(), ResultSearchPattern.setSoftDefaults(), PlotSelection.setSumDefault(), PlotSelection.setSumPlots(), HTMLWriter.setVerbose(), PlotSelection.sumIsEmpty(), and HTMLWriter.writeTitle().

Referenced by Searcher.doPost().

00064                                                  {
00065 
00066     String servletPath=JetWebConfig.searchServletPath;
00067 
00068     //String title = "NB: If you make a wide-ranging search it
00069     //will take a minute or two for the results to return. Please
00070     //be patient.";
00071     String title = " ";
00072     response.setContentType("text/html");
00073     PrintWriter out = response.getWriter();
00074     ResultSearchPattern pattern = null; 
00075     PlotSelection selection;
00076     Vector<MCProcessType> reactionList;
00077 
00078     JetWebConfig.setPrintWriter(out);
00079 
00080     System.out.println("SEARCH ACCESS FROM: "
00081                +request.getRemoteHost()+" = "+request.getRemoteAddr());
00082     String requestingHost = request.getRemoteHost();
00083     
00084     try {
00085 
00086         // Methods not requiring a pattern or a selection
00087         if ((request.getParameter("MORERESULTS")!=null)){
00088 
00089 
00090         boolean verbose = Boolean.parseBoolean(request.getParameter("VERBOSE"));
00091         HTMLUtils.displayListContinued(out,servletPath,verbose,
00092                            request.getParameter("RESULTKEY"));
00093         return;
00094         
00095         } else if (request.getParameter("REALDATA")!=null) {
00096 
00097         List<DataPlot> list = new Vector<DataPlot>();
00098 
00099         if (request.getParameter("COLLISIONID")!=null){
00100             String[] collIds = request.getParameterValues("COLLISIONID");       
00101             for (int i=0; i<collIds.length; i++){
00102             Collision coll = new Collision(Integer.parseInt(collIds[i]));
00103             for (DataPlot plot : PaperBank.getPlots(coll)){
00104                 list.add(plot);
00105             }
00106             }
00107         } else if (request.getParameter("PROCESSID")!=null){
00108             String[] procIds = request.getParameterValues("PROCESSID");     
00109             for (int i=0; i<procIds.length; i++){
00110             MCProcessType proc = new MCProcessType(Integer.parseInt(procIds[i]));
00111             for (DataPlot plot : PaperBank.getPlots(proc)){
00112                 list.add(plot);
00113             }
00114             }
00115         } else if (request.getParameter("PLOTID")!=null){
00116             String[] ids = request.getParameterValues("PLOTID");        
00117             for (int i=0; i<ids.length; i++){
00118             list.add(PaperBank.getPlot(Integer.parseInt(ids[i])));
00119             }
00120         } else if (request.getParameter("PAPERID")!=null){
00121             String[] ids = request.getParameterValues("PAPERID");       
00122             for (int i=0; i<ids.length; i++){
00123             Paper paper = PaperBank.getPaper(Integer.parseInt(ids[i]));
00124             for (DataPlot plot : paper.getPlots()){
00125                 list.add(plot);
00126             }
00127             }
00128         } else {
00129             list = new Vector(PaperBank.getAllPlots());
00130         }
00131         HTMLUtils.displayList(out,servletPath,false,list);
00132         return;
00133 
00134         } else if (request.getParameter("PAPER")!=null) {
00135 
00136         List<Paper> list = new Vector<Paper>();
00137 
00138         if (request.getParameter("FITID")!=null) {
00139             // list of fitted papers.
00140 
00141             try {
00142 
00143             int fitId   = Integer.parseInt(request.getParameter("FITID"));
00144             int paperId = Integer.parseInt(request.getParameter("PAPERID"));
00145             System.out.println("fit id "+fitId);
00146             Fit fit = new Fit(fitId);
00147             System.out.println("fit id "+fit.getId());
00148             Paper paper = new Paper(paperId);
00149             
00150             HTMLPaperWriter op = new HTMLPaperWriter(out,servletPath);
00151             op.setVerbose(true);
00152             op.display(paper,fit);
00153             op.close();
00154             return;
00155             
00156             } catch (NumberFormatException ne){
00157             System.out.println("ServletUtils: ID not defined: "+ne);
00158             System.out.println("Default Query Screen");
00159             // If we get here, just write a new page.
00160             HTMLUtils.writeQueryScreen(title,pattern,null,out,servletPath);
00161             return;
00162             }
00163 
00164         } else if (request.getParameter("PAPERID")!=null){
00165             String[] ids = request.getParameterValues("PAPERID");       
00166             for (int i=0; i<ids.length; i++){
00167             list.add(PaperBank.getPaper(Integer.parseInt(ids[i])));
00168             }
00169 
00170         } else if (request.getParameter("COLLISIONID")!=null){
00171             String[] ids = request.getParameterValues("COLLISIONID");       
00172             for (int i=0; i<ids.length; i++){
00173             Collision coll = new Collision(Integer.parseInt(ids[i]));
00174             for (Paper paper : PaperBank.getPapers(coll)){
00175                 list.add(paper);
00176             }
00177             }
00178         } else if (request.getParameter("PROCESSID")!=null){
00179             String[] ids = request.getParameterValues("PROCESSID");     
00180             for (int i=0; i<ids.length; i++){
00181             MCProcessType proc = new MCProcessType(Integer.parseInt(ids[i]));
00182             for (Paper paper : PaperBank.getPapers(proc)){
00183                 list.add(paper);
00184             }
00185             }
00186         } else if (request.getParameter("PLOTID")!=null){
00187             String[] ids = request.getParameterValues("PLOTID");        
00188             for (int i=0; i<ids.length; i++){
00189             list.add(PaperBank.getPaper(PaperBank.getPlot(Integer.parseInt(ids[i]))));
00190             }
00191         } else {
00192             list = new Vector(PaperBank.getPapers());
00193         }
00194         HTMLUtils.displayList(out,servletPath,false,list);
00195         return;
00196         //************
00197         } else if ((request.getParameter("PROCESSTYPE") != null)) {
00198 
00199         List<MCProcessType> list = new Vector<MCProcessType>();
00200 
00201         if (request.getParameter("COLLISIONID")!=null){
00202             // Write out all the MCProcessTypes for the given Collisions.
00203             String[] collIds = request.getParameterValues("COLLISIONID");       
00204             for (int i=0; i<collIds.length; i++){
00205             Collision coll = new Collision(Integer.parseInt(collIds[i]));
00206             list.addAll(MCProcessType.getAll(coll,false));
00207             }
00208         } else if (request.getParameter("PROCESSID")!=null){
00209             String[] procIds = request.getParameterValues("PROCESSID");     
00210             for (int i=0; i<procIds.length; i++){
00211             MCProcessType proc = new MCProcessType(Integer.parseInt(procIds[i]));
00212             list.add(proc);
00213             }
00214         } else {            
00215             // Write out all the MCProcessTypes.
00216             list.addAll(MCProcessType.getAll(false));
00217         }
00218         HTMLUtils.displayList(out,servletPath,true,list);
00219         return;
00220         //**************
00221         } else if ((request.getParameter("COLLISION") != null)) {
00222 
00223         // write out collisions.
00224         List<Collision> list = new Vector<Collision>();
00225         if (request.getParameter("COLLISIONID")!=null){
00226 
00227             String[] collIds = request.getParameterValues("COLLISIONID");
00228             for (int i=0; i<collIds.length; i++){
00229             Collision coll = new Collision(Integer.parseInt(collIds[i]));
00230             list.add(coll);
00231             }
00232 
00233         } else {
00234             // write them all out.
00235             list.addAll(Collision.getAll());
00236         }
00237         HTMLUtils.displayList(out,servletPath,true,list);
00238         return;
00239 
00240         } else if (request.getParameter("FITIDGET") != null) {
00241 
00242         try {
00243 
00244             int fitId   = Integer.parseInt(request.getParameter("FITID"));
00245             Fit fit = new Fit(fitId);
00246             HTMLFitWriter op = new HTMLFitWriter(out,servletPath);
00247             op.setVerbose(true);
00248             op.display(fit);
00249             op.close();
00250             return;
00251 
00252         } catch (NumberFormatException ne){
00253             System.out.println("ServletUtils: Fit ID not defined: "+ne);
00254             System.out.println("Default Query Screen");
00255             // If we get here, just write a new page.
00256             HTMLUtils.writeQueryScreen(title,pattern,null,out,servletPath);
00257         }
00258 
00259         } else if (request.getParameter("MODELIDGET") != null) {
00260 
00261         try {
00262 
00263             int modelId   = Integer.parseInt(request.getParameter("MODELID"));
00264             Model model = new Model(modelId);
00265             HTMLModelWriter op = new HTMLModelWriter(out,servletPath);
00266             op.setVerbose(true);
00267             op.display(model);
00268             op.close();
00269             return;
00270 
00271         } catch (NumberFormatException ne){
00272             System.out.println("ServletUtils: Model ID not defined: "+ne);
00273             System.out.println("Default Query Screen");
00274             // If we get here, just write a new page.
00275             HTMLUtils.writeQueryScreen(title,pattern,null,out,servletPath);
00276         }
00277 
00278         } else if (request.getParameter("PLOTSELECTIONIDGET") != null) {
00279 
00280         // Display a plot selection.
00281         try {
00282 
00283             int psId   = Integer.parseInt(request.getParameter("PLOTSELECTIONID"));
00284             selection = new PlotSelection(psId);
00285             HTMLPlotWriter op = new HTMLPlotWriter(out,servletPath);
00286             op.setVerbose(true);
00287             op.displaySelection(selection);
00288             op.close();
00289             return;
00290 
00291         } catch (NumberFormatException ne){
00292             System.out.println("ServletUtils: Model ID not defined: "+ne);
00293             System.out.println("Default Query Screen");
00294             // If we get here, just write a new page.
00295             HTMLUtils.writeQueryScreen(title,pattern,null,out,servletPath);
00296         }
00297 
00298         } else if ((request.getParameter("CANCEL") != null)) {
00299         // Cancel. //////////////////////////////////////////////
00300         pattern=new ResultSearchPattern();
00301         selection=new PlotSelection();
00302         HTMLUtils.writeQueryScreen("Cancelled operation",pattern,selection,
00303                           out,servletPath);
00304         return;
00305 
00306         } else if (request.getParameter("PLOTTEXT")!=null) {
00307         // Write plot data to a text file.
00308         HTMLPlotWriter.writePlotText(request.getParameter("FITID"),
00309                        request.getParameter("PLOTID"),out);
00310         
00311         return;
00312 
00313         } else if ((request.getParameter("CHOOSEPROC") != null)) {
00314         HTMLUtils.writeProcScreen(request.getParameter("MODELID"),
00315                          out,servletPath);
00316         return;
00317 
00318         } else if (request.getParameter("RSLOGS")!=null) {
00319         // List all the logfiles for a given runseries.
00320         int rsid = Integer.parseInt(request.getParameter("RUNSERIESID"));
00321         Vector<LogFile> logs = JobUtils.getLogFiles(rsid);
00322         HTMLJobWriter jw = new HTMLJobWriter(out,servletPath);
00323         jw.writeTitle("LogFiles for RunSeries "+rsid);
00324         jw.listLogs(logs);
00325         jw.close();
00326         return;
00327         }
00328 
00329         System.out.println("request = "+request);
00330 
00331         // Make a pattern from the submitted form.
00332         pattern = ServletUtils.makePattern(request);
00333 
00334         // Make a reactionList from the submitted form.
00335         reactionList = ServletUtils.makeMCProcessList(request);
00336 
00337         // Methods requiring a pattern but not a selection
00338         if (request.getParameter("SUBMIT1") != null) {
00339         // Submit a job (first pass) ///////////////////////////////
00340         JobUtils.doJobRequest(pattern,reactionList,out,
00341                       servletPath,requestingHost);
00342         return;
00343         
00344         } else if ((request.getParameter("FINDDATA") != null)) {
00345         boolean submitting = false;
00346         HTMLUtils.writeParameterScreen(pattern,out,servletPath,submitting);
00347         return;
00348         
00349         } else if ((request.getParameter("SETPARS") != null)) {
00350         boolean submitting = (request.getParameterValues("SUBMITTINGJOB")!=null);
00351         if (pattern.getGenerator()==null){
00352 
00353             String[] gname = request.getParameterValues("SETPARS");     
00354             String[] tmp = request.getParameterValues("GENERATOR");
00355 
00356             String vers = null;
00357             if (tmp!=null){
00358             for (int i=0; i<tmp.length;i++){
00359                 String name = tmp[i].substring(0,tmp[i].indexOf("-"));
00360                 if (name.equals(gname[0])){
00361                 vers = tmp[i].substring(tmp[i].indexOf("-")+1);
00362                 }
00363             }
00364             }
00365             System.out.println(gname[0]+":"+vers);
00366             Generator gen = Generator.Maker(gname[0],vers);
00367             pattern.setGenerator(gen);      
00368 
00369         }
00370         // If this is a job submission rather than a
00371         // search, then set all parameters.
00372         if (submitting) pattern.getGenerator().setSoftDefaults();
00373 
00374         HTMLUtils.writeParameterScreen(pattern,out,servletPath,submitting);
00375         return;
00376         
00377         } else if ((request.getParameter("MOREDATA") != null)) {
00378         JobUtils.doJobRequest(pattern,reactionList,out,servletPath,
00379                       requestingHost);
00380         return;
00381         }
00382 
00383 
00384         // Build a paper selection from the page.
00385         selection = ServletUtils.makePlotSelection(request);
00386         
00387         // make this check only the sum plots!
00388         if (selection.fitIsEmpty()) { selection.setFitDefault(); }
00389         // make this check only the sum plots!
00390         if (selection.sumIsEmpty()) { selection.setSumDefault(); }
00391                 
00392         // Methods requiring both pattern and selection.
00393         
00394         // Return page of results matching this pattern /////////////
00395         if (request.getParameter("GETFITS") != null || request.getParameter("GETMODELS") != null) {
00396         ServletUtils.performResultSearch
00397             (pattern,out,servletPath,selection, request);
00398         return;
00399         
00400         } else if (request.getParameter("DEFAULT") != null) {
00401         if (pattern.getGeneratorList().size()==1){
00402             // Set the parameters for this generator to default.
00403             pattern.setSoftDefaults();
00404             pattern.getGenerator().setDefaults();
00405         } else {
00406             // Set everything, including the generator, to default.
00407             pattern.setDefaults();
00408         }
00409         HTMLUtils.writeQueryScreen(title,pattern,selection,out,servletPath);
00410         return;
00411         
00412         
00413         } else if ((request.getParameter("SIMILARDATA") != null)) {
00414         HTMLUtils.writeJobRequestForm("Set your parameters",
00415                          pattern,selection,out,servletPath);
00416         return;
00417 
00418         } else if ((request.getParameter("CLEARPARS") != null)) {
00419         pattern.getGenerator().setDefaults();
00420         boolean submitting = (request.getParameterValues("SUBMITTINGJOB")!=null);
00421         HTMLUtils.writeParameterScreen(pattern,out,servletPath,submitting);
00422         return;
00423         
00424         } else if ((request.getParameter("SELECTPLOTS")!=null)){
00425         // Write out the page to select plots with defaults filled in.
00426         HTMLUtils.writeSelectPlotsPage(pattern,selection,out,servletPath);
00427         
00428         }else if ((request.getParameter("RESET")!=null)){
00429         // Write out the page to select plots with nothing filled in.
00430         selection.setSumPlots(new ArrayList<DataPlot>());
00431         selection.setFitPlots(new ArrayList<DataPlot>());
00432         HTMLUtils.writeSelectPlotsPage(pattern,selection,out,servletPath);
00433         
00434         } else if ((request.getParameter("COMPAREFIT")!=null)){
00435         HTMLFitWriter.writeCompareFitsPage(request.getParameter("FIT1"),
00436                            request.getParameter("FIT2"),
00437                            out,servletPath);
00438         return;
00439 
00440         } else if ((request.getParameter("COMPAREMODEL")!=null)){
00441 
00442                 Model model1 = new Model(Integer.parseInt(request.getParameter("MODEL1")));
00443                 Model model2 = new Model(Integer.parseInt(request.getParameter("MODEL2")));
00444         HTMLModelWriter op = new HTMLModelWriter(out,servletPath);
00445         op.listDifferences(model1,model2);
00446         op.close();
00447         return;
00448 
00449         } else if ((request.getParameter("NONDEF")!=null)){
00450         System.out.println("Showing non-default parameters");
00451                 Model model = new Model(Integer.parseInt(request.getParameter("MODELID")));
00452         HTMLModelWriter op = new HTMLModelWriter(out,servletPath);
00453         op.listNonDefaults(model);
00454         op.close();
00455         return;
00456 
00457         } else if (request.getParameter("CLEARALL")!=null) {
00458         // Clear all parameters -> write new search page.
00459         pattern = new ResultSearchPattern();
00460         HTMLUtils.writeQueryScreen(title,pattern,selection,out,servletPath);
00461         return;
00462 
00463         } else {
00464         System.out.println("Default Query Screen");
00465         // If we get here, just write a new page.
00466         HTMLUtils.writeQueryScreen(title,pattern,selection,out,servletPath);
00467         }
00468 
00469     } catch (JetWebException e){
00470         HTMLErrorWriter.write(out,e);
00471     }
00472 
00473     }

void doPost HttpServletRequest  request,
HttpServletResponse  response
throws ServletException, java.io.IOException [protected]
 

Handles the HTTP POST method.

Parameters:
request servlet request
response servlet response

Definition at line 478 of file Searcher.java.

References Searcher.doGet().

00479                                                  {
00480         doGet(request,response);
00481     }

String getServletInfo  ) 
 

Returns a short description of the servlet.

Definition at line 485 of file Searcher.java.

00485                                    {
00486         return "Test servlet. Do not use.";
00487     }

void init ServletConfig  config  )  throws ServletException
 

Initializes the servlet. i.e. Build the database.

Parameters:
ServletConfig 
Exceptions:
ServletException 

Definition at line 38 of file Searcher.java.

00038                                                                    {
00039         super.init(config);
00040 
00041     // Set up configuration with servlet mode on.
00042     JetWebConfig.init();
00043 
00044     // Read in all papers from the database.
00045     try {
00046         PaperBank.getConfig();
00047     } catch (JetWebException e){
00048         System.out.println(e.getMessage());
00049         e.printStackTrace(System.out);
00050     }
00051     }


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

Generated Wed Jan 17 09:14:27 GMT 2007