Merge pull request #223 from charithag/master

Add device modify and remove options
revert-70aa11f8
Ruwan 9 years ago
commit 4c50d4842d

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

@ -24,7 +24,7 @@ import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.mgt.jaxrs.api.common.MDMAPIException;
import org.wso2.carbon.device.mgt.jaxrs.api.util.DeviceMgtAPIUtils;
import org.wso2.carbon.device.mgt.jaxrs.beans.PriorityUpdatedPolicyWrapper;
import org.wso2.carbon.device.mgt.jaxrs.util.MDMUtil;
import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtUtil;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.jaxrs.api.util.ResponsePayload;
import org.wso2.carbon.device.mgt.jaxrs.beans.PolicyWrapper;
@ -62,7 +62,7 @@ public class Policy {
policy.setPolicyName(policyWrapper.getPolicyName());
policy.setProfileId(policyWrapper.getProfileId());
policy.setDescription(policyWrapper.getDescription());
policy.setProfile(MDMUtil.convertProfile(policyWrapper.getProfile()));
policy.setProfile(DeviceMgtUtil.convertProfile(policyWrapper.getProfile()));
policy.setOwnershipType(policyWrapper.getOwnershipType());
policy.setRoles(policyWrapper.getRoles());
policy.setUsers(policyWrapper.getUsers());
@ -82,7 +82,7 @@ public class Policy {
policy.setPolicyName(policyWrapper.getPolicyName());
policy.setProfileId(policyWrapper.getProfileId());
policy.setDescription(policyWrapper.getDescription());
policy.setProfile(MDMUtil.convertProfile(policyWrapper.getProfile()));
policy.setProfile(DeviceMgtUtil.convertProfile(policyWrapper.getProfile()));
policy.setOwnershipType(policyWrapper.getOwnershipType());
policy.setRoles(policyWrapper.getRoles());
policy.setUsers(policyWrapper.getUsers());
@ -181,7 +181,7 @@ public class Policy {
policy.setId(policyId);
policy.setProfileId(policyWrapper.getProfileId());
policy.setDescription(policyWrapper.getDescription());
policy.setProfile(MDMUtil.convertProfile(policyWrapper.getProfile()));
policy.setProfile(DeviceMgtUtil.convertProfile(policyWrapper.getProfile()));
policy.setOwnershipType(policyWrapper.getOwnershipType());
policy.setRoles(policyWrapper.getRoles());
policy.setUsers(policyWrapper.getUsers());

@ -24,7 +24,7 @@ import org.wso2.carbon.policy.mgt.common.Profile;
import java.util.ArrayList;
import java.util.List;
public class MDMUtil {
public class DeviceMgtUtil {
public static Profile convertProfile(org.wso2.carbon.device.mgt.jaxrs.beans.Profile mdmProfile) {
Profile profile = new Profile();

@ -206,6 +206,20 @@
<method>GET</method>
</Permission>
<Permission>
<name>Modify user device</name>
<path>/device-mgt/user/devices/update</path>
<url>/devices/type/*/id/*</url>
<method>PUT</method>
</Permission>
<Permission>
<name>Remove user device</name>
<path>/device-mgt/user/devices/remove</path>
<url>/devices/type/*/id/*</url>
<method>DELETE</method>
</Permission>
<!--<Permission>-->
<!--<name>Get device</name>-->
<!--<path>/device-mgt/devices/view</path>-->

@ -243,8 +243,7 @@ deviceModule = function () {
deviceObject[constants["DEVICE_PROPERTIES"]] = properties;
return deviceObject;
}
}
,
},
function (responsePayload) {
var response = {};
response["status"] = "error";
@ -266,8 +265,7 @@ deviceModule = function () {
return serviceInvokers.XMLHttp.get(
url, function (responsePayload) {
return responsePayload;
}
,
},
function (responsePayload) {
log.error(responsePayload);
return -1;
@ -280,8 +278,7 @@ deviceModule = function () {
return serviceInvokers.XMLHttp.get(
url, function (responsePayload) {
return responsePayload;
}
,
},
function (responsePayload) {
log.error(responsePayload);
return -1;
@ -289,14 +286,12 @@ deviceModule = function () {
);
};
publicMethods.getDeviceTypes = function () {
var url = devicemgtProps["httpsURL"] + constants.ADMIN_SERVICE_CONTEXT + "/devices/types";
return serviceInvokers.XMLHttp.get(
url, function (responsePayload) {
return responsePayload;
}
,
},
function (responsePayload) {
log.error(responsePayload);
return -1;
@ -336,8 +331,7 @@ deviceModule = function () {
responsePayload[i].thumb = utility.getDeviceThumb(responsePayload[i].type);
}
return responsePayload;
}
,
},
function (responsePayload) {
log.error(responsePayload);
return -1;

@ -96,7 +96,7 @@ $(document).ready(function () {
console.log(message);
}, function(message){
console.log(message.content);
});
});
});
});
@ -592,21 +592,19 @@ function attachDeviceEvents() {
$("a.remove-device-link").click(function () {
var deviceId = $(this).data("deviceid");
var deviceType = $(this).data("devicetype");
var removeDeviceAPI = "/devicemgt/api/devices/" + deviceType + "/" + deviceId + "/remove";
var serviceURL = "/devicemgt_admin/devices/type/" + deviceType + "/id/" + deviceId;
$(modalPopupContent).html($('#remove-device-modal-content').html());
showPopup();
$("a#remove-device-yes-link").click(function () {
var postOperationRequest = $.ajax({
url: removeDeviceAPI,
method: "post"
});
postOperationRequest.done(function (data) {
invokerUtil.delete(serviceURL, function (message) {
$(modalPopupContent).html($('#remove-device-200-content').html());
window.location.reload(false);
});
postOperationRequest.fail(function (jqXHR, textStatus) {
setTimeout(function () {
hidePopup();
location.reload(false);
}, 2000);
}, function (message) {
displayDeviceErrors(jqXHR);
});
});
@ -614,7 +612,6 @@ function attachDeviceEvents() {
$("a#remove-device-cancel-link").click(function () {
hidePopup();
});
});
/**
@ -626,7 +623,7 @@ function attachDeviceEvents() {
var deviceId = $(this).data("deviceid");
var deviceType = $(this).data("devicetype");
var deviceName = $(this).data("devicename");
var editDeviceAPI = "/devicemgt/api/devices/" + deviceType + "/" + deviceId + "/update?name=";
var serviceURL = "/devicemgt_admin/devices/type/" + deviceType + "/id/" + deviceId;
$(modalPopupContent).html($('#edit-device-modal-content').html());
$('#edit-device-name').val(deviceName);
@ -634,18 +631,13 @@ function attachDeviceEvents() {
$("a#edit-device-yes-link").click(function () {
var newDeviceName = $('#edit-device-name').val();
var postOperationRequest = $.ajax({
url: editDeviceAPI + newDeviceName,
method: "post"
});
postOperationRequest.done(function (data) {
invokerUtil.put(serviceURL, {"name": newDeviceName}, function (message) {
$(modalPopupContent).html($('#edit-device-200-content').html());
setTimeout(function () {
hidePopup();
location.reload(false);
}, 2000);
});
postOperationRequest.fail(function (jqXHR, textStatus) {
}, function (message) {
displayDeviceErrors(jqXHR);
});
});

Loading…
Cancel
Save