forked from community/device-mgt-core
Merge pull request #582 from charithag/master-update-swagger-docs
Update swagger docsrevert-70aa11f8
commit
54d0d7a5ee
@ -1,841 +0,0 @@
|
|||||||
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.Authorization;
|
|
||||||
import io.swagger.annotations.AuthorizationScope;
|
|
||||||
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.analytics.dashboard.bean.DeviceCountByGroup;
|
|
||||||
import org.wso2.carbon.device.mgt.jaxrs.beans.DashboardGadgetDataWrapper;
|
|
||||||
import org.wso2.carbon.device.mgt.jaxrs.beans.DashboardPaginationGadgetDataWrapper;
|
|
||||||
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
|
|
||||||
import org.wso2.carbon.device.mgt.jaxrs.util.Constants;
|
|
||||||
|
|
||||||
import javax.ws.rs.Consumes;
|
|
||||||
import javax.ws.rs.GET;
|
|
||||||
import javax.ws.rs.Path;
|
|
||||||
import javax.ws.rs.Produces;
|
|
||||||
import javax.ws.rs.QueryParam;
|
|
||||||
import javax.ws.rs.core.MediaType;
|
|
||||||
import javax.ws.rs.core.Response;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Device Analytics Dashboard related REST-APIs. This can be used to obtain device related analytics.
|
|
||||||
*/
|
|
||||||
@SwaggerDefinition(
|
|
||||||
info = @Info(
|
|
||||||
version = "1.0.0",
|
|
||||||
title = "",
|
|
||||||
extensions = {
|
|
||||||
@Extension(properties = {
|
|
||||||
@ExtensionProperty(name = "name", value = "DeviceAnalyticsDashboard"),
|
|
||||||
@ExtensionProperty(name = "context", value = "/api/device-mgt/v1.0/dashboard"),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
),
|
|
||||||
tags = {
|
|
||||||
@Tag(name = "device_management", description = "Device Analytics Dashboard related APIs.")
|
|
||||||
}
|
|
||||||
)
|
|
||||||
@Scopes(
|
|
||||||
scopes = {
|
|
||||||
@Scope(
|
|
||||||
name = "Device Count Overview",
|
|
||||||
description = "Device Count Overview",
|
|
||||||
key = "perm:dashboard:count-overview",
|
|
||||||
permissions = {"/device-mgt/dashboard/view"}
|
|
||||||
),
|
|
||||||
@Scope(
|
|
||||||
name = "Device Counts by Potential Vulnerabilities",
|
|
||||||
description = "Device Counts by Potential Vulnerabilities",
|
|
||||||
key = "perm:dashboard:vulnerabilities",
|
|
||||||
permissions = {"/device-mgt/dashboard/view"}
|
|
||||||
),
|
|
||||||
@Scope(
|
|
||||||
name = "Get the number of devices that have not complied to a policy",
|
|
||||||
description = "Get the number of devices that have not complied to a policy",
|
|
||||||
key = "perm:dashboard:non-compliant",
|
|
||||||
permissions = {"/device-mgt/dashboard/view"}
|
|
||||||
),
|
|
||||||
@Scope(
|
|
||||||
name = "Get the number of devices for a given device type, such as connectivity status, "
|
|
||||||
+ "potential vulnerability, platform, and ownership",
|
|
||||||
description = "Get the number of devices for a given device type, such as connectivity status, "
|
|
||||||
+ "potential vulnerability, platform, and ownership",
|
|
||||||
key = "perm:dashboard:by-groups",
|
|
||||||
permissions = {"/device-mgt/dashboard/view"}
|
|
||||||
),
|
|
||||||
@Scope(
|
|
||||||
name = "Get the number of devices that have not complied to a given policy based on a particular",
|
|
||||||
description = "Get the number of devices that have not complied to a given policy based on a particular",
|
|
||||||
key = "perm:dashboard:device-counts",
|
|
||||||
permissions = {"/device-mgt/dashboard/view"}
|
|
||||||
),
|
|
||||||
@Scope(
|
|
||||||
name = "Get the number of devices that have not complied to a given policy based on a particular"
|
|
||||||
+ " device type.",
|
|
||||||
description = "Get the number of devices that have not complied to a given policy based on a " +
|
|
||||||
"particular device type.",
|
|
||||||
key = "perm:dashboard:filtered-count",
|
|
||||||
permissions = {"/device-mgt/dashboard/view"}
|
|
||||||
),
|
|
||||||
@Scope(
|
|
||||||
name = "Get the number of devices that have not complied to a given policy over the total"
|
|
||||||
+ " number of devices registered with WSO2 EMM.\n",
|
|
||||||
description = "Get the number of devices that have not complied to a given policy over the total"
|
|
||||||
+ " number of devices registered with WSO2 EMM.\n",
|
|
||||||
key = "perm:dashboard:non-compliant-count",
|
|
||||||
permissions = {"/device-mgt/dashboard/view"}
|
|
||||||
),
|
|
||||||
@Scope(
|
|
||||||
name = "Get device details of devices based on a particular device type.",
|
|
||||||
description = "Get device details of devices based on a particular device type.",
|
|
||||||
key = "perm:dashboard:details",
|
|
||||||
permissions = {"/device-mgt/dashboard/view"}
|
|
||||||
),
|
|
||||||
@Scope(
|
|
||||||
name = "Get device details of non-compliant devices which do not comply to a given policy.",
|
|
||||||
description = "Get device details of non-compliant devices which do not comply to a given policy.",
|
|
||||||
key = "perm:dashboard:feature-non-compliant",
|
|
||||||
permissions = {"/device-mgt/dashboard/view"}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
@Path("/dashboard")
|
|
||||||
@Api(value = "Device Analytics Dashboard",
|
|
||||||
description = "Device Analytics Dashboard related information APIs are described here.")
|
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
|
||||||
public interface Dashboard {
|
|
||||||
|
|
||||||
String CONNECTIVITY_STATUS = "connectivity-status";
|
|
||||||
String POTENTIAL_VULNERABILITY = "potential-vulnerability";
|
|
||||||
String NON_COMPLIANT_FEATURE_CODE = "non-compliant-feature-code";
|
|
||||||
String PLATFORM = "platform";
|
|
||||||
String OWNERSHIP = "ownership";
|
|
||||||
// Constants related to pagination
|
|
||||||
String PAGINATION_ENABLED = "pagination-enabled";
|
|
||||||
String START_INDEX = "start";
|
|
||||||
String RESULT_COUNT = "length";
|
|
||||||
|
|
||||||
@GET
|
|
||||||
@Path("device-count-overview")
|
|
||||||
@ApiOperation(
|
|
||||||
produces = MediaType.APPLICATION_JSON,
|
|
||||||
httpMethod = "GET",
|
|
||||||
value = "Get the details of registered devices in WSO2 IoT.",
|
|
||||||
notes = "Get the details of active, inactive, removed and total number of registered devices in"
|
|
||||||
+ " WSO2 IoT.",
|
|
||||||
tags = "Dashboard",
|
|
||||||
extensions = {
|
|
||||||
@Extension(properties = {
|
|
||||||
@ExtensionProperty(name = Constants.SCOPE, value = "perm:dashboard:count-overview")
|
|
||||||
})
|
|
||||||
}
|
|
||||||
)
|
|
||||||
@ApiResponses(value = {
|
|
||||||
@ApiResponse(
|
|
||||||
code = 200,
|
|
||||||
message = "OK.",
|
|
||||||
response = DashboardGadgetDataWrapper.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. \n Empty body because the client has already the latest version of " +
|
|
||||||
"the requested resource."),
|
|
||||||
@ApiResponse(
|
|
||||||
code = 400,
|
|
||||||
message = "Bad Request. \n Invalid request or validation error.",
|
|
||||||
response = ErrorResponse.class),
|
|
||||||
@ApiResponse(
|
|
||||||
code = 401,
|
|
||||||
message = "Unauthorized. \n Unauthorized request."),
|
|
||||||
@ApiResponse(
|
|
||||||
code = 404,
|
|
||||||
message = "Not Found.",
|
|
||||||
response = ErrorResponse.class),
|
|
||||||
@ApiResponse(
|
|
||||||
code = 406,
|
|
||||||
message = "Not Acceptable.\n The requested media type is not supported"),
|
|
||||||
@ApiResponse(
|
|
||||||
code = 500,
|
|
||||||
message = "Internal Server Error. \n ErrorResponse in retrieving requested data.",
|
|
||||||
response = ErrorResponse.class)
|
|
||||||
})
|
|
||||||
Response getOverviewDeviceCounts();
|
|
||||||
|
|
||||||
@GET
|
|
||||||
@Path("device-counts-by-potential-vulnerabilities")
|
|
||||||
@ApiOperation(
|
|
||||||
produces = MediaType.APPLICATION_JSON,
|
|
||||||
httpMethod = "GET",
|
|
||||||
value = "Get the number of unmonitored and non-compliant devices in WSO2 IoT.",
|
|
||||||
tags = "Dashboard",
|
|
||||||
extensions = {
|
|
||||||
@Extension(properties = {
|
|
||||||
@ExtensionProperty(name = Constants.SCOPE, value = "perm:dashboard:vulnerabilities")
|
|
||||||
})
|
|
||||||
}
|
|
||||||
)
|
|
||||||
@ApiResponses(value = {
|
|
||||||
@ApiResponse(
|
|
||||||
code = 200,
|
|
||||||
message = "OK.",
|
|
||||||
response = DashboardGadgetDataWrapper.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. \n Empty body because the client has already the latest version of " +
|
|
||||||
"the requested resource."),
|
|
||||||
@ApiResponse(
|
|
||||||
code = 400,
|
|
||||||
message = "Bad Request. \n Invalid request or validation error.",
|
|
||||||
response = ErrorResponse.class),
|
|
||||||
@ApiResponse(
|
|
||||||
code = 401,
|
|
||||||
message = "Unauthorized. \n Unauthorized request."),
|
|
||||||
@ApiResponse(
|
|
||||||
code = 404,
|
|
||||||
message = "Not Found.",
|
|
||||||
response = ErrorResponse.class),
|
|
||||||
@ApiResponse(
|
|
||||||
code = 406,
|
|
||||||
message = "Not Acceptable.\n The requested media type is not supported"),
|
|
||||||
@ApiResponse(
|
|
||||||
code = 500,
|
|
||||||
message = "Internal Server Error. \n Server error occurred while fetching activity data.",
|
|
||||||
response = ErrorResponse.class)
|
|
||||||
})
|
|
||||||
Response getDeviceCountsByPotentialVulnerabilities();
|
|
||||||
|
|
||||||
@GET
|
|
||||||
@Path("non-compliant-device-counts-by-features")
|
|
||||||
@ApiOperation(
|
|
||||||
produces = MediaType.APPLICATION_JSON,
|
|
||||||
httpMethod = "GET",
|
|
||||||
value = "Get the number of devices that have not complied to a policy that was enforced on a "
|
|
||||||
+ "device.",
|
|
||||||
tags = "Dashboard",
|
|
||||||
extensions = {
|
|
||||||
@Extension(properties = {
|
|
||||||
@ExtensionProperty(name = Constants.SCOPE, value = "perm:dashboard:non-compliant")
|
|
||||||
})
|
|
||||||
}
|
|
||||||
)
|
|
||||||
@ApiResponses(value = {
|
|
||||||
@ApiResponse(
|
|
||||||
code = 200,
|
|
||||||
message = "OK.",
|
|
||||||
response = DashboardPaginationGadgetDataWrapper.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. \n Empty body because the client has already the latest version of " +
|
|
||||||
"the requested resource."),
|
|
||||||
@ApiResponse(
|
|
||||||
code = 400,
|
|
||||||
message = "Bad Request. \n",
|
|
||||||
response = ErrorResponse.class),
|
|
||||||
@ApiResponse(
|
|
||||||
code = 401,
|
|
||||||
message = "Unauthorized. \n Unauthorized request."),
|
|
||||||
@ApiResponse(
|
|
||||||
code = 404,
|
|
||||||
message = "Not Found. \n",
|
|
||||||
response = ErrorResponse.class),
|
|
||||||
@ApiResponse(
|
|
||||||
code = 406,
|
|
||||||
message = "Not Acceptable.\n The requested media type is not supported"),
|
|
||||||
@ApiResponse(
|
|
||||||
code = 500,
|
|
||||||
message = "Internal Server Error. \n ErrorResponse in retrieving requested data.",
|
|
||||||
response = ErrorResponse.class)
|
|
||||||
})
|
|
||||||
Response getNonCompliantDeviceCountsByFeatures(
|
|
||||||
@ApiParam(
|
|
||||||
name = "start",
|
|
||||||
value = "Provide the starting pagination index. Example 10",
|
|
||||||
required = true)
|
|
||||||
@QueryParam(START_INDEX) int startIndex,
|
|
||||||
@ApiParam(
|
|
||||||
name = "length",
|
|
||||||
value = "Provide how many policy details you require from the starting pagination index."
|
|
||||||
+ " For example if you require the non-compliant policy details from the 10th "
|
|
||||||
+ "pagination index to the 15th, you must define 10 as the value for start and "
|
|
||||||
+ "5 as the value for length.",
|
|
||||||
required = true)
|
|
||||||
@QueryParam(RESULT_COUNT) int resultCount);
|
|
||||||
|
|
||||||
@GET
|
|
||||||
@Path("device-counts-by-groups")
|
|
||||||
@ApiOperation(
|
|
||||||
produces = MediaType.APPLICATION_JSON,
|
|
||||||
httpMethod = "GET",
|
|
||||||
value = "Get the number of devices for a given device type, such as connectivity status, "
|
|
||||||
+ "potential vulnerability, platform, and ownership.\n",
|
|
||||||
tags = "Dashboard",
|
|
||||||
extensions = {
|
|
||||||
@Extension(properties = {
|
|
||||||
@ExtensionProperty(name = Constants.SCOPE, value = "perm:dashboard:by-groups")
|
|
||||||
})
|
|
||||||
}
|
|
||||||
)
|
|
||||||
@ApiResponses(value = {
|
|
||||||
@ApiResponse(
|
|
||||||
code = 200,
|
|
||||||
message = "OK.",
|
|
||||||
response = DeviceCountByGroup.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. \n Empty body because the client has already the latest version of " +
|
|
||||||
"the requested resource."),
|
|
||||||
@ApiResponse(
|
|
||||||
code = 400,
|
|
||||||
message = "Bad Request.",
|
|
||||||
response = ErrorResponse.class),
|
|
||||||
@ApiResponse(
|
|
||||||
code = 401,
|
|
||||||
message = "Unauthorized. \n Unauthorized request."),
|
|
||||||
@ApiResponse(
|
|
||||||
code = 404,
|
|
||||||
message = "Not Found.",
|
|
||||||
response = ErrorResponse.class),
|
|
||||||
@ApiResponse(
|
|
||||||
code = 406,
|
|
||||||
message = "Not Acceptable.\n The requested media type is not supported"),
|
|
||||||
@ApiResponse(
|
|
||||||
code = 500,
|
|
||||||
message = "Internal Server Error. \n ErrorResponse in retrieving requested data.",
|
|
||||||
response = ErrorResponse.class)
|
|
||||||
})
|
|
||||||
Response getDeviceCountsByGroups(
|
|
||||||
@ApiParam(
|
|
||||||
name = "connectivity-status",
|
|
||||||
value = "Provide the connectivity status of the device. The following values can be assigned:\n"
|
|
||||||
+ "active: The devices that are registered with WSO2 IoT and are actively "
|
|
||||||
+ "communicating with the server.\n"
|
|
||||||
+ "inactive: The devices that are registered with WSO2 IoT but unable to "
|
|
||||||
+ "actively communicate with the server.\n"
|
|
||||||
+ "removed: The devices that have unregistered from WSO2 IoT",
|
|
||||||
required = true)
|
|
||||||
@QueryParam(CONNECTIVITY_STATUS) String connectivityStatus,
|
|
||||||
@ApiParam(
|
|
||||||
name = "potential-vulnerability",
|
|
||||||
value = "Provide details of the potential vulnerabilities of the device. The following "
|
|
||||||
+ "values can be assigned:\n"
|
|
||||||
+ "non-compliant: Devices that have not complied to the policies enforced on the "
|
|
||||||
+ "device by WSO2 IoT.\n"
|
|
||||||
+ "unmonitored: Devices that have no policy assigned to them.",
|
|
||||||
required = true)
|
|
||||||
@QueryParam(POTENTIAL_VULNERABILITY) String potentialVulnerability,
|
|
||||||
@ApiParam(
|
|
||||||
name = "platform",
|
|
||||||
value = "Provide the platform that the device is running on. The following values can "
|
|
||||||
+ "be assigned:\n"
|
|
||||||
+ "iOS\n" + "Android\n" + "Windows",
|
|
||||||
required = true)
|
|
||||||
@QueryParam(PLATFORM) String platform,
|
|
||||||
@ApiParam(
|
|
||||||
name = "ownership",
|
|
||||||
value = "Provide the ownership status of the device. The following values can be assigned:\n"
|
|
||||||
+ "BYOD: Bring Your Own Device\n" + "COPE: Corporate-Owned, Personally-Enabled",
|
|
||||||
required = true)
|
|
||||||
@QueryParam(OWNERSHIP) String ownership);
|
|
||||||
|
|
||||||
@GET
|
|
||||||
@Path("feature-non-compliant-device-counts-by-groups")
|
|
||||||
@ApiOperation(
|
|
||||||
produces = MediaType.APPLICATION_JSON,
|
|
||||||
httpMethod = "GET",
|
|
||||||
value = "Get the number of devices that have not complied to a given policy based on a particular"
|
|
||||||
+ " device type.",
|
|
||||||
tags = "Dashboard",
|
|
||||||
extensions = {
|
|
||||||
@Extension(properties = {
|
|
||||||
@ExtensionProperty(name = Constants.SCOPE, value = "perm:dashboard:device-counts")
|
|
||||||
})
|
|
||||||
}
|
|
||||||
)
|
|
||||||
@ApiResponses(value = {
|
|
||||||
@ApiResponse(
|
|
||||||
code = 200,
|
|
||||||
message = "OK.",
|
|
||||||
response = DeviceCountByGroup.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. \n Empty body because the client has already the latest version of " +
|
|
||||||
"the requested resource."),
|
|
||||||
@ApiResponse(
|
|
||||||
code = 400,
|
|
||||||
message = "Bad Request.",
|
|
||||||
response = ErrorResponse.class),
|
|
||||||
@ApiResponse(
|
|
||||||
code = 401,
|
|
||||||
message = "Unauthorized. \n Unauthorized request."),
|
|
||||||
@ApiResponse(
|
|
||||||
code = 404,
|
|
||||||
message = "Not Found.",
|
|
||||||
response = ErrorResponse.class),
|
|
||||||
@ApiResponse(
|
|
||||||
code = 406,
|
|
||||||
message = "Not Acceptable.\n The requested media type is not supported"),
|
|
||||||
@ApiResponse(
|
|
||||||
code = 500,
|
|
||||||
message = "Internal Server Error. \n ErrorResponse in retrieving requested data.",
|
|
||||||
response = ErrorResponse.class)
|
|
||||||
})
|
|
||||||
Response getFeatureNonCompliantDeviceCountsByGroups(
|
|
||||||
@ApiParam(
|
|
||||||
name = "non-compliant-feature-code",
|
|
||||||
value = "As the value for this parameter, the policy feature code or ID can be used. Some"
|
|
||||||
+ " examples for feature codes are: PASSCODE_POLICY,CAMERA and WIFI.",
|
|
||||||
required = true)
|
|
||||||
@QueryParam(NON_COMPLIANT_FEATURE_CODE) String nonCompliantFeatureCode,
|
|
||||||
@ApiParam(
|
|
||||||
name = "platform",
|
|
||||||
value = "Provide the platform that the device is running on. The following values can "
|
|
||||||
+ "be assigned:\n"
|
|
||||||
+ "iOS\n" + "Android\n" + "Windows",
|
|
||||||
required = false)
|
|
||||||
@QueryParam(PLATFORM) String platform,
|
|
||||||
@ApiParam(
|
|
||||||
name = "ownership",
|
|
||||||
value = "Provide the ownership status of the device. The following values can be assigned:\n"
|
|
||||||
+ "BYOD: Bring Your Own Device\n" + "COPE: Corporate-Owned, Personally-Enabled",
|
|
||||||
required = false)
|
|
||||||
@QueryParam(OWNERSHIP) String ownership);
|
|
||||||
|
|
||||||
@GET
|
|
||||||
@Path("filtered-device-count-over-total")
|
|
||||||
@ApiOperation(
|
|
||||||
produces = MediaType.APPLICATION_JSON,
|
|
||||||
httpMethod = "GET",
|
|
||||||
value = "Get the number of devices that are registered with WSO2 IoT filtered by one of the "
|
|
||||||
+ "following attributes:\n"
|
|
||||||
+ "Connectivity status of the device, such as active, inactive or removed.\n"
|
|
||||||
+ "The device ownership type, such as BYOD or COPE.\n" + "The device platform.\n"
|
|
||||||
+ "The potential vulnerabilities faced by the devices.",
|
|
||||||
tags = "Dashboard",
|
|
||||||
extensions = {
|
|
||||||
@Extension(properties = {
|
|
||||||
@ExtensionProperty(name = Constants.SCOPE, value = "perm:dashboard:filtered-count")
|
|
||||||
})
|
|
||||||
}
|
|
||||||
)
|
|
||||||
@ApiResponses(value = {
|
|
||||||
@ApiResponse(
|
|
||||||
code = 200,
|
|
||||||
message = "OK.",
|
|
||||||
response = DashboardGadgetDataWrapper.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. \n Empty body because the client has already the latest version of " +
|
|
||||||
"the requested resource."),
|
|
||||||
@ApiResponse(
|
|
||||||
code = 400,
|
|
||||||
message = "Bad Request.",
|
|
||||||
response = ErrorResponse.class),
|
|
||||||
@ApiResponse(
|
|
||||||
code = 401,
|
|
||||||
message = "Unauthorized. \n Unauthorized request."),
|
|
||||||
@ApiResponse(
|
|
||||||
code = 404,
|
|
||||||
message = "Not Found.",
|
|
||||||
response = ErrorResponse.class),
|
|
||||||
@ApiResponse(
|
|
||||||
code = 406,
|
|
||||||
message = "Not Acceptable.\n The requested media type is not supported"),
|
|
||||||
@ApiResponse(
|
|
||||||
code = 500,
|
|
||||||
message = "Internal Server Error. \n ErrorResponse in retrieving requested data.",
|
|
||||||
response = ErrorResponse.class)
|
|
||||||
})
|
|
||||||
Response getFilteredDeviceCountOverTotal(
|
|
||||||
@ApiParam(
|
|
||||||
name = "connectivity-status",
|
|
||||||
value = "Provide the connectivity status of the device. You can assign any of the values "
|
|
||||||
+ "given below:\n"
|
|
||||||
+ "Total: All the devices that have registered with WSO2 IoT.\n"
|
|
||||||
+ "active: The devices that are registered with WSO2 IoT and are actively "
|
|
||||||
+ "communicating with the server.\n"
|
|
||||||
+ "inactive: The devices that are registered with WSO2 IoT but unable to actively"
|
|
||||||
+ " communicate with the server.\n"
|
|
||||||
+ "removed: The devices that have unregistered from WSO2 IoT.",
|
|
||||||
required = true)
|
|
||||||
@QueryParam(CONNECTIVITY_STATUS) String connectivityStatus,
|
|
||||||
@ApiParam(
|
|
||||||
name = "potential-vulnerability",
|
|
||||||
value = "Provide details of the potential vulnerabilities of the device. You can assign"
|
|
||||||
+ " any of the values given below:\n"
|
|
||||||
+ "non-compliant: Devices that have not complied to the policies enforced on the "
|
|
||||||
+ "device by WSO2 IoT.\n"
|
|
||||||
+ "unmonitored: Devices that have no policy assigned to them.",
|
|
||||||
required = true)
|
|
||||||
@QueryParam(POTENTIAL_VULNERABILITY) String potentialVulnerability,
|
|
||||||
@ApiParam(
|
|
||||||
name = "platform",
|
|
||||||
value = "Provide the platform that the device is running on. You can assign any of the "
|
|
||||||
+ "values given below:\n"
|
|
||||||
+ "iOS\n" + "Android\n" + "Windows",
|
|
||||||
required = true)
|
|
||||||
@QueryParam(PLATFORM) String platform,
|
|
||||||
@ApiParam(
|
|
||||||
name = "ownership",
|
|
||||||
value = "Provide the ownership status of the device. You can assign any of the values "
|
|
||||||
+ "given below:\n"
|
|
||||||
+ "BYOD: Bring Your Own Device\n" + "COPE: Corporate-Owned, Personally-Enabled",
|
|
||||||
required = true)
|
|
||||||
@QueryParam(OWNERSHIP) String ownership);
|
|
||||||
|
|
||||||
@GET
|
|
||||||
@Path("feature-non-compliant-device-count-over-total")
|
|
||||||
@ApiOperation(
|
|
||||||
produces = MediaType.APPLICATION_JSON,
|
|
||||||
httpMethod = "GET",
|
|
||||||
value = "Get the number of devices that have not complied to a given policy over the total"
|
|
||||||
+ " number of devices registered with WSO2 IoT.\n",
|
|
||||||
tags = "Dashboard",
|
|
||||||
extensions = {
|
|
||||||
@Extension(properties = {
|
|
||||||
@ExtensionProperty(name = Constants.SCOPE, value = "perm:dashboard:non-compliant-count")
|
|
||||||
})
|
|
||||||
}
|
|
||||||
)
|
|
||||||
@ApiResponses(value = {
|
|
||||||
@ApiResponse(
|
|
||||||
code = 200,
|
|
||||||
message = "OK.",
|
|
||||||
response = DashboardGadgetDataWrapper.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. \n Empty body because the client has already the latest version of " +
|
|
||||||
"the requested resource."),
|
|
||||||
@ApiResponse(
|
|
||||||
code = 400,
|
|
||||||
message = "Bad Request.",
|
|
||||||
response = ErrorResponse.class),
|
|
||||||
@ApiResponse(
|
|
||||||
code = 401,
|
|
||||||
message = "Unauthorized. \n Unauthorized request."),
|
|
||||||
@ApiResponse(
|
|
||||||
code = 404,
|
|
||||||
message = "Not Found.",
|
|
||||||
response = ErrorResponse.class),
|
|
||||||
@ApiResponse(
|
|
||||||
code = 406,
|
|
||||||
message = "Not Acceptable.\n The requested media type is not supported"),
|
|
||||||
@ApiResponse(
|
|
||||||
code = 500,
|
|
||||||
message = "Internal Server Error. \n ErrorResponse in retrieving requested data.",
|
|
||||||
response = ErrorResponse.class)
|
|
||||||
})
|
|
||||||
Response getFeatureNonCompliantDeviceCountOverTotal(
|
|
||||||
@ApiParam(
|
|
||||||
name = "non-compliant-feature-code",
|
|
||||||
value = "Provide the feature code or ID of the policy. Some examples for feature codes "
|
|
||||||
+ "are: WIFI, PASSCODE_POLICY, CAMERA and ENCRYPT_STORAGE.",
|
|
||||||
required = true)
|
|
||||||
@QueryParam(NON_COMPLIANT_FEATURE_CODE) String nonCompliantFeatureCode,
|
|
||||||
@ApiParam(
|
|
||||||
name = "platform",
|
|
||||||
value = "Provide the platform that the device is running on. You can assign the values "
|
|
||||||
+ "given below:\n"
|
|
||||||
+ "iOS\n" + "Android\n" + "Windows",
|
|
||||||
required = true)
|
|
||||||
@QueryParam(PLATFORM) String platform,
|
|
||||||
@ApiParam(
|
|
||||||
name = "ownership",
|
|
||||||
value = "Provide the ownership status of the device. You can assign the values given below:\n"
|
|
||||||
+ "BYOD: Bring Your Own Device\n" + "COPE: Corporate-Owned, Personally-Enabled",
|
|
||||||
required = true)
|
|
||||||
@QueryParam(OWNERSHIP) String ownership);
|
|
||||||
|
|
||||||
@GET
|
|
||||||
@Path("devices-with-details")
|
|
||||||
@ApiOperation(
|
|
||||||
produces = MediaType.APPLICATION_JSON,
|
|
||||||
httpMethod = "GET",
|
|
||||||
value = "Get device details of devices based on a particular device type.",
|
|
||||||
tags = "Dashboard",
|
|
||||||
extensions = {
|
|
||||||
@Extension(properties = {
|
|
||||||
@ExtensionProperty(name = Constants.SCOPE, value = "perm:dashboard:details")
|
|
||||||
})
|
|
||||||
}
|
|
||||||
)
|
|
||||||
@ApiResponses(value = {
|
|
||||||
@ApiResponse(
|
|
||||||
code = 200,
|
|
||||||
message = "OK.",
|
|
||||||
response = DashboardPaginationGadgetDataWrapper.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. \n Empty body because the client has already the latest version of " +
|
|
||||||
"the requested resource."),
|
|
||||||
@ApiResponse(
|
|
||||||
code = 400,
|
|
||||||
message = "Bad Request.",
|
|
||||||
response = ErrorResponse.class),
|
|
||||||
@ApiResponse(
|
|
||||||
code = 401,
|
|
||||||
message = "Unauthorized. \n Unauthorized request."),
|
|
||||||
@ApiResponse(
|
|
||||||
code = 404,
|
|
||||||
message = "Not Found.",
|
|
||||||
response = ErrorResponse.class),
|
|
||||||
@ApiResponse(
|
|
||||||
code = 406,
|
|
||||||
message = "Not Acceptable.\n The requested media type is not supported"),
|
|
||||||
@ApiResponse(
|
|
||||||
code = 500,
|
|
||||||
message = "Internal Server Error. \n ErrorResponse in retrieving requested data.",
|
|
||||||
response = ErrorResponse.class)
|
|
||||||
})
|
|
||||||
Response getDevicesWithDetails(
|
|
||||||
@ApiParam(
|
|
||||||
name = "connectivity-status",
|
|
||||||
value = "Provide the connectivity status of the device. This can be one of the following:\n"
|
|
||||||
+ "Total: All the devices that have registered with WSO2 IoT.\n"
|
|
||||||
+ "active: The devices that are registered with WSO2 IoT and are actively "
|
|
||||||
+ "communicating with the server.\n"
|
|
||||||
+ "inactive: The devices that are registered with WSO2 IoT but unable to actively"
|
|
||||||
+ " communicate with the server.\n"
|
|
||||||
+ "removed: The devices that have unregistered from WSO2 IoT.",
|
|
||||||
required = true)
|
|
||||||
@QueryParam(CONNECTIVITY_STATUS) String connectivityStatus,
|
|
||||||
@ApiParam(
|
|
||||||
name = "potential-vulnerability",
|
|
||||||
value = "Provide details of the potential vulnerabilities of the device. This can be:\n"
|
|
||||||
+ "non-compliant: Devices that have not complied to the policies enforced on "
|
|
||||||
+ "the device by WSO2 IoT.\n"
|
|
||||||
+ "unmonitored: Devices that have no policy assigned to them. ",
|
|
||||||
required = true)
|
|
||||||
@QueryParam(POTENTIAL_VULNERABILITY) String potentialVulnerability,
|
|
||||||
@ApiParam(
|
|
||||||
name = "platform",
|
|
||||||
value = "Provide the platform that the device is running on. This can be one of the following:\n"
|
|
||||||
+ "iOS\n" + "Android\n" + "Windows",
|
|
||||||
required = true)
|
|
||||||
@QueryParam(PLATFORM) String platform,
|
|
||||||
@ApiParam(
|
|
||||||
name = "ownership",
|
|
||||||
value = "Provide the ownership status of the device. This can be one of the following:\n"
|
|
||||||
+ "BYOD: Bring Your Own Device\n" + "COPE: Corporate-Owned, Personally-Enabled",
|
|
||||||
required = true)
|
|
||||||
@QueryParam(OWNERSHIP) String ownership,
|
|
||||||
@ApiParam(
|
|
||||||
name = "pagination-enabled",
|
|
||||||
value = "To enable/disable pagination set the value as true or false",
|
|
||||||
required = true)
|
|
||||||
@QueryParam(PAGINATION_ENABLED) String paginationEnabled,
|
|
||||||
@ApiParam(
|
|
||||||
name = "start",
|
|
||||||
value = "Provide the starting pagination index.",
|
|
||||||
required = true)
|
|
||||||
@QueryParam(START_INDEX) int startIndex,
|
|
||||||
@ApiParam(
|
|
||||||
name = "length",
|
|
||||||
value = "Provide how many policy details you require from the starting pagination index.",
|
|
||||||
required = true)
|
|
||||||
@QueryParam(RESULT_COUNT) int resultCount);
|
|
||||||
|
|
||||||
@GET
|
|
||||||
@Path("feature-non-compliant-devices-with-details")
|
|
||||||
@ApiOperation(
|
|
||||||
produces = MediaType.APPLICATION_JSON,
|
|
||||||
httpMethod = "GET",
|
|
||||||
value = "Get device details of non-compliant devices which do not comply to a given policy.",
|
|
||||||
tags = "Dashboard",
|
|
||||||
extensions = {
|
|
||||||
@Extension(properties = {
|
|
||||||
@ExtensionProperty(name = Constants.SCOPE, value = "perm:dashboard:feature-non-compliant")
|
|
||||||
})
|
|
||||||
}
|
|
||||||
)
|
|
||||||
@ApiResponses(value = {
|
|
||||||
@ApiResponse(
|
|
||||||
code = 200,
|
|
||||||
message = "OK.",
|
|
||||||
response = DashboardPaginationGadgetDataWrapper.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. \n Empty body because the client has already the latest version of " +
|
|
||||||
"the requested resource."),
|
|
||||||
@ApiResponse(
|
|
||||||
code = 400,
|
|
||||||
message = "Bad Request.",
|
|
||||||
response = ErrorResponse.class),
|
|
||||||
@ApiResponse(
|
|
||||||
code = 401,
|
|
||||||
message = "Unauthorized. \n Unauthorized request."),
|
|
||||||
@ApiResponse(
|
|
||||||
code = 404,
|
|
||||||
message = "Not Found.",
|
|
||||||
response = ErrorResponse.class),
|
|
||||||
@ApiResponse(
|
|
||||||
code = 406,
|
|
||||||
message = "Not Acceptable.\n The requested media type is not supported"),
|
|
||||||
@ApiResponse(
|
|
||||||
code = 500,
|
|
||||||
message = "Internal Server Error. \n ErrorResponse in retrieving requested data.",
|
|
||||||
response = ErrorResponse.class)
|
|
||||||
})
|
|
||||||
Response getFeatureNonCompliantDevicesWithDetails(
|
|
||||||
@ApiParam(
|
|
||||||
name = "non-compliant-feature-code",
|
|
||||||
value = "Provide the code specific to the feature "
|
|
||||||
+ "(examples for feature codes are: WIFI,PASSCODE_POLICY, CAMERA and ENCRYPT_STORAGE.)",
|
|
||||||
required = true)
|
|
||||||
@QueryParam(NON_COMPLIANT_FEATURE_CODE) String nonCompliantFeatureCode,
|
|
||||||
@ApiParam(
|
|
||||||
name = "platform",
|
|
||||||
value = "Provide the platform that the device is running on. This can be one of the following:\n"
|
|
||||||
+ "iOS\n" + "Android\n" + "Windows",
|
|
||||||
required = true)
|
|
||||||
@QueryParam(PLATFORM) String platform,
|
|
||||||
@ApiParam(
|
|
||||||
name = "ownership",
|
|
||||||
value = "Provide the ownership status of the device. This can be one of the following:\n"
|
|
||||||
+ "BYOD: Bring Your Own Device\n" + "COPE: Corporate-Owned, Personally-Enabled",
|
|
||||||
required = true)
|
|
||||||
@QueryParam(OWNERSHIP) String ownership,
|
|
||||||
@ApiParam(
|
|
||||||
name = "pagination-enabled",
|
|
||||||
value = "To enable/disable pagination set the value as true or false",
|
|
||||||
required = true)
|
|
||||||
@QueryParam(PAGINATION_ENABLED) String paginationEnabled,
|
|
||||||
@ApiParam(
|
|
||||||
name = "start",
|
|
||||||
value = "Provide the starting pagination index.",
|
|
||||||
required = true)
|
|
||||||
@QueryParam(START_INDEX) int startIndex,
|
|
||||||
@ApiParam(
|
|
||||||
name = "length",
|
|
||||||
value = "Provide how many policy details you require from the starting pagination index.",
|
|
||||||
required = true)
|
|
||||||
@QueryParam(RESULT_COUNT) int resultCount);
|
|
||||||
}
|
|
@ -1,706 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
|
||||||
*
|
|
||||||
* WSO2 Inc. 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.httpclient.HttpStatus;
|
|
||||||
import org.apache.commons.logging.Log;
|
|
||||||
import org.apache.commons.logging.LogFactory;
|
|
||||||
import org.wso2.carbon.device.mgt.analytics.dashboard.GadgetDataService;
|
|
||||||
import org.wso2.carbon.device.mgt.analytics.dashboard.bean.BasicFilterSet;
|
|
||||||
import org.wso2.carbon.device.mgt.analytics.dashboard.bean.DeviceCountByGroup;
|
|
||||||
import org.wso2.carbon.device.mgt.analytics.dashboard.bean.DeviceWithDetails;
|
|
||||||
import org.wso2.carbon.device.mgt.analytics.dashboard.bean.ExtendedFilterSet;
|
|
||||||
import org.wso2.carbon.device.mgt.analytics.dashboard.exception.*;
|
|
||||||
import org.wso2.carbon.device.mgt.common.PaginationResult;
|
|
||||||
import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils;
|
|
||||||
import org.wso2.carbon.device.mgt.jaxrs.beans.DashboardGadgetDataWrapper;
|
|
||||||
import org.wso2.carbon.device.mgt.jaxrs.beans.DashboardPaginationGadgetDataWrapper;
|
|
||||||
import org.wso2.carbon.device.mgt.jaxrs.service.api.Dashboard;
|
|
||||||
|
|
||||||
import javax.ws.rs.*;
|
|
||||||
import javax.ws.rs.core.Response;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import static org.wso2.carbon.device.mgt.analytics.dashboard.util.APIUtil.getAuthenticatedUser;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This class consists of dashboard related REST APIs
|
|
||||||
* to be consumed by individual client gadgets such as
|
|
||||||
* [1] Overview of Devices,
|
|
||||||
* [2] Potential Vulnerabilities,
|
|
||||||
* [3] Non-compliant Devices by Features,
|
|
||||||
* [4] Device Groupings and etc.
|
|
||||||
*/
|
|
||||||
|
|
||||||
@Consumes({"application/json"})
|
|
||||||
@Produces({"application/json"})
|
|
||||||
|
|
||||||
@SuppressWarnings("NonJaxWsWebServices")
|
|
||||||
public class DashboardImpl implements Dashboard {
|
|
||||||
|
|
||||||
private static Log log = LogFactory.getLog(DashboardImpl.class);
|
|
||||||
|
|
||||||
private static final String FLAG_TRUE = "true";
|
|
||||||
private static final String FLAG_FALSE = "false";
|
|
||||||
// Constants related to common error-response messages
|
|
||||||
private static final String INVALID_QUERY_PARAM_VALUE_POTENTIAL_VULNERABILITY = "Received an invalid value for " +
|
|
||||||
"query parameter : " + POTENTIAL_VULNERABILITY + ", Should be either NON_COMPLIANT or UNMONITORED.";
|
|
||||||
private static final String INVALID_QUERY_PARAM_VALUE_START_INDEX = "Received an invalid value for " +
|
|
||||||
"query parameter : " + START_INDEX + ", Should not be lesser than 0.";
|
|
||||||
private static final String INVALID_QUERY_PARAM_VALUE_RESULT_COUNT = "Received an invalid value for " +
|
|
||||||
"query parameter : " + RESULT_COUNT + ", Should not be lesser than 5.";
|
|
||||||
private static final String INVALID_QUERY_PARAM_VALUE_PAGINATION_ENABLED = "Received an invalid value for " +
|
|
||||||
"query parameter : " + PAGINATION_ENABLED + ", Should be either true or false.";
|
|
||||||
private static final String REQUIRED_QUERY_PARAM_VALUE_NON_COMPLIANT_FEATURE_CODE = "Missing required query " +
|
|
||||||
"parameter : " + NON_COMPLIANT_FEATURE_CODE;
|
|
||||||
private static final String REQUIRED_QUERY_PARAM_VALUE_PAGINATION_ENABLED = "Missing required query " +
|
|
||||||
"parameter : " + PAGINATION_ENABLED;
|
|
||||||
private static final String ERROR_IN_RETRIEVING_REQUESTED_DATA = "ErrorResponse in retrieving requested data.";
|
|
||||||
|
|
||||||
@GET
|
|
||||||
@Path("device-count-overview")
|
|
||||||
public Response getOverviewDeviceCounts() {
|
|
||||||
GadgetDataService gadgetDataService = DeviceMgtAPIUtils.getGadgetDataService();
|
|
||||||
|
|
||||||
DashboardGadgetDataWrapper dashboardGadgetDataWrapper1 = new DashboardGadgetDataWrapper();
|
|
||||||
|
|
||||||
// getting total device count
|
|
||||||
DeviceCountByGroup totalDeviceCount;
|
|
||||||
try {
|
|
||||||
String userName = getAuthenticatedUser();
|
|
||||||
totalDeviceCount = gadgetDataService.getTotalDeviceCount(userName);
|
|
||||||
} catch (DataAccessLayerException e) {
|
|
||||||
log.error("An internal error occurred while trying to execute relevant data service function " +
|
|
||||||
"@ Dashboard API layer to retrieve total device count.", e);
|
|
||||||
return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR).
|
|
||||||
entity(ERROR_IN_RETRIEVING_REQUESTED_DATA).build();
|
|
||||||
}
|
|
||||||
|
|
||||||
List<DeviceCountByGroup> totalDeviceCountInListEntry = new ArrayList<>();
|
|
||||||
totalDeviceCountInListEntry.add(totalDeviceCount);
|
|
||||||
|
|
||||||
dashboardGadgetDataWrapper1.setContext("Total-device-count");
|
|
||||||
dashboardGadgetDataWrapper1.setGroupingAttribute(null);
|
|
||||||
dashboardGadgetDataWrapper1.setData(totalDeviceCountInListEntry);
|
|
||||||
|
|
||||||
// getting device counts by connectivity statuses
|
|
||||||
List<DeviceCountByGroup> deviceCountsByConnectivityStatuses;
|
|
||||||
try {
|
|
||||||
String userName = getAuthenticatedUser();
|
|
||||||
deviceCountsByConnectivityStatuses = gadgetDataService.getDeviceCountsByConnectivityStatuses(userName);
|
|
||||||
} catch (DataAccessLayerException e) {
|
|
||||||
log.error("An internal error occurred while trying to execute relevant data service function " +
|
|
||||||
"@ Dashboard API layer to retrieve device counts by connectivity statuses.", e);
|
|
||||||
return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR).
|
|
||||||
entity(ERROR_IN_RETRIEVING_REQUESTED_DATA).build();
|
|
||||||
}
|
|
||||||
|
|
||||||
DashboardGadgetDataWrapper dashboardGadgetDataWrapper2 = new DashboardGadgetDataWrapper();
|
|
||||||
|
|
||||||
dashboardGadgetDataWrapper2.setContext("Device-counts-by-connectivity-statuses");
|
|
||||||
dashboardGadgetDataWrapper2.setGroupingAttribute(CONNECTIVITY_STATUS);
|
|
||||||
dashboardGadgetDataWrapper2.setData(deviceCountsByConnectivityStatuses);
|
|
||||||
|
|
||||||
List<DashboardGadgetDataWrapper> responsePayload = new ArrayList<>();
|
|
||||||
responsePayload.add(dashboardGadgetDataWrapper1);
|
|
||||||
responsePayload.add(dashboardGadgetDataWrapper2);
|
|
||||||
|
|
||||||
return Response.status(HttpStatus.SC_OK).entity(responsePayload).build();
|
|
||||||
}
|
|
||||||
|
|
||||||
@GET
|
|
||||||
@Path("device-counts-by-potential-vulnerabilities")
|
|
||||||
public Response getDeviceCountsByPotentialVulnerabilities() {
|
|
||||||
GadgetDataService gadgetDataService = DeviceMgtAPIUtils.getGadgetDataService();
|
|
||||||
|
|
||||||
List<DeviceCountByGroup> deviceCountsByPotentialVulnerabilities;
|
|
||||||
try {
|
|
||||||
String userName = getAuthenticatedUser();
|
|
||||||
deviceCountsByPotentialVulnerabilities = gadgetDataService.getDeviceCountsByPotentialVulnerabilities(userName);
|
|
||||||
} catch (DataAccessLayerException e) {
|
|
||||||
log.error("An internal error occurred while trying to execute relevant data service function " +
|
|
||||||
"@ Dashboard API layer to retrieve device counts by potential vulnerabilities.", e);
|
|
||||||
return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR).
|
|
||||||
entity(ERROR_IN_RETRIEVING_REQUESTED_DATA).build();
|
|
||||||
}
|
|
||||||
|
|
||||||
DashboardGadgetDataWrapper dashboardGadgetDataWrapper = new DashboardGadgetDataWrapper();
|
|
||||||
dashboardGadgetDataWrapper.setContext("Device-counts-by-potential-vulnerabilities");
|
|
||||||
dashboardGadgetDataWrapper.setGroupingAttribute(POTENTIAL_VULNERABILITY);
|
|
||||||
dashboardGadgetDataWrapper.setData(deviceCountsByPotentialVulnerabilities);
|
|
||||||
|
|
||||||
List<DashboardGadgetDataWrapper> responsePayload = new ArrayList<>();
|
|
||||||
responsePayload.add(dashboardGadgetDataWrapper);
|
|
||||||
|
|
||||||
return Response.status(HttpStatus.SC_OK).entity(responsePayload).build();
|
|
||||||
}
|
|
||||||
|
|
||||||
@GET
|
|
||||||
@Path("non-compliant-device-counts-by-features")
|
|
||||||
public Response getNonCompliantDeviceCountsByFeatures(@QueryParam(START_INDEX) int startIndex,
|
|
||||||
@QueryParam(RESULT_COUNT) int resultCount) {
|
|
||||||
|
|
||||||
GadgetDataService gadgetDataService = DeviceMgtAPIUtils.getGadgetDataService();
|
|
||||||
DashboardPaginationGadgetDataWrapper
|
|
||||||
dashboardPaginationGadgetDataWrapper = new DashboardPaginationGadgetDataWrapper();
|
|
||||||
|
|
||||||
PaginationResult paginationResult;
|
|
||||||
try {
|
|
||||||
String userName = getAuthenticatedUser();
|
|
||||||
paginationResult = gadgetDataService.
|
|
||||||
getNonCompliantDeviceCountsByFeatures(startIndex, resultCount, userName);
|
|
||||||
} catch (InvalidStartIndexValueException e) {
|
|
||||||
log.error("Bad request and error occurred @ Gadget Data Service layer due to " +
|
|
||||||
"invalid (query) parameter value. This was while trying to execute relevant data service " +
|
|
||||||
"function @ Dashboard API layer to retrieve a non-compliant set " +
|
|
||||||
"of device counts by features.", e);
|
|
||||||
return Response.status(HttpStatus.SC_BAD_REQUEST).entity(INVALID_QUERY_PARAM_VALUE_START_INDEX).build();
|
|
||||||
} catch (InvalidResultCountValueException e) {
|
|
||||||
log.error("Bad request and error occurred @ Gadget Data Service layer due to " +
|
|
||||||
"invalid (query) parameter value. This was while trying to execute relevant data service " +
|
|
||||||
"function @ Dashboard API layer to retrieve a non-compliant set " +
|
|
||||||
"of device counts by features.", e);
|
|
||||||
return Response.status(HttpStatus.SC_BAD_REQUEST).entity(INVALID_QUERY_PARAM_VALUE_RESULT_COUNT).build();
|
|
||||||
} catch (DataAccessLayerException e) {
|
|
||||||
log.error("An internal error occurred while trying to execute relevant data service function " +
|
|
||||||
"@ Dashboard API layer to retrieve a non-compliant set of device counts by features.", e);
|
|
||||||
return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR).
|
|
||||||
entity(ERROR_IN_RETRIEVING_REQUESTED_DATA).build();
|
|
||||||
}
|
|
||||||
|
|
||||||
dashboardPaginationGadgetDataWrapper.setContext("Non-compliant-device-counts-by-features");
|
|
||||||
dashboardPaginationGadgetDataWrapper.setGroupingAttribute(NON_COMPLIANT_FEATURE_CODE);
|
|
||||||
dashboardPaginationGadgetDataWrapper.setData(paginationResult.getData());
|
|
||||||
dashboardPaginationGadgetDataWrapper.setTotalRecordCount(paginationResult.getRecordsTotal());
|
|
||||||
|
|
||||||
List<DashboardPaginationGadgetDataWrapper> responsePayload = new ArrayList<>();
|
|
||||||
responsePayload.add(dashboardPaginationGadgetDataWrapper);
|
|
||||||
|
|
||||||
return Response.status(HttpStatus.SC_OK).entity(responsePayload).build();
|
|
||||||
}
|
|
||||||
|
|
||||||
@GET
|
|
||||||
@Path("device-counts-by-groups")
|
|
||||||
public Response getDeviceCountsByGroups(@QueryParam(CONNECTIVITY_STATUS) String connectivityStatus,
|
|
||||||
@QueryParam(POTENTIAL_VULNERABILITY) String potentialVulnerability,
|
|
||||||
@QueryParam(PLATFORM) String platform,
|
|
||||||
@QueryParam(OWNERSHIP) String ownership) {
|
|
||||||
|
|
||||||
// getting gadget data service
|
|
||||||
GadgetDataService gadgetDataService = DeviceMgtAPIUtils.getGadgetDataService();
|
|
||||||
|
|
||||||
// constructing filter set
|
|
||||||
ExtendedFilterSet filterSet = new ExtendedFilterSet();
|
|
||||||
filterSet.setConnectivityStatus(connectivityStatus);
|
|
||||||
filterSet.setPotentialVulnerability(potentialVulnerability);
|
|
||||||
filterSet.setPlatform(platform);
|
|
||||||
filterSet.setOwnership(ownership);
|
|
||||||
|
|
||||||
// creating device-Counts-by-platforms Data Wrapper
|
|
||||||
List<DeviceCountByGroup> deviceCountsByPlatforms;
|
|
||||||
try {
|
|
||||||
String userName = getAuthenticatedUser();
|
|
||||||
deviceCountsByPlatforms = gadgetDataService.getDeviceCountsByPlatforms(filterSet, userName);
|
|
||||||
} catch (InvalidPotentialVulnerabilityValueException e) {
|
|
||||||
log.error("Bad request and error occurred @ Gadget Data Service layer due to " +
|
|
||||||
"invalid (query) parameter value. This was while trying to execute relevant data service " +
|
|
||||||
"function @ Dashboard API layer to retrieve a filtered set of device counts by platforms.", e);
|
|
||||||
return Response.status(HttpStatus.SC_BAD_REQUEST).
|
|
||||||
entity(INVALID_QUERY_PARAM_VALUE_POTENTIAL_VULNERABILITY).build();
|
|
||||||
} catch (DataAccessLayerException e) {
|
|
||||||
log.error("An internal error occurred while trying to execute relevant data service function " +
|
|
||||||
"@ Dashboard API layer to retrieve a filtered set of device counts by platforms.", e);
|
|
||||||
return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR).
|
|
||||||
entity(ERROR_IN_RETRIEVING_REQUESTED_DATA).build();
|
|
||||||
}
|
|
||||||
|
|
||||||
DashboardGadgetDataWrapper dashboardGadgetDataWrapper1 = new DashboardGadgetDataWrapper();
|
|
||||||
dashboardGadgetDataWrapper1.setContext("Device-counts-by-platforms");
|
|
||||||
dashboardGadgetDataWrapper1.setGroupingAttribute(PLATFORM);
|
|
||||||
dashboardGadgetDataWrapper1.setData(deviceCountsByPlatforms);
|
|
||||||
|
|
||||||
// creating device-Counts-by-ownership-types Data Wrapper
|
|
||||||
List<DeviceCountByGroup> deviceCountsByOwnerships;
|
|
||||||
try {
|
|
||||||
String userName = getAuthenticatedUser();
|
|
||||||
deviceCountsByOwnerships = gadgetDataService.getDeviceCountsByOwnershipTypes(filterSet, userName);
|
|
||||||
} catch (InvalidPotentialVulnerabilityValueException e) {
|
|
||||||
log.error("Bad request and error occurred @ Gadget Data Service layer due to " +
|
|
||||||
"invalid (query) parameter value. This was while trying to execute relevant data service " +
|
|
||||||
"function @ Dashboard API layer to retrieve a filtered set of device counts by ownerships.", e);
|
|
||||||
return Response.status(HttpStatus.SC_BAD_REQUEST).
|
|
||||||
entity(INVALID_QUERY_PARAM_VALUE_POTENTIAL_VULNERABILITY).build();
|
|
||||||
} catch (DataAccessLayerException e) {
|
|
||||||
log.error("An internal error occurred while trying to execute relevant data service function " +
|
|
||||||
"@ Dashboard API layer to retrieve a filtered set of device counts by ownerships.", e);
|
|
||||||
return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR).
|
|
||||||
entity(ERROR_IN_RETRIEVING_REQUESTED_DATA).build();
|
|
||||||
}
|
|
||||||
|
|
||||||
DashboardGadgetDataWrapper dashboardGadgetDataWrapper2 = new DashboardGadgetDataWrapper();
|
|
||||||
dashboardGadgetDataWrapper2.setContext("Device-counts-by-ownerships");
|
|
||||||
dashboardGadgetDataWrapper2.setGroupingAttribute(OWNERSHIP);
|
|
||||||
dashboardGadgetDataWrapper2.setData(deviceCountsByOwnerships);
|
|
||||||
|
|
||||||
List<DashboardGadgetDataWrapper> responsePayload = new ArrayList<>();
|
|
||||||
responsePayload.add(dashboardGadgetDataWrapper1);
|
|
||||||
responsePayload.add(dashboardGadgetDataWrapper2);
|
|
||||||
|
|
||||||
return Response.status(HttpStatus.SC_OK).entity(responsePayload).build();
|
|
||||||
}
|
|
||||||
|
|
||||||
@GET
|
|
||||||
@Path("feature-non-compliant-device-counts-by-groups")
|
|
||||||
public Response getFeatureNonCompliantDeviceCountsByGroups(@QueryParam(NON_COMPLIANT_FEATURE_CODE) String nonCompliantFeatureCode,
|
|
||||||
@QueryParam(PLATFORM) String platform,
|
|
||||||
@QueryParam(OWNERSHIP) String ownership) {
|
|
||||||
// getting gadget data service
|
|
||||||
GadgetDataService gadgetDataService = DeviceMgtAPIUtils.getGadgetDataService();
|
|
||||||
|
|
||||||
// constructing filter set
|
|
||||||
BasicFilterSet filterSet = new BasicFilterSet();
|
|
||||||
filterSet.setPlatform(platform);
|
|
||||||
filterSet.setOwnership(ownership);
|
|
||||||
|
|
||||||
// creating feature-non-compliant-device-Counts-by-platforms Data Wrapper
|
|
||||||
List<DeviceCountByGroup> featureNonCompliantDeviceCountsByPlatforms;
|
|
||||||
try {
|
|
||||||
String userName = getAuthenticatedUser();
|
|
||||||
featureNonCompliantDeviceCountsByPlatforms = gadgetDataService.
|
|
||||||
getFeatureNonCompliantDeviceCountsByPlatforms(nonCompliantFeatureCode, filterSet, userName);
|
|
||||||
} catch (InvalidFeatureCodeValueException e) {
|
|
||||||
log.error("Bad request and error occurred @ Gadget Data Service layer due to " +
|
|
||||||
"invalid (query) parameter value. This was while trying to execute relevant data service " +
|
|
||||||
"function @ Dashboard API layer to retrieve a filtered set of feature " +
|
|
||||||
"non-compliant device counts by platforms.", e);
|
|
||||||
return Response.status(HttpStatus.SC_BAD_REQUEST).
|
|
||||||
entity(REQUIRED_QUERY_PARAM_VALUE_NON_COMPLIANT_FEATURE_CODE).build();
|
|
||||||
} catch (DataAccessLayerException e) {
|
|
||||||
log.error("An internal error occurred while trying to execute relevant data service function " +
|
|
||||||
"@ Dashboard API layer to retrieve a filtered set of feature non-compliant " +
|
|
||||||
"device counts by platforms.", e);
|
|
||||||
return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR).
|
|
||||||
entity(ERROR_IN_RETRIEVING_REQUESTED_DATA).build();
|
|
||||||
}
|
|
||||||
|
|
||||||
DashboardGadgetDataWrapper dashboardGadgetDataWrapper1 = new DashboardGadgetDataWrapper();
|
|
||||||
dashboardGadgetDataWrapper1.setContext("Feature-non-compliant-device-counts-by-platforms");
|
|
||||||
dashboardGadgetDataWrapper1.setGroupingAttribute(PLATFORM);
|
|
||||||
dashboardGadgetDataWrapper1.setData(featureNonCompliantDeviceCountsByPlatforms);
|
|
||||||
|
|
||||||
// creating feature-non-compliant-device-Counts-by-ownership-types Data Wrapper
|
|
||||||
List<DeviceCountByGroup> featureNonCompliantDeviceCountsByOwnerships;
|
|
||||||
try {
|
|
||||||
String userName = getAuthenticatedUser();
|
|
||||||
featureNonCompliantDeviceCountsByOwnerships = gadgetDataService.
|
|
||||||
getFeatureNonCompliantDeviceCountsByOwnershipTypes(nonCompliantFeatureCode, filterSet, userName);
|
|
||||||
} catch (InvalidFeatureCodeValueException e) {
|
|
||||||
log.error("Bad request and error occurred @ Gadget Data Service layer due to " +
|
|
||||||
"invalid (query) parameter value. This was while trying to execute relevant data service function " +
|
|
||||||
"@ Dashboard API layer to retrieve a filtered set of feature " +
|
|
||||||
"non-compliant device counts by ownerships.", e);
|
|
||||||
return Response.status(HttpStatus.SC_BAD_REQUEST).
|
|
||||||
entity(REQUIRED_QUERY_PARAM_VALUE_NON_COMPLIANT_FEATURE_CODE).build();
|
|
||||||
} catch (DataAccessLayerException e) {
|
|
||||||
log.error("An internal error occurred while trying to execute relevant data service function " +
|
|
||||||
"@ Dashboard API layer to retrieve a filtered set of feature non-compliant " +
|
|
||||||
"device counts by ownerships.", e);
|
|
||||||
return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR).
|
|
||||||
entity(ERROR_IN_RETRIEVING_REQUESTED_DATA).build();
|
|
||||||
}
|
|
||||||
|
|
||||||
DashboardGadgetDataWrapper dashboardGadgetDataWrapper2 = new DashboardGadgetDataWrapper();
|
|
||||||
dashboardGadgetDataWrapper2.setContext("Feature-non-compliant-device-counts-by-ownerships");
|
|
||||||
dashboardGadgetDataWrapper2.setGroupingAttribute(OWNERSHIP);
|
|
||||||
dashboardGadgetDataWrapper2.setData(featureNonCompliantDeviceCountsByOwnerships);
|
|
||||||
|
|
||||||
List<DashboardGadgetDataWrapper> responsePayload = new ArrayList<>();
|
|
||||||
responsePayload.add(dashboardGadgetDataWrapper1);
|
|
||||||
responsePayload.add(dashboardGadgetDataWrapper2);
|
|
||||||
|
|
||||||
return Response.status(HttpStatus.SC_OK).entity(responsePayload).build();
|
|
||||||
}
|
|
||||||
|
|
||||||
@GET
|
|
||||||
@Path("filtered-device-count-over-total")
|
|
||||||
public Response getFilteredDeviceCountOverTotal(@QueryParam(CONNECTIVITY_STATUS) String connectivityStatus,
|
|
||||||
@QueryParam(POTENTIAL_VULNERABILITY) String potentialVulnerability,
|
|
||||||
@QueryParam(PLATFORM) String platform,
|
|
||||||
@QueryParam(OWNERSHIP) String ownership) {
|
|
||||||
|
|
||||||
// getting gadget data service
|
|
||||||
GadgetDataService gadgetDataService = DeviceMgtAPIUtils.getGadgetDataService();
|
|
||||||
|
|
||||||
// constructing filter set
|
|
||||||
ExtendedFilterSet filterSet = new ExtendedFilterSet();
|
|
||||||
filterSet.setConnectivityStatus(connectivityStatus);
|
|
||||||
filterSet.setPotentialVulnerability(potentialVulnerability);
|
|
||||||
filterSet.setPlatform(platform);
|
|
||||||
filterSet.setOwnership(ownership);
|
|
||||||
|
|
||||||
// creating filteredDeviceCount Data Wrapper
|
|
||||||
DeviceCountByGroup filteredDeviceCount;
|
|
||||||
try {
|
|
||||||
String userName = getAuthenticatedUser();
|
|
||||||
filteredDeviceCount = gadgetDataService.getDeviceCount(filterSet, userName);
|
|
||||||
} catch (InvalidPotentialVulnerabilityValueException e) {
|
|
||||||
log.error("Bad request and error occurred @ Gadget Data Service layer due to " +
|
|
||||||
"invalid (query) parameter value. This was while trying to execute relevant data service " +
|
|
||||||
"function @ Dashboard API layer to retrieve a filtered device count over the total.", e);
|
|
||||||
return Response.status(HttpStatus.SC_BAD_REQUEST).
|
|
||||||
entity(INVALID_QUERY_PARAM_VALUE_POTENTIAL_VULNERABILITY).build();
|
|
||||||
} catch (DataAccessLayerException e) {
|
|
||||||
log.error("An internal error occurred while trying to execute relevant data service function " +
|
|
||||||
"@ Dashboard API layer to retrieve a filtered device count over the total.", e);
|
|
||||||
return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR).
|
|
||||||
entity(ERROR_IN_RETRIEVING_REQUESTED_DATA).build();
|
|
||||||
}
|
|
||||||
|
|
||||||
// creating TotalDeviceCount Data Wrapper
|
|
||||||
DeviceCountByGroup totalDeviceCount;
|
|
||||||
try {
|
|
||||||
String userName = getAuthenticatedUser();
|
|
||||||
totalDeviceCount = gadgetDataService.getTotalDeviceCount(userName);
|
|
||||||
} catch (DataAccessLayerException e) {
|
|
||||||
log.error("An internal error occurred while trying to execute relevant data service function " +
|
|
||||||
"@ Dashboard API layer to retrieve the total device count over filtered.", e);
|
|
||||||
return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR).
|
|
||||||
entity(ERROR_IN_RETRIEVING_REQUESTED_DATA).build();
|
|
||||||
}
|
|
||||||
|
|
||||||
List<Object> filteredDeviceCountOverTotalDataWrapper = new ArrayList<>();
|
|
||||||
filteredDeviceCountOverTotalDataWrapper.add(filteredDeviceCount);
|
|
||||||
filteredDeviceCountOverTotalDataWrapper.add(totalDeviceCount);
|
|
||||||
|
|
||||||
DashboardGadgetDataWrapper dashboardGadgetDataWrapper = new DashboardGadgetDataWrapper();
|
|
||||||
dashboardGadgetDataWrapper.setContext("Filtered-device-count-over-total");
|
|
||||||
dashboardGadgetDataWrapper.setGroupingAttribute(null);
|
|
||||||
dashboardGadgetDataWrapper.setData(filteredDeviceCountOverTotalDataWrapper);
|
|
||||||
|
|
||||||
List<DashboardGadgetDataWrapper> responsePayload = new ArrayList<>();
|
|
||||||
responsePayload.add(dashboardGadgetDataWrapper);
|
|
||||||
|
|
||||||
return Response.status(HttpStatus.SC_OK).entity(responsePayload).build();
|
|
||||||
}
|
|
||||||
|
|
||||||
@GET
|
|
||||||
@Path("feature-non-compliant-device-count-over-total")
|
|
||||||
public Response getFeatureNonCompliantDeviceCountOverTotal(@QueryParam(NON_COMPLIANT_FEATURE_CODE) String nonCompliantFeatureCode,
|
|
||||||
@QueryParam(PLATFORM) String platform,
|
|
||||||
@QueryParam(OWNERSHIP) String ownership) {
|
|
||||||
|
|
||||||
// getting gadget data service
|
|
||||||
GadgetDataService gadgetDataService = DeviceMgtAPIUtils.getGadgetDataService();
|
|
||||||
|
|
||||||
// constructing filter set
|
|
||||||
BasicFilterSet filterSet = new BasicFilterSet();
|
|
||||||
filterSet.setPlatform(platform);
|
|
||||||
filterSet.setOwnership(ownership);
|
|
||||||
|
|
||||||
// creating featureNonCompliantDeviceCount Data Wrapper
|
|
||||||
DeviceCountByGroup featureNonCompliantDeviceCount;
|
|
||||||
try {
|
|
||||||
String userName = getAuthenticatedUser();
|
|
||||||
featureNonCompliantDeviceCount = gadgetDataService.
|
|
||||||
getFeatureNonCompliantDeviceCount(nonCompliantFeatureCode, filterSet, userName);
|
|
||||||
} catch (InvalidFeatureCodeValueException e) {
|
|
||||||
log.error("Bad request and error occurred @ Gadget Data Service layer due to " +
|
|
||||||
"invalid (query) parameter value. This was while trying to execute relevant data service function " +
|
|
||||||
"@ Dashboard API layer to retrieve a feature non-compliant device count over the total.", e);
|
|
||||||
return Response.status(HttpStatus.SC_BAD_REQUEST).
|
|
||||||
entity(REQUIRED_QUERY_PARAM_VALUE_NON_COMPLIANT_FEATURE_CODE).build();
|
|
||||||
} catch (DataAccessLayerException e) {
|
|
||||||
log.error("An internal error occurred while trying to execute relevant data service function " +
|
|
||||||
"@ Dashboard API layer to retrieve a feature non-compliant device count over the total.", e);
|
|
||||||
return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR).
|
|
||||||
entity(ERROR_IN_RETRIEVING_REQUESTED_DATA).build();
|
|
||||||
}
|
|
||||||
|
|
||||||
// creating TotalDeviceCount Data Wrapper
|
|
||||||
DeviceCountByGroup totalDeviceCount;
|
|
||||||
try {
|
|
||||||
String userName = getAuthenticatedUser();
|
|
||||||
totalDeviceCount = gadgetDataService.getTotalDeviceCount(userName);
|
|
||||||
} catch (DataAccessLayerException e) {
|
|
||||||
log.error("An internal error occurred while trying to execute relevant data service function " +
|
|
||||||
"@ Dashboard API layer to retrieve the total device count over filtered feature non-compliant.", e);
|
|
||||||
return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR).
|
|
||||||
entity(ERROR_IN_RETRIEVING_REQUESTED_DATA).build();
|
|
||||||
}
|
|
||||||
|
|
||||||
List<Object> featureNonCompliantDeviceCountOverTotalDataWrapper = new ArrayList<>();
|
|
||||||
featureNonCompliantDeviceCountOverTotalDataWrapper.add(featureNonCompliantDeviceCount);
|
|
||||||
featureNonCompliantDeviceCountOverTotalDataWrapper.add(totalDeviceCount);
|
|
||||||
|
|
||||||
DashboardGadgetDataWrapper dashboardGadgetDataWrapper = new DashboardGadgetDataWrapper();
|
|
||||||
dashboardGadgetDataWrapper.setContext("Feature-non-compliant-device-count-over-total");
|
|
||||||
dashboardGadgetDataWrapper.setGroupingAttribute(null);
|
|
||||||
dashboardGadgetDataWrapper.setData(featureNonCompliantDeviceCountOverTotalDataWrapper);
|
|
||||||
|
|
||||||
List<DashboardGadgetDataWrapper> responsePayload = new ArrayList<>();
|
|
||||||
responsePayload.add(dashboardGadgetDataWrapper);
|
|
||||||
|
|
||||||
return Response.status(HttpStatus.SC_OK).entity(responsePayload).build();
|
|
||||||
}
|
|
||||||
|
|
||||||
@GET
|
|
||||||
@Path("devices-with-details")
|
|
||||||
public Response getDevicesWithDetails(@QueryParam(CONNECTIVITY_STATUS) String connectivityStatus,
|
|
||||||
@QueryParam(POTENTIAL_VULNERABILITY) String potentialVulnerability,
|
|
||||||
@QueryParam(PLATFORM) String platform,
|
|
||||||
@QueryParam(OWNERSHIP) String ownership,
|
|
||||||
@QueryParam(PAGINATION_ENABLED) String paginationEnabled,
|
|
||||||
@QueryParam(START_INDEX) int startIndex,
|
|
||||||
@QueryParam(RESULT_COUNT) int resultCount) {
|
|
||||||
|
|
||||||
if (paginationEnabled == null) {
|
|
||||||
|
|
||||||
log.error("Bad request on retrieving a filtered set of devices with details @ " +
|
|
||||||
"Dashboard API layer. " + REQUIRED_QUERY_PARAM_VALUE_PAGINATION_ENABLED);
|
|
||||||
return Response.status(HttpStatus.SC_BAD_REQUEST).
|
|
||||||
entity(REQUIRED_QUERY_PARAM_VALUE_PAGINATION_ENABLED).build();
|
|
||||||
|
|
||||||
} else if (FLAG_TRUE.equals(paginationEnabled)) {
|
|
||||||
|
|
||||||
// getting gadget data service
|
|
||||||
GadgetDataService gadgetDataService = DeviceMgtAPIUtils.getGadgetDataService();
|
|
||||||
|
|
||||||
// constructing filter set
|
|
||||||
ExtendedFilterSet filterSet = new ExtendedFilterSet();
|
|
||||||
filterSet.setConnectivityStatus(connectivityStatus);
|
|
||||||
filterSet.setPotentialVulnerability(potentialVulnerability);
|
|
||||||
filterSet.setPlatform(platform);
|
|
||||||
filterSet.setOwnership(ownership);
|
|
||||||
|
|
||||||
PaginationResult paginationResult;
|
|
||||||
try {
|
|
||||||
String userName = getAuthenticatedUser();
|
|
||||||
paginationResult = gadgetDataService.
|
|
||||||
getDevicesWithDetails(filterSet, startIndex, resultCount, userName);
|
|
||||||
} catch (InvalidPotentialVulnerabilityValueException e) {
|
|
||||||
log.error("Bad request and error occurred @ Gadget Data Service layer due to " +
|
|
||||||
"invalid (query) parameter value. This was while trying to execute relevant data service " +
|
|
||||||
"function @ Dashboard API layer to retrieve a filtered set of devices with details.", e);
|
|
||||||
return Response.status(HttpStatus.SC_BAD_REQUEST).
|
|
||||||
entity(INVALID_QUERY_PARAM_VALUE_POTENTIAL_VULNERABILITY).build();
|
|
||||||
} catch (InvalidStartIndexValueException e) {
|
|
||||||
log.error("Bad request and error occurred @ Gadget Data Service layer due to " +
|
|
||||||
"invalid (query) parameter value. This was while trying to execute relevant data service " +
|
|
||||||
"function @ Dashboard API layer to retrieve a filtered set of devices with details.", e);
|
|
||||||
return Response.status(HttpStatus.SC_BAD_REQUEST).
|
|
||||||
entity(INVALID_QUERY_PARAM_VALUE_START_INDEX).build();
|
|
||||||
} catch (InvalidResultCountValueException e) {
|
|
||||||
log.error("Bad request and error occurred @ Gadget Data Service layer due to " +
|
|
||||||
"invalid (query) parameter value. This was while trying to execute relevant data service " +
|
|
||||||
"function @ Dashboard API layer to retrieve a filtered set of devices with details.", e);
|
|
||||||
return Response.status(HttpStatus.SC_BAD_REQUEST).
|
|
||||||
entity(INVALID_QUERY_PARAM_VALUE_RESULT_COUNT).build();
|
|
||||||
} catch (DataAccessLayerException e) {
|
|
||||||
log.error("An internal error occurred while trying to execute relevant data service function " +
|
|
||||||
"@ Dashboard API layer to retrieve a filtered set of devices with details.", e);
|
|
||||||
return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR).
|
|
||||||
entity(ERROR_IN_RETRIEVING_REQUESTED_DATA).build();
|
|
||||||
}
|
|
||||||
|
|
||||||
DashboardPaginationGadgetDataWrapper
|
|
||||||
dashboardPaginationGadgetDataWrapper = new DashboardPaginationGadgetDataWrapper();
|
|
||||||
dashboardPaginationGadgetDataWrapper.setContext("Filtered-and-paginated-devices-with-details");
|
|
||||||
dashboardPaginationGadgetDataWrapper.setGroupingAttribute(null);
|
|
||||||
dashboardPaginationGadgetDataWrapper.setData(paginationResult.getData());
|
|
||||||
dashboardPaginationGadgetDataWrapper.setTotalRecordCount(paginationResult.getRecordsTotal());
|
|
||||||
|
|
||||||
List<DashboardPaginationGadgetDataWrapper> responsePayload = new ArrayList<>();
|
|
||||||
responsePayload.add(dashboardPaginationGadgetDataWrapper);
|
|
||||||
|
|
||||||
return Response.status(HttpStatus.SC_OK).entity(responsePayload).build();
|
|
||||||
|
|
||||||
} else if (FLAG_FALSE.equals(paginationEnabled)) {
|
|
||||||
|
|
||||||
// getting gadget data service
|
|
||||||
GadgetDataService gadgetDataService = DeviceMgtAPIUtils.getGadgetDataService();
|
|
||||||
|
|
||||||
// constructing filter set
|
|
||||||
ExtendedFilterSet filterSet = new ExtendedFilterSet();
|
|
||||||
filterSet.setConnectivityStatus(connectivityStatus);
|
|
||||||
filterSet.setPotentialVulnerability(potentialVulnerability);
|
|
||||||
filterSet.setPlatform(platform);
|
|
||||||
filterSet.setOwnership(ownership);
|
|
||||||
|
|
||||||
List<DeviceWithDetails> devicesWithDetails;
|
|
||||||
try {
|
|
||||||
String userName = getAuthenticatedUser();
|
|
||||||
devicesWithDetails = gadgetDataService.getDevicesWithDetails(filterSet, userName);
|
|
||||||
} catch (InvalidPotentialVulnerabilityValueException e) {
|
|
||||||
log.error("Bad request and error occurred @ Gadget Data Service layer due to " +
|
|
||||||
"invalid (query) parameter value. This was while trying to execute relevant data service " +
|
|
||||||
"function @ Dashboard API layer to retrieve a filtered set of devices with details.", e);
|
|
||||||
return Response.status(HttpStatus.SC_BAD_REQUEST).
|
|
||||||
entity(INVALID_QUERY_PARAM_VALUE_POTENTIAL_VULNERABILITY).build();
|
|
||||||
} catch (DataAccessLayerException e) {
|
|
||||||
log.error("An internal error occurred while trying to execute relevant data service function " +
|
|
||||||
"@ Dashboard API layer to retrieve a filtered set of devices with details.", e);
|
|
||||||
return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR).
|
|
||||||
entity(ERROR_IN_RETRIEVING_REQUESTED_DATA).build();
|
|
||||||
}
|
|
||||||
|
|
||||||
DashboardGadgetDataWrapper dashboardGadgetDataWrapper = new DashboardGadgetDataWrapper();
|
|
||||||
dashboardGadgetDataWrapper.setContext("Filtered-devices-with-details");
|
|
||||||
dashboardGadgetDataWrapper.setGroupingAttribute(null);
|
|
||||||
dashboardGadgetDataWrapper.setData(devicesWithDetails);
|
|
||||||
|
|
||||||
List<DashboardGadgetDataWrapper> responsePayload = new ArrayList<>();
|
|
||||||
responsePayload.add(dashboardGadgetDataWrapper);
|
|
||||||
|
|
||||||
return Response.status(HttpStatus.SC_OK).entity(responsePayload).build();
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
log.error("Bad request on retrieving a filtered set of devices with details @ " +
|
|
||||||
"Dashboard API layer. " + INVALID_QUERY_PARAM_VALUE_PAGINATION_ENABLED);
|
|
||||||
return Response.status(HttpStatus.SC_BAD_REQUEST).
|
|
||||||
entity(INVALID_QUERY_PARAM_VALUE_PAGINATION_ENABLED).build();
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@GET
|
|
||||||
@Path("feature-non-compliant-devices-with-details")
|
|
||||||
public Response getFeatureNonCompliantDevicesWithDetails(@QueryParam(NON_COMPLIANT_FEATURE_CODE) String nonCompliantFeatureCode,
|
|
||||||
@QueryParam(PLATFORM) String platform,
|
|
||||||
@QueryParam(OWNERSHIP) String ownership,
|
|
||||||
@QueryParam(PAGINATION_ENABLED) String paginationEnabled,
|
|
||||||
@QueryParam(START_INDEX) int startIndex,
|
|
||||||
@QueryParam(RESULT_COUNT) int resultCount) {
|
|
||||||
if (paginationEnabled == null) {
|
|
||||||
|
|
||||||
log.error("Bad request on retrieving a filtered set of feature non-compliant devices with " +
|
|
||||||
"details @ Dashboard API layer. " + REQUIRED_QUERY_PARAM_VALUE_PAGINATION_ENABLED);
|
|
||||||
return Response.status(HttpStatus.SC_BAD_REQUEST).
|
|
||||||
entity(REQUIRED_QUERY_PARAM_VALUE_PAGINATION_ENABLED).build();
|
|
||||||
|
|
||||||
} else if (FLAG_TRUE.equals(paginationEnabled)) {
|
|
||||||
|
|
||||||
// getting gadget data service
|
|
||||||
GadgetDataService gadgetDataService = DeviceMgtAPIUtils.getGadgetDataService();
|
|
||||||
|
|
||||||
// constructing filter set
|
|
||||||
BasicFilterSet filterSet = new BasicFilterSet();
|
|
||||||
filterSet.setPlatform(platform);
|
|
||||||
filterSet.setOwnership(ownership);
|
|
||||||
|
|
||||||
PaginationResult paginationResult;
|
|
||||||
try {
|
|
||||||
String userName = getAuthenticatedUser();
|
|
||||||
paginationResult = gadgetDataService.
|
|
||||||
getFeatureNonCompliantDevicesWithDetails(nonCompliantFeatureCode,
|
|
||||||
filterSet, startIndex, resultCount, userName);
|
|
||||||
} catch (InvalidFeatureCodeValueException e) {
|
|
||||||
log.error("Bad request and error occurred @ Gadget Data Service layer due to " +
|
|
||||||
"invalid (query) parameter value. This was while trying to execute relevant data service " +
|
|
||||||
"function @ Dashboard API layer to retrieve a filtered set of " +
|
|
||||||
"feature non-compliant devices with details.", e);
|
|
||||||
return Response.status(HttpStatus.SC_BAD_REQUEST).
|
|
||||||
entity(REQUIRED_QUERY_PARAM_VALUE_NON_COMPLIANT_FEATURE_CODE).build();
|
|
||||||
} catch (InvalidStartIndexValueException e) {
|
|
||||||
log.error("Bad request and error occurred @ Gadget Data Service layer due to " +
|
|
||||||
"invalid (query) parameter value. This was while trying to execute relevant data service " +
|
|
||||||
"function @ Dashboard API layer to retrieve a filtered set of " +
|
|
||||||
"feature non-compliant devices with details.", e);
|
|
||||||
return Response.status(HttpStatus.SC_BAD_REQUEST).
|
|
||||||
entity(INVALID_QUERY_PARAM_VALUE_START_INDEX).build();
|
|
||||||
} catch (InvalidResultCountValueException e) {
|
|
||||||
log.error("Bad request and error occurred @ Gadget Data Service layer due to " +
|
|
||||||
"invalid (query) parameter value. This was while trying to execute relevant data service " +
|
|
||||||
"function @ Dashboard API layer to retrieve a filtered set of " +
|
|
||||||
"feature non-compliant devices with details.", e);
|
|
||||||
return Response.status(HttpStatus.SC_BAD_REQUEST).
|
|
||||||
entity(INVALID_QUERY_PARAM_VALUE_RESULT_COUNT).build();
|
|
||||||
} catch (DataAccessLayerException e) {
|
|
||||||
log.error("An internal error occurred while trying to execute relevant data service function " +
|
|
||||||
"@ Dashboard API layer to retrieve a filtered set of feature " +
|
|
||||||
"non-compliant devices with details.", e);
|
|
||||||
return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR).
|
|
||||||
entity(ERROR_IN_RETRIEVING_REQUESTED_DATA).build();
|
|
||||||
}
|
|
||||||
|
|
||||||
DashboardPaginationGadgetDataWrapper
|
|
||||||
dashboardPaginationGadgetDataWrapper = new DashboardPaginationGadgetDataWrapper();
|
|
||||||
dashboardPaginationGadgetDataWrapper.
|
|
||||||
setContext("Filtered-and-paginated-feature-non-compliant-devices-with-details");
|
|
||||||
dashboardPaginationGadgetDataWrapper.setGroupingAttribute(null);
|
|
||||||
dashboardPaginationGadgetDataWrapper.setData(paginationResult.getData());
|
|
||||||
dashboardPaginationGadgetDataWrapper.setTotalRecordCount(paginationResult.getRecordsTotal());
|
|
||||||
|
|
||||||
List<DashboardPaginationGadgetDataWrapper> responsePayload = new ArrayList<>();
|
|
||||||
responsePayload.add(dashboardPaginationGadgetDataWrapper);
|
|
||||||
|
|
||||||
return Response.status(HttpStatus.SC_OK).entity(responsePayload).build();
|
|
||||||
|
|
||||||
} else if (FLAG_FALSE.equals(paginationEnabled)) {
|
|
||||||
|
|
||||||
// getting gadget data service
|
|
||||||
GadgetDataService gadgetDataService = DeviceMgtAPIUtils.getGadgetDataService();
|
|
||||||
|
|
||||||
// constructing filter set
|
|
||||||
BasicFilterSet filterSet = new BasicFilterSet();
|
|
||||||
filterSet.setPlatform(platform);
|
|
||||||
filterSet.setOwnership(ownership);
|
|
||||||
|
|
||||||
List<DeviceWithDetails> featureNonCompliantDevicesWithDetails;
|
|
||||||
try {
|
|
||||||
String userName = getAuthenticatedUser();
|
|
||||||
featureNonCompliantDevicesWithDetails = gadgetDataService.
|
|
||||||
getFeatureNonCompliantDevicesWithDetails(nonCompliantFeatureCode, filterSet, userName);
|
|
||||||
} catch (InvalidFeatureCodeValueException e) {
|
|
||||||
log.error("Bad request and error occurred @ Gadget Data Service layer due to " +
|
|
||||||
"invalid (query) parameter value. This was while trying to execute relevant data service " +
|
|
||||||
"function @ Dashboard API layer to retrieve a filtered set of " +
|
|
||||||
"feature non-compliant devices with details.", e);
|
|
||||||
return Response.status(HttpStatus.SC_BAD_REQUEST).
|
|
||||||
entity(REQUIRED_QUERY_PARAM_VALUE_NON_COMPLIANT_FEATURE_CODE).build();
|
|
||||||
} catch (DataAccessLayerException e) {
|
|
||||||
log.error("An internal error occurred while trying to execute relevant data service function " +
|
|
||||||
"@ Dashboard API layer to retrieve a filtered set of feature " +
|
|
||||||
"non-compliant devices with details.", e);
|
|
||||||
return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR).
|
|
||||||
entity(ERROR_IN_RETRIEVING_REQUESTED_DATA).build();
|
|
||||||
}
|
|
||||||
|
|
||||||
DashboardGadgetDataWrapper dashboardGadgetDataWrapper = new DashboardGadgetDataWrapper();
|
|
||||||
dashboardGadgetDataWrapper.setContext("Filtered-feature-non-compliant-devices-with-details");
|
|
||||||
dashboardGadgetDataWrapper.setGroupingAttribute(null);
|
|
||||||
dashboardGadgetDataWrapper.setData(featureNonCompliantDevicesWithDetails);
|
|
||||||
|
|
||||||
List<DashboardGadgetDataWrapper> responsePayload = new ArrayList<>();
|
|
||||||
responsePayload.add(dashboardGadgetDataWrapper);
|
|
||||||
|
|
||||||
return Response.status(HttpStatus.SC_OK).entity(responsePayload).build();
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
log.error("Bad request on retrieving a filtered set of feature non-compliant devices with " +
|
|
||||||
"details @ Dashboard API layer. " + INVALID_QUERY_PARAM_VALUE_PAGINATION_ENABLED);
|
|
||||||
return Response.status(HttpStatus.SC_BAD_REQUEST).
|
|
||||||
entity(INVALID_QUERY_PARAM_VALUE_PAGINATION_ENABLED).build();
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
Loading…
Reference in new issue