Changeset 1623
- Timestamp:
- 11/22/11 10:57:22 (13 years ago)
- 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 5 5 import org.apache.log4j.Logger; 6 6 import eu.clarin.cmdi.mdservice.model.Diagnostic; 7 import eu.clarin.cmdi.mdservice.model.Query; 7 8 import eu.clarin.cmdi.mdservice.model.WorkspaceProfile; 8 9 import eu.clarin.cmdi.mdservice.proxy.MDRepoProxy; … … 29 30 30 31 protected URL base_url ; 31 32 Query query; 33 32 34 @Override 33 35 public String getFullFormat() { … … 35 37 } 36 38 39 @Override 40 @SuppressWarnings("unchecked") 41 protected void loadParams() { 42 super.loadParams(); 43 query = new Query(getActionkey(), this.getParams()); 44 } 37 45 /** 38 46 * Based on the repository type - we create a typed Proxy, that will do the work. … … 50 58 return; 51 59 } 60 //Query query = new Query(); 52 61 switch (WorkspaceProfile.RepositoryType.toRepositoryType(WorkspaceProfile.getRepositoryType(getRepository()))) 53 62 { … … 56 65 return; 57 66 case SRU: 58 setTargetProxy(new SRUProxy( ));67 setTargetProxy(new SRUProxy(query)); 59 68 return; 60 69 case MD: 61 setTargetProxy(new MDRepoProxy( ));70 setTargetProxy(new MDRepoProxy(query)); 62 71 return; 63 72 default: -
MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/model/Query.java
r1613 r1623 14 14 import java.net.MalformedURLException; 15 15 import java.net.URL; 16 import java.util.HashMap; 16 17 import java.util.Iterator; 17 18 import java.util.Map; … … 50 51 51 52 private String syntax = "cql"; /* cql, cmdIndex, xpath */ 52 private String query_string;53 //private String query_string; 53 54 //private String full_query_string; 54 55 private CQLNode query_cql; … … 57 58 * temporary default; 58 59 */ 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 }}; 66 83 67 84 private Map sruMap = null; … … 85 102 public Query(String queryString, String type, String collection, String columns) { 86 103 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); 91 110 } 92 111 … … 112 131 this(queryString, type, ""); 113 132 } 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 115 206 public Boolean isStatus(String qstatus) { 116 207 return (qstatus.equals(getStatus())); … … 118 209 119 210 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() != "")) { 121 212 return Query.PARSEERROR; 122 213 } else { … … 135 226 136 227 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 //} 147 243 148 244 log.debug("QUERY.FULLQUERYSTRING:" + query_string); … … 153 249 154 250 } 251 155 252 /* 156 253 public String getFullQueryString() { … … 158 255 } 159 256 */ 160 257 /* 161 258 public void setCollection(String collection) { 162 259 if (collection!=null) { … … 232 329 return maxdepth; 233 330 } 234 331 */ 235 332 public void setResult(Result result) { 236 333 this.result = result; … … 313 410 314 411 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() + */ 316 414 } 317 415 else if (type.equals(COLLECTION)) { 318 targetRequest = get Collection() + "&maxdepth=" + getMaxdepth() ; /* + "&maxdepth=" + getMaxdepth() ); "&collection=" + getCollection() + */416 targetRequest = getParam("collection") + "&maxdepth=" + getParam("maxdepth") ; /* + "&maxdepth=" + getMaxdepth() ); "&collection=" + getCollection() + */ 319 417 320 418 } else if (type.equals(SRUEXTERN)) { … … 332 430 targetRequest = fromCMDIndex2Xpath() ; /* + "&maxdepth=" + getMaxdepth() ); "&collection=" + getCollection() + */ 333 431 334 if ( startItem!= null) {335 targetRequest = targetRequest + "&startItem=" + get StartItem();336 } 337 if ( maximumItems!= null) {338 targetRequest = targetRequest + "&maxItems=" + get MaximumItems();339 } 340 if ( sort!= null) {341 targetRequest = targetRequest + "&sort=" + get Sort();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"); 342 440 } 343 441 … … 352 450 } else { 353 451 if (query_cql == null){ 354 targetRequest = "//*" + "&collection=" + get Collection();452 targetRequest = "//*" + "&collection=" + getParam("collection"); 355 453 } else { 356 targetRequest = toXPath() + "&collection=" + get Collection();357 } 358 if ( startItem!= null) {359 targetRequest = targetRequest + "&startItem=" + get StartItem();360 } 361 if ( maximumItems!= null) {362 targetRequest = targetRequest + "&maxItems=" + get MaximumItems();363 } 364 if (( options!= null)) {365 targetRequest = targetRequest + "&format=xml-" + get Options();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"); 366 464 } 367 465 } … … 380 478 CQLParser parser = new CQLParser(); 381 479 // cannot accept '-' at the CQL beginning 382 String local_full_query_string = query_string;480 String local_full_query_string = this.getQueryString(); 383 481 local_full_query_string = local_full_query_string.replace("-", "%2D"); 384 482 … … 457 555 public String fromCMDIndex2Xpath() { 458 556 String xpath = ""; 557 String query_string= getQueryString(); 459 558 if (query_string.contains(":")) { 460 559 int delim_index = query_string.indexOf(":"); -
MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/proxy/MDRepoProxy.java
r1588 r1623 27 27 28 28 private String proxy_key = "mdrepository"; 29 30 31 public MDRepoProxy(Query q){ 32 setQuery(q); 33 } 34 29 35 30 36 /** … … 63 69 public URL getTargetRequest() throws IOException, CQLParseException { 64 70 65 Query query = new Query(getParam("query"),getSourceAction().getActionkey());71 //Query query = new Query(getParam("query"),getSourceAction().getActionkey()); 66 72 67 73 log.debug("MDRP.getQuery:" + getParam("query")); … … 69 75 70 76 // 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()); 74 80 //getSourceAction().getDiagnostics().Add(Diagnostic.SYSTEM_ERROR, "MDRP.query.PARSEERROR:" + query.getMsg()); 75 81 //TODO exception ?? 76 82 //return null; 77 83 } 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")); 85 92 86 93 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()); 88 95 89 96 log.debug("MDRPA.targetURL:" + targetURL); -
MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/proxy/Pz2Proxy.java
r1569 r1623 49 49 private String proxy_key = "pazpar2"; 50 50 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 /* 57 57 public void setCommand(String command) { 58 58 this.command = command; … … 87 87 } 88 88 89 89 */ 90 90 public String createURLParams(){ 91 91 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"); 100 100 } 101 101 /* … … 108 108 } 109 109 */ 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"); 114 114 } 115 115 } … … 141 141 @Override 142 142 public InputStream getSourceStream() throws IOException, NoStylesheetException, CQLParseException { 143 if (get Command() == null){143 if (getParam("command") == null){ 144 144 try { 145 145 return getSourcePz2(); … … 213 213 // TODO param settings 214 214 //init 215 setCommand("init");215 //setParam("command","init"); 216 216 String sessionID = getDocumentData(this.getSourceStream(), "//init/session"); 217 217 // get result 218 setCommand("search");219 setSessionID(sessionID);218 //setCommand("search"); 219 //setSessionID(sessionID); 220 220 //setQuery(this.getSquery()); //matej 20110903 221 221 setQuery(this.getQuery()); … … 223 223 224 224 String activeclients = "1"; 225 setCommand("show");226 setSort("relevance");227 setBlock("1");225 //setCommand("show"); 226 //setSort("relevance"); 227 //setBlock("1"); 228 228 //TODO timeout settings 229 229 long startMillis = System.currentTimeMillis(); -
MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/proxy/RepoProxy.java
r1613 r1623 13 13 import eu.clarin.cmdi.mdservice.internal.NoStylesheetException; 14 14 import eu.clarin.cmdi.mdservice.model.Diagnostic; 15 import eu.clarin.cmdi.mdservice.model.Query; 15 16 import eu.clarin.cmdi.mdservice.model.WorkspaceProfile; 16 17 … … 36 37 // should perhaps be RepoAction, but it gets complicated with the types 37 38 private GenericAction source_action; 39 40 private Query query; 41 38 42 39 43 … … 149 153 } 150 154 155 public void setQuery(Query query) { 156 this.query = query; 157 } 158 159 public Query getQuery() { 160 return query; 161 } 162 151 163 152 164 -
MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/proxy/SRUProxy.java
r1540 r1623 21 21 22 22 import eu.clarin.cmdi.mdservice.model.Diagnostics; 23 import eu.clarin.cmdi.mdservice.model.Query; 23 24 import eu.clarin.cmdi.mdservice.model.WorkspaceProfile; 24 25 … … 39 40 * Properties to be filled by Struts with according request-parameters 40 41 */ 42 /* 41 43 private String q; 42 44 private String version; … … 54 56 private String x_cmd_repository; 55 57 private String x_cmd_collections; 58 */ 56 59 private Set paramSet; 57 60 … … 59 62 private static int OP_EXPLAIN = 2; 60 63 private static int OP_SCAN = 3; 64 65 61 66 62 67 … … 82 87 } 83 88 89 public SRUProxy(Query q){ 90 setQuery(q); 91 } 92 84 93 protected void initialize(){ 85 94 /* 86 95 // TODO set SRU params 87 96 // missing collections, columns... … … 94 103 setX_cmd_repository(getSourceAction().getRepository()); 95 104 setQuery(this.fullQueryString()); 96 105 */ 97 106 /* 98 107 if (getServletRequest() != null){ … … 126 135 } 127 136 128 137 /* 129 138 public String getQ() { 130 139 return q; … … 134 143 this.q = q; 135 144 } 145 */ 136 146 /* 137 147 public InputStream getResultStream() { … … 142 152 } 143 153 */ 144 154 /* 145 155 public String getVersion() { 146 156 return version; … … 254 264 this.x_cmd_collections = x_cmd_collections; 255 265 } 256 266 */ 257 267 258 268 @Override … … 483 493 //TODO params 484 494 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(get StartRecord());496 } 497 if ( getMaximumRecords()> 0){498 params = params + "&numRecords=" + String.valueOf(get MaximumRecords());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")); 499 509 } 500 510 } else { … … 519 529 520 530 if (this.getBaseURI() == null){ 521 requestURI = this.getX_cmd_repository();531 requestURI = getParam("x_cmd_repository");//this.getX_cmd_repository(); 522 532 } else { 523 533 requestURI = this.getBaseURI();
Note: See TracChangeset
for help on using the changeset viewer.