FindPaperPhysics.java

Go to the documentation of this file.
00001 package cedar.hepdata.webapp.pages;
00002 
00003 import cedar.hepdata.model.*;
00004 import cedar.hepdata.xml.*;
00005 import cedar.hepdata.db.*;
00006 
00007 import org.apache.tapestry.annotations.*;
00008 import org.apache.tapestry.services.*;
00009 
00010 import org.hibernate.*;
00011 import org.hibernate.criterion.*;
00012 import java.util.*;
00013 
00014 public class FindPaperPhysics{
00015 
00016     @Inject
00017     private RequestGlobals _reqGlobals;
00018 
00019     @Inject
00020     private org.hibernate.Session _session;
00021 
00022    
00023     public String getQueryParam(String param){
00024        return _reqGlobals.getRequest().getParameter(param);
00025     }
00026 
00027     public String getQueryParameters(){
00028         StringBuffer qs = new StringBuffer();
00029         String mid = "";
00030         int number =  Integer.parseInt(getQueryParam("number"));
00031         int newstart = Integer.parseInt(getQueryParam("start"));
00032         newstart += number;
00033         qs.append(mid + "beam=" + getQueryParam("beam"));  mid = "&";
00034         qs.append(mid + "targ=" + getQueryParam("targ"));  mid = "&";
00035         qs.append(mid + "fsp1=" + getQueryParam("fsp1"));  mid = "&"; 
00036         qs.append(mid + "mfsp1=" + getQueryParam("mfsp1"));  mid = "&";
00037         qs.append(mid + "fsp2=" + getQueryParam("fsp2"));  mid = "&"; 
00038         qs.append(mid + "mfsp2=" + getQueryParam("mfsp2"));  mid = "&";
00039         qs.append(mid + "fsp3=" + getQueryParam("fsp3"));  mid = "&"; 
00040         qs.append(mid + "mfsp3=" + getQueryParam("mfsp3"));  mid = "&";
00041         qs.append(mid + "obs=" + getQueryParam("obs"));  mid = "&";
00042         qs.append(mid + "number=" + getQueryParam("number") + mid + "start=" + Integer.toString(newstart));
00043         return qs.toString().replaceAll("\\+","%2B");
00044     }
00045 
00046     public String getFirstNumber(){
00047        return getQueryParam("start");
00048     }
00049 
00050     public String getLastNumber(){
00051         int first =  Integer.parseInt(getQueryParam("start"));
00052         int number = Integer.parseInt(getQueryParam("number"));
00053         int last = first + number - 1;
00054         return Integer.toString(last);
00055    }
00056 
00057     public String getPageSize(){
00058        return getQueryParam("number");
00059     }
00060 
00061     public Long getCount(){
00062         return (Long) constructQuery("count").uniqueResult();
00063     }
00064 
00065 //Papers
00066     private Paper _paper;
00067     public Paper getPaper() { return _paper; }
00068     public void setPaper(Paper p) { _paper = p; }
00069    
00070     public List <Paper> getPapers(){
00071         Query q = constructQuery();
00072            // how many results do we want out and where to start
00073         q.setFirstResult(Integer.parseInt(getQueryParam("start"))).setMaxResults(Integer.parseInt(getQueryParam("number")));
00074            // execute the query and return the list of results
00075         return q.list();   
00076     }
00077 
00078 
00079     private Query constructQuery(){
00080         return this.constructQuery("blank");
00081     }
00082 
00083     private Query constructQuery(String flag){
00084 
00085         String theBeam = "";
00086         String theTarg = "";
00087         String theFsp1 = "";
00088         String theFsp2 = "";
00089         String theFsp3 = "";
00090         String theMFsp1 = "";
00091         String theMFsp2 = "";
00092         String theMFsp3 = "";
00093         String theObs = "";
00094         if ( getQueryParam("beam") != "") { theBeam = getQueryParam("beam"); }
00095         if ( getQueryParam("targ") != "") { theTarg = getQueryParam("targ"); }
00096         if ( getQueryParam("fsp1") != "") { theFsp1 = getQueryParam("fsp1"); } 
00097         if ( getQueryParam("mfsp1") != ""){ theMFsp1 = getQueryParam("mfsp1"); }
00098         if ( getQueryParam("fsp2") != "") { theFsp2 = getQueryParam("fsp2"); } 
00099         if ( getQueryParam("mfsp2") != ""){ theMFsp2 = getQueryParam("mfsp2"); }
00100         if ( getQueryParam("fsp3") != "") { theFsp3 = getQueryParam("fsp3"); } 
00101         if ( getQueryParam("mfsp3") != ""){ theMFsp3 = getQueryParam("mfsp3"); }
00102         if ( getQueryParam("obs")  != "") { theObs  = getQueryParam("obs");  }
00103 
00104         Query q = null;
00105 
00106         // the string buffer way!!
00107         StringBuffer b = new StringBuffer();
00108 
00109         // assuming a spiresid search first 
00110         // assuming we have a beam particle next 
00111         if(theBeam != ""){
00112             if (flag == "count"){
00113                 b.append("select count(distinct pbeam) from Paper pbeam join pbeam._datasets dsbeam join dsbeam._yAxes yabeam join yabeam._reactions yrbeam join yrbeam._initialState beam"); 
00114            }
00115             else{
00116                 b.append("select distinct pbeam from Paper pbeam join pbeam._datasets dsbeam join dsbeam._yAxes yabeam join yabeam._reactions yrbeam join yrbeam._initialState beam"); 
00117             }
00118             if (theTarg != ""){ b.append(",Paper ptarg join ptarg._datasets dstarg join dstarg._yAxes yatarg join yatarg._reactions yrtarg join yrtarg._initialState targ"); }
00119             if (theFsp1 != ""){ b.append(",Paper pfsp1 join pfsp1._datasets dsfsp1 join dsfsp1._yAxes yafsp1 join yafsp1._reactions yrfsp1 join yrfsp1._finalState fsp1"); }
00120             if (theFsp2 != ""){ b.append(",Paper pfsp2 join pfsp2._datasets dsfsp2 join dsfsp2._yAxes yafsp2 join yafsp2._reactions yrfsp2 join yrfsp2._finalState fsp2"); }
00121             if (theFsp3 != ""){ b.append(",Paper pfsp3 join pfsp3._datasets dsfsp3 join dsfsp3._yAxes yafsp3 join yafsp3._reactions yrfsp3 join yrfsp3._finalState fsp3"); }
00122             b.append(" where beam.name=:beampart");
00123             if (theTarg != ""){ b.append(" and targ.name=:targpart"); } 
00124             if (theFsp1 != ""){ b.append(" and fsp1.name=:fsp1part and fsp1.multiplicity=:fsp1mult"); } 
00125             if (theFsp2 != ""){ b.append(" and fsp2.name=:fsp2part and fsp2.multiplicity=:fsp2mult"); } 
00126             if (theFsp3 != ""){ b.append(" and fsp3.name=:fsp3part and fsp3.multiplicity=:fsp3mult"); } 
00127             if (theObs  != ""){ b.append(" and yabeam._observable=:observable"); } 
00128             if (theTarg != ""){ b.append(" and yrbeam = yrtarg");  }
00129             if (theFsp1 != ""){ b.append(" and yrbeam = yrfsp1"); }
00130             if (theFsp2 != ""){ b.append(" and yrbeam = yrfsp2"); }
00131             if (theFsp3 != ""){ b.append(" and yrbeam = yrfsp3"); }
00132             q = _session.createQuery(b.toString());
00133             q.setString("beampart",theBeam);
00134             if (theTarg != "")  {q.setString( "targpart",theTarg); }
00135             if (theFsp1 != "")  {q.setString( "fsp1part",theFsp1); }
00136             if (theFsp2 != "")  {q.setString( "fsp2part",theFsp2); }
00137             if (theFsp3 != "")  {q.setString( "fsp3part",theFsp3); }
00138             if (theFsp1 != "")  {q.setString( "fsp1mult",theMFsp1); }
00139             if (theFsp2 != "")  {q.setString( "fsp2mult",theMFsp2); }
00140             if (theFsp3 != "")  {q.setString( "fsp3mult",theMFsp3); }
00141             if (theObs  != "")  {q.setString( "observable",theObs); }
00142         }
00143 
00144         // no inital state so next assuming we have a fsp
00145         else if(theFsp1 != "") {
00146             if (flag == "count"){
00147                 b.append("select count(distinct pfsp1) from Paper pfsp1 join pfsp1._datasets dsfsp1 join dsfsp1._yAxes yafsp1 join yafsp1._reactions yrfsp1 join yrfsp1._finalState fsp1"); 
00148             }
00149             else{
00150                 b.append("select distinct pfsp1 from Paper pfsp1 join pfsp1._datasets dsfsp1 join dsfsp1._yAxes yafsp1 join yafsp1._reactions yrfsp1 join yrfsp1._finalState fsp1"); 
00151             }
00152             if (theFsp2 != ""){ b.append(",Paper pfsp2 join pfsp2._datasets dsfsp2 join dsfsp2._yAxes yafsp2 join yafsp2._reactions yrfsp2 join yrfsp2._finalState fsp2"); }
00153             if (theFsp3 != ""){ b.append(",Paper pfsp3 join pfsp3._datasets dsfsp3 join dsfsp3._yAxes yafsp3 join yafsp3._reactions yrfsp3 join yrfsp3._finalState fsp3"); }
00154             b.append(" where fsp1.name=:fsp1part and fsp1.multiplicity=:fsp1mult"); 
00155             if (theFsp2 != ""){ b.append(" and fsp2.name=:fsp2part and fsp2.multiplicity=:fsp2mult"); } 
00156             if (theFsp3 != ""){ b.append(" and fsp3.name=:fsp3part and fsp3.multiplicity=:fsp3mult"); } 
00157             if (theObs  != ""){ b.append(" and yafsp1._observable=:observable"); } 
00158             if (theFsp2 != ""){ b.append(" and yrfsp1 = yrfsp2"); }
00159             if (theFsp3 != ""){ b.append(" and yrfsp1 = yrfsp3"); }
00160             q = _session.createQuery(b.toString());
00161             q.setString("fsp1part",theFsp1); q.setString("fsp1mult",theMFsp1);
00162             if (theFsp2 != "") {q.setString("fsp2part",theFsp2); q.setString("fsp2mult",theMFsp2);}
00163             if (theFsp3 != "") {q.setString("fsp3part",theFsp3); q.setString("fsp3mult",theMFsp3);}
00164             if (theObs  != "") {q.setString("observable",theObs);}
00165         }
00166 
00167         // OK no reaction  .. so do we have an observable? 
00168         else if(theObs != "") {
00169             if (flag == "count"){
00170                 b.append("select count(distinct pobs) from Paper pobs join pobs._datasets dsobs join dsobs._yAxes yaobs"); 
00171             }
00172             else{
00173                 b.append("select distinct pobs from Paper pobs join pobs._datasets dsobs join dsobs._yAxes yaobs"); 
00174             }
00175             b.append(" where yaobs._observable=:observable");  
00176             q = _session.createQuery(b.toString());
00177             q.setString("observable",theObs);
00178         }
00179 
00180         // nothing left so must want everything !!
00181         else {
00182             if (flag == "count"){
00183                 b.append("select count(distinct pa) from Paper pa");
00184             }
00185             else{
00186                 b.append("select distinct pa from Paper pa");
00187             }
00188             q = _session.createQuery(b.toString());
00189         }
00190 
00191         // how many results do we want out
00192         q.setMaxResults(Integer.parseInt(getQueryParam("number")));
00193 
00194         // execute the query and return the list of results
00195         return q;
00196 
00197     }
00198         
00199      
00200 }

Generated on Tue Apr 21 15:55:00 2009 for HepData Web servlets by  doxygen 1.5.5