Fixing issues in GET /operations and /admin/devices APIs

4.x.x
dilanua 9 years ago
parent 7a029743ba
commit 25e45dc9f1

@ -326,8 +326,8 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
dms = DeviceMgtAPIUtils.getDeviceManagementService(); dms = DeviceMgtAPIUtils.getDeviceManagementService();
operations = dms.getOperations(new DeviceIdentifier(id, type)); operations = dms.getOperations(new DeviceIdentifier(id, type));
if (operations == null) { if (operations == null) {
Response.status(Response.Status.NOT_FOUND).entity("It is likely that no device is found upon " + return Response.status(Response.Status.NOT_FOUND).entity("It is likely that no device is found upon " +
"the provided type and id"); "the provided type and id").build();
} }
} catch (OperationManagementException e) { } catch (OperationManagementException e) {
String msg = "Error occurred while fetching the operations for the '" + type + "' device, which " + String msg = "Error occurred while fetching the operations for the '" + type + "' device, which " +

@ -25,9 +25,11 @@ import org.wso2.carbon.context.CarbonContext;
import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.device.mgt.common.Device; 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.jaxrs.beans.DeviceList;
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse; import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
import org.wso2.carbon.device.mgt.jaxrs.service.api.admin.DeviceManagementAdminService; import org.wso2.carbon.device.mgt.jaxrs.service.api.admin.DeviceManagementAdminService;
import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.UnauthorizedAccessException; import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.UnauthorizedAccessException;
import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.UnexpectedServerErrorException;
import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils; import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils;
import javax.ws.rs.*; import javax.ws.rs.*;
@ -67,11 +69,17 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
return Response.status(Response.Status.NOT_FOUND).entity("No device, which carries the name '" + return Response.status(Response.Status.NOT_FOUND).entity("No device, which carries the name '" +
name + "', is currently enrolled in the system").build(); name + "', is currently enrolled in the system").build();
} }
return Response.status(Response.Status.OK).entity(devices).build();
DeviceList deviceList = new DeviceList();
deviceList.setCount(devices.size());
deviceList.setList(devices);
return Response.status(Response.Status.OK).entity(deviceList).build();
} catch (DeviceManagementException e) { } catch (DeviceManagementException e) {
String msg = "Error occurred while fetching the devices that carry the name '" + name + "'"; String msg = "Error occurred at server side while fetching device list.";
log.error(msg, e); log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); throw new UnexpectedServerErrorException(
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build());
} finally { } finally {
PrivilegedCarbonContext.endTenantFlow(); PrivilegedCarbonContext.endTenantFlow();
} }

@ -394,6 +394,20 @@
<method>GET</method> <method>GET</method>
</Permission> </Permission>
<Permission>
<name>View device</name>
<path>/device-mgt/admin/devices/view</path>
<url>/devices/*/*/operations</url>
<method>GET</method>
</Permission>
<Permission>
<name>View device</name>
<path>/device-mgt/user/devices/view</path>
<url>/devices/*/*/operations</url>
<method>GET</method>
</Permission>
<!--<Permission>--> <!--<Permission>-->
<!--<name>Get Applications For Device Type</name>--> <!--<name>Get Applications For Device Type</name>-->
<!--<path>/device-mgt/operations/application/view</path>--> <!--<path>/device-mgt/operations/application/view</path>-->

Loading…
Cancel
Save