Changeset 1455 for MDService2


Ignore:
Timestamp:
06/29/11 21:54:52 (13 years ago)
Author:
gaba
Message:

sru-reader first version

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

Legend:

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

    r1429 r1455  
    523523        }
    524524       
     525        public Boolean isSRURepository(){
     526                //Boolean issru = false;
     527                String srustr = "";
     528               
     529                if (repositories == null ) {
     530                        try {
     531                                setRepositories(GenericProxyAction.createRepositories());
     532                        } catch (IOException e) {
     533                                // TODO Auto-generated catch block
     534                                e.printStackTrace();
     535                        } catch (InterruptedException e) {
     536                                // TODO Auto-generated catch block
     537                                e.printStackTrace();
     538                        } catch (TransformerException e) {
     539                                // TODO Auto-generated catch block
     540                                e.printStackTrace();
     541                        }
     542                }
     543                // static repositories
     544                net.sf.json.JSONArray json = getRepositories();
     545                for(int i=0;i<json.size();i++){
     546                        if (json.getJSONObject(i).getString("name").equals(getRepository())){
     547                                srustr =  json.getJSONObject(i).getString("sruextern");
     548                        }
     549                }
     550               
     551                return (srustr.equals("1"));
     552               
     553        }
    525554        public String addDurationKey(){
    526555                String req_key = getRequestKey();
  • MDService2/trunk/MDService2/src/eu/clarin/cmdi/mdservice/action/SRUProxyAction.java

    r1236 r1455  
    1515import java.net.URL;
    1616import java.util.HashMap;
     17import java.util.Iterator;
     18import java.util.Map;
     19import java.util.Set;
    1720
    1821import javax.servlet.http.HttpServletRequest;
     
    287290                mdrepoproxyaction.setActionkey(hash_operations.get(this.getOperation()));
    288291               
     292                // set the SRU extern property in proxyaction
     293                if (this.getX_cmd_repository() != null ) {
     294                        mdrepoproxyaction.setRepository(this.getX_cmd_repository());
     295                        //TODO\
     296                        if (mdrepoproxyaction.getBaseURI() == null) this.Diagnostics().Add(Diagnostic.UNSUPPORTED_PARAMETERVALUE, "Unknown repository." + getX_cmd_repository());
     297                }
     298               
    289299                if (operation.equals("searchRetrieve")){
    290300                       
     
    351361        public void prepare() throws UnsupportedEncodingException{
    352362                // special handling of parameter setting, x-cmd-... not alowed in java
    353                 this.setX_cmd_repository(getServletRequest().getParameter("x-cmd-repository"));
    354363                this.setX_cmd_collections(getServletRequest().getParameter("x-cmd-collections"));
    355364               
    356                 // root call
     365                // root call own SRU SERVER
    357366                //operation
    358367                if (operation.equals("explain") || operation == null){
     
    455464         */
    456465        public String execute() throws Exception {
     466                this.setX_cmd_repository(getServletRequest().getParameter("x-cmd-repository"));
     467                //check if extern SRU repository
     468                if (this.getX_cmd_repository() != null){
     469                        MDRepoProxyAction a = new MDRepoProxyAction();
     470                        a.setRepository(this.getX_cmd_repository());
     471                        // direct SRU - URL
     472                        if (a.isSRURepository() || (a.getBaseURI() == null)){
     473                                String requestURL = "";
     474                                if (a.getBaseURI() == null){
     475                                        requestURL = this.getX_cmd_repository();
     476                                } else {
     477                                        requestURL = a.getBaseURI();
     478                                }
     479                                Set set = getServletRequest().getParameterMap().entrySet();
     480                                Iterator i = set.iterator();
     481                                String params = "";
     482                            while(i.hasNext()){
     483                                      Map.Entry me = (Map.Entry)i.next();
     484                                      params = params + "&" + me.getKey() + "=" + ((String[])me.getValue())[0];
     485                                }
     486                            params = params.substring(1);
     487                            URL url = new URL(requestURL + "?" + params);
     488                            //getServletRequest().getRequestURL()
     489                            resultStream =  url.openStream();//getServletRequest().getRequestURL().openStream();
     490                                return SUCCESS;                         
     491                        }
     492                }
    457493                prepare();
    458494                if (Diagnostics().Accepted()){
  • MDService2/trunk/MDService2/src/eu/clarin/cmdi/mdservice/model/Query.java

    r1429 r1455  
    1414import java.net.MalformedURLException;
    1515import java.net.URL;
     16import java.util.Iterator;
     17import java.util.Map;
     18import java.util.Set;
    1619
    1720import javax.xml.parsers.DocumentBuilder;
     
    3336        public static String RECORDSET = "recordset";
    3437        public static String RECORD = "record";
     38        public static String SRUEXTERN = "sruextern";
    3539       
    3640        public static String PARSED = "parsed";
     
    6468        private int maxdepth=1;
    6569       
     70        private Map sruMap = null;
    6671        /**
    6772         * reference to the result-object
     
    278283        }
    279284
     285       
     286        public Map getSruMap() {
     287                return sruMap;
     288        }
     289
     290        public void setSruMap(Map sruMap) {
     291                this.sruMap = sruMap;
     292        }
     293
     294       
    280295        // apply rules form squery
    281296        public String createsqueryString (String _squery){
     
    342357                if (type.equals(MODEL)) {
    343358                        targetRequest = fromCMDIndex2Xpath() + "&maxdepth=" + getMaxdepth()  ; /* + "&maxdepth=" + getMaxdepth() );  "&collection=" + getCollection() + */
     359                } else if (type.equals(SRUEXTERN)) {
     360                        targetRequest = "";//fromCMDIndex2Xpath() + "&maxdepth=" + getMaxdepth()  ; /* + "&maxdepth=" + getMaxdepth() );  "&collection=" + getCollection() + */
     361                       
     362                        Set set = sruMap.entrySet();
     363                        Iterator i = set.iterator();
     364                       
     365                    while(i.hasNext()){
     366                              Map.Entry me = (Map.Entry)i.next();
     367                              targetRequest = targetRequest + "&" + me.getKey() + "=" + me.getValue();
     368                        }
     369                                       
    344370                } else if (type.equals(VALUES)) {
    345371                        targetRequest = fromCMDIndex2Xpath() ; /* + "&maxdepth=" + getMaxdepth() );  "&collection=" + getCollection() + */
     
    363389                        Admin.notifyUser("Query.toURLParam.corrid=" + corrid);
    364390                        targetRequest = "//MdSelfLink[ft:query(.,'" + corrid + "')]";                   
    365                 } else { 
    366                         if (query_cql == null){
    367                                 targetRequest =  "//*" + "&collection=" + getCollection();
    368                         } else {
    369                                 targetRequest = toXPath() + "&collection=" + getCollection();   
    370                         }
    371                         if (startItem != null) {
    372                                 targetRequest = targetRequest +  "&startItem=" + getStartItem();
    373                         }
    374                         if (maximumItems != null) {
    375                                 targetRequest = targetRequest +  "&maxItems=" + getMaximumItems();
    376                         }
    377                         if ((options != null)) {
    378                                 targetRequest = targetRequest +  "&format=xml-" + getOptions();
    379                         }
    380                 }
    381                
     391                } else {
     392                                if (query_cql == null){
     393                                        targetRequest =  "//*" + "&collection=" + getCollection();
     394                                } else {
     395                                        targetRequest = toXPath() + "&collection=" + getCollection();   
     396                                }
     397                                if (startItem != null) {
     398                                        targetRequest = targetRequest +  "&startItem=" + getStartItem();
     399                                }
     400                                if (maximumItems != null) {
     401                                        targetRequest = targetRequest +  "&maxItems=" + getMaximumItems();
     402                                }
     403                                if ((options != null)) {
     404                                        targetRequest = targetRequest +  "&format=xml-" + getOptions();
     405                                }
     406                }
     407       
    382408                return targetRequest;
    383409               
    384         }
     410}
    385411       
    386412        /**
Note: See TracChangeset for help on using the changeset viewer.