diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.api/pom.xml
index 932f4894ebe..4de371b1173 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.api/pom.xml
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/pom.xml
@@ -238,6 +238,11 @@
org.wso2.carbon.devicemgt
org.wso2.carbon.apimgt.annotations
+
+ org.wso2.carbon.devicemgt
+ org.wso2.carbon.device.mgt.analytics.dashboard
+ provided
+
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Certificate.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Certificate.java
index 56ec881e924..b4efa5d9853 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Certificate.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Certificate.java
@@ -52,7 +52,6 @@ public interface Certificate {
* @return Status of the data persist operation.
*/
@POST
- @Path("saveCertificate")
@ApiOperation(
consumes = MediaType.APPLICATION_JSON + ", " + MediaType.APPLICATION_XML,
produces = MediaType.APPLICATION_JSON + ", " + MediaType.APPLICATION_XML,
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Dashboard.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Dashboard.java
new file mode 100644
index 00000000000..12a1d977963
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Dashboard.java
@@ -0,0 +1,81 @@
+package org.wso2.carbon.device.mgt.jaxrs.api;
+
+import io.swagger.annotations.Api;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.Response;
+
+@Path("/dashboard")
+@Api(value = "Dashboard", description = "Dashboard related operations are described here.")
+@SuppressWarnings("NonJaxWsWebServices")
+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")
+ Response getOverviewDeviceCounts();
+
+ @GET
+ @Path("device-counts-by-potential-vulnerabilities")
+ Response getDeviceCountsByPotentialVulnerabilities();
+
+ @GET
+ @Path("non-compliant-device-counts-by-features")
+ Response getNonCompliantDeviceCountsByFeatures(@QueryParam(START_INDEX) int startIndex,
+ @QueryParam(RESULT_COUNT) int resultCount);
+
+ @GET
+ @Path("device-counts-by-groups")
+ Response getDeviceCountsByGroups(@QueryParam(CONNECTIVITY_STATUS) String connectivityStatus,
+ @QueryParam(POTENTIAL_VULNERABILITY) String potentialVulnerability,
+ @QueryParam(PLATFORM) String platform,
+ @QueryParam(OWNERSHIP) String ownership);
+
+ @GET
+ @Path("feature-non-compliant-device-counts-by-groups")
+ Response getFeatureNonCompliantDeviceCountsByGroups(@QueryParam(NON_COMPLIANT_FEATURE_CODE) String nonCompliantFeatureCode,
+ @QueryParam(PLATFORM) String platform,
+ @QueryParam(OWNERSHIP) String ownership);
+ @GET
+ @Path("filtered-device-count-over-total")
+ Response getFilteredDeviceCountOverTotal(@QueryParam(CONNECTIVITY_STATUS) String connectivityStatus,
+ @QueryParam(POTENTIAL_VULNERABILITY) String potentialVulnerability,
+ @QueryParam(PLATFORM) String platform,
+ @QueryParam(OWNERSHIP) String ownership);
+
+ @GET
+ @Path("feature-non-compliant-device-count-over-total")
+ Response getFeatureNonCompliantDeviceCountOverTotal(@QueryParam(NON_COMPLIANT_FEATURE_CODE) String nonCompliantFeatureCode,
+ @QueryParam(PLATFORM) String platform,
+ @QueryParam(OWNERSHIP) String ownership);
+
+ @GET
+ @Path("devices-with-details")
+ 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);
+
+ @GET
+ @Path("feature-non-compliant-devices-with-details")
+ 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);
+}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/DeviceSearch.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/DeviceSearch.java
index 24a58f739cd..34790156a03 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/DeviceSearch.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/DeviceSearch.java
@@ -24,7 +24,9 @@ import org.wso2.carbon.device.mgt.common.device.details.DeviceWrapper;
import org.wso2.carbon.device.mgt.common.search.SearchContext;
import javax.ws.rs.GET;
+import javax.ws.rs.POST;
import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
@@ -50,8 +52,25 @@ public interface DeviceSearch {
@ApiResponses(value = {
@ApiResponse(code = 200, message = "OK", response = DeviceWrapper.class, responseContainer = "List"),
@ApiResponse(code = 500, message = "Error occurred while searching the device information")
- })
+ })
@Permission(scope = "device-search", permissions = {"/permission/admin/device-mgt/admin/devices/list"})
- Response getFilteredDeviceInfo(@ApiParam(name = "enrollmentCertificates", value = "List of search conditions",
- required = true) SearchContext searchContext);
+ Response getDeviceInfo(@ApiParam(name = "enrollmentCertificates", value = "List of search conditions",
+ required = true) SearchContext searchContext);
+
+ @GET
+ @Path("after/{time}")
+ @ApiOperation(
+ consumes = MediaType.APPLICATION_JSON,
+ httpMethod = "GET",
+ value = "Get devices information since a specified time.",
+ notes = "Get devices information of devices updated since a specified time.",
+ response = DeviceWrapper.class,
+ responseContainer = "List")
+ @ApiResponses(value = {
+ @ApiResponse(code = 200, message = "OK", response = DeviceWrapper.class, responseContainer = "List"),
+ @ApiResponse(code = 500, message = "Error occurred while fetching the device information")
+ })
+ @Permission(scope = "device-search", permissions = {"/permission/admin/device-mgt/admin/devices/update-since-list"})
+ Response getUpdatedDevices(@ApiParam(name = "time", value = "Time since the updated devices should be " +
+ "fetched.", required = true)@PathParam("time") String time);
}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Policy.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Policy.java
index 7067eb19f67..5ee6e3633a6 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Policy.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Policy.java
@@ -280,4 +280,9 @@ public interface Policy {
required = true) @PathParam("type") String type,
@ApiParam(name = "id", value = "Define the device ID as the value for {id}.",
required = true) @PathParam("id") String id);
+
+ //TODO: This API is still not in use, but will be needed when grouping is implemented.
+ @GET
+ @Path("/device-group/{user}")
+ public Response getDeviceGroupsRelatedToPolicies(@PathParam("user") String userName);
}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/impl/CertificateImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/impl/CertificateImpl.java
index de062241f96..a4ebb4c8316 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/impl/CertificateImpl.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/impl/CertificateImpl.java
@@ -31,6 +31,7 @@ import org.wso2.carbon.device.mgt.common.PaginationRequest;
import org.wso2.carbon.device.mgt.common.PaginationResult;
import org.wso2.carbon.device.mgt.jaxrs.api.util.DeviceMgtAPIUtils;
import org.wso2.carbon.device.mgt.jaxrs.beans.EnrollmentCertificate;
+import org.wso2.carbon.device.mgt.jaxrs.exception.BadRequestException;
import org.wso2.carbon.device.mgt.jaxrs.exception.Message;
import javax.ws.rs.Consumes;
@@ -65,7 +66,6 @@ public class CertificateImpl implements Certificate {
* @return Status of the data persist operation.
*/
@POST
- @Path("saveCertificate")
public Response saveCertificate(@HeaderParam("Accept") String acceptHeader,
EnrollmentCertificate[] enrollmentCertificates) {
MediaType responseMediaType = DeviceMgtAPIUtils.getResponseMediaType(acceptHeader);
@@ -111,14 +111,11 @@ public class CertificateImpl implements Certificate {
}
CertificateManagementService certificateService = DeviceMgtAPIUtils.getCertificateManagementService();
- CertificateResponse certificateResponse;
+ List certificateResponse;
try {
- certificateResponse = certificateService.getCertificateBySerial(serialNumber);
- if(certificateResponse != null) {
- certificateResponse.setCertificate(null); //avoid sending byte array in response.
- }
+ certificateResponse = certificateService.searchCertificates(serialNumber);
return Response.status(Response.Status.OK).entity(certificateResponse).type(responseMediaType).build();
- } catch (KeystoreException e) {
+ } catch (CertificateManagementDAOException e) {
String msg = "Error occurred while converting PEM file to X509Certificate";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).type(responseMediaType).build();
@@ -164,6 +161,28 @@ public class CertificateImpl implements Certificate {
}
}
+ /**
+ * Get all certificates
+ *
+ * @return certificate details in an array.
+ * @throws MDMAPIException
+ */
+ @GET
+ public Response getAllCertificates(@HeaderParam("Accept") String acceptHeader)
+ throws MDMAPIException {
+ MediaType responseMediaType = DeviceMgtAPIUtils.getResponseMediaType(acceptHeader);
+
+ CertificateManagementService certificateService = DeviceMgtAPIUtils.getCertificateManagementService();
+ try {
+ List certificates = certificateService.getCertificates();
+ return Response.status(Response.Status.OK).entity(certificates).type(responseMediaType).build();
+ } catch (CertificateManagementDAOException e) {
+ String msg = "Error occurred while fetching all certificates.";
+ log.error(msg, e);
+ throw new MDMAPIException(msg, e);
+ }
+ }
+
@DELETE
@Path("{serialNumber}")
public Response removeCertificate(@HeaderParam("Accept") String acceptHeader,
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/impl/DashboardImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/impl/DashboardImpl.java
new file mode 100644
index 00000000000..3995e656a0d
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/impl/DashboardImpl.java
@@ -0,0 +1,687 @@
+/*
+ * 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.api;
+
+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.api.util.DeviceMgtAPIUtils;
+import org.wso2.carbon.device.mgt.jaxrs.beans.DashboardGadgetDataWrapper;
+import org.wso2.carbon.device.mgt.jaxrs.beans.DashboardPaginationGadgetDataWrapper;
+
+import javax.ws.rs.*;
+import javax.ws.rs.core.Response;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * 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 = "Error 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 {
+ totalDeviceCount = gadgetDataService.getTotalDeviceCount();
+ } 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 totalDeviceCountInListEntry = new ArrayList<>();
+ totalDeviceCountInListEntry.add(totalDeviceCount);
+
+ dashboardGadgetDataWrapper1.setContext("Total-device-count");
+ dashboardGadgetDataWrapper1.setGroupingAttribute(null);
+ dashboardGadgetDataWrapper1.setData(totalDeviceCountInListEntry);
+
+ // getting device counts by connectivity statuses
+ List deviceCountsByConnectivityStatuses;
+ try {
+ deviceCountsByConnectivityStatuses = gadgetDataService.getDeviceCountsByConnectivityStatuses();
+ } 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 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 deviceCountsByPotentialVulnerabilities;
+ try {
+ deviceCountsByPotentialVulnerabilities = gadgetDataService.getDeviceCountsByPotentialVulnerabilities();
+ } 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 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 {
+ paginationResult = gadgetDataService.
+ getNonCompliantDeviceCountsByFeatures(startIndex, resultCount);
+ } 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 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 deviceCountsByPlatforms;
+ try {
+ deviceCountsByPlatforms = gadgetDataService.getDeviceCountsByPlatforms(filterSet);
+ } 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 deviceCountsByOwnerships;
+ try {
+ deviceCountsByOwnerships = gadgetDataService.getDeviceCountsByOwnershipTypes(filterSet);
+ } 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 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 featureNonCompliantDeviceCountsByPlatforms;
+ try {
+ featureNonCompliantDeviceCountsByPlatforms = gadgetDataService.
+ getFeatureNonCompliantDeviceCountsByPlatforms(nonCompliantFeatureCode, filterSet);
+ } 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 featureNonCompliantDeviceCountsByOwnerships;
+ try {
+ featureNonCompliantDeviceCountsByOwnerships = gadgetDataService.
+ getFeatureNonCompliantDeviceCountsByOwnershipTypes(nonCompliantFeatureCode, filterSet);
+ } 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 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 {
+ filteredDeviceCount = gadgetDataService.getDeviceCount(filterSet);
+ } 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 {
+ totalDeviceCount = gadgetDataService.getTotalDeviceCount();
+ } 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