diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/ActivityInfoProviderService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/ActivityInfoProviderService.java index 275a31cd07..4adaa9ac14 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/ActivityInfoProviderService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/ActivityInfoProviderService.java @@ -91,7 +91,10 @@ public interface ActivityInfoProviderService { message = "Internal Server Error. \n Server error occurred while fetching activity data.", response = ErrorResponse.class) }) - @Permission(scope = "activity-view", permissions = {"/permission/admin/device-mgt/admin/activities/view"}) + @Permission( + scope = "activity-view", + permissions = {"/permission/admin/device-mgt/admin/activities/view"} + ) Response getActivity( @ApiParam( name = "id", @@ -150,7 +153,10 @@ public interface ActivityInfoProviderService { message = "Internal Server Error. \n Server error occurred while fetching activity data.", response = ErrorResponse.class) }) - @Permission(scope = "activity-view", permissions = {"/permission/admin/device-mgt/admin/activities/view"}) + @Permission( + scope = "activity-view", + permissions = {"/permission/admin/device-mgt/admin/activities/view"} + ) Response getActivities( @ApiParam( name = "since", diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/ConfigurationManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/ConfigurationManagementService.java index 5cbe24305d..fa6ed7527b 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/ConfigurationManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/ConfigurationManagementService.java @@ -47,7 +47,8 @@ public interface ConfigurationManagementService { value = "Get the general platform configurations.", notes = "Get the general platform level configuration details.", tags = "Configuration Management") - @ApiResponses(value = { + @ApiResponses( + value = { @ApiResponse( code = 200, message = "OK. \n Successfully fetched general platform configuration.", @@ -65,7 +66,8 @@ public interface ConfigurationManagementService { 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. \n Empty body because the client has already the latest version of " + @@ -78,15 +80,19 @@ public interface ConfigurationManagementService { message = "Internal Server Error. \n Server error occurred while fetching the general " + "platform configuration.", response = ErrorResponse.class) - }) - @Permission(scope = "configuration-view", - permissions = {"/permission/admin/device-mgt/admin/platform-configs/view"}) + } + ) + @Permission( + scope = "configuration-view", + permissions = {"/permission/admin/device-mgt/admin/platform-configs/view"} + ) Response getConfiguration( @ApiParam( name = "If-Modified-Since", value = "Validates if the requested variant has not been modified since the time specified", required = false) - @HeaderParam("If-Modified-Since") String ifModifiedSince); + @HeaderParam("If-Modified-Since") + String ifModifiedSince); @PUT @ApiOperation( @@ -96,7 +102,8 @@ public interface ConfigurationManagementService { value = "Update General Platform Configurations.", notes = "This resource is used to update the general platform configuration.", tags = "Configuration Management") - @ApiResponses(value = { + @ApiResponses( + value = { @ApiResponse( code = 200, message = "OK. \n General platform configuration has been updated successfully", @@ -123,13 +130,17 @@ public interface ConfigurationManagementService { message = "Internal Server Error. \n " + "Server error occurred while modifying general platform configuration.", response = ErrorResponse.class) - }) - @Permission(scope = "configuration-modify", - permissions = {"/permission/admin/device-mgt/admin/platform-configs/modify"}) + } + ) + @Permission( + scope = "configuration-modify", + permissions = {"/permission/admin/device-mgt/admin/platform-configs/modify"} + ) Response updateConfiguration( @ApiParam( name = "configuration", value = "The required properties to be updated in the platform configuration.", - required = true) PlatformConfiguration configuration); + required = true) + PlatformConfiguration configuration); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/NotificationManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/NotificationManagementService.java index 33838ef48d..669f7aace0 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/NotificationManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/NotificationManagementService.java @@ -89,13 +89,14 @@ public interface NotificationManagementService { message = "Internal Server Error. " + "\n Server error occurred while fetching the notification list.", response = ErrorResponse.class) - }) + } + ) @Permission( scope = "device-notification-view", permissions = { "/permission/admin/device-mgt/admin/notifications/view", - "/permission/admin/device-mgt/user/notifications/view" - }) + "/permission/admin/device-mgt/user/notifications/view" } + ) Response getNotifications( @ApiParam( name = "status", @@ -122,4 +123,15 @@ public interface NotificationManagementService { required = false) @QueryParam("limit") int limit); + + @PUT + @Path("{id}/{status}") + @ApiOperation( + produces = MediaType.APPLICATION_JSON, + httpMethod = "PUT", + value = "", + notes = "", + tags = "Device Notification Management") + Response updateNotificationStatus( + @PathParam("id") int id); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/PolicyManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/PolicyManagementService.java index 7fde2c4233..36301bd8f9 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/PolicyManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/PolicyManagementService.java @@ -69,7 +69,8 @@ public interface PolicyManagementService { 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 = 303, message = "See Other. \n Source can be retrieved from the URL specified at the Location header.", @@ -93,10 +94,12 @@ public interface PolicyManagementService { message = "Internal Server Error. \n " + "Server error occurred while adding a new policy.", response = ErrorResponse.class) - }) + } + ) @Permission( scope = "policy-modify", - permissions = {"/permission/admin/device-mgt/admin/policies/add"}) + permissions = {"/permission/admin/device-mgt/admin/policies/add"} + ) Response addPolicy( @ApiParam( name = "policy", @@ -132,7 +135,8 @@ public interface PolicyManagementService { 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. \n Empty body because the client has already the latest version of the requested resource."), @@ -148,10 +152,12 @@ public interface PolicyManagementService { message = ("Internal Server Error. \n Server error occurred while fetching " + "policies."), response = ErrorResponse.class) - }) + } + ) @Permission( scope = "policy-view", - permissions = {"/permission/admin/device-mgt/admin/policies/list"}) + permissions = {"/permission/admin/device-mgt/admin/policies/list"} + ) Response getPolicies( @ApiParam( name = "If-Modified-Since", @@ -199,15 +205,15 @@ public interface PolicyManagementService { 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. \n Empty body because the client has already the latest version of the requested resource."), @ApiResponse( code = 404, message = "Not Found. \n No policy is found with the given id.", - response = ErrorResponse.class - ), + response = ErrorResponse.class), @ApiResponse( code = 406, message = "Not Acceptable.\n The requested media type is not supported"), @@ -219,7 +225,8 @@ public interface PolicyManagementService { }) @Permission( scope = "policy-view", - permissions = {"/permission/admin/device-mgt/admin/policies/list"}) + permissions = {"/permission/admin/device-mgt/admin/policies/list"} + ) Response getPolicy( @ApiParam( name = "id", @@ -263,7 +270,9 @@ public interface PolicyManagementService { @ResponseHeader( name = "Last-Modified", description = "Date and time the resource has been modified the last time.\n" + - "Used by caches, or in conditional requests.")}), + "Used by caches, or in conditional requests.") + } + ), @ApiResponse( code = 400, message = "Bad Request. \n Invalid request or validation error.", @@ -280,10 +289,12 @@ public interface PolicyManagementService { message = "Internal Server Error. \n " + "Server error occurred while updating the policy.", response = ErrorResponse.class) - }) + } + ) @Permission( scope = "policy-modify", - permissions = {"/permission/admin/device-mgt/admin/policies/update"}) + permissions = {"/permission/admin/device-mgt/admin/policies/update"} + ) Response updatePolicy( @ApiParam( name = "id", @@ -321,16 +332,19 @@ public interface PolicyManagementService { response = ErrorResponse.class), @ApiResponse( code = 415, - message = "Unsupported media type. \n The entity of the request was in a not supported format."), + message = "Unsupported media type. \n The entity of the request was in a not " + + "supported format."), @ApiResponse( code = 500, message = "Internal Server Error. \n " + "Server error occurred while bulk removing policies.", response = ErrorResponse.class) - }) + } + ) @Permission( scope = "policy-modify", - permissions = {"/permission/admin/device-mgt/admin/policies/remove"}) + permissions = {"/permission/admin/device-mgt/admin/policies/remove"} + ) Response removePolicies( @ApiParam( name = "policyIds", @@ -365,11 +379,13 @@ public interface PolicyManagementService { code = 500, message = "ErrorResponse in activating policies.", response = ErrorResponse.class) - }) + } + ) @Permission( scope = "policy-modify", permissions = { "/permission/admin/device-mgt/admin/policies/update", - "/permission/admin/device-mgt/admin/policies/add"}) + "/permission/admin/device-mgt/admin/policies/add"} + ) Response activatePolicies( @ApiParam( name = "policyIds", @@ -384,8 +400,8 @@ public interface PolicyManagementService { produces = MediaType.APPLICATION_JSON, httpMethod = "PUT", value = "Deactivating policies.", - notes = "Using the REST API command you are able to unpublish a policy in order to bring a policy that " + - "is in the active state to the inactive state.", + notes = "Using the REST API command you are able to unpublish a policy in order to bring a " + + "policy that is in the active state to the inactive state.", tags = "Device Policy Management") @ApiResponses( value = { @@ -404,12 +420,14 @@ public interface PolicyManagementService { code = 500, message = "ErrorResponse in deactivating policies.", response = ErrorResponse.class) - }) + } + ) @Permission( scope = "policy-modify", permissions = { "/permission/admin/device-mgt/admin/policies/update", - "/permission/admin/device-mgt/admin/policies/add"}) + "/permission/admin/device-mgt/admin/policies/add"} + ) Response deactivatePolicies( @ApiParam( name = "policyIds", @@ -441,8 +459,12 @@ public interface PolicyManagementService { code = 500, message = "ErrorResponse in deactivating policies.", response = ErrorResponse.class) - }) - @Permission(scope = "policy-modify", permissions = {"/permission/admin/device-mgt/admin/policies/update"}) + } + ) + @Permission( + scope = "policy-modify", + permissions = {"/permission/admin/device-mgt/admin/policies/update"} + ) Response applyChanges(); @@ -470,7 +492,8 @@ public interface PolicyManagementService { code = 500, message = "Exception in updating policy priorities.", response = ErrorResponse.class) - }) + } + ) @Permission( scope = "", permissions = {}) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/NotificationManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/NotificationManagementServiceImpl.java index b9afcfa605..ec01db35cd 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/NotificationManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/NotificationManagementServiceImpl.java @@ -28,6 +28,7 @@ import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse; import org.wso2.carbon.device.mgt.jaxrs.beans.NotificationList; import org.wso2.carbon.device.mgt.jaxrs.service.api.NotificationManagementService; import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.RequestValidationUtil; +import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.UnexpectedServerErrorException; import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils; import javax.ws.rs.*; @@ -74,4 +75,29 @@ public class NotificationManagementServiceImpl implements NotificationManagement } } + @PUT + @Path("{id}/mark-checked") + public Response updateNotificationStatus( + @PathParam("id") int id) { + String msg; + Notification.Status status = Notification.Status.CHECKED; + Notification notification; + try { + DeviceMgtAPIUtils.getNotificationManagementService().updateNotificationStatus(id, status); + } catch (NotificationManagementException e) { + msg = "Error occurred while updating notification status."; + log.error(msg, e); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build()); + } + try { + notification = DeviceMgtAPIUtils.getNotificationManagementService().getNotification(id); + return Response.status(Response.Status.OK).entity(notification).build(); + } catch (NotificationManagementException e) { + msg = "Notification updated successfully. But the retrial of the updated notification failed"; + log.error(msg, e); + return Response.status(Response.Status.OK).build(); + } + } + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/notification/mgt/NotificationManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/notification/mgt/NotificationManagementService.java index c854e47279..cbf26cc4cf 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/notification/mgt/NotificationManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/notification/mgt/NotificationManagementService.java @@ -71,6 +71,8 @@ public interface NotificationManagementService { */ List getAllNotifications() throws NotificationManagementException; + Notification getNotification(int notificationId) throws NotificationManagementException; + PaginationResult getAllNotifications(PaginationRequest request) throws NotificationManagementException; /** diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/notification/mgt/NotificationManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/notification/mgt/NotificationManagementServiceImpl.java index ffac513eca..59692da94d 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/notification/mgt/NotificationManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/notification/mgt/NotificationManagementServiceImpl.java @@ -160,6 +160,19 @@ public class NotificationManagementServiceImpl implements NotificationManagement } } + @Override + public Notification getNotification(int notificationId) throws NotificationManagementException { + try { + NotificationManagementDAOFactory.openConnection(); + return notificationDAO.getNotification(NotificationDAOUtil.getTenantId(), notificationId); + } catch (SQLException e) { + throw new NotificationManagementException("Error occurred while opening a connection to" + + " the data source", e); + } finally { + NotificationManagementDAOFactory.closeConnection(); + } + } + @Override public PaginationResult getAllNotifications(PaginationRequest request) throws NotificationManagementException { PaginationResult paginationResult = new PaginationResult(); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/notification/mgt/dao/NotificationDAO.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/notification/mgt/dao/NotificationDAO.java index d2fc0efcb1..978d2cc3b7 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/notification/mgt/dao/NotificationDAO.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/notification/mgt/dao/NotificationDAO.java @@ -71,6 +71,8 @@ public interface NotificationDAO { */ List getAllNotifications(int tenantId) throws NotificationManagementException; + Notification getNotification(int tenantId, int notificationId) throws NotificationManagementException; + List getAllNotifications(PaginationRequest request, int tenantId) throws NotificationManagementException; int getNotificationCount(int tenantId) throws NotificationManagementException; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/notification/mgt/dao/impl/NotificationDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/notification/mgt/dao/impl/NotificationDAOImpl.java index 695832b3d2..608c5a4f2e 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/notification/mgt/dao/impl/NotificationDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/notification/mgt/dao/impl/NotificationDAOImpl.java @@ -70,6 +70,35 @@ public class NotificationDAOImpl implements NotificationDAO { return notificationId; } + @Override + public Notification getNotification(int tenantId, int notificationId) throws NotificationManagementException { + Connection conn; + PreparedStatement stmt = null; + ResultSet rs = null; + Notification notification = null; + try { + conn = NotificationManagementDAOFactory.getConnection(); + String sql = + "SELECT NOTIFICATION_ID, OPERATION_ID, DESCRIPTION, STATUS FROM DM_NOTIFICATION WHERE " + + "TENANT_ID = ? AND NOTIFICATION_ID = ?"; + stmt = conn.prepareStatement(sql); + stmt.setInt(1, tenantId); + stmt.setInt(2, notificationId); + rs = stmt.executeQuery(); + + while (rs.next()) { + notification = this.getNotification(rs); + } + } catch (SQLException e) { + throw new NotificationManagementException( + "Error occurred while retrieving information of all notifications", e); + } finally { + NotificationDAOUtil.cleanupResources(stmt, rs); + } + return notification; + + } + @Override public int updateNotification(Notification notification) throws NotificationManagementException {