From 1eb60aa8c53558d5112eb1c54c7a74d73eee36b7 Mon Sep 17 00:00:00 2001 From: charithag Date: Thu, 20 Aug 2015 19:35:09 +0530 Subject: [PATCH] Change to comply with JAX-RS update --- .../jaggeryapps/iotserver/api/group-api.jag | 10 +- .../units/device-listing/device-listing.hbs | 28 +-- .../public/js/device-listing.js | 178 ++++++++---------- .../units/group-listing/group-listing.hbs | 4 +- .../group-listing/public/js/group-listing.js | 55 +++--- 5 files changed, 120 insertions(+), 155 deletions(-) diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/api/group-api.jag b/modules/distribution/src/repository/jaggeryapps/iotserver/api/group-api.jag index 7028b71a..6e101dd4 100644 --- a/modules/distribution/src/repository/jaggeryapps/iotserver/api/group-api.jag +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/api/group-api.jag @@ -67,9 +67,8 @@ if (uriMatcher.match("/{context}/api/group/add")) { groupId = uriMatcher.elements().groupId; //URL: DELETE https://localhost:9443/devicecloud/group_manager/group/id/{groupId} - endPoint = deviceCloudService + "/group/id/" + groupId; - data = {"username": user.username}; - result = del(endPoint, data, "json"); + endPoint = deviceCloudService + "/group/id/" + groupId + "?username=" + user.username; + result = del(endPoint, {}, "json"); } else if (uriMatcher.match("/{context}/api/group/id/{groupId}")) { groupId = uriMatcher.elements().groupId; @@ -139,9 +138,8 @@ if (uriMatcher.match("/{context}/api/group/add")) { role = request.getContent()["role"]; //URL: DELETE https://localhost:9443/devicecloud/group_manager/group/id/{groupId}/role - endPoint = deviceCloudService + "/group/id/" + groupId + "/role"; - data = {"username": user.username, "role": role}; - result = del(endPoint, data, "json"); + endPoint = deviceCloudService + "/group/id/" + groupId + "/role/" + role; + result = del(endPoint, {}, "json"); } else if (uriMatcher.match("/{context}/api/group/id/{groupId}/role/all")) { diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/device-listing/device-listing.hbs b/modules/distribution/src/repository/jaggeryapps/iotserver/units/device-listing/device-listing.hbs index d4ee9d87..7ff2282d 100644 --- a/modules/distribution/src/repository/jaggeryapps/iotserver/units/device-listing/device-listing.hbs +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/units/device-listing/device-listing.hbs @@ -176,7 +176,7 @@

Exception at backend. Try Later.

- +     Ok    
@@ -189,10 +189,10 @@
-

Action not permitted.

+

Operation not permitted.

@@ -217,22 +217,6 @@
-
-
-
-
-

Device does not exist.

- - -
-
-
-
-
@@ -403,14 +387,14 @@
-
+
-

Group does not exist.

+

Unexpected error occurred!

diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/device-listing/public/js/device-listing.js b/modules/distribution/src/repository/jaggeryapps/iotserver/units/device-listing/public/js/device-listing.js index b3049268..f4552fad 100644 --- a/modules/distribution/src/repository/jaggeryapps/iotserver/units/device-listing/public/js/device-listing.js +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/units/device-listing/public/js/device-listing.js @@ -200,8 +200,8 @@ function loadDevices() { } }; invokerUtil.get(serviceURL, - successCallback, function (message) { - console.log(message); + successCallback, function (jqXHR) { + displayDeviceErrors(jqXHR); }); }); } @@ -286,28 +286,12 @@ function attachDeviceEvents() { setTimeout(function () { hidePopup(); }, 2000); - } else if (status == 400) { - $(modalPopupContent).html($('#remove-device-400-content').html()); - $("a#remove-device-400-link").click(function () { - hidePopup(); - }); - } else if (status == 403) { - $(modalPopupContent).html($('#remove-device-403-content').html()); - $("a#remove-device-403-link").click(function () { - hidePopup(); - }); - } else if (status == 409) { - $(modalPopupContent).html($('#remove-device-409-content').html()); - $("a#remove-device-409-link").click(function () { - hidePopup(); - }); + } else { + displayDeviceErrors(jqXHR); } }, - function () { - $(modalPopupContent).html($('#remove-device-unexpected-error-content').html()); - $("a#remove-device-unexpected-error-link").click(function () { - hidePopup(); - }); + function (jqXHR) { + displayDeviceErrors(jqXHR); } ); }); @@ -347,28 +331,12 @@ function attachDeviceEvents() { setTimeout(function () { hidePopup(); }, 2000); - } else if (status == 400) { - $(modalPopupContent).html($('#device-400-content').html()); - $("a#device-400-link").click(function () { - hidePopup(); - }); - } else if (status == 403) { - $(modalPopupContent).html($('#device-403-content').html()); - $("a#device-403-link").click(function () { - hidePopup(); - }); - } else if (status == 409) { - $(modalPopupContent).html($('#device-409-content').html()); - $("a#device-409-link").click(function () { - hidePopup(); - }); + } else { + displayDeviceErrors(jqXHR); } }, - function () { - $(modalPopupContent).html($('#device-unexpected-error-content').html()); - $("a#device-unexpected-error-link").click(function () { - hidePopup(); - }); + function (jqXHR) { + displayDeviceErrors(jqXHR); } ); }); @@ -425,39 +393,21 @@ function attachDeviceEvents() { setTimeout(function () { hidePopup(); }, 2000); - } else if (status == 400) { - $(modalPopupContent).html($('#device-400-content').html()); - $("a#device-400-link").click(function () { - hidePopup(); - }); - } else if (status == 403) { - $(modalPopupContent).html($('#device-403-content').html()); - $("a#device-403-link").click(function () { - hidePopup(); - }); - } else if (status == 409) { - $(modalPopupContent).html($('#device-409-content').html()); - $("a#device-409-link").click(function () { - hidePopup(); - }); + } else { + displayDeviceErrors(jqXHR); } }, - function () { - $(modalPopupContent).html($('#device-unexpected-error-content').html()); - $("a#device-unexpected-error-link").click(function () { - hidePopup(); - }); - }); + function (jqXHR) { + displayDeviceErrors(jqXHR); + } + ); }); } }, - function () { - $(modalPopupContent).html($('#device-unexpected-error-content').html()); - $("a#device-unexpected-error-link").click(function () { - hidePopup(); - }); - }); - + function (jqXHR) { + displayDeviceErrors(jqXHR); + } + ); $("a#group-device-cancel-link").click(function () { hidePopup(); }); @@ -466,13 +416,6 @@ function attachDeviceEvents() { } } -var errorHandler = function () { - $(modalPopupContent).html($('#add-group-unexpected-error-content').html()); - $("a#group-unexpected-error-link").click(function () { - hidePopup(); - }); -}; - /** * Following functions should be triggered after AJAX request is made. */ @@ -556,22 +499,31 @@ function attachGroupEvents() { hidePopup(); }, 2000); } else { - displayErrors(status); + displayGroupErrors(status); } - }, errorHandler); + }, function (jqXHR) { + displayGroupErrors(jqXHR); + } + ); }); } else { - displayErrors(status); + displayGroupErrors(status); } - }, errorHandler); + }, function (jqXHR) { + displayGroupErrors(jqXHR); + } + ); $("a#share-group-w2-cancel-link").click(function () { hidePopup(); }); }); } else { - displayErrors(status); + displayGroupErrors(status); } - }, errorHandler); + }, function (jqXHR) { + displayGroupErrors(jqXHR); + } + ); $("a#share-group-w1-cancel-link").click(function () { hidePopup(); @@ -603,14 +555,11 @@ function attachGroupEvents() { hidePopup(); }, 2000); } else { - displayErrors(status); + displayGroupErrors(status); } }, - function () { - $(modalPopupContent).html($('#group-unexpected-error-content').html()); - $("a#group-unexpected-error-link").click(function () { - hidePopup(); - }); + function (jqXHR) { + displayGroupErrors(jqXHR); } ); }); @@ -660,14 +609,11 @@ function attachGroupEvents() { }); } } else { - displayErrors(status); + displayGroupErrors(status); } }, - function () { - $(modalPopupContent).html($('#group-unexpected-error-content').html()); - $("a#group-unexpected-error-link").click(function () { - hidePopup(); - }); + function (jqXHR) { + displayGroupErrors(jqXHR); } ); }); @@ -678,21 +624,55 @@ function attachGroupEvents() { }); } -function displayErrors(status) { - if (status == 400) { +function displayDeviceErrors(jqXHR) { + showPopup(); + if (jqXHR.status == 400) { $(modalPopupContent).html($('#group-400-content').html()); $("a#group-400-link").click(function () { hidePopup(); }); - } else if (status == 403) { + } else if (jqXHR.status == 403) { $(modalPopupContent).html($('#group-403-content').html()); $("a#group-403-link").click(function () { hidePopup(); }); - } else if (status == 409) { + } else if (jqXHR.status == 409) { $(modalPopupContent).html($('#group-409-content').html()); $("a#group-409-link").click(function () { hidePopup(); }); + } else { + $(modalPopupContent).html($('#group-unexpected-error-content').html()); + $("a#group-unexpected-error-link").click(function () { + hidePopup(); + }); + console.log("Error code: " + jqXHR.status); } } + + +function displayGroupErrors(jqXHR) { + showPopup(); + if (jqXHR.status == 400) { + $(modalPopupContent).html($('#group-400-content').html()); + $("a#group-400-link").click(function () { + hidePopup(); + }); + } else if (jqXHR.status == 403) { + $(modalPopupContent).html($('#group-403-content').html()); + $("a#group-403-link").click(function () { + hidePopup(); + }); + } else if (jqXHR.status == 409) { + $(modalPopupContent).html($('#group-409-content').html()); + $("a#group-409-link").click(function () { + hidePopup(); + }); + } else { + $(modalPopupContent).html($('#group-unexpected-error-content').html()); + $("a#group-unexpected-error-link").click(function () { + hidePopup(); + }); + console.log("Error code: " + jqXHR.status); + } +} \ No newline at end of file diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/group-listing/group-listing.hbs b/modules/distribution/src/repository/jaggeryapps/iotserver/units/group-listing/group-listing.hbs index e34e9e84..2374c191 100644 --- a/modules/distribution/src/repository/jaggeryapps/iotserver/units/group-listing/group-listing.hbs +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/units/group-listing/group-listing.hbs @@ -173,7 +173,7 @@
-

Action not permitted.

+

Operation not permitted.

@@ -205,7 +205,7 @@
-

Group does not exist.

+

Unexpected error occurred!

diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/group-listing/public/js/group-listing.js b/modules/distribution/src/repository/jaggeryapps/iotserver/units/group-listing/public/js/group-listing.js index 39fc5650..7abd030f 100644 --- a/modules/distribution/src/repository/jaggeryapps/iotserver/units/group-listing/public/js/group-listing.js +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/units/group-listing/public/js/group-listing.js @@ -165,8 +165,8 @@ function loadGroups(searchType, searchParam) { } }; invokerUtil.get(serviceURL, - successCallback, function (message) { - console.log(message); + successCallback, function (jqXHR) { + displayErrors(jqXHR); }); }); } @@ -222,13 +222,6 @@ function hidePopup() { $(modalPopup).hide(); } -var errorHandler = function () { - $(modalPopupContent).html($('#add-group-unexpected-error-content').html()); - $("a#group-unexpected-error-link").click(function () { - hidePopup(); - }); -}; - /** * Following functions should be triggered after AJAX request is made. */ @@ -324,12 +317,18 @@ function attachEvents() { } else { displayErrors(status); } - }, errorHandler); + }, function (jqXHR) { + displayErrors(jqXHR); + } + ); }); } else { displayErrors(status); } - }, errorHandler); + }, function (jqXHR) { + displayErrors(jqXHR); + } + ); $("a#share-group-w2-cancel-link").click(function () { hidePopup(); }); @@ -337,7 +336,10 @@ function attachEvents() { } else { displayErrors(status); } - }, errorHandler); + }, function (jqXHR) { + displayErrors(jqXHR); + } + ); $("a#share-group-w1-cancel-link").click(function () { hidePopup(); @@ -372,11 +374,8 @@ function attachEvents() { displayErrors(status); } }, - function () { - $(modalPopupContent).html($('#group-unexpected-error-content').html()); - $("a#group-unexpected-error-link").click(function () { - hidePopup(); - }); + function (jqXHR) { + displayErrors(jqXHR); } ); }); @@ -429,11 +428,8 @@ function attachEvents() { displayErrors(status); } }, - function () { - $(modalPopupContent).html($('#group-unexpected-error-content').html()); - $("a#group-unexpected-error-link").click(function () { - hidePopup(); - }); + function (jqXHR) { + displayErrors(jqXHR); } ); }); @@ -444,21 +440,28 @@ function attachEvents() { }); } -function displayErrors(status) { - if (status == 400) { +function displayErrors(jqXHR) { + showPopup(); + if (jqXHR.status == 400) { $(modalPopupContent).html($('#group-400-content').html()); $("a#group-400-link").click(function () { hidePopup(); }); - } else if (status == 403) { + } else if (jqXHR.status == 403) { $(modalPopupContent).html($('#group-403-content').html()); $("a#group-403-link").click(function () { hidePopup(); }); - } else if (status == 409) { + } else if (jqXHR.status == 409) { $(modalPopupContent).html($('#group-409-content').html()); $("a#group-409-link").click(function () { hidePopup(); }); + } else { + $(modalPopupContent).html($('#group-unexpected-error-content').html()); + $("a#group-unexpected-error-link").click(function () { + hidePopup(); + }); + console.log("Error code: " + jqXHR.status); } }