Added Android-REST API implementation changes

revert-70aa11f8
harshanL 10 years ago
parent ef515289cc
commit c2f5d79b9c

@ -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());

@ -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() {

@ -6,6 +6,7 @@
<artifactId>device-mgt</artifactId>
<groupId>org.wso2.carbon</groupId>
<version>2.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

@ -150,6 +150,21 @@
<groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.utils</artifactId>
</dependency>
<dependency>
<groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.device.mgt.common</artifactId>
<version>2.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.device.mgt.core</artifactId>
<version>2.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.device.mgt.mobile.impl</artifactId>
<version>2.0.0-SNAPSHOT</version>
</dependency>
</dependencies>
<properties>
<cxf.version>2.6.1</cxf.version>

@ -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

@ -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;
}
}

Loading…
Cancel
Save