Ignore:
Timestamp:
07/22/11 21:31:08 (13 years ago)
Author:
gaba
Message:

SRU queries added

Location:
MDService2/trunk/MDService2/src/eu/clarin/cmdi/mdservice/action
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • MDService2/trunk/MDService2/src/eu/clarin/cmdi/mdservice/action/GenericProxyAction.java

    r1455 r1467  
    525525        public Boolean isSRURepository(){
    526526                //Boolean issru = false;
    527                 String srustr = "";
     527                String typestr = "";
    528528               
    529529                if (repositories == null ) {
     
    545545                for(int i=0;i<json.size();i++){
    546546                        if (json.getJSONObject(i).getString("name").equals(getRepository())){
    547                                 srustr =  json.getJSONObject(i).getString("sruextern");
    548                         }
    549                 }
    550                
    551                 return (srustr.equals("1"));
     547                                typestr =  json.getJSONObject(i).getString("type");
     548                        }
     549                }
     550               
     551                return (typestr.equals("sru"));
    552552               
    553553        }
  • MDService2/trunk/MDService2/src/eu/clarin/cmdi/mdservice/action/SRUProxyAction.java

    r1455 r1467  
    5353
    5454
    55 public class SRUProxyAction extends ActionSupport
    56 implements ServletRequestAware
     55public class SRUProxyAction extends GenericProxyAction//ActionSupport
     56//implements ServletRequestAware
    5757{
    5858
     
    8282        private MDRepoProxyAction mdrepoproxyaction;
    8383        private TermsProxyAction termsproxyaction;
    84         private InputStream resultStream;
    85         private HttpServletRequest request;
     84        //private InputStream resultStream;
     85        //private HttpServletRequest request;
    8686       
    8787        private static int OP_SEARCHRETRIEVE = 1;
    8888        private static int OP_EXPLAIN = 2;
    8989        private static int OP_SCAN = 3;
     90       
     91        //TODO cache after analysis
     92        @Override
     93        public String getCache() {
     94                return Cache.SKIP;
     95        }
    9096       
    9197        private final static HashMap<String,String> hash_operations = new HashMap<String,String>();
     
    116122         }
    117123         
    118          @Override
     124         /*@Override
    119125                public void setServletRequest(HttpServletRequest arg0) {
    120126                        request = arg0;
     
    124130                        return request;
    125131                }
    126                
     132                */
    127133                public Diagnostics getDiagnostics(){
    128134                        return this.diagnostics;
     
    141147                        this.q = q;
    142148                }
    143          
     149         /*
    144150         public InputStream getResultStream() {
    145151             return resultStream;
     
    148154                resultStream = _resultStream;
    149155         }
    150        
     156        */
    151157
    152158        public String getVersion() {
     
    264270       
    265271        public String getDiagnosticStreamName() throws TransformerConfigurationException, UnsupportedEncodingException, ParserConfigurationException, TransformerException, TransformerFactoryConfigurationError{
    266                 resultStream = this.Diagnostics().buildXMLStream();
     272                this.setResultStream(this.Diagnostics().buildXMLStream());
    267273                return "resultStream";
    268274        }
     
    275281        public String getProxyKey() {
    276282                return "";
     283        }
     284       
     285        @Override
     286        public String getBaseURI() {           
     287                Admin.notifyUser("SRU-repositorypath:" + getRepositoryPath());
     288                String uri = getRepositoryPath();//Admin.getConfig().getProperty(getProxyKey() + ".uri");               
     289                return uri;
    277290        }
    278291       
     
    346359                                                                XMLSerializer xmlserializer = new XMLSerializer();
    347360                                                                String xml = xmlserializer.write( mdrepoproxyaction.getRepositories() ); 
    348                                                                 resultStream = new ByteArrayInputStream(xml.getBytes("UTF-8"));
     361                                                                this.setResultStream(new ByteArrayInputStream(xml.getBytes("UTF-8")));
    349362
    350363                                                        } else {
     
    359372        }
    360373       
    361         public void prepare() throws UnsupportedEncodingException{
     374        public void sru2MD() throws UnsupportedEncodingException{
    362375                // special handling of parameter setting, x-cmd-... not alowed in java
    363376                this.setX_cmd_collections(getServletRequest().getParameter("x-cmd-collections"));
     
    393406        }
    394407       
     408        public void  prepareMD() throws Exception{
     409                sru2MD();
     410                if (Diagnostics().Accepted()){
     411                        // root-explain
     412                        if (this.termsproxyaction != null) {                   
     413                                if (this.termsproxyaction.execute() == SUCCESS){
     414                                        this.setResultStream(this.termsproxyaction.getResultStream());
     415                                        //return SUCCESS;
     416                                }
     417                        } else {
     418                                //TODO diagnostic                       
     419                                if (this.mdrepoproxyaction.getTargetRequest() == null) {
     420                                        Diagnostics().Add(Diagnostic.QUERYSYNTAXERROR);
     421                                        //return ERROR;
     422                                }
     423                                if (this.mdrepoproxyaction.execute() == SUCCESS){
     424                                        this.setResultStream(this.mdrepoproxyaction.getResultStream());
     425                                        postprocess();
     426                                        //return SUCCESS;
     427                                }
     428                        }
     429                }
     430                //return ERROR;
     431        }
     432       
    395433        public static String inputStreamAsString(InputStream stream)
    396434                throws IOException {
     
    435473                        if (this.getRecordPacking().toLowerCase().equals("string")){
    436474                                try {
    437                                         resultStream = IOUtils.toInputStream(StringEscapeUtils.escapeXml(inputStreamAsString(resultStream)));
     475                                        this.setResultStream(IOUtils.toInputStream(StringEscapeUtils.escapeXml(inputStreamAsString(this.getResultStream()))));
    438476                                } catch (IOException e) {
    439477                                        // TODO Auto-generated catch block
     
    446484                // add diagnostics
    447485                if (Diagnostics().Exists()){
    448                         Document doc = newDocumentFromInputStream(resultStream);
     486                        Document doc = newDocumentFromInputStream(this.getResultStream());
    449487                        Node r_element=  doc.getElementsByTagName("searchRetrieveResponse").item(0);
    450488                        Document ddoc = Diagnostics().buildXMLDocument();
     
    456494                        StreamResult result = new StreamResult(xmlAsWriter);   
    457495                        TransformerFactory.newInstance().newTransformer().transform(source, result);
    458                         resultStream = new ByteArrayInputStream(xmlAsWriter.toString().getBytes("UTF-8"));
    459                 }
    460         }
    461        
     496                        this.setResultStream(new ByteArrayInputStream(xmlAsWriter.toString().getBytes("UTF-8")));
     497                }
     498        }
     499       
     500        @Override
     501        public URL getTargetRequest() throws IOException {
     502                String requestURI = "";
     503                URL targetURL;
     504               
     505                if (this.getBaseURI() == null){
     506                        requestURI = this.getX_cmd_repository();
     507                } else {
     508                        requestURI = this.getBaseURI();
     509                }
     510                //TODO params
     511                Set set = getServletRequest().getParameterMap().entrySet();
     512                Iterator i = set.iterator();
     513                String params = "";
     514            while(i.hasNext()){
     515                      Map.Entry me = (Map.Entry)i.next();
     516                      if (!(me.getKey().equals("x-cmd-repository") || me.getKey().equals("x-cmd-collections"))){
     517                              params = params + "&" + me.getKey() + "=" + ((String[])me.getValue())[0]; 
     518                      }
     519                }
     520            params = params.substring(1);
     521            targetURL = new URL(requestURI + "?" + params);
     522                return targetURL;
     523        }
     524       
     525        @Override
     526        public void prepare() throws Exception{
     527                this.setX_cmd_repository(getServletRequest().getParameter("x-cmd-repository"));
     528                this.setRepository(this.getX_cmd_repository());
     529                //TODO xsl usage according particular repositories ?
     530                //this.setActionkey("recordset");
     531                this.setFormat("xml");
     532               
     533                //extern SRU repository
     534                if (this.isSRURepository() || this.getBaseURI() == null){
     535                        super.prepare();
     536                }
     537                else {
     538                         prepareMD();
     539                }
     540               
     541        }
    462542        /**
    463543         * default Action method
    464544         */
     545        /*
    465546        public String execute() throws Exception {
    466547                this.setX_cmd_repository(getServletRequest().getParameter("x-cmd-repository"));
     
    514595                return ERROR;
    515596        }
    516 
     597*/
    517598
    518599}
Note: See TracChangeset for help on using the changeset viewer.