Changeset 1509 for MDService2
- Timestamp:
- 09/03/11 11:58:22 (13 years ago)
- Location:
- MDService2/branches/MDService_simple/src/eu/clarin/cmdi/mdservice/action
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
MDService2/branches/MDService_simple/src/eu/clarin/cmdi/mdservice/action/MDRepoProxyAction.java
r1496 r1509 39 39 * 40 40 */ 41 public class MDRepoProxyAction extends GenericProxyAction {41 public class MDRepoProxyAction extends RepoProxyAction { 42 42 43 43 private static final long serialVersionUID = 1L; -
MDService2/branches/MDService_simple/src/eu/clarin/cmdi/mdservice/action/Pz2ProxyAction.java
r1496 r1509 39 39 40 40 */ 41 public class Pz2ProxyAction extends GenericProxyAction {41 public class Pz2ProxyAction extends RepoProxyAction { 42 42 43 43 private static final long serialVersionUID = 1L; … … 136 136 } 137 137 138 /* 138 /** 139 * Overrides the default implementation for the case, when the Service shall act as "collector", 140 * waiting for the final result (implemented in getSourcePz2 141 * The distinction is based on the command parameter: if it is given, the Class(Service) acts as a basic proxy 142 * transparently passing the communication between client and target repository. 143 */ 139 144 @Override 140 145 public InputStream getSourceStream() throws IOException, NoStylesheetException { … … 151 156 } 152 157 158 /** 159 * TODO: move to Utils 160 * @param is 161 * @return 162 */ 153 163 public Document getDocument(InputStream is){ 154 164 Document doc = null; … … 170 180 return doc; 171 181 } 182 183 /** 184 * TODO: move to Utils 185 * @param is 186 * @param expression 187 * @return 188 */ 172 189 public String getDocumentData(InputStream is, String expression){ 173 190 String sessionid = ""; … … 187 204 188 205 } 189 */ 190 /* 206 207 /** 208 * This function wraps the session-based communication with a Pazpar2-target, waiting until all the responses were returned (or timeout occured) 209 * returning the full result at the end. 210 * @return returns the collected final result as a stream 211 * @throws Exception 212 */ 191 213 public InputStream getSourcePz2() throws Exception { 192 214 … … 227 249 return is; 228 250 } 229 */230 251 231 252 } -
MDService2/branches/MDService_simple/src/eu/clarin/cmdi/mdservice/action/RepoProxyAction.java
r1508 r1509 44 44 45 45 private String proxy_key = "repository"; 46 46 private RepoProxyAction target_proxy; 47 private RepoProxyAction source_action; 48 49 /** 50 * Based on the repository type - we create a typed Proxy, that will do the work. 51 * If the type is not recognized <this> will be also the target_proxy - 52 * TODO: check if it is sane, to work without a typed target_proxy 53 */ 54 protected void initialize(){ 55 56 switch (WorkspaceProfile.RepositoryType.toRepositoryType(WorkspaceProfile.getRepositoryType(getRepository()))) 57 { 58 case PAZPAR: 59 target_proxy = new Pz2ProxyAction(); 60 case SRU: 61 target_proxy = new SRUProxyAction(); 62 case MD: 63 target_proxy = new MDRepoProxyAction(); 64 default: 65 target_proxy = this; 66 } 67 target_proxy.setSourceAction(this); 68 69 } 70 71 public RepoProxyAction getTargetProxy() { 72 return target_proxy; 73 } 74 75 public RepoProxyAction getSourceAction() { 76 return source_action; 77 } 78 79 public void setSourceAction(RepoProxyAction p_source_action) { 80 source_action = p_source_action; 81 } 82 83 /** 84 * Pass the proxy_key of the actual target_proxy, 85 * or the basic "repository" if the target_proxy is identical 86 */ 47 87 @Override 48 88 public String getProxyKey() { 49 return proxy_key; 89 if (target_proxy.equals(this)) { 90 return proxy_key; 91 } else { 92 return getTargetProxy().getProxyKey(); 93 } 50 94 } 51 95 … … 60 104 } 61 105 62 /**63 * A mapping between the actionkeys in the request and the operation-parameter expected by the MD!Repository64 * FIXME: This is taken from MDRepoProxyAction - so it will not work for SRU and Pazpar265 */66 private final static HashMap<String,String> urls = new HashMap<String,String>();67 static68 { urls.put("collection", "?operation=getCollections&collection=");69 urls.put("model", "?operation=queryModel&q=");70 urls.put("values", "?operation=scanIndex&q=");71 urls.put("search", "?operation=searchRetrieve&query=");72 urls.put("record", "?operation=searchRetrieve&query=");73 }74 75 76 106 //TODO remove - just for tests 77 107 @Override … … 106 136 } 107 137 108 public URL getTargetRequestSRU() throws IOException, NoStylesheetException{109 110 SRUProxyAction sruaction = new SRUProxyAction();111 // TODO MD to SRU params112 // missing collections, columns...113 sruaction.setOperation("searchRetrieve");114 //TODO what version115 sruaction.setVersion("1.2");116 sruaction.setStartRecord(Integer.parseInt(this.getStartItem()));117 sruaction.setMaximumRecords(Integer.parseInt(this.getMaximumItems()));118 sruaction.setRepository(getRepository());119 sruaction.setQuery(this.fullQueryString());120 121 return sruaction.getTargetRequest();122 123 }124 public InputStream getSourcePz2() throws Exception {125 126 InputStream is = null;127 Pz2ProxyAction pzaction = new Pz2ProxyAction();128 // TODO param settings129 //init130 pzaction.setRepository(getRepository());131 pzaction.setCommand("init");132 String sessionID = Helpers.getDocumentData(pzaction.getSourceStream(), "//init/session");133 // get result134 pzaction.setCommand("search");135 pzaction.setSessionID(sessionID);136 pzaction.setQuery(this.fullQueryString());137 String ok = Helpers.getDocumentData(pzaction.getSourceStream(),"//search/status");138 139 String activeclients = "1";140 pzaction.setCommand("show");141 pzaction.setSort("relevance");142 pzaction.setBlock("1");143 //TODO timeout settings144 long startMillis = System.currentTimeMillis();145 long timeout = 0;146 if (WorkspaceProfile.getOption("pazpartimeout") == null){147 timeout = 1000;148 } else {149 timeout = Integer.parseInt(WorkspaceProfile.getOption("pazpartimeout"));150 }151 while (Integer.parseInt(activeclients) > 0){152 //activeclients = getDocumentData(this.getSourceStream(), "//show/activeclients");153 is = pzaction.getSourceStream();154 activeclients = Helpers.getDocumentData(is, "//show/activeclients");155 Thread.sleep(1000);156 Admin.notifyUser("ActiveClients: " + activeclients, Admin.DEBUG);157 if ((System.currentTimeMillis() - startMillis)/1000 > timeout) {158 break;159 }160 }161 is = pzaction.getSourceStream();162 return is;163 }164 165 138 @Override 166 139 public InputStream getSourceStream() throws IOException, NoStylesheetException { 167 168 140 141 return getTargetProxy().getSourceStream(); 142 /* 169 143 switch (WorkspaceProfile.RepositoryType.toRepositoryType(WorkspaceProfile.getRepositoryType(getRepository()))) 170 144 { … … 183 157 return super.getSourceStream(); 184 158 } 185 159 */ 186 160 } 187 161 -
MDService2/branches/MDService_simple/src/eu/clarin/cmdi/mdservice/action/SRUProxyAction.java
r1496 r1509 54 54 55 55 56 public class SRUProxyAction extends GenericProxyAction//ActionSupport56 public class SRUProxyAction extends RepoProxyAction//ActionSupport 57 57 //implements ServletRequestAware 58 58 { … … 386 386 public void sru2MD() throws UnsupportedEncodingException{ 387 387 // special handling of parameter setting, x-cmd-... not alowed in java 388 this.setX_cmd_collections(getServletRequest().getParameter("x-cmd-collections")); 389 388 this.setX_cmd_collections(getServletRequest().getParameter("x-cmd-collections")); 390 389 // root call own SRU SERVER 391 390 //operation … … 560 559 return targetURL; 561 560 } 562 561 562 563 public URL getTargetRequestSRU() throws IOException, NoStylesheetException{ 564 565 SRUProxyAction sruaction = new SRUProxyAction(); 566 // TODO MD to SRU params 567 // missing collections, columns... 568 sruaction.setOperation("searchRetrieve"); 569 //TODO what version 570 sruaction.setVersion("1.2"); 571 sruaction.setStartRecord(Integer.parseInt(this.getStartItem())); 572 sruaction.setMaximumRecords(Integer.parseInt(this.getMaximumItems())); 573 sruaction.setRepository(getRepository()); 574 sruaction.setQuery(this.fullQueryString()); 575 576 return sruaction.getTargetRequest(); 577 578 } 579 563 580 @Override 564 581 public void prepare() throws Exception{
Note: See TracChangeset
for help on using the changeset viewer.