FindPaperFromReaction.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.tapestry5.annotations.*;
00008 import org.apache.tapestry5.ioc.annotations.*;
00009 import org.apache.tapestry5.services.*;
00010 
00011 import org.hibernate.*;
00012 import org.hibernate.criterion.*;
00013 import java.util.*;
00014 
00015 public class FindPaperFromReaction{
00016 
00017     @Inject
00018     private RequestGlobals _reqGlobals;
00019 
00020     @Inject
00021     private org.hibernate.Session _session;
00022 
00023    
00024     public String getQueryParam(String param){
00025        return _reqGlobals.getRequest().getParameter(param);
00026     }
00027 
00028     public String getQueryParameters(){
00029         StringBuffer qs = new StringBuffer();
00030         String mid = "";
00031         int number =  Integer.parseInt(getQueryParam("number"));
00032         int newstart = Integer.parseInt(getQueryParam("start"));
00033         newstart += number;
00034         qs.append(mid + "beam=" + getQueryParam("beam"));  mid = "&";
00035         qs.append(mid + "targ=" + getQueryParam("targ"));  mid = "&";
00036         qs.append(mid + "fsp1=" + getQueryParam("fsp1"));  mid = "&"; 
00037         qs.append(mid + "mfsp1=" + getQueryParam("mfsp1"));  mid = "&";
00038         qs.append(mid + "fsp2=" + getQueryParam("fsp2"));  mid = "&"; 
00039         qs.append(mid + "mfsp2=" + getQueryParam("mfsp2"));  mid = "&";
00040         qs.append(mid + "fsp3=" + getQueryParam("fsp3"));  mid = "&"; 
00041         qs.append(mid + "mfsp3=" + getQueryParam("mfsp3"));  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 //    public String getSpiresId(){
00066 //      Long _irn = _reaction.getYAxis().getDataset().getPaper().getSpiresId();
00067 //      return String.valueOf(_irn);
00068 //    }
00069 
00070 //    public String getRedId(){
00071 //      Long _red = _reaction.getYAxis().getDataset().getPaper().getRedId();
00072 //      return String.valueOf(_red);
00073 //    }
00074 
00075 //Paper
00076     private Paper _paper;
00077     public Paper getPaper() { return _paper; }
00078     public void setPaper(Paper p) { _paper = p; }
00079 
00080     private List <Paper> pout = new Vector<Paper>();
00081     private Long old = null;
00082 
00083     public List <Paper> getPapers(){
00084         Query q = constructQuery();
00085 //      q.setFirstResult(Integer.parseInt(getQueryParam("start"))).setMaxResults(Integer.parseInt(getQueryParam("number")));
00086 //      q.setFirstResult(Integer.parseInt(getQueryParam("start"))).setMaxResults(Integer.parseInt(getQueryParam("number")));
00087         
00088         pout.clear();
00089         old = null;
00090         for (Iterator it = q.iterate();  it.hasNext();){
00091             AxisReaction _reaction = (AxisReaction) it.next();
00092             _paper = _reaction.getYAxis().getDataset().getPaper(); 
00093 //          if(_paper.getSpiresId().equals(old) )  {} else { pout.add(_paper); }
00094             if(_paper.getSpiresId() != old) { pout.add(_paper); }
00095             old = _paper.getSpiresId(); 
00096             if(pout.size() > 9) break;
00097         }
00098         return pout;
00099     }
00100 
00101 
00102 //AxisReaction
00103 //    private AxisReaction _reaction;
00104 //    public AxisReaction getReaction() { return _reaction; }
00105 //    public void setReaction(AxisReaction r) { _reaction = r; }
00106 //   
00107 //    public List <AxisReaction> getReactions(){
00108 //        Query q = constructQuery();
00109 //           // how many results do we want out and where to start
00110 //      q.setFirstResult(Integer.parseInt(getQueryParam("start"))).setMaxResults(Integer.parseInt(getQueryParam("number")));
00111 //         // execute the query and return the list of results
00112 //        return q.list();   
00113 //    }
00114 
00115 
00116     private Query constructQuery(){
00117         return this.constructQuery("blank");
00118     }
00119 
00120     private Query constructQuery(String flag){
00121 
00122         String theBeam = "";
00123         String theTarg = "";
00124         String theFsp1 = "";
00125         String theFsp2 = "";
00126         String theFsp3 = "";
00127         String theMFsp1 = "";
00128         String theMFsp2 = "";
00129         String theMFsp3 = "";
00130         if ( getQueryParam("beam") != "") { theBeam = getQueryParam("beam"); }
00131         if ( getQueryParam("targ") != "") { theTarg = getQueryParam("targ"); }
00132         if ( getQueryParam("fsp1") != "") { theFsp1 = getQueryParam("fsp1"); } 
00133         if ( getQueryParam("mfsp1") != ""){ theMFsp1 = getQueryParam("mfsp1"); }
00134         if ( getQueryParam("fsp2") != "") { theFsp2 = getQueryParam("fsp2"); } 
00135         if ( getQueryParam("mfsp2") != ""){ theMFsp2 = getQueryParam("mfsp2"); }
00136         if ( getQueryParam("fsp3") != "") { theFsp3 = getQueryParam("fsp3"); } 
00137         if ( getQueryParam("mfsp3") != ""){ theMFsp3 = getQueryParam("mfsp3"); }
00138 
00139         Query q = null;
00140 
00141         // the string buffer way!!
00142         StringBuffer b = new StringBuffer();
00143 
00144         // assuming a spiresid search first 
00145         // assuming we have a beam particle next 
00146         if(theBeam != ""){
00147             if (flag == "count"){
00148                 b.append("select count(distinct yrbeam) from AxisReaction yrbeam join yrbeam._initialState beam"); 
00149            }
00150             else{
00151                 b.append("select distinct yrbeam from AxisReaction yrbeam join yrbeam._initialState beam"); 
00152             }
00153             if (theTarg != ""){ b.append(",AxisReaction yrtarg join yrtarg._initialState targ"); }
00154             if (theFsp1 != ""){ b.append(",AxisReaction yrfsp1 join yrfsp1._finalState fsp1"); }
00155             if (theFsp2 != ""){ b.append(",AxisReaction yrfsp2 join yrfsp2._finalState fsp2"); }
00156             if (theFsp3 != ""){ b.append(",AxisReaction yrfsp3 join yrfsp3._finalState fsp3"); }
00157             b.append(" where beam.name=:beampart");
00158             if (theTarg != ""){ b.append(" and targ.name=:targpart"); } 
00159             if (theFsp1 != ""){ b.append(" and fsp1.name=:fsp1part and fsp1.multiplicity=:fsp1mult"); } 
00160             if (theFsp2 != ""){ b.append(" and fsp2.name=:fsp2part and fsp2.multiplicity=:fsp2mult"); } 
00161             if (theFsp3 != ""){ b.append(" and fsp3.name=:fsp3part and fsp3.multiplicity=:fsp3mult"); } 
00162             if (theTarg != ""){ b.append(" and yrbeam = yrtarg");  }
00163             if (theFsp1 != ""){ b.append(" and yrbeam = yrfsp1"); }
00164             if (theFsp2 != ""){ b.append(" and yrbeam = yrfsp2"); }
00165             if (theFsp3 != ""){ b.append(" and yrbeam = yrfsp3"); }
00166             q = _session.createQuery(b.toString());
00167             q.setString("beampart",theBeam);
00168             if (theTarg != "")  {q.setString( "targpart",theTarg); }
00169             if (theFsp1 != "")  {q.setString( "fsp1part",theFsp1); }
00170             if (theFsp2 != "")  {q.setString( "fsp2part",theFsp2); }
00171             if (theFsp3 != "")  {q.setString( "fsp3part",theFsp3); }
00172             if (theFsp1 != "")  {q.setString( "fsp1mult",theMFsp1); }
00173             if (theFsp2 != "")  {q.setString( "fsp2mult",theMFsp2); }
00174             if (theFsp3 != "")  {q.setString( "fsp3mult",theMFsp3); }
00175         }
00176 
00177         // no inital state so next assuming we have a fsp
00178         else if(theFsp1 != "") {
00179             if (flag == "count"){
00180                 b.append("select count(distinct yrfsp1) AxisReaction yrfsp1 join yrfsp1._finalState fsp1"); 
00181             }
00182             else{
00183                 b.append("select distinct yrfsp1 from AxisReaction yrfsp1 join yrfsp1._finalState fsp1"); 
00184             }
00185             if (theFsp2 != ""){ b.append(",AxisReaction yrfsp2 join yrfsp2._finalState fsp2"); }
00186             if (theFsp3 != ""){ b.append(",AxisRreaction yrfsp3 join yrfsp3._finalState fsp3"); }
00187             b.append(" where fsp1.name=:fsp1part and fsp1.multiplicity=:fsp1mult"); 
00188             if (theFsp2 != ""){ b.append(" and fsp2.name=:fsp2part and fsp2.multiplicity=:fsp2mult"); } 
00189             if (theFsp3 != ""){ b.append(" and fsp3.name=:fsp3part and fsp3.multiplicity=:fsp3mult"); } 
00190             if (theFsp2 != ""){ b.append(" and yrfsp1 = yrfsp2"); }
00191             if (theFsp3 != ""){ b.append(" and yrfsp1 = yrfsp3"); }
00192             q = _session.createQuery(b.toString());
00193             q.setString("fsp1part",theFsp1); q.setString("fsp1mult",theMFsp1);
00194             if (theFsp2 != "") {q.setString("fsp2part",theFsp2); q.setString("fsp2mult",theMFsp2);}
00195             if (theFsp3 != "") {q.setString("fsp3part",theFsp3); q.setString("fsp3mult",theMFsp3);}
00196         }
00197 
00198         // nothing left so must want everything !!
00199         else {
00200             if (flag == "count"){
00201                 b.append("select count(distinct reac) from AxisReaction reac");
00202             }
00203             else{
00204                 b.append("select distinct reac from AxisReaction reac");
00205             }
00206             q = _session.createQuery(b.toString());
00207         }
00208 
00209         // how many results do we want out
00210 //      q.setMaxResults(Integer.parseInt(getQueryParam("number")));
00211 
00212         // execute the query and return the list of results
00213         return q;
00214 
00215     }
00216         
00217      
00218 }

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