Changeset 1623 for MDService2


Ignore:
Timestamp:
11/22/11 10:57:22 (12 years ago)
Author:
gaba
Message:

query params

Location:
MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/action/RepoAction.java

    r1613 r1623  
    55import org.apache.log4j.Logger;
    66import eu.clarin.cmdi.mdservice.model.Diagnostic;
     7import eu.clarin.cmdi.mdservice.model.Query;
    78import eu.clarin.cmdi.mdservice.model.WorkspaceProfile;
    89import eu.clarin.cmdi.mdservice.proxy.MDRepoProxy;
     
    2930       
    3031        protected URL base_url ;
    31 
     32        Query query;
     33       
    3234        @Override
    3335        public String getFullFormat() {         
     
    3537        }
    3638
     39        @Override
     40        @SuppressWarnings("unchecked")
     41        protected void loadParams() {   
     42                super.loadParams();
     43                query = new Query(getActionkey(), this.getParams());
     44        }
    3745        /**
    3846         * Based on the repository type - we create a typed Proxy, that will do the work.
     
    5058                                return;
    5159                        }
     60                        //Query query = new Query();
    5261                        switch (WorkspaceProfile.RepositoryType.toRepositoryType(WorkspaceProfile.getRepositoryType(getRepository())))
    5362                        {               
     
    5665                                return;
    5766                            case SRU:
    58                                 setTargetProxy(new SRUProxy());
     67                                setTargetProxy(new SRUProxy(query));
    5968                                return;
    6069                            case MD:
    61                                 setTargetProxy(new MDRepoProxy());
     70                                setTargetProxy(new MDRepoProxy(query));
    6271                                return;
    6372                            default:
  • MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/model/Query.java

    r1613 r1623  
    1414import java.net.MalformedURLException;
    1515import java.net.URL;
     16import java.util.HashMap;
    1617import java.util.Iterator;
    1718import java.util.Map;
     
    5051       
    5152        private String syntax = "cql";  /* cql, cmdIndex, xpath */
    52         private String query_string;
     53        //private String query_string;
    5354        //private String full_query_string;
    5455        private CQLNode query_cql;
     
    5758         * temporary default;
    5859         */
    59         private String collection="";
    60         private String columns="Id,name";
    61         private String startItem = "1";
    62         private String maximumItems = "50";
    63         private String options = null;
    64         private String sort;
    65         private int maxdepth=1;
     60        //private String collection="";
     61        //private String columns="Id,name";
     62        //private String startItem = "1";
     63        //private String maximumItems = "50";
     64        //private String options = null;
     65        //private String sort;
     66        //private int maxdepth=1;
     67       
     68        private Map<String,String[]> params = new HashMap<String,String[]>() {{
     69                String[] sarr = new String[1];
     70                sarr[0] = "1";
     71                put("startItem", sarr);
     72                sarr = new String[1];
     73                sarr[0] = "50";
     74                put("maximumItems", sarr);     
     75                sarr = new String[1];
     76                sarr[0] = "Id,name";
     77                put("columns", sarr);
     78                sarr = new String[1];
     79                sarr[0] = "1";
     80                put("maxdepth", sarr);
     81               
     82        }};
    6683       
    6784        private Map sruMap = null;
     
    85102        public Query(String queryString, String type, String collection, String columns) {
    86103                this.type =type;
    87                 if (queryString == null)queryString ="";
    88                 setFullQueryString(queryString);
    89                 setCollection(collection);
    90                 setColumns(columns);
     104                addParam("query", queryString);
     105                //if (queryString == null)queryString ="";
     106                //setFullQueryString(queryString);
     107                setFullQueryString();
     108                addParam("collection", collection);
     109                addParam("columns",columns);
    91110        }
    92111       
     
    112131                this(queryString, type, "");
    113132        }
    114 
     133       
     134        /**     
     135         * another constructor, with user's querystring and type of the query;
     136         * @param type
     137         * @param _params
     138         */
     139
     140        public Query( String type, Map<String,String[]> _params) {
     141               
     142                this.type = type;
     143                params = _params;
     144                this.setFullQueryString();
     145        }
     146       
     147        /**     
     148         * another constructor, with user's querystring and type of the query;
     149         * @param _params
     150         */
     151
     152        public Query(Map<String,String[]> _params) {
     153                this("search", _params);
     154                //this("search", _params);
     155                /*
     156                String query = null , collections = "", columns = "";
     157                if (!(_params.get("query")==null)) {
     158                        query=(String)params.get("query")[0];
     159                } else {
     160                        // error
     161                        return;
     162                }
     163                this(queryString, "search", "");
     164                params = _params;
     165                */
     166        }
     167       
     168        public void setParams(Map<String,String[]> _params){
     169                params = _params;
     170        }
     171       
     172        /**
     173         * Gets the local parameter map.
     174         *
     175         * @return
     176         */
     177        public Map<String,String[]> getParams() {               
     178                return params;
     179        }
     180
     181        /**
     182         * Add parameter into local parameter map.
     183         *
     184         * @param key - parameter key
     185         * @param value - parameter value
     186         */
     187        public void addParam(String key, String value){
     188                String[] sarr = new String[1];
     189                sarr[0] = value;
     190                params.put(key, sarr); 
     191        }
     192        /**
     193         * This is for simplified access to the the values of the request-parameters
     194         * They are stored in the parameters-map as a String-array,
     195         * but in most(?) situations, we expect just a simple string.
     196         * @param key
     197         * @return
     198         */
     199        public String getParam(String key) {
     200                String v = null;
     201                if (!(params.get(key)==null)) v=(String)params.get(key)[0];
     202                return v;
     203        }
     204
     205       
    115206        public Boolean isStatus(String qstatus) {
    116207                return (qstatus.equals(getStatus()));
     
    118209       
    119210        public String getStatus() {
    120                 if (type.equals(Query.RECORDSET) && query_cql== null && (query_string != "")) {
     211                if (type.equals(Query.RECORDSET) && query_cql== null && (this.getQueryString() != "")) {
    121212                        return Query.PARSEERROR;
    122213                } else {
     
    135226
    136227        public String getQueryString() {
    137                 return query_string;
    138         }
    139 
    140         public void setFullQueryString(String queryString) {
    141                
    142                 query_string=queryString;
    143                
    144                 if (queryString.trim().length() == 0){
    145                         queryString = null;
    146                 }
     228                //return query_string;
     229                if (getParam("query") == null){
     230                        return "";
     231                }
     232                return  getParam("query");
     233        }
     234
     235        //public void setFullQueryString(String queryString) {
     236        public void setFullQueryString() {
     237               
     238                String query_string = this.getQueryString();
     239               
     240                //if (queryString.trim().length() == 0){
     241                //      queryString = null;
     242                //}
    147243               
    148244                log.debug("QUERY.FULLQUERYSTRING:" + query_string);
     
    153249                       
    154250        }
     251       
    155252        /*
    156253        public String getFullQueryString() {
     
    158255        }
    159256*/
    160        
     257        /*
    161258        public void setCollection(String collection) {
    162259                if (collection!=null) {
     
    232329                return maxdepth;
    233330        }
    234 
     331*/
    235332        public void setResult(Result result) {
    236333                this.result = result;
     
    313410               
    314411                if (type.equals(MODEL)) {
    315                         targetRequest = fromCMDIndex2Xpath() + "&maxdepth=" + getMaxdepth()  ; /* + "&maxdepth=" + getMaxdepth() );  "&collection=" + getCollection() + */
     412                        //targetRequest = fromCMDIndex2Xpath() + "&maxdepth=" + getMaxdepth()  ; /* + "&maxdepth=" + getMaxdepth() );  "&collection=" + getCollection() + */
     413                        targetRequest = fromCMDIndex2Xpath() + "&maxdepth=" + getParam("maxdepth")  ; /* + "&maxdepth=" + getMaxdepth() );  "&collection=" + getCollection() + */
    316414                }
    317415                else if (type.equals(COLLECTION)) {
    318                         targetRequest = getCollection() + "&maxdepth=" + getMaxdepth()  ; /* + "&maxdepth=" + getMaxdepth() );  "&collection=" + getCollection() + */
     416                        targetRequest = getParam("collection") + "&maxdepth=" + getParam("maxdepth")  ; /* + "&maxdepth=" + getMaxdepth() );  "&collection=" + getCollection() + */
    319417
    320418                } else if (type.equals(SRUEXTERN)) {
     
    332430                        targetRequest = fromCMDIndex2Xpath() ; /* + "&maxdepth=" + getMaxdepth() );  "&collection=" + getCollection() + */
    333431                       
    334                         if (startItem != null) {
    335                                 targetRequest = targetRequest +  "&startItem=" + getStartItem();
    336                         }
    337                         if (maximumItems != null) {
    338                                 targetRequest = targetRequest +  "&maxItems=" + getMaximumItems();
    339                         }
    340                         if (sort != null) {
    341                                 targetRequest = targetRequest +  "&sort=" + getSort();
     432                        if (getParam("startItem") != null) {
     433                                targetRequest = targetRequest +  "&startItem=" + getParam("startItem");
     434                        }
     435                        if (getParam("maximumItems") != null) {
     436                                targetRequest = targetRequest +  "&maxItems=" + getParam("maximumItems");
     437                        }
     438                        if (getParam("sort") != null) {
     439                                targetRequest = targetRequest +  "&sort=" + getParam("sort");
    342440                        }
    343441                       
     
    352450                } else {
    353451                                if (query_cql == null){
    354                                         targetRequest =  "//*" + "&collection=" + getCollection();
     452                                        targetRequest =  "//*" + "&collection=" + getParam("collection");
    355453                                } else {
    356                                         targetRequest = toXPath() + "&collection=" + getCollection();   
    357                                 }
    358                                 if (startItem != null) {
    359                                         targetRequest = targetRequest +  "&startItem=" + getStartItem();
    360                                 }
    361                                 if (maximumItems != null) {
    362                                         targetRequest = targetRequest +  "&maxItems=" + getMaximumItems();
    363                                 }
    364                                 if ((options != null)) {
    365                                         targetRequest = targetRequest +  "&format=xml-" + getOptions();
     454                                        targetRequest = toXPath() + "&collection=" + getParam("collection");   
     455                                }
     456                                if (getParam("startItem") != null) {
     457                                        targetRequest = targetRequest +  "&startItem=" + getParam("startItem");
     458                                }
     459                                if (getParam("maximumItems") != null) {
     460                                        targetRequest = targetRequest +  "&maxItems=" + getParam("maximumItems");
     461                                }
     462                                if ((getParam("options") != null)) {
     463                                        targetRequest = targetRequest +  "&format=xml-" + getParam("options");
    366464                                }
    367465                }
     
    380478                CQLParser parser = new CQLParser();             
    381479                // cannot accept '-' at the CQL beginning
    382                 String local_full_query_string = query_string;
     480                String local_full_query_string = this.getQueryString();
    383481                local_full_query_string = local_full_query_string.replace("-", "%2D");
    384482
     
    457555        public String fromCMDIndex2Xpath() {
    458556                String xpath = "";
     557                String query_string= getQueryString();
    459558                if (query_string.contains(":")) {
    460559                        int delim_index = query_string.indexOf(":");
  • MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/proxy/MDRepoProxy.java

    r1588 r1623  
    2727       
    2828        private String proxy_key = "mdrepository";
     29
     30       
     31        public MDRepoProxy(Query q){
     32                setQuery(q);
     33        }
     34       
    2935       
    3036        /**
     
    6369        public URL getTargetRequest() throws IOException, CQLParseException {
    6470       
    65                 Query query = new Query(getParam("query"),getSourceAction().getActionkey());
     71                //Query query = new Query(getParam("query"),getSourceAction().getActionkey());
    6672       
    6773                log.debug("MDRP.getQuery:" + getParam("query"));
     
    6975
    7076        // check if the query could get parsed
    71                 if (query.isStatus(Query.PARSEERROR)) {
    72                         log.debug("MDRP.query.PARSEERROR:" + query.getMsg());
    73                         throw new CQLParseException("MDRP.query.PARSEERROR:" + query.getMsg());
     77                if (getQuery().isStatus(Query.PARSEERROR)) {
     78                        log.debug("MDRP.query.PARSEERROR:" + getQuery().getMsg());
     79                        throw new CQLParseException("MDRP.query.PARSEERROR:" + getQuery().getMsg());
    7480                        //getSourceAction().getDiagnostics().Add(Diagnostic.SYSTEM_ERROR, "MDRP.query.PARSEERROR:" + query.getMsg());
    7581                        //TODO exception ??
    7682                        //return null;
    7783                } else {
    78                         query.setMaxdepth(Integer.valueOf(getParam("maxdepth")));               
    79                         query.setCollection(getParam("collections"));
    80                         query.setColumns(getParam("columns"));
    81                         query.setMaximumItems(getParam("maximumRecords"));
    82                         query.setStartItem(getParam("startRecord"));
    83                         query.setOptions(getParam("options"));
    84                         query.setSort(getParam("sort"));
     84                        //query.setParams(getParams());
     85                        //query.setMaxdepth(Integer.valueOf(getParam("maxdepth")));             
     86                        //query.setCollection(getParam("collections"));
     87                        //query.setColumns(getParam("columns"));
     88                        //query.setMaximumItems(getParam("maximumRecords"));
     89                        //query.setStartItem(getParam("startRecord"));
     90                        //query.setOptions(getParam("options"));
     91                        //query.setSort(getParam("sort"));
    8592               
    8693                        URL targetURL = null;
    87                         targetURL =new URL( getBaseURL(), urls.get(getSourceAction().getActionkey()) + query.toURLParam());
     94                        targetURL =new URL( getBaseURL(), urls.get(getSourceAction().getActionkey()) + getQuery().toURLParam());
    8895               
    8996                        log.debug("MDRPA.targetURL:" + targetURL);
  • MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/proxy/Pz2Proxy.java

    r1569 r1623  
    4949        private String proxy_key = "pazpar2";
    5050       
    51         private String command;
    52         private String query;
    53         private String sessionID;
    54         private String sort;
    55         private String block;
    56        
     51        //private String command;
     52        //private String query;
     53        //private String sessionID;
     54        //private String sort;
     55        //private String block;
     56        /*
    5757        public void setCommand(String command) {
    5858                this.command = command;
     
    8787        }
    8888       
    89        
     89        */
    9090        public String createURLParams(){
    9191                String params = "?";
    92                 if (!(command == null)){
    93                         params = params + "command=" + command;
    94                 }
    95                 if (!(sessionID == null)){
    96                         params = params + "&session=" + sessionID;
    97                 }
    98                 if (!(query == null)){
    99                         params = params + "&query=" + query;
     92                if (!(getParam("command") == null)){
     93                        params = params + "command=" + getParam("command");
     94                }
     95                if (!(getParam("sessionID") == null)){
     96                        params = params + "&session=" + getParam("sessionID");
     97                }
     98                if (!(getParam("query") == null)){
     99                        params = params + "&query=" + getParam("query");
    100100                }
    101101                /*
     
    108108                }
    109109                */
    110                 if (!(sort == null)){
    111                         params = params + "&sort=" + sort;
    112                         if (!(block == null)){
    113                                 params = params + ":" + block;
     110                if (!(getParam("sort") == null)){
     111                        params = params + "&sort=" + getParam("sort");
     112                        if (!(getParam("block") == null)){
     113                                params = params + ":" + getParam("block");
    114114                        }
    115115                }
     
    141141        @Override
    142142        public InputStream getSourceStream() throws IOException, NoStylesheetException, CQLParseException {
    143                 if (getCommand() == null){
     143                if (getParam("command") == null){
    144144                        try {
    145145                                return getSourcePz2();
     
    213213                // TODO param settings
    214214                //init
    215                 setCommand("init");
     215                //setParam("command","init");
    216216                String sessionID = getDocumentData(this.getSourceStream(), "//init/session");
    217217                // get result
    218                 setCommand("search");
    219                 setSessionID(sessionID);
     218                //setCommand("search");
     219                //setSessionID(sessionID);
    220220                //setQuery(this.getSquery()); //matej 20110903
    221221                setQuery(this.getQuery());
     
    223223               
    224224                String activeclients = "1";
    225                 setCommand("show");
    226                 setSort("relevance");
    227                 setBlock("1");
     225                //setCommand("show");
     226                //setSort("relevance");
     227                //setBlock("1");
    228228                //TODO timeout  settings
    229229                long startMillis = System.currentTimeMillis();
  • MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/proxy/RepoProxy.java

    r1613 r1623  
    1313import eu.clarin.cmdi.mdservice.internal.NoStylesheetException;
    1414import eu.clarin.cmdi.mdservice.model.Diagnostic;
     15import eu.clarin.cmdi.mdservice.model.Query;
    1516import eu.clarin.cmdi.mdservice.model.WorkspaceProfile;
    1617
     
    3637        // should perhaps be RepoAction, but it gets complicated with the types
    3738        private GenericAction source_action;
     39       
     40        private Query query;
     41       
    3842       
    3943       
     
    149153        }
    150154
     155        public void setQuery(Query query) {
     156                this.query = query;
     157        }
     158
     159        public Query getQuery() {
     160                return query;
     161        }
     162
    151163       
    152164
  • MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/proxy/SRUProxy.java

    r1540 r1623  
    2121
    2222import eu.clarin.cmdi.mdservice.model.Diagnostics;
     23import eu.clarin.cmdi.mdservice.model.Query;
    2324import eu.clarin.cmdi.mdservice.model.WorkspaceProfile;
    2425
     
    3940         * Properties to be filled by Struts with according request-parameters
    4041         */     
     42        /*
    4143        private String q;
    4244        private String version;
     
    5456        private String x_cmd_repository;
    5557        private String x_cmd_collections;
     58        */
    5659        private Set paramSet;
    5760
     
    5962        private static int OP_EXPLAIN = 2;
    6063        private static int OP_SCAN = 3;
     64       
     65       
    6166       
    6267       
     
    8287         }
    8388         
     89         public SRUProxy(Query q){
     90                        setQuery(q);
     91                }
     92         
    8493         protected void  initialize(){
    85                                
     94                /*             
    8695                 // TODO set SRU params
    8796                        // missing collections, columns...
     
    94103                        setX_cmd_repository(getSourceAction().getRepository());
    95104                        setQuery(this.fullQueryString());
    96                        
     105                */     
    97106        /*       
    98107                 if (getServletRequest() != null){
     
    126135                }
    127136       
    128                
     137        /*     
    129138         public String getQ() {
    130139                        return q;
     
    134143                        this.q = q;
    135144                }
     145                */
    136146         /*
    137147         public InputStream getResultStream() {
     
    142152         }
    143153        */
    144 
     154/*
    145155        public String getVersion() {
    146156                return version;
     
    254264                this.x_cmd_collections = x_cmd_collections;
    255265        }
    256        
     266        */
    257267       
    258268        @Override
     
    483493                //TODO params
    484494                if (paramSet == null){
    485                         if (!(operation == null)){
    486                                 params = params + "operation=" + operation;
    487                         }
    488                         if (!(version == null)){
    489                                 params = params + "&version=" + version;
    490                         }
    491                         if (!(query == null)){
    492                                 params = params + "&query=" + query;
    493                         }
    494                         if (getStartRecord() > 0){
    495                                 params = params + "&startRecord=" + String.valueOf(getStartRecord());
    496                         }
    497                         if (getMaximumRecords()> 0){
    498                                 params = params + "&numRecords=" + String.valueOf(getMaximumRecords());
     495                        if (!(getParam("operation") == null)){
     496                                params = params + "operation=" + getParam("operation");
     497                        }
     498                        if (!(getParam("version") == null)){
     499                                params = params + "&version=" + getParam("version");
     500                        }
     501                        if (!(getParam("query") == null)){
     502                                params = params + "&query=" + getParam("query");
     503                        }
     504                        if (Integer.parseInt(getParam("startRecord")) > 0){
     505                                params = params + "&startRecord=" + String.valueOf(getParam("startRecord"));
     506                        }
     507                        if (Integer.parseInt(getParam("maximumRecords"))> 0){
     508                                params = params + "&numRecords=" + String.valueOf(getParam("maximumRecords"));
    499509                        }
    500510                } else {
     
    519529               
    520530                if (this.getBaseURI() == null){
    521                         requestURI = this.getX_cmd_repository();
     531                        requestURI = getParam("x_cmd_repository");//this.getX_cmd_repository();
    522532                } else {
    523533                        requestURI = this.getBaseURI();
Note: See TracChangeset for help on using the changeset viewer.