aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-gwt-api
diff options
context:
space:
mode:
authorsimonbrandhof <simon.brandhof@gmail.com>2010-10-19 12:28:40 +0000
committersimonbrandhof <simon.brandhof@gmail.com>2010-10-19 12:28:40 +0000
commit21d609df3a50bc7252d383ece40413ba3baac6ff (patch)
tree7af3758860a429f97ca666c7facdbd716e136ca9 /sonar-gwt-api
parent2ca3e28c0bc9990f774b7c927e04f100894b1004 (diff)
downloadsonarqube-21d609df3a50bc7252d383ece40413ba3baac6ff.tar.gz
sonarqube-21d609df3a50bc7252d383ece40413ba3baac6ff.zip
SONAR-1852 Add the analysis date to the Java web service client libray
Diffstat (limited to 'sonar-gwt-api')
-rw-r--r--sonar-gwt-api/src/main/java/org/sonar/gwt/JsonUtils.java63
-rw-r--r--sonar-gwt-api/src/main/java/org/sonar/wsclient/gwt/unmarshallers/ResourceUnmarshaller.java1
2 files changed, 35 insertions, 29 deletions
diff --git a/sonar-gwt-api/src/main/java/org/sonar/gwt/JsonUtils.java b/sonar-gwt-api/src/main/java/org/sonar/gwt/JsonUtils.java
index 5221c70b450..9682d29749c 100644
--- a/sonar-gwt-api/src/main/java/org/sonar/gwt/JsonUtils.java
+++ b/sonar-gwt-api/src/main/java/org/sonar/gwt/JsonUtils.java
@@ -36,7 +36,9 @@ public final class JsonUtils {
public interface JSONHandler {
void onResponse(JavaScriptObject obj);
+
void onTimeout();
+
void onError(int errorCode, String errorMessage);
}
@@ -55,35 +57,35 @@ public final class JsonUtils {
}
public static native void makeJSONRequest(int requestId, String url, JSONHandler handler) /*-{
- var callback = "callback" + requestId;
+ var callback = "callback" + requestId;
- // create SCRIPT tag, and set SRC attribute equal to JSON feed URL + callback function name
- var script = document.createElement("script");
- script.setAttribute("src", url+callback);
- script.setAttribute("type", "text/javascript");
+ // create SCRIPT tag, and set SRC attribute equal to JSON feed URL + callback function name
+ var script = document.createElement("script");
+ script.setAttribute("src", url + callback);
+ script.setAttribute("type", "text/javascript");
- window[callback] = function(jsonObj) {
- @org.sonar.gwt.JsonUtils::dispatchJSON(Lcom/google/gwt/core/client/JavaScriptObject;Lorg/sonar/gwt/JsonUtils$JSONHandler;)(jsonObj, handler);
- window[callback + "done"] = true;
- }
+ window[callback] = function(jsonObj) {
+ @org.sonar.gwt.JsonUtils::dispatchJSON(Lcom/google/gwt/core/client/JavaScriptObject;Lorg/sonar/gwt/JsonUtils$JSONHandler;)(jsonObj, handler);
+ window[callback + "done"] = true;
+ }
- setTimeout(function() {
- if (!window[callback + "done"]) {
- handler.@org.sonar.gwt.JsonUtils.JSONHandler::onTimeout();
- }
+ setTimeout(function() {
+ if (!window[callback + "done"]) {
+ handler.@org.sonar.gwt.JsonUtils.JSONHandler::onTimeout();
+ }
- // cleanup
- document.body.removeChild(script);
- if (window[callback]) {
- delete window[callback];
- }
- if (window[callback + "done"]) {
- delete window[callback + "done"];
- }
- }, 120000);
+ // cleanup
+ document.body.removeChild(script);
+ if (window[callback]) {
+ delete window[callback];
+ }
+ if (window[callback + "done"]) {
+ delete window[callback + "done"];
+ }
+ }, 120000);
- document.body.appendChild(script);
- }-*/;
+ document.body.appendChild(script);
+ }-*/;
public static void dispatchJSON(JavaScriptObject jsonObj, JSONHandler handler) {
JSONObject obj = new JSONObject(jsonObj);
@@ -111,13 +113,16 @@ public final class JsonUtils {
}
public static Date getDate(JSONObject json, String field) {
- DateTimeFormat frmt = DateTimeFormat.getFormat("yyyy-MM-dd'T'HH:mm:ssZ");
String date = getString(json, field);
- if (date!=null && date.endsWith("Z") && date.length()>2) {
- // see SONAR-1182
- date = date.substring(0, date.length()-2) + "+00:00";
+ if (date != null) {
+ DateTimeFormat frmt = DateTimeFormat.getFormat("yyyy-MM-dd'T'HH:mm:ssZ");
+ if (date.endsWith("Z") && date.length() > 2) {
+ // see SONAR-1182
+ date = date.substring(0, date.length() - 2) + "+0000";
+ }
+ return frmt.parse(date);
}
- return frmt.parse(date);
+ return null;
}
public static Boolean getBoolean(JSONObject json, String field) {
diff --git a/sonar-gwt-api/src/main/java/org/sonar/wsclient/gwt/unmarshallers/ResourceUnmarshaller.java b/sonar-gwt-api/src/main/java/org/sonar/wsclient/gwt/unmarshallers/ResourceUnmarshaller.java
index 49562c54993..f6ad914bffc 100644
--- a/sonar-gwt-api/src/main/java/org/sonar/wsclient/gwt/unmarshallers/ResourceUnmarshaller.java
+++ b/sonar-gwt-api/src/main/java/org/sonar/wsclient/gwt/unmarshallers/ResourceUnmarshaller.java
@@ -55,6 +55,7 @@ public class ResourceUnmarshaller extends AbstractUnmarshaller<Resource> {
.setQualifier(JsonUtils.getString(json, "qualifier"))
.setLanguage(JsonUtils.getString(json, "lang"))
.setVersion(JsonUtils.getString(json, "version"))
+ .setDate(JsonUtils.getDate(json, "date"))
.setCopy(JsonUtils.getInteger(json, "copy"));
}