From 026bd175e929c9d7319e44a07e1d0d676999e5f4 Mon Sep 17 00:00:00 2001 From: charitha Date: Thu, 17 Jan 2019 22:46:32 +0530 Subject: [PATCH] Reformat & fix API publishing issue to Gateway --- .../service/api/DeviceManagementService.java | 194 ++++++++++ .../api/DeviceStatusManagementService.java | 360 ------------------ .../impl/DeviceManagementServiceImpl.java | 48 +++ .../DeviceStatusManagementServiceImpl.java | 93 ----- .../src/main/webapp/META-INF/permissions.xml | 12 - .../src/main/webapp/WEB-INF/cxf-servlet.xml | 2 - .../org.wso2.carbon.device.mgt.common/pom.xml | 5 - .../core/dao/impl/AbstractDeviceDAOImpl.java | 4 +- 8 files changed, 244 insertions(+), 474 deletions(-) delete mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceStatusManagementService.java delete mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceStatusManagementServiceImpl.java diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceManagementService.java index d4b52f2aab..ab50ccc8ab 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceManagementService.java @@ -60,6 +60,7 @@ import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; +import java.util.List; /** * Device related REST-API. This can be used to manipulated device related details. @@ -1452,5 +1453,198 @@ public interface DeviceManagementService { @ApiParam(name = "deviceOperation", value = "Operation object with device ids.", required = true) @Valid OperationRequest operationRequest); + @GET + @Path("/status/count/{type}/{status}") + @ApiOperation( + produces = MediaType.APPLICATION_JSON, + httpMethod = "GET", + value = "Get Device Count with status", + notes = "Get specified device count with status.", + tags = "Device Management", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "perm:devices:details") + }) + } + ) + @ApiResponses( + value = { + @ApiResponse( + code = 200, + message = "OK. \n Successfully fetched the details of the device.", + response = int.class, + responseHeaders = { + @ResponseHeader( + name = "Content-Type", + description = "The content type of the body"), + @ResponseHeader( + name = "ETag", + description = "Entity Tag of the response resource.\n" + + "Used by caches, or in conditional requests."), + @ResponseHeader( + name = "Last-Modified", + description = "Date and time the resource was last modified.\n" + + "Used by caches, or in conditional requests."), + }), + @ApiResponse( + code = 304, + message = "Not Modified. Empty body because the client already has the latest version" + + " of the requested resource.\n"), + @ApiResponse( + code = 400, + message = "Bad Request. \n Invalid request or validation error.", + response = ErrorResponse.class), + @ApiResponse( + code = 404, + message = "Not Found. \n A device with the specified device type and id was not found.", + response = ErrorResponse.class), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n " + + "Server error occurred while retrieving the device details.", + response = ErrorResponse.class) + }) + Response getDeviceCountByStatus( + @ApiParam( + name = "type", + value = "The device type name, such as ios, android, windows or fire-alarm.", + required = true) + @PathParam("type") + @Size(max = 45) + String type, + @ApiParam( + name = "status", + value = "The device identifier of the device you want ot get details.", + required = true) + @PathParam("status") + @Size(max = 45) + String status); + + + @GET + @Path("/status/ids/{type}/{status}") + @ApiOperation( + produces = MediaType.APPLICATION_JSON, + httpMethod = "GET", + value = "Getting Details of a Device", + notes = "Get the details of a device by specifying the device type and device identifier and optionally " + + "the owner.", + tags = "Device Management", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "perm:devices:details") + }) + } + ) + @ApiResponses( + value = { + @ApiResponse( + code = 200, + message = "OK. \n Successfully fetched the details of the device.", + response = String[].class, + responseHeaders = { + @ResponseHeader( + name = "Content-Type", + description = "The content type of the body"), + @ResponseHeader( + name = "ETag", + description = "Entity Tag of the response resource.\n" + + "Used by caches, or in conditional requests."), + @ResponseHeader( + name = "Last-Modified", + description = "Date and time the resource was last modified.\n" + + "Used by caches, or in conditional requests."), + }), + @ApiResponse( + code = 304, + message = "Not Modified. Empty body because the client already has the latest version" + + " of the requested resource.\n"), + @ApiResponse( + code = 400, + message = "Bad Request. \n Invalid request or validation error.", + response = ErrorResponse.class), + @ApiResponse( + code = 404, + message = "Not Found. \n A device with the specified device type and id was not found.", + response = ErrorResponse.class), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n " + + "Server error occurred while retrieving the device details.", + response = ErrorResponse.class) + }) + Response getDeviceIdentifiersByStatus( + @ApiParam( + name = "type", + value = "The device type name, such as ios, android, windows or fire-alarm.", + required = true) + @PathParam("type") + @Size(max = 45) + String type, + @ApiParam( + name = "status", + value = "The device identifier of the device you want ot get details.", + required = true) + @PathParam("status") + @Size(max = 45) + String status); + @PUT + @Path("/status/update/{type}/{status}") + @ApiOperation( + produces = MediaType.APPLICATION_JSON, + consumes = MediaType.APPLICATION_JSON, + httpMethod = "PUT", + value = "Changing the Status of a Devices", + notes = "Change the status of a devices from one state to another.", + tags = "Device Management", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "perm:devices:change-status") + }) + } + ) + @ApiResponses( + value = { + @ApiResponse( + code = 200, + message = "OK. \n Successfully changed the device status.", + response = Device.class, + responseHeaders = { + @ResponseHeader( + name = "Content-Type", + description = "The content type of the body"), + @ResponseHeader( + name = "ETag", + description = "Entity Tag of the response resource.\n" + + "Used by caches, or in conditional requests."), + @ResponseHeader( + name = "Last-Modified", + description = "Date and time the resource has been modified the last time.\n" + + "Used by caches, or in conditional requests."), + }), + @ApiResponse( + code = 304, + message = "Not Modified. Empty body because the client already has the latest " + + "version of the requested resource."), + @ApiResponse( + code = 400, + message = "Bad Request. \n Invalid request or validation error.", + response = ErrorResponse.class), + @ApiResponse( + code = 404, + message = "Not Found. \n No device is found under the provided type and id.", + response = ErrorResponse.class), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n " + + "Server error occurred while retrieving information requested device.", + response = ErrorResponse.class) + }) + Response bulkUpdateDeviceStatus(@ApiParam(name = "type", value = "The device type, such as ios, android or windows.", required = true) + @PathParam("type") String type, + @ApiParam(name = "status", value = "The device type, such as ios, android or windows.", required = true) + @PathParam("status") String status, + @ApiParam(name = "deviceList", value = "The payload containing the new name of the device.", required = true) + @Valid List deviceList); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceStatusManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceStatusManagementService.java deleted file mode 100644 index c300f1a5c9..0000000000 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceStatusManagementService.java +++ /dev/null @@ -1,360 +0,0 @@ -/* - * Copyright (c) 2019, Entgra (pvt) Ltd. (http://www.entgra.io) All Rights Reserved. - * - * Entgra (pvt) Ltd. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ -package org.wso2.carbon.device.mgt.jaxrs.service.api; - -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiOperation; -import io.swagger.annotations.ApiParam; -import io.swagger.annotations.ApiResponse; -import io.swagger.annotations.ApiResponses; -import io.swagger.annotations.Extension; -import io.swagger.annotations.ExtensionProperty; -import io.swagger.annotations.Info; -import io.swagger.annotations.ResponseHeader; -import io.swagger.annotations.SwaggerDefinition; -import io.swagger.annotations.Tag; -import org.wso2.carbon.apimgt.annotations.api.Scope; -import org.wso2.carbon.apimgt.annotations.api.Scopes; -import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse; -import org.wso2.carbon.device.mgt.jaxrs.util.Constants; - -import javax.validation.constraints.Size; -import javax.ws.rs.Consumes; -import javax.ws.rs.GET; -import javax.ws.rs.HeaderParam; -import javax.ws.rs.PUT; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; -import java.util.List; - -/** - * Device related REST-API. This can be used to manipulated device related details. - */ -@SwaggerDefinition( - info = @Info( - version = "1.0.0", - title = "", - extensions = { - @Extension(properties = { - @ExtensionProperty(name = "name", value = "DeviceStatusManagement"), - @ExtensionProperty(name = "context", value = "/api/device-mgt/v1.0/device-status"), - }) - } - ), - tags = { - @Tag(name = "device_status_management", description = "") - } -) -@Scopes( - scopes = { - @Scope( - name = "Getting Details of Registered Devices", - description = "Getting Details of Registered Devices", - key = "perm:devices:view", - permissions = {"/device-mgt/devices/owning-device/view"} - ), - @Scope( - name = "Getting Details of a Device", - description = "Getting Details of a Device", - key = "perm:devices:details", - permissions = {"/device-mgt/devices/owning-device/view"} - ), - @Scope( - name = "Update the device specified by device id", - description = "Update the device specified by device id", - key = "perm:devices:update", - permissions = {"/device-mgt/devices/owning-device/view"} - ), - @Scope( - name = "Delete the device specified by device id", - description = "Delete the device specified by device id", - key = "perm:devices:delete", - permissions = {"/device-mgt/devices/owning-device/view"} - ), - @Scope( - name = "Getting Feature Details of a Device", - description = "Getting Feature Details of a Device", - key = "perm:devices:features", - permissions = {"/device-mgt/devices/owning-device/view"} - ), - @Scope( - name = "Advanced Search for Devices", - description = "Advanced Search for Devices", - key = "perm:devices:search", - permissions = {"/device-mgt/devices/owning-device/view"} - ), - @Scope( - name = "Getting Installed Application Details of a Device", - description = "Getting Installed Application Details of a Device", - key = "perm:devices:applications", - permissions = {"/device-mgt/devices/owning-device/view"} - ), - @Scope( - name = "Getting Device Operation Details", - description = "Getting Device Operation Details", - key = "perm:devices:operations", - permissions = {"/device-mgt/devices/owning-device/view"} - ), - @Scope( - name = "Get the details of the policy that is enforced on a device.", - description = "Get the details of the policy that is enforced on a device.", - key = "perm:devices:effective-policy", - permissions = {"/device-mgt/devices/owning-device/view"} - ), - @Scope( - name = "Getting Policy Compliance Details of a Device", - description = "Getting Policy Compliance Details of a Device", - key = "perm:devices:compliance-data", - permissions = {"/device-mgt/devices/owning-device/view"} - ), - @Scope( - name = "Change device status.", - description = "Change device status.", - key = "perm:devices:change-status", - permissions = {"/device-mgt/devices/change-status"} - ), - } -) -@Path("/device-status") -@Api(value = "Device Status Management", description = "This API carries all device status management related operations " + - "such as get all the available devices, etc.") -@Produces(MediaType.APPLICATION_JSON) -@Consumes(MediaType.APPLICATION_JSON) -public interface DeviceStatusManagementService { - - @GET - @Path("/count/{type}/{status}") - @ApiOperation( - produces = MediaType.APPLICATION_JSON, - httpMethod = "GET", - value = "Getting Details of a Device", - notes = "Get the details of a device by specifying the device type and device identifier and optionally " + - "the owner.", - tags = "Device Status Management", - extensions = { - @Extension(properties = { - @ExtensionProperty(name = Constants.SCOPE, value = "perm:devices:details") - }) - } - ) - @ApiResponses( - value = { - @ApiResponse( - code = 200, - message = "OK. \n Successfully fetched the details of the device.", - response = int.class, - responseHeaders = { - @ResponseHeader( - name = "Content-Type", - description = "The content type of the body"), - @ResponseHeader( - name = "ETag", - description = "Entity Tag of the response resource.\n" + - "Used by caches, or in conditional requests."), - @ResponseHeader( - name = "Last-Modified", - description = "Date and time the resource was last modified.\n" + - "Used by caches, or in conditional requests."), - }), - @ApiResponse( - code = 304, - message = "Not Modified. Empty body because the client already has the latest version" + - " of the requested resource.\n"), - @ApiResponse( - code = 400, - message = "Bad Request. \n Invalid request or validation error.", - response = ErrorResponse.class), - @ApiResponse( - code = 404, - message = "Not Found. \n A device with the specified device type and id was not found.", - response = ErrorResponse.class), - @ApiResponse( - code = 500, - message = "Internal Server Error. \n " + - "Server error occurred while retrieving the device details.", - response = ErrorResponse.class) - }) - Response getDeviceCountByStatus( - @ApiParam( - name = "type", - value = "The device type name, such as ios, android, windows or fire-alarm.", - required = true) - @PathParam("type") - @Size(max = 45) - String type, - @ApiParam( - name = "status", - value = "The device identifier of the device you want ot get details.", - required = true) - @PathParam("status") - @Size(max = 45) - String status, - @ApiParam( - name = "If-Modified-Since", - value = "Checks if the requested variant was modified, since the specified date-time. \n" + - "Provide the value in the following format: EEE, d MMM yyyy HH:mm:ss Z. \n" + - "Example: Mon, 05 Jan 2014 15:10:00 +0200", - required = false) - @HeaderParam("If-Modified-Since") - String ifModifiedSince); - - - @GET - @Path("/ids/{type}/{status}") - @ApiOperation( - produces = MediaType.APPLICATION_JSON, - httpMethod = "GET", - value = "Getting Details of a Device", - notes = "Get the details of a device by specifying the device type and device identifier and optionally " + - "the owner.", - tags = "Device Status Management", - extensions = { - @Extension(properties = { - @ExtensionProperty(name = Constants.SCOPE, value = "perm:devices:details") - }) - } - ) - @ApiResponses( - value = { - @ApiResponse( - code = 200, - message = "OK. \n Successfully fetched the details of the device.", - response = String[].class, - responseHeaders = { - @ResponseHeader( - name = "Content-Type", - description = "The content type of the body"), - @ResponseHeader( - name = "ETag", - description = "Entity Tag of the response resource.\n" + - "Used by caches, or in conditional requests."), - @ResponseHeader( - name = "Last-Modified", - description = "Date and time the resource was last modified.\n" + - "Used by caches, or in conditional requests."), - }), - @ApiResponse( - code = 304, - message = "Not Modified. Empty body because the client already has the latest version" + - " of the requested resource.\n"), - @ApiResponse( - code = 400, - message = "Bad Request. \n Invalid request or validation error.", - response = ErrorResponse.class), - @ApiResponse( - code = 404, - message = "Not Found. \n A device with the specified device type and id was not found.", - response = ErrorResponse.class), - @ApiResponse( - code = 500, - message = "Internal Server Error. \n " + - "Server error occurred while retrieving the device details.", - response = ErrorResponse.class) - }) - Response getDeviceIdentifiersByStatus( - @ApiParam( - name = "type", - value = "The device type name, such as ios, android, windows or fire-alarm.", - required = true) - @PathParam("type") - @Size(max = 45) - String type, - @ApiParam( - name = "status", - value = "The device identifier of the device you want ot get details.", - required = true) - @PathParam("status") - @Size(max = 45) - String status, - @ApiParam( - name = "If-Modified-Since", - value = "Checks if the requested variant was modified, since the specified date-time. \n" + - "Provide the value in the following format: EEE, d MMM yyyy HH:mm:ss Z. \n" + - "Example: Mon, 05 Jan 2014 15:10:00 +0200", - required = false) - @HeaderParam("If-Modified-Since") - String ifModifiedSince); - - - @PUT - @Path("/update/{type}/{status}") - @ApiOperation( - produces = MediaType.APPLICATION_JSON, - consumes = MediaType.APPLICATION_JSON, - httpMethod = "PUT", - value = "Getting the Device Enrollment Status", - notes = "Get the device enrollment status and the device details of the device.", - tags = "Device Status Management", - extensions = { - @Extension(properties = { - @ExtensionProperty(name = Constants.SCOPE, value = "perm:devices:view") - }) - } - ) - @ApiResponses( - value = { - @ApiResponse( - code = 200, - message = "OK. \n Successfully created a device instance.", - responseHeaders = { - @ResponseHeader( - name = "Content-Type", - description = "The content type of the body"), - @ResponseHeader( - name = "ETag", - description = "Entity Tag of the response resource.\n" + - "Used by caches, or in conditional requests."), - @ResponseHeader( - name = "Last-Modified", - description = "Date and time the resource was last modified.\n" + - "Used by caches, or in conditional requests."), - }), - @ApiResponse( - code = 304, - message = "Not Modified. Empty body because the client already has the latest version" + - " of the requested resource.\n"), - @ApiResponse( - code = 400, - message = "Bad Request. \n Invalid request or validation error.", - response = ErrorResponse.class), - @ApiResponse( - code = 404, - message = "Not Found. \n A deviceType with the specified device type was not found.", - response = ErrorResponse.class), - @ApiResponse( - code = 500, - message = "Internal Server Error. \n " + - "Server error occurred while retrieving the device details.", - response = ErrorResponse.class) - }) - Response bulkUpdateDeviceStatus(@ApiParam(name = "type", value = "The device type, such as ios, android or windows.", required = true) - @PathParam("type") String type, - @ApiParam(name = "status", value = "The device type, such as ios, android or windows.", required = true) - @PathParam("status") String status, - @ApiParam( - name = "statusList", - value = "The payload containing the new name of the device.", - required = true) - List deviceList); - - -} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceManagementServiceImpl.java index 1d17ac9450..10aa8538fa 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceManagementServiceImpl.java @@ -788,4 +788,52 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); } } + + @GET + @Override + @Path("/status/count/{type}/{status}") + public Response getDeviceCountByStatus(@PathParam("type") String type, @PathParam("status") String status) { + int deviceCount; + try { + deviceCount = DeviceMgtAPIUtils.getDeviceManagementService().getDeviceCountOfTypeByStatus(type, status); + return Response.status(Response.Status.OK).entity(deviceCount).build(); + } catch (DeviceManagementException e) { + String errorMessage = "Error while retrieving device count."; + log.error(errorMessage, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity( + new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build(); + } + } + + @GET + @Override + @Path("/status/ids/{type}/{status}") + public Response getDeviceIdentifiersByStatus(@PathParam("type") String type, @PathParam("status") String status) { + List deviceIds; + try { + deviceIds = DeviceMgtAPIUtils.getDeviceManagementService().getDeviceIdentifiersByStatus(type, status); + return Response.status(Response.Status.OK).entity(deviceIds.toArray(new String[0])).build(); + } catch (DeviceManagementException e) { + String errorMessage = "Error while obtaining list of devices"; + log.error(errorMessage, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity( + new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build(); + } + } + + @PUT + @Override + @Path("/status/update/{type}/{status}") + public Response bulkUpdateDeviceStatus(@PathParam("type") String type, @PathParam("status") String status, + @Valid List deviceList) { + try { + DeviceMgtAPIUtils.getDeviceManagementService().bulkUpdateDeviceStatus(type, deviceList, status); + } catch (DeviceManagementException e) { + String errorMessage = "Error while updating device status in bulk."; + log.error(errorMessage, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity( + new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build(); + } + return Response.status(Response.Status.OK).build(); + } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceStatusManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceStatusManagementServiceImpl.java deleted file mode 100644 index 0cd23ca094..0000000000 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceStatusManagementServiceImpl.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright (c) 2019, Entgra (pvt) Ltd. (http://www.entgra.io) All Rights Reserved. - * - * Entgra (pvt) Ltd. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ -package org.wso2.carbon.device.mgt.jaxrs.service.impl; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.device.mgt.common.DeviceManagementException; -import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse; -import org.wso2.carbon.device.mgt.jaxrs.service.api.DeviceStatusManagementService; -import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils; - -import javax.ws.rs.Consumes; -import javax.ws.rs.GET; -import javax.ws.rs.HeaderParam; -import javax.ws.rs.PUT; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; -import java.util.List; - -@Path("/device-status") -@Produces(MediaType.APPLICATION_JSON) -@Consumes(MediaType.APPLICATION_JSON) -public class DeviceStatusManagementServiceImpl implements DeviceStatusManagementService { - - private static final Log log = LogFactory.getLog(DeviceStatusManagementServiceImpl.class); - - @GET - @Override - @Path("/count/{type}/{status}") - public Response getDeviceCountByStatus(@PathParam("type") String type, @PathParam("status") String status, - @HeaderParam("If-Modified-Since") String ifModifiedSince) { - int deviceCount; - try { - deviceCount = DeviceMgtAPIUtils.getDeviceManagementService().getDeviceCountOfTypeByStatus(type, status); - return Response.status(Response.Status.OK).entity(deviceCount).build(); - } catch (DeviceManagementException e) { - String errorMessage = "Error while retrieving device count."; - log.error(errorMessage, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity( - new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build(); - } - } - - @GET - @Override - @Path("/ids/{type}/{status}") - public Response getDeviceIdentifiersByStatus(@PathParam("type") String type, @PathParam("status") String status, String ifModifiedSince) { - List deviceIds; - try { - deviceIds = DeviceMgtAPIUtils.getDeviceManagementService().getDeviceIdentifiersByStatus(type, status); - return Response.status(Response.Status.OK).entity(deviceIds.toArray(new String[0])).build(); - } catch (DeviceManagementException e) { - String errorMessage = "Error while obtaining list of devices"; - log.error(errorMessage, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity( - new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build(); - } - } - - @PUT - @Override - @Path("/update/{type}/{status}") - public Response bulkUpdateDeviceStatus(@PathParam("type") String type, @PathParam("status") String status, List deviceList) { - try { - DeviceMgtAPIUtils.getDeviceManagementService().bulkUpdateDeviceStatus(type, deviceList, status); - } catch (DeviceManagementException e) { - String errorMessage = "Error while updating device status in bulk."; - log.error(errorMessage, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity( - new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build(); - } - return Response.status(Response.Status.OK).build(); - } -} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/webapp/META-INF/permissions.xml b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/webapp/META-INF/permissions.xml index 3bd974401b..befabcd097 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/webapp/META-INF/permissions.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/webapp/META-INF/permissions.xml @@ -56,18 +56,6 @@ /devices GET - - Get device Count - /device-mgt/devices/Status-Observer - /device-status/*/* - GET - - - Update device status - /device-mgt/devices/Status-Update - /device-status/update/* - PUT - Search devices /device-mgt/devices/Search diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/webapp/WEB-INF/cxf-servlet.xml b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/webapp/WEB-INF/cxf-servlet.xml index d5c1e9b4dc..e1e2c46e8c 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/webapp/WEB-INF/cxf-servlet.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/webapp/WEB-INF/cxf-servlet.xml @@ -26,7 +26,6 @@ - @@ -74,7 +73,6 @@ - diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.common/pom.xml index a01515dfe4..03cf504ccd 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/pom.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/pom.xml @@ -51,7 +51,6 @@ javax.xml.bind.annotation; version="${javax.xml.bind.imp.pkg.version}", com.fasterxml.jackson.annotation;version="${jackson-annotations.version}", org.wso2.carbon.analytics.datasource.commons;version="${carbon.analytics.version.range}", - com.google.gson, io.swagger.annotations; version="${swagger.annotations.version}"; resolution:=optional @@ -104,10 +103,6 @@ org.wso2.carbon.analytics org.wso2.carbon.analytics.datasource.commons - - com.google.code.gson - gson - diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/AbstractDeviceDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/AbstractDeviceDAOImpl.java index 2903373102..66e15a47cf 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/AbstractDeviceDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/AbstractDeviceDAOImpl.java @@ -556,7 +556,7 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO { List deviceIDs = new ArrayList<>(); try { conn = this.getConnection(); - String sql = "SELECT d.ID AS DEVICE_IDS FROM (SELECT e.DEVICE_ID FROM DM_ENROLMENT e WHERE " + + String sql = "SELECT d.DEVICE_IDENTIFICATION AS DEVICE_IDS FROM (SELECT e.DEVICE_ID FROM DM_ENROLMENT e WHERE " + "TENANT_ID = ? AND STATUS = ?) e, DM_DEVICE d, DM_DEVICE_TYPE t WHERE d.ID = e.DEVICE_ID AND " + "d.DEVICE_TYPE_ID = t.ID AND d.TENANT_ID = ? AND t.NAME=?"; stmt = conn.prepareStatement(sql); @@ -585,7 +585,7 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO { try { conn = this.getConnection(); StringBuilder sql = new StringBuilder("UPDATE DM_ENROLMENT SET STATUS = ? WHERE DEVICE_ID IN " + - "(SELECT d.ID FROM DM_DEVICE d, DM_DEVICE_TYPE t WHERE d.DEVICE_TYPE_ID = t.ID AND d.ID IN ("); + "(SELECT d.ID FROM DM_DEVICE d, DM_DEVICE_TYPE t WHERE d.DEVICE_TYPE_ID = t.ID AND d.DEVICE_IDENTIFICATION IN ("); for (int i = 0; i < devices.size(); i++) { sql.append("?,"); }