diff --git a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android_sense.type-view/public/asset/androidsense.apk b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android_sense.type-view/public/asset/androidsense.apk index 37a03c22b..6e9ad39dd 100644 Binary files a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android_sense.type-view/public/asset/androidsense.apk and b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android_sense.type-view/public/asset/androidsense.apk differ diff --git a/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.input.adapter.mqtt/src/main/java/org/wso2/carbon/device/mgt/iot/input/adapter/mqtt/util/MQTTAdapterListener.java b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.input.adapter.mqtt/src/main/java/org/wso2/carbon/device/mgt/iot/input/adapter/mqtt/util/MQTTAdapterListener.java index 305367141..ecd1b9345 100644 --- a/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.input.adapter.mqtt/src/main/java/org/wso2/carbon/device/mgt/iot/input/adapter/mqtt/util/MQTTAdapterListener.java +++ b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.input.adapter.mqtt/src/main/java/org/wso2/carbon/device/mgt/iot/input/adapter/mqtt/util/MQTTAdapterListener.java @@ -69,7 +69,6 @@ public class MQTTAdapterListener implements MqttCallback, Runnable { private InputEventAdapterListener eventAdapterListener = null; - public MQTTAdapterListener(MQTTBrokerConnectionConfiguration mqttBrokerConnectionConfiguration, String topic, String mqttClientId, InputEventAdapterListener inputEventAdapterListener, int tenantId) { @@ -173,22 +172,26 @@ public class MQTTAdapterListener implements MqttCallback, Runnable { StringEntity requestEntity = new StringEntity(jsonString, ContentType.APPLICATION_JSON); postMethod.setEntity(requestEntity); HttpResponse httpResponse = httpClient.execute(postMethod); - String response = MQTTUtil.getResponseString(httpResponse); - try { - JSONParser jsonParser = new JSONParser(); - JSONObject jsonPayload = (JSONObject) jsonParser.parse(response); - String clientId = (String) jsonPayload.get(MQTTEventAdapterConstants.CLIENT_ID); - String clientSecret = (String) jsonPayload.get(MQTTEventAdapterConstants.CLIENT_SECRET); - JWTClientManagerService jwtClientManagerService = MQTTUtil.getJWTClientManagerService(); - AccessTokenInfo accessTokenInfo = jwtClientManagerService.getJWTClient().getAccessToken( - clientId, clientSecret, username, scopes); - connectionOptions.setUserName(accessTokenInfo.getAccessToken()); - } catch (ParseException e) { - String msg = "error occurred while parsing client credential payload"; - log.error(msg, e); - } catch (JWTClientException e) { - String msg = "error occurred while parsing the response from JWT Client"; - log.error(msg, e); + if (httpResponse != null) { + String response = MQTTUtil.getResponseString(httpResponse); + try { + if (response != null) { + JSONParser jsonParser = new JSONParser(); + JSONObject jsonPayload = (JSONObject) jsonParser.parse(response); + String clientId = (String) jsonPayload.get(MQTTEventAdapterConstants.CLIENT_ID); + String clientSecret = (String) jsonPayload.get(MQTTEventAdapterConstants.CLIENT_SECRET); + JWTClientManagerService jwtClientManagerService = MQTTUtil.getJWTClientManagerService(); + AccessTokenInfo accessTokenInfo = jwtClientManagerService.getJWTClient().getAccessToken( + clientId, clientSecret, username, scopes); + connectionOptions.setUserName(accessTokenInfo.getAccessToken()); + } + } catch (ParseException e) { + String msg = "error occurred while parsing client credential payload"; + log.error(msg, e); + } catch (JWTClientException e) { + String msg = "error occurred while parsing the response from JWT Client"; + log.error(msg, e); + } } } catch (MalformedURLException e) { log.error("Invalid dcrUrl : " + dcrUrlString); @@ -263,11 +266,11 @@ public class MQTTAdapterListener implements MqttCallback, Runnable { @Override public void run() { + int connectionDuration = MQTTEventAdapterConstants.INITIAL_RECONNECTION_DURATION; while (!connectionSucceeded) { try { - MQTTEventAdapterConstants.initialReconnectDuration = MQTTEventAdapterConstants.initialReconnectDuration - * MQTTEventAdapterConstants.reconnectionProgressionFactor; - Thread.sleep(MQTTEventAdapterConstants.initialReconnectDuration); + connectionDuration = connectionDuration * MQTTEventAdapterConstants.RECONNECTION_PROGRESS_FACTOR; + Thread.sleep(connectionDuration); startListener(); connectionSucceeded = true; log.info("MQTT Connection successful"); diff --git a/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.input.adapter.mqtt/src/main/java/org/wso2/carbon/device/mgt/iot/input/adapter/mqtt/util/MQTTEventAdapterConstants.java b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.input.adapter.mqtt/src/main/java/org/wso2/carbon/device/mgt/iot/input/adapter/mqtt/util/MQTTEventAdapterConstants.java index 88ac43171..1ac0ee949 100644 --- a/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.input.adapter.mqtt/src/main/java/org/wso2/carbon/device/mgt/iot/input/adapter/mqtt/util/MQTTEventAdapterConstants.java +++ b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.input.adapter.mqtt/src/main/java/org/wso2/carbon/device/mgt/iot/input/adapter/mqtt/util/MQTTEventAdapterConstants.java @@ -47,8 +47,8 @@ public class MQTTEventAdapterConstants { public static final String ADAPTER_CONF_KEEP_ALIVE = "keepAlive"; public static final int ADAPTER_CONF_DEFAULT_KEEP_ALIVE = 60000; - public static int initialReconnectDuration = 2000; - public static final int reconnectionProgressionFactor = 2; + public static final int INITIAL_RECONNECTION_DURATION = 4000; + public static final int RECONNECTION_PROGRESS_FACTOR = 2; public static final String EMPTY_STRING = ""; public static final String GRANT_TYPE = "urn:ietf:params:oauth:grant-type:jwt-bearer refresh_token"; diff --git a/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.input.adapter.xmpp/src/main/java/org/wso2/carbon/device/mgt/iot/input/adapter/xmpp/util/XMPPAdapterListener.java b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.input.adapter.xmpp/src/main/java/org/wso2/carbon/device/mgt/iot/input/adapter/xmpp/util/XMPPAdapterListener.java index bf5c6fde8..168b9e6a8 100644 --- a/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.input.adapter.xmpp/src/main/java/org/wso2/carbon/device/mgt/iot/input/adapter/xmpp/util/XMPPAdapterListener.java +++ b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.input.adapter.xmpp/src/main/java/org/wso2/carbon/device/mgt/iot/input/adapter/xmpp/util/XMPPAdapterListener.java @@ -203,10 +203,10 @@ public class XMPPAdapterListener implements Runnable { @Override public void run() { while (!connectionSucceeded) { + int connectionDuration = XMPPEventAdapterConstants.INITIAL_RECONNECTION_DURATION; try { - XMPPEventAdapterConstants.initialReconnectDuration = XMPPEventAdapterConstants.initialReconnectDuration - * XMPPEventAdapterConstants.reconnectionProgressionFactor; - Thread.sleep(XMPPEventAdapterConstants.initialReconnectDuration); + connectionDuration = connectionDuration * XMPPEventAdapterConstants.RECONNECTION_PROGRESS_FACTOR; + Thread.sleep(connectionDuration); startListener(); connectionSucceeded = true; log.info("XMPP Connection successful"); diff --git a/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.input.adapter.xmpp/src/main/java/org/wso2/carbon/device/mgt/iot/input/adapter/xmpp/util/XMPPEventAdapterConstants.java b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.input.adapter.xmpp/src/main/java/org/wso2/carbon/device/mgt/iot/input/adapter/xmpp/util/XMPPEventAdapterConstants.java index 8f94f96ac..d823d8ba1 100644 --- a/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.input.adapter.xmpp/src/main/java/org/wso2/carbon/device/mgt/iot/input/adapter/xmpp/util/XMPPEventAdapterConstants.java +++ b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.input.adapter.xmpp/src/main/java/org/wso2/carbon/device/mgt/iot/input/adapter/xmpp/util/XMPPEventAdapterConstants.java @@ -49,8 +49,8 @@ public class XMPPEventAdapterConstants { public static final int DEFAULT_XMPP_PORT = 5222; public static final int DEFAULT_TIMEOUT_INTERVAL = 5000; - public static int initialReconnectDuration = 10000; - public static final int reconnectionProgressionFactor = 2; + public static int INITIAL_RECONNECTION_DURATION = 4000; + public static final int RECONNECTION_PROGRESS_FACTOR = 2; public static final String DEFAULT = "default"; diff --git a/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.ui/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.operation-bar/public/js/operation-bar.js b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.ui/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.operation-bar/public/js/operation-bar.js index 514508077..68bb7f5f1 100644 --- a/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.ui/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.operation-bar/public/js/operation-bar.js +++ b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.ui/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.operation-bar/public/js/operation-bar.js @@ -61,9 +61,15 @@ function submitForm(formId) { var statusIcon = content.find("#status-icon"); var description = content.find("#description"); var successCallBack = function (response) { - title.html("Response Received!"); - statusIcon.attr("class", defaultStatusClasses + " fw-success"); - description.html(response); + var res = response; + try { + res = JSON.parse(response).messageFromServer; + } catch (err) { + //do nothing + } + title.html("Operation Triggered!"); + statusIcon.attr("class", defaultStatusClasses + " fw-check"); + description.html(res); $(modalPopupContent).html(content.html()); }; var errorCallBack = function (response) { @@ -94,9 +100,9 @@ function submitForm(formId) { $(document).on('submit', 'form', function (e) { e.preventDefault(); var postOperationRequest = $.ajax({ - url: $(this).attr("action") + '&' + $(this).serialize(), - method: "post" - }); + url: $(this).attr("action") + '&' + $(this).serialize(), + method: "post" + }); var btnSubmit = $('#btnSend', this); btnSubmit.addClass('hidden'); diff --git a/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.ui/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.policy.wizard/public/js/policy-create.js b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.ui/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.policy.wizard/public/js/policy-create.js index 84e988643..4c838a1c4 100644 --- a/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.ui/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.policy.wizard/public/js/policy-create.js +++ b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.ui/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.policy.wizard/public/js/policy-create.js @@ -73,7 +73,6 @@ validateStep["policy-profile"] = function () { }; stepForwardFrom["policy-profile"] = function () { - policy["profile"] = operationModule.generateProfile(policy["platform"], configuredOperations); // updating next-page wizard title with selected platform $("#policy-criteria-page-wizard-title").text("ADD " + deviceTypeLabel + " POLICY"); }; @@ -105,6 +104,8 @@ stepForwardFrom["policy-criteria"] = function () { policy["selectedUsers"] = $("#users-input").val(); } else if ($(this).attr("id") == "user-roles-radio-btn") { policy["selectedUserRoles"] = $("#user-roles-input").val(); + } else if ($(this).attr("id") == "groups-radio-btn") { + policy["selectedUserGroups"] = $("#groups-input").val(); } } } @@ -247,12 +248,15 @@ var savePolicy = function (policy, state) { invokerUtil.post( serviceURL, payload, - function () { - $(".add-policy").addClass("hidden"); - $(".policy-naming").addClass("hidden"); - $(".policy-message").removeClass("hidden"); - if (state == "publish") { - publishToDevice(); + function (response) { + response = JSON.parse(response); + if (response["statusCode"] == 201) { + $(".add-policy").addClass("hidden"); + $(".policy-naming").addClass("hidden"); + $(".policy-message").removeClass("hidden"); + if (state == "publish") { + publishToDevice(); + } } }, function (err) { @@ -351,6 +355,31 @@ function formatRepoSelection(user) { return user.username || user.text; } +function formatGroupRepo(group) { + if (group.loading) { + return group.text + } + if (!group.name) { + return; + } + var markup = '
' + + '
' + + '
' + + '
' + group.name + '
'; + if (group.name) { + markup += '
' + group.name + '
'; + } + if (group.owner) { + markup += '
' + group.owner + '
'; + } + markup += '
'; + return markup; +} + +function formatGroupRepoSelection(group) { + return group.name || group.text; +} + // End of functions related to grid-input-view @@ -372,46 +401,85 @@ $(document).ready(function () { }); $("#users-input").select2({ - multiple: true, - tags: true, - ajax: { - url: window.location.origin + "/devicemgt/api/invoker/execute/", - method: "POST", - dataType: 'json', - delay: 250, - id: function (user) { - return user.username; - }, - data: function (params) { - var postData = {}; - postData.actionMethod = "GET"; - postData.actionUrl = "/devicemgt_admin/users"; - postData.actionPayload = JSON.stringify({ - q: params.term, // search term - page: params.page - }); - - return JSON.stringify(postData); - }, - processResults: function (data, page) { - var newData = []; - $.each(data.responseContent, function (index, value) { - value.id = value.username; - newData.push(value); - }); - return { - results: newData - }; - }, - cache: true - }, - escapeMarkup: function (markup) { - return markup; - }, // let our custom formatter work - minimumInputLength: 1, - templateResult: formatRepo, // omitted for brevity, see the source of this page - templateSelection: formatRepoSelection // omitted for brevity, see the source of this page - }); + multiple: true, + tags: true, + ajax: { + url: window.location.origin + "/devicemgt/api/invoker/execute/", + method: "POST", + dataType: 'json', + delay: 250, + id: function (user) { + return user.username; + }, + data: function (params) { + var postData = {}; + postData.actionMethod = "GET"; + postData.actionUrl = "/devicemgt_admin/users"; + postData.actionPayload = JSON.stringify({ + q: params.term, // search term + page: params.page + }); + + return JSON.stringify(postData); + }, + processResults: function (data, page) { + var newData = []; + $.each(data.responseContent, function (index, value) { + value.id = value.username; + newData.push(value); + }); + return { + results: newData + }; + }, + cache: true + }, + escapeMarkup: function (markup) { + return markup; + }, // let our custom formatter work + minimumInputLength: 1, + templateResult: formatRepo, // omitted for brevity, see the source of this page + templateSelection: formatRepoSelection // omitted for brevity, see the source of this page + }); + + $("#groups-input").select2({ + multiple: true, + tags: true, + ajax: { + url: window.location.origin + "/devicemgt/api/invoker/execute/", + method: "POST", + dataType: 'json', + delay: 250, + id: function (group) { + return group.name; + }, + data: function (params) { + var postData = {}; + postData.actionMethod = "GET"; + var username = $("#platform").data("username"); + postData.actionUrl = "/devicemgt_admin/groups/user/" + username + + "/search?groupName=" + params.term; + return JSON.stringify(postData); + }, + processResults: function (data, page) { + var newData = []; + $.each(data, function (index, value) { + value.id = value.name; + newData.push(value); + }); + return { + results: newData + }; + }, + cache: true + }, + escapeMarkup: function (markup) { + return markup; + }, // let our custom formatter work + minimumInputLength: 1, + templateResult: formatGroupRepo, // omitted for brevity, see the source of this page + templateSelection: formatGroupRepoSelection // omitted for brevity, see the source of this page + }); // Adding initial state of wizard-steps. $("#policy-profile-wizard-steps").html($(".wr-steps").html()); @@ -427,16 +495,24 @@ $(document).ready(function () { }); $("#users-select-field").hide(); + $("#groups-select-field").hide(); $("#user-roles-select-field").show(); $("input[type='radio'].select-users-radio").change(function () { + if ($("#user-roles-radio-btn").is(":checked")) { + $("#user-roles-select-field").show(); + $("#users-select-field").hide(); + $("#groups-select-field").hide(); + } if ($("#users-radio-btn").is(":checked")) { $("#user-roles-select-field").hide(); $("#users-select-field").show(); + $("#groups-select-field").hide(); } - if ($("#user-roles-radio-btn").is(":checked")) { + if ($("#groups-radio-btn").is(":checked")) { + $("#user-roles-select-field").hide(); $("#users-select-field").hide(); - $("#user-roles-select-field").show(); + $("#groups-select-field").show(); } }); @@ -657,7 +733,9 @@ $(document).ready(function () { // hiding current section of the wizard and showing next section. $("." + currentStep).addClass("hidden"); - $("." + nextStep).removeClass("hidden"); + if (nextStep !== "policy-message") { + $("." + nextStep).removeClass("hidden"); + } } }); }); diff --git a/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.ui/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.policy.wizard/wizard.hbs b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.ui/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.policy.wizard/wizard.hbs index 4cc6fa272..1c661f000 100644 --- a/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.ui/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.policy.wizard/wizard.hbs +++ b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.ui/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.policy.wizard/wizard.hbs @@ -2,7 +2,7 @@ {{css "css/codemirror.css"}} {{/zone}} + data-platform-label="{{type.label}}" data-username="{{username}}">