FindPapersAsList.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 
00016 public class FindPapersAsList{
00017 
00018     @Inject
00019     private org.hibernate.Session _session;
00020 
00021     @Inject
00022     private RequestGlobals _reqGlobals;
00023      
00024 
00025     public String getQueryParam(String param){
00026        return _reqGlobals.getRequest().getParameter(param);
00027     }
00028 
00029     @Persist
00030     private String reaction;
00031     public String getReaction(){ return reaction; } 
00032     public void setReaction(String reaction){this.reaction = reaction;}
00033 
00034     @Persist
00035     private String observable;
00036     public String getObservable(){ return observable; } 
00037     public void setObservable(String observable){this.observable = observable;}
00038 
00039     @Persist
00040     private String sqrts;
00041     public String getSqrts(){ return sqrts; } 
00042     public void setSqrts(String sqrts){this.sqrts = sqrts;}
00043 
00044     @Persist
00045     private String plength;
00046     public String getPlength(){ return plength; } 
00047     public void setPlength(String plength){this.plength = plength;}
00048 
00049     @Persist
00050     private String starting;
00051     public String getStarting(){ return starting; } 
00052     public void setStarting(String starting){this.starting = starting;}
00053 
00054 
00055     public String getFirstQueryParameters(){
00056         StringBuffer qs = new StringBuffer();
00057         String mid = "";
00058         int number =  Integer.parseInt(plength);
00059         int newstart = 1;
00060         qs.append(mid + "reac=" + reaction);  mid = "&";
00061         qs.append(mid + "obs=" + observable);  mid = "&";
00062         qs.append(mid + "sqrtslo=" + sqrts);  mid = "&";
00063         qs.append(mid + "number=" + plength + mid + "start=" + Integer.toString(newstart));
00064         return qs.toString().replaceAll("\\+","%2B");
00065     }
00066  
00067     public String getLastQueryParameters(){
00068         StringBuffer qs = new StringBuffer();
00069         String mid = "";
00070         int number =  Integer.parseInt(plength);
00071         int newstart = Integer.parseInt(starting);
00072         int last = getCount().intValue();
00073         newstart = last - Integer.parseInt(plength) + 1;
00074         qs.append(mid + "reac=" + reaction);  mid = "&";
00075         qs.append(mid + "obs=" + observable);  mid = "&";
00076         qs.append(mid + "sqrtslo=" + sqrts);  mid = "&";
00077         qs.append(mid + "number=" + plength + mid + "start=" + Integer.toString(newstart));
00078         return qs.toString().replaceAll("\\+","%2B");
00079     }
00080 
00081     public String getNextQueryParameters(){
00082         StringBuffer qs = new StringBuffer();
00083         String mid = "";
00084         int number =  Integer.parseInt(plength);
00085         int newstart = Integer.parseInt(starting);
00086         newstart += number;
00087         qs.append(mid + "reac=" + reaction);  mid = "&";
00088         qs.append(mid + "obs=" + observable);  mid = "&";
00089         qs.append(mid + "sqrtslo=" + sqrts);  mid = "&";
00090         qs.append(mid + "number=" + plength + mid + "start=" + Integer.toString(newstart));
00091         return qs.toString().replaceAll("\\+","%2B");
00092     }
00093 
00094     public String getPrevQueryParameters(){
00095         StringBuffer qs = new StringBuffer();
00096         String mid = "";
00097         int number =  Integer.parseInt(plength);
00098         int newstart = Integer.parseInt(starting);
00099         newstart -= number;
00100         qs.append(mid + "reac=" + reaction);  mid = "&";
00101         qs.append(mid + "obs=" + observable);  mid = "&";
00102         qs.append(mid + "sqrtslo=" + sqrts);  mid = "&";
00103         qs.append(mid + "number=" + plength + mid + "start=" + Integer.toString(newstart));
00104         return qs.toString().replaceAll("\\+","%2B");
00105     }
00106 
00107     public String getFirstNumber(){
00108        return starting;
00109     }
00110 
00111     public String getSearchString(){
00112         StringBuffer qs = new StringBuffer();
00113         qs.append("(");
00114         qs.append(reaction);
00115         qs.append(")");
00116         qs.append(" " + observable);
00117         qs.append(" " + sqrts);
00118         qs.append(" " + sqrts);
00119         return qs.toString();
00120     }
00121 
00122     public String getLastNumber(){
00123         int first =  Integer.parseInt(starting);
00124         int number = Integer.parseInt(plength);
00125         int last = first + number - 1;
00126         return Integer.toString(last);
00127    }
00128 
00129     public String getPageSize(){
00130        return plength;
00131     }
00132 
00133     public Long getCount(){
00134         return (Long) ConstructQuery.Papers(reaction,observable,sqrts,"count",_session).uniqueResult();
00135     }
00136 
00137  
00138 //Papers search
00139     private Paper _paper;
00140     public Paper getPaper() { return _paper; }
00141     public void setPaper(Paper paper) { _paper = paper; }
00142    
00143     public List <Paper> getPapers(){
00144 
00145         if(getQueryParam("reac") == null){}else{ reaction = getQueryParam("reac"); }
00146         if(getQueryParam("obs") == null){}else {observable = getQueryParam("obs");}
00147         if(getQueryParam("sqrtslo") == null){}else {sqrts = getQueryParam("sqrtslo");}
00148         if(getQueryParam("number") == null){}else {plength = getQueryParam("number");}
00149         if(getQueryParam("start") == null){}else {starting = getQueryParam("start");}        System.out.println("sqrts is " + sqrts);
00150         System.out.println("reaction is " + reaction);
00151         System.out.println("observable is " + observable);
00152         System.out.println("sqrts is " + sqrts);
00153         System.out.println("plength is " + plength);
00154         System.out.println("starting is " + starting);
00155         Query q = ConstructQuery.Papers(reaction,observable,sqrts,"",_session);
00156            // how many results do we want out and where to start
00157         int first = Integer.parseInt(starting);
00158         // setFirstResult counts from zero!!
00159         first=first-1;
00160         q.setFirstResult(first).setMaxResults(Integer.parseInt(plength));
00161            // execute the query and return the list of results
00162         System.out.println(q);
00163         return q.list();   
00164      }
00165 }

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