From 8b4649b4e53261352069c52619e79da87f208028 Mon Sep 17 00:00:00 2001 From: amalhub Date: Mon, 3 Oct 2016 11:39:03 +0530 Subject: [PATCH 1/9] Fixing issue: EMM-1537 --- .../jaggeryapps/devicemgt/api/operation-api.jag | 7 ++++++- .../oauth/token-protected-service-invokers.js | 14 ++++++++------ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/api/operation-api.jag b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/api/operation-api.jag index 7465f21649..ac30769bb4 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/api/operation-api.jag +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/api/operation-api.jag @@ -51,7 +51,12 @@ if (uriMatcher.match("/{context}/api/operation/paginate")) { } else { response["status"] = restAPIResponse["status"]; if (restAPIResponse["responseText"]) { - response["content"] = parse(restAPIResponse["responseText"]); + var responseText = ""; + try { + response["content"] = parse(restAPIResponse["responseText"]); + } catch (e) { + responseText = restAPIResponse["responseText"]; + } } } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/oauth/token-protected-service-invokers.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/oauth/token-protected-service-invokers.js index 1600618775..673c3e199f 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/oauth/token-protected-service-invokers.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/oauth/token-protected-service-invokers.js @@ -45,12 +45,13 @@ var invokers = function () { * If the token pair is not set in the session, this will return null. */ privateMethods.getAccessToken = function () { - var tokenPair = session.get(constants["TOKEN_PAIR"]); - if (tokenPair) { - return parse(tokenPair)["accessToken"]; - } else { - return null; + if (session) { + var tokenPair = session.get(constants["TOKEN_PAIR"]); + if (tokenPair) { + return parse(tokenPair)["accessToken"]; + } } + return null; }; /** @@ -80,9 +81,10 @@ var invokers = function () { if (devicemgtProps["isOAuthEnabled"]) { var accessToken = privateMethods.getAccessToken(); - if (!accessToken) { + if (accessToken == null) { userModule.logout(function () { response.sendRedirect(devicemgtProps["appContext"] + "login"); + return responseCallback({"status": 401, "responseText" : "Session expired!"}); }); } else { xmlHttpRequest.setRequestHeader(constants["AUTHORIZATION_HEADER"], From c87c5a83221f27c16bed7ee4742901342455b2d0 Mon Sep 17 00:00:00 2001 From: amalhub Date: Tue, 4 Oct 2016 11:14:39 +0530 Subject: [PATCH 2/9] Fixing issue: EMM-1537 --- .../app/modules/oauth/token-protected-service-invokers.js | 1 - 1 file changed, 1 deletion(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/oauth/token-protected-service-invokers.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/oauth/token-protected-service-invokers.js index 673c3e199f..b79e7c6a07 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/oauth/token-protected-service-invokers.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/oauth/token-protected-service-invokers.js @@ -84,7 +84,6 @@ var invokers = function () { if (accessToken == null) { userModule.logout(function () { response.sendRedirect(devicemgtProps["appContext"] + "login"); - return responseCallback({"status": 401, "responseText" : "Session expired!"}); }); } else { xmlHttpRequest.setRequestHeader(constants["AUTHORIZATION_HEADER"], From f664749c1f6ca8bd1f5744d4d8d0198f25ef8dce Mon Sep 17 00:00:00 2001 From: thusithakalugamage Date: Tue, 4 Oct 2016 15:22:41 +0530 Subject: [PATCH 3/9] platform configuration style defect fixes --- .../configuration.hbs | 34 +++++++++++-------- .../public/css/custom-common.css | 4 --- .../public/css/custom-desktop.css | 22 +++++++++--- 3 files changed, 36 insertions(+), 24 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.platform.configuration/configuration.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.platform.configuration/configuration.hbs index e856208e3a..1fdef264e8 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.platform.configuration/configuration.hbs +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.platform.configuration/configuration.hbs @@ -35,16 +35,26 @@
- - - + + + + + + + + General Configurations {{#each deviceTypes}} - - - + + + + + + + + {{label}} Configurations {{/each}} @@ -79,9 +89,7 @@ placeholder="[ Required Field ]">
- +
@@ -107,12 +115,8 @@ "Exit" to complete the process and go back to the dashboard.
- + onclick="window.location.href='{{@app.context}}/platform-configuration'">Go back to configurations + diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.theme/public/css/custom-common.css b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.theme/public/css/custom-common.css index 0fede3d552..a0e5807636 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.theme/public/css/custom-common.css +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.theme/public/css/custom-common.css @@ -16,10 +16,6 @@ * under the License. */ -.wr-content { - padding-left: 33px; - padding-right: 33px; -} .wr-input-control .helper { font-weight: 100; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.theme/public/css/custom-desktop.css b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.theme/public/css/custom-desktop.css index fe75cb54f0..6d253dcc0d 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.theme/public/css/custom-desktop.css +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.theme/public/css/custom-desktop.css @@ -167,7 +167,7 @@ pre { position: absolute; right: 0; height: 10000px; - width: 60px; + width: 20px; } body.inverse .fade-edge:after { @@ -181,7 +181,7 @@ body.inverse .fade-edge:after { position: absolute; right: 0; height: 10000px; - width: 60px; + width: 20px; } .visible-block { @@ -4552,6 +4552,15 @@ a.wr-side-panel-toggle-btn.selected { background: #f4f4f4; } +.wr-advance-operations .wr-hidden-operations-nav a.selected span span > i{ + color: #526A84; +} +.wr-advance-operations .wr-hidden-operations-nav a.selected span span > i.fw.fw-circle.fw-stack-2x{ + color: #fff; +} +.wr-advance-operations .wr-hidden-operations-nav a.selected span span > i.fw.fw-circle.fw-stack-2x.fw-stroke.fw-inverse{ + color: #526A84; +} .wr-advance-operations .wr-hidden-operations-nav a.selected, .wr-hidden-operations .wr-hidden-operations-nav a.selected:hover { color: #ffffff; background: #526A84; @@ -5515,7 +5524,7 @@ ul.listing li.grouped-input ul.grouped-child-input.disabled { position: absolute; right: 0; height: 10000px; - width: 60px; + width: 20px; } body.inverse .fade-edge:after { content: ""; @@ -5528,7 +5537,7 @@ body.inverse .fade-edge:after { position: absolute; right: 0; height: 10000px; - width: 60px; + width: 20px; } /* ======================================================================== @@ -5752,7 +5761,7 @@ body.inverse .fade-edge:after { position: absolute; right: 0; height: 10000px; - width: 60px; + width: 20px; } .table.table-selectable > tbody > tr:hover { cursor: pointer; @@ -6495,3 +6504,6 @@ select > option:hover { /*background:url('http://cdn-sg1.pgimgs.com/images/pg/close-button.png') no-repeat center center;*/ } +.label-bold{ + font-weight:400; +} From 1ca5762c44a856e828f96d6ddebf4ecd0264ab16 Mon Sep 17 00:00:00 2001 From: dilanua Date: Tue, 4 Oct 2016 15:49:29 +0530 Subject: [PATCH 4/9] Uncommenting Dashboard APIs --- .../mgt/jaxrs/service/api/Dashboard.java | 136 +- .../mgt/jaxrs/service/impl/DashboardImpl.java | 1268 ++++++++--------- 2 files changed, 702 insertions(+), 702 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/Dashboard.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/Dashboard.java index c910074006..8dbf6bf3c5 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/Dashboard.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/Dashboard.java @@ -7,75 +7,75 @@ 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.") +@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); + 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/service/impl/DashboardImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DashboardImpl.java index 3bf8332bdb..ba5e00d0d8 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DashboardImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DashboardImpl.java @@ -46,643 +46,643 @@ import java.util.List; * [3] Non-compliant Devices by Features, * [4] Device Groupings and etc. */ -// -//@Consumes({"application/json"}) -//@Produces({"application/json"}) + +@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 { -// 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 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 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 { -// featureNonCompliantDeviceCount = gadgetDataService. -// getFeatureNonCompliantDeviceCount(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 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 { -// 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 feature non-compliant.", e); -// return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR). -// entity(ERROR_IN_RETRIEVING_REQUESTED_DATA).build(); -// } -// -// List 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 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 { -// paginationResult = gadgetDataService. -// getDevicesWithDetails(filterSet, startIndex, resultCount); -// } 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 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 devicesWithDetails; -// try { -// devicesWithDetails = gadgetDataService.getDevicesWithDetails(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 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 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 { -// paginationResult = gadgetDataService. -// getFeatureNonCompliantDevicesWithDetails(nonCompliantFeatureCode, -// filterSet, startIndex, resultCount); -// } 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 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 featureNonCompliantDevicesWithDetails; -// try { -// featureNonCompliantDevicesWithDetails = gadgetDataService. -// getFeatureNonCompliantDevicesWithDetails(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 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 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(); -// -// } -// } + 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 { + 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 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 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 { + featureNonCompliantDeviceCount = gadgetDataService. + getFeatureNonCompliantDeviceCount(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 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 { + 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 feature non-compliant.", e); + return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR). + entity(ERROR_IN_RETRIEVING_REQUESTED_DATA).build(); + } + + List 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 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 { + paginationResult = gadgetDataService. + getDevicesWithDetails(filterSet, startIndex, resultCount); + } 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 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 devicesWithDetails; + try { + devicesWithDetails = gadgetDataService.getDevicesWithDetails(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 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 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 { + paginationResult = gadgetDataService. + getFeatureNonCompliantDevicesWithDetails(nonCompliantFeatureCode, + filterSet, startIndex, resultCount); + } 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 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 featureNonCompliantDevicesWithDetails; + try { + featureNonCompliantDevicesWithDetails = gadgetDataService. + getFeatureNonCompliantDevicesWithDetails(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 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 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(); + + } + } } From dff32af832c72cbf7de2710a3940b412b8684654 Mon Sep 17 00:00:00 2001 From: dilanua Date: Tue, 4 Oct 2016 16:25:17 +0530 Subject: [PATCH 5/9] Adding initial swagger annotations and permissions to Dashboard APIs --- .../mgt/jaxrs/service/api/Dashboard.java | 89 +++++++++++++------ 1 file changed, 63 insertions(+), 26 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/Dashboard.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/Dashboard.java index 8dbf6bf3c5..0c4fd54ea2 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/Dashboard.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/Dashboard.java @@ -1,14 +1,42 @@ +/* + * 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.api; import io.swagger.annotations.Api; +import org.wso2.carbon.apimgt.annotations.api.API; +import org.wso2.carbon.apimgt.annotations.api.Permission; -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.QueryParam; +import javax.ws.rs.*; +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. + */ +@API(name = "Device Analytics Dashboard", + version = "1.0.0", context = "/api/device-mgt/v1.0/dashboard", tags = {"devicemgt_admin"}) + @Path("/dashboard") -@Api(value = "Dashboard", description = "Dashboard related operations are described here.") +@Api(value = "Device Analytics Dashboard", + description = "Device Analytics Dashboard related information APIs are described here.") +@Produces(MediaType.APPLICATION_JSON) @SuppressWarnings("NonJaxWsWebServices") public interface Dashboard { @@ -24,58 +52,67 @@ public interface Dashboard { @GET @Path("device-count-overview") + @Permission(name = "View Dashboard", permission = "/device-mgt/dashboard/view") Response getOverviewDeviceCounts(); @GET @Path("device-counts-by-potential-vulnerabilities") + @Permission(name = "View Dashboard", permission = "/device-mgt/dashboard/view") Response getDeviceCountsByPotentialVulnerabilities(); @GET @Path("non-compliant-device-counts-by-features") + @Permission(name = "View Dashboard", permission = "/device-mgt/dashboard/view") Response getNonCompliantDeviceCountsByFeatures(@QueryParam(START_INDEX) int startIndex, - @QueryParam(RESULT_COUNT) int resultCount); + @QueryParam(RESULT_COUNT) int resultCount); @GET @Path("device-counts-by-groups") + @Permission(name = "View Dashboard", permission = "/device-mgt/dashboard/view") Response getDeviceCountsByGroups(@QueryParam(CONNECTIVITY_STATUS) String connectivityStatus, - @QueryParam(POTENTIAL_VULNERABILITY) String potentialVulnerability, - @QueryParam(PLATFORM) String platform, - @QueryParam(OWNERSHIP) String ownership); + @QueryParam(POTENTIAL_VULNERABILITY) String potentialVulnerability, + @QueryParam(PLATFORM) String platform, + @QueryParam(OWNERSHIP) String ownership); @GET @Path("feature-non-compliant-device-counts-by-groups") + @Permission(name = "View Dashboard", permission = "/device-mgt/dashboard/view") Response getFeatureNonCompliantDeviceCountsByGroups(@QueryParam(NON_COMPLIANT_FEATURE_CODE) String nonCompliantFeatureCode, - @QueryParam(PLATFORM) String platform, - @QueryParam(OWNERSHIP) String ownership); + @QueryParam(PLATFORM) String platform, + @QueryParam(OWNERSHIP) String ownership); @GET @Path("filtered-device-count-over-total") + @Permission(name = "View Dashboard", permission = "/device-mgt/dashboard/view") Response getFilteredDeviceCountOverTotal(@QueryParam(CONNECTIVITY_STATUS) String connectivityStatus, - @QueryParam(POTENTIAL_VULNERABILITY) String potentialVulnerability, - @QueryParam(PLATFORM) String platform, - @QueryParam(OWNERSHIP) String ownership); + @QueryParam(POTENTIAL_VULNERABILITY) String potentialVulnerability, + @QueryParam(PLATFORM) String platform, + @QueryParam(OWNERSHIP) String ownership); @GET @Path("feature-non-compliant-device-count-over-total") + @Permission(name = "View Dashboard", permission = "/device-mgt/dashboard/view") Response getFeatureNonCompliantDeviceCountOverTotal(@QueryParam(NON_COMPLIANT_FEATURE_CODE) String nonCompliantFeatureCode, - @QueryParam(PLATFORM) String platform, - @QueryParam(OWNERSHIP) String ownership); + @QueryParam(PLATFORM) String platform, + @QueryParam(OWNERSHIP) String ownership); @GET @Path("devices-with-details") + @Permission(name = "View Dashboard", permission = "/device-mgt/dashboard/view") 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); + @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") + @Permission(name = "View Dashboard", permission = "/device-mgt/dashboard/view") 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); + @QueryParam(PLATFORM) String platform, + @QueryParam(OWNERSHIP) String ownership, + @QueryParam(PAGINATION_ENABLED) String paginationEnabled, + @QueryParam(START_INDEX) int startIndex, + @QueryParam(RESULT_COUNT) int resultCount); } From b7990b91462092090aabdb5be90e9a8b3bd2f6b7 Mon Sep 17 00:00:00 2001 From: Megala Date: Tue, 4 Oct 2016 17:22:45 +0530 Subject: [PATCH 6/9] Fixing problems in retriveing data from secondary user store --- .../service/api/UserManagementService.java | 25 +++++++++++++++++-- .../api/admin/UserManagementAdminService.java | 5 ++++ .../impl/UserManagementServiceImpl.java | 20 ++++++++++++--- .../admin/UserManagementAdminServiceImpl.java | 5 +++- .../app/modules/business-controllers/user.js | 16 ++++++++++++ .../cdmf.page.user.edit/public/js/bottomJs.js | 4 +-- .../cdmf.page.users/public/js/listing.js | 18 ++++++++++++- .../user-menu.hbs | 2 +- 8 files changed, 84 insertions(+), 11 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/UserManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/UserManagementService.java index 7ea6d8d5c5..c8d528dd3e 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/UserManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/UserManagementService.java @@ -135,6 +135,7 @@ public interface UserManagementService { " fetching the requested user.", response = ErrorResponse.class) }) + @Permission(name = "View Users", permission = "/device-mgt/users/view") Response getUser( @ApiParam( @@ -142,6 +143,11 @@ public interface UserManagementService { value = "Username of the user to be fetched.", required = true) @PathParam("username") String username, + @ApiParam( + name = "domain", + value = "Domain name of the user store.", + required = false) + @QueryParam("domain") String domain, @ApiParam( name = "If-Modified-Since", value = "Validates if the requested variant has not been modified since the time specified", @@ -199,6 +205,11 @@ public interface UserManagementService { value = "Username of the user to be updated.", required = true) @PathParam("username") String username, + @ApiParam( + name = "domain", + value = "Domain name of the user store.", + required = false) + @QueryParam("domain") String domain, @ApiParam( name = "userData", value = "User related details.", @@ -230,7 +241,12 @@ public interface UserManagementService { @Permission(name = "Manage Users", permission = "/device-mgt/users/manage") Response removeUser( @ApiParam(name = "username", value = "Username of the user to be deleted.", required = true) - @PathParam("username") String username); + @PathParam("username") String username, + @ApiParam( + name = "domain", + value = "Domain name of the user store.", + required = false) + @QueryParam("domain") String domain); @GET @Path("/{username}/roles") @@ -279,7 +295,12 @@ public interface UserManagementService { @Permission(name = "View Users", permission = "/device-mgt/users/view") Response getRolesOfUser( @ApiParam(name = "username", value = "Username of the user.", required = true) - @PathParam("username") String username); + @PathParam("username") String username, + @ApiParam( + name = "domain", + value = "Domain name of the user store.", + required = false) + @QueryParam("domain") String domain); @GET @ApiOperation( diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/UserManagementAdminService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/UserManagementAdminService.java index 6b18ea8367..026910d8e2 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/UserManagementAdminService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/UserManagementAdminService.java @@ -78,6 +78,11 @@ public interface UserManagementAdminService { @PathParam("username") @Size(max = 45) String username, + @ApiParam( + name = "domain", + value = "Domain name of the user store.", + required = false) + @QueryParam("domain") String domain, @ApiParam( name = "credentials", value = "Credential.", diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/UserManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/UserManagementServiceImpl.java index 43f52d812a..f6ba34a085 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/UserManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/UserManagementServiceImpl.java @@ -105,8 +105,11 @@ public class UserManagementServiceImpl implements UserManagementService { @GET @Path("/{username}") @Override - public Response getUser(@PathParam("username") String username, + public Response getUser(@PathParam("username") String username, @QueryParam("domain") String domain, @HeaderParam("If-Modified-Since") String ifModifiedSince) { + if (domain != null) { + username = domain + '/' + username; + } try { UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager(); if (!userStoreManager.isExistingUser(username)) { @@ -131,7 +134,10 @@ public class UserManagementServiceImpl implements UserManagementService { @PUT @Path("/{username}") @Override - public Response updateUser(@PathParam("username") String username, UserInfo userInfo) { + public Response updateUser(@PathParam("username") String username, @QueryParam("domain") String domain, UserInfo userInfo) { + if (domain != null) { + username = domain + '/' + username; + } try { UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager(); if (!userStoreManager.isExistingUser(username)) { @@ -205,7 +211,10 @@ public class UserManagementServiceImpl implements UserManagementService { @DELETE @Path("/{username}") @Override - public Response removeUser(@PathParam("username") String username) { + public Response removeUser(@PathParam("username") String username, @QueryParam("domain") String domain) { + if (domain != null) { + username = domain + '/' + username; + } try { UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager(); if (!userStoreManager.isExistingUser(username)) { @@ -233,7 +242,10 @@ public class UserManagementServiceImpl implements UserManagementService { @GET @Path("/{username}/roles") @Override - public Response getRolesOfUser(@PathParam("username") String username) { + public Response getRolesOfUser(@PathParam("username") String username, @QueryParam("domain") String domain) { + if (domain != null) { + username = domain + '/' + username; + } try { UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager(); if (!userStoreManager.isExistingUser(username)) { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/admin/UserManagementAdminServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/admin/UserManagementAdminServiceImpl.java index 5fad04b0d9..fbcc38178b 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/admin/UserManagementAdminServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/admin/UserManagementAdminServiceImpl.java @@ -37,7 +37,10 @@ public class UserManagementAdminServiceImpl implements UserManagementAdminServic @Override public Response resetUserPassword(@PathParam("username") @Size(max = 45) - String user, PasswordResetWrapper credentials) { + String user, @QueryParam("domain") String domain, PasswordResetWrapper credentials) { + if (domain != null) { + user = domain + '/' + user; + } return CredentialManagementResponseBuilder.buildResetPasswordResponse(user, credentials); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/user.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/user.js index 43e30b530c..299c39ebc6 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/user.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/user.js @@ -177,10 +177,18 @@ var userModule = function () { */ publicMethods.getUser = function (username) { var carbonUser = privateMethods.getCarbonUser(); + var domain; + if (username.indexOf('/') > 0) { + domain = username.substr(0, username.indexOf('/')); + username = username.substr(username.indexOf('/')+1); + } try { utility.startTenantFlow(carbonUser); var url = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] + "/users/" + encodeURIComponent(username); + if (domain) { + url += '?domain=' + domain; + } var response = privateMethods.callBackend(url, constants["HTTP_GET"]); response["content"] = parse(response.content); response["userDomain"] = carbonUser.domain; @@ -199,10 +207,18 @@ var userModule = function () { */ publicMethods.getRolesByUsername = function (username) { var carbonUser = privateMethods.getCarbonUser(); + var domain; + if (username.indexOf('/') > 0) { + domain = username.substr(0, username.indexOf('/')); + username = username.substr(username.indexOf('/')+1); + } try { utility.startTenantFlow(carbonUser); var url = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] + "/users/" + encodeURIComponent(username) + "/roles"; + if (domain) { + url += '?domain=' + domain; + } var response = privateMethods.callBackend(url, constants["HTTP_GET"]); if (response.status == "success") { response.content = parse(response.content).roles; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.user.edit/public/js/bottomJs.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.user.edit/public/js/bottomJs.js index 295195e3f7..a39472b01a 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.user.edit/public/js/bottomJs.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.user.edit/public/js/bottomJs.js @@ -235,8 +235,8 @@ $(document).ready(function () { roles = []; } addUserFormData.roles = roles; - - var addUserAPI = deviceMgtBasePath + "/users/" + username; + username = username.substr(username.indexOf('/') + 1); + var addUserAPI = deviceMgtBasePath + "/users/" + username + "?domain="+domain; invokerUtil.put( addUserAPI, diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.users/public/js/listing.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.users/public/js/listing.js index 2d5b88e35b..30c601f180 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.users/public/js/listing.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.users/public/js/listing.js @@ -162,9 +162,17 @@ function resetPassword(username) { } else { var resetPasswordFormData = {}; resetPasswordFormData.newPassword = unescape(confirmedPassword); - + var domain; + if (username.indexOf('/') > 0) { + domain = username.substr(0, username.indexOf('/')); + username = username.substr(username.indexOf('/')+1); + } var resetPasswordServiceURL = apiBasePath + "/admin/users/"+ username +"/credentials"; + if (domain) { + resetPasswordServiceURL += '?domain=' + domain; + } + invokerUtil.post( resetPasswordServiceURL, resetPasswordFormData, @@ -198,7 +206,15 @@ function resetPassword(username) { * on User Listing page in WSO2 MDM Console. */ function removeUser(username) { + var domain; + if (username.indexOf('/') > 0) { + domain = username.substr(0, username.indexOf('/')); + username = username.substr(username.indexOf('/')+1); + } var removeUserAPI = apiBasePath + "/users/" + username; + if (domain) { + url += '?domain=' + domain; + } $(modalPopupContent).html($('#remove-user-modal-content').html()); showPopup(); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.header.user-menu/user-menu.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.header.user-menu/user-menu.hbs index eb958f6bfc..d2aba63fdc 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.header.user-menu/user-menu.hbs +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.header.user-menu/user-menu.hbs @@ -46,7 +46,7 @@
- +