onModuleLoad()
.
+ */
+public class CkanToZenodoPublisher implements EntryPoint {
+ /**
+ * The message displayed to the user when the server cannot be reached or
+ * returns an error.
+ */
+ private static final String SERVER_ERROR = "An error occurred while "
+ + "attempting to contact the server. Please check your network "
+ + "connection and try again.";
+
+ /**
+ * Create a remote service proxy to talk to the server-side Greeting service.
+ */
+ private final GreetingServiceAsync greetingService = GWT.create(GreetingService.class);
+
+ /**
+ * This is the entry point method.
+ */
+ public void onModuleLoad() {
+
+ }
+}
diff --git a/src/main/java/org/gcube/portlets/widgets/ckan2zenodopublisher/client/GreetingService.java b/src/main/java/org/gcube/portlets/widgets/ckan2zenodopublisher/client/GreetingService.java
new file mode 100644
index 0000000..97494d7
--- /dev/null
+++ b/src/main/java/org/gcube/portlets/widgets/ckan2zenodopublisher/client/GreetingService.java
@@ -0,0 +1,12 @@
+package org.gcube.portlets.widgets.ckan2zenodopublisher.client;
+
+import com.google.gwt.user.client.rpc.RemoteService;
+import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
+
+/**
+ * The client side stub for the RPC service.
+ */
+@RemoteServiceRelativePath("greet")
+public interface GreetingService extends RemoteService {
+ String greetServer(String name) throws IllegalArgumentException;
+}
diff --git a/src/main/java/org/gcube/portlets/widgets/ckan2zenodopublisher/client/GreetingServiceAsync.java b/src/main/java/org/gcube/portlets/widgets/ckan2zenodopublisher/client/GreetingServiceAsync.java
new file mode 100644
index 0000000..44d2ab6
--- /dev/null
+++ b/src/main/java/org/gcube/portlets/widgets/ckan2zenodopublisher/client/GreetingServiceAsync.java
@@ -0,0 +1,37 @@
+package org.gcube.portlets.widgets.ckan2zenodopublisher.client;
+
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.user.client.rpc.AsyncCallback;
+
+public interface GreetingServiceAsync
+{
+
+ /**
+ * GWT-RPC service asynchronous (client-side) interface
+ * @see org.gcube.portlets.widgets.ckan2zenodopublisher.client.GreetingService
+ */
+ void greetServer( java.lang.String name, AsyncCallback+ * FieldVerifier validates that the name the user enters is valid. + *
+ *
+ * This class is in the shared
packing because we use it in both
+ * the client code and on the server. On the client, we verify that the name is
+ * valid before sending an RPC request so the user doesn't have to wait for a
+ * network round trip to get feedback. On the server, we verify that the name is
+ * correct to ensure that the input is correct regardless of where the RPC
+ * originates.
+ *
+ * When creating a class that is used on both the client and the server, be sure + * that all code is translatable and does not use native JavaScript. Code that + * is note translatable (such as code that interacts with a database or the file + * system) cannot be compiled into client side JavaScript. Code that uses native + * JavaScript (such as Widgets) cannot be run on the server. + *
+ */ +public class FieldVerifier { + + /** + * Verifies that the specified name is valid for our service. + * + * In this example, we only require that the name is at least four + * characters. In your application, you can use more complex checks to ensure + * that usernames, passwords, email addresses, URLs, and other fields have the + * proper syntax. + * + * @param name the name to validate + * @return true if valid, false if invalid + */ + public static boolean isValidName(String name) { + if (name == null) { + return false; + } + return name.length() > 3; + } +} diff --git a/src/main/resources/org/gcube/portlets/widgets/ckan2zenodopublisher/CkanToZenodoPublisher.gwt.xml b/src/main/resources/org/gcube/portlets/widgets/ckan2zenodopublisher/CkanToZenodoPublisher.gwt.xml new file mode 100644 index 0000000..6653a1b --- /dev/null +++ b/src/main/resources/org/gcube/portlets/widgets/ckan2zenodopublisher/CkanToZenodoPublisher.gwt.xml @@ -0,0 +1,22 @@ + +Please enter your name: | +|
+ | + |
+ |
"GwtTest*"
naming pattern exclude them from running with
+ * surefire during the test phase.
+ *
+ * If you run the tests using the Maven command line, you will have to
+ * navigate with your browser to a specific url given by Maven.
+ * See http://mojo.codehaus.org/gwt-maven-plugin/user-guide/testing.html
+ * for details.
+ */
+public class GwtTestCkanToZenodoPublisher extends GWTTestCase {
+
+ /**
+ * Must refer to a valid module that sources this class.
+ */
+ public String getModuleName() {
+ return "org.gcube.portlets.widgets.ckan2zenodopublisher.CkanToZenodoPublisherJUnit";
+ }
+
+ /**
+ * Tests the FieldVerifier.
+ */
+ public void testFieldVerifier() {
+ assertFalse(FieldVerifier.isValidName(null));
+ assertFalse(FieldVerifier.isValidName(""));
+ assertFalse(FieldVerifier.isValidName("a"));
+ assertFalse(FieldVerifier.isValidName("ab"));
+ assertFalse(FieldVerifier.isValidName("abc"));
+ assertTrue(FieldVerifier.isValidName("abcd"));
+ }
+
+ /**
+ * This test will send a request to the server using the greetServer method in
+ * GreetingService and verify the response.
+ */
+ public void testGreetingService() {
+ // Create the service that we will test.
+ GreetingServiceAsync greetingService = GWT.create(GreetingService.class);
+ ServiceDefTarget target = (ServiceDefTarget) greetingService;
+ target.setServiceEntryPoint(GWT.getModuleBaseURL() + "CkanToZenodoPublisher/greet");
+
+ // Since RPC calls are asynchronous, we will need to wait for a response
+ // after this test method returns. This line tells the test runner to wait
+ // up to 10 seconds before timing out.
+ delayTestFinish(10000);
+
+ // Send a request to the server.
+ greetingService.greetServer("GWT User", new AsyncCallback