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/BlacklistApplications.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/BlacklistApplications.java index 97c1ae5dee..c37417ac61 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/BlacklistApplications.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/BlacklistApplications.java @@ -21,7 +21,6 @@ package org.wso2.carbon.mdm.services.android.bean; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; -import javax.validation.constraints.Pattern; import javax.validation.constraints.Size; import java.io.Serializable; import java.util.List; @@ -36,7 +35,6 @@ public class BlacklistApplications extends AndroidOperation implements Serializa @ApiModelProperty(name = "appIdentifiers", value = "A list of application package names to be blacklisted.", required = true) @Size(min = 2, max = 45) - @Pattern(regexp = "^[A-Za-z0-9]*$") private List appIdentifiers; public List getAppIdentifier() { 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/wrapper/BlacklistApplicationsBeanWrapper.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/wrapper/BlacklistApplicationsBeanWrapper.java index 3abf32c22c..32b107bf46 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/wrapper/BlacklistApplicationsBeanWrapper.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/wrapper/BlacklistApplicationsBeanWrapper.java @@ -32,16 +32,15 @@ import java.util.List; public class BlacklistApplicationsBeanWrapper { @ApiModelProperty(name = "operation", value = "Blacklist applications information", required = true) - @Valid - private BlacklistApplications operation; + private @Valid BlacklistApplications operation; @ApiModelProperty(name = "deviceIDs", value = "List of device Ids", required = true) private List deviceIDs; - public BlacklistApplications getOperation() { + public @Valid BlacklistApplications getOperation() { return operation; } - public void setOperation(BlacklistApplications operation) { + public void setOperation(@Valid BlacklistApplications operation) { this.operation = operation; } 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/wrapper/VpnBeanWrapper.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/wrapper/VpnBeanWrapper.java index 26d1913b36..e71270d229 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/wrapper/VpnBeanWrapper.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/wrapper/VpnBeanWrapper.java @@ -21,8 +21,6 @@ import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import org.wso2.carbon.mdm.services.android.bean.Vpn; -import javax.validation.constraints.Pattern; -import javax.validation.constraints.Size; import java.util.List; /** @@ -36,8 +34,6 @@ public class VpnBeanWrapper { private Vpn operation; @ApiModelProperty(name = "deviceIDs", value = "List of device Ids to be need to execute VPN operation.", required = true) - @Size(min = 2, max = 45) - @Pattern(regexp = "^[A-Za-z0-9]*$") private List deviceIDs; public Vpn getOperation() { 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/exception/GlobalThrowableMapper.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/exception/GlobalThrowableMapper.java index 631c3e6ae6..6a7d45afb1 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/exception/GlobalThrowableMapper.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/exception/GlobalThrowableMapper.java @@ -105,9 +105,7 @@ public class GlobalThrowableMapper implements ExceptionMapper { return ((ForbiddenException) e).getResponse(); } //unknown exception log and return - if (log.isDebugEnabled()) { log.error("An Unknown exception has been captured by global exception mapper.", e); - } return Response.status(Response.Status.INTERNAL_SERVER_ERROR).header("Content-Type", "application/json") .entity(e500).build(); } 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/DeviceManagementAdminService.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/DeviceManagementAdminService.java index a23eedb331..d923e49bde 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/DeviceManagementAdminService.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/DeviceManagementAdminService.java @@ -24,6 +24,7 @@ import org.wso2.carbon.apimgt.annotations.api.Scope; import org.wso2.carbon.device.mgt.common.operation.mgt.Activity; import org.wso2.carbon.mdm.services.android.bean.wrapper.*; +import javax.validation.Valid; import javax.ws.rs.Consumes; import javax.ws.rs.POST; import javax.ws.rs.Path; @@ -961,7 +962,7 @@ public interface DeviceManagementAdminService { Response blacklistApplications( @ApiParam(name = "blacklistApplicationsBeanWrapper", value = "BlacklistApplications " + "Configuration and DeviceIds") - BlacklistApplicationsBeanWrapper blacklistApplicationsBeanWrapper); + @Valid BlacklistApplicationsBeanWrapper blacklistApplicationsBeanWrapper); @POST @Path("/upgrade-firmware") 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 20283b727f..b5eecd3e78 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 @@ -25,43 +25,15 @@ import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException; import org.wso2.carbon.device.mgt.core.operation.mgt.CommandOperation; import org.wso2.carbon.device.mgt.core.operation.mgt.ProfileOperation; -import org.wso2.carbon.mdm.services.android.bean.ApplicationInstallation; -import org.wso2.carbon.mdm.services.android.bean.ApplicationUninstallation; -import org.wso2.carbon.mdm.services.android.bean.ApplicationUpdate; -import org.wso2.carbon.mdm.services.android.bean.BlacklistApplications; -import org.wso2.carbon.mdm.services.android.bean.Camera; -import org.wso2.carbon.mdm.services.android.bean.DeviceEncryption; -import org.wso2.carbon.mdm.services.android.bean.DeviceLock; -import org.wso2.carbon.mdm.services.android.bean.ErrorResponse; -import org.wso2.carbon.mdm.services.android.bean.LockCode; -import org.wso2.carbon.mdm.services.android.bean.Notification; -import org.wso2.carbon.mdm.services.android.bean.PasscodePolicy; -import org.wso2.carbon.mdm.services.android.bean.UpgradeFirmware; -import org.wso2.carbon.mdm.services.android.bean.Vpn; -import org.wso2.carbon.mdm.services.android.bean.WebClip; -import org.wso2.carbon.mdm.services.android.bean.Wifi; -import org.wso2.carbon.mdm.services.android.bean.WipeData; -import org.wso2.carbon.mdm.services.android.bean.wrapper.ApplicationInstallationBeanWrapper; -import org.wso2.carbon.mdm.services.android.bean.wrapper.ApplicationUninstallationBeanWrapper; -import org.wso2.carbon.mdm.services.android.bean.wrapper.ApplicationUpdateBeanWrapper; -import org.wso2.carbon.mdm.services.android.bean.wrapper.BlacklistApplicationsBeanWrapper; -import org.wso2.carbon.mdm.services.android.bean.wrapper.CameraBeanWrapper; -import org.wso2.carbon.mdm.services.android.bean.wrapper.DeviceLockBeanWrapper; -import org.wso2.carbon.mdm.services.android.bean.wrapper.EncryptionBeanWrapper; -import org.wso2.carbon.mdm.services.android.bean.wrapper.LockCodeBeanWrapper; -import org.wso2.carbon.mdm.services.android.bean.wrapper.NotificationBeanWrapper; -import org.wso2.carbon.mdm.services.android.bean.wrapper.PasswordPolicyBeanWrapper; -import org.wso2.carbon.mdm.services.android.bean.wrapper.UpgradeFirmwareBeanWrapper; -import org.wso2.carbon.mdm.services.android.bean.wrapper.VpnBeanWrapper; -import org.wso2.carbon.mdm.services.android.bean.wrapper.WebClipBeanWrapper; -import org.wso2.carbon.mdm.services.android.bean.wrapper.WifiBeanWrapper; -import org.wso2.carbon.mdm.services.android.bean.wrapper.WipeDataBeanWrapper; +import org.wso2.carbon.mdm.services.android.bean.*; +import org.wso2.carbon.mdm.services.android.bean.wrapper.*; import org.wso2.carbon.mdm.services.android.exception.BadRequestException; import org.wso2.carbon.mdm.services.android.exception.UnexpectedServerErrorException; import org.wso2.carbon.mdm.services.android.services.DeviceManagementAdminService; import org.wso2.carbon.mdm.services.android.util.AndroidAPIUtils; import org.wso2.carbon.mdm.services.android.util.AndroidConstants; +import javax.validation.Valid; import javax.ws.rs.Consumes; import javax.ws.rs.POST; import javax.ws.rs.Path; @@ -556,7 +528,7 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe @POST @Path("/blacklist-applications") @Override - public Response blacklistApplications(BlacklistApplicationsBeanWrapper blacklistApplicationsBeanWrapper) { + public Response blacklistApplications(@Valid BlacklistApplicationsBeanWrapper blacklistApplicationsBeanWrapper) { if (log.isDebugEnabled()) { log.debug("Invoking 'Blacklist-Applications' operation"); } 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.device.view/view.hbs b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.device.view/view.hbs index 1eb7f0e3c0..59c6de171c 100644 --- a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.device.view/view.hbs +++ b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.device.view/view.hbs @@ -1,19 +1,20 @@ -{{#zone "content"}} - {{#defineZone "device-detail-top"}} -
-
-
+{{/zone}} + +{{#zone "content"}}
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.ui.navbar.nav-menu/nav-menu.hbs b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.ui.navbar.nav-menu/nav-menu.hbs index a89cb00316..b4c15eea3c 100644 --- a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.ui.navbar.nav-menu/nav-menu.hbs +++ b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.ui.navbar.nav-menu/nav-menu.hbs @@ -104,7 +104,7 @@ {{/zone}} {{#zone "bottomJs"}} {{js "js/nav-menu.js"}} {{/zone}} 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.ui.navbar.nav-menu/public/js/nav-menu.js b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.ui.navbar.nav-menu/public/js/nav-menu.js index c15f80b268..5015563a9b 100644 --- a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.ui.navbar.nav-menu/public/js/nav-menu.js +++ b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.ui.navbar.nav-menu/public/js/nav-menu.js @@ -22,6 +22,15 @@ var modalPopup = ".wr-modalpopup", var emmAdminBasePath = "/api/device-mgt/v1.0"; +//function openCollapsedNav() { +// $(".wr-hidden-nav-toggle-btn").addClass("active"); +// $("#hiddenNav").slideToggle("slideDown", function () { +// if ($(this).css("display") == "none") { +// $(".wr-hidden-nav-toggle-btn").removeClass("active"); +// } +// }); +//} + /* * set popup maximum height function. */ @@ -50,74 +59,93 @@ function hidePopup() { $(modalPopup).hide(); } -var updateNotificationCount = function (data, textStatus, jqXHR) { +/* + * QR-code generation function. + */ +function generateQRCode(qrCodeClass) { + var enrollmentURL = $("#qr-code-modal").data("enrollment-url"); + $(qrCodeClass).qrcode({ + text: enrollmentURL, + width: 200, + height: 200 + }); +} + +function toggleEnrollment() { + $(".modalpopup-content").html($("#qr-code-modal").html()); + generateQRCode(".modalpopup-content .qr-code"); + showPopup(); +} + +var updateNotificationCountOnSuccess = function (data, textStatus, jqXHR) { + var notificationBubble = "#notification-bubble"; if (jqXHR.status == 200 && data) { var responsePayload = JSON.parse(data); - var newNotificationsCount = responsePayload.count; + var newNotificationsCount = responsePayload["count"]; if (newNotificationsCount > 0) { - $("#notification-bubble").html(newNotificationsCount); + $(notificationBubble).html(newNotificationsCount); + $(notificationBubble).show(); + } else { + $(notificationBubble).hide(); } -// } else { -// $("#notification-bubble").html("Error"); -// } } }; -function loadNotificationsPanel() { - if ("true" == $("#right-sidebar").attr("is-authorized")) { - var serviceURL = emmAdminBasePath + "/notifications?status=NEW"; - invokerUtil.get(serviceURL, updateNotificationCount, hideNotificationCount); - loadNewNotifications(); - } else { - $("#notification-bubble-wrapper").remove(); - } +function updateNotificationCountOnError() { + var notificationBubble = "#notification-bubble"; + $(notificationBubble).html("Error"); + $(notificationBubble).show(); } -function hideNotificationCount(jqXHR) { - if (jqXHR.status == 404) { - // this means "no new notifications to show" - $("#notification-bubble").hide(); +function loadNewNotificationsOnSideViewPanel() { + if ($("#right-sidebar").attr("is-authorized") == "false") { + $("#notification-bubble-wrapper").remove(); } else { - $("#notification-bubble").html("Error"); + var serviceURL = emmAdminBasePath + "/notifications?status=NEW"; + invokerUtil.get(serviceURL, updateNotificationCountOnSuccess, updateNotificationCountOnError); + loadNewNotifications(); } } function loadNewNotifications() { var messageSideBar = ".sidebar-messages"; - if ($("#right-sidebar").attr("is-authorized") == "true") { + if ($("#right-sidebar").attr("is-authorized") == "false") { + $(messageSideBar).html("

You are not authorized to view notifications.

"); + } else { var notifications = $("#notifications"); var currentUser = notifications.data("currentUser"); $.template("notification-listing", notifications.attr("src"), function (template) { var serviceURL = emmAdminBasePath + "/notifications?status=NEW"; - - var successCallback = function (data, textStatus, jqXHR) { - if (jqXHR.status == 200 && data) { - var viewModel = {}; - var responsePayload = JSON.parse(data); - - if (responsePayload.notifications) { - viewModel.notifications = responsePayload.notifications; - if (responsePayload.count > 0) { - $(messageSideBar).html(template(viewModel)); + invokerUtil.get( + serviceURL, + // on success + function (data, textStatus, jqXHR) { + if (jqXHR.status == 200 && data) { + var viewModel = {}; + var responsePayload = JSON.parse(data); + if (responsePayload["notifications"]) { + if (responsePayload.count > 0) { + viewModel["notifications"] = responsePayload["notifications"]; + $(messageSideBar).html(template(viewModel)); + } else { + $(messageSideBar).html("

No new notifications found...

"); + } } else { - $(messageSideBar).html("

No new notifications found...

"); + $(messageSideBar).html("

Unexpected error " + + "occurred while loading new notifications.

"); } - } else { - $(messageSideBar).html("

Unexpected error occurred while loading new notifications.

"); + } + }, + // on error + function (jqXHR) { + if (jqXHR.status = 500) { + $(messageSideBar).html("

Unexpected error occurred while trying " + + "to retrieve any new notifications.

"); } } - }; - var errorCallback = function (jqXHR) { - if (jqXHR.status = 500) { - $(messageSideBar).html("

Unexpected error occurred while trying " + - "to retrieve any new notifications.

"); - } - }; - invokerUtil.get(serviceURL, successCallback, errorCallback); + ); }); - } else { - $(messageSideBar).html("

You are not authorized to view notifications

"); } } @@ -178,8 +206,7 @@ $.sidebar_toggle = function (action, target, container) { if (buttonParent.is('li')) { if (relationship !== '') { $(elem + '[rel=' + relationship + ']:not([data-handle=close])').parent().removeClass("active"); - $(elem + '[rel=' + relationship + ']:not([data-handle=close])').parent(). - attr('aria-expanded', 'false'); + $(elem + '[rel=' + relationship + ']:not([data-handle=close])').parent().attr('aria-expanded', 'false'); } buttonParent.addClass("active"); buttonParent.attr('aria-expanded', 'true'); @@ -217,8 +244,7 @@ $.sidebar_toggle = function (action, target, container) { if ($(button).parent().is('li')) { if (relationship !== '') { $(elem + '[rel=' + relationship + ']:not([data-handle=close])').parent().removeClass("active"); - $(elem + '[rel=' + relationship + ']:not([data-handle=close])').parent(). - attr('aria-expanded', 'false'); + $(elem + '[rel=' + relationship + ']:not([data-handle=close])').parent().attr('aria-expanded', 'false'); } } } @@ -317,24 +343,32 @@ $.fn.collapse_nav_sub = function () { }; $(document).ready(function () { - loadNotificationsPanel(); $.sidebar_toggle(); + if (typeof $.fn.collapse == 'function') { + $('.navbar-collapse.tiles').on('shown.bs.collapse', function () { + $(this).collapse_nav_sub(); + }); + } + loadNewNotificationsOnSideViewPanel(); $("#right-sidebar").on("click", ".new-notification", function () { var notificationId = $(this).data("id"); var redirectUrl = $(this).data("url"); - var markAsReadNotificationsAPI = "/mdm-admin/notifications/" + notificationId + "/CHECKED"; + var markAsReadNotificationsEpr = emmAdminBasePath + "/notifications/" + notificationId + "/mark-checked"; var messageSideBar = ".sidebar-messages"; invokerUtil.put( - markAsReadNotificationsAPI, + markAsReadNotificationsEpr, null, + // on success function (data) { data = JSON.parse(data); if (data.statusCode == responseCodes["ACCEPTED"]) { location.href = redirectUrl; } - }, function () { + }, + // on error + function () { var content = "
  • Warning

    " + "

    Unexpected error occurred while loading notification. Please refresh the page and" + " try again

  • "; @@ -342,10 +376,4 @@ $(document).ready(function () { } ); }); - - if (typeof $.fn.collapse == 'function') { - $('.navbar-collapse.tiles').on('shown.bs.collapse', function () { - $(this).collapse_nav_sub(); - }); - } }); diff --git a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/mdm/mobileservices/windows/services/devicemgtservice/DeviceManagementService.java b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/mdm/mobileservices/windows/services/devicemgtservice/DeviceManagementService.java index ee83cc53ff..db2ce7fc34 100644 --- a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/mdm/mobileservices/windows/services/devicemgtservice/DeviceManagementService.java +++ b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/mdm/mobileservices/windows/services/devicemgtservice/DeviceManagementService.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. * * WSO2 Inc. licenses this file to you under the Apache License, * Version 2.0 (the "License"); you may not use this file except @@ -18,21 +18,14 @@ package org.wso2.carbon.mdm.mobileservices.windows.services.devicemgtservice; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.wso2.carbon.device.mgt.common.Device; -import org.wso2.carbon.device.mgt.common.DeviceIdentifier; -import org.wso2.carbon.device.mgt.common.DeviceManagementConstants; -import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.common.license.mgt.License; import org.wso2.carbon.mdm.mobileservices.windows.common.exceptions.WindowsConfigurationException; import org.wso2.carbon.mdm.mobileservices.windows.common.util.Message; -import org.wso2.carbon.mdm.mobileservices.windows.common.util.WindowsAPIUtils; import javax.jws.WebService; import javax.ws.rs.*; import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; import java.util.List; /** @@ -40,11 +33,10 @@ import java.util.List; * All end points supports JSON, XMl with content negotiation. */ @WebService +@Path("/devices") @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) @Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) -public class DeviceManagementService { - - private static Log log = LogFactory.getLog(DeviceManagementService.class); +public interface DeviceManagementService { /** * Get all devices.Returns list of Windows devices registered in MDM. @@ -53,19 +45,7 @@ public class DeviceManagementService { * @throws WindowsConfigurationException occurred while retrieving all the devices from DB. */ @GET - public List getAllDevices() throws WindowsConfigurationException { - String msg; - List devices; - try { - devices = WindowsAPIUtils.getDeviceManagementService(). - getAllDevices(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS); - } catch (DeviceManagementException e) { - msg = "Error occurred while fetching the device list."; - log.error(msg, e); - throw new WindowsConfigurationException(msg, e); - } - return devices; - } + List getAllDevices() throws WindowsConfigurationException; /** * Fetch Windows device details of a given device Id. @@ -76,22 +56,7 @@ public class DeviceManagementService { */ @GET @Path("{id}") - public Device getDevice(@PathParam("id") String id) throws WindowsConfigurationException { - String msg; - Device device; - try { - DeviceIdentifier deviceIdentifier = WindowsAPIUtils.convertToDeviceIdentifierObject(id); - device = WindowsAPIUtils.getDeviceManagementService().getDevice(deviceIdentifier); - if (device == null) { - Response.status(Response.Status.NOT_FOUND); - } - } catch (DeviceManagementException e) { - msg = "Error occurred while fetching the device information."; - log.error(msg, e); - throw new WindowsConfigurationException(msg, e); - } - return device; - } + Device getDevice(@PathParam("id") String id) throws WindowsConfigurationException; /** * Update Windows device details of given device id. @@ -103,31 +68,7 @@ public class DeviceManagementService { */ @PUT @Path("{id}") - public Message updateDevice(@PathParam("id") String id, Device device) throws WindowsConfigurationException { - String msg; - Message responseMessage = new Message(); - DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); - deviceIdentifier.setId(id); - deviceIdentifier.setType(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS); - boolean isUpdated; - try { - device.setType(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS); - isUpdated = WindowsAPIUtils.getDeviceManagementService().updateDeviceInfo(deviceIdentifier, device); - if (isUpdated) { - Response.status(Response.Status.ACCEPTED); - responseMessage.setResponseMessage("Device information has modified successfully."); - } else { - Response.status(Response.Status.NOT_MODIFIED); - responseMessage.setResponseMessage("Device not found for the update."); - } - } catch (DeviceManagementException e) { - msg = "Error occurred while modifying the device information."; - log.error(msg, e); - throw new WindowsConfigurationException(msg, e); - } - return responseMessage; - } - + Message updateDevice(@PathParam("id") String id, Device device) throws WindowsConfigurationException; /** * Fetch the Licence agreement for specific windows platform. * @@ -137,18 +78,5 @@ public class DeviceManagementService { @GET @Path("license") @Produces("application/json") - public License getLicense() throws WindowsConfigurationException { - License license; - try { - license = - WindowsAPIUtils.getDeviceManagementService().getLicense( - DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS, - DeviceManagementConstants.LanguageCodes.LANGUAGE_CODE_ENGLISH_US); - } catch (DeviceManagementException e) { - String msg = "Error occurred while retrieving the license configured for Windows device enrollment"; - log.error(msg, e); - throw new WindowsConfigurationException(msg, e); - } - return license; - } + License getLicense() throws WindowsConfigurationException; } diff --git a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/mdm/mobileservices/windows/services/devicemgtservice/impl/DeviceManagementServiceImpl.java b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/mdm/mobileservices/windows/services/devicemgtservice/impl/DeviceManagementServiceImpl.java new file mode 100644 index 0000000000..0c348b4eca --- /dev/null +++ b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/mdm/mobileservices/windows/services/devicemgtservice/impl/DeviceManagementServiceImpl.java @@ -0,0 +1,156 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.carbon.mdm.mobileservices.windows.services.devicemgtservice.impl; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.device.mgt.common.Device; +import org.wso2.carbon.device.mgt.common.DeviceIdentifier; +import org.wso2.carbon.device.mgt.common.DeviceManagementConstants; +import org.wso2.carbon.device.mgt.common.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.license.mgt.License; +import org.wso2.carbon.mdm.mobileservices.windows.common.exceptions.WindowsConfigurationException; +import org.wso2.carbon.mdm.mobileservices.windows.common.util.Message; +import org.wso2.carbon.mdm.mobileservices.windows.common.util.WindowsAPIUtils; +import org.wso2.carbon.mdm.mobileservices.windows.services.devicemgtservice.DeviceManagementService; + +import javax.jws.WebService; +import javax.ws.rs.*; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import java.util.List; + +/** + * Windows Device Management REST-API implementation. + * All end points supports JSON, XMl with content negotiation. + */ +@WebService +@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) +@Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) +public class DeviceManagementServiceImpl implements DeviceManagementService { + + + private static Log log = LogFactory.getLog(DeviceManagementServiceImpl.class); + + /** + * Get all devices.Returns list of Windows devices registered in MDM. + * + * @return Returns retrieved devices. + * @throws WindowsConfigurationException occurred while retrieving all the devices from DB. + */ + @GET + public List getAllDevices() throws WindowsConfigurationException { + String msg; + List devices; + try { + devices = WindowsAPIUtils.getDeviceManagementService(). + getAllDevices(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS); + } catch (DeviceManagementException e) { + msg = "Error occurred while fetching the device list."; + log.error(msg, e); + throw new WindowsConfigurationException(msg, e); + } + return devices; + } + + /** + * Fetch Windows device details of a given device Id. + * + * @param id Device Id + * @return Returns retrieved device. + * @throws WindowsConfigurationException occurred while getting device from DB. + */ + @GET + @Path("{id}") + public Device getDevice(@PathParam("id") String id) throws WindowsConfigurationException { + String msg; + Device device; + try { + DeviceIdentifier deviceIdentifier = WindowsAPIUtils.convertToDeviceIdentifierObject(id); + device = WindowsAPIUtils.getDeviceManagementService().getDevice(deviceIdentifier); + if (device == null) { + Response.status(Response.Status.NOT_FOUND); + } + } catch (DeviceManagementException e) { + msg = "Error occurred while fetching the device information."; + log.error(msg, e); + throw new WindowsConfigurationException(msg, e); + } + return device; + } + + /** + * Update Windows device details of given device id. + * + * @param id Device Id. + * @param device Device details to be updated. + * @return Returns the message whether device update or not. + * @throws WindowsConfigurationException occurred while updating the Device Info. + */ + @PUT + @Path("{id}") + public Message updateDevice(@PathParam("id") String id, Device device) throws WindowsConfigurationException { + String msg; + Message responseMessage = new Message(); + DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); + deviceIdentifier.setId(id); + deviceIdentifier.setType(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS); + boolean isUpdated; + try { + device.setType(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS); + isUpdated = WindowsAPIUtils.getDeviceManagementService().updateDeviceInfo(deviceIdentifier, device); + if (isUpdated) { + Response.status(Response.Status.ACCEPTED); + responseMessage.setResponseMessage("Device information has modified successfully."); + } else { + Response.status(Response.Status.NOT_MODIFIED); + responseMessage.setResponseMessage("Device not found for the update."); + } + } catch (DeviceManagementException e) { + msg = "Error occurred while modifying the device information."; + log.error(msg, e); + throw new WindowsConfigurationException(msg, e); + } + return responseMessage; + } + + /** + * Fetch the Licence agreement for specific windows platform. + * + * @return Returns License agreement. + * @throws WindowsConfigurationException occurred while getting licence for specific platform and Language. + */ + @GET + @Path("license") + @Produces("application/json") + public License getLicense() throws WindowsConfigurationException { + License license; + try { + license = + WindowsAPIUtils.getDeviceManagementService().getLicense( + DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS, + DeviceManagementConstants.LanguageCodes.LANGUAGE_CODE_ENGLISH_US); + } catch (DeviceManagementException e) { + String msg = "Error occurred while retrieving the license configured for Windows device enrollment"; + log.error(msg, e); + throw new WindowsConfigurationException(msg, e); + } + return license; + } +} diff --git a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/webapp/WEB-INF/cxf-servlet.xml b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/webapp/WEB-INF/cxf-servlet.xml index 117db3174b..e756b20fe7 100644 --- a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/webapp/WEB-INF/cxf-servlet.xml +++ b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/webapp/WEB-INF/cxf-servlet.xml @@ -202,6 +202,6 @@ class="org.wso2.carbon.mdm.mobileservices.windows.services.policymgtservice.PolicyMgtService"/> + class="org.wso2.carbon.mdm.mobileservices.windows.services.devicemgtservice.impl.DeviceManagementServiceImpl"/>