make the clean refactor become the new trunk
git-svn-id: http://google-refine.googlecode.com/svn/trunk@917 7d457c2a-affb-35e4-300a-418c747d4874
This commit is contained in:
commit
f92ecfb715
@ -1,10 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="con" path="com.google.appengine.eclipse.core.GAE_CONTAINER"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/gridworks"/>
|
||||
<classpathentry kind="lib" path="/gridworks/webapp/WEB-INF/lib/httpcore-4.0.1.jar" sourcepath="/gridworks/webapp/WEB-INF/lib-src/httpcore-4.0.1-sources.jar"/>
|
||||
<classpathentry kind="lib" path="/gridworks/webapp/WEB-INF/lib/httpclient-4.0.1.jar" sourcepath="/gridworks/webapp/WEB-INF/lib-src/httpclient-4.0.1-sources.jar"/>
|
||||
<classpathentry kind="output" path="classes"/>
|
||||
</classpath>
|
@ -1,7 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<launchConfiguration type="org.eclipse.ui.externaltools.ProgramBuilderLaunchConfigurationType">
|
||||
<booleanAttribute key="org.eclipse.ui.externaltools.ATTR_BUILDER_ENABLED" value="false"/>
|
||||
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_DISABLED_BUILDER" value="com.google.appengine.eclipse.core.projectValidator"/>
|
||||
<mapAttribute key="org.eclipse.ui.externaltools.ATTR_TOOL_ARGUMENTS"/>
|
||||
<booleanAttribute key="org.eclipse.ui.externaltools.ATTR_TRIGGERS_CONFIGURED" value="true"/>
|
||||
</launchConfiguration>
|
@ -1,7 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<launchConfiguration type="org.eclipse.ui.externaltools.ProgramBuilderLaunchConfigurationType">
|
||||
<booleanAttribute key="org.eclipse.ui.externaltools.ATTR_BUILDER_ENABLED" value="false"/>
|
||||
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_DISABLED_BUILDER" value="com.google.gdt.eclipse.core.webAppProjectValidator"/>
|
||||
<mapAttribute key="org.eclipse.ui.externaltools.ATTR_TOOL_ARGUMENTS"/>
|
||||
<booleanAttribute key="org.eclipse.ui.externaltools.ATTR_TRIGGERS_CONFIGURED" value="true"/>
|
||||
</launchConfiguration>
|
@ -1,43 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>gridworks appengine</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.ui.externaltools.ExternalToolBuilder</name>
|
||||
<triggers>full,incremental,</triggers>
|
||||
<arguments>
|
||||
<dictionary>
|
||||
<key>LaunchConfigHandle</key>
|
||||
<value><project>/.externalToolBuilders/com.google.gdt.eclipse.core.webAppProjectValidator.launch</value>
|
||||
</dictionary>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>com.google.appengine.eclipse.core.enhancerbuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.ui.externaltools.ExternalToolBuilder</name>
|
||||
<triggers>full,incremental,</triggers>
|
||||
<arguments>
|
||||
<dictionary>
|
||||
<key>LaunchConfigHandle</key>
|
||||
<value><project>/.externalToolBuilders/com.google.appengine.eclipse.core.projectValidator.launch</value>
|
||||
</dictionary>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
<nature>com.google.appengine.eclipse.core.gaeNature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
@ -1,3 +0,0 @@
|
||||
#Wed May 26 15:13:15 PDT 2010
|
||||
eclipse.preferences.version=1
|
||||
validationExclusions=src/com/metaweb/gridworks/appengine/*ClientConnection*.java
|
@ -1,5 +0,0 @@
|
||||
#Wed May 26 15:11:38 PDT 2010
|
||||
eclipse.preferences.version=1
|
||||
jarsExcludedFromWebInfLib=
|
||||
warSrcDir=
|
||||
warSrcDirIsOutput=true
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -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;
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -118,6 +118,7 @@
|
||||
<src path="${webapp.src.dir}"/>
|
||||
<classpath refid="webapp.class.path" />
|
||||
</javac>
|
||||
<copy file="${webapp.src.dir}/log4j.properties" tofile="${webapp.classes.dir}/log4j.properties"/>
|
||||
</target>
|
||||
|
||||
<target name="build_tests" depends="build_webapp">
|
||||
@ -125,6 +126,7 @@
|
||||
<javac srcdir="${server.tests.src.dir}" destdir="${server.tests.classes.dir}" debug="true" includeAntRuntime="no">
|
||||
<classpath refid="tests.class.path" />
|
||||
</javac>
|
||||
<copy file="${server.tests.src.dir}/log4j.properties" tofile="${server.tests.classes.dir}/log4j.properties"/>
|
||||
</target>
|
||||
|
||||
<target name="build" depends="build_server, build_webapp"/>
|
||||
|
@ -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.
|
@ -6,7 +6,6 @@
|
||||
</listAttribute>
|
||||
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="org.testng.remote.RemoteTestNG"/>
|
||||
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="gridworks"/>
|
||||
<stringAttribute key="org.eclipse.jdt.launching.WORKING_DIRECTORY" value="${workspace_loc:gridworks/tests/server}"/>
|
||||
<mapAttribute key="org.testng.eclipse.ALL_CLASS_METHODS"/>
|
||||
<listAttribute key="org.testng.eclipse.CLASS_TEST_LIST"/>
|
||||
<stringAttribute key="org.testng.eclipse.COMPLIANCE_LEVEL" value="JDK"/>
|
@ -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;
|
||||
|
@ -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);
|
||||
|
@ -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 =
|
||||
|
@ -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);
|
||||
|
@ -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));
|
||||
|
@ -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);
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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))) {
|
||||
|
@ -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<RecordFilter> _recordFilters = new LinkedList<RecordFilter>();
|
||||
|
||||
public void add(RecordFilter recordFilter) {
|
||||
_recordFilters.add(recordFilter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(Project project, RecordVisitor visitor) {
|
||||
try {
|
||||
visitor.start(project);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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<Record> _records;
|
||||
|
||||
public SortingRecordVisitor(RecordVisitor visitor) {
|
||||
_visitor = visitor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start(Project project) {
|
||||
int count = project.recordModel.getRecordCount();
|
||||
_records = new ArrayList<Record>(count);
|
||||
_keys = new ArrayList<Object[]>(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);
|
||||
}
|
||||
}
|
||||
|
@ -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<IndexedRow> _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<IndexedRow>(count);
|
||||
_keys = new ArrayList<Object[]>(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);
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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 = "<http://rdf.freebase.com/ns/en.bob_dylan> <http://rdf.freebase.com/ns/music.artist.album> <http://rdf.freebase.com/ns/en.blood_on_the_tracks>.";
|
||||
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 = "<http://rdf.freebase.com/ns/en.bob_dylan> <http://rdf.freebase.com/ns/music.artist.album> <http://rdf.freebase.com/ns/en.blood_on_the_tracks>.\n" +
|
||||
"<http://rdf.freebase.com/ns/en.bob_dylan> <http://rdf.freebase.com/ns/music.artist.album> <http://rdf.freebase.com/ns/en.under_the_red_sky>.\n" +
|
||||
"<http://rdf.freebase.com/ns/en.bob_dylan> <http://rdf.freebase.com/ns/music.artist.album> <http://rdf.freebase.com/ns/en.bringing_it_all_back_home>.";
|
||||
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 = "<http://rdf.freebase.com/ns/en.bob_dylan> <http://rdf.freebase.com/ns/music.artist.album> <http://rdf.freebase.com/ns/en.blood_on_the_tracks>.\n" +
|
||||
"<http://rdf.freebase.com/ns/en.bob_dylan> <http://rdf.freebase.com/ns/music.artist.genre> <http://rdf.freebase.com/ns/en.folk_rock>.\n" +
|
||||
"<http://rdf.freebase.com/ns/en.bob_dylan> <http://rdf.freebase.com/ns/music.artist.album> <http://rdf.freebase.com/ns/en.bringing_it_all_back_home>.";
|
||||
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 = "<http://rdf.freebase.com/ns/en.bob_dylan> <http://rdf.freebase.com/ns/common.topic.alias> \"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 = "<http://rdf.freebase.com/ns/en.bob_dylan> <http://rdf.freebase.com/ns/music.artist.album> <http://rdf.freebase.com/ns/en.blood_on_the_tracks>.";
|
||||
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 = "<http://rdf.freebase.com/ns/en.bob_dylan> <http://rdf.freebase.com/ns/music.artist.album> <http://rdf.freebase.com/ns/en.blood_on_the_tracks>.\n" +
|
||||
"<http://rdf.freebase.com/ns/en.bob_dylan> <http://rdf.freebase.com/ns/music.artist.album> <http://rdf.freebase.com/ns/en.under_the_red_sky>.\n" +
|
||||
"<http://rdf.freebase.com/ns/en.bob_dylan> <http://rdf.freebase.com/ns/music.artist.album> <http://rdf.freebase.com/ns/en.bringing_it_all_back_home>.";
|
||||
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 = "<http://rdf.freebase.com/ns/en.bob_dylan> <http://rdf.freebase.com/ns/music.artist.album> <http://rdf.freebase.com/ns/en.blood_on_the_tracks>.\n" +
|
||||
"<http://rdf.freebase.com/ns/en.bob_dylan> <http://rdf.freebase.com/ns/music.artist.genre> <http://rdf.freebase.com/ns/en.folk_rock>.\n" +
|
||||
"<http://rdf.freebase.com/ns/en.bob_dylan> <http://rdf.freebase.com/ns/music.artist.album> <http://rdf.freebase.com/ns/en.bringing_it_all_back_home>.";
|
||||
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 = "<http://rdf.freebase.com/ns/en.bob_dylan> <http://rdf.freebase.com/ns/common.topic.alias> \"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");
|
||||
}
|
||||
}
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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<String> 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<String> 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);
|
||||
}
|
||||
}
|
||||
|
@ -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("<?xml version=\"1.0\"?><library><book id=\"1\"><author>author1</author><genre>genre1</genre></book></library>");
|
||||
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("<?xml version=\"1.0\"?><library><book id=\"1\"><author>author1</author><genre>genre1</genre></book></library>");
|
||||
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("<?xml version=\"1.0\"?><library><book id=\"1\"><author>author1</author><genre>genre1</genre></book></library>");
|
||||
createParser();
|
||||
String tag="library";
|
||||
|
||||
List<String> response = new ArrayList<String>();
|
||||
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("<?xml version=\"1.0\"?><library><book id=\"1\"><author>author1</author><genre>genre1</genre></book></library>");
|
||||
createParser();
|
||||
String tag="book";
|
||||
|
||||
List<String> response = new ArrayList<String>();
|
||||
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("<?xml version=\"1.0\"?><library><book id=\"1\"><author>author1</author><genre>genre1</genre></book></library>");
|
||||
createParser();
|
||||
String tag="";
|
||||
|
||||
List<String> response = new ArrayList<String>();
|
||||
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("<?xml version=\"1.0\"?><library><book id=\"1\"><author>author1</author><genre>genre1</genre></book></library>");
|
||||
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("<?xml version=\"1.0\"?><library><book id=\"1\"><author>author1</author><author>author2</author><genre>genre1</genre></book></library>");
|
||||
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("<?xml version=\"1.0\"?><library><book id=\"1\"><author><author-name>author1</author-name><author-dob>a date</author-dob></author><genre>genre1</genre></book></library>");
|
||||
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("<?xml version=\"1.0\"?><library><book id=\"1\"><author>author1</author><genre>genre1</genre></book></library>");
|
||||
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("<?xml version=\"1.0\"?><library><book id=\"1\"><author>author1</author><genre>genre1</genre></book></library>");
|
||||
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("<?xml version=\"1.0\"?><library><book id=\"1\"><author>author1</author><genre>genre1</genre></book></library>");
|
||||
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("<?xml version=\"1.0\"?><library><book id=\"1\"><author>author1</author><genre>genre1</genre></book></library>");
|
||||
createParser();
|
||||
String tag="library";
|
||||
|
||||
List<String> response = new ArrayList<String>();
|
||||
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("<?xml version=\"1.0\"?><library><book id=\"1\"><author>author1</author><genre>genre1</genre></book></library>");
|
||||
createParser();
|
||||
String tag="book";
|
||||
|
||||
List<String> response = new ArrayList<String>();
|
||||
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("<?xml version=\"1.0\"?><library><book id=\"1\"><author>author1</author><genre>genre1</genre></book></library>");
|
||||
createParser();
|
||||
String tag="";
|
||||
|
||||
List<String> response = new ArrayList<String>();
|
||||
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("<?xml version=\"1.0\"?><library><book id=\"1\"><author>author1</author><genre>genre1</genre></book></library>");
|
||||
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("<?xml version=\"1.0\"?><library><book id=\"1\"><author>author1</author><author>author2</author><genre>genre1</genre></book></library>");
|
||||
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("<?xml version=\"1.0\"?><library><book id=\"1\"><author><author-name>author1</author-name><author-dob>a date</author-dob></author><genre>genre1</genre></book></library>");
|
||||
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("<?xml version=\"1.0\"?><library><book id=\"1\"><author>author1</author><genre>genre1</genre></book></library>");
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
7
main/tests/server/src/log4j.properties
Normal file
7
main/tests/server/src/log4j.properties
Normal file
@ -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
|
@ -1,42 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src/main/java"/>
|
||||
<classpathentry kind="src" path="src/server/java"/>
|
||||
<classpathentry kind="src" path="tests/java/src"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
|
||||
<classpathentry kind="lib" path="lib/servlet-api-2.5.jar" sourcepath="lib-src/servlet-api-2.5-sources.jar"/>
|
||||
<classpathentry kind="lib" path="lib/jetty-6.1.22.jar" sourcepath="lib-src/jetty-6.1.22-sources.jar"/>
|
||||
<classpathentry kind="lib" path="lib/jetty-util-6.1.22.jar" sourcepath="lib-src/jetty-util-6.1.22-sources.jar"/>
|
||||
<classpathentry kind="lib" path="lib/slf4j-api-1.5.6.jar" sourcepath="lib-src/slf4j-api-1.5.6-sources.jar"/>
|
||||
<classpathentry kind="lib" path="lib/log4j-1.2.15.jar" sourcepath="lib-src/log4j-1.2.15-sources.jar"/>
|
||||
<classpathentry kind="lib" path="lib/slf4j-log4j12-1.5.6.jar" sourcepath="lib-src/slf4j-log4j12-1.5.6-sources.jar"/>
|
||||
<classpathentry kind="lib" path="lib/jcl-over-slf4j-1.5.6.jar" sourcepath="lib-src/jcl-over-slf4j-1.5.6-sources.jar"/>
|
||||
<classpathentry kind="lib" path="lib/commons-codec-1.4.jar" sourcepath="lib-src/commons-codec-1.4-sources.jar"/>
|
||||
<classpathentry kind="lib" path="lib/commons-lang-2.5.jar" sourcepath="lib-src/commons-lang-2.5-sources.jar"/>
|
||||
<classpathentry kind="lib" path="lib/commons-fileupload-1.2.1.jar" sourcepath="lib-src/commons-fileupload-1.2.1-sources.jar"/>
|
||||
<classpathentry kind="lib" path="lib/json-20100208.jar" sourcepath="lib-src/json-20100208-sources.jar"/>
|
||||
<classpathentry kind="lib" path="lib/icu4j-4.2.1.jar" sourcepath="lib-src/icu4j-4.2.1-sources.jar"/>
|
||||
<classpathentry kind="lib" path="lib/arithcode-1.1.jar" sourcepath="lib-src/arithcode-1.1-sources.jar"/>
|
||||
<classpathentry kind="lib" path="lib/jdatapath-alpha2.jar" sourcepath="lib-src/jdatapath-alpha2-sources.jar"/>
|
||||
<classpathentry kind="lib" path="lib/secondstring-20100303.jar" sourcepath="lib-src/secondstring-20100303-sources.jar"/>
|
||||
<classpathentry kind="lib" path="lib/ant-tools-1.8.0.jar" sourcepath="lib-src/ant-tools-1.8.0-sources.jar"/>
|
||||
<classpathentry kind="lib" path="lib/vicino-1.1.jar" sourcepath="lib-src/vicino-1.1-sources.jar"/>
|
||||
<classpathentry kind="lib" path="lib/httpcore-4.0.1.jar" sourcepath="lib-src/httpcore-4.0.1-sources.jar"/>
|
||||
<classpathentry kind="lib" path="lib/httpclient-4.0.1.jar" sourcepath="lib-src/httpclient-4.0.1-sources.jar"/>
|
||||
<classpathentry kind="lib" path="lib/signpost-core-1.2.1.1.jar" sourcepath="lib-src/signpost-core-1.2.1.1-sources.jar"/>
|
||||
<classpathentry kind="lib" path="lib/signpost-commonshttp4-1.2.1.1.jar" sourcepath="lib-src/signpost-commonshttp4-1.2.1.1-sources.jar"/>
|
||||
<classpathentry kind="lib" path="lib/opencsv-2.2.jar" sourcepath="tests/java/lib-src/opencsv-2.2-sources.jar"/>
|
||||
<classpathentry kind="lib" path="lib/poi-3.6.jar"/>
|
||||
<classpathentry kind="lib" path="lib/poi-ooxml-3.6.jar"/>
|
||||
<classpathentry kind="lib" path="lib/poi-ooxml-schemas-3.6-20091214.jar"/>
|
||||
<classpathentry kind="lib" path="lib/dom4j-1.6.1.jar"/>
|
||||
<classpathentry kind="lib" path="lib/xmlbeans-2.3.0.jar"/>
|
||||
<classpathentry kind="lib" path="lib/jython-2.5.1.jar"/>
|
||||
<classpathentry kind="lib" path="lib/clojure-1.1.0.jar"/>
|
||||
<classpathentry kind="lib" path="lib/jackson-core-asl-1.5.1.jar"/>
|
||||
<classpathentry kind="lib" path="lib/marc4j-2.4.jar"/>
|
||||
<classpathentry kind="lib" path="tests/java/lib/mockito-all-1.8.4.jar" sourcepath="tests/java/lib-src/mockito-all-1.8.4-sources.jar"/>
|
||||
<classpathentry kind="lib" path="tests/java/lib/testng-5.12.1.jar" sourcepath="tests/java/lib-src/testng-5.12.1-sources.jar"/>
|
||||
<classpathentry kind="lib" path="lib/jrdf-0.5.6.jar"/>
|
||||
<classpathentry kind="output" path="src/main/webapp/WEB-INF/classes"/>
|
||||
</classpath>
|
@ -1,12 +0,0 @@
|
||||
<projectDescription>
|
||||
<name>gridworks</name>
|
||||
<projects/>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
Loading…
Reference in New Issue
Block a user