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 e9fdd98fbd..b15f94d233 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 @@ -107,7 +107,7 @@ public final class DeviceManagementDAOUtil { Device deviceBO = new Device(); deviceBO.setDescription(device.getDescription()); deviceBO.setName(device.getName()); - deviceBO.setDateOfEnrolment(device.getDateOfEnrolment()); + deviceBO.setDateOfEnrollment(device.getDateOfEnrolment()); deviceBO.setDateOfLastUpdate(device.getDateOfLastUpdate()); deviceBO.setStatus(Status.valueOf(String.valueOf(device.isStatus()))); deviceBO.setOwnerId(device.getOwner()); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/Device.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/Device.java index 534a7511c2..44c9d3e579 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/Device.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/Device.java @@ -27,7 +27,7 @@ public class Device implements Serializable { private String id; private String description; private String name; - private Date dateOfEnrolment; + private Date dateOfEnrollment; private Date dateOfLastUpdate; private String deviceIdentificationId; private Status status; @@ -68,12 +68,12 @@ public class Device implements Serializable { this.name = name; } - public Date getDateOfEnrolment() { - return dateOfEnrolment; + public Date getDateOfEnrollment() { + return dateOfEnrollment; } - public void setDateOfEnrolment(Date dateOfEnrolment) { - this.dateOfEnrolment = dateOfEnrolment; + public void setDateOfEnrollment(Date dateOfEnrollment) { + this.dateOfEnrollment = dateOfEnrollment; } public Date getDateOfLastUpdate() { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/pom.xml index 18f3cb20a1..043e0dd60e 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/pom.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/pom.xml @@ -6,6 +6,7 @@ device-mgt org.wso2.carbon 2.0.0-SNAPSHOT + ../pom.xml 4.0.0 diff --git a/product/modules/agents/android/jax-rs/pom.xml b/product/modules/agents/android/jax-rs/pom.xml index c9d0901cf6..7233388162 100644 --- a/product/modules/agents/android/jax-rs/pom.xml +++ b/product/modules/agents/android/jax-rs/pom.xml @@ -150,6 +150,21 @@ org.wso2.carbon org.wso2.carbon.utils + + org.wso2.carbon + org.wso2.carbon.device.mgt.common + 2.0.0-SNAPSHOT + + + org.wso2.carbon + org.wso2.carbon.device.mgt.core + 2.0.0-SNAPSHOT + + + org.wso2.carbon + org.wso2.carbon.device.mgt.mobile.impl + 2.0.0-SNAPSHOT + 2.6.1 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 1699c78910..57dfcb2cc0 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 @@ -21,8 +21,9 @@ import com.google.gson.JsonObject; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.context.CarbonContext; +import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.DeviceManagementException; -import org.wso2.carbon.device.mgt.core.dto.Device; +import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.core.service.DeviceManagementService; import javax.ws.rs.*; @@ -36,15 +37,14 @@ public class Enrollment { private static Log log = LogFactory.getLog(Enrollment.class); @POST - @Consumes("application/json") public Response enrollDevice() { JsonObject result = new JsonObject(); result.addProperty("senderId","jwwfowrjwqporqwrpqworpq"); CarbonContext context = CarbonContext.getThreadLocalCarbonContext(); DeviceManagementService dmService = (DeviceManagementService) context.getOSGiService(DeviceManagementService.class,null); - Device device = AndroidAPIUtil.convertToDeviceDTO(result); + Device device = AndroidAPIUtil.convertToDeviceObject(result); try { - dmService.enrollDevice(null); + dmService.enrollDevice(device); } catch (DeviceManagementException e) { String msg = "Error occurred while enrolling the device"; log.error(msg, e); @@ -54,16 +54,18 @@ public class Enrollment { @GET @Path("{id}") - public String isEnrolled(@PathParam("id") String id) { + public Response isEnrolled(@PathParam("id") String id) { + boolean status = false; CarbonContext context = CarbonContext.getThreadLocalCarbonContext(); DeviceManagementService dmService = (DeviceManagementService) context.getOSGiService(DeviceManagementService.class,null); try { - Device device = AndroidAPIUtil.convertToDeviceDTO(id); - dmService.isRegistered(null); + DeviceIdentifier deviceIdentifier = AndroidAPIUtil.convertToDeviceIdentifierObject(id); + status = dmService.isRegistered(deviceIdentifier); } catch (DeviceManagementException e) { - e.printStackTrace(); + String msg = "Error occurred while checking enrollment of the device"; + log.error(msg, e); } - return "true"; + return Response.status(200).entity(status).build(); } @PUT diff --git a/product/modules/agents/android/jax-rs/src/main/java/cdm/api/android/util/AndroidAPIUtil.java b/product/modules/agents/android/jax-rs/src/main/java/cdm/api/android/util/AndroidAPIUtil.java index 0995f27cc9..e2610565f0 100644 --- a/product/modules/agents/android/jax-rs/src/main/java/cdm/api/android/util/AndroidAPIUtil.java +++ b/product/modules/agents/android/jax-rs/src/main/java/cdm/api/android/util/AndroidAPIUtil.java @@ -17,26 +17,28 @@ package cdm.api.android.util; import com.google.gson.JsonObject; -import org.wso2.carbon.device.mgt.core.dto.Device; -import org.wso2.carbon.device.mgt.core.dto.DeviceType; +import org.wso2.carbon.device.mgt.common.Device; +import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.mobile.impl.MobileDeviceManagementConstants; + /** * AndroidAPIUtil class provides utility function used by Android REST-API classes. */ public class AndroidAPIUtil { - public static Device convertToDeviceDTO(JsonObject json){ + public static Device convertToDeviceObject(JsonObject json){ Device device = new Device(); + device.setType(MobileDeviceManagementConstants.PlatformTypes.MOBILE_DEVICE_TYPE_ANDROID); + device.setName("Test Device"); + device.setOwner("harshan"); return device; } - public static Device convertToDeviceDTO(String deviceId){ - Device device = new Device(); - DeviceType type = new DeviceType(); - device.setId(deviceId); - type.setName(MobileDeviceManagementConstants.MOBILE_DEVICE_TYPE_ANDROID); - device.setDeviceType(type); - return device; + public static DeviceIdentifier convertToDeviceIdentifierObject(String deviceId){ + DeviceIdentifier identifier = new DeviceIdentifier(); + identifier.setId(deviceId); + identifier.setType(MobileDeviceManagementConstants.PlatformTypes.MOBILE_DEVICE_TYPE_ANDROID); + return identifier; } }