From 617849c053d3807550dfbef0281b092394623612 Mon Sep 17 00:00:00 2001 From: dilanua Date: Wed, 7 Sep 2016 16:24:17 +0530 Subject: [PATCH 1/2] Updating policy UIs with API method updates --- .../app/pages/mdm.page.policies/public/js/policy-list.js | 4 ++-- .../app/units/mdm.unit.policy.edit/public/js/edit.js | 4 ++-- .../app/units/mdm.unit.policy.view/public/js/view.js | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/mdm.page.policies/public/js/policy-list.js b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/mdm.page.policies/public/js/policy-list.js index 978d6f0bd7..763d70245e 100644 --- a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/mdm.page.policies/public/js/policy-list.js +++ b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/mdm.page.policies/public/js/policy-list.js @@ -215,7 +215,7 @@ $(document).ready(function () { // on-click function for policy un-publishing "yes" button $("a#unpublish-policy-yes-link").click(function () { - invokerUtil.put( + invokerUtil.post( serviceURL, policyList, // on success @@ -268,7 +268,7 @@ $(document).ready(function () { // on-click function for policy removing "yes" button $("a#publish-policy-yes-link").click(function () { - invokerUtil.put( + invokerUtil.post( serviceURL, policyList, // on success diff --git a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.policy.edit/public/js/edit.js b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.policy.edit/public/js/edit.js index 89252aaf16..d347446a3a 100644 --- a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.policy.edit/public/js/edit.js +++ b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.policy.edit/public/js/edit.js @@ -2038,7 +2038,7 @@ var updatePolicy = function (policy, state) { policyList.push(getParameterByName("id")); if (state == "save") { serviceURL = "/api/device-mgt/v1.0/policies/deactivate-policy"; - invokerUtil.put( + invokerUtil.post( serviceURL, policyList, // on success @@ -2055,7 +2055,7 @@ var updatePolicy = function (policy, state) { ); } else if (state == "publish") { serviceURL = "/api/device-mgt/v1.0/policies/activate-policy"; - invokerUtil.put( + invokerUtil.post( serviceURL, policyList, // on success diff --git a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.policy.view/public/js/view.js b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.policy.view/public/js/view.js index cbb4d7a586..703b523ea2 100644 --- a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.policy.view/public/js/view.js +++ b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.policy.view/public/js/view.js @@ -1824,7 +1824,7 @@ var updatePolicy = function (policy, state) { var policyList = []; policyList.push(getParameterByName("id")); serviceURL = base_api_url + "/policies/deactivate-policy"; - invokerUtil.put( + invokerUtil.post( serviceURL, policyList, // on success @@ -1841,7 +1841,7 @@ var updatePolicy = function (policy, state) { var policyList = []; policyList.push(getParameterByName("id")); serviceURL = base_api_url + "/policies/activate-policy"; - invokerUtil.put( + invokerUtil.post( serviceURL, policyList, // on success From bfba00821819b3af5b4b43e92f6ab9fd985abd9a Mon Sep 17 00:00:00 2001 From: charitha Date: Thu, 8 Sep 2016 10:17:13 +0530 Subject: [PATCH 2/2] Removed url from application uninstall (cherry picked from commit 45a582e) --- .../bean/ApplicationUninstallation.java | 11 ------ .../DeviceManagementAdminServiceImpl.java | 39 +++++++++++-------- 2 files changed, 23 insertions(+), 27 deletions(-) diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/ApplicationUninstallation.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/ApplicationUninstallation.java index 45b98b47d6..5c078f87db 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/ApplicationUninstallation.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/ApplicationUninstallation.java @@ -43,9 +43,6 @@ public class ApplicationUninstallation extends AndroidOperation implements Seria @Pattern(regexp = "^[A-Za-z]*$") private String type; - @ApiModelProperty(name = "url", value = "The URL of the application.", required = true) - private String url; - @ApiModelProperty(name = "name", value = "The name of the application.", required = true) @Size(min = 2, max = 45) private String name; @@ -66,14 +63,6 @@ public class ApplicationUninstallation extends AndroidOperation implements Seria this.type = type; } - public String getUrl() { - return url; - } - - public void setUrl(String url) { - this.url = url; - } - public String getName() { return name; } diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/impl/DeviceManagementAdminServiceImpl.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/impl/DeviceManagementAdminServiceImpl.java index 8442d44c7d..11840a6697 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/impl/DeviceManagementAdminServiceImpl.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/impl/DeviceManagementAdminServiceImpl.java @@ -558,22 +558,7 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe throw new BadRequestException( new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); } - if (payload.has("type")) { - String type = payload.getString("type"); - if (!"enterprise".equalsIgnoreCase(type) - && !"public".equalsIgnoreCase(type) - && !"webapp".equalsIgnoreCase(type)) { - String errorMessage = "Invalid application type."; - log.error(errorMessage); - throw new BadRequestException( - new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); - } - } else { - String errorMessage = "Application type is missing."; - log.error(errorMessage); - throw new BadRequestException( - new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); - } + validateType(payload); } catch (MalformedURLException e) { String errorMessage = "Malformed application url."; log.error(errorMessage); @@ -673,6 +658,9 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); } ApplicationUninstallation applicationUninstallation = applicationUninstallationBeanWrapper.getOperation(); + JSONObject payload = new JSONObject(applicationUninstallation.toJSON()); + validateType(payload); + ProfileOperation operation = new ProfileOperation(); operation.setCode(AndroidConstants.OperationCodes.UNINSTALL_APPLICATION); operation.setType(Operation.Type.PROFILE); @@ -698,6 +686,25 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe } } + private void validateType(JSONObject payload) { + if (payload.has("type")) { + String type = payload.getString("type"); + if (!"enterprise".equalsIgnoreCase(type) + && !"public".equalsIgnoreCase(type) + && !"webapp".equalsIgnoreCase(type)) { + String errorMessage = "Invalid application type."; + log.error(errorMessage); + throw new BadRequestException( + new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + } + } else { + String errorMessage = "Application type is missing."; + log.error(errorMessage); + throw new BadRequestException( + new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + } + } + @POST @Path("/blacklist-applications") @Override