FindPaperSummary.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 FindPaperSummary{
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        String temp =  _reqGlobals.getRequest().getParameter(param);
00027        return _reqGlobals.getRequest().getParameter(param);
00028     }
00029 
00030     @Persist
00031     private String queryString;
00032     public String getQueryString(){ return queryString; } 
00033     public void setQueryString(String queryString){this.queryString = queryString;}
00034 
00035     @Persist
00036     private String experiment;
00037     public String getExperiment(){ return experiment; } 
00038     public void setExperiment(String experiment){this.experiment = experiment;}
00039 
00040     @Persist
00041     private String reaction;
00042     public String getReaction(){ return reaction; } 
00043     public void setReaction(String reaction){this.reaction = reaction;}
00044 
00045     @Persist
00046     private String observable;
00047     public String getObservable(){ return observable; } 
00048     public void setObservable(String observable){this.observable = observable;}
00049 
00050     @Persist
00051     private String sqrts;
00052     public String getSqrts(){ return sqrts; } 
00053     public void setSqrts(String sqrts){this.sqrts = sqrts;}
00054 
00055     @Persist
00056     private String plength;
00057     public String getPlength(){ return plength; } 
00058     public void setPlength(String plength){this.plength = plength;}
00059 
00060     @Persist
00061     private String starting = "1";
00062     public String getStarting(){
00063         if(getQueryParam("start") == null){starting = "1";}
00064         else {starting = getQueryParam("start");}        
00065         return starting; 
00066     } 
00067     public void setStarting(String starting){this.starting = starting;}
00068 
00069 
00070     public String getFirstQueryParameters(){
00071         StringBuffer qs = new StringBuffer();
00072         String mid = "";
00073         int number =  Integer.parseInt(plength);
00074         int newstart = 1;
00075         qs.append(mid + "experiment=" + experiment);  mid = "&";
00076         qs.append(mid + "reaction=" + reaction);  mid = "&";
00077         qs.append(mid + "observable=" + observable);  mid = "&";
00078         qs.append(mid + "sqrtslo=" + sqrts);  mid = "&";
00079         qs.append(mid + "number=" + plength + mid + "start=" + Integer.toString(newstart));
00080         return qs.toString().replaceAll("\\+","%2B");
00081     }
00082  
00083     public String getLastQueryParameters(){
00084         StringBuffer qs = new StringBuffer();
00085         String mid = "";
00086         int number =  Integer.parseInt(plength);
00087         int newstart = Integer.parseInt(starting);
00088         int last = getCount().intValue();
00089         newstart = last - Integer.parseInt(plength) + 1;
00090         qs.append(mid + "experiment=" + experiment);  mid = "&";
00091         qs.append(mid + "reaction=" + reaction);  mid = "&";
00092         qs.append(mid + "observable=" + observable);  mid = "&";
00093         qs.append(mid + "sqrtslo=" + sqrts);  mid = "&";
00094         qs.append(mid + "number=" + plength + mid + "start=" + Integer.toString(newstart));
00095         return qs.toString().replaceAll("\\+","%2B");
00096     }
00097 
00098     public String getNextQueryParameters(){
00099         StringBuffer qs = new StringBuffer();
00100         String mid = "";
00101         int number =  Integer.parseInt(plength);
00102         int newstart = Integer.parseInt(starting);
00103         newstart += number;
00104         qs.append(mid + "experiment=" + experiment);  mid = "&";
00105         qs.append(mid + "reaction=" + reaction);  mid = "&";
00106         qs.append(mid + "observable=" + observable);  mid = "&";
00107         qs.append(mid + "sqrtslo=" + sqrts);  mid = "&";
00108         qs.append(mid + "number=" + plength + mid + "start=" + Integer.toString(newstart));
00109         return qs.toString().replaceAll("\\+","%2B");
00110     }
00111 
00112     public String getPrevQueryParameters(){
00113         StringBuffer qs = new StringBuffer();
00114         String mid = "";
00115         int number =  Integer.parseInt(plength);
00116         int newstart = Integer.parseInt(starting);
00117         newstart -= number;
00118         qs.append(mid + "experiment=" + experiment);  mid = "&";
00119         qs.append(mid + "reaction=" + reaction);  mid = "&";
00120         qs.append(mid + "observable=" + observable);  mid = "&";
00121         qs.append(mid + "sqrtslo=" + sqrts);  mid = "&";
00122         qs.append(mid + "number=" + plength + mid + "start=" + Integer.toString(newstart));
00123         return qs.toString().replaceAll("\\+","%2B");
00124     }
00125 
00126     public String getFirstNumber(){
00127        if(getQueryParam("start") == null){starting = "1";}else {starting = getQueryParam("start");}        
00128        return starting;
00129     }
00130 
00131     public String getSearchString(){
00132         StringBuffer qs = new StringBuffer();
00133         qs.append("(");
00134         qs.append(reaction);
00135         qs.append(")");
00136         qs.append(" " + observable);
00137         qs.append(" " + sqrts);
00138         qs.append(" " + sqrts);
00139         return qs.toString();
00140     }
00141 
00142     public String getLastNumber(){
00143         int first =  Integer.parseInt(starting);
00144         int number = Integer.parseInt(plength);
00145         int last = first + number - 1;
00146         return Integer.toString(last);
00147    }
00148 
00149     public String getPageSize(){
00150        return plength;
00151     }
00152 
00153     public Long getCount(){
00154         if(
00155            (getQueryParam("experiment") == null || getQueryParam("experiment").equals("null")) 
00156                          && (experiment == null || experiment.equals("null")) 
00157        && (getQueryParam("queryString") == null || getQueryParam("queryString").equals("null")) 
00158                         && (queryString == null || queryString.equals("null")) 
00159           ){
00160             return (Long) ConstructQueryPaper.Physics(experiment,null,null,reaction,observable,sqrts,"count",_session).uniqueResult();
00161         }
00162         else if(
00163           (getQueryParam("queryString") == null || getQueryParam("queryString").equals("null")) 
00164                         && (queryString == null || queryString.equals("null")) 
00165           ){
00166             return (Long) ConstructQueryPaper.Experiment(experiment,"count",_session).uniqueResult();
00167         }
00168         else{
00169             return (Long) ConstructQueryPaper.QueryString(queryString,"count",_session).uniqueResult();
00170         }
00171 
00172 //        if((getQueryParam("experiment") == null || getQueryParam("experiment").equals("null")) 
00173 //                       && (experiment == null || experiment.equals("null")) ){
00174 //           return (Long) ConstructQuery.Papers(reaction,observable,sqrts,"count",_session).uniqueResult();
00175 //         }
00176 //        else{           
00177 //           return (Long) ConstructQuery.Papers(experiment,"count",_session).uniqueResult();
00178 //        }
00179    }
00180 
00181    public String getFirstAuthorName(){
00182        int n = 0;
00183        String _firstauthor = "";
00184        for (String author : _paper.getAuthors()){
00185          n += 1;
00186          if(n == 1) {_firstauthor = author;}
00187        }
00188        String _refdate = "xx";
00189        for (Reference reference : _paper.getReferences()){
00190           _refdate = reference.getDate();
00191        }
00192         int _lref = _refdate.length();
00193        _firstauthor = _firstauthor + " " + _refdate.substring(_lref-2,_lref);
00194        return _firstauthor;
00195    }
00196    public String getFirstExperimentName(){
00197        int n = 0;
00198        String _firstexperiment = "";
00199        for (Experiment experiment : _paper.getExperiments()){
00200            n += 1;
00201            if(n == 1) { _firstexperiment = experiment.getName();}
00202        }
00203        return _firstexperiment;
00204    }
00205   public String getFirstInformalName(){
00206        int n = 0;
00207        String _firstinformal = "";
00208        for (Experiment experiment : _paper.getExperiments()){
00209            n += 1;
00210            if(n == 1) { _firstinformal = experiment.getInformalName();}
00211        }
00212        return _firstinformal;
00213    }
00214    public String getFirstPublished(){
00215        int n = 0;
00216        String _firstpublished = "Not Published";
00217        for (Reference ref : _paper.getReferences()){
00218            String refdesc = ref.getDescription();
00219            if(refdesc.startsWith("PL")  ||
00220               refdesc.startsWith("PR")  ||
00221               refdesc.startsWith("ZP")  ||
00222               refdesc.startsWith("EPJ") ||
00223               refdesc.startsWith("NC")  ||
00224               refdesc.startsWith("JPG") ||
00225               refdesc.startsWith("JHEP") ){
00226                  n += 1;
00227                  if(n == 1) { _firstpublished = refdesc;}
00228            }
00229        }
00230        return _firstpublished;
00231    }
00232    public String getFirstPreprint(){
00233        int n = 0;
00234        String _firstpreprint= "Not Known";
00235        for (Reference reference : _paper.getReferences()){
00236            String ref = reference.getDescription();
00237            if(ref.startsWith("PL")  ||
00238               ref.startsWith("PR")  ||
00239               ref.startsWith("ZP")  ||
00240               ref.startsWith("EPJ") ||
00241               ref.startsWith("NC")  ||
00242               ref.startsWith("JPG") ||
00243               ref.startsWith("JHEP") ){
00244             }
00245            else{
00246                  n += 1;
00247                  if(n == 1) { _firstpreprint = ref;}
00248              
00249            }
00250        }
00251        return _firstpreprint;
00252    }
00253    
00254    public String getTitle(){
00255        return _paper.getTitle();
00256    }
00257    @Persist
00258    private int counter=0;
00259    public String setCounter(){
00260        counter = Integer.parseInt(starting)-1;
00261        return "";
00262    }
00263    public int getCounter(){
00264        counter += 1;
00265        return counter;
00266    }
00267 //Papers search
00268     private Paper _paper;
00269     public Paper getPaper() {  return _paper; }
00270     public void setPaper(Paper paper) {  _paper = paper; }
00271    
00272     public List <Paper> getPapers(){
00273         if(getQueryParam("queryString") == null){}else{ queryString = getQueryParam("queryString"); }
00274         if(getQueryParam("experiment") == null){}else{ experiment = getQueryParam("experiment"); }
00275         if(getQueryParam("reaction") == null){}else{ reaction = getQueryParam("reaction"); }
00276         if(getQueryParam("observable") == null){}else {observable = getQueryParam("observable");}
00277         if(getQueryParam("sqrtslo") == null){}else {sqrts = getQueryParam("sqrtslo");}
00278         if(getQueryParam("number") == null){}else {plength = getQueryParam("number");}
00279         if(getQueryParam("start") == null){}else {starting = getQueryParam("start");}        
00280         Query q=null;
00281         if(
00282            (getQueryParam("experiment") == null || getQueryParam("experiment").equals("null")) 
00283                          && (experiment == null || experiment.equals("null")) 
00284        && (getQueryParam("queryString") == null || getQueryParam("queryString").equals("null")) 
00285                         && (queryString == null || queryString.equals("null")) 
00286           ){
00287             q = ConstructQueryPaper.Physics(experiment,null,null,reaction,observable,sqrts,"",_session);
00288         }
00289         else if(
00290           (getQueryParam("queryString") == null || getQueryParam("queryString").equals("null")) 
00291                         && (queryString == null || queryString.equals("null")) 
00292           ){
00293             q = ConstructQueryPaper.Experiment(experiment,"",_session);
00294         }
00295         else{
00296             q = ConstructQueryPaper.QueryString(queryString,"",_session);
00297         }
00298            // how many results do we want out and where to start
00299         int first = Integer.parseInt(starting);
00300         // setFirstResult counts from zero!!
00301         first=first-1;
00302         q.setFirstResult(first).setMaxResults(Integer.parseInt(plength));
00303            // execute the query and return the list of results
00304         return q.list();   
00305  
00306     }
00307 }

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