|
|
|
@ -21,6 +21,7 @@ package org.wso2.carbon.device.mgt.jaxrs.api;
|
|
|
|
|
import org.apache.commons.httpclient.HttpStatus;
|
|
|
|
|
import org.apache.commons.logging.Log;
|
|
|
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
|
|
import org.wso2.carbon.device.mgt.core.service.DeviceManagementAdminService;
|
|
|
|
|
import org.wso2.carbon.device.mgt.jaxrs.api.util.DeviceMgtAPIUtils;
|
|
|
|
|
import org.wso2.carbon.device.mgt.jaxrs.api.util.ResponsePayload;
|
|
|
|
|
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
|
|
|
@ -30,7 +31,9 @@ import org.wso2.carbon.device.mgt.common.PaginationRequest;
|
|
|
|
|
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
|
|
|
|
|
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
|
|
|
|
|
|
|
|
|
import javax.ws.rs.DELETE;
|
|
|
|
|
import javax.ws.rs.GET;
|
|
|
|
|
import javax.ws.rs.PUT;
|
|
|
|
|
import javax.ws.rs.Path;
|
|
|
|
|
import javax.ws.rs.PathParam;
|
|
|
|
|
import javax.ws.rs.Produces;
|
|
|
|
@ -231,4 +234,52 @@ public class Device {
|
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Update device.
|
|
|
|
|
*
|
|
|
|
|
* @return update status.
|
|
|
|
|
*/
|
|
|
|
|
@PUT
|
|
|
|
|
@Path("type/{type}/id/{deviceId}")
|
|
|
|
|
public Response updateDevice(@PathParam("type") String deviceType, @PathParam("deviceId") String deviceId,
|
|
|
|
|
org.wso2.carbon.device.mgt.common.Device updatedDevice) {
|
|
|
|
|
try {
|
|
|
|
|
DeviceManagementProviderService deviceManagementService = DeviceMgtAPIUtils.getDeviceManagementService();
|
|
|
|
|
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
|
|
|
|
deviceIdentifier.setType(deviceType);
|
|
|
|
|
deviceIdentifier.setId(deviceId);
|
|
|
|
|
org.wso2.carbon.device.mgt.common.Device device = deviceManagementService.getDevice(deviceIdentifier);
|
|
|
|
|
device.setName(updatedDevice.getName());
|
|
|
|
|
device.setDescription(updatedDevice.getDescription());
|
|
|
|
|
Boolean response = deviceManagementService.modifyEnrollment(device);
|
|
|
|
|
return Response.status(Response.Status.OK).entity(response).build();
|
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
|
String msg = "Error occurred while fetching the list of device types.";
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* disenroll device.
|
|
|
|
|
*
|
|
|
|
|
* @return disenrollment status.
|
|
|
|
|
*/
|
|
|
|
|
@DELETE
|
|
|
|
|
@Path("type/{type}/id/{deviceId}")
|
|
|
|
|
public Response disenrollDevice(@PathParam("type") String deviceType, @PathParam("deviceId") String deviceId) {
|
|
|
|
|
try {
|
|
|
|
|
DeviceManagementProviderService deviceManagementService = DeviceMgtAPIUtils.getDeviceManagementService();
|
|
|
|
|
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
|
|
|
|
deviceIdentifier.setType(deviceType);
|
|
|
|
|
deviceIdentifier.setId(deviceId);
|
|
|
|
|
Boolean response = deviceManagementService.disenrollDevice(deviceIdentifier);
|
|
|
|
|
return Response.status(Response.Status.OK).entity(response).build();
|
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
|
String msg = "Error occurred while fetching the list of device types.";
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|