|
|
@ -18,17 +18,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
package org.wso2.cdmserver.mobileservices.android;
|
|
|
|
package org.wso2.cdmserver.mobileservices.android;
|
|
|
|
|
|
|
|
|
|
|
|
import org.wso2.cdmserver.mobileservices.android.common.AndroidAgentException;
|
|
|
|
|
|
|
|
import org.wso2.cdmserver.mobileservices.android.util.AndroidAPIUtils;
|
|
|
|
|
|
|
|
import org.wso2.cdmserver.mobileservices.android.util.Message;
|
|
|
|
|
|
|
|
import org.apache.commons.httpclient.HttpStatus;
|
|
|
|
|
|
|
|
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.device.mgt.common.DeviceIdentifier;
|
|
|
|
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
|
|
|
import org.wso2.carbon.device.mgt.common.DeviceManagementConstants;
|
|
|
|
import org.wso2.carbon.device.mgt.common.DeviceManagementConstants;
|
|
|
|
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
|
|
|
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
|
|
|
import org.wso2.carbon.device.mgt.common.DeviceManagementServiceException;
|
|
|
|
import org.wso2.carbon.device.mgt.common.DeviceManagementServiceException;
|
|
|
|
import org.wso2.carbon.device.mgt.core.service.DeviceManagementService;
|
|
|
|
import org.wso2.cdmserver.mobileservices.android.common.AndroidAgentException;
|
|
|
|
|
|
|
|
import org.wso2.cdmserver.mobileservices.android.util.AndroidAPIUtils;
|
|
|
|
|
|
|
|
import org.wso2.cdmserver.mobileservices.android.util.Message;
|
|
|
|
|
|
|
|
|
|
|
|
import javax.ws.rs.*;
|
|
|
|
import javax.ws.rs.*;
|
|
|
|
import javax.ws.rs.core.Response;
|
|
|
|
import javax.ws.rs.core.Response;
|
|
|
|
|
|
|
|
|
|
|
@ -50,7 +49,7 @@ public class Enrollment {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
device.setType(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID);
|
|
|
|
device.setType(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID);
|
|
|
|
AndroidAPIUtils.getDeviceManagementService().enrollDevice(device);
|
|
|
|
AndroidAPIUtils.getDeviceManagementService().enrollDevice(device);
|
|
|
|
Response.status(HttpStatus.SC_CREATED);
|
|
|
|
Response.status(Response.Status.CREATED);
|
|
|
|
responseMsg.setResponseMessage("Device enrollment succeeded");
|
|
|
|
responseMsg.setResponseMessage("Device enrollment succeeded");
|
|
|
|
return responseMsg;
|
|
|
|
return responseMsg;
|
|
|
|
} catch (DeviceManagementServiceException deviceServiceMgtEx) {
|
|
|
|
} catch (DeviceManagementServiceException deviceServiceMgtEx) {
|
|
|
@ -71,13 +70,13 @@ public class Enrollment {
|
|
|
|
boolean result;
|
|
|
|
boolean result;
|
|
|
|
Message responseMsg = new Message();
|
|
|
|
Message responseMsg = new Message();
|
|
|
|
DeviceIdentifier deviceIdentifier = AndroidAPIUtils.convertToDeviceIdentifierObject(id);
|
|
|
|
DeviceIdentifier deviceIdentifier = AndroidAPIUtils.convertToDeviceIdentifierObject(id);
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
result = AndroidAPIUtils.getDeviceManagementService().isEnrolled(deviceIdentifier);
|
|
|
|
result = AndroidAPIUtils.getDeviceManagementService().isEnrolled(deviceIdentifier);
|
|
|
|
if (result) {
|
|
|
|
if (result) {
|
|
|
|
Response.status(HttpStatus.SC_OK);
|
|
|
|
|
|
|
|
responseMsg.setResponseMessage("Device has already enrolled");
|
|
|
|
responseMsg.setResponseMessage("Device has already enrolled");
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
Response.status(HttpStatus.SC_NOT_FOUND);
|
|
|
|
Response.status(Response.Status.NOT_FOUND);
|
|
|
|
responseMsg.setResponseMessage("Device not found");
|
|
|
|
responseMsg.setResponseMessage("Device not found");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return responseMsg;
|
|
|
|
return responseMsg;
|
|
|
@ -99,16 +98,15 @@ public class Enrollment {
|
|
|
|
|
|
|
|
|
|
|
|
boolean result;
|
|
|
|
boolean result;
|
|
|
|
Message responseMsg = new Message();
|
|
|
|
Message responseMsg = new Message();
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
device.setType(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID);
|
|
|
|
device.setType(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID);
|
|
|
|
result = AndroidAPIUtils.getDeviceManagementService().modifyEnrollment(device);
|
|
|
|
result = AndroidAPIUtils.getDeviceManagementService().modifyEnrollment(device);
|
|
|
|
if (result) {
|
|
|
|
if (result) {
|
|
|
|
responseMsg.setResponseMessage("Device enrollment has updated successfully");
|
|
|
|
responseMsg.setResponseMessage("Device enrollment has updated successfully");
|
|
|
|
Response.status(HttpStatus.SC_ACCEPTED);
|
|
|
|
Response.status(Response.Status.ACCEPTED);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
responseMsg.setResponseMessage("Device not found for enrollment");
|
|
|
|
responseMsg.setResponseMessage("Device not found for enrollment");
|
|
|
|
Response.status(HttpStatus.SC_NOT_MODIFIED);
|
|
|
|
Response.status(Response.Status.NOT_MODIFIED);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return responseMsg;
|
|
|
|
return responseMsg;
|
|
|
|
} catch (DeviceManagementServiceException deviceServiceMgtEx) {
|
|
|
|
} catch (DeviceManagementServiceException deviceServiceMgtEx) {
|
|
|
@ -126,9 +124,7 @@ public class Enrollment {
|
|
|
|
@Path("{id}")
|
|
|
|
@Path("{id}")
|
|
|
|
public Message disEnrollDevice(@PathParam("id") String id) throws AndroidAgentException {
|
|
|
|
public Message disEnrollDevice(@PathParam("id") String id) throws AndroidAgentException {
|
|
|
|
|
|
|
|
|
|
|
|
DeviceManagementService dmService;
|
|
|
|
|
|
|
|
Message responseMsg = new Message();
|
|
|
|
Message responseMsg = new Message();
|
|
|
|
|
|
|
|
|
|
|
|
boolean result;
|
|
|
|
boolean result;
|
|
|
|
DeviceIdentifier deviceIdentifier = AndroidAPIUtils.convertToDeviceIdentifierObject(id);
|
|
|
|
DeviceIdentifier deviceIdentifier = AndroidAPIUtils.convertToDeviceIdentifierObject(id);
|
|
|
|
|
|
|
|
|
|
|
@ -136,10 +132,9 @@ public class Enrollment {
|
|
|
|
result = AndroidAPIUtils.getDeviceManagementService().disenrollDevice(deviceIdentifier);
|
|
|
|
result = AndroidAPIUtils.getDeviceManagementService().disenrollDevice(deviceIdentifier);
|
|
|
|
if (result) {
|
|
|
|
if (result) {
|
|
|
|
responseMsg.setResponseMessage("Device has removed successfully");
|
|
|
|
responseMsg.setResponseMessage("Device has removed successfully");
|
|
|
|
Response.status(HttpStatus.SC_OK);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
responseMsg.setResponseMessage("Device not found");
|
|
|
|
responseMsg.setResponseMessage("Device not found");
|
|
|
|
Response.status(HttpStatus.SC_NOT_FOUND);
|
|
|
|
Response.status(Response.Status.NOT_FOUND);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return responseMsg;
|
|
|
|
return responseMsg;
|
|
|
|
} catch (DeviceManagementServiceException deviceServiceMgtEx) {
|
|
|
|
} catch (DeviceManagementServiceException deviceServiceMgtEx) {
|
|
|
|