diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/Device.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/Device.java index c00dd74579f..d3eac453b83 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/Device.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/Device.java @@ -15,8 +15,10 @@ */ package org.wso2.carbon.device.mgt.common; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; import java.util.List; - +@XmlRootElement public class Device { private int id; @@ -45,6 +47,7 @@ public class Device { private List properties; + @XmlElement public int getId() { return id; } @@ -52,7 +55,7 @@ public class Device { public void setId(int id) { this.id = id; } - + @XmlElement public String getDescription() { return description; } @@ -60,7 +63,7 @@ public class Device { public void setDescription(String description) { this.description = description; } - + @XmlElement public String getName() { return name; } @@ -68,7 +71,7 @@ public class Device { public void setName(String name) { this.name = name; } - + @XmlElement public Long getDateOfEnrolment() { return dateOfEnrolment; } @@ -76,7 +79,7 @@ public class Device { public void setDateOfEnrolment(Long dateOfEnrolment) { this.dateOfEnrolment = dateOfEnrolment; } - + @XmlElement public Long getDateOfLastUpdate() { return dateOfLastUpdate; } @@ -84,7 +87,7 @@ public class Device { public void setDateOfLastUpdate(Long dateOfLastUpdate) { this.dateOfLastUpdate = dateOfLastUpdate; } - + @XmlElement public String getOwnership() { return ownership; } @@ -92,7 +95,7 @@ public class Device { public void setOwnership(String ownership) { this.ownership = ownership; } - + @XmlElement public boolean isStatus() { return status; } @@ -100,7 +103,7 @@ public class Device { public void setStatus(boolean status) { this.status = status; } - + @XmlElement public int getDeviceTypeId() { return deviceTypeId; } @@ -108,7 +111,7 @@ public class Device { public void setDeviceTypeId(int deviceTypeId) { this.deviceTypeId = deviceTypeId; } - + @XmlElement public String getDeviceIdentifier() { return deviceIdentifier; } @@ -116,7 +119,7 @@ public class Device { public void setDeviceIdentifier(String deviceIdentifier) { this.deviceIdentifier = deviceIdentifier; } - + @XmlElement public String getOwner() { return owner; } @@ -124,7 +127,7 @@ public class Device { public void setOwner(String owner) { this.owner = owner; } - + @XmlElement public List getFeatures() { return features; } @@ -132,7 +135,7 @@ public class Device { public void setFeatures(List features) { this.features = features; } - + @XmlElement public String getType() { return type; } @@ -140,7 +143,7 @@ public class Device { public void setType(String type) { this.type = type; } - + @XmlElement public List getProperties() { return properties; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/util/DeviceManagementDAOUtil.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/util/DeviceManagementDAOUtil.java index b71aaeaa155..2300db16b7a 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/util/DeviceManagementDAOUtil.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/util/DeviceManagementDAOUtil.java @@ -109,7 +109,12 @@ public final class DeviceManagementDAOUtil { deviceBO.setName(device.getName()); deviceBO.setDateOfEnrollment(device.getDateOfEnrolment()); deviceBO.setDateOfLastUpdate(device.getDateOfLastUpdate()); - deviceBO.setStatus(Status.valueOf(String.valueOf(device.isStatus()))); + + if (!device.isStatus()){ + deviceBO.setStatus(Status.INACTIVE); + }else{ + deviceBO.setStatus(Status.ACTIVE); + } deviceBO.setOwnerId(device.getOwner()); deviceBO.setOwnerShip(device.getOwnership()); deviceBO.setTenantId(DeviceManagementDAOUtil.getTenantId()); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java index 85ae3ec4e5f..102ca5fb707 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java @@ -41,7 +41,7 @@ import org.wso2.carbon.user.core.service.RealmService; * unbind="unsetRealmService" * @scr.reference name="device.manager.service" * interface="org.wso2.carbon.device.mgt.common.spi.DeviceManagerService" - * cardinality="1..n" + * cardinality="0..n" * policy="dynamic" * bind="setDeviceManagerService" * unbind="unsetDeviceManagerService" diff --git a/product/modules/agents/android/jax-rs/pom.xml b/product/modules/agents/android/jax-rs/pom.xml index 744ae057a24..49ccbaf328f 100644 --- a/product/modules/agents/android/jax-rs/pom.xml +++ b/product/modules/agents/android/jax-rs/pom.xml @@ -144,11 +144,6 @@ 1.1.1 provided - - com.google.code.gson - gson - 2.2.4 - org.wso2.carbon org.wso2.carbon.utils @@ -171,6 +166,11 @@ org.wso2.carbon.logging provided + + org.codehaus.jackson + jackson-jaxrs + 1.1.1 + 2.6.1 diff --git a/product/modules/agents/android/jax-rs/src/main/java/cdm/api/android/Authentication.java b/product/modules/agents/android/jax-rs/src/main/java/cdm/api/android/Authentication.java index 9b81095ac89..ce225f61b88 100644 --- a/product/modules/agents/android/jax-rs/src/main/java/cdm/api/android/Authentication.java +++ b/product/modules/agents/android/jax-rs/src/main/java/cdm/api/android/Authentication.java @@ -18,31 +18,27 @@ package cdm.api.android; import com.google.gson.JsonObject; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.FormParam; -import javax.ws.rs.core.Response; +import javax.ws.rs.*; +@Produces({ "application/json", "application/xml" }) +@Consumes({ "application/json", "application/xml" }) @Path("/authenticate/") public class Authentication { - @POST - @Path("/device/") - @Produces("application/json") - public String authenticateDevice(@FormParam("username") String username, - @FormParam("password") String password) { - JsonObject result = new JsonObject(); - result.addProperty("senderId", "jwwfowrjwqporqwrpqworpq"); - return result.toString(); - } + @POST + @Path("/device/") + public String authenticateDevice(@FormParam("username") String username, + @FormParam("password") String password) { + JsonObject result = new JsonObject(); + result.addProperty("senderId", "jwwfowrjwqporqwrpqworpq"); + return result.toString(); + } - @POST - @Path("/device/license") - @Produces("application/json") - public String getLicense() { - JsonObject result = new JsonObject(); - result.addProperty("licenseText", "License Agreement"); - return result.toString(); - } + @POST + @Path("/device/license") + public String getLicense() { + JsonObject result = new JsonObject(); + result.addProperty("licenseText", "License Agreement"); + return result.toString(); + } } diff --git a/product/modules/agents/android/jax-rs/src/main/java/cdm/api/android/Device.java b/product/modules/agents/android/jax-rs/src/main/java/cdm/api/android/Device.java index ae2e805dd27..1638e297fda 100644 --- a/product/modules/agents/android/jax-rs/src/main/java/cdm/api/android/Device.java +++ b/product/modules/agents/android/jax-rs/src/main/java/cdm/api/android/Device.java @@ -5,7 +5,7 @@ * 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 + * 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, @@ -18,7 +18,7 @@ package cdm.api.android; import cdm.api.android.util.AndroidAPIUtils; import cdm.api.android.util.AndroidConstants; -import com.google.gson.Gson; +import cdm.api.android.util.Message; import org.apache.commons.httpclient.HttpStatus; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -30,130 +30,118 @@ import org.wso2.carbon.device.mgt.core.service.DeviceManagementService; import javax.ws.rs.*; import javax.ws.rs.core.Response; +import java.util.ArrayList; import java.util.List; /** * Android Device Management REST-API implementation. */ +@Produces({ "application/json", "application/xml" }) +@Consumes({ "application/json", "application/xml" }) public class Device { - private static Log log = LogFactory.getLog(Device.class); - - @GET - public Response getAllDevices() { - List result = null; - int status = 0; - String msg = ""; - DeviceManagementService dmService; - try { - dmService = AndroidAPIUtils.getDeviceManagementService(); - } finally { - PrivilegedCarbonContext.endTenantFlow(); - } - try { - if (dmService != null) { - result = dmService.getAllDevices( - DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID); - status = 1; - } else { - status = -1; - msg = AndroidConstants.Messages.DEVICE_MANAGER_SERVICE_NOT_AVAILABLE; - } - - } catch (DeviceManagementException e) { - msg = "Error occurred while fetching the device list"; - log.error(msg, e); - status = -1; - } - switch (status) { - case 1: - if(result!=null){ - String response = new Gson().toJson(result); - return Response.status(HttpStatus.SC_OK).entity(response).build(); - } - case -1: - return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR).entity(msg).build(); - } - return Response.status(HttpStatus.SC_NOT_FOUND).entity("Unable to fetch device list").build(); - } - - @GET - @Path("{id}") - public Response getDevice(@PathParam("id") String id) { - int status = 0; - String msg = ""; - DeviceManagementService dmService; - org.wso2.carbon.device.mgt.common.Device device = - new org.wso2.carbon.device.mgt.common.Device(); - try { - dmService = AndroidAPIUtils.getDeviceManagementService(); - } finally { - PrivilegedCarbonContext.endTenantFlow(); - } - DeviceIdentifier deviceIdentifier = AndroidAPIUtils.convertToDeviceIdentifierObject(id); - try { - if (dmService != null) { - device = dmService.getDevice(deviceIdentifier); - status = 1; - } else { - status = -1; - msg = AndroidConstants.Messages.DEVICE_MANAGER_SERVICE_NOT_AVAILABLE; - } - - } catch (DeviceManagementException e) { - msg = "Error occurred while fetching the device information"; - log.error(msg, e); - status = -1; - } - switch (status) { - case 1: - if(device!=null) { - String response = new Gson().toJson(device); - return Response.status(HttpStatus.SC_OK).entity(response).build(); - } - break; - case -1: - return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR).entity(msg).build(); - } - return Response.status(HttpStatus.SC_NOT_FOUND).entity("Unable to fetch device information").build(); - } - - @PUT - @Path("{id}") - public Response updateDevice(@PathParam("id") String id, String jsonPayload) { - boolean result = false; - int status = 0; - String msg = ""; - DeviceManagementService dmService; - try { - dmService = AndroidAPIUtils.getDeviceManagementService(); - } finally { - PrivilegedCarbonContext.endTenantFlow(); - } - org.wso2.carbon.device.mgt.common.Device device = - AndroidAPIUtils.convertToDeviceObject(jsonPayload); - try { - if (dmService != null) { - result = dmService.updateDeviceInfo(device); - status = 1; - } else { - status = -1; - msg = AndroidConstants.Messages.DEVICE_MANAGER_SERVICE_NOT_AVAILABLE; - } - } catch (DeviceManagementException e) { - msg = "Error occurred while modifying the device information"; - log.error(msg, e); - status = -1; - } - switch (status) { - case 1: - if (result) { - return Response.status(HttpStatus.SC_OK).entity("Device has modified").build(); - } - break; - case -1: - return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR).entity(msg).build(); - } - return Response.status(HttpStatus.SC_NOT_MODIFIED).entity("Update device has failed").build(); - } + private static Log log = LogFactory.getLog(Device.class); + + @GET + public List getAllDevices() { + + List devices = null; + String msg = ""; + DeviceManagementService dmService; + + try { + dmService = AndroidAPIUtils.getDeviceManagementService(); + } finally { + PrivilegedCarbonContext.endTenantFlow(); + } + try { + if (dmService != null) { + devices = dmService.getAllDevices(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID); + Response.status(HttpStatus.SC_OK); + } else { + Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR); + } + } catch (DeviceManagementException e) { + msg = "Error occurred while fetching the device list"; + log.error(msg, e); + Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR); + } + return devices; + } + + @GET + @Path("{id}") + public org.wso2.carbon.device.mgt.common.Device getDevice(@PathParam("id") String id) { + + String msg = ""; + DeviceManagementService dmService; + org.wso2.carbon.device.mgt.common.Device device = new org.wso2.carbon.device.mgt.common.Device(); + + try { + dmService = AndroidAPIUtils.getDeviceManagementService(); + } finally { + PrivilegedCarbonContext.endTenantFlow(); + } + DeviceIdentifier deviceIdentifier = AndroidAPIUtils.convertToDeviceIdentifierObject(id); + try { + if (dmService != null) { + device = dmService.getDevice(deviceIdentifier); + if (device == null) { + Response.status(HttpStatus.SC_NOT_FOUND); + } + + } else { + Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR); + } + + } catch (DeviceManagementException e) { + msg = "Error occurred while fetching the device information"; + log.error(msg, e); + Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR); + } + return device; + } + + @PUT + @Path("{id}") + public Message updateDevice(@PathParam("id") String id, String jsonPayload) { + + boolean result = false; + String msg = ""; + DeviceManagementService dmService; + Message responseMessage = new Message(); + + try { + dmService = AndroidAPIUtils.getDeviceManagementService(); + } finally { + PrivilegedCarbonContext.endTenantFlow(); + } + org.wso2.carbon.device.mgt.common.Device device = + AndroidAPIUtils.convertToDeviceObject(jsonPayload); + try { + if (dmService != null) { + result = dmService.updateDeviceInfo(device); + if (result) { + Response.status(HttpStatus.SC_OK); + responseMessage.setResponseMessage("Device has modified"); + } else { + Response.status(HttpStatus.SC_NOT_MODIFIED); + responseMessage.setResponseMessage("Update device has failed"); + } + } else { + Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR); + msg = AndroidConstants.Messages.DEVICE_MANAGER_SERVICE_NOT_AVAILABLE; + responseMessage.setResponseMessage(msg); + } + + } catch (DeviceManagementException e) { + msg = "Error occurred while modifying the device information"; + log.error(msg, e); + Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR); + responseMessage.setResponseMessage(msg); + + } + + return responseMessage; + } } diff --git a/product/modules/agents/android/jax-rs/src/main/java/cdm/api/android/Enrollment.java b/product/modules/agents/android/jax-rs/src/main/java/cdm/api/android/Enrollment.java index 7a7b3bd29ad..5f9bb096385 100644 --- a/product/modules/agents/android/jax-rs/src/main/java/cdm/api/android/Enrollment.java +++ b/product/modules/agents/android/jax-rs/src/main/java/cdm/api/android/Enrollment.java @@ -18,9 +18,10 @@ package cdm.api.android; import cdm.api.android.util.AndroidAPIUtils; import cdm.api.android.util.AndroidConstants; +import cdm.api.android.util.Message; +import org.apache.commons.httpclient.HttpStatus; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.apache.commons.httpclient.HttpStatus; import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; @@ -33,158 +34,170 @@ import javax.ws.rs.core.Response; /** * Android Device Enrollment REST-API implementation. */ +@Produces({ "application/json", "application/xml" }) +@Consumes({ "application/json", "application/xml" }) public class Enrollment { - private static Log log = LogFactory.getLog(Enrollment.class); - - @POST - public Response enrollDevice(String jsonPayload) { - boolean result = false; - int status = 0; - String msg = ""; - DeviceManagementService dmService; - try { - dmService = AndroidAPIUtils.getDeviceManagementService(); - } finally { - PrivilegedCarbonContext.endTenantFlow(); - } - Device device = AndroidAPIUtils.convertToDeviceObject(jsonPayload); - try { - if (dmService != null) { - result = dmService.enrollDevice(device); - status = 1; - } else { - status = -1; - msg = AndroidConstants.Messages.DEVICE_MANAGER_SERVICE_NOT_AVAILABLE; - } - } catch (DeviceManagementException e) { - msg = "Error occurred while enrolling the device"; - log.error(msg, e); - status = -1; - } - switch (status) { - case 1: - if (result) { - return Response.status(HttpStatus.SC_CREATED).entity("Device enrollment has succeeded").build(); - } - break; - case -1: - return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR).entity(msg).build(); - } - return Response.status(HttpStatus.SC_BAD_REQUEST).entity("Device enrollment has Failed").build(); - } - - @GET - @Path("{id}") - public Response isEnrolled(@PathParam("id") String id) { - boolean result = false; - int status = 0; - String msg = ""; - DeviceManagementService dmService; - try { - dmService = AndroidAPIUtils.getDeviceManagementService(); - } finally { - PrivilegedCarbonContext.endTenantFlow(); - } - DeviceIdentifier deviceIdentifier = AndroidAPIUtils.convertToDeviceIdentifierObject(id); - try { - if (dmService != null) { - result = dmService.isEnrolled(deviceIdentifier); - status = 1; - } else { - status = -1; - msg = AndroidConstants.Messages.DEVICE_MANAGER_SERVICE_NOT_AVAILABLE; - } - } catch (DeviceManagementException e) { - msg = "Error occurred while checking enrollment of the device"; - log.error(msg, e); - status = -1; - } - switch (status) { - case 1: - if (result) { - return Response.status(HttpStatus.SC_OK).entity(result).build(); - } - break; - case -1: - return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR).entity(msg).build(); - } - return Response.status(HttpStatus.SC_NOT_FOUND).entity(result).build(); - } - - @PUT - @Path("{id}") - public Response modifyEnrollment(@PathParam("id") String id, String jsonPayload) { - boolean result = false; - int status = 0; - String msg = ""; - DeviceManagementService dmService; - try { - dmService = AndroidAPIUtils.getDeviceManagementService(); - } finally { - PrivilegedCarbonContext.endTenantFlow(); - } - Device device = AndroidAPIUtils.convertToDeviceObject(jsonPayload); - try { - if (dmService != null) { - result = dmService.modifyEnrollment(device); - status = 1; - } else { - status = -1; - msg = AndroidConstants.Messages.DEVICE_MANAGER_SERVICE_NOT_AVAILABLE; - } - } catch (DeviceManagementException e) { - msg = "Error occurred while modifying enrollment of the device"; - log.error(msg, e); - status = -1; - } - switch (status) { - case 1: - if (result) { - return Response.status(HttpStatus.SC_OK).entity("Enrollment information has modified").build(); - } - break; - case -1: - return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR).entity(msg).build(); - } - return Response.status(HttpStatus.SC_NOT_MODIFIED).entity("Update enrollment has failed").build(); - } - - @DELETE - @Path("{id}") - public Response disenrollDevice(@PathParam("id") String id) { - boolean result = false; - int status = 0; - String msg = ""; - DeviceManagementService dmService; - try { - dmService = AndroidAPIUtils.getDeviceManagementService(); - } finally { - PrivilegedCarbonContext.endTenantFlow(); - } - DeviceIdentifier deviceIdentifier = AndroidAPIUtils.convertToDeviceIdentifierObject(id); - try { - if (dmService != null) { - result = dmService.disenrollDevice(deviceIdentifier); - status = 1; - } else { - status = -1; - msg = AndroidConstants.Messages.DEVICE_MANAGER_SERVICE_NOT_AVAILABLE; - } - } catch (DeviceManagementException e) { - msg = "Error occurred while disenrolling the device"; - log.error(msg, e); - status = -1; - } - switch (status) { - case 1: - if (result) { - return Response.status(HttpStatus.SC_OK).entity(result).build(); - } - break; - case -1: - return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR).entity(msg).build(); - } - return Response.status(HttpStatus.SC_NOT_FOUND).entity("Device not found").build(); - } + private static Log log = LogFactory.getLog(Enrollment.class); + + @POST + public Message enrollDevice(String jsonPayload) { + + boolean result = false; + int status = 0; + String msg = ""; + DeviceManagementService dmService; + Message responseMsg = new Message(); + + try { + dmService = AndroidAPIUtils.getDeviceManagementService(); + } finally { + PrivilegedCarbonContext.endTenantFlow(); + } + Device device = AndroidAPIUtils.convertToDeviceObject(jsonPayload); + try { + if (dmService != null) { + result = dmService.enrollDevice(device); + Response.status(HttpStatus.SC_CREATED); + responseMsg.setResponseMessage("Device enrollment has succeeded"); + return responseMsg; + + } else { + responseMsg.setResponseMessage(AndroidConstants.Messages.DEVICE_MANAGER_SERVICE_NOT_AVAILABLE); + Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR); + return responseMsg; + } + } catch (DeviceManagementException e) { + log.error(msg, e); + responseMsg.setResponseMessage("Error occurred while enrolling the device"); + Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR); + return responseMsg; + } + + } + + @GET + @Path("{id}") + public Message isEnrolled(@PathParam("id") String id) { + + boolean result = false; + String msg = ""; + DeviceManagementService dmService; + Message responseMsg = new Message(); + + try { + dmService = AndroidAPIUtils.getDeviceManagementService(); + } finally { + PrivilegedCarbonContext.endTenantFlow(); + } + DeviceIdentifier deviceIdentifier = AndroidAPIUtils.convertToDeviceIdentifierObject(id); + try { + if (dmService != null) { + result = dmService.isEnrolled(deviceIdentifier); + if (result) { + Response.status(HttpStatus.SC_OK); + responseMsg.setResponseMessage("Device already enroll"); + } else { + + Response.status(HttpStatus.SC_NOT_FOUND); + responseMsg.setResponseMessage("Device not enroll"); + } + return responseMsg; + } else { + Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR); + responseMsg.setResponseMessage(AndroidConstants.Messages.DEVICE_MANAGER_SERVICE_NOT_AVAILABLE); + return responseMsg; + } + } catch (DeviceManagementException e) { + msg = "Error occurred while checking enrollment of the device"; + log.error(msg, e); + responseMsg.setResponseMessage(msg); + Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR); + return responseMsg; + } + + } + + @PUT + @Path("{id}") + public Message modifyEnrollment(@PathParam("id") String id, String jsonPayload) { + boolean result = false; + String msg = ""; + DeviceManagementService dmService; + Message responseMsg = new Message(); + + try { + dmService = AndroidAPIUtils.getDeviceManagementService(); + } finally { + PrivilegedCarbonContext.endTenantFlow(); + } + Device device = AndroidAPIUtils.convertToDeviceObject(jsonPayload); + try { + if (dmService != null) { + result = dmService.modifyEnrollment(device); + + if (result) { + responseMsg.setResponseMessage("update device"); + Response.status(HttpStatus.SC_OK); + }else{ + responseMsg.setResponseMessage("Update enrollment has failed"); + Response.status(HttpStatus.SC_NOT_MODIFIED); + } + } else { + msg = AndroidConstants.Messages.DEVICE_MANAGER_SERVICE_NOT_AVAILABLE; + responseMsg.setResponseMessage(msg); + Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR); + } + return responseMsg; + } catch (DeviceManagementException e) { + msg = "Error occurred while modifying enrollment of the device"; + log.error(msg, e); + Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR); + responseMsg.setResponseMessage(msg); + return responseMsg; + } + + } + + @DELETE + @Path("{id}") + public Message disenrollDevice(@PathParam("id") String id) { + + boolean result = false; + String msg = ""; + DeviceManagementService dmService; + Message responseMsg = new Message(); + + + try { + dmService = AndroidAPIUtils.getDeviceManagementService(); + } finally { + PrivilegedCarbonContext.endTenantFlow(); + } + DeviceIdentifier deviceIdentifier = AndroidAPIUtils.convertToDeviceIdentifierObject(id); + try { + if (dmService != null) { + result = dmService.disenrollDevice(deviceIdentifier); + if (result) { + responseMsg.setResponseMessage("Dis enrolled device"); + Response.status(HttpStatus.SC_OK); + }else{ + responseMsg.setResponseMessage("Device not found"); + Response.status(HttpStatus.SC_NOT_FOUND); + } + } else { + Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR); + msg = AndroidConstants.Messages.DEVICE_MANAGER_SERVICE_NOT_AVAILABLE; + responseMsg.setResponseMessage(msg); + } + + return responseMsg; + } catch (DeviceManagementException e) { + msg = "Error occurred while disenrolling the device"; + log.error(msg, e); + Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR); + responseMsg.setResponseMessage(msg); + return responseMsg; + } + } } diff --git a/product/modules/agents/android/jax-rs/src/main/webapp/WEB-INF/cxf-servlet.xml b/product/modules/agents/android/jax-rs/src/main/webapp/WEB-INF/cxf-servlet.xml index a75cad35907..bab3022d98d 100644 --- a/product/modules/agents/android/jax-rs/src/main/webapp/WEB-INF/cxf-servlet.xml +++ b/product/modules/agents/android/jax-rs/src/main/webapp/WEB-INF/cxf-servlet.xml @@ -27,20 +27,33 @@ + + + + + + + + + + + + +