diff --git a/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/test/java/org/wso2/extension/siddhi/device/test/util/TestDeviceManager.java b/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/test/java/org/wso2/extension/siddhi/device/test/util/TestDeviceManager.java index 78197c0ce0..58d8b77493 100644 --- a/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/test/java/org/wso2/extension/siddhi/device/test/util/TestDeviceManager.java +++ b/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/test/java/org/wso2/extension/siddhi/device/test/util/TestDeviceManager.java @@ -63,6 +63,11 @@ public class TestDeviceManager implements DeviceManager { return true; } + @Override + public boolean deleteDevice(DeviceIdentifier deviceId, Device device) throws DeviceManagementException { + return true; + } + @Override public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException { return true; 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/DeviceManagementService.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/DeviceManagementService.java index bb172a6192..59898ff893 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/DeviceManagementService.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/DeviceManagementService.java @@ -15,6 +15,22 @@ * specific language governing permissions and limitations * under the License. * + * + * Copyright (c) 2019, Entgra (pvt) Ltd. (http://entgra.io) All Rights Reserved. + * + * Entgra (Pvt) Ltd. 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.services.android.services; @@ -40,6 +56,7 @@ import javax.ws.rs.PUT; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import java.util.List; @@ -406,6 +423,10 @@ public interface DeviceManagementService { @ApiParam( name = "id", value = "The unique device identifier.") - @PathParam("id") String id); + @PathParam("id") String id, + @ApiParam( + name = "permanentDelete", + value = "Boolean flag indicating whether to permanently delete the device.") + @QueryParam("permanentDelete") boolean permanentDelete); } 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/DeviceManagementServiceImpl.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/DeviceManagementServiceImpl.java index 0322bd5e05..a595bdba7c 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/DeviceManagementServiceImpl.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/DeviceManagementServiceImpl.java @@ -78,6 +78,7 @@ import javax.ws.rs.PUT; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import java.util.ArrayList; @@ -446,26 +447,40 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { @DELETE @Path("/{id}") @Override - public Response disEnrollDevice(@PathParam("id") String id) { + public Response disEnrollDevice(@PathParam("id") String id, + @QueryParam("permanentDelete") boolean permanentDelete) { boolean result; DeviceIdentifier deviceIdentifier = AndroidDeviceUtils.convertToDeviceIdentifierObject(id); try { - result = AndroidAPIUtils.getDeviceManagementService().disenrollDevice(deviceIdentifier); + if (permanentDelete) { + result = AndroidAPIUtils.getDeviceManagementService().deleteDevice(deviceIdentifier); + } else { + AndroidDeviceUtils.updateDisEnrollOperationStatus(deviceIdentifier); + result = AndroidAPIUtils.getDeviceManagementService().disenrollDevice(deviceIdentifier); + } if (result) { + String msg = "Android device that carries id '" + id + "' is successfully "; Message responseMessage = new Message(); responseMessage.setResponseCode(Response.Status.OK.toString()); - responseMessage.setResponseMessage("Android device that carries id '" + id + - "' has successfully dis-enrolled"); + if (permanentDelete) { + responseMessage.setResponseMessage(msg + "deleted"); + } else { + responseMessage.setResponseMessage(msg + "dis-enrolled"); + } return Response.status(Response.Status.OK).entity(responseMessage).build(); } else { Message responseMessage = new Message(); responseMessage.setResponseCode(Response.Status.NOT_FOUND.toString()); - responseMessage.setResponseMessage("Android device that carries id '" + id + - "' has not been dis-enrolled"); + responseMessage.setResponseMessage("Android device that carries id '" + id + "' is not available"); return Response.status(Response.Status.NOT_FOUND).entity(responseMessage).build(); } } catch (DeviceManagementException e) { - String msg = "Error occurred while dis-enrolling the Android device that carries the id '" + id + "'"; + String msg = "Error occurred while %s the Android device that carries the id '" + id + "'"; + if (permanentDelete) { + msg = String.format(msg, "deleting"); + } else { + msg = String.format(msg, "dis-enrolling"); + } log.error(msg, e); throw new UnexpectedServerErrorException( new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).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/util/AndroidDeviceUtils.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/util/AndroidDeviceUtils.java index 0e6319f9a5..a6c9499575 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/util/AndroidDeviceUtils.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/util/AndroidDeviceUtils.java @@ -572,4 +572,25 @@ public class AndroidDeviceUtils { } } + /** + * Update status of pending operations to error when a dis-enroll operation is triggered. + * + * @param deviceIdentifier Identifier of the device + * @throws DeviceManagementException + */ + public static void updateDisEnrollOperationStatus(DeviceIdentifier deviceIdentifier) + throws DeviceManagementException { + try { + List pendingOperations = getPendingOperations(deviceIdentifier); + for (Operation operation : pendingOperations) { + operation.setStatus(Operation.Status.ERROR); + AndroidAPIUtils.getDeviceManagementService().updateOperation(deviceIdentifier, operation); + } + } catch (OperationManagementException e) { + String msg = "Error occurred while retrieving pending operations to update operation statuses of " + + "device to be dis-enrolled"; + log.error(msg); + throw new DeviceManagementException(msg, e); + } + } } diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/test/java/org/wso2/carbon/mdm/services/android/DeviceManagementServiceTests.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/test/java/org/wso2/carbon/mdm/services/android/DeviceManagementServiceTests.java index dc16b5d43c..b1b3de01e6 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/test/java/org/wso2/carbon/mdm/services/android/DeviceManagementServiceTests.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/test/java/org/wso2/carbon/mdm/services/android/DeviceManagementServiceTests.java @@ -300,7 +300,7 @@ public class DeviceManagementServiceTests { public void testDisEnrollDeviceSuccess() throws DeviceManagementException, OperationManagementException, InvalidDeviceException { mockDeviceManagementService(); - Response response = deviceManagementService.disEnrollDevice(TestUtils.getDeviceId()); + Response response = deviceManagementService.disEnrollDevice(TestUtils.getDeviceId(), false); Assert.assertNotNull(response); Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode()); } @@ -309,7 +309,7 @@ public class DeviceManagementServiceTests { public void testDisenrollUnSuccess() throws DeviceManagementException, OperationManagementException, InvalidDeviceException { mockDeviceManagementService(); - Response response = deviceManagementService.disEnrollDevice("1234"); + Response response = deviceManagementService.disEnrollDevice("1234", false); Assert.assertNotNull(response); Assert.assertEquals(response.getStatus(), Response.Status.NOT_FOUND.getStatusCode()); } diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android/src/main/java/org/wso2/carbon/device/mgt/mobile/android/impl/AndroidDeviceManager.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android/src/main/java/org/wso2/carbon/device/mgt/mobile/android/impl/AndroidDeviceManager.java index 63df2b80d2..33bb666b9f 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android/src/main/java/org/wso2/carbon/device/mgt/mobile/android/impl/AndroidDeviceManager.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android/src/main/java/org/wso2/carbon/device/mgt/mobile/android/impl/AndroidDeviceManager.java @@ -220,6 +220,12 @@ public class AndroidDeviceManager implements DeviceManager { return true; } + @Override + public boolean deleteDevice(DeviceIdentifier deviceId, Device device) throws DeviceManagementException { + //Returning false since AndroidDeviceManager is not used instead DeviceTypeManager is used. + return false; + } + @Override public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException { boolean isEnrolled = false; diff --git a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/impl/WindowsDeviceManager.java b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/impl/WindowsDeviceManager.java index 33752a2d1e..9688d8cb05 100644 --- a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/impl/WindowsDeviceManager.java +++ b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/impl/WindowsDeviceManager.java @@ -168,6 +168,12 @@ public class WindowsDeviceManager implements DeviceManager { return true; } + @Override + public boolean deleteDevice(DeviceIdentifier deviceId, Device device) throws DeviceManagementException { + //Returning false since WindowsDeviceManager is not used instead DeviceTypeManager is used. + return false; + } + @Override public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException { boolean isEnrolled = false; diff --git a/pom.xml b/pom.xml index 1573decb5b..597997657e 100644 --- a/pom.xml +++ b/pom.xml @@ -1242,7 +1242,7 @@ 1.1.1 - 3.2.6 + 3.2.7-SNAPSHOT [3.1.0, 4.0.0)