|
|
@ -21,8 +21,8 @@ import com.google.gson.JsonObject;
|
|
|
|
import org.apache.commons.logging.Log;
|
|
|
|
import org.apache.commons.logging.Log;
|
|
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
|
import org.wso2.carbon.context.CarbonContext;
|
|
|
|
import org.wso2.carbon.context.CarbonContext;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.common.Device;
|
|
|
|
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
|
|
|
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
|
|
|
import org.wso2.carbon.device.mgt.core.dto.Device;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.core.service.DeviceManagementService;
|
|
|
|
import org.wso2.carbon.device.mgt.core.service.DeviceManagementService;
|
|
|
|
|
|
|
|
|
|
|
|
import javax.ws.rs.*;
|
|
|
|
import javax.ws.rs.*;
|
|
|
@ -34,17 +34,19 @@ import javax.ws.rs.core.Response;
|
|
|
|
@Path("/enrollment")
|
|
|
|
@Path("/enrollment")
|
|
|
|
public class Enrollment {
|
|
|
|
public class Enrollment {
|
|
|
|
|
|
|
|
|
|
|
|
private static Log log = LogFactory.getLog(Enrollment.class);
|
|
|
|
private static final Log log = LogFactory.getLog(Enrollment.class);
|
|
|
|
|
|
|
|
|
|
|
|
@POST
|
|
|
|
@POST
|
|
|
|
@Consumes("application/json")
|
|
|
|
@Consumes("application/json")
|
|
|
|
public Response enrollDevice() {
|
|
|
|
public Response enrollDevice() {
|
|
|
|
JsonObject result = new JsonObject();
|
|
|
|
JsonObject result = new JsonObject();
|
|
|
|
result.addProperty("senderId", "jwwfowrjwqporqwrpqworpq");
|
|
|
|
result.addProperty("senderId", "jwwfowrjwqporqwrpqworpq");
|
|
|
|
CarbonContext context = CarbonContext.getThreadLocalCarbonContext();
|
|
|
|
CarbonContext context = CarbonContext.getThreadLocalCarbonContext();
|
|
|
|
DeviceManagementService dmService = (DeviceManagementService) context.getOSGiService(DeviceManagementService.class,null);
|
|
|
|
DeviceManagementService dmService =
|
|
|
|
|
|
|
|
(DeviceManagementService) context.getOSGiService(DeviceManagementService.class, null);
|
|
|
|
Device device = AndroidAPIUtil.convertToDeviceDTO(result);
|
|
|
|
Device device = AndroidAPIUtil.convertToDeviceDTO(result);
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
dmService.enrollDevice(null);
|
|
|
|
dmService.enrollDevice(device);
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
String msg = "Error occurred while enrolling the device";
|
|
|
|
String msg = "Error occurred while enrolling the device";
|
|
|
|
log.error(msg, e);
|
|
|
|
log.error(msg, e);
|
|
|
@ -71,7 +73,8 @@ public class Enrollment {
|
|
|
|
@Path("{id}")
|
|
|
|
@Path("{id}")
|
|
|
|
public Response modifyEnrollment(@PathParam("id") String id) {
|
|
|
|
public Response modifyEnrollment(@PathParam("id") String id) {
|
|
|
|
CarbonContext context = CarbonContext.getThreadLocalCarbonContext();
|
|
|
|
CarbonContext context = CarbonContext.getThreadLocalCarbonContext();
|
|
|
|
DeviceManagementService dmService = (DeviceManagementService) context.getOSGiService(DeviceManagementService.class,null);
|
|
|
|
DeviceManagementService dmService =
|
|
|
|
|
|
|
|
(DeviceManagementService) context.getOSGiService(DeviceManagementService.class, null);
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
dmService.isRegistered(null);
|
|
|
|
dmService.isRegistered(null);
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
@ -84,7 +87,8 @@ public class Enrollment {
|
|
|
|
@Path("{id}")
|
|
|
|
@Path("{id}")
|
|
|
|
public Response disenrollDevice(@PathParam("id") String id) {
|
|
|
|
public Response disenrollDevice(@PathParam("id") String id) {
|
|
|
|
CarbonContext context = CarbonContext.getThreadLocalCarbonContext();
|
|
|
|
CarbonContext context = CarbonContext.getThreadLocalCarbonContext();
|
|
|
|
DeviceManagementService dmService = (DeviceManagementService) context.getOSGiService(DeviceManagementService.class,null);
|
|
|
|
DeviceManagementService dmService =
|
|
|
|
|
|
|
|
(DeviceManagementService) context.getOSGiService(DeviceManagementService.class, null);
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
dmService.isRegistered(null);
|
|
|
|
dmService.isRegistered(null);
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|