Changeset 2738
- Timestamp:
- 03/26/13 14:04:11 (11 years ago)
- Location:
- SRUAggregator/trunk
- Files:
-
- 1 added
- 6 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
SRUAggregator/trunk/pom.xml
r2694 r2738 65 65 <version>1.17.1</version> 66 66 </dependency> 67 <dependency> 68 <groupId>com.googlecode.sardine</groupId> 69 <artifactId>sardine</artifactId> 70 <version>314</version> 71 <type>jar</type> 72 </dependency> 67 73 </dependencies> 68 74 <build> -
SRUAggregator/trunk/src/main/java/eu/clarin/sru/fcs/aggregator/app/Aggregator.java
r2694 r2738 46 46 import eu.clarin.weblicht.wlfxb.xb.WLData; 47 47 import javax.ws.rs.core.MediaType; 48 import org.zkoss.zul.Popup; 48 49 49 50 /** 50 51 * Main window of the Aggregator application. 51 * 52 * 52 53 * @author Yana Panchenko 53 54 */ … … 55 56 56 57 private static final Logger logger = Logger.getLogger(Aggregator.class.getName()); 57 58 58 // @Wire 59 59 // private Grid anzeigeGrid; … … 88 88 @Wire 89 89 private Label searchResultsProgress; 90 90 @Wire 91 private Popup wspaceSigninpop; 92 @Wire 93 private Textbox wspaceUserName; 94 @Wire 95 private Textbox wspaceUserPwd; 91 96 private WebResource mapGenerator; 92 97 public static final String MAPS_SERVICE_URL = "http://weblicht.sfs.uni-tuebingen.de/rws/service-geolocationconsumer/resources/geoloc/"; 93 94 98 private Map<String, List<String>> xAggregationContext; 95 99 private SRUVersion version = SRUVersion.VERSION_1_2; 96 100 private SearchResultsController searchResultsController; 97 101 private CenterRegistry registry; 102 private boolean testingMode = false; 98 103 99 104 @Override 100 105 public void doAfterCompose(Component comp) throws Exception { 101 106 102 107 super.doAfterCompose(comp); 103 108 … … 105 110 106 111 languageSelect.setSelectedItem(anyLanguage); 107 112 108 113 searchResultsController = new SearchResultsController(resultsBox, searchResultsProgress); 109 114 // assign the search controller to desktop, so that it can be accessed to be shutdown when the desktop is destroyed … … 112 117 Set<SearchResultsController> activeControllers = (Set<SearchResultsController>) Executions.getCurrent().getDesktop().getWebApp().getAttribute(WebAppListener.ACTIVE_SEARCH_CONTROLLERS); 113 118 activeControllers.add(searchResultsController); 114 119 115 120 registry = new CenterRegistry(); 116 registry.loadChildren( );121 registry.loadChildren(testingMode); 117 122 CorpusTreeModel corporaModel = new CorpusTreeModel(registry); 118 123 tree.setModel(corporaModel); 119 124 tree.setItemRenderer(new CorpusTreeNodeRenderer()); 120 125 tree.setMultiple(true); 121 122 126 127 123 128 //tempMap(); 124 129 … … 127 132 @Listen("onSelect = #languageSelect") 128 133 public void onSelectLanguage(Event ev) { 129 //TODO 130 } 131 132 134 //TODO 135 } 136 133 137 @Listen(ZulEvents.ON_AFTER_RENDER + "=#tree") 134 138 public void onAfterRenderCorporaTree(Event ev) { … … 157 161 searchResultsController.executeSearch(tree.getSelectedItems(), maxRecords, searchString.getText(), version); 158 162 } 159 163 160 164 @Listen("onOK = #searchString") 161 165 public void onEnterSearchString(Event ev) { 162 166 onExecuteSearch(ev); 163 167 } 164 168 165 169 @Listen("onClick=#clearResults") 166 170 public void onClearResults(Event ev) { … … 193 197 searchResultsController.exportTCF(); 194 198 } 199 200 @Listen("onClick=#exportResultsPWTCF") 201 public void onExportResultsPWTCF(Event ev) { 202 wspaceSigninpop.open(resultsBox, "top_center"); 203 } 204 205 @Listen("onClick=#wspaceSigninBtn") 206 public void onSignInExportResultsPWTCF(Event ev) { 207 String user = wspaceUserName.getValue(); 208 String pswd = wspaceUserPwd.getValue(); 209 if (user.isEmpty() || pswd.isEmpty()) { 210 Messagebox.show("Need user name and password!"); 211 } else { 212 wspaceUserPwd.setValue(""); 213 wspaceSigninpop.close(); 214 searchResultsController.exportPWTCF(user, pswd); 215 } 216 } 195 217 218 @Listen("onOK=#wspaceUserPwd") 219 public void onSignInExportResultsPWTCFPwdOK(Event ev) { 220 onSignInExportResultsPWTCF(ev); 221 } 222 223 @Listen("onClick=#wspaceCancelBtn") 224 public void onSignInPWCancel(Event ev) { 225 wspaceUserPwd.setValue(""); 226 wspaceSigninpop.close(); 227 } 228 229 196 230 @Listen("onClick=#addForeignEndpoint") 197 231 public void onAddForeignEndpoint(Event ev) { 198 232 registry.addForeignPoint(foreignEndpointSelect.getValue().split(";")[1], foreignEndpointSelect.getValue().split(";")[0]); 199 233 } 200 234 201 235 private void processParameters() { 202 236 203 237 String[] paramValue; 204 238 String contextJson = null; … … 236 270 paramsReceived[3] = contextJson; 237 271 } 238 logger.log(Level.INFO, "Received parameters: query[{0}], operation[{1}], version[{2}], x-aggregation-context[{3}], ", paramsReceived); 239 240 272 logger.log(Level.INFO, "Received parameters: query[{0}], operation[{1}], version[{2}], x-aggregation-context[{3}], ", paramsReceived); 273 274 paramValue = Executions.getCurrent().getParameterMap().get("mode"); 275 if (paramValue != null) { 276 String mode = paramValue[0].trim(); 277 if (mode.equals("testing")) { 278 testingMode = true; 279 } 280 } 241 281 242 282 if (contextJson != null) { … … 245 285 }.getType(); 246 286 try { 247 this.xAggregationContext = gson.fromJson(contextJson, mapType);287 this.xAggregationContext = gson.fromJson(contextJson, mapType); 248 288 } catch (Exception ex) { 249 289 logger.log(Level.SEVERE, "Error parsing JSON from x-aggregation-context: {0} {1}", new String[]{ex.getMessage(), contextJson}); … … 260 300 TextCorpusStored tc = new TextCorpusStored("en"); 261 301 Token t1 = tc.createTokensLayer().addToken("Virginia"); 262 List<Token> s1 = new ArrayList<Token>(); s1.add(t1); 302 List<Token> s1 = new ArrayList<Token>(); 303 s1.add(t1); 263 304 tc.createSentencesLayer().addSentence(s1); 264 305 tc.createGeoLayer("unknown", GeoLongLatFormat.DegDec); 265 306 //tc.getGeoLayer().addPoint("138.56027", "-34.6663", 15.0, null, null, null, t1); 266 307 WLData data = new WLData(tc); 267 308 268 309 Iframe resultsPic = (Iframe) resultsBox.getFellow("resultsPic"); 269 310 270 311 try { 271 272 273 274 275 276 277 312 String output = mapGenerator.path("3").accept(MediaType.TEXT_HTML).type("text/tcf+xml").post(String.class, data); 313 Media media = new AMedia("map-" + 4 + ".html", null, "text/html", output); 314 resultsPic.setContent(media); 315 } catch (Exception e) { 316 Logger.getLogger(Aggregator.class.getName()).log(Level.SEVERE, "ERROR accessing the maps generator service", e); 317 Messagebox.show("ERROR accessing the maps generator service \n" + e.getMessage(), "FCS", 0, Messagebox.INFORMATION); 318 } 278 319 } 279 320 } -
SRUAggregator/trunk/src/main/java/eu/clarin/sru/fcs/aggregator/data/CenterRegistry.java
r2527 r2738 3 3 * and open the template in the editor. 4 4 */ 5 6 5 package eu.clarin.sru.fcs.aggregator.data; 7 6 … … 25 24 /** 26 25 * Center registry node. Its children are centers (institutions). 27 * 26 * 28 27 * @author Yana Panchenko 29 28 */ 30 29 public class CenterRegistry implements CorpusTreeNode { 31 30 32 31 private static final Logger logger = Logger.getLogger(CenterRegistry.class.getName()); 33 34 32 private static final String crStartpoint = "http://130.183.206.32/restxml/"; 35 36 33 //https://centerregistry-clarin.esc.rzg.mpg.de/restxml/ 37 38 34 private boolean hasChildrenLoaded = false; 39 private List<Institution> centers = new ArrayList<Institution>(); 35 private List<Institution> centers = new ArrayList<Institution>(); 40 36 41 37 @Override … … 46 42 @Override 47 43 public void loadChildren() { 48 //TODO change to use Alex binding for that... 44 loadChildren(false); 45 } 46 47 public void loadChildren(boolean testingMode) { 48 49 49 if (hasChildrenLoaded) { 50 50 return; 51 51 } 52 52 hasChildrenLoaded = true; 53 54 if (testingMode) { 55 loadInstitutionForTesting(); 56 } else { 57 loadInstitutionsFromCR(); 58 } 59 60 logger.log(Level.FINE, "Number of Centers: {0}", centers.size()); 61 62 } 63 64 @Override 65 public List<? extends CorpusTreeNode> getChildren() { 66 loadChildren(); 67 return centers; 68 } 69 70 @Override 71 public CorpusTreeNode getChild(int index) { 72 loadChildren(); 73 if (index >= centers.size()) { 74 return null; 75 } 76 return centers.get(index); 77 } 78 79 public void addForeignPoint(String endpointUrl, String institutionLink) { 80 //TODO: ask what functionality is required here?? 81 // boolean added = false; 82 // for (Institution center : this.centers) { 83 // if (center.getLink().equals(institutionLink)) { 84 // EndpointY ep = new EndpointY(endpointUrl, center); 85 // center.loadChildren(); 86 // //center.loadChildren(); 87 // //ep.loadChildren(); 88 // } 89 // } 90 // if (!added) { 91 // Institution institution = new Institution("unknown", institutionLink); 92 // this.centers.add(institution); 93 // //EndpointY ep = new EndpointY(endpointUrl, institution); 94 // //this.loadChildren(); 95 // //institution.loadChildren(); 96 // } 97 } 98 99 public static NodeList evaluateXPath(String statement, org.w3c.dom.Document domtree) { 100 NodeList result = null; 101 102 XPath xpath = XPathFactory.newInstance().newXPath(); 103 try { 104 result = (NodeList) xpath.evaluate(statement, domtree, XPathConstants.NODESET); 105 } catch (XPathExpressionException ex) { 106 logger.log(Level.SEVERE, "Error parsing XML: ", statement); 107 } 108 return result; 109 } 110 111 //TODO change to use Alex binding for that... 112 private void loadInstitutionsFromCR() { 53 113 InputStream is = null; 54 114 URL u; … … 63 123 64 124 //HttpsURLConnection urlConn = (HttpsURLConnection) u.openConnection(); 65 66 urlConn.setConnectTimeout(5000); 125 126 urlConn.setConnectTimeout(5000); 67 127 urlConn.setReadTimeout(15000); 68 128 urlConn.setAllowUserInteraction(false); 69 129 70 130 is = urlConn.getInputStream(); 71 131 … … 76 136 org.w3c.dom.Document document = builder.parse(is); 77 137 78 138 79 139 instituteNames = evaluateXPath("//Centername", document); 80 140 institutionsUrls = evaluateXPath("//Center_id_link", document); … … 101 161 } 102 162 } 103 logger.log(Level.FINE, "Number of Centers: {0}", centers.size());104 105 163 } 106 164 107 @Override 108 public List<? extends CorpusTreeNode> getChildren() { 109 loadChildren(); 110 return centers; 165 private void loadInstitutionForTesting() { 166 String institutionUrl = "http://www.example.org"; 167 String institutionName = "Institution for Testing"; 168 Institution institution = new InstitutionForTesting(institutionName, institutionUrl); 169 if (!institution.getChildren().isEmpty()) { 170 centers.add(institution); 171 } 111 172 } 112 113 @Override114 public CorpusTreeNode getChild(int index) {115 loadChildren();116 if (index >= centers.size()) {117 return null;118 }119 return centers.get(index);120 }121 122 123 public void addForeignPoint(String endpointUrl, String institutionLink) {124 125 //TODO: ask what functionality is required here??126 127 // boolean added = false;128 // for (Institution center : this.centers) {129 // if (center.getLink().equals(institutionLink)) {130 // EndpointY ep = new EndpointY(endpointUrl, center);131 // center.loadChildren();132 // //center.loadChildren();133 // //ep.loadChildren();134 // }135 // }136 // if (!added) {137 // Institution institution = new Institution("unknown", institutionLink);138 // this.centers.add(institution);139 // //EndpointY ep = new EndpointY(endpointUrl, institution);140 // //this.loadChildren();141 // //institution.loadChildren();142 // }143 }144 145 146 public static NodeList evaluateXPath(String statement, org.w3c.dom.Document domtree) {147 NodeList result = null;148 149 XPath xpath = XPathFactory.newInstance().newXPath();150 try {151 result = (NodeList) xpath.evaluate(statement, domtree, XPathConstants.NODESET);152 } catch (XPathExpressionException ex) {153 System.out.println(ex.getMessage());154 }155 return result;156 }157 158 173 } -
SRUAggregator/trunk/src/main/java/eu/clarin/sru/fcs/aggregator/data/Corpus.java
r2599 r2738 127 127 StringBuilder scanClause = new StringBuilder("fcs.resource"); 128 128 scanClause.append("="); 129 scanClause.append(""); 129 130 scanClause.append(value); 131 scanClause.append(""); 130 132 try { 131 133 SRUClient sruClient = new SRUClient(SRUVersion.VERSION_1_2); -
SRUAggregator/trunk/src/main/java/eu/clarin/sru/fcs/aggregator/data/InstitutionForTesting.java
r2599 r2738 19 19 * @author Yana Panchenko 20 20 */ 21 public class Institution implements CorpusTreeNode{21 public class InstitutionForTesting extends Institution { 22 22 23 private String name; 24 private String link; 25 private ArrayList<Endpoint> endpoints; 23 private List<Endpoint> endpoints = new ArrayList<Endpoint>(); 26 24 private boolean hasChildrenLoaded = false; 25 26 private static final String[] testEndpoints = new String[]{"http://lux17.mpi.nl/cqltest"}; 27 27 28 28 private static final Logger logger = Logger.getLogger(Institution.class.getName()); 29 29 30 public Institution(String name, String link) { 31 this.name = name; 32 this.link = link; 33 this.endpoints = new ArrayList<Endpoint>(); 30 public InstitutionForTesting(String name, String link) { 31 super(name,link); 34 32 } 35 33 36 public String getName() {37 return name;38 }39 34 40 public String getLink() {41 return link;42 }43 35 44 36 @Override … … 54 46 } 55 47 hasChildrenLoaded = true; 56 InputStream is = null;57 48 58 try { 59 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 60 DocumentBuilder builder = factory.newDocumentBuilder(); 61 URL u = new URL(link); 62 is = u.openStream(); 63 Document doc = builder.parse(is); 64 is.close(); 65 NodeList endpointsUrls = CenterRegistry 66 .evaluateXPath("//WebReference[./Description[text()=\"CQL\"]]/Website", doc); 67 68 for (int j = 0; j < endpointsUrls.getLength(); j++) { 69 String epUrl = endpointsUrls.item(j).getTextContent(); 49 for (int j = 0; j < testEndpoints.length; j++) { 50 String epUrl = testEndpoints[j]; 70 51 Endpoint endpoint = new Endpoint(epUrl, this); 71 52 endpoints.add(endpoint); 72 } 73 } catch (Exception ex) { 74 logger.log(Level.SEVERE, "Error accessing endpoint of {0} {1} {2}", 75 new String[]{link, ex.getClass().getName(), ex.getMessage()}); 76 } finally { 77 if (is != null) { 78 try { 79 is.close(); 80 } catch (IOException ex) { 81 logger.log(Level.SEVERE, null, ex); 82 } 83 } 84 } 53 } 54 85 55 } 86 56 … … 100 70 } 101 71 102 @Override 103 public String toString() { 104 if (name != null && name.length() > 0) { 105 return name; 106 } else { 107 return link; 108 } 109 } 72 110 73 } -
SRUAggregator/trunk/src/main/java/eu/clarin/sru/fcs/aggregator/sresult/SearchResultsController.java
r2606 r2738 1 1 package eu.clarin.sru.fcs.aggregator.sresult; 2 2 3 import com.googlecode.sardine.Sardine; 4 import com.googlecode.sardine.SardineFactory; 3 5 import eu.clarin.sru.client.SRUClientException; 4 6 import eu.clarin.sru.client.SRURecord; … … 19 21 import eu.clarin.weblicht.wlfxb.tc.xb.TextCorpusStored; 20 22 import eu.clarin.weblicht.wlfxb.xb.WLData; 23 import java.io.ByteArrayInputStream; 21 24 import java.io.ByteArrayOutputStream; 25 import java.io.IOException; 26 import java.io.InputStream; 27 import java.text.DateFormat; 28 import java.text.SimpleDateFormat; 22 29 import java.util.ArrayList; 30 import java.util.Date; 23 31 import java.util.List; 32 import java.util.Random; 24 33 import java.util.Set; 25 34 import java.util.concurrent.Future; … … 58 67 private Label progress; 59 68 69 70 private static final String WSPACE_SERVER_URL = "http://egi-cloud21.zam.kfa-juelich.de"; 71 private static final String WSPACE_WEBDAV_DIR = "/owncloud/remote.php/webdav/"; 72 private static final String AGGREGATOR_DIR = "aggregator_results/"; 73 60 74 private static final Logger logger = Logger.getLogger(SearchResultsController.class.getName()); 61 75 … … 171 185 resultsThread = new UpdateResultsThread(); 172 186 resultsThread.start(); 187 } 188 189 private String kwcToText() { 190 StringBuilder text = new StringBuilder(); 191 192 if (resultsProcessed != null && !resultsProcessed.isEmpty()) { 193 for (SearchResult result : resultsProcessed) { 194 for (DataViewKWIC kwic : result.getDataKWIC()) { 195 text.append(kwic.getLeft()); 196 text.append(" "); 197 text.append(kwic.getKeyword()); 198 text.append(" "); 199 text.append(kwic.getRight()); 200 text.append("\n"); 201 } 202 } 203 204 } 205 return text.toString(); 173 206 } 174 207 … … 387 420 } 388 421 } 422 423 424 425 public void exportPWTCF(String user, String pass) { 426 String text = kwcToText(); 427 428 if (text.isEmpty()) { 429 Messagebox.show("Nothing to export!"); 430 } else { 431 WLData data; 432 MetaData md = new MetaData(); 433 //data.metaData.source = "Tuebingen Uni"; 434 //md.addMetaDataItem("title", "binding test"); 435 //md.addMetaDataItem("author", "Yana"); 436 TextCorpusStored tc = new TextCorpusStored("unknown"); 437 tc.createTextLayer().addText(text.toString()); 438 data = new WLData(md, tc); 439 ByteArrayOutputStream os = new ByteArrayOutputStream(); 440 try { 441 WLDObjector.write(data, os); 442 //Filedownload.save(os.toByteArray(), "text/tcf+xml", "ClarinDFederatedContentSearch.xml"); 443 Sardine sardine = SardineFactory.begin(); 444 sardine.setCredentials(user, pass); 445 String outputDir = WSPACE_SERVER_URL + WSPACE_WEBDAV_DIR + AGGREGATOR_DIR; 446 if (!sardine.exists(outputDir)) { 447 sardine.createDirectory(outputDir); 448 } 449 Date currentDate = new Date(); 450 SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss-SSS"); 451 Random generator = new Random(); 452 int rn1 = generator.nextInt(1000000000); 453 String createdFilePath = outputDir + format.format(currentDate) + "-" + rn1 + ".tcf"; 454 while (sardine.exists(createdFilePath)) { 455 rn1 = generator.nextInt(1000000000); 456 createdFilePath = outputDir + format.format(currentDate) + "-" + rn1 + ".tcf"; 457 } 458 sardine.put(createdFilePath, os.toByteArray(), "text/tcf+xml"); 459 Messagebox.show("Export complete!\nCreated file:\n" + createdFilePath); 460 461 } catch (IOException ex) { 462 Logger.getLogger(SearchResultsController.class.getName()).log(Level.SEVERE, "Error accessing " + WSPACE_SERVER_URL + WSPACE_WEBDAV_DIR, ex); 463 } catch (WLFormatException ex) { 464 logger.log(Level.SEVERE, "Error exporting TCF {0} {1}", new String[]{ex.getClass().getName(), ex.getMessage()}); 465 Messagebox.show("Sorry, export error!"); 466 } 467 } 468 } 389 469 390 470 public void shutdown() { -
SRUAggregator/trunk/src/main/webapp/index.zul
r2694 r2738 151 151 <menuitem label="Export Results to TCF" id="exportResultsTCF" 152 152 image="buttonExport.png"/> 153 <menuitem label="Export Results as TCF to personal workspace" id="exportResultsPWTCF" 154 image="buttonExport.png"/> 153 155 </menupopup> 154 156 </menu> … … 162 164 </menubar> 163 165 </north> 164 <center margins="0,5,0,0" autoscroll="true" border="0" >165 <panel width="100%" height="100%">166 <panelchildren id="resultsPanel" style="overflow: auto">167 <window id="resultsBox" style="overflow:auto;" width="100%" height="100%">168 <iframe id="resultsPic" src="help.html" width=" 100%" height="100%"/>166 <center margins="0,5,0,0" autoscroll="true" border="0" > 167 <panel> 168 <panelchildren id="resultsPanel" > 169 <window id="resultsBox" style="overflow:auto;"> 170 <iframe id="resultsPic" src="help.html" width="80%" height="80%"/> 169 171 </window> 170 172 <label value=" " id="searchResultsProgress" style="border-width:0px;margin-left:5px;"/> … … 181 183 182 184 </borderlayout> 185 186 187 188 <popup id="wspaceSigninpop" width="400px"> 189 <label value="Personal Workspace Sign In" style="font-weight:bold;color:#0e4071;"/> 190 <grid> 191 192 <rows> 193 <row> 194 <label style="font-weight:bold" value="Username:"/> 195 <textbox id="wspaceUserName" width="150px" value=""/> 196 </row> 197 <row> 198 <label style="font-weight:bold" value="Password:"/> 199 <textbox id="wspaceUserPwd" type="password" width="150px" value=""/> 200 </row> 201 202 <!-- 203 <row spans="2"> 204 <div align="center"> 205 <button id="wspaceSigninBtn" label="Sign in" image="key.png" sclass="ccsDarkBlue" /> 206 <button id="wspaceCancelBtn" label="Cancel" image="buttonDelete.png" sclass="ccsDarkBlue" style="margin-left:10px;"/> 207 </div> 208 </row> 209 --> 210 <row> 211 <div> 212 </div> 213 <div align="center"> 214 <button id="wspaceSigninBtn" label="Sign in" image="key.png" sclass="ccsDarkBlue" /> 215 <button id="wspaceCancelBtn" label="Cancel" image="buttonDelete.png" sclass="ccsDarkBlue" style="margin-left:10px;"/> 216 </div> 217 </row> 218 219 </rows> 220 </grid> 221 </popup> 183 222 184 223 </window>
Note: See TracChangeset
for help on using the changeset viewer.