mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Merge branch 'master' of https://github.com/wso2/carbon-device-mgt
This commit is contained in:
commit
59028f9f09
@ -90,53 +90,66 @@ public interface DeviceManagementService {
|
||||
message = "Internal Server ErrorResponse. \n Server error occurred while fetching the device list.",
|
||||
response = ErrorResponse.class)
|
||||
})
|
||||
@Permission(scope = "device-list", permissions = {"/permission/admin/device-mgt/admin/devices/list"})
|
||||
@Permission(
|
||||
scope = "device-list",
|
||||
permissions = {"/permission/admin/device-mgt/admin/devices/list"}
|
||||
)
|
||||
Response getDevices(
|
||||
@ApiParam(
|
||||
name = "type",
|
||||
value = "The device type, such as ios, android or windows.",
|
||||
required = false)
|
||||
@QueryParam("type") String type,
|
||||
@QueryParam("type")
|
||||
String type,
|
||||
@ApiParam(
|
||||
name = "user", value = "Username of owner of the devices.",
|
||||
name = "user",
|
||||
value = "Username of owner of the devices.",
|
||||
required = false)
|
||||
@QueryParam("user") String user,
|
||||
@QueryParam("user")
|
||||
String user,
|
||||
@ApiParam(
|
||||
name = "roleName",
|
||||
value = "Role name of the devices to be fetched.",
|
||||
required = false)
|
||||
@QueryParam("roleName") String roleName,
|
||||
@QueryParam("roleName")
|
||||
String roleName,
|
||||
@ApiParam(
|
||||
name = "ownership",
|
||||
allowableValues = "BYOD, COPE",
|
||||
value = "Ownership of the devices to be fetched registered under.",
|
||||
required = false)
|
||||
@QueryParam("ownership") String ownership,
|
||||
@QueryParam("ownership")
|
||||
String ownership,
|
||||
@ApiParam(
|
||||
name = "status",
|
||||
value = "Enrollment status of devices to be fetched.",
|
||||
required = false)
|
||||
@QueryParam("status") String status,
|
||||
@QueryParam("status")
|
||||
String status,
|
||||
@ApiParam(
|
||||
name = "since",
|
||||
value = "Last modified timestamp",
|
||||
required = false)
|
||||
@QueryParam("since") String since,
|
||||
@QueryParam("since")
|
||||
String since,
|
||||
@ApiParam(
|
||||
name = "If-Modified-Since",
|
||||
value = "Timestamp of the last modified date",
|
||||
required = false)
|
||||
@HeaderParam("If-Modified-Since") String timestamp,
|
||||
@HeaderParam("If-Modified-Since")
|
||||
String timestamp,
|
||||
@ApiParam(
|
||||
name = "offset",
|
||||
value = "Starting point within the complete list of items qualified.",
|
||||
required = false)
|
||||
@QueryParam("offset") int offset,
|
||||
@QueryParam("offset")
|
||||
int offset,
|
||||
@ApiParam(
|
||||
name = "limit",
|
||||
value = "Maximum size of resource array to return.",
|
||||
required = false)
|
||||
@QueryParam("limit") int limit);
|
||||
@QueryParam("limit")
|
||||
int limit);
|
||||
|
||||
|
||||
@GET
|
||||
@ -184,25 +197,32 @@ public interface DeviceManagementService {
|
||||
"Server error occurred while retrieving information requested device.",
|
||||
response = ErrorResponse.class)
|
||||
})
|
||||
@Permission(scope = "device-view", permissions = {
|
||||
@Permission(
|
||||
scope = "device-view",
|
||||
permissions = {
|
||||
"/permission/admin/device-mgt/admin/devices/view",
|
||||
"/permission/admin/device-mgt/user/devices/view"})
|
||||
"/permission/admin/device-mgt/user/devices/view"
|
||||
}
|
||||
)
|
||||
Response getDevice(
|
||||
@ApiParam(
|
||||
name = "type",
|
||||
value = "The device type, such as ios, android or windows.",
|
||||
required = true)
|
||||
@PathParam("type") String type,
|
||||
@PathParam("type")
|
||||
String type,
|
||||
@ApiParam(
|
||||
name = "id",
|
||||
value = "The device identifier of the device.",
|
||||
required = true)
|
||||
@PathParam("id") String id,
|
||||
@PathParam("id")
|
||||
String id,
|
||||
@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);
|
||||
|
||||
@GET
|
||||
@Path("/{type}/{id}/features")
|
||||
@ -263,24 +283,31 @@ public interface DeviceManagementService {
|
||||
"Server error occurred while retrieving feature list of the device.",
|
||||
response = ErrorResponse.class)
|
||||
})
|
||||
@Permission(scope = "device-search", permissions = {"/permission/admin/device-mgt/admin/devices/view",
|
||||
"/permission/admin/device-mgt/user/devices/view"})
|
||||
@Permission(
|
||||
scope = "device-search",
|
||||
permissions = {"/permission/admin/device-mgt/admin/devices/view",
|
||||
"/permission/admin/device-mgt/user/devices/view"
|
||||
}
|
||||
)
|
||||
Response getFeaturesOfDevice(
|
||||
@ApiParam(
|
||||
name = "type",
|
||||
value = "The device type, such as ios, android or windows.",
|
||||
required = true)
|
||||
@PathParam("type") String type,
|
||||
@PathParam("type")
|
||||
String type,
|
||||
@ApiParam(
|
||||
name = "id",
|
||||
value = "The device identifier of the device.",
|
||||
required = true)
|
||||
@PathParam("id") String id,
|
||||
@PathParam("id")
|
||||
String id,
|
||||
@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);
|
||||
|
||||
@POST
|
||||
@Path("/search-devices")
|
||||
@ -335,23 +362,28 @@ public interface DeviceManagementService {
|
||||
"Server error occurred while enrolling the device.",
|
||||
response = ErrorResponse.class)
|
||||
})
|
||||
@Permission(scope = "device-search", permissions = {"/permission/admin/device-mgt/admin/devices/list"})
|
||||
@Permission(
|
||||
scope = "device-search",
|
||||
permissions = {"/permission/admin/device-mgt/admin/devices/list" }
|
||||
)
|
||||
Response searchDevices(
|
||||
@ApiParam(
|
||||
name = "offset",
|
||||
value = "Starting point within the complete list of items qualified.",
|
||||
required = false)
|
||||
@QueryParam("offset") int offset,
|
||||
@QueryParam("offset")
|
||||
int offset,
|
||||
@ApiParam(
|
||||
name = "limit",
|
||||
value = "Maximum size of resource array to return.",
|
||||
required = false)
|
||||
@QueryParam("limit") int limit,
|
||||
@QueryParam("limit")
|
||||
int limit,
|
||||
@ApiParam(
|
||||
name = "searchContext",
|
||||
value = "List of search conditions.",
|
||||
required = true)
|
||||
SearchContext searchContext);
|
||||
SearchContext searchContext);
|
||||
|
||||
@GET
|
||||
@Path("/{type}/{id}/applications")
|
||||
@ -378,7 +410,8 @@ public interface DeviceManagementService {
|
||||
"Used by caches, or in conditional requests."),
|
||||
@ResponseHeader(
|
||||
name = "Last-Modified",
|
||||
description = "Date and time the resource has been modified the last time.\n" +
|
||||
description = "Date and time the resource has been modified the "
|
||||
+ "last time.\n" +
|
||||
"Used by caches, or in conditional requests.")}),
|
||||
@ApiResponse(
|
||||
code = 303,
|
||||
@ -391,14 +424,16 @@ public interface DeviceManagementService {
|
||||
@ApiResponse(
|
||||
code = 304,
|
||||
message = "Not Modified. \n " +
|
||||
"Empty body because the client already has the latest version of the requested resource."),
|
||||
"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 Device of which the application list is requested, is not found.",
|
||||
message = "Not Found. \n Device of which the application list is requested, is "
|
||||
+ "not found.",
|
||||
response = ErrorResponse.class),
|
||||
@ApiResponse(
|
||||
code = 406,
|
||||
@ -406,38 +441,47 @@ public interface DeviceManagementService {
|
||||
@ApiResponse(
|
||||
code = 500,
|
||||
message = "Internal Server ErrorResponse. \n " +
|
||||
"Server error occurred while retrieving installed application list of the device.",
|
||||
"Server error occurred while retrieving installed application list of "
|
||||
+ "the device.",
|
||||
response = ErrorResponse.class)
|
||||
})
|
||||
@Permission(scope = "operation-view", permissions = {
|
||||
@Permission(
|
||||
scope = "operation-view",
|
||||
permissions = {
|
||||
"/permission/admin/device-mgt/admin/devices/view",
|
||||
"/permission/admin/device-mgt/user/devices/view"
|
||||
})
|
||||
}
|
||||
)
|
||||
Response getInstalledApplications(
|
||||
@ApiParam(
|
||||
name = "type",
|
||||
value = "The device type, such as ios, android or windows.", required = true)
|
||||
@PathParam("type") String type,
|
||||
@PathParam("type")
|
||||
String type,
|
||||
@ApiParam(
|
||||
name = "id",
|
||||
value = "The device identifier of the device.",
|
||||
required = true)
|
||||
@PathParam("id") String id,
|
||||
@PathParam("id")
|
||||
String id,
|
||||
@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,
|
||||
@ApiParam(
|
||||
name = "offset",
|
||||
value = "Starting point within the complete list of items qualified.",
|
||||
required = false)
|
||||
@QueryParam("offset") int offset,
|
||||
@QueryParam("offset")
|
||||
int offset,
|
||||
@ApiParam(
|
||||
name = "limit",
|
||||
value = "Maximum size of resource array to return.",
|
||||
required = false)
|
||||
@QueryParam("limit") int limit);
|
||||
@QueryParam("limit")
|
||||
int limit);
|
||||
|
||||
|
||||
@GET
|
||||
@ -446,9 +490,9 @@ public interface DeviceManagementService {
|
||||
produces = MediaType.APPLICATION_JSON,
|
||||
httpMethod = "GET",
|
||||
value = "Getting paginated details for operations on a device.",
|
||||
notes = "You will carry out many operations on a device. In a situation where you wish to view the all" +
|
||||
" the operations carried out on a device it is not feasible to show all the details on one page" +
|
||||
" therefore the details are paginated.",
|
||||
notes = "You will carry out many operations on a device. In a situation where you wish to view "
|
||||
+ "the all the operations carried out on a device it is not feasible to show all the "
|
||||
+ "details on one page therefore the details are paginated.",
|
||||
tags = "Device Management")
|
||||
@ApiResponses(
|
||||
value = {
|
||||
@ -467,7 +511,8 @@ public interface DeviceManagementService {
|
||||
"Used by caches, or in conditional requests."),
|
||||
@ResponseHeader(
|
||||
name = "Last-Modified",
|
||||
description = "Date and time the resource has been modified the last time.\n" +
|
||||
description = "Date and time the resource has been modified the "
|
||||
+ "last time.\n" +
|
||||
"Used by caches, or in conditional requests.")}),
|
||||
@ApiResponse(
|
||||
code = 303,
|
||||
@ -480,14 +525,16 @@ public interface DeviceManagementService {
|
||||
@ApiResponse(
|
||||
code = 304,
|
||||
message = "Not Modified. \n " +
|
||||
"Empty body because the client already has the latest version of the requested resource."),
|
||||
"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 Device of which the operation list is requested, is not found.",
|
||||
message = "Not Found. \n Device of which the operation list is requested, is not "
|
||||
+ "found.",
|
||||
response = ErrorResponse.class),
|
||||
@ApiResponse(
|
||||
code = 406,
|
||||
@ -495,39 +542,49 @@ public interface DeviceManagementService {
|
||||
@ApiResponse(
|
||||
code = 500,
|
||||
message = "Internal Server ErrorResponse. \n " +
|
||||
"Server error occurred while retrieving operation list scheduled for the device.",
|
||||
"Server error occurred while retrieving operation list scheduled for the "
|
||||
+ "device.",
|
||||
response = ErrorResponse.class)
|
||||
})
|
||||
@Permission(scope = "operation-view", permissions = {
|
||||
@Permission(
|
||||
scope = "operation-view",
|
||||
permissions = {
|
||||
"/permission/admin/device-mgt/admin/devices/view",
|
||||
"/permission/admin/device-mgt/user/devices/view"
|
||||
})
|
||||
}
|
||||
)
|
||||
Response getDeviceOperations(
|
||||
@ApiParam(
|
||||
name = "type",
|
||||
value = "The device type, such as ios, android or windows.",
|
||||
required = true)
|
||||
@PathParam("type") String type,
|
||||
@PathParam("type")
|
||||
String type,
|
||||
@ApiParam(
|
||||
name = "id",
|
||||
value = "The device identifier of the device.",
|
||||
required = true)
|
||||
@PathParam("id") String id,
|
||||
@PathParam("id")
|
||||
String id,
|
||||
@ApiParam(
|
||||
name = "If-Modified-Since",
|
||||
value = "Validates if the requested variant has not been modified since the time specified",
|
||||
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,
|
||||
@ApiParam(
|
||||
name = "offset",
|
||||
value = "Starting point within the complete list of items qualified.",
|
||||
required = false)
|
||||
@QueryParam("offset") int offset,
|
||||
@QueryParam("offset")
|
||||
int offset,
|
||||
@ApiParam(
|
||||
name = "limit",
|
||||
value = "Maximum size of resource array to return.",
|
||||
required = false)
|
||||
@QueryParam("limit") int limit);
|
||||
@QueryParam("limit")
|
||||
int limit);
|
||||
|
||||
@GET
|
||||
@Path("/{type}/{id}/effective-policy")
|
||||
@ -535,9 +592,10 @@ public interface DeviceManagementService {
|
||||
produces = MediaType.APPLICATION_JSON,
|
||||
httpMethod = "GET",
|
||||
value = "Get the effective policy calculated for a device.",
|
||||
notes = "When a device registers with WSO2 EMM a policy is enforced on the device. Initially the EMM " +
|
||||
"filters the policies based on the Platform (device type), filters based on the device ownership" +
|
||||
" type , filters based on the user role or name and finally the policy is enforced on the device.",
|
||||
notes = "When a device registers with WSO2 EMM a policy is enforced on the device. Initially the "
|
||||
+ "EMM filters the policies based on the Platform (device type), filters based on the "
|
||||
+ "device ownership type , filters based on the user role or name and finally the policy"
|
||||
+ " is enforced on the device.",
|
||||
tags = "Device Management")
|
||||
@ApiResponses(
|
||||
value = {
|
||||
@ -555,7 +613,8 @@ public interface DeviceManagementService {
|
||||
"Used by caches, or in conditional requests."),
|
||||
@ResponseHeader(
|
||||
name = "Last-Modified",
|
||||
description = "Date and time the resource has been modified the last time.\n" +
|
||||
description = "Date and time the resource has been modified the "
|
||||
+ "last time.\n" +
|
||||
"Used by caches, or in conditional requests.")}),
|
||||
@ApiResponse(
|
||||
code = 303,
|
||||
@ -568,14 +627,16 @@ public interface DeviceManagementService {
|
||||
@ApiResponse(
|
||||
code = 304,
|
||||
message = "Not Modified. \n " +
|
||||
"Empty body because the client already has the latest version of the requested resource."),
|
||||
"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 Device of which the effective policy is requested, is not found.",
|
||||
message = "Not Found. \n Device of which the effective policy is requested, is "
|
||||
+ "not found.",
|
||||
response = ErrorResponse.class),
|
||||
@ApiResponse(
|
||||
code = 406,
|
||||
@ -583,27 +644,50 @@ public interface DeviceManagementService {
|
||||
@ApiResponse(
|
||||
code = 500,
|
||||
message = "Internal Server ErrorResponse. \n " +
|
||||
"Server error occurred while retrieving the effective policy calculated for the device.",
|
||||
"Server error occurred while retrieving the effective policy calculated "
|
||||
+ "for the device.",
|
||||
response = ErrorResponse.class)
|
||||
})
|
||||
}
|
||||
)
|
||||
Response getEffectivePolicyOfDevice(
|
||||
@ApiParam(
|
||||
name = "type",
|
||||
value = "The device type, such as ios, android or windows.",
|
||||
required = true)
|
||||
@PathParam("type") String type,
|
||||
@PathParam("type")
|
||||
String type,
|
||||
@ApiParam(
|
||||
name = "id",
|
||||
value = "Device Identifier",
|
||||
required = true)
|
||||
@PathParam("id") String id,
|
||||
@PathParam("id")
|
||||
String id,
|
||||
@ApiParam(
|
||||
name = "If-Modified-Since",
|
||||
value = "Validates if the requested variant has not been modified since the time specified",
|
||||
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);
|
||||
|
||||
@GET
|
||||
@Path("/types")
|
||||
@ApiOperation(
|
||||
produces = MediaType.APPLICATION_JSON,
|
||||
httpMethod = "GET",
|
||||
value = "Get the device type.",
|
||||
notes = "You are able to register Android, iOS and Windows devices with WSO2 EMM. In order to"
|
||||
+ "retrieve the device type details that are registered this end-point van be used.",
|
||||
tags = "Device Management")
|
||||
@ApiResponses(
|
||||
value = {
|
||||
@ApiResponse(
|
||||
code = 200,
|
||||
message = "OK. \n Registered device types have successfully retrieved"),
|
||||
@ApiResponse(
|
||||
code = 500,
|
||||
message = "Error occurred while fetching the list of device types.")
|
||||
}
|
||||
)
|
||||
Response getDeviceTypes();
|
||||
}
|
||||
|
||||
@ -21,6 +21,7 @@ package org.wso2.carbon.device.mgt.jaxrs.service.api;
|
||||
import io.swagger.annotations.*;
|
||||
import org.wso2.carbon.apimgt.annotations.api.API;
|
||||
import org.wso2.carbon.apimgt.annotations.api.Permission;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||
import org.wso2.carbon.device.mgt.common.notification.mgt.Notification;
|
||||
import org.wso2.carbon.device.mgt.jaxrs.NotificationContext;
|
||||
import org.wso2.carbon.device.mgt.jaxrs.NotificationList;
|
||||
@ -88,31 +89,36 @@ public interface NotificationManagementService {
|
||||
message = "Internal Server ErrorResponse. \n Server error occurred while fetching the notification list.",
|
||||
response = ErrorResponse.class)
|
||||
})
|
||||
@Permission(scope = "device-notification-view", permissions = {
|
||||
@Permission(
|
||||
scope = "device-notification-view",
|
||||
permissions = {
|
||||
"/permission/admin/device-mgt/admin/notifications/view",
|
||||
"/permission/admin/device-mgt/user/notifications/view"
|
||||
})
|
||||
})
|
||||
Response getNotifications(
|
||||
@ApiParam(name = "status",
|
||||
@ApiParam(
|
||||
name = "status",
|
||||
value = "Status of the notification.",
|
||||
allowableValues = "NEW, CHECKED",
|
||||
required = false)
|
||||
@QueryParam("status") String status,
|
||||
@QueryParam("status")
|
||||
String status,
|
||||
@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,
|
||||
@ApiParam(
|
||||
name = "offset",
|
||||
value = "Starting point within the complete list of items qualified.",
|
||||
required = false)
|
||||
@QueryParam("offset") int offset,
|
||||
@QueryParam("offset")
|
||||
int offset,
|
||||
@ApiParam(
|
||||
name = "limit",
|
||||
value = "Maximum size of resource array to return.",
|
||||
required = false)
|
||||
@QueryParam("limit") int limit);
|
||||
|
||||
|
||||
@QueryParam("limit")
|
||||
int limit);
|
||||
}
|
||||
|
||||
@ -94,12 +94,15 @@ public interface PolicyManagementService {
|
||||
"Server error occurred while adding a new policy.",
|
||||
response = ErrorResponse.class)
|
||||
})
|
||||
@Permission(scope = "policy-modify", permissions = {"/permission/admin/device-mgt/admin/policies/add"})
|
||||
@Permission(
|
||||
scope = "policy-modify",
|
||||
permissions = {"/permission/admin/device-mgt/admin/policies/add"})
|
||||
Response addPolicy(
|
||||
@ApiParam(
|
||||
name = "policy",
|
||||
value = "Policy details related to the operation.",
|
||||
required = true) PolicyWrapper policy);
|
||||
required = true)
|
||||
PolicyWrapper policy);
|
||||
|
||||
@GET
|
||||
@ApiOperation(
|
||||
@ -146,23 +149,28 @@ public interface PolicyManagementService {
|
||||
"policies."),
|
||||
response = ErrorResponse.class)
|
||||
})
|
||||
@Permission(scope = "policy-view", permissions = {"/permission/admin/device-mgt/admin/policies/list"})
|
||||
@Permission(
|
||||
scope = "policy-view",
|
||||
permissions = {"/permission/admin/device-mgt/admin/policies/list"})
|
||||
Response getPolicies(
|
||||
@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,
|
||||
@ApiParam(
|
||||
name = "offset",
|
||||
value = "Starting point within the complete list of items qualified.",
|
||||
required = false)
|
||||
@QueryParam("offset") int offset,
|
||||
@QueryParam("offset")
|
||||
int offset,
|
||||
@ApiParam(
|
||||
name = "limit",
|
||||
value = "Maximum size of resource array to return.",
|
||||
required = false)
|
||||
@QueryParam("limit") int limit);
|
||||
@QueryParam("limit")
|
||||
int limit);
|
||||
|
||||
@GET
|
||||
@Path("/{id}")
|
||||
@ -209,18 +217,22 @@ public interface PolicyManagementService {
|
||||
"policy.",
|
||||
response = ErrorResponse.class)
|
||||
})
|
||||
@Permission(scope = "policy-view", permissions = {"/permission/admin/device-mgt/admin/policies/list"})
|
||||
@Permission(
|
||||
scope = "policy-view",
|
||||
permissions = {"/permission/admin/device-mgt/admin/policies/list"})
|
||||
Response getPolicy(
|
||||
@ApiParam(
|
||||
name = "id",
|
||||
value = "Policy identifier",
|
||||
required = true)
|
||||
@PathParam("id") int id,
|
||||
@PathParam("id")
|
||||
int id,
|
||||
@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
|
||||
@Path("/{id}")
|
||||
@ -269,16 +281,21 @@ public interface PolicyManagementService {
|
||||
"Server error occurred while updating the policy.",
|
||||
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 updatePolicy(
|
||||
@ApiParam(
|
||||
name = "id",
|
||||
value = "The device identifier of the device.", required = true)
|
||||
@PathParam("id") int id,
|
||||
value = "The device identifier of the device.",
|
||||
required = true)
|
||||
@PathParam("id")
|
||||
int id,
|
||||
@ApiParam(
|
||||
name = "policy",
|
||||
value = "Policy details related to the operation.",
|
||||
required = true) PolicyWrapper policy);
|
||||
required = true)
|
||||
PolicyWrapper policy);
|
||||
|
||||
@POST
|
||||
@Path("/remove-policy")
|
||||
@ -311,12 +328,15 @@ public interface PolicyManagementService {
|
||||
"Server error occurred while bulk removing policies.",
|
||||
response = ErrorResponse.class)
|
||||
})
|
||||
@Permission(scope = "policy-modify", permissions = {"/permission/admin/device-mgt/admin/policies/remove"})
|
||||
@Permission(
|
||||
scope = "policy-modify",
|
||||
permissions = {"/permission/admin/device-mgt/admin/policies/remove"})
|
||||
Response removePolicies(
|
||||
@ApiParam(
|
||||
name = "policyIds",
|
||||
value = "Policy id list to be deleted.",
|
||||
required = true) List<Integer> policyIds);
|
||||
required = true)
|
||||
List<Integer> policyIds);
|
||||
|
||||
@POST
|
||||
@Path("/activate-policy")
|
||||
@ -346,12 +366,16 @@ public interface PolicyManagementService {
|
||||
message = "ErrorResponse in activating policies.",
|
||||
response = ErrorResponse.class)
|
||||
})
|
||||
@Permission(scope = "policy-modify", permissions = {
|
||||
@Permission(
|
||||
scope = "policy-modify", permissions = {
|
||||
"/permission/admin/device-mgt/admin/policies/update",
|
||||
"/permission/admin/device-mgt/admin/policies/add"})
|
||||
Response activatePolicies(
|
||||
@ApiParam(name = "policyIds", value = "Policy ID list to be activated.",
|
||||
required = true) List<Integer> policyIds);
|
||||
@ApiParam(
|
||||
name = "policyIds",
|
||||
value = "Policy ID list to be activated.",
|
||||
required = true)
|
||||
List<Integer> policyIds);
|
||||
|
||||
@POST
|
||||
@Path("/deactivate-policy")
|
||||
@ -363,7 +387,8 @@ public interface PolicyManagementService {
|
||||
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 = {
|
||||
@ApiResponses(
|
||||
value = {
|
||||
@ApiResponse(
|
||||
code = 200,
|
||||
message = "Policies have been successfully deactivated."),
|
||||
@ -380,12 +405,17 @@ public interface PolicyManagementService {
|
||||
message = "ErrorResponse in deactivating policies.",
|
||||
response = ErrorResponse.class)
|
||||
})
|
||||
@Permission(scope = "policy-modify", permissions = {
|
||||
@Permission(
|
||||
scope = "policy-modify",
|
||||
permissions = {
|
||||
"/permission/admin/device-mgt/admin/policies/update",
|
||||
"/permission/admin/device-mgt/admin/policies/add"})
|
||||
Response deactivatePolicies(
|
||||
@ApiParam(name = "policyIds", value = "Policy ID list to be deactivated.",
|
||||
required = true) List<Integer> policyIds);
|
||||
@ApiParam(
|
||||
name = "policyIds",
|
||||
value = "Policy ID list to be deactivated.",
|
||||
required = true)
|
||||
List<Integer> policyIds);
|
||||
|
||||
@PUT
|
||||
@Produces("application/json")
|
||||
@ -399,8 +429,11 @@ public interface PolicyManagementService {
|
||||
" the policy enforcement criteria . In a situation where you need to make changes to existing" +
|
||||
" policies (removing, activating, deactivating and updating) or add new policies, the existing" +
|
||||
" devices will not receive these changes immediately. Once all the required changes are made" +
|
||||
" you need to apply the changes to push the policy changes to the existing devices.")
|
||||
@ApiResponses(value = {
|
||||
" you need to apply the changes to push the policy changes to the existing devices.",
|
||||
tags = "Device Policy Management"
|
||||
)
|
||||
@ApiResponses(
|
||||
value = {
|
||||
@ApiResponse(
|
||||
code = 200,
|
||||
message = "Changes have been successfully updated."),
|
||||
@ -420,10 +453,12 @@ public interface PolicyManagementService {
|
||||
produces = MediaType.APPLICATION_JSON,
|
||||
httpMethod = "PUT",
|
||||
value = "Prioritizing policies.",
|
||||
notes = "",
|
||||
notes = "If you wish to make changes to the existing policy priority order, you can do so by "
|
||||
+ "updating the priority order using this end-point",
|
||||
tags = "Device Policy Management"
|
||||
)
|
||||
@ApiResponses(value = {
|
||||
@ApiResponses(
|
||||
value = {
|
||||
@ApiResponse(
|
||||
code = 200,
|
||||
message = "Policy Priorities successfully updated."),
|
||||
@ -436,9 +471,15 @@ public interface PolicyManagementService {
|
||||
message = "Exception in updating policy priorities.",
|
||||
response = ErrorResponse.class)
|
||||
})
|
||||
@Permission(scope = "", permissions = {})
|
||||
Response updatePolicyPriorities(@ApiParam(name = "priorityUpdatedPolicies", value = "",
|
||||
required = true) List<PriorityUpdatedPolicyWrapper> priorityUpdatedPolicies);
|
||||
@Permission(
|
||||
scope = "",
|
||||
permissions = {})
|
||||
Response updatePolicyPriorities(
|
||||
@ApiParam(
|
||||
name = "priorityUpdatedPolicies",
|
||||
value = "List of policies with priorities",
|
||||
required = true)
|
||||
List<PriorityUpdatedPolicyWrapper> priorityUpdatedPolicies);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -321,6 +321,8 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
|
||||
}
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/types")
|
||||
@Override
|
||||
public Response getDeviceTypes() {
|
||||
List<DeviceType> deviceTypes;
|
||||
|
||||
@ -20,10 +20,16 @@ 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.DeviceIdentifier;
|
||||
import org.wso2.carbon.device.mgt.common.PaginationRequest;
|
||||
import org.wso2.carbon.device.mgt.common.PaginationResult;
|
||||
import org.wso2.carbon.device.mgt.common.notification.mgt.Notification;
|
||||
import org.wso2.carbon.device.mgt.common.notification.mgt.NotificationManagementException;
|
||||
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
|
||||
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
||||
import org.wso2.carbon.device.mgt.jaxrs.NotificationContext;
|
||||
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.*;
|
||||
import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.NotFoundException;
|
||||
@ -47,24 +53,33 @@ public class NotificationManagementServiceImpl implements NotificationManagement
|
||||
@QueryParam("status") String status,
|
||||
@HeaderParam("If-Modified-Since") String ifModifiedSince,
|
||||
@QueryParam("offset") int offset, @QueryParam("limit") int limit) {
|
||||
|
||||
PaginationRequest request = new PaginationRequest(offset, limit);
|
||||
PaginationResult result = null;
|
||||
|
||||
NotificationList notificationList = new NotificationList();
|
||||
int resultCount = 0;
|
||||
|
||||
String msg;
|
||||
List<Notification> notifications;
|
||||
try {
|
||||
if (status != null) {
|
||||
RequestValidationUtil.validateNotificationStatus(status);
|
||||
notifications =
|
||||
DeviceMgtAPIUtils.getNotificationManagementService().getNotificationsByStatus(
|
||||
Notification.Status.valueOf(status));
|
||||
result = DeviceMgtAPIUtils.getNotificationManagementService().getNotificationsByStatus(
|
||||
Notification.Status.valueOf(status),request);
|
||||
resultCount = result.getRecordsTotal();
|
||||
} else {
|
||||
notifications = DeviceMgtAPIUtils.getNotificationManagementService().getAllNotifications();
|
||||
result = DeviceMgtAPIUtils.getNotificationManagementService().getAllNotifications(request);
|
||||
}
|
||||
|
||||
if (notifications == null || notifications.size() == 0) {
|
||||
if (resultCount == 0) {
|
||||
throw new NotFoundException(
|
||||
new ErrorResponse.ErrorResponseBuilder().setCode(404l).setMessage("No notification is " +
|
||||
"available to be retrieved.").build());
|
||||
}
|
||||
return Response.status(Response.Status.OK).entity(notifications).build();
|
||||
|
||||
notificationList.setNotifications((List<Notification>) result.getData());
|
||||
notificationList.setCount(result.getRecordsTotal());
|
||||
return Response.status(Response.Status.OK).entity(notificationList).build();
|
||||
} catch (NotificationManagementException e) {
|
||||
msg = "Error occurred while retrieving notification info";
|
||||
log.error(msg, e);
|
||||
|
||||
@ -348,7 +348,7 @@ public class UserManagementServiceImpl implements UserManagementService {
|
||||
UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
|
||||
|
||||
//As the listUsers function accepts limit only to accommodate offset we are passing offset + limit
|
||||
String[] users = userStoreManager.listUsers(appliedFilter, appliedLimit);
|
||||
String[] users = userStoreManager.listUsers(appliedFilter + "*", appliedLimit);
|
||||
userList = new ArrayList<>(users.length);
|
||||
BasicUserInfo user;
|
||||
for (String username : users) {
|
||||
|
||||
@ -589,13 +589,13 @@
|
||||
</Permission>
|
||||
<Permission>
|
||||
<name>Deactivate Policy</name>
|
||||
<path>/device-mgt/user/policies/add</path>
|
||||
<path>/device-mgt/admin/policies/add</path>
|
||||
<url>/policies/deactivate-policy</url>
|
||||
<method>PUT</method>
|
||||
</Permission>
|
||||
<Permission>
|
||||
<name>Remove Policy</name>
|
||||
<path>/device-mgt/user/policies/remove</path>
|
||||
<path>/device-mgt/admin/policies/remove</path>
|
||||
<url>/policies/remove-policy</url>
|
||||
<method>POST</method>
|
||||
</Permission>
|
||||
|
||||
@ -19,6 +19,8 @@
|
||||
package org.wso2.carbon.device.mgt.common.notification.mgt;
|
||||
|
||||
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||
import org.wso2.carbon.device.mgt.common.PaginationRequest;
|
||||
import org.wso2.carbon.device.mgt.common.PaginationResult;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -69,6 +71,8 @@ public interface NotificationManagementService {
|
||||
*/
|
||||
List<Notification> getAllNotifications() throws NotificationManagementException;
|
||||
|
||||
PaginationResult getAllNotifications(PaginationRequest request) throws NotificationManagementException;
|
||||
|
||||
/**
|
||||
* @param status - Status of the notifications to be fetched from database.
|
||||
* @return A list of notifications matching the given status.
|
||||
@ -78,4 +82,7 @@ public interface NotificationManagementService {
|
||||
List<Notification> getNotificationsByStatus(Notification.Status status) throws
|
||||
NotificationManagementException;
|
||||
|
||||
PaginationResult getNotificationsByStatus(Notification.Status status,
|
||||
PaginationRequest request) throws NotificationManagementException;
|
||||
|
||||
}
|
||||
|
||||
@ -23,6 +23,8 @@ import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.device.mgt.common.Device;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||
import org.wso2.carbon.device.mgt.common.EntityDoesNotExistException;
|
||||
import org.wso2.carbon.device.mgt.common.PaginationRequest;
|
||||
import org.wso2.carbon.device.mgt.common.PaginationResult;
|
||||
import org.wso2.carbon.device.mgt.common.TransactionManagementException;
|
||||
import org.wso2.carbon.device.mgt.common.notification.mgt.Notification;
|
||||
import org.wso2.carbon.device.mgt.common.notification.mgt.NotificationManagementException;
|
||||
@ -35,6 +37,7 @@ import org.wso2.carbon.device.mgt.core.notification.mgt.dao.NotificationManageme
|
||||
import org.wso2.carbon.device.mgt.core.notification.mgt.dao.util.NotificationDAOUtil;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@ -157,6 +160,50 @@ public class NotificationManagementServiceImpl implements NotificationManagement
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public PaginationResult getAllNotifications(PaginationRequest request) throws NotificationManagementException {
|
||||
PaginationResult paginationResult = new PaginationResult();
|
||||
List<Notification> notifications = new ArrayList<>();
|
||||
int count =0;
|
||||
try {
|
||||
NotificationManagementDAOFactory.openConnection();
|
||||
notifications = notificationDAO.getAllNotifications(request, NotificationDAOUtil.getTenantId());
|
||||
count = notificationDAO.getNotificationCount(NotificationDAOUtil.getTenantId());
|
||||
paginationResult.setData(notifications);
|
||||
paginationResult.setRecordsFiltered(count);
|
||||
paginationResult.setRecordsTotal(count);
|
||||
return paginationResult;
|
||||
} catch (SQLException e) {
|
||||
throw new NotificationManagementException("Error occurred while opening a connection to" +
|
||||
" the data source", e);
|
||||
} finally {
|
||||
NotificationManagementDAOFactory.closeConnection();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public PaginationResult getNotificationsByStatus(Notification.Status status,
|
||||
PaginationRequest request) throws NotificationManagementException{
|
||||
PaginationResult paginationResult = new PaginationResult();
|
||||
List<Notification> notifications = new ArrayList<>();
|
||||
int count =0;
|
||||
try {
|
||||
NotificationManagementDAOFactory.openConnection();
|
||||
notifications = notificationDAO.getNotificationsByStatus(request, status, NotificationDAOUtil.getTenantId());
|
||||
count = notificationDAO.getNotificationCountByStatus(status, NotificationDAOUtil.getTenantId());
|
||||
paginationResult.setData(notifications);
|
||||
paginationResult.setRecordsFiltered(count);
|
||||
paginationResult.setRecordsTotal(count);
|
||||
return paginationResult;
|
||||
} catch (SQLException e) {
|
||||
throw new NotificationManagementException("Error occurred while opening a connection " +
|
||||
"to the data source", e);
|
||||
} finally {
|
||||
NotificationManagementDAOFactory.closeConnection();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<Notification> getNotificationsByStatus(Notification.Status status)
|
||||
throws NotificationManagementException {
|
||||
|
||||
@ -18,6 +18,8 @@
|
||||
|
||||
package org.wso2.carbon.device.mgt.core.notification.mgt.dao;
|
||||
|
||||
import org.wso2.carbon.device.mgt.common.PaginationRequest;
|
||||
import org.wso2.carbon.device.mgt.common.PaginationResult;
|
||||
import org.wso2.carbon.device.mgt.common.notification.mgt.Notification;
|
||||
import org.wso2.carbon.device.mgt.common.notification.mgt.NotificationManagementException;
|
||||
|
||||
@ -69,6 +71,12 @@ public interface NotificationDAO {
|
||||
*/
|
||||
List<Notification> getAllNotifications(int tenantId) throws NotificationManagementException;
|
||||
|
||||
List<Notification> getAllNotifications(PaginationRequest request, int tenantId) throws NotificationManagementException;
|
||||
|
||||
int getNotificationCount(int tenantId) throws NotificationManagementException;
|
||||
|
||||
int getNotificationCountByStatus(Notification.Status status, int tenantId) throws NotificationManagementException;
|
||||
|
||||
/**
|
||||
* This method is used to get all notifications based on notification-status.
|
||||
*
|
||||
@ -80,4 +88,7 @@ public interface NotificationDAO {
|
||||
List<Notification> getNotificationsByStatus(Notification.Status status, int tenantId) throws
|
||||
NotificationManagementException;
|
||||
|
||||
List<Notification> getNotificationsByStatus(PaginationRequest request, Notification.Status status, int tenantId) throws
|
||||
NotificationManagementException;
|
||||
|
||||
}
|
||||
|
||||
@ -18,8 +18,12 @@
|
||||
|
||||
package org.wso2.carbon.device.mgt.core.notification.mgt.dao.impl;
|
||||
|
||||
import org.wso2.carbon.device.mgt.common.PaginationRequest;
|
||||
import org.wso2.carbon.device.mgt.common.PaginationResult;
|
||||
import org.wso2.carbon.device.mgt.common.notification.mgt.Notification;
|
||||
import org.wso2.carbon.device.mgt.common.notification.mgt.NotificationManagementException;
|
||||
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException;
|
||||
import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil;
|
||||
import org.wso2.carbon.device.mgt.core.notification.mgt.dao.NotificationDAO;
|
||||
import org.wso2.carbon.device.mgt.core.notification.mgt.dao.NotificationManagementDAOFactory;
|
||||
import org.wso2.carbon.device.mgt.core.notification.mgt.dao.util.NotificationDAOUtil;
|
||||
@ -143,6 +147,85 @@ public class NotificationDAOImpl implements NotificationDAO {
|
||||
return notifications;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Notification> getAllNotifications(PaginationRequest request, int tenantId) throws NotificationManagementException {
|
||||
Connection conn;
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet rs = null;
|
||||
List<Notification> notifications = null;
|
||||
try {
|
||||
conn = NotificationManagementDAOFactory.getConnection();
|
||||
String sql =
|
||||
"SELECT n1.NOTIFICATION_ID, n1.DEVICE_ID, n1.OPERATION_ID, n1.STATUS, n1.DESCRIPTION," +
|
||||
" d.DEVICE_IDENTIFICATION, t.NAME AS DEVICE_TYPE FROM DM_DEVICE d, DM_DEVICE_TYPE t, (SELECT " +
|
||||
"NOTIFICATION_ID, DEVICE_ID, OPERATION_ID, STATUS, DESCRIPTION FROM DM_NOTIFICATION WHERE " +
|
||||
"TENANT_ID = ?) n1 WHERE n1.DEVICE_ID = d.ID AND d.DEVICE_TYPE_ID=t.ID AND TENANT_ID = ?";
|
||||
|
||||
sql = sql + " LIMIT ?,?";
|
||||
|
||||
stmt = conn.prepareStatement(sql);
|
||||
stmt.setInt(1, tenantId);
|
||||
stmt.setInt(2, tenantId);
|
||||
int paramIdx = 3;
|
||||
|
||||
stmt.setInt(paramIdx++, request.getStartIndex());
|
||||
stmt.setInt(paramIdx, request.getRowCount());
|
||||
|
||||
rs = stmt.executeQuery();
|
||||
notifications = new ArrayList<>();
|
||||
while (rs.next()) {
|
||||
notifications.add(this.getNotification(rs));
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new NotificationManagementException(
|
||||
"Error occurred while retrieving information of all notifications", e);
|
||||
} finally {
|
||||
NotificationDAOUtil.cleanupResources(stmt, rs);
|
||||
}
|
||||
return notifications;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getNotificationCount(int tenantId) throws NotificationManagementException {
|
||||
int notificationCount = 0;
|
||||
Connection conn;
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet rs = null;
|
||||
try {
|
||||
conn = NotificationManagementDAOFactory.getConnection();
|
||||
String sql =
|
||||
"SELECT COUNT(n1.NOTIFICATION_ID) AS NOTIFICATION_COUNT FROM DM_DEVICE d, DM_DEVICE_TYPE t, (SELECT " +
|
||||
"NOTIFICATION_ID, DEVICE_ID, OPERATION_ID, STATUS, DESCRIPTION FROM DM_NOTIFICATION WHERE " +
|
||||
"TENANT_ID = ?) n1 WHERE n1.DEVICE_ID = d.ID AND d.DEVICE_TYPE_ID=t.ID AND TENANT_ID = ?";
|
||||
|
||||
/*if (deviceType != null && !deviceType.isEmpty()) {
|
||||
sql = sql + " AND t.NAME = ?";
|
||||
isDeviceTypeProvided = true;
|
||||
}*/
|
||||
stmt = conn.prepareStatement(sql);
|
||||
stmt.setInt(1, tenantId);
|
||||
stmt.setInt(2, tenantId);
|
||||
//int paramIdx = 2;
|
||||
/*if (isDeviceTypeProvided) {
|
||||
stmt.setString(paramIdx++, request.getDeviceType());
|
||||
}*/
|
||||
|
||||
rs = stmt.executeQuery();
|
||||
if (rs.next()) {
|
||||
notificationCount = rs.getInt("NOTIFICATION_COUNT");
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new NotificationManagementException("Error occurred while retrieving information of all " +
|
||||
"notifications", e);
|
||||
} finally {
|
||||
NotificationDAOUtil.cleanupResources(stmt, rs);
|
||||
}
|
||||
return notificationCount;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public List<Notification> getNotificationsByStatus(Notification.Status status,
|
||||
int tenantId) throws NotificationManagementException {
|
||||
@ -177,6 +260,85 @@ public class NotificationDAOImpl implements NotificationDAO {
|
||||
return notifications;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getNotificationCountByStatus(Notification.Status status, int tenantId) throws NotificationManagementException {
|
||||
int notificationCountByStatus = 0;
|
||||
Connection conn;
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet rs = null;
|
||||
try {
|
||||
conn = NotificationManagementDAOFactory.getConnection();
|
||||
|
||||
String sql = "SELECT COUNT(n1.NOTIFICATION_ID) AS NOTIFICATION_COUNT FROM " +
|
||||
"DM_DEVICE d, DM_DEVICE_TYPE t, (SELECT NOTIFICATION_ID, DEVICE_ID, " +
|
||||
"OPERATION_ID, STATUS, DESCRIPTION FROM DM_NOTIFICATION WHERE " +
|
||||
"TENANT_ID = ? AND STATUS = ?) n1 WHERE n1.DEVICE_ID = d.ID AND d.DEVICE_TYPE_ID=t.ID " +
|
||||
"AND TENANT_ID = ?";
|
||||
|
||||
stmt = conn.prepareStatement(sql);
|
||||
stmt.setInt(1, tenantId);
|
||||
stmt.setString(2, status.toString());
|
||||
stmt.setInt(3, tenantId);
|
||||
|
||||
rs = stmt.executeQuery();
|
||||
if (rs.next()) {
|
||||
notificationCountByStatus = rs.getInt("NOTIFICATION_COUNT");
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new NotificationManagementException("Error occurred while retrieving information of all " +
|
||||
"notifications", e);
|
||||
} finally {
|
||||
NotificationDAOUtil.cleanupResources(stmt, rs);
|
||||
}
|
||||
return notificationCountByStatus;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Notification> getNotificationsByStatus(PaginationRequest request, Notification.Status status, int tenantId) throws
|
||||
NotificationManagementException{
|
||||
Connection conn;
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet rs = null;
|
||||
List<Notification> notifications = null;
|
||||
try {
|
||||
conn = NotificationManagementDAOFactory.getConnection();
|
||||
String sql = "SELECT n1.NOTIFICATION_ID, n1.DEVICE_ID, n1.OPERATION_ID, n1.STATUS," +
|
||||
" n1.DESCRIPTION, d.DEVICE_IDENTIFICATION, t.NAME AS DEVICE_TYPE FROM " +
|
||||
"DM_DEVICE d, DM_DEVICE_TYPE t, (SELECT NOTIFICATION_ID, DEVICE_ID, " +
|
||||
"OPERATION_ID, STATUS, DESCRIPTION FROM DM_NOTIFICATION WHERE " +
|
||||
"TENANT_ID = ? AND STATUS = ?) n1 WHERE n1.DEVICE_ID = d.ID AND d.DEVICE_TYPE_ID=t.ID " +
|
||||
"AND TENANT_ID = ?";
|
||||
|
||||
sql = sql + " LIMIT ?,?";
|
||||
|
||||
stmt = conn.prepareStatement(sql);
|
||||
stmt.setInt(1, tenantId);
|
||||
stmt.setString(2, status.toString());
|
||||
stmt.setInt(3, tenantId);
|
||||
|
||||
int paramIdx = 4;
|
||||
|
||||
stmt.setInt(paramIdx++, request.getStartIndex());
|
||||
stmt.setInt(paramIdx, request.getRowCount());
|
||||
|
||||
|
||||
rs = stmt.executeQuery();
|
||||
notifications = new ArrayList<>();
|
||||
while (rs.next()) {
|
||||
notifications.add(this.getNotification(rs));
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new NotificationManagementException(
|
||||
"Error occurred while retrieving information of all " +
|
||||
"notifications by status : " + status, e);
|
||||
} finally {
|
||||
NotificationDAOUtil.cleanupResources(stmt, rs);
|
||||
}
|
||||
return notifications;
|
||||
|
||||
}
|
||||
|
||||
private Notification getNotification(ResultSet rs) throws SQLException {
|
||||
Notification notification = new Notification();
|
||||
notification.setNotificationId(rs.getInt("NOTIFICATION_ID"));
|
||||
|
||||
Loading…
Reference in New Issue
Block a user