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 FindYAxesAsFull{
00017
00018 @Persist
00019 private String reaction;
00020 public String getReaction(){ return reaction; }
00021 public void setReaction(String reaction){this.reaction = reaction;}
00022
00023 @Persist
00024 private String observable;
00025 public String getObservable(){ return observable; }
00026 public void setObservable(String observable){this.observable = observable;}
00027
00028 @Persist
00029 private String sqrts;
00030 public String getSqrts(){ return sqrts; }
00031 public void setSqrts(String sqrts){this.sqrts = sqrts;}
00032
00033 @Persist
00034 private String plength;
00035 public String getPlength(){ return plength; }
00036 public void setPlength(String plength){this.plength = plength;}
00037
00038 @Persist
00039 private String starting;
00040 public String getStarting(){ return starting; }
00041 public void setStarting(String starting){this.starting = starting;}
00042
00043
00044
00045
00046
00047 @Inject
00048 private org.hibernate.Session _session;
00049
00050
00051
00052
00053
00054
00055 public String getQueryParameters(){
00056 StringBuffer qs = new StringBuffer();
00057 String mid = "";
00058 int number = Integer.parseInt(plength);
00059 int newstart = Integer.parseInt(starting);
00060 newstart += number;
00061 qs.append(mid + "reac=" + reaction); mid = "&";
00062 qs.append(mid + "obs=" + observable); mid = "&";
00063 qs.append(mid + "sqrtslo=" + sqrts); mid = "&";
00064 qs.append(mid + "number=" + plength + mid + "start=" + Integer.toString(newstart));
00065 return qs.toString().replaceAll("\\+","%2B");
00066 }
00067
00068 public String getFirstNumber(){
00069
00070 return starting;
00071 }
00072
00073 public String getSearchString(){
00074 StringBuffer qs = new StringBuffer();
00075 qs.append("(");
00076 qs.append(reaction);
00077 qs.append(")");
00078 qs.append(" " + observable);
00079 qs.append(" " + sqrts);
00080 qs.append(" " + sqrts);
00081 return qs.toString();
00082 }
00083
00084 public String getLastNumber(){
00085 int first = Integer.parseInt(starting);
00086 int number = Integer.parseInt(plength);
00087 int last = first + number - 1;
00088 return Integer.toString(last);
00089 }
00090
00091 public String getPageSize(){
00092 return plength;
00093 }
00094
00095 public Long getCount(){
00096 return (Long) constructQuery("count").uniqueResult();
00097 }
00098
00099
00100 private String getInitialState(String r){
00101 String is="";
00102 int ipos = r.indexOf("-->");
00103 if(ipos > -1 ){ is = r.substring(0,ipos); }
00104 else { is = r; }
00105 return is.trim();
00106 }
00107 private String getFinalState(String r){
00108 String fs="";
00109 int ipos = r.indexOf("-->");
00110 if(ipos > -1) {fs = r.substring(ipos+3);}
00111 return fs.trim();
00112 }
00113
00114
00115
00116 @Persist
00117 private Paper _currentPaper;
00118
00119 public Paper getPaper() { return _currentPaper; }
00120 public void setPaper(Paper p) { _currentPaper = p; }
00121
00122 @Persist
00123 private Map <Paper,ArrayList<YAxis>> map = new HashMap<Paper,ArrayList<YAxis>>();
00124
00125 public Set <Paper> getPapers() {
00126 Query q = constructQuery();
00127
00128 int first = Integer.parseInt(starting);
00129
00130 first=first-1;
00131
00132
00133
00134
00135 map.clear();
00136 for (Iterator it=q.iterate(); it.hasNext(); ){
00137 YAxis _yAxis = (YAxis) it.next();
00138 Paper _paper=_yAxis.getDataset().getPaper();
00139 if(map.get(_paper) == null) { map.put(_paper,new ArrayList<YAxis>());}
00140 map.get(_paper).add(_yAxis);
00141
00142
00143
00144 if (map.size() > (Integer.parseInt(plength)-1)) { break; }
00145 }
00146 return map.keySet();
00147 }
00148
00149 @Persist
00150 private YAxis _yAxis;
00151
00152 public YAxis getYAxis() { return _yAxis; }
00153 public void setYAxis(YAxis yax) { _yAxis = yax; }
00154
00155 public List <YAxis> getYAxes(){
00156 return map.get(_currentPaper);
00157 }
00158
00159
00160
00161 private Query constructQuery(){
00162 return this.constructQuery("blank");
00163 }
00164
00165 private Query constructQuery(String flag){
00166
00167 List <String> isp = new ArrayList();
00168 List <String> fsp = new ArrayList();
00169 List <String> mfsp = new ArrayList();
00170
00171
00172
00173 if( reaction != "") {
00174 String is = getInitialState(reaction);
00175
00176 java.util.StringTokenizer stis = new java.util.StringTokenizer(is);
00177 while(stis.hasMoreTokens()){
00178 isp.add(stis.nextToken());
00179 }
00180 String fs = getFinalState(reaction);
00181
00182 java.util.StringTokenizer stfs = new java.util.StringTokenizer(fs);
00183 String st = "";
00184 while(stfs.hasMoreTokens()){
00185 st = stfs.nextToken();
00186 if(st.matches("^[A-Za-z].*")){
00187 fsp.add(st);
00188 mfsp.add("1");
00189 }
00190 else{
00191 fsp.add(st.substring(1));
00192 mfsp.add(st.substring(0,1));
00193 }
00194 }
00195 }
00196 String theObs = "";
00197 if ( observable != "") { theObs = observable; }
00198
00199 String theSqrtsLo = "";
00200 if ( sqrts != "") { theSqrtsLo = sqrts; }
00201
00202
00203 Query q = null;
00204
00205
00206 StringBuffer b = new StringBuffer();
00207
00208
00209
00210 if(isp.size() > 0){
00211
00212 if (flag == "count"){
00213 b.append("select count(distinct yabeam) from YAxis yabeam");
00214 }
00215 else{
00216 b.append("select distinct yabeam from YAxis yabeam");
00217 }
00218
00219 b.append(" join yabeam._reactions yrbeam");
00220 b.append(" join yrbeam._initialState beam");
00221 if (isp.size() > 1){
00222 b.append(",YAxis yatarg");
00223 b.append(" join yatarg._reactions yrtarg");
00224 b.append(" join yrtarg._initialState targ");
00225 }
00226 for (int i = 1 ; i <= fsp.size(); i++){
00227 b.append(",YAxis yafsp"+i);
00228 b.append(" join yafsp"+i+"._reactions yrfsp"+i);
00229 b.append(" join yrfsp"+i+"._finalState fsp"+i);
00230 }
00231 if(theSqrtsLo != ""){
00232 b.append(",YAxis yaprop");
00233 b.append(" join yaprop._properties prop");
00234 }
00235
00236 b.append(" where beam.name=:beampart");
00237 if (isp.size() > 1){
00238 b.append(" and targ.name=:targpart");
00239 b.append(" and yrbeam = yrtarg");
00240 }
00241 for (int i = 1 ; i <= fsp.size(); i++){
00242 b.append(" and fsp"+i+".name=:fsp"+i+"part and fsp"+i+".multiplicity=:fsp"+i+"mult");
00243 b.append(" and yrbeam = yrfsp"+i);
00244 }
00245 if (theObs != "") { b.append(" and yabeam._observable like:observable"); }
00246 if(theSqrtsLo != ""){
00247 b.append(" and yabeam = yaprop");
00248 b.append(" and prop._name like 'sqrts' and prop._lowValue>:sqrtslo");
00249 }
00250
00251
00252
00253
00254
00255 q = _session.createQuery(b.toString());
00256 q.setString("beampart",isp.get(0));
00257 if (isp.size() > 1) {q.setString( "targpart",isp.get(1)); }
00258 for (int i = 1 ; i <= fsp.size(); i++){
00259 q.setString( "fsp"+i+"part",fsp.get(i-1));
00260 q.setString( "fsp"+i+"mult",mfsp.get(i-1));
00261 }
00262
00263 if (theObs != "") {q.setString( "observable",theObs); }
00264 if (theSqrtsLo != "") {q.setString( "sqrtslo",theSqrtsLo); }
00265 }
00266
00267
00268 else if(fsp.size() > 0) {
00269
00270 if (flag == "count"){
00271 b.append("select count(distinct yafsp1) from YAxis yafsp1");
00272 }
00273 else{
00274 b.append("select distinct yafsp1 from YAxis yafsp1");
00275 }
00276
00277 b.append(" join yafsp1._reactions yrfsp1");
00278 b.append(" join yrfsp1._finalState fsp1");
00279 for (int i = 2 ; i <= fsp.size(); i++){
00280 b.append(",YAxis yafsp"+i);
00281 b.append(" join yafsp"+i+"._reactions yrfsp"+i);
00282 b.append(" join yrfsp"+i+"._finalState fsp"+i);
00283 }
00284 if(theSqrtsLo != ""){
00285 b.append(",YAxis yaprop");
00286 b.append(" join yaprop._properties prop");
00287 }
00288
00289 b.append(" where fsp1.name=:fsp1part and fsp1.multiplicity=:fsp1mult");
00290 for (int i = 2 ; i <= fsp.size(); i++){
00291 b.append(" and fsp"+i+".name=:fsp"+i+"part and fsp"+i+".multiplicity=:fsp"+i+"mult");
00292 b.append(" and yrfsp1 = yrfsp"+i);
00293 }
00294 if (theObs != ""){ b.append(" and yafsp1._observable like:observable"); }
00295 if(theSqrtsLo != ""){
00296 b.append(" and yafsp1 = yaprop");
00297 b.append(" and prop._name like 'sqrts' and prop._lowValue>:sqrtslo");
00298 }
00299
00300
00301 q = _session.createQuery(b.toString());
00302 for (int i = 1 ; i <= fsp.size(); i++){
00303 q.setString("fsp"+i+"part",fsp.get(i-1));
00304 q.setString("fsp"+i+"mult",mfsp.get(i-1));
00305 }
00306 if (theObs != "") {q.setString("observable",theObs);}
00307 if (theSqrtsLo != "") {q.setString( "sqrtslo",theSqrtsLo); }
00308 }
00309
00310 else if(theObs != "") {
00311 if (flag == "count"){
00312 b.append("select count(distinct yaobs) from YAxis yaobs");
00313 }
00314 else{
00315 b.append("select distinct yaobs from YAxis yaobs");
00316 }
00317 if(theSqrtsLo != ""){
00318 b.append(",YAxis yaprop");
00319 b.append(" join yaprop._properties prop");
00320 }
00321 b.append(" where yaobs._observable like:observable");
00322 if(theSqrtsLo != ""){
00323 b.append(" and yaobs = yaprop");
00324 b.append(" and prop._name like 'sqrts' and prop._lowValue>:sqrtslo");
00325 }
00326 q = _session.createQuery(b.toString());
00327 q.setString("observable",theObs);
00328 if (theSqrtsLo != "") {q.setString( "sqrtslo",theSqrtsLo); }
00329 }
00330
00331
00332 else if(theSqrtsLo != "") {
00333 if (flag == "count"){
00334 b.append("select count(distinct yaprop) from YAxis yaprop");
00335 }
00336 else{
00337 b.append("select distinct yaprop from YAxis yaprop");
00338 }
00339 b.append(" join yaprop._properties prop");
00340
00341 b.append(" where prop._name like 'sqrts' and prop._lowValue>:sqrtslo");
00342
00343 q = _session.createQuery(b.toString());
00344 q.setString("sqrtslo",theSqrtsLo);
00345 }
00346
00347 else{
00348 if (flag == "count"){
00349 b.append("select count(distinct ya) from YAxis ya");
00350 }
00351 else{
00352 b.append("select distinct ya from YAxis ya");
00353 }
00354 q = _session.createQuery(b.toString());
00355 }
00356
00357
00358
00359
00360
00361 return q;
00362
00363 }
00364
00365
00366
00367 }