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