Changeset 1509 for MDService2/branches/MDService_simple/src/eu/clarin/cmdi/mdservice/action/RepoProxyAction.java
- Timestamp:
- 09/03/11 11:58:22 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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
Note: See TracChangeset
for help on using the changeset viewer.