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
00016 public class TestSearch{
00017
00018 @Inject
00019 private RequestGlobals _reqGlobals;
00020
00021 @Inject
00022 private org.hibernate.Session _session;
00023
00024
00025 public String getQueryParam(String param){
00026 return _reqGlobals.getRequest().getParameter(param);
00027 }
00028
00029 public Long getCount(){
00030 return (Long) constructQuery("count").uniqueResult();
00031 }
00032
00033
00034
00035
00036 private YAxis _yaxis;
00037 public YAxis getYAxis() { return _yaxis; }
00038 public void setYAxis(YAxis y) { _yaxis = y; }
00039
00040 public List <YAxis> getYAxes(){
00041 Query q = constructQuery();
00042
00043 q.setMaxResults(Integer.parseInt(getQueryParam("number")));
00044
00045 return q.list();
00046 }
00047
00048 public Query constructQuery(){
00049 return this.constructQuery("blank");
00050 }
00051
00052 public Query constructQuery(String flag){
00053
00054 String theBeam = "";
00055 String theTarg = "";
00056 String theFsp1 = "";
00057 String theFsp2 = "";
00058 String theFsp3 = "";
00059 String theMFsp1 = "";
00060 String theMFsp2 = "";
00061 String theMFsp3 = "";
00062 String theObs = "";
00063 if ( getQueryParam("beam") != "") { theBeam = getQueryParam("beam"); }
00064 if ( getQueryParam("targ") != "") { theTarg = getQueryParam("targ"); }
00065 if ( getQueryParam("fsp1") != "") { theFsp1 = getQueryParam("fsp1"); }
00066 if ( getQueryParam("mfsp1") != ""){ theMFsp1 = getQueryParam("mfsp1"); }
00067 if ( getQueryParam("fsp2") != "") { theFsp2 = getQueryParam("fsp2"); }
00068 if ( getQueryParam("mfsp2") != ""){ theMFsp2 = getQueryParam("mfsp2"); }
00069 if ( getQueryParam("fsp3") != "") { theFsp3 = getQueryParam("fsp3"); }
00070 if ( getQueryParam("mfsp3") != ""){ theMFsp3 = getQueryParam("mfsp3"); }
00071 if ( getQueryParam("obs") != "") { theObs = getQueryParam("obs"); }
00072
00073 Query q = null;
00074
00075
00076 StringBuffer b = new StringBuffer();
00077
00078
00079 if(theBeam != ""){
00080 if (flag == "count"){
00081 b.append("select count(yabeam) from YAxis yabeam join yabeam._reactions yrbeam join yrbeam._initialState beam");
00082 }
00083 else{
00084 b.append("select distinct yabeam from YAxis yabeam join yabeam._reactions yrbeam join yrbeam._initialState beam");
00085 }
00086 if (theTarg != ""){ b.append(",YAxis yatarg join yatarg._reactions yrtarg join yrtarg._initialState targ"); }
00087 if (theFsp1 != ""){ b.append(",YAxis yafsp1 join yafsp1._reactions yrfsp1 join yrfsp1._finalState fsp1"); }
00088 if (theFsp2 != ""){ b.append(",YAxis yafsp2 join yafsp2._reactions yrfsp2 join yrfsp2._finalState fsp2"); }
00089 if (theFsp3 != ""){ b.append(",YAxis yafsp3 join yafsp3._reactions yrfsp3 join yrfsp3._finalState fsp3"); }
00090 b.append(" where beam.name=:beampart");
00091 if (theTarg != ""){ b.append(" and targ.name=:targpart"); }
00092 if (theFsp1 != ""){ b.append(" and fsp1.name=:fsp1part and fsp1.multiplicity=:fsp1mult"); }
00093 if (theFsp2 != ""){ b.append(" and fsp2.name=:fsp2part and fsp2.multiplicity=:fsp2mult"); }
00094 if (theFsp3 != ""){ b.append(" and fsp3.name=:fsp3part and fsp3.multiplicity=:fsp3mult"); }
00095 if (theObs != ""){ b.append(" and yabeam._observable=:observable"); }
00096 if (theTarg != ""){ b.append(" and yrbeam = yrtarg"); }
00097 if (theFsp1 != ""){ b.append(" and yrbeam = yrfsp1"); }
00098 if (theFsp2 != ""){ b.append(" and yrbeam = yrfsp2"); }
00099 if (theFsp3 != ""){ b.append(" and yrbeam = yrfsp3"); }
00100 q = _session.createQuery(b.toString());
00101 q.setString("beampart",theBeam);
00102 if (theTarg != "") {q.setString( "targpart",theTarg); }
00103 if (theFsp1 != "") {q.setString( "fsp1part",theFsp1); }
00104 if (theFsp2 != "") {q.setString( "fsp2part",theFsp2); }
00105 if (theFsp3 != "") {q.setString( "fsp3part",theFsp3); }
00106 if (theFsp1 != "") {q.setString( "fsp1mult",theMFsp1); }
00107 if (theFsp2 != "") {q.setString( "fsp2mult",theMFsp2); }
00108 if (theFsp3 != "") {q.setString( "fsp3mult",theMFsp3); }
00109 if (theObs != "") {q.setString( "observable",theObs); }
00110 }
00111
00112
00113 else if(theFsp1 != "") {
00114 if (flag == "count"){
00115 b.append("select count(yafsp1) from YAxis yafsp1 join yafsp1._reactions yrfsp1 join yrfsp1._finalState fsp1");
00116 }
00117 else {
00118 b.append("select distinct yafsp1 from YAxis yafsp1 join yafsp1._reactions yrfsp1 join yrfsp1._finalState fsp1");
00119 }
00120 if (theFsp2 != ""){ b.append(",YAxis yafsp2 join yafsp2._reactions yrfsp2 join yrfsp2._finalState fsp2"); }
00121 if (theFsp3 != ""){ b.append(",YAxis yafsp3 join yafsp3._reactions yrfsp3 join yrfsp3._finalState fsp3"); }
00122 b.append(" where fsp1.name=:fsp1part and fsp1.multiplicity=:fsp1mult");
00123 if (theFsp2 != ""){ b.append(" and fsp2.name=:fsp2part and fsp2.multiplicity=:fsp2mult"); }
00124 if (theFsp3 != ""){ b.append(" and fsp3.name=:fsp3part and fsp3.multiplicity=:fsp3mult"); }
00125 if (theObs != ""){ b.append(" and yafsp1._observable=:observable"); }
00126 if (theFsp2 != ""){ b.append(" and yrfsp1 = yrfsp2"); }
00127 if (theFsp3 != ""){ b.append(" and yrfsp1 = yrfsp3"); }
00128 q = _session.createQuery(b.toString());
00129 q.setString("fsp1part",theFsp1); q.setString("fsp1mult",theMFsp1);
00130 if (theFsp2 != "") {q.setString("fsp2part",theFsp2); q.setString("fsp2mult",theMFsp2);}
00131 if (theFsp3 != "") {q.setString("fsp3part",theFsp3); q.setString("fsp3mult",theMFsp3);}
00132 if (theObs != "") {q.setString("observable",theObs);}
00133 }
00134
00135
00136 else if(theObs != "") {
00137 if (flag == "count"){
00138 b.append("select count(yaobs) from YAxis yaobs");
00139 }
00140 else {
00141 b.append("select distinct yaobs from YAxis yaobs");
00142 }
00143 b.append(" where yaobs._observable=:observable");
00144 q = _session.createQuery(b.toString());
00145 q.setString("observable",theObs);
00146 }
00147
00148
00149 else {
00150 if (flag == "count"){
00151 b.append("select count(ya) from YAxis ya");
00152 }
00153 else {
00154 b.append("select distinct ya from YAxis ya");
00155 }
00156 q = _session.createQuery(b.toString());
00157 }
00158
00159 return q;
00160 }
00161
00162
00163 public Long getSpiresId(){
00164 return _yaxis.getPaper().getSpiresId();
00165 }
00166
00167 }