diff --git a/IDE/eclipse/Gridworks.style.xml b/IDEs/eclipse/Gridworks.style.xml similarity index 100% rename from IDE/eclipse/Gridworks.style.xml rename to IDEs/eclipse/Gridworks.style.xml diff --git a/IDE/eclipse/README.txt b/IDEs/eclipse/README.txt similarity index 100% rename from IDE/eclipse/README.txt rename to IDEs/eclipse/README.txt diff --git a/appengine/.classpath b/appengine/.classpath deleted file mode 100644 index cc1ca7b80..000000000 --- a/appengine/.classpath +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - - - diff --git a/appengine/.externalToolBuilders/com.google.appengine.eclipse.core.projectValidator.launch b/appengine/.externalToolBuilders/com.google.appengine.eclipse.core.projectValidator.launch deleted file mode 100644 index 3a3b1b194..000000000 --- a/appengine/.externalToolBuilders/com.google.appengine.eclipse.core.projectValidator.launch +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - diff --git a/appengine/.externalToolBuilders/com.google.gdt.eclipse.core.webAppProjectValidator.launch b/appengine/.externalToolBuilders/com.google.gdt.eclipse.core.webAppProjectValidator.launch deleted file mode 100644 index eb4252719..000000000 --- a/appengine/.externalToolBuilders/com.google.gdt.eclipse.core.webAppProjectValidator.launch +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - diff --git a/appengine/.project b/appengine/.project deleted file mode 100644 index c7fc93149..000000000 --- a/appengine/.project +++ /dev/null @@ -1,43 +0,0 @@ - - - gridworks appengine - - - - - - org.eclipse.jdt.core.javabuilder - - - - - org.eclipse.ui.externaltools.ExternalToolBuilder - full,incremental, - - - LaunchConfigHandle - <project>/.externalToolBuilders/com.google.gdt.eclipse.core.webAppProjectValidator.launch - - - - - com.google.appengine.eclipse.core.enhancerbuilder - - - - - org.eclipse.ui.externaltools.ExternalToolBuilder - full,incremental, - - - LaunchConfigHandle - <project>/.externalToolBuilders/com.google.appengine.eclipse.core.projectValidator.launch - - - - - - org.eclipse.jdt.core.javanature - com.google.appengine.eclipse.core.gaeNature - - diff --git a/appengine/.settings/com.google.appengine.eclipse.core.prefs b/appengine/.settings/com.google.appengine.eclipse.core.prefs deleted file mode 100644 index b727dd4d9..000000000 --- a/appengine/.settings/com.google.appengine.eclipse.core.prefs +++ /dev/null @@ -1,3 +0,0 @@ -#Wed May 26 15:13:15 PDT 2010 -eclipse.preferences.version=1 -validationExclusions=src/com/metaweb/gridworks/appengine/*ClientConnection*.java diff --git a/appengine/.settings/com.google.gdt.eclipse.core.prefs b/appengine/.settings/com.google.gdt.eclipse.core.prefs deleted file mode 100644 index a060470b7..000000000 --- a/appengine/.settings/com.google.gdt.eclipse.core.prefs +++ /dev/null @@ -1,5 +0,0 @@ -#Wed May 26 15:11:38 PDT 2010 -eclipse.preferences.version=1 -jarsExcludedFromWebInfLib= -warSrcDir= -warSrcDirIsOutput=true diff --git a/appengine/lib/commons-vfs-2.0-SNAPSHOT.jar b/appengine/lib/commons-vfs-2.0-SNAPSHOT.jar deleted file mode 100644 index f237fc065..000000000 Binary files a/appengine/lib/commons-vfs-2.0-SNAPSHOT.jar and /dev/null differ diff --git a/appengine/lib/gaevfs-0.3.jar b/appengine/lib/gaevfs-0.3.jar deleted file mode 100644 index ce90204cb..000000000 Binary files a/appengine/lib/gaevfs-0.3.jar and /dev/null differ diff --git a/appengine/lib/slf4j-jdk14-1.5.6.jar b/appengine/lib/slf4j-jdk14-1.5.6.jar deleted file mode 100644 index 1ce0a28e7..000000000 Binary files a/appengine/lib/slf4j-jdk14-1.5.6.jar and /dev/null differ diff --git a/appengine/src/com/metaweb/gridworks/appengine/AppEngineClientConnection.java b/appengine/src/com/metaweb/gridworks/appengine/AppEngineClientConnection.java deleted file mode 100644 index 9f0effa08..000000000 --- a/appengine/src/com/metaweb/gridworks/appengine/AppEngineClientConnection.java +++ /dev/null @@ -1,243 +0,0 @@ -package com.metaweb.gridworks.appengine; - -import static com.google.appengine.api.urlfetch.FetchOptions.Builder.allowTruncate; - -import java.io.ByteArrayOutputStream; -import java.net.InetAddress; -import java.net.URL; -import java.util.concurrent.TimeUnit; - -import javax.net.ssl.SSLSession; - -import org.apache.http.Header; -import org.apache.http.HttpConnectionMetrics; -import org.apache.http.HttpHost; -import org.apache.http.HttpResponse; -import org.apache.http.ProtocolVersion; -import org.apache.http.conn.ManagedClientConnection; -import org.apache.http.conn.routing.HttpRoute; -import org.apache.http.entity.ByteArrayEntity; -import org.apache.http.message.BasicHttpResponse; -import org.apache.http.params.HttpParams; -import org.apache.http.protocol.HttpContext; - -import com.google.appengine.api.urlfetch.HTTPHeader; -import com.google.appengine.api.urlfetch.HTTPMethod; -import com.google.appengine.api.urlfetch.HTTPRequest; -import com.google.appengine.api.urlfetch.HTTPResponse; -import com.google.appengine.api.urlfetch.URLFetchService; -import com.google.appengine.api.urlfetch.URLFetchServiceFactory; - -class AppEngineClientConnection implements ManagedClientConnection { - // Managed is the composition of ConnectionReleaseTrigger, - // HttpClientConnection, HttpConnection, HttpInetConnection - - private HttpRoute _route; - private Object _state; - private boolean _reuseable; - - public AppEngineClientConnection(HttpRoute route, Object state) { - _route = route; - _state = state; - } - - // ManagedClientConnection methods - - public HttpRoute getRoute() { - return _route; - } - - public Object getState() { - return _state; - } - - public SSLSession getSSLSession() { - return null; - } - - public boolean isSecure() { - // XXX maybe parse the url to see if it's https? - return false; - } - - public boolean isMarkedReusable() { - return _reuseable; - } - - public void markReusable() { - _reuseable = true; - } - - public void layerProtocol(HttpContext context, HttpParams params) { - return; - } - - public void open(HttpRoute route, HttpContext context, HttpParams params) { - return; - } - - public void setIdleDuration(long duration, TimeUnit unit) { - return; - } - - public void setState(Object state) { - _state = state; - } - - public void tunnelProxy(HttpHost next, boolean secure, HttpParams params) { - return; - } - - public void tunnelTarget(boolean secure, HttpParams params) { - return; - } - - public void unmarkReusable() { - _reuseable = false; - } - - - // ConnectionReleaseTrigger methods - - public void releaseConnection() { - return; - } - - public void abortConnection() { - return; - } - - // HttpClientConnection methods - - private HTTPRequest _appengine_hrequest; - private HTTPResponse _appengine_hresponse; - - public void flush() { - return; - } - - public boolean isResponseAvailable(int timeout) { - // XXX possibly use Async fetcher - return true; - } - - public void receiveResponseEntity(org.apache.http.HttpResponse apache_response) { - byte[] data = _appengine_hresponse.getContent(); - - if (data != null) { - apache_response.setEntity(new ByteArrayEntity(data)); - } - } - - public HttpResponse receiveResponseHeader() { - URLFetchService ufs = URLFetchServiceFactory.getURLFetchService(); - try { - _appengine_hresponse = ufs.fetch(_appengine_hrequest); - } catch (java.io.IOException e) { - throw new RuntimeException(e); - } - - org.apache.http.HttpResponse apache_response = - new BasicHttpResponse(new ProtocolVersion("HTTP", 1, 0), - _appengine_hresponse.getResponseCode(), - null); - - for (HTTPHeader h : _appengine_hresponse.getHeaders()) { - apache_response.addHeader(h.getName(), h.getValue()); - } - - return apache_response; - } - - public void sendRequestEntity(org.apache.http.HttpEntityEnclosingRequest request) { - ByteArrayOutputStream os = new ByteArrayOutputStream(); - - org.apache.http.HttpEntity ent = request.getEntity(); - if (ent != null) { - try { - ent.writeTo(os); - } catch (java.io.IOException e) { - throw new RuntimeException(e); - } - } - - _appengine_hrequest.setPayload(os.toByteArray()); - } - - public void sendRequestHeader(org.apache.http.HttpRequest apache_request) { - URL request_url; - - HttpHost host = _route.getTargetHost(); - - String protocol = host.getSchemeName(); - String addr = host.getHostName(); - int port = host.getPort(); - - String path = apache_request.getRequestLine().getUri(); - - try { - request_url = new URL(protocol, addr, port, path); - } catch (java.net.MalformedURLException e) { - throw new RuntimeException(e); - } - - HTTPMethod method = HTTPMethod.valueOf(apache_request.getRequestLine().getMethod()); - _appengine_hrequest = new HTTPRequest(request_url, method, allowTruncate() - .doNotFollowRedirects()); - - Header[] apache_headers = apache_request.getAllHeaders(); - for (int i = 0; i < apache_headers.length; i++) { - Header h = apache_headers[i]; - _appengine_hrequest - .setHeader(new HTTPHeader(h.getName(), h.getValue())); - } - } - - // HttpConnection methods - - public void close() { - return; - } - - public HttpConnectionMetrics getMetrics() { - return null; - } - - public int getSocketTimeout() { - return -1; - } - - public boolean isOpen() { - return true; - } - - public boolean isStale() { - return false; - } - - public void setSocketTimeout(int timeout) { - return; - } - - public void shutdown() { - return; - } - - // HttpInetConnection methods - - public InetAddress getLocalAddress() { - return null; - } - - public int getLocalPort() { - return -1; - } - - public InetAddress getRemoteAddress() { - return null; - } - - public int getRemotePort() { - return -1; - } -} \ No newline at end of file diff --git a/appengine/src/com/metaweb/gridworks/appengine/AppEngineClientConnectionManager.java b/appengine/src/com/metaweb/gridworks/appengine/AppEngineClientConnectionManager.java deleted file mode 100644 index 9bbc1e9f4..000000000 --- a/appengine/src/com/metaweb/gridworks/appengine/AppEngineClientConnectionManager.java +++ /dev/null @@ -1,83 +0,0 @@ -package com.metaweb.gridworks.appengine; - -import java.net.InetAddress; -import java.net.Socket; -import java.util.concurrent.TimeUnit; - -import org.apache.http.conn.ClientConnectionManager; -import org.apache.http.conn.ClientConnectionRequest; -import org.apache.http.conn.ManagedClientConnection; -import org.apache.http.conn.routing.HttpRoute; -import org.apache.http.conn.scheme.Scheme; -import org.apache.http.conn.scheme.SchemeRegistry; -import org.apache.http.conn.scheme.SocketFactory; -import org.apache.http.params.HttpParams; - -public class AppEngineClientConnectionManager implements ClientConnectionManager { - private SchemeRegistry schemes; - - class NoopSocketFactory implements SocketFactory { - public Socket connectSocket(Socket sock, String host, int port, - InetAddress addr, int lport, - HttpParams params) { - return null; - } - - public Socket createSocket() { - return null; - } - - public boolean isSecure(Socket sock) { - return false; - } - } - - public AppEngineClientConnectionManager() { - SocketFactory noop_sf = new NoopSocketFactory(); - - schemes = new SchemeRegistry(); - schemes.register(new Scheme("http", noop_sf, 80)); - schemes.register(new Scheme("https", noop_sf, 443)); - } - - public void closeExpiredConnections() { - return; - } - - public void closeIdleConnections(long idletime, TimeUnit tunit) { - return; - } - - public ManagedClientConnection getConnection(HttpRoute route, Object state) { - return new AppEngineClientConnection(route, state); - } - - public SchemeRegistry getSchemeRegistry() { - return schemes; - } - - public void releaseConnection(ManagedClientConnection conn, - long valid, TimeUnit tuint) { - return; - } - - public ClientConnectionRequest requestConnection(final HttpRoute route, - final Object state) { - return new ClientConnectionRequest() { - public void abortRequest() { - return; - } - - public ManagedClientConnection getConnection(long idletime, - TimeUnit tunit) { - - return AppEngineClientConnectionManager.this.getConnection(route, state); - } - }; - } - - public void shutdown() { - return; - } -} - diff --git a/build.xml b/build.xml index 82097d3ea..2dc4a6b82 100644 --- a/build.xml +++ b/build.xml @@ -118,6 +118,7 @@ + @@ -125,6 +126,7 @@ + diff --git a/licenses/gaevfs.LICENSE.txt b/licenses/gaevfs.LICENSE.txt deleted file mode 100644 index 75b52484e..000000000 --- a/licenses/gaevfs.LICENSE.txt +++ /dev/null @@ -1,202 +0,0 @@ - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. diff --git a/main/IDE/eclipse/GridworksTests.launch b/main/IDEs/eclipse/GridworksTests.launch similarity index 90% rename from main/IDE/eclipse/GridworksTests.launch rename to main/IDEs/eclipse/GridworksTests.launch index 8c71e0fee..0cc57b89a 100644 --- a/main/IDE/eclipse/GridworksTests.launch +++ b/main/IDEs/eclipse/GridworksTests.launch @@ -6,7 +6,6 @@ - diff --git a/main/IDE/eclipse/README.txt b/main/IDEs/eclipse/README.txt similarity index 100% rename from main/IDE/eclipse/README.txt rename to main/IDEs/eclipse/README.txt diff --git a/main/src/com/metaweb/gridworks/GridworksServlet.java b/main/src/com/metaweb/gridworks/GridworksServlet.java index 89b774a80..d884d5ef6 100644 --- a/main/src/com/metaweb/gridworks/GridworksServlet.java +++ b/main/src/com/metaweb/gridworks/GridworksServlet.java @@ -245,6 +245,7 @@ public class GridworksServlet extends HttpServlet { Command cmd; try { cmd = (Command) this.getClass().getClassLoader().loadClass(className).newInstance(); + cmd.init(this); } catch (InstantiationException e) { logger.error("Failed to load command class " + className, e); status = false; diff --git a/main/src/com/metaweb/gridworks/browsing/Engine.java b/main/src/com/metaweb/gridworks/browsing/Engine.java index ef09b67ec..2fe6f0227 100644 --- a/main/src/com/metaweb/gridworks/browsing/Engine.java +++ b/main/src/com/metaweb/gridworks/browsing/Engine.java @@ -59,6 +59,7 @@ public class Engine implements Jsonizable { public FilteredRows getAllRows() { return new FilteredRows() { + @Override public void accept(Project project, RowVisitor visitor) { try { visitor.start(project); @@ -99,6 +100,7 @@ public class Engine implements Jsonizable { public FilteredRecords getAllRecords() { return new FilteredRecords() { + @Override public void accept(Project project, RecordVisitor visitor) { try { visitor.start(project); diff --git a/main/src/com/metaweb/gridworks/browsing/facets/ListFacet.java b/main/src/com/metaweb/gridworks/browsing/facets/ListFacet.java index d926f877e..e446e4e5a 100644 --- a/main/src/com/metaweb/gridworks/browsing/facets/ListFacet.java +++ b/main/src/com/metaweb/gridworks/browsing/facets/ListFacet.java @@ -58,7 +58,9 @@ public class ListFacet implements Facet { public ListFacet() { } - public void write(JSONWriter writer, Properties options) throws JSONException { + @Override + public void write(JSONWriter writer, Properties options) + throws JSONException { writer.object(); writer.key("name"); writer.value(_name); @@ -96,6 +98,7 @@ public class ListFacet implements Facet { writer.endObject(); } + @Override public void initializeFromJSON(Project project, JSONObject o) throws Exception { _name = o.getString("name"); _expression = o.getString("expression"); @@ -144,6 +147,7 @@ public class ListFacet implements Facet { _selectError = JSONUtilities.getBoolean(o, "selectError", false); } + @Override public RowFilter getRowFilter(Project project) { return _eval == null || @@ -160,11 +164,13 @@ public class ListFacet implements Facet { _invert); } + @Override public RecordFilter getRecordFilter(Project project) { RowFilter rowFilter = getRowFilter(project); return rowFilter == null ? null : new AnyRowRecordFilter(rowFilter); } + @Override public void computeChoices(Project project, FilteredRows filteredRows) { if (_eval != null && _errorMessage == null) { ExpressionNominalValueGrouper grouper = @@ -176,6 +182,7 @@ public class ListFacet implements Facet { } } + @Override public void computeChoices(Project project, FilteredRecords filteredRecords) { if (_eval != null && _errorMessage == null) { ExpressionNominalValueGrouper grouper = diff --git a/main/src/com/metaweb/gridworks/browsing/facets/RangeFacet.java b/main/src/com/metaweb/gridworks/browsing/facets/RangeFacet.java index 5df1f967b..63286a729 100644 --- a/main/src/com/metaweb/gridworks/browsing/facets/RangeFacet.java +++ b/main/src/com/metaweb/gridworks/browsing/facets/RangeFacet.java @@ -174,6 +174,7 @@ public class RangeFacet implements Facet { } } + @Override public RecordFilter getRecordFilter(Project project) { RowFilter rowFilter = getRowFilter(project); return rowFilter == null ? null : new AnyRowRecordFilter(rowFilter); diff --git a/main/src/com/metaweb/gridworks/browsing/facets/ScatterplotDrawingRowVisitor.java b/main/src/com/metaweb/gridworks/browsing/facets/ScatterplotDrawingRowVisitor.java index 0d6384a7a..1c6c041d9 100644 --- a/main/src/com/metaweb/gridworks/browsing/facets/ScatterplotDrawingRowVisitor.java +++ b/main/src/com/metaweb/gridworks/browsing/facets/ScatterplotDrawingRowVisitor.java @@ -87,14 +87,17 @@ public class ScatterplotDrawingRowVisitor implements RowVisitor, RecordVisitor { g2.setPaint(color); } + @Override public void start(Project project) { // nothing to do } + @Override public void end(Project project) { // nothing to do } + @Override public boolean visit(Project project, int rowIndex, Row row) { Cell cellx = row.getCell(col_x); Cell celly = row.getCell(col_y); @@ -115,6 +118,7 @@ public class ScatterplotDrawingRowVisitor implements RowVisitor, RecordVisitor { return false; } + @Override public boolean visit(Project project, Record record) { for (int r = record.fromRowIndex; r < record.toRowIndex; r++) { visit(project, r, project.rows.get(r)); diff --git a/main/src/com/metaweb/gridworks/browsing/facets/ScatterplotFacet.java b/main/src/com/metaweb/gridworks/browsing/facets/ScatterplotFacet.java index 2dd1b7b15..a47cd5436 100644 --- a/main/src/com/metaweb/gridworks/browsing/facets/ScatterplotFacet.java +++ b/main/src/com/metaweb/gridworks/browsing/facets/ScatterplotFacet.java @@ -276,6 +276,7 @@ public class ScatterplotFacet implements Facet { } } + @Override public RecordFilter getRecordFilter(Project project) { RowFilter rowFilter = getRowFilter(project); return rowFilter == null ? null : new AnyRowRecordFilter(rowFilter); diff --git a/main/src/com/metaweb/gridworks/browsing/facets/TextSearchFacet.java b/main/src/com/metaweb/gridworks/browsing/facets/TextSearchFacet.java index 83f8e946c..7ef20ca35 100644 --- a/main/src/com/metaweb/gridworks/browsing/facets/TextSearchFacet.java +++ b/main/src/com/metaweb/gridworks/browsing/facets/TextSearchFacet.java @@ -36,7 +36,10 @@ public class TextSearchFacet implements Facet { public TextSearchFacet() { } - public void write(JSONWriter writer, Properties options) throws JSONException { + @Override + public void write(JSONWriter writer, Properties options) + throws JSONException { + writer.object(); writer.key("name"); writer.value(_name); writer.key("columnName"); writer.value(_columnName); @@ -46,6 +49,7 @@ public class TextSearchFacet implements Facet { writer.endObject(); } + @Override public void initializeFromJSON(Project project, JSONObject o) throws Exception { _name = o.getString("name"); _columnName = o.getString("columnName"); @@ -73,6 +77,7 @@ public class TextSearchFacet implements Facet { } } + @Override public RowFilter getRowFilter(Project project) { if (_query == null || _query.length() == 0) { return null; @@ -97,15 +102,18 @@ public class TextSearchFacet implements Facet { } } + @Override public RecordFilter getRecordFilter(Project project) { RowFilter rowFilter = getRowFilter(project); return rowFilter == null ? null : new AnyRowRecordFilter(rowFilter); } + @Override public void computeChoices(Project project, FilteredRows filteredRows) { // nothing to do } + @Override public void computeChoices(Project project, FilteredRecords filteredRecords) { // nothing to do } diff --git a/main/src/com/metaweb/gridworks/browsing/filters/AnyRowRecordFilter.java b/main/src/com/metaweb/gridworks/browsing/filters/AnyRowRecordFilter.java index 157f339a9..8208bf2cc 100644 --- a/main/src/com/metaweb/gridworks/browsing/filters/AnyRowRecordFilter.java +++ b/main/src/com/metaweb/gridworks/browsing/filters/AnyRowRecordFilter.java @@ -6,13 +6,13 @@ import com.metaweb.gridworks.model.Project; import com.metaweb.gridworks.model.Record; public class AnyRowRecordFilter implements RecordFilter { - - final protected RowFilter _rowFilter; + final protected RowFilter _rowFilter; public AnyRowRecordFilter(RowFilter rowFilter) { _rowFilter = rowFilter; } + @Override public boolean filterRecord(Project project, Record record) { for (int r = record.fromRowIndex; r < record.toRowIndex; r++) { if (_rowFilter.filterRow(project, r, project.rows.get(r))) { diff --git a/main/src/com/metaweb/gridworks/browsing/util/ConjunctiveFilteredRecords.java b/main/src/com/metaweb/gridworks/browsing/util/ConjunctiveFilteredRecords.java index fc52b2895..e17b453f8 100644 --- a/main/src/com/metaweb/gridworks/browsing/util/ConjunctiveFilteredRecords.java +++ b/main/src/com/metaweb/gridworks/browsing/util/ConjunctiveFilteredRecords.java @@ -13,13 +13,13 @@ import com.metaweb.gridworks.model.Record; * Encapsulate logic for visiting records that match all given record filters. */ public class ConjunctiveFilteredRecords implements FilteredRecords { - final protected List _recordFilters = new LinkedList(); public void add(RecordFilter recordFilter) { _recordFilters.add(recordFilter); } + @Override public void accept(Project project, RecordVisitor visitor) { try { visitor.start(project); diff --git a/main/src/com/metaweb/gridworks/browsing/util/ExpressionBasedRowEvaluable.java b/main/src/com/metaweb/gridworks/browsing/util/ExpressionBasedRowEvaluable.java index 8b128e8be..2e5fdeafa 100644 --- a/main/src/com/metaweb/gridworks/browsing/util/ExpressionBasedRowEvaluable.java +++ b/main/src/com/metaweb/gridworks/browsing/util/ExpressionBasedRowEvaluable.java @@ -9,20 +9,22 @@ import com.metaweb.gridworks.model.Project; import com.metaweb.gridworks.model.Row; public class ExpressionBasedRowEvaluable implements RowEvaluable { + final protected String _columnName; + final protected int _cellIndex; + final protected Evaluable _eval; + + public ExpressionBasedRowEvaluable( + String columnName, int cellIndex, Evaluable eval) { + + _columnName = columnName; + _cellIndex = cellIndex; + _eval = eval; + } - final protected String _columnName; - final protected int _cellIndex; - final protected Evaluable _eval; - - public ExpressionBasedRowEvaluable(String columnName, int cellIndex, Evaluable eval) { - - _columnName = columnName; - _cellIndex = cellIndex; - _eval = eval; - } - - public Object eval(Project project, int rowIndex, Row row, Properties bindings) { - + @Override + public Object eval( + Project project, int rowIndex, Row row, Properties bindings) { + Cell cell = row.getCell(_cellIndex); ExpressionUtils.bind(bindings, row, rowIndex, _columnName, cell); diff --git a/main/src/com/metaweb/gridworks/browsing/util/ExpressionNominalValueGrouper.java b/main/src/com/metaweb/gridworks/browsing/util/ExpressionNominalValueGrouper.java index 127249c06..abf4bfced 100644 --- a/main/src/com/metaweb/gridworks/browsing/util/ExpressionNominalValueGrouper.java +++ b/main/src/com/metaweb/gridworks/browsing/util/ExpressionNominalValueGrouper.java @@ -58,10 +58,12 @@ public class ExpressionNominalValueGrouper implements RowVisitor, RecordVisitor _cellIndex = cellIndex; } + @Override public void start(Project project) { // nothing to do } + @Override public void end(Project project) { // nothing to do } @@ -84,6 +86,7 @@ public class ExpressionNominalValueGrouper implements RowVisitor, RecordVisitor return false; } + @Override public boolean visit(Project project, Record record) { hasError = false; hasBlank = false; @@ -161,10 +164,12 @@ public class ExpressionNominalValueGrouper implements RowVisitor, RecordVisitor public RowEvaluable getChoiceCountRowEvaluable() { return new RowEvaluable() { + @Override public Object eval(Project project, int rowIndex, Row row, Properties bindings) { Object value = evalRow(project, rowIndex, row, bindings); return getChoiceValueCountMultiple(value); } + }; } diff --git a/main/src/com/metaweb/gridworks/browsing/util/ExpressionNumericValueBinner.java b/main/src/com/metaweb/gridworks/browsing/util/ExpressionNumericValueBinner.java index ccc9f4080..402427fd4 100644 --- a/main/src/com/metaweb/gridworks/browsing/util/ExpressionNumericValueBinner.java +++ b/main/src/com/metaweb/gridworks/browsing/util/ExpressionNumericValueBinner.java @@ -15,7 +15,6 @@ import com.metaweb.gridworks.model.Row; * from a given expression. */ public class ExpressionNumericValueBinner implements RowVisitor, RecordVisitor { - /* * Configuration */ @@ -45,14 +44,17 @@ public class ExpressionNumericValueBinner implements RowVisitor, RecordVisitor { bins = new int[_index.getBins().length]; } + @Override public void start(Project project) { // nothing to do } + @Override public void end(Project project) { // nothing to do } + @Override public boolean visit(Project project, int rowIndex, Row row) { resetFlags(); @@ -64,6 +66,7 @@ public class ExpressionNumericValueBinner implements RowVisitor, RecordVisitor { return false; } + @Override public boolean visit(Project project, Record record) { resetFlags(); diff --git a/main/src/com/metaweb/gridworks/browsing/util/FilteredRecordsAsFilteredRows.java b/main/src/com/metaweb/gridworks/browsing/util/FilteredRecordsAsFilteredRows.java index 9d0654c41..286a9fd97 100644 --- a/main/src/com/metaweb/gridworks/browsing/util/FilteredRecordsAsFilteredRows.java +++ b/main/src/com/metaweb/gridworks/browsing/util/FilteredRecordsAsFilteredRows.java @@ -6,14 +6,15 @@ import com.metaweb.gridworks.browsing.RowVisitor; import com.metaweb.gridworks.model.Project; public class FilteredRecordsAsFilteredRows implements FilteredRows { - final protected FilteredRecords _filteredRecords; - - public FilteredRecordsAsFilteredRows(FilteredRecords filteredRecords) { - _filteredRecords = filteredRecords; - } + + public FilteredRecordsAsFilteredRows(FilteredRecords filteredRecords) { + _filteredRecords = filteredRecords; + } + + @Override + public void accept(Project project, RowVisitor visitor) { + _filteredRecords.accept(project, new RowVisitorAsRecordVisitor(visitor)); + } - public void accept(Project project, RowVisitor visitor) { - _filteredRecords.accept(project, new RowVisitorAsRecordVisitor(visitor)); - } } diff --git a/main/src/com/metaweb/gridworks/browsing/util/RowVisitorAsRecordVisitor.java b/main/src/com/metaweb/gridworks/browsing/util/RowVisitorAsRecordVisitor.java index b9aa491c0..476f732a5 100644 --- a/main/src/com/metaweb/gridworks/browsing/util/RowVisitorAsRecordVisitor.java +++ b/main/src/com/metaweb/gridworks/browsing/util/RowVisitorAsRecordVisitor.java @@ -6,27 +6,29 @@ import com.metaweb.gridworks.model.Project; import com.metaweb.gridworks.model.Record; public class RowVisitorAsRecordVisitor implements RecordVisitor { - final protected RowVisitor _rowVisitor; - - public RowVisitorAsRecordVisitor(RowVisitor rowVisitor) { - _rowVisitor = rowVisitor; - } + + public RowVisitorAsRecordVisitor(RowVisitor rowVisitor) { + _rowVisitor = rowVisitor; + } + @Override public void start(Project project) { _rowVisitor.start(project); } + @Override public void end(Project project) { _rowVisitor.end(project); } - public boolean visit(Project project, Record record) { - for (int r = record.fromRowIndex; r < record.toRowIndex; r++) { - if (_rowVisitor.visit(project, r, project.rows.get(r))) { - return true; - } - } - return false; - } + @Override + public boolean visit(Project project, Record record) { + for (int r = record.fromRowIndex; r < record.toRowIndex; r++) { + if (_rowVisitor.visit(project, r, project.rows.get(r))) { + return true; + } + } + return false; + } } diff --git a/main/src/com/metaweb/gridworks/clustering/binning/BinningClusterer.java b/main/src/com/metaweb/gridworks/clustering/binning/BinningClusterer.java index d7fe727fe..ec30c4c76 100644 --- a/main/src/com/metaweb/gridworks/clustering/binning/BinningClusterer.java +++ b/main/src/com/metaweb/gridworks/clustering/binning/BinningClusterer.java @@ -66,10 +66,12 @@ public class BinningClusterer extends Clusterer { } } + @Override public void start(Project project) { // nothing to do } + @Override public void end(Project project) { // nothing to do } diff --git a/main/src/com/metaweb/gridworks/clustering/knn/kNNClusterer.java b/main/src/com/metaweb/gridworks/clustering/knn/kNNClusterer.java index ed7d5dc98..38432e55e 100644 --- a/main/src/com/metaweb/gridworks/clustering/knn/kNNClusterer.java +++ b/main/src/com/metaweb/gridworks/clustering/knn/kNNClusterer.java @@ -80,10 +80,12 @@ public class kNNClusterer extends Clusterer { } } + @Override public void start(Project project) { // nothing to do } + @Override public void end(Project project) { // nothing to do } @@ -129,10 +131,12 @@ public class kNNClusterer extends Clusterer { _clusterer = new NGramClusterer(_distance, _blockingNgramSize); } + @Override public void start(Project project) { // nothing to do } + @Override public void end(Project project) { // nothing to do } diff --git a/main/src/com/metaweb/gridworks/commands/row/GetRowsCommand.java b/main/src/com/metaweb/gridworks/commands/row/GetRowsCommand.java index d9af977e4..2a2bdbdcd 100644 --- a/main/src/com/metaweb/gridworks/commands/row/GetRowsCommand.java +++ b/main/src/com/metaweb/gridworks/commands/row/GetRowsCommand.java @@ -126,10 +126,12 @@ public class GetRowsCommand extends Command { this.options = options; } + @Override public void start(Project project) { // nothing to do } + @Override public void end(Project project) { // nothing to do } @@ -143,6 +145,7 @@ public class GetRowsCommand extends Command { return false; } + @Override public boolean visit(Project project, Record record) { if (total >= start && total < start + limit) { internalVisit(project, record); diff --git a/main/src/com/metaweb/gridworks/exporters/CsvExporter.java b/main/src/com/metaweb/gridworks/exporters/CsvExporter.java index 1e35da443..f001233cf 100644 --- a/main/src/com/metaweb/gridworks/exporters/CsvExporter.java +++ b/main/src/com/metaweb/gridworks/exporters/CsvExporter.java @@ -1,111 +1,115 @@ -package com.metaweb.gridworks.exporters; - -import java.io.IOException; -import java.io.OutputStream; -import java.io.Writer; -import java.util.Properties; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.metaweb.gridworks.browsing.Engine; -import com.metaweb.gridworks.browsing.FilteredRows; -import com.metaweb.gridworks.browsing.RowVisitor; -import com.metaweb.gridworks.model.Cell; -import com.metaweb.gridworks.model.Column; -import com.metaweb.gridworks.model.Project; -import com.metaweb.gridworks.model.Row; - -import au.com.bytecode.opencsv.CSVWriter; - - -public class CsvExporter implements Exporter { - - final static Logger logger = LoggerFactory.getLogger("CsvExporter"); - char separator; - - public CsvExporter() { - separator = ','; //Comma separated-value is default - } - - public CsvExporter(char separator) { - this.separator = separator; - } - - public void export(Project project, Properties options, Engine engine, OutputStream outputStream) throws IOException { - throw new RuntimeException("Not implemented"); - } - - public void export(Project project, Properties options, Engine engine, Writer writer) throws IOException { - - boolean printColumnHeader = true; - - if (options != null) { - String printColHead = options.getProperty("printColumnHeader"); - if(printColHead != null) - printColumnHeader = !printColHead.toLowerCase().equals("false"); - } - - RowVisitor visitor = new RowVisitor() { - CSVWriter csvWriter; - boolean printColumnHeader = true; - boolean isFirstRow = true; //the first row should also add the column headers - - public RowVisitor init(CSVWriter writer, boolean printColumnHeader){ - this.csvWriter = writer; - this.printColumnHeader = printColumnHeader; - return this; - } - - public boolean visit(Project project, int rowIndex, Row row) { - String[] cols = new String[project.columnModel.columns.size()]; - String[] vals = new String[row.cells.size()]; - - int i = 0; - for(Column col : project.columnModel.columns){ - int cellIndex = col.getCellIndex(); - cols[i] = col.getName(); - - Cell cell = row.cells.get(cellIndex); - if(cell != null){ - vals[i] = cell.value.toString(); - } - i++; - } - - if( printColumnHeader && isFirstRow ){ - csvWriter.writeNext(cols,false); - isFirstRow = false; //switch off flag - } - csvWriter.writeNext(vals,false); - - return false; - } - - public void start(Project project) { - // nothing to do - } - - public void end(Project project) { - try { - csvWriter.close(); - } catch (IOException e) { - logger.error("CsvExporter could not close writer : " + e.getMessage()); - } - } - - }.init(new CSVWriter(writer, separator), printColumnHeader); - - FilteredRows filteredRows = engine.getAllFilteredRows(); - filteredRows.accept(project, visitor); - } - - public String getContentType() { - return "application/x-unknown"; - } - - public boolean takeWriter() { - return true; - } - -} +package com.metaweb.gridworks.exporters; + +import java.io.IOException; +import java.io.OutputStream; +import java.io.Writer; +import java.util.Properties; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.metaweb.gridworks.browsing.Engine; +import com.metaweb.gridworks.browsing.FilteredRows; +import com.metaweb.gridworks.browsing.RowVisitor; +import com.metaweb.gridworks.model.Cell; +import com.metaweb.gridworks.model.Column; +import com.metaweb.gridworks.model.Project; +import com.metaweb.gridworks.model.Row; + +import au.com.bytecode.opencsv.CSVWriter; + + +public class CsvExporter implements Exporter{ + + final static Logger logger = LoggerFactory.getLogger("CsvExporter"); + char separator; + + public CsvExporter(){ + separator = ','; //Comma separated-value is default + } + + public CsvExporter(char separator){ + this.separator = separator; + } + + @Override + public void export(Project project, Properties options, Engine engine, OutputStream outputStream) + throws IOException { + throw new RuntimeException("Not implemented"); + } + + @Override + public void export(Project project, Properties options, Engine engine, Writer writer) throws IOException { + boolean printColumnHeader = true; + + if (options != null) { + printColumnHeader = Boolean.parseBoolean(options.getProperty("printColumnHeader")); + } + + RowVisitor visitor = new RowVisitor() { + CSVWriter csvWriter; + boolean printColumnHeader = true; + boolean isFirstRow = true; //the first row should also add the column headers + + public RowVisitor init(CSVWriter writer, boolean printColumnHeader){ + this.csvWriter = writer; + this.printColumnHeader = printColumnHeader; + return this; + } + + public boolean visit(Project project, int rowIndex, Row row) { + String[] cols = new String[project.columnModel.columns.size()]; + String[] vals = new String[row.cells.size()]; + + int i = 0; + for(Column col : project.columnModel.columns){ + int cellIndex = col.getCellIndex(); + cols[i] = col.getName(); + + Cell cell = row.cells.get(cellIndex); + if(cell != null){ + vals[i] = cell.value.toString(); + } + i++; + } + + if( printColumnHeader && isFirstRow ){ + csvWriter.writeNext(cols,false); + isFirstRow = false; //switch off flag + } + csvWriter.writeNext(vals,false); + + return false; + } + + @Override + public void start(Project project) { + // nothing to do + } + + @Override + public void end(Project project) { + try { + csvWriter.close(); + } catch (IOException e) { + logger.error("CsvExporter could not close writer : " + e.getMessage()); + } + } + + }.init(new CSVWriter(writer, separator), printColumnHeader); + + FilteredRows filteredRows = engine.getAllFilteredRows(); + filteredRows.accept(project, visitor); + } + + @Override + public String getContentType() { + return "application/x-unknown"; + } + + @Override + public boolean takeWriter() { + return true; + } + +} diff --git a/main/src/com/metaweb/gridworks/exporters/HtmlTableExporter.java b/main/src/com/metaweb/gridworks/exporters/HtmlTableExporter.java index 9ed9cd221..4926a3ccd 100644 --- a/main/src/com/metaweb/gridworks/exporters/HtmlTableExporter.java +++ b/main/src/com/metaweb/gridworks/exporters/HtmlTableExporter.java @@ -15,7 +15,6 @@ import com.metaweb.gridworks.model.Project; import com.metaweb.gridworks.model.Row; public class HtmlTableExporter implements Exporter { - public String getContentType() { return "text/html"; } @@ -57,10 +56,12 @@ public class HtmlTableExporter implements Exporter { return this; } + @Override public void start(Project project) { // nothing to do } + @Override public void end(Project project) { // nothing to do } diff --git a/main/src/com/metaweb/gridworks/exporters/XlsExporter.java b/main/src/com/metaweb/gridworks/exporters/XlsExporter.java index 04eabd728..79b9c2abf 100644 --- a/main/src/com/metaweb/gridworks/exporters/XlsExporter.java +++ b/main/src/com/metaweb/gridworks/exporters/XlsExporter.java @@ -22,7 +22,6 @@ import com.metaweb.gridworks.model.Project; import com.metaweb.gridworks.model.Row; public class XlsExporter implements Exporter { - public String getContentType() { return "application/xls"; } @@ -65,10 +64,12 @@ public class XlsExporter implements Exporter { return this; } + @Override public void start(Project project) { // nothing to do } + @Override public void end(Project project) { // nothing to do } diff --git a/main/src/com/metaweb/gridworks/expr/JythonEvaluable.java b/main/src/com/metaweb/gridworks/expr/JythonEvaluable.java index ba2d448c7..5264db879 100644 --- a/main/src/com/metaweb/gridworks/expr/JythonEvaluable.java +++ b/main/src/com/metaweb/gridworks/expr/JythonEvaluable.java @@ -15,17 +15,16 @@ import org.python.core.PyString; import org.python.util.PythonInterpreter; public class JythonEvaluable implements Evaluable { - private static final String s_functionName = "___temp___"; private static PythonInterpreter _engine; - static { File libPath = new File("webapp/WEB-INF/lib/jython"); if (libPath.exists()) { Properties props = new Properties(); props.setProperty("python.path", libPath.getAbsolutePath()); - PythonInterpreter.initialize(System.getProperties(), props, new String[] { "" }); + + PythonInterpreter.initialize(System.getProperties(),props, new String[] { "" }); } _engine = new PythonInterpreter(); } diff --git a/main/src/com/metaweb/gridworks/importers/RdfTripleImporter.java b/main/src/com/metaweb/gridworks/importers/RdfTripleImporter.java index 490e49cb1..6c58642eb 100644 --- a/main/src/com/metaweb/gridworks/importers/RdfTripleImporter.java +++ b/main/src/com/metaweb/gridworks/importers/RdfTripleImporter.java @@ -30,7 +30,6 @@ import com.metaweb.gridworks.model.Project; import com.metaweb.gridworks.model.Row; public class RdfTripleImporter implements Importer{ - JRDFFactory JrdfFactory; NTriplesParserFactory nTriplesParserFactory; MemMapFactory newMapFactory; @@ -41,6 +40,7 @@ public class RdfTripleImporter implements Importer{ newMapFactory = new MemMapFactory(); } + @Override public void read(Reader reader, Project project, Properties options) throws Exception { String baseUrl = options.getProperty("base-url"); @@ -109,11 +109,13 @@ public class RdfTripleImporter implements Importer{ } } + @Override public void read(InputStream inputStream, Project project, Properties options) throws Exception { // TODO throw new UnsupportedOperationException(); } + @Override public boolean takesReader() { return true; } diff --git a/main/src/com/metaweb/gridworks/operations/cell/MassEditOperation.java b/main/src/com/metaweb/gridworks/operations/cell/MassEditOperation.java index efeff95ce..842b54ce5 100644 --- a/main/src/com/metaweb/gridworks/operations/cell/MassEditOperation.java +++ b/main/src/com/metaweb/gridworks/operations/cell/MassEditOperation.java @@ -198,10 +198,12 @@ public class MassEditOperation extends EngineDependentMassCellOperation { return this; } + @Override public void start(Project project) { // nothing to do } + @Override public void end(Project project) { // nothing to do } diff --git a/main/src/com/metaweb/gridworks/operations/cell/TextTransformOperation.java b/main/src/com/metaweb/gridworks/operations/cell/TextTransformOperation.java index a8831f534..421535bbc 100644 --- a/main/src/com/metaweb/gridworks/operations/cell/TextTransformOperation.java +++ b/main/src/com/metaweb/gridworks/operations/cell/TextTransformOperation.java @@ -24,7 +24,6 @@ import com.metaweb.gridworks.operations.OnError; import com.metaweb.gridworks.operations.OperationRegistry; public class TextTransformOperation extends EngineDependentMassCellOperation { - final protected String _expression; final protected OnError _onError; final protected boolean _repeat; @@ -123,10 +122,12 @@ public class TextTransformOperation extends EngineDependentMassCellOperation { return this; } + @Override public void start(Project project) { // nothing to do } + @Override public void end(Project project) { // nothing to do } diff --git a/main/src/com/metaweb/gridworks/operations/column/ColumnAdditionOperation.java b/main/src/com/metaweb/gridworks/operations/column/ColumnAdditionOperation.java index 82b57c6ef..d818ea935 100644 --- a/main/src/com/metaweb/gridworks/operations/column/ColumnAdditionOperation.java +++ b/main/src/com/metaweb/gridworks/operations/column/ColumnAdditionOperation.java @@ -139,10 +139,12 @@ public class ColumnAdditionOperation extends EngineDependentOperation { return this; } + @Override public void start(Project project) { // nothing to do } + @Override public void end(Project project) { // nothing to do } diff --git a/main/src/com/metaweb/gridworks/operations/column/ColumnSplitOperation.java b/main/src/com/metaweb/gridworks/operations/column/ColumnSplitOperation.java index df140d0c6..af19ba939 100644 --- a/main/src/com/metaweb/gridworks/operations/column/ColumnSplitOperation.java +++ b/main/src/com/metaweb/gridworks/operations/column/ColumnSplitOperation.java @@ -236,10 +236,12 @@ public class ColumnSplitOperation extends EngineDependentOperation { this.tuples = tuples; } + @Override public void start(Project project) { // nothing to do } + @Override public void end(Project project) { // nothing to do } diff --git a/main/src/com/metaweb/gridworks/operations/column/ExtendDataOperation.java b/main/src/com/metaweb/gridworks/operations/column/ExtendDataOperation.java index 054aa130a..8d553b206 100644 --- a/main/src/com/metaweb/gridworks/operations/column/ExtendDataOperation.java +++ b/main/src/com/metaweb/gridworks/operations/column/ExtendDataOperation.java @@ -151,10 +151,12 @@ public class ExtendDataOperation extends EngineDependentOperation { return this; } + @Override public void start(Project project) { // nothing to do } + @Override public void end(Project project) { // nothing to do } diff --git a/main/src/com/metaweb/gridworks/operations/recon/ReconDiscardJudgmentsOperation.java b/main/src/com/metaweb/gridworks/operations/recon/ReconDiscardJudgmentsOperation.java index 83c15edd5..287ac328a 100644 --- a/main/src/com/metaweb/gridworks/operations/recon/ReconDiscardJudgmentsOperation.java +++ b/main/src/com/metaweb/gridworks/operations/recon/ReconDiscardJudgmentsOperation.java @@ -76,10 +76,12 @@ public class ReconDiscardJudgmentsOperation extends EngineDependentMassCellOpera return this; } + @Override public void start(Project project) { // nothing to do } + @Override public void end(Project project) { // nothing to do } diff --git a/main/src/com/metaweb/gridworks/operations/recon/ReconJudgeSimilarCellsOperation.java b/main/src/com/metaweb/gridworks/operations/recon/ReconJudgeSimilarCellsOperation.java index 5c9589cb1..cf76fa02c 100644 --- a/main/src/com/metaweb/gridworks/operations/recon/ReconJudgeSimilarCellsOperation.java +++ b/main/src/com/metaweb/gridworks/operations/recon/ReconJudgeSimilarCellsOperation.java @@ -164,10 +164,12 @@ public class ReconJudgeSimilarCellsOperation extends EngineDependentMassCellOper return this; } + @Override public void start(Project project) { // nothing to do } + @Override public void end(Project project) { // nothing to do } diff --git a/main/src/com/metaweb/gridworks/operations/recon/ReconMarkNewTopicsOperation.java b/main/src/com/metaweb/gridworks/operations/recon/ReconMarkNewTopicsOperation.java index bc2ce45f4..7efae9d7c 100644 --- a/main/src/com/metaweb/gridworks/operations/recon/ReconMarkNewTopicsOperation.java +++ b/main/src/com/metaweb/gridworks/operations/recon/ReconMarkNewTopicsOperation.java @@ -86,10 +86,12 @@ public class ReconMarkNewTopicsOperation extends EngineDependentMassCellOperatio return this; } + @Override public void start(Project project) { // nothing to do } + @Override public void end(Project project) { // nothing to do } diff --git a/main/src/com/metaweb/gridworks/operations/recon/ReconMatchBestCandidatesOperation.java b/main/src/com/metaweb/gridworks/operations/recon/ReconMatchBestCandidatesOperation.java index 3a71ea9b9..e72d888fd 100644 --- a/main/src/com/metaweb/gridworks/operations/recon/ReconMatchBestCandidatesOperation.java +++ b/main/src/com/metaweb/gridworks/operations/recon/ReconMatchBestCandidatesOperation.java @@ -77,10 +77,12 @@ public class ReconMatchBestCandidatesOperation extends EngineDependentMassCellOp return this; } + @Override public void start(Project project) { // nothing to do } + @Override public void end(Project project) { // nothing to do } diff --git a/main/src/com/metaweb/gridworks/operations/recon/ReconMatchSpecificTopicOperation.java b/main/src/com/metaweb/gridworks/operations/recon/ReconMatchSpecificTopicOperation.java index a67b6f5a8..50007e46a 100644 --- a/main/src/com/metaweb/gridworks/operations/recon/ReconMatchSpecificTopicOperation.java +++ b/main/src/com/metaweb/gridworks/operations/recon/ReconMatchSpecificTopicOperation.java @@ -110,10 +110,12 @@ public class ReconMatchSpecificTopicOperation extends EngineDependentMassCellOpe return this; } + @Override public void start(Project project) { // nothing to do } + @Override public void end(Project project) { // nothing to do } diff --git a/main/src/com/metaweb/gridworks/operations/recon/ReconOperation.java b/main/src/com/metaweb/gridworks/operations/recon/ReconOperation.java index 8b8823648..6964150de 100644 --- a/main/src/com/metaweb/gridworks/operations/recon/ReconOperation.java +++ b/main/src/com/metaweb/gridworks/operations/recon/ReconOperation.java @@ -178,10 +178,12 @@ public class ReconOperation extends EngineDependentOperation { FilteredRows filteredRows = engine.getAllFilteredRows(); filteredRows.accept(_project, new RowVisitor() { + @Override public void start(Project project) { // nothing to do } + @Override public void end(Project project) { // nothing to do } diff --git a/main/src/com/metaweb/gridworks/operations/row/RowFlagOperation.java b/main/src/com/metaweb/gridworks/operations/row/RowFlagOperation.java index d663708fc..53e953202 100644 --- a/main/src/com/metaweb/gridworks/operations/row/RowFlagOperation.java +++ b/main/src/com/metaweb/gridworks/operations/row/RowFlagOperation.java @@ -80,10 +80,12 @@ public class RowFlagOperation extends EngineDependentOperation { return this; } + @Override public void start(Project project) { // nothing to do } + @Override public void end(Project project) { // nothing to do } diff --git a/main/src/com/metaweb/gridworks/operations/row/RowRemovalOperation.java b/main/src/com/metaweb/gridworks/operations/row/RowRemovalOperation.java index f6f9962f8..a08aa9717 100644 --- a/main/src/com/metaweb/gridworks/operations/row/RowRemovalOperation.java +++ b/main/src/com/metaweb/gridworks/operations/row/RowRemovalOperation.java @@ -72,10 +72,12 @@ public class RowRemovalOperation extends EngineDependentOperation { return this; } + @Override public void start(Project project) { // nothing to do } + @Override public void end(Project project) { // nothing to do } diff --git a/main/src/com/metaweb/gridworks/operations/row/RowReorderOperation.java b/main/src/com/metaweb/gridworks/operations/row/RowReorderOperation.java index ff8b9453e..2244adc1d 100644 --- a/main/src/com/metaweb/gridworks/operations/row/RowReorderOperation.java +++ b/main/src/com/metaweb/gridworks/operations/row/RowReorderOperation.java @@ -101,17 +101,21 @@ public class RowReorderOperation extends AbstractOperation { _indices = indices; } + @Override public void start(Project project) { } + @Override public void end(Project project) { } + @Override public boolean visit(Project project, int rowIndex, Row row) { _indices.add(rowIndex); return false; } + @Override public boolean visit(Project project, Record record) { for (int r = record.fromRowIndex; r < record.toRowIndex; r++) { _indices.add(r); diff --git a/main/src/com/metaweb/gridworks/operations/row/RowStarOperation.java b/main/src/com/metaweb/gridworks/operations/row/RowStarOperation.java index 588e07c2f..a37db65c9 100644 --- a/main/src/com/metaweb/gridworks/operations/row/RowStarOperation.java +++ b/main/src/com/metaweb/gridworks/operations/row/RowStarOperation.java @@ -80,10 +80,12 @@ public class RowStarOperation extends EngineDependentOperation { return this; } + @Override public void start(Project project) { // nothing to do } + @Override public void end(Project project) { // nothing to do } diff --git a/main/src/com/metaweb/gridworks/protograph/transpose/MqlwriteLikeTransposedNodeFactory.java b/main/src/com/metaweb/gridworks/protograph/transpose/MqlwriteLikeTransposedNodeFactory.java index f68d8ac1f..f69aafb05 100644 --- a/main/src/com/metaweb/gridworks/protograph/transpose/MqlwriteLikeTransposedNodeFactory.java +++ b/main/src/com/metaweb/gridworks/protograph/transpose/MqlwriteLikeTransposedNodeFactory.java @@ -42,6 +42,7 @@ public class MqlwriteLikeTransposedNodeFactory implements TransposedNodeFactory return new JSONArray(rootObjects); } + @Override public void flush() throws IOException { try { JSONWriter jsonWriter = new JSONWriter(writer); diff --git a/main/src/com/metaweb/gridworks/protograph/transpose/Transposer.java b/main/src/com/metaweb/gridworks/protograph/transpose/Transposer.java index ac80da85a..1ee67144d 100644 --- a/main/src/com/metaweb/gridworks/protograph/transpose/Transposer.java +++ b/main/src/com/metaweb/gridworks/protograph/transpose/Transposer.java @@ -49,6 +49,7 @@ public class Transposer { Node rootNode; TransposedNodeFactory nodeFactory; + @Override public boolean visit(Project project, int rowIndex, Row row) { if (rootContext.limit <= 0 || rootContext.count < rootContext.limit) { descend(project, protograph, nodeFactory, row, rootNode, rootContext); @@ -60,11 +61,13 @@ public class Transposer { return false; } + @Override public void start(Project project) { // TODO Auto-generated method stub } + @Override public void end(Project project) { // TODO Auto-generated method stub diff --git a/main/src/com/metaweb/gridworks/protograph/transpose/TripleLoaderTransposedNodeFactory.java b/main/src/com/metaweb/gridworks/protograph/transpose/TripleLoaderTransposedNodeFactory.java index 2603a70ff..632510859 100644 --- a/main/src/com/metaweb/gridworks/protograph/transpose/TripleLoaderTransposedNodeFactory.java +++ b/main/src/com/metaweb/gridworks/protograph/transpose/TripleLoaderTransposedNodeFactory.java @@ -35,6 +35,7 @@ public class TripleLoaderTransposedNodeFactory implements TransposedNodeFactory this.writer = writer; } + @Override public void flush() throws IOException { if (lastRootNode != null) { lastRootNode.write(null, null, null); diff --git a/main/src/com/metaweb/gridworks/sorting/SortingRecordVisitor.java b/main/src/com/metaweb/gridworks/sorting/SortingRecordVisitor.java index 4d189ac4e..bd7da57c2 100644 --- a/main/src/com/metaweb/gridworks/sorting/SortingRecordVisitor.java +++ b/main/src/com/metaweb/gridworks/sorting/SortingRecordVisitor.java @@ -11,20 +11,21 @@ import com.metaweb.gridworks.model.Record; import com.metaweb.gridworks.sorting.Criterion.KeyMaker; public class SortingRecordVisitor extends BaseSorter implements RecordVisitor { - - final protected RecordVisitor _visitor; + final protected RecordVisitor _visitor; protected List _records; public SortingRecordVisitor(RecordVisitor visitor) { _visitor = visitor; } + @Override public void start(Project project) { int count = project.recordModel.getRecordCount(); _records = new ArrayList(count); _keys = new ArrayList(count); } + @Override public void end(Project project) { _visitor.start(project); @@ -36,6 +37,7 @@ public class SortingRecordVisitor extends BaseSorter implements RecordVisitor { return this; } + @Override public int compare(Record o1, Record o2) { return SortingRecordVisitor.this.compare(project, o1, o1.recordIndex, o2, o2.recordIndex); } @@ -48,12 +50,16 @@ public class SortingRecordVisitor extends BaseSorter implements RecordVisitor { _visitor.end(project); } + @Override public boolean visit(Project project, Record record) { _records.add(record); return false; } - protected Object makeKey(Project project, KeyMaker keyMaker, Criterion c, Object o, int index) { + @Override + protected Object makeKey( + Project project, KeyMaker keyMaker, Criterion c, Object o, int index) { + return keyMaker.makeKey(project, (Record) o); } } diff --git a/main/src/com/metaweb/gridworks/sorting/SortingRowVisitor.java b/main/src/com/metaweb/gridworks/sorting/SortingRowVisitor.java index fd8f13d5a..e6019126a 100644 --- a/main/src/com/metaweb/gridworks/sorting/SortingRowVisitor.java +++ b/main/src/com/metaweb/gridworks/sorting/SortingRowVisitor.java @@ -11,8 +11,7 @@ import com.metaweb.gridworks.model.Row; import com.metaweb.gridworks.sorting.Criterion.KeyMaker; public class SortingRowVisitor extends BaseSorter implements RowVisitor { - - final protected RowVisitor _visitor; + final protected RowVisitor _visitor; protected List _indexedRows; static protected class IndexedRow { @@ -29,12 +28,14 @@ public class SortingRowVisitor extends BaseSorter implements RowVisitor { _visitor = visitor; } + @Override public void start(Project project) { int count = project.rows.size(); _indexedRows = new ArrayList(count); _keys = new ArrayList(count); } + @Override public void end(Project project) { _visitor.start(project); @@ -46,6 +47,7 @@ public class SortingRowVisitor extends BaseSorter implements RowVisitor { return this; } + @Override public int compare(IndexedRow o1, IndexedRow o2) { return SortingRowVisitor.this.compare(project, o1.row, o1.index, o2.row, o2.index); } @@ -58,12 +60,16 @@ public class SortingRowVisitor extends BaseSorter implements RowVisitor { _visitor.end(project); } + @Override public boolean visit(Project project, int rowIndex, Row row) { _indexedRows.add(new IndexedRow(rowIndex, row)); return false; } - protected Object makeKey(Project project, KeyMaker keyMaker, Criterion c, Object o, int index) { + @Override + protected Object makeKey( + Project project, KeyMaker keyMaker, Criterion c, Object o, int index) { + return keyMaker.makeKey(project, (Row) o, index); } } diff --git a/main/src/com/metaweb/gridworks/templating/Template.java b/main/src/com/metaweb/gridworks/templating/Template.java index 1210fe78f..988d43a4f 100644 --- a/main/src/com/metaweb/gridworks/templating/Template.java +++ b/main/src/com/metaweb/gridworks/templating/Template.java @@ -60,6 +60,7 @@ public class Template { this.writer = writer; } + @Override public void start(Project project) { bindings = ExpressionUtils.createBindings(project); @@ -72,6 +73,7 @@ public class Template { } } + @Override public void end(Project project) { try { if (_suffix != null) { @@ -91,6 +93,7 @@ public class Template { return limit > 0 && total >= limit; } + @Override public boolean visit(Project project, Record record) { if (limit <= 0 || total < limit) { internalVisit(project, record); diff --git a/main/tests/server/src/com/metaweb/gridworks/tests/importers/RdfTripleImporterTests.java b/main/tests/server/src/com/metaweb/gridworks/tests/importers/RdfTripleImporterTests.java index 694521e80..91a4f5059 100644 --- a/main/tests/server/src/com/metaweb/gridworks/tests/importers/RdfTripleImporterTests.java +++ b/main/tests/server/src/com/metaweb/gridworks/tests/importers/RdfTripleImporterTests.java @@ -1,153 +1,153 @@ -package com.metaweb.gridworks.tests.importers; - -import java.io.StringReader; -import java.util.Properties; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.testng.Assert; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; - -import com.metaweb.gridworks.importers.RdfTripleImporter; -import com.metaweb.gridworks.model.Project; - - -public class RdfTripleImporterTests { - // logging - final static protected Logger logger = LoggerFactory.getLogger("RdfImporterTests"); - - //System Under Test - RdfTripleImporter SUT = null; - Project project = null; - Properties options = null; - - @BeforeMethod - public void SetUp(){ - SUT = new RdfTripleImporter(); - project = new Project(); - options = new Properties(); - options.put("base-url", "http://rdf.freebase.com"); - } - - @Test(enabled=false) - public void CanParseSingleLineTriple(){ - String sampleRdf = " ."; - StringReader reader = new StringReader(sampleRdf); - - try { - SUT.read(reader, project, options); - project.update(); - } catch (Exception e) { - Assert.fail(); - } - - Assert.assertEquals(project.columnModel.columns.size(), 2); - Assert.assertEquals(project.columnModel.columns.get(0).getName(), "subject"); - Assert.assertEquals(project.columnModel.columns.get(1).getName(), "http://rdf.freebase.com/ns/music.artist.album"); - Assert.assertEquals(project.rows.size(), 1); - Assert.assertEquals(project.rows.get(0).cells.size(), 2); - Assert.assertEquals(project.rows.get(0).cells.get(0).value, "http://rdf.freebase.com/ns/en.bob_dylan"); - Assert.assertEquals(project.rows.get(0).cells.get(1).value, "http://rdf.freebase.com/ns/en.blood_on_the_tracks"); - } - - @Test - public void CanParseMultiLineTriple(){ - String sampleRdf = " .\n" + - " .\n" + - " ."; - StringReader reader = new StringReader(sampleRdf); - - try { - SUT.read(reader, project, options); - project.update(); - } catch (Exception e) { - Assert.fail(); - } - - //columns - Assert.assertEquals(project.columnModel.columns.size(), 2); - Assert.assertEquals(project.columnModel.columns.get(0).getName(), "subject"); - Assert.assertEquals(project.columnModel.columns.get(1).getName(), "http://rdf.freebase.com/ns/music.artist.album"); - - //rows - Assert.assertEquals(project.rows.size(), 3); - - //row0 - Assert.assertEquals(project.rows.get(0).cells.size(), 2); - Assert.assertEquals(project.rows.get(0).cells.get(0).value, "http://rdf.freebase.com/ns/en.bob_dylan"); - Assert.assertEquals(project.rows.get(0).cells.get(1).value, "http://rdf.freebase.com/ns/en.blood_on_the_tracks"); - - //row1 - Assert.assertEquals(project.rows.get(1).cells.size(), 2); - Assert.assertNull(project.rows.get(1).cells.get(0)); - Assert.assertEquals(project.rows.get(1).cells.get(1).value, "http://rdf.freebase.com/ns/en.bringing_it_all_back_home"); //NB triples aren't created in order they were input - Assert.assertEquals(project.recordModel.getRowDependency(1).cellDependencies[1].rowIndex, 0); - Assert.assertEquals(project.recordModel.getRowDependency(1).cellDependencies[1].cellIndex, 0); - - //row2 - Assert.assertEquals(project.rows.get(2).cells.size(), 2); - Assert.assertNull(project.rows.get(2).cells.get(0)); - Assert.assertEquals(project.rows.get(2).cells.get(1).value, "http://rdf.freebase.com/ns/en.under_the_red_sky"); //NB triples aren't created in order they were input - Assert.assertEquals(project.recordModel.getRowDependency(2).cellDependencies[1].rowIndex, 0); - Assert.assertEquals(project.recordModel.getRowDependency(2).cellDependencies[1].cellIndex, 0); - } - - @Test - public void CanParseMultiLineMultiPredicatesTriple(){ - String sampleRdf = " .\n" + - " .\n" + - " ."; - StringReader reader = new StringReader(sampleRdf); - - try { - SUT.read(reader, project, options); - project.update(); - } catch (Exception e) { - Assert.fail(); - } - - //columns - Assert.assertEquals(project.columnModel.columns.size(), 3); - Assert.assertEquals(project.columnModel.columns.get(0).getName(), "subject"); - Assert.assertEquals(project.columnModel.columns.get(1).getName(), "http://rdf.freebase.com/ns/music.artist.album"); - Assert.assertEquals(project.columnModel.columns.get(2).getName(), "http://rdf.freebase.com/ns/music.artist.genre"); - - //rows - Assert.assertEquals(project.rows.size(), 2); - - //row0 - Assert.assertEquals(project.rows.get(0).cells.size(), 3); - Assert.assertEquals(project.rows.get(0).cells.get(0).value, "http://rdf.freebase.com/ns/en.bob_dylan"); - Assert.assertEquals(project.rows.get(0).cells.get(1).value, "http://rdf.freebase.com/ns/en.blood_on_the_tracks"); - Assert.assertEquals(project.rows.get(0).cells.get(2).value, "http://rdf.freebase.com/ns/en.folk_rock"); - - //row1 - Assert.assertEquals(project.rows.get(1).cells.size(), 2); - Assert.assertNull(project.rows.get(1).cells.get(0)); - Assert.assertEquals(project.rows.get(1).cells.get(1).value, "http://rdf.freebase.com/ns/en.bringing_it_all_back_home"); - Assert.assertEquals(project.recordModel.getRowDependency(1).cellDependencies[1].rowIndex, 0); - Assert.assertEquals(project.recordModel.getRowDependency(1).cellDependencies[1].cellIndex, 0); - } - - @Test - public void CanParseTripleWithValue(){ - String sampleRdf = " \"Robert Zimmerman\"@en."; - StringReader reader = new StringReader(sampleRdf); - - try { - SUT.read(reader, project, options); - project.update(); - } catch (Exception e) { - Assert.fail(); - } - - Assert.assertEquals(project.columnModel.columns.size(), 2); - Assert.assertEquals(project.columnModel.columns.get(0).getName(), "subject"); - Assert.assertEquals(project.columnModel.columns.get(1).getName(), "http://rdf.freebase.com/ns/common.topic.alias"); - Assert.assertEquals(project.rows.size(), 1); - Assert.assertEquals(project.rows.get(0).cells.size(), 2); - Assert.assertEquals(project.rows.get(0).cells.get(0).value, "http://rdf.freebase.com/ns/en.bob_dylan"); - Assert.assertEquals(project.rows.get(0).cells.get(1).value, "\"Robert Zimmerman\"@en"); - } -} +package com.metaweb.gridworks.tests.importers; + +import java.io.StringReader; +import java.util.Properties; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.testng.Assert; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +import com.metaweb.gridworks.importers.RdfTripleImporter; +import com.metaweb.gridworks.model.Project; + + +public class RdfTripleImporterTests { + // logging + final static protected Logger logger = LoggerFactory.getLogger("RdfImporterTests"); + + //System Under Test + RdfTripleImporter SUT = null; + Project project = null; + Properties options = null; + + @BeforeMethod + public void SetUp(){ + SUT = new RdfTripleImporter(); + project = new Project(); + options = new Properties(); + options.put("base-url", "http://rdf.freebase.com"); + } + + @Test(enabled=false) + public void CanParseSingleLineTriple(){ + String sampleRdf = " ."; + StringReader reader = new StringReader(sampleRdf); + + try { + SUT.read(reader, project, options); + project.update(); + } catch (Exception e) { + Assert.fail(); + } + + Assert.assertEquals(project.columnModel.columns.size(), 2); + Assert.assertEquals(project.columnModel.columns.get(0).getName(), "subject"); + Assert.assertEquals(project.columnModel.columns.get(1).getName(), "http://rdf.freebase.com/ns/music.artist.album"); + Assert.assertEquals(project.rows.size(), 1); + Assert.assertEquals(project.rows.get(0).cells.size(), 2); + Assert.assertEquals(project.rows.get(0).cells.get(0).value, "http://rdf.freebase.com/ns/en.bob_dylan"); + Assert.assertEquals(project.rows.get(0).cells.get(1).value, "http://rdf.freebase.com/ns/en.blood_on_the_tracks"); + } + + @Test + public void CanParseMultiLineTriple(){ + String sampleRdf = " .\n" + + " .\n" + + " ."; + StringReader reader = new StringReader(sampleRdf); + + try { + SUT.read(reader, project, options); + project.update(); + } catch (Exception e) { + Assert.fail(); + } + + //columns + Assert.assertEquals(project.columnModel.columns.size(), 2); + Assert.assertEquals(project.columnModel.columns.get(0).getName(), "subject"); + Assert.assertEquals(project.columnModel.columns.get(1).getName(), "http://rdf.freebase.com/ns/music.artist.album"); + + //rows + Assert.assertEquals(project.rows.size(), 3); + + //row0 + Assert.assertEquals(project.rows.get(0).cells.size(), 2); + Assert.assertEquals(project.rows.get(0).cells.get(0).value, "http://rdf.freebase.com/ns/en.bob_dylan"); + Assert.assertEquals(project.rows.get(0).cells.get(1).value, "http://rdf.freebase.com/ns/en.blood_on_the_tracks"); + + //row1 + Assert.assertEquals(project.rows.get(1).cells.size(), 2); + Assert.assertNull(project.rows.get(1).cells.get(0)); + Assert.assertEquals(project.rows.get(1).cells.get(1).value, "http://rdf.freebase.com/ns/en.bringing_it_all_back_home"); //NB triples aren't created in order they were input + Assert.assertEquals(project.recordModel.getRowDependency(1).cellDependencies[1].rowIndex, 0); + Assert.assertEquals(project.recordModel.getRowDependency(1).cellDependencies[1].cellIndex, 0); + + //row2 + Assert.assertEquals(project.rows.get(2).cells.size(), 2); + Assert.assertNull(project.rows.get(2).cells.get(0)); + Assert.assertEquals(project.rows.get(2).cells.get(1).value, "http://rdf.freebase.com/ns/en.under_the_red_sky"); //NB triples aren't created in order they were input + Assert.assertEquals(project.recordModel.getRowDependency(2).cellDependencies[1].rowIndex, 0); + Assert.assertEquals(project.recordModel.getRowDependency(2).cellDependencies[1].cellIndex, 0); + } + + @Test + public void CanParseMultiLineMultiPredicatesTriple(){ + String sampleRdf = " .\n" + + " .\n" + + " ."; + StringReader reader = new StringReader(sampleRdf); + + try { + SUT.read(reader, project, options); + project.update(); + } catch (Exception e) { + Assert.fail(); + } + + //columns + Assert.assertEquals(project.columnModel.columns.size(), 3); + Assert.assertEquals(project.columnModel.columns.get(0).getName(), "subject"); + Assert.assertEquals(project.columnModel.columns.get(1).getName(), "http://rdf.freebase.com/ns/music.artist.album"); + Assert.assertEquals(project.columnModel.columns.get(2).getName(), "http://rdf.freebase.com/ns/music.artist.genre"); + + //rows + Assert.assertEquals(project.rows.size(), 2); + + //row0 + Assert.assertEquals(project.rows.get(0).cells.size(), 3); + Assert.assertEquals(project.rows.get(0).cells.get(0).value, "http://rdf.freebase.com/ns/en.bob_dylan"); + Assert.assertEquals(project.rows.get(0).cells.get(1).value, "http://rdf.freebase.com/ns/en.blood_on_the_tracks"); + Assert.assertEquals(project.rows.get(0).cells.get(2).value, "http://rdf.freebase.com/ns/en.folk_rock"); + + //row1 + Assert.assertEquals(project.rows.get(1).cells.size(), 2); + Assert.assertNull(project.rows.get(1).cells.get(0)); + Assert.assertEquals(project.rows.get(1).cells.get(1).value, "http://rdf.freebase.com/ns/en.bringing_it_all_back_home"); + Assert.assertEquals(project.recordModel.getRowDependency(1).cellDependencies[1].rowIndex, 0); + Assert.assertEquals(project.recordModel.getRowDependency(1).cellDependencies[1].cellIndex, 0); + } + + @Test + public void CanParseTripleWithValue(){ + String sampleRdf = " \"Robert Zimmerman\"@en."; + StringReader reader = new StringReader(sampleRdf); + + try { + SUT.read(reader, project, options); + project.update(); + } catch (Exception e) { + Assert.fail(); + } + + Assert.assertEquals(project.columnModel.columns.size(), 2); + Assert.assertEquals(project.columnModel.columns.get(0).getName(), "subject"); + Assert.assertEquals(project.columnModel.columns.get(1).getName(), "http://rdf.freebase.com/ns/common.topic.alias"); + Assert.assertEquals(project.rows.size(), 1); + Assert.assertEquals(project.rows.get(0).cells.size(), 2); + Assert.assertEquals(project.rows.get(0).cells.get(0).value, "http://rdf.freebase.com/ns/en.bob_dylan"); + Assert.assertEquals(project.rows.get(0).cells.get(1).value, "\"Robert Zimmerman\"@en"); + } +} diff --git a/main/tests/server/src/com/metaweb/gridworks/tests/importers/TestTools.java b/main/tests/server/src/com/metaweb/gridworks/tests/importers/TestTools.java index c1148623a..68fb8321a 100644 --- a/main/tests/server/src/com/metaweb/gridworks/tests/importers/TestTools.java +++ b/main/tests/server/src/com/metaweb/gridworks/tests/importers/TestTools.java @@ -1,50 +1,50 @@ -package com.metaweb.gridworks.tests.importers; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.testng.Assert; - -import com.metaweb.gridworks.model.Cell; -import com.metaweb.gridworks.model.Column; -import com.metaweb.gridworks.model.Project; -import com.metaweb.gridworks.model.Row; - -/** - * Helper methods for Importer testing - * - */ -public class TestTools { - final static Logger logger = LoggerFactory.getLogger("Common"); - - public static void AssertGridCreated(Project project, int numCols, int numRows){ - Assert.assertNotNull(project); - Assert.assertNotNull(project.columnModel); - Assert.assertNotNull(project.columnModel.columns); - Assert.assertEquals(project.columnModel.columns.size(), numCols); - Assert.assertNotNull(project.rows); - Assert.assertEquals(project.rows.size(), numRows); - } - - public static void PrintProject(Project project){ - //some quick and dirty debugging - StringBuilder sb = new StringBuilder(); - for(Column c : project.columnModel.columns){ - sb.append(c.getName()); - sb.append("; "); - } - logger.info(sb.toString()); - for(Row r : project.rows){ - sb = new StringBuilder(); - for(int i = 0; i < r.cells.size(); i++){ - Cell c = r.getCell(i); - if(c != null){ - sb.append(c.value); - sb.append("; "); - }else{ - sb.append("null; "); - } - } - logger.info(sb.toString()); - } - } -} +package com.metaweb.gridworks.tests.importers; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.testng.Assert; + +import com.metaweb.gridworks.model.Cell; +import com.metaweb.gridworks.model.Column; +import com.metaweb.gridworks.model.Project; +import com.metaweb.gridworks.model.Row; + +/** + * Helper methods for Importer testing + * + */ +public class TestTools { + final static Logger logger = LoggerFactory.getLogger("Common"); + + public static void AssertGridCreated(Project project, int numCols, int numRows){ + Assert.assertNotNull(project); + Assert.assertNotNull(project.columnModel); + Assert.assertNotNull(project.columnModel.columns); + Assert.assertEquals(project.columnModel.columns.size(), numCols); + Assert.assertNotNull(project.rows); + Assert.assertEquals(project.rows.size(), numRows); + } + + public static void PrintProject(Project project){ + //some quick and dirty debugging + StringBuilder sb = new StringBuilder(); + for(Column c : project.columnModel.columns){ + sb.append(c.getName()); + sb.append("; "); + } + logger.info(sb.toString()); + for(Row r : project.rows){ + sb = new StringBuilder(); + for(int i = 0; i < r.cells.size(); i++){ + Cell c = r.getCell(i); + if(c != null){ + sb.append(c.value); + sb.append("; "); + }else{ + sb.append("null; "); + } + } + logger.info(sb.toString()); + } + } +} diff --git a/main/tests/server/src/com/metaweb/gridworks/tests/importers/XmlImportUtilitiesStub.java b/main/tests/server/src/com/metaweb/gridworks/tests/importers/XmlImportUtilitiesStub.java index ed0943dab..a35cdb6e7 100644 --- a/main/tests/server/src/com/metaweb/gridworks/tests/importers/XmlImportUtilitiesStub.java +++ b/main/tests/server/src/com/metaweb/gridworks/tests/importers/XmlImportUtilitiesStub.java @@ -1,32 +1,32 @@ -package com.metaweb.gridworks.tests.importers; - -import java.util.List; - -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.XMLStreamReader; - -import com.metaweb.gridworks.importers.XmlImportUtilities; -import com.metaweb.gridworks.model.Project; - - -public class XmlImportUtilitiesStub extends XmlImportUtilities{ - public List detectRecordElementWrapper(XMLStreamReader parser, String tag) throws XMLStreamException{ - return super.detectRecordElement(parser, tag); - } - - public void ProcessSubRecordWrapper(Project project, XMLStreamReader parser, ImportColumnGroup columnGroup, ImportRecord record) throws XMLStreamException{ - super.processSubRecord(project, parser, columnGroup, record); - } - - public void findRecordWrapper(Project project, XMLStreamReader parser, String[] recordPath, int pathIndex, ImportColumnGroup rootColumnGroup) throws XMLStreamException{ - super.findRecord(project, parser, recordPath, pathIndex, rootColumnGroup); - } - - public void processRecordWrapper(Project project, XMLStreamReader parser, ImportColumnGroup rootColumnGroup) throws XMLStreamException{ - super.processRecord(project, parser, rootColumnGroup); - } - - public void addCellWrapper(Project project, ImportColumnGroup columnGroup, ImportRecord record, String columnLocalName, String text, int commonStartingRowIndex){ - super.addCell(project, columnGroup, record, columnLocalName, text, commonStartingRowIndex); - } -} +package com.metaweb.gridworks.tests.importers; + +import java.util.List; + +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; + +import com.metaweb.gridworks.importers.XmlImportUtilities; +import com.metaweb.gridworks.model.Project; + + +public class XmlImportUtilitiesStub extends XmlImportUtilities{ + public List detectRecordElementWrapper(XMLStreamReader parser, String tag) throws XMLStreamException{ + return super.detectRecordElement(parser, tag); + } + + public void ProcessSubRecordWrapper(Project project, XMLStreamReader parser, ImportColumnGroup columnGroup, ImportRecord record) throws XMLStreamException{ + super.processSubRecord(project, parser, columnGroup, record); + } + + public void findRecordWrapper(Project project, XMLStreamReader parser, String[] recordPath, int pathIndex, ImportColumnGroup rootColumnGroup) throws XMLStreamException{ + super.findRecord(project, parser, recordPath, pathIndex, rootColumnGroup); + } + + public void processRecordWrapper(Project project, XMLStreamReader parser, ImportColumnGroup rootColumnGroup) throws XMLStreamException{ + super.processRecord(project, parser, rootColumnGroup); + } + + public void addCellWrapper(Project project, ImportColumnGroup columnGroup, ImportRecord record, String columnLocalName, String text, int commonStartingRowIndex){ + super.addCell(project, columnGroup, record, columnLocalName, text, commonStartingRowIndex); + } +} diff --git a/main/tests/server/src/com/metaweb/gridworks/tests/importers/XmlImportUtilitiesTests.java b/main/tests/server/src/com/metaweb/gridworks/tests/importers/XmlImportUtilitiesTests.java index a5b8a9176..c21c94314 100644 --- a/main/tests/server/src/com/metaweb/gridworks/tests/importers/XmlImportUtilitiesTests.java +++ b/main/tests/server/src/com/metaweb/gridworks/tests/importers/XmlImportUtilitiesTests.java @@ -1,336 +1,336 @@ -package com.metaweb.gridworks.tests.importers; - -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.UnsupportedEncodingException; -import java.util.ArrayList; -import java.util.List; - -import javax.xml.stream.FactoryConfigurationError; -import javax.xml.stream.XMLInputFactory; -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.XMLStreamReader; - -import org.apache.log4j.Level; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.testng.Assert; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; - -import com.metaweb.gridworks.importers.XmlImportUtilities.ImportColumn; -import com.metaweb.gridworks.importers.XmlImportUtilities.ImportColumnGroup; -import com.metaweb.gridworks.importers.XmlImportUtilities.ImportRecord; -import com.metaweb.gridworks.model.Project; -import com.metaweb.gridworks.model.Row; - - -public class XmlImportUtilitiesTests { - final static Logger logger = LoggerFactory.getLogger("XmlImporterUtilitiesTests"); - - //dependencies - Project project; - XMLStreamReader parser; - ImportColumnGroup columnGroup; - ImportRecord record; - ByteArrayInputStream inputStream; - - //System Under Test - XmlImportUtilitiesStub SUT; - - @BeforeMethod - public void SetUp(){ - org.apache.log4j.Logger.getRootLogger().setLevel(Level.toLevel("trace")); - SUT = new XmlImportUtilitiesStub(); - project = new Project(); - columnGroup = new ImportColumnGroup(); - record = new ImportRecord(); - } - - @AfterMethod - public void TearDown() throws IOException{ - SUT = null; - project = null; - parser = null; - columnGroup = null; - record = null; - if(inputStream != null) - inputStream.close(); - inputStream = null; - } - - @Test - public void detectPathFromTagTest(){ - loadXml("author1genre1"); - String tag = "library"; - - String[] response = XmlImportUtilitiesStub.detectPathFromTag(inputStream, tag); - Assert.assertNotNull(response); - Assert.assertEquals(response.length, 1); - Assert.assertEquals(response[0], "library"); - } - - @Test - public void detectPathFromTagWithNestedElement(){ - loadXml("author1genre1"); - String tag = "book"; - String[] response = XmlImportUtilitiesStub.detectPathFromTag(inputStream, tag); - Assert.assertNotNull(response); - Assert.assertEquals(response.length, 2); - Assert.assertEquals(response[0], "library"); - Assert.assertEquals(response[1], "book"); - } - - @Test - public void detectRecordElementTest(){ - loadXml("author1genre1"); - createParser(); - String tag="library"; - - List response = new ArrayList(); - try { - response = SUT.detectRecordElementWrapper(parser, tag); - } catch (XMLStreamException e) { - Assert.fail(); - } - Assert.assertNotNull(response); - Assert.assertEquals(response.size(), 1); - Assert.assertEquals(response.get(0), "library"); - } - - @Test - public void detectRecordElementCanHandleWithNestedElements(){ - loadXml("author1genre1"); - createParser(); - String tag="book"; - - List response = new ArrayList(); - try { - response = SUT.detectRecordElementWrapper(parser, tag); - } catch (XMLStreamException e) { - Assert.fail(); - } - Assert.assertNotNull(response); - Assert.assertEquals(response.size(), 2); - Assert.assertEquals(response.get(0), "library"); - Assert.assertEquals(response.get(1), "book"); - } - - @Test - public void detectRecordElementIsNullForUnfoundTag(){ - loadXml("author1genre1"); - createParser(); - String tag=""; - - List response = new ArrayList(); - try { - response = SUT.detectRecordElementWrapper(parser, tag); - } catch (XMLStreamException e) { - Assert.fail(); - } - Assert.assertNull(response); - } - - @Test - public void detectRecordElementRegressionTest(){ - loadSampleXml(); - - String[] path = XmlImportUtilitiesStub.detectRecordElement(inputStream); - Assert.assertNotNull(path); - Assert.assertEquals(path.length, 2); - Assert.assertEquals(path[0], "library"); - Assert.assertEquals(path[1], "book"); - } - - @Test - public void importXmlTest(){ - loadSampleXml(); - - String[] recordPath = new String[]{"library","book"}; - XmlImportUtilitiesStub.importXml(inputStream, project, recordPath, columnGroup ); - - TestTools.PrintProject(project); - TestTools.AssertGridCreated(project, 0, 6); - Assert.assertEquals(project.rows.get(0).cells.size(), 4); - //TODO - } - - @Test - public void createColumnsFromImportTest(){ - - ImportColumnGroup columnGroup = new ImportColumnGroup(); - ImportColumn ic1 = new ImportColumn(); - ic1.name = "hello"; - ImportColumn ic2 = new ImportColumn(); - ic2.name = "world"; - ImportColumnGroup subGroup = new ImportColumnGroup(); - ImportColumn ic3 = new ImportColumn(); - ic3.name = "foo"; - ImportColumn ic4 = new ImportColumn(); - ic4.name = "bar"; - subGroup.columns.put("c", ic3); - subGroup.columns.put("d", ic4); - columnGroup.columns.put("a", ic1); - columnGroup.columns.put("b", ic2); - columnGroup.subgroups.put("e", subGroup); - XmlImportUtilitiesStub.createColumnsFromImport(project, columnGroup); - TestTools.PrintProject(project); - TestTools.AssertGridCreated(project, 4, 0); - Assert.assertEquals(project.columnModel.columns.get(0).getName(), "world"); - Assert.assertEquals(project.columnModel.columns.get(1).getName(), "hello"); - Assert.assertEquals(project.columnModel.columns.get(2).getName(), "bar"); - Assert.assertEquals(project.columnModel.columns.get(3).getName(), "foo"); - Assert.assertEquals(project.columnModel.columnGroups.get(0).keyColumnIndex, 2); - Assert.assertEquals(project.columnModel.columnGroups.get(0).startColumnIndex, 2); - Assert.assertEquals(project.columnModel.columnGroups.get(0).columnSpan, 2); - } - - @Test - public void findRecordTest(){ - loadSampleXml(); - createParser(); - ParserSkip(); - - String[] recordPath = new String[]{"library","book"}; - int pathIndex = 0; - - try { - SUT.findRecordWrapper(project, parser, recordPath, pathIndex, columnGroup); - } catch (XMLStreamException e) { - Assert.fail(); - } - - TestTools.PrintProject(project); - TestTools.AssertGridCreated(project, 0, 6); - Assert.assertEquals(project.rows.get(0).cells.size(), 4); - //TODO - } - - @Test - public void processRecordTest(){ - loadXml("author1genre1"); - createParser(); - ParserSkip(); - - try { - SUT.processRecordWrapper(project, parser, columnGroup); - } catch (XMLStreamException e) { - Assert.fail(); - } - TestTools.PrintProject(project); - Assert.assertNotNull(project.rows); - Assert.assertEquals(project.rows.size(), 1); - Row row = project.rows.get(0); - Assert.assertNotNull(row); - Assert.assertNotNull(row.getCell(1)); - Assert.assertEquals(row.getCell(1).value, "author1"); - - } - - @Test - public void processRecordTestDuplicateColumns(){ - loadXml("author1author2genre1"); - createParser(); - ParserSkip(); - - try { - SUT.processRecordWrapper(project, parser, columnGroup); - } catch (XMLStreamException e) { - Assert.fail(); - } - TestTools.PrintProject(project); - Assert.assertNotNull(project.rows); - Assert.assertEquals(project.rows.size(), 2); - Row row = project.rows.get(0); - Assert.assertNotNull(row); - Assert.assertEquals(row.cells.size(), 3); - Assert.assertNotNull(row.getCell(1)); - Assert.assertEquals(row.getCell(1).value, "author1"); - row = project.rows.get(1); - Assert.assertEquals(row.getCell(1).value, "author2"); - } - - @Test - public void processRecordTestNestedElement(){ - loadXml("author1a dategenre1"); - createParser(); - ParserSkip(); - - try { - SUT.processRecordWrapper(project, parser, columnGroup); - } catch (XMLStreamException e) { - Assert.fail(); - } - TestTools.PrintProject(project); - Assert.assertNotNull(project.rows); - Assert.assertEquals(project.rows.size(), 1); - Row row = project.rows.get(0); - Assert.assertNotNull(row); - Assert.assertEquals(row.cells.size(), 4); - Assert.assertNotNull(row.getCell(1)); - Assert.assertEquals(row.getCell(1).value, "author1"); - Assert.assertNotNull(row.getCell(2)); - Assert.assertEquals(row.getCell(2).value, "a date"); - } - - - @Test(groups={"broken"}) - public void processSubRecordTest(){ - loadXml("author1genre1"); - createParser(); - ParserSkip(); - - try { - SUT.ProcessSubRecordWrapper(project, parser, columnGroup, record); - } catch (XMLStreamException e) { - Assert.fail(); - } - TestTools.PrintProject(project); - Assert.fail(); - //TODO need to verify 'record' was set correctly which we can't do as ImportRecord is an internal class - } - - @Test(groups={"broken"}) - public void addCellTest(){ - String columnLocalName = "author"; - String text = "Author1, The"; - int commonStartingRowIndex = 0; - project.rows.add(new Row(0)); - SUT.addCellWrapper(project, columnGroup, record, columnLocalName, text, commonStartingRowIndex); - - Assert.fail(); - //TODO need to verify 'record' was set correctly which we can't do as ImportRecord is an internal class - } - - //----------------helpers------------- - public void loadSampleXml(){ - loadXml( XmlImporterTests.getSample() ); - } - - public void loadXml(String xml){ - try { - inputStream = new ByteArrayInputStream( xml.getBytes( "UTF-8" ) ); - } catch (UnsupportedEncodingException e1) { - Assert.fail(); - } - } - - public void ParserSkip(){ - try { - parser.next(); //move parser forward once e.g. skip the START_DOCUMENT parser event - } catch (XMLStreamException e1) { - Assert.fail(); - } - } - - public void createParser(){ - try { - parser = XMLInputFactory.newInstance().createXMLStreamReader(inputStream); - } catch (XMLStreamException e1) { - Assert.fail(); - } catch (FactoryConfigurationError e1) { - Assert.fail(); - } - } -} +package com.metaweb.gridworks.tests.importers; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.util.ArrayList; +import java.util.List; + +import javax.xml.stream.FactoryConfigurationError; +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; + +import org.apache.log4j.Level; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.testng.Assert; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +import com.metaweb.gridworks.importers.XmlImportUtilities.ImportColumn; +import com.metaweb.gridworks.importers.XmlImportUtilities.ImportColumnGroup; +import com.metaweb.gridworks.importers.XmlImportUtilities.ImportRecord; +import com.metaweb.gridworks.model.Project; +import com.metaweb.gridworks.model.Row; + + +public class XmlImportUtilitiesTests { + final static Logger logger = LoggerFactory.getLogger("XmlImporterUtilitiesTests"); + + //dependencies + Project project; + XMLStreamReader parser; + ImportColumnGroup columnGroup; + ImportRecord record; + ByteArrayInputStream inputStream; + + //System Under Test + XmlImportUtilitiesStub SUT; + + @BeforeMethod + public void SetUp(){ + org.apache.log4j.Logger.getRootLogger().setLevel(Level.toLevel("trace")); + SUT = new XmlImportUtilitiesStub(); + project = new Project(); + columnGroup = new ImportColumnGroup(); + record = new ImportRecord(); + } + + @AfterMethod + public void TearDown() throws IOException{ + SUT = null; + project = null; + parser = null; + columnGroup = null; + record = null; + if(inputStream != null) + inputStream.close(); + inputStream = null; + } + + @Test + public void detectPathFromTagTest(){ + loadXml("author1genre1"); + String tag = "library"; + + String[] response = XmlImportUtilitiesStub.detectPathFromTag(inputStream, tag); + Assert.assertNotNull(response); + Assert.assertEquals(response.length, 1); + Assert.assertEquals(response[0], "library"); + } + + @Test + public void detectPathFromTagWithNestedElement(){ + loadXml("author1genre1"); + String tag = "book"; + String[] response = XmlImportUtilitiesStub.detectPathFromTag(inputStream, tag); + Assert.assertNotNull(response); + Assert.assertEquals(response.length, 2); + Assert.assertEquals(response[0], "library"); + Assert.assertEquals(response[1], "book"); + } + + @Test + public void detectRecordElementTest(){ + loadXml("author1genre1"); + createParser(); + String tag="library"; + + List response = new ArrayList(); + try { + response = SUT.detectRecordElementWrapper(parser, tag); + } catch (XMLStreamException e) { + Assert.fail(); + } + Assert.assertNotNull(response); + Assert.assertEquals(response.size(), 1); + Assert.assertEquals(response.get(0), "library"); + } + + @Test + public void detectRecordElementCanHandleWithNestedElements(){ + loadXml("author1genre1"); + createParser(); + String tag="book"; + + List response = new ArrayList(); + try { + response = SUT.detectRecordElementWrapper(parser, tag); + } catch (XMLStreamException e) { + Assert.fail(); + } + Assert.assertNotNull(response); + Assert.assertEquals(response.size(), 2); + Assert.assertEquals(response.get(0), "library"); + Assert.assertEquals(response.get(1), "book"); + } + + @Test + public void detectRecordElementIsNullForUnfoundTag(){ + loadXml("author1genre1"); + createParser(); + String tag=""; + + List response = new ArrayList(); + try { + response = SUT.detectRecordElementWrapper(parser, tag); + } catch (XMLStreamException e) { + Assert.fail(); + } + Assert.assertNull(response); + } + + @Test + public void detectRecordElementRegressionTest(){ + loadSampleXml(); + + String[] path = XmlImportUtilitiesStub.detectRecordElement(inputStream); + Assert.assertNotNull(path); + Assert.assertEquals(path.length, 2); + Assert.assertEquals(path[0], "library"); + Assert.assertEquals(path[1], "book"); + } + + @Test + public void importXmlTest(){ + loadSampleXml(); + + String[] recordPath = new String[]{"library","book"}; + XmlImportUtilitiesStub.importXml(inputStream, project, recordPath, columnGroup ); + + TestTools.PrintProject(project); + TestTools.AssertGridCreated(project, 0, 6); + Assert.assertEquals(project.rows.get(0).cells.size(), 4); + //TODO + } + + @Test + public void createColumnsFromImportTest(){ + + ImportColumnGroup columnGroup = new ImportColumnGroup(); + ImportColumn ic1 = new ImportColumn(); + ic1.name = "hello"; + ImportColumn ic2 = new ImportColumn(); + ic2.name = "world"; + ImportColumnGroup subGroup = new ImportColumnGroup(); + ImportColumn ic3 = new ImportColumn(); + ic3.name = "foo"; + ImportColumn ic4 = new ImportColumn(); + ic4.name = "bar"; + subGroup.columns.put("c", ic3); + subGroup.columns.put("d", ic4); + columnGroup.columns.put("a", ic1); + columnGroup.columns.put("b", ic2); + columnGroup.subgroups.put("e", subGroup); + XmlImportUtilitiesStub.createColumnsFromImport(project, columnGroup); + TestTools.PrintProject(project); + TestTools.AssertGridCreated(project, 4, 0); + Assert.assertEquals(project.columnModel.columns.get(0).getName(), "world"); + Assert.assertEquals(project.columnModel.columns.get(1).getName(), "hello"); + Assert.assertEquals(project.columnModel.columns.get(2).getName(), "bar"); + Assert.assertEquals(project.columnModel.columns.get(3).getName(), "foo"); + Assert.assertEquals(project.columnModel.columnGroups.get(0).keyColumnIndex, 2); + Assert.assertEquals(project.columnModel.columnGroups.get(0).startColumnIndex, 2); + Assert.assertEquals(project.columnModel.columnGroups.get(0).columnSpan, 2); + } + + @Test + public void findRecordTest(){ + loadSampleXml(); + createParser(); + ParserSkip(); + + String[] recordPath = new String[]{"library","book"}; + int pathIndex = 0; + + try { + SUT.findRecordWrapper(project, parser, recordPath, pathIndex, columnGroup); + } catch (XMLStreamException e) { + Assert.fail(); + } + + TestTools.PrintProject(project); + TestTools.AssertGridCreated(project, 0, 6); + Assert.assertEquals(project.rows.get(0).cells.size(), 4); + //TODO + } + + @Test + public void processRecordTest(){ + loadXml("author1genre1"); + createParser(); + ParserSkip(); + + try { + SUT.processRecordWrapper(project, parser, columnGroup); + } catch (XMLStreamException e) { + Assert.fail(); + } + TestTools.PrintProject(project); + Assert.assertNotNull(project.rows); + Assert.assertEquals(project.rows.size(), 1); + Row row = project.rows.get(0); + Assert.assertNotNull(row); + Assert.assertNotNull(row.getCell(1)); + Assert.assertEquals(row.getCell(1).value, "author1"); + + } + + @Test + public void processRecordTestDuplicateColumns(){ + loadXml("author1author2genre1"); + createParser(); + ParserSkip(); + + try { + SUT.processRecordWrapper(project, parser, columnGroup); + } catch (XMLStreamException e) { + Assert.fail(); + } + TestTools.PrintProject(project); + Assert.assertNotNull(project.rows); + Assert.assertEquals(project.rows.size(), 2); + Row row = project.rows.get(0); + Assert.assertNotNull(row); + Assert.assertEquals(row.cells.size(), 3); + Assert.assertNotNull(row.getCell(1)); + Assert.assertEquals(row.getCell(1).value, "author1"); + row = project.rows.get(1); + Assert.assertEquals(row.getCell(1).value, "author2"); + } + + @Test + public void processRecordTestNestedElement(){ + loadXml("author1a dategenre1"); + createParser(); + ParserSkip(); + + try { + SUT.processRecordWrapper(project, parser, columnGroup); + } catch (XMLStreamException e) { + Assert.fail(); + } + TestTools.PrintProject(project); + Assert.assertNotNull(project.rows); + Assert.assertEquals(project.rows.size(), 1); + Row row = project.rows.get(0); + Assert.assertNotNull(row); + Assert.assertEquals(row.cells.size(), 4); + Assert.assertNotNull(row.getCell(1)); + Assert.assertEquals(row.getCell(1).value, "author1"); + Assert.assertNotNull(row.getCell(2)); + Assert.assertEquals(row.getCell(2).value, "a date"); + } + + + @Test(groups={"broken"}) + public void processSubRecordTest(){ + loadXml("author1genre1"); + createParser(); + ParserSkip(); + + try { + SUT.ProcessSubRecordWrapper(project, parser, columnGroup, record); + } catch (XMLStreamException e) { + Assert.fail(); + } + TestTools.PrintProject(project); + Assert.fail(); + //TODO need to verify 'record' was set correctly which we can't do as ImportRecord is an internal class + } + + @Test(groups={"broken"}) + public void addCellTest(){ + String columnLocalName = "author"; + String text = "Author1, The"; + int commonStartingRowIndex = 0; + project.rows.add(new Row(0)); + SUT.addCellWrapper(project, columnGroup, record, columnLocalName, text, commonStartingRowIndex); + + Assert.fail(); + //TODO need to verify 'record' was set correctly which we can't do as ImportRecord is an internal class + } + + //----------------helpers------------- + public void loadSampleXml(){ + loadXml( XmlImporterTests.getSample() ); + } + + public void loadXml(String xml){ + try { + inputStream = new ByteArrayInputStream( xml.getBytes( "UTF-8" ) ); + } catch (UnsupportedEncodingException e1) { + Assert.fail(); + } + } + + public void ParserSkip(){ + try { + parser.next(); //move parser forward once e.g. skip the START_DOCUMENT parser event + } catch (XMLStreamException e1) { + Assert.fail(); + } + } + + public void createParser(){ + try { + parser = XMLInputFactory.newInstance().createXMLStreamReader(inputStream); + } catch (XMLStreamException e1) { + Assert.fail(); + } catch (FactoryConfigurationError e1) { + Assert.fail(); + } + } +} diff --git a/main/tests/server/src/log4j.properties b/main/tests/server/src/log4j.properties new file mode 100644 index 000000000..adaedaa02 --- /dev/null +++ b/main/tests/server/src/log4j.properties @@ -0,0 +1,7 @@ +log4j.rootLogger=ERROR, console +log4j.logger.org.apache.http.headers=WARN +log4j.logger.org.apache.http.impl=WARN +log4j.logger.org.apache.http.client=WARN + +log4j.appender.console=org.apache.log4j.ConsoleAppender +log4j.appender.console.layout=com.metaweb.gridworks.logging.IndentingLayout diff --git a/main/webapp/.classpath b/main/webapp/.classpath deleted file mode 100644 index f451f1089..000000000 --- a/main/webapp/.classpath +++ /dev/null @@ -1,42 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/main/webapp/.project b/main/webapp/.project deleted file mode 100644 index 912cc542a..000000000 --- a/main/webapp/.project +++ /dev/null @@ -1,12 +0,0 @@ - - gridworks - - - - org.eclipse.jdt.core.javabuilder - - - - org.eclipse.jdt.core.javanature - - \ No newline at end of file diff --git a/server/IDE/eclipse/Gridworks.launch b/server/IDEs/eclipse/Gridworks.launch similarity index 100% rename from server/IDE/eclipse/Gridworks.launch rename to server/IDEs/eclipse/Gridworks.launch diff --git a/server/IDE/eclipse/README.txt b/server/IDEs/eclipse/README.txt similarity index 100% rename from server/IDE/eclipse/README.txt rename to server/IDEs/eclipse/README.txt