DisplayDataset.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 DisplayDataset{
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 
00030     public String getRecordNumber(){
00031        return getQueryParam("irn");
00032     }
00033 
00034     public String getQueryString(){
00035        return getQueryParam("string");
00036     }
00037 
00038     public String getDatasetNumber(){
00039        return getQueryParam("dataset");
00040     }
00041 
00042 //Datasets
00043     private Dataset _dataset;
00044     public Dataset getDataset() { return _dataset; }
00045     public void setDataset(Dataset d) { _dataset = d; }
00046    
00047     public List <Dataset> getDatasets(){
00048         Query q = constructQuery();
00049         // how many results do we want out
00050         //q.setMaxResults(Integer.parseInt(getQueryParam("number")));
00051         // execute the query and return the list of results
00052         return q.list();   
00053     }
00054     
00055     //Paper only
00056     private Paper _paper;
00057     public Paper getPaper() { return _paper; }
00058     public void setPaper(Paper p){ _paper = p; }
00059     public List <Paper> getPapers(){
00060        String theIrn = getQueryParam("irn");
00061        Query q = _session.createQuery("select distinct p from Paper p where p._hepdataId = :irn");
00062        q.setString("irn",theIrn);
00063        return q.list();
00064     }
00065    
00066 
00067     private Query constructQuery(){
00068         return this.constructQuery("blank");
00069     }
00070 
00071     private Query constructQuery(String flag){
00072 
00073         String theIrn = "";
00074         if (!getQueryParam("irn").equals("")){ theIrn  = getQueryParam("irn");  }
00075         String theDataset = "";
00076         if (!getQueryParam("dataset").equals("")){ theDataset  = getQueryParam("dataset");  }
00077         System.out.println("irn/dataset" +  theDataset + "/" + theIrn);
00078         Query q = null;
00079 
00080         // the string buffer way!!
00081         StringBuffer b = new StringBuffer();
00082  
00083         if (flag == "count"){
00084              b.append("select count(distinct d) from Paper p join p._datasets d where d._localId = :dataset and p._hepdataId = :irn"); 
00085         }
00086         else{
00087             b.append("select distinct d from Paper p join p._datasets d where d._localId = :dataset and p._hepdataId = :irn"); 
00088         }
00089         q = _session.createQuery(b.toString());
00090         q.setString( "irn",theIrn);
00091         q.setString( "dataset",theDataset);
00092 
00093         
00094         // how many results do we want out
00095         // q.setMaxResults(Integer.parseInt(getQueryParam("number")));
00096   
00097         // execute the query and return the list of results
00098         return q;
00099 
00100     }
00101         
00102  public String getFirstAuthorName(){
00103        int n = 0;
00104        String _firstauthor = "";
00105        for (String author : _paper.getAuthors()){
00106          n += 1;
00107          if(n == 1) {_firstauthor = author;}
00108        }
00109        String _refdate = "xx";
00110        for (Reference reference : _paper.getReferences()){
00111           _refdate = reference.getDate();
00112        }
00113         int _lref = _refdate.length();
00114        _firstauthor = _firstauthor + " " + _refdate.substring(_lref-2,_lref);
00115        return _firstauthor;
00116    }
00117    public String getFirstExperimentName(){
00118        int n = 0;
00119        String _firstexperiment = "";
00120        for (Experiment experiment : _paper.getExperiments()){
00121            n += 1;
00122            if(n == 1) { _firstexperiment = experiment.getName();}
00123        }
00124        return _firstexperiment;
00125    }
00126   public String getFirstInformalName(){
00127        int n = 0;
00128        String _firstinformal = "";
00129        for (Experiment experiment : _paper.getExperiments()){
00130            n += 1;
00131            if(n == 1) { _firstinformal = experiment.getInformalName();}
00132        }
00133        return _firstinformal;
00134    }
00135    public String getFirstPublished(){
00136        int n = 0;
00137        String _firstpublished = "Not Published";
00138        System.out.println("number of references:" + _paper.getReferences().size());
00139        for (Reference ref : _paper.getReferences()){
00140            String refdesc = ref.getDescription();
00141            if(refdesc.startsWith("PL")  ||
00142               refdesc.startsWith("PR")  ||
00143               refdesc.startsWith("ZP")  ||
00144               refdesc.startsWith("EPJ") ||
00145               refdesc.startsWith("NC")  ||
00146               refdesc.startsWith("JPG") ||
00147               refdesc.startsWith("JHEP") ){
00148                  n += 1;
00149                  if(n == 1) { _firstpublished = refdesc;}
00150            }
00151        }
00152        return _firstpublished;
00153    }
00154    public String getFirstPreprint(){
00155        int n = 0;
00156        String _firstpreprint= "Not Known";
00157        System.out.println("number of references:" + _paper.getReferences().size());
00158        for (Reference reference : _paper.getReferences()){
00159            String ref = reference.getDescription();
00160            System.out.println(ref);
00161            if(ref.startsWith("PL")  ||
00162               ref.startsWith("PR")  ||
00163               ref.startsWith("ZP")  ||
00164               ref.startsWith("EPJ") ||
00165               ref.startsWith("NC")  ||
00166               ref.startsWith("JPG") ||
00167               ref.startsWith("JHEP") ){
00168             }
00169            else{
00170                  n += 1;
00171                  if(n == 1) { _firstpreprint = ref;}
00172              
00173            }
00174        }
00175        return _firstpreprint;
00176    }
00177    
00178    public String getTitle(){
00179        return _paper.getTitle();
00180    }
00181     
00182 }

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