revert-70aa11f8
hasuniea 8 years ago
commit 7281abf876

@ -238,6 +238,11 @@
<groupId>org.wso2.carbon.devicemgt</groupId> <groupId>org.wso2.carbon.devicemgt</groupId>
<artifactId>org.wso2.carbon.apimgt.annotations</artifactId> <artifactId>org.wso2.carbon.apimgt.annotations</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.wso2.carbon.devicemgt</groupId>
<artifactId>org.wso2.carbon.device.mgt.analytics.dashboard</artifactId>
<scope>provided</scope>
</dependency>
</dependencies> </dependencies>
</project> </project>

@ -52,7 +52,6 @@ public interface Certificate {
* @return Status of the data persist operation. * @return Status of the data persist operation.
*/ */
@POST @POST
@Path("saveCertificate")
@ApiOperation( @ApiOperation(
consumes = MediaType.APPLICATION_JSON + ", " + MediaType.APPLICATION_XML, consumes = MediaType.APPLICATION_JSON + ", " + MediaType.APPLICATION_XML,
produces = MediaType.APPLICATION_JSON + ", " + MediaType.APPLICATION_XML, produces = MediaType.APPLICATION_JSON + ", " + MediaType.APPLICATION_XML,

@ -0,0 +1,81 @@
package org.wso2.carbon.device.mgt.jaxrs.api;
import io.swagger.annotations.Api;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Response;
@Path("/dashboard")
@Api(value = "Dashboard", description = "Dashboard related operations are described here.")
@SuppressWarnings("NonJaxWsWebServices")
public interface Dashboard {
String CONNECTIVITY_STATUS = "connectivity-status";
String POTENTIAL_VULNERABILITY = "potential-vulnerability";
String NON_COMPLIANT_FEATURE_CODE = "non-compliant-feature-code";
String PLATFORM = "platform";
String OWNERSHIP = "ownership";
// Constants related to pagination
String PAGINATION_ENABLED = "pagination-enabled";
String START_INDEX = "start";
String RESULT_COUNT = "length";
@GET
@Path("device-count-overview")
Response getOverviewDeviceCounts();
@GET
@Path("device-counts-by-potential-vulnerabilities")
Response getDeviceCountsByPotentialVulnerabilities();
@GET
@Path("non-compliant-device-counts-by-features")
Response getNonCompliantDeviceCountsByFeatures(@QueryParam(START_INDEX) int startIndex,
@QueryParam(RESULT_COUNT) int resultCount);
@GET
@Path("device-counts-by-groups")
Response getDeviceCountsByGroups(@QueryParam(CONNECTIVITY_STATUS) String connectivityStatus,
@QueryParam(POTENTIAL_VULNERABILITY) String potentialVulnerability,
@QueryParam(PLATFORM) String platform,
@QueryParam(OWNERSHIP) String ownership);
@GET
@Path("feature-non-compliant-device-counts-by-groups")
Response getFeatureNonCompliantDeviceCountsByGroups(@QueryParam(NON_COMPLIANT_FEATURE_CODE) String nonCompliantFeatureCode,
@QueryParam(PLATFORM) String platform,
@QueryParam(OWNERSHIP) String ownership);
@GET
@Path("filtered-device-count-over-total")
Response getFilteredDeviceCountOverTotal(@QueryParam(CONNECTIVITY_STATUS) String connectivityStatus,
@QueryParam(POTENTIAL_VULNERABILITY) String potentialVulnerability,
@QueryParam(PLATFORM) String platform,
@QueryParam(OWNERSHIP) String ownership);
@GET
@Path("feature-non-compliant-device-count-over-total")
Response getFeatureNonCompliantDeviceCountOverTotal(@QueryParam(NON_COMPLIANT_FEATURE_CODE) String nonCompliantFeatureCode,
@QueryParam(PLATFORM) String platform,
@QueryParam(OWNERSHIP) String ownership);
@GET
@Path("devices-with-details")
Response getDevicesWithDetails(@QueryParam(CONNECTIVITY_STATUS) String connectivityStatus,
@QueryParam(POTENTIAL_VULNERABILITY) String potentialVulnerability,
@QueryParam(PLATFORM) String platform,
@QueryParam(OWNERSHIP) String ownership,
@QueryParam(PAGINATION_ENABLED) String paginationEnabled,
@QueryParam(START_INDEX) int startIndex,
@QueryParam(RESULT_COUNT) int resultCount);
@GET
@Path("feature-non-compliant-devices-with-details")
Response getFeatureNonCompliantDevicesWithDetails(@QueryParam(NON_COMPLIANT_FEATURE_CODE) String nonCompliantFeatureCode,
@QueryParam(PLATFORM) String platform,
@QueryParam(OWNERSHIP) String ownership,
@QueryParam(PAGINATION_ENABLED) String paginationEnabled,
@QueryParam(START_INDEX) int startIndex,
@QueryParam(RESULT_COUNT) int resultCount);
}

@ -24,7 +24,9 @@ import org.wso2.carbon.device.mgt.common.device.details.DeviceWrapper;
import org.wso2.carbon.device.mgt.common.search.SearchContext; import org.wso2.carbon.device.mgt.common.search.SearchContext;
import javax.ws.rs.GET; import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path; import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
@ -50,8 +52,25 @@ public interface DeviceSearch {
@ApiResponses(value = { @ApiResponses(value = {
@ApiResponse(code = 200, message = "OK", response = DeviceWrapper.class, responseContainer = "List"), @ApiResponse(code = 200, message = "OK", response = DeviceWrapper.class, responseContainer = "List"),
@ApiResponse(code = 500, message = "Error occurred while searching the device information") @ApiResponse(code = 500, message = "Error occurred while searching the device information")
}) })
@Permission(scope = "device-search", permissions = {"/permission/admin/device-mgt/admin/devices/list"}) @Permission(scope = "device-search", permissions = {"/permission/admin/device-mgt/admin/devices/list"})
Response getFilteredDeviceInfo(@ApiParam(name = "enrollmentCertificates", value = "List of search conditions", Response getDeviceInfo(@ApiParam(name = "enrollmentCertificates", value = "List of search conditions",
required = true) SearchContext searchContext); required = true) SearchContext searchContext);
@GET
@Path("after/{time}")
@ApiOperation(
consumes = MediaType.APPLICATION_JSON,
httpMethod = "GET",
value = "Get devices information since a specified time.",
notes = "Get devices information of devices updated since a specified time.",
response = DeviceWrapper.class,
responseContainer = "List")
@ApiResponses(value = {
@ApiResponse(code = 200, message = "OK", response = DeviceWrapper.class, responseContainer = "List"),
@ApiResponse(code = 500, message = "Error occurred while fetching the device information")
})
@Permission(scope = "device-search", permissions = {"/permission/admin/device-mgt/admin/devices/update-since-list"})
Response getUpdatedDevices(@ApiParam(name = "time", value = "Time since the updated devices should be " +
"fetched.", required = true)@PathParam("time") String time);
} }

@ -280,4 +280,9 @@ public interface Policy {
required = true) @PathParam("type") String type, required = true) @PathParam("type") String type,
@ApiParam(name = "id", value = "Define the device ID as the value for {id}.", @ApiParam(name = "id", value = "Define the device ID as the value for {id}.",
required = true) @PathParam("id") String id); required = true) @PathParam("id") String id);
//TODO: This API is still not in use, but will be needed when grouping is implemented.
@GET
@Path("/device-group/{user}")
public Response getDeviceGroupsRelatedToPolicies(@PathParam("user") String userName);
} }

@ -31,6 +31,7 @@ import org.wso2.carbon.device.mgt.common.PaginationRequest;
import org.wso2.carbon.device.mgt.common.PaginationResult; import org.wso2.carbon.device.mgt.common.PaginationResult;
import org.wso2.carbon.device.mgt.jaxrs.api.util.DeviceMgtAPIUtils; import org.wso2.carbon.device.mgt.jaxrs.api.util.DeviceMgtAPIUtils;
import org.wso2.carbon.device.mgt.jaxrs.beans.EnrollmentCertificate; import org.wso2.carbon.device.mgt.jaxrs.beans.EnrollmentCertificate;
import org.wso2.carbon.device.mgt.jaxrs.exception.BadRequestException;
import org.wso2.carbon.device.mgt.jaxrs.exception.Message; import org.wso2.carbon.device.mgt.jaxrs.exception.Message;
import javax.ws.rs.Consumes; import javax.ws.rs.Consumes;
@ -65,7 +66,6 @@ public class CertificateImpl implements Certificate {
* @return Status of the data persist operation. * @return Status of the data persist operation.
*/ */
@POST @POST
@Path("saveCertificate")
public Response saveCertificate(@HeaderParam("Accept") String acceptHeader, public Response saveCertificate(@HeaderParam("Accept") String acceptHeader,
EnrollmentCertificate[] enrollmentCertificates) { EnrollmentCertificate[] enrollmentCertificates) {
MediaType responseMediaType = DeviceMgtAPIUtils.getResponseMediaType(acceptHeader); MediaType responseMediaType = DeviceMgtAPIUtils.getResponseMediaType(acceptHeader);
@ -111,14 +111,11 @@ public class CertificateImpl implements Certificate {
} }
CertificateManagementService certificateService = DeviceMgtAPIUtils.getCertificateManagementService(); CertificateManagementService certificateService = DeviceMgtAPIUtils.getCertificateManagementService();
CertificateResponse certificateResponse; List<CertificateResponse> certificateResponse;
try { try {
certificateResponse = certificateService.getCertificateBySerial(serialNumber); certificateResponse = certificateService.searchCertificates(serialNumber);
if(certificateResponse != null) {
certificateResponse.setCertificate(null); //avoid sending byte array in response.
}
return Response.status(Response.Status.OK).entity(certificateResponse).type(responseMediaType).build(); return Response.status(Response.Status.OK).entity(certificateResponse).type(responseMediaType).build();
} catch (KeystoreException e) { } catch (CertificateManagementDAOException e) {
String msg = "Error occurred while converting PEM file to X509Certificate"; String msg = "Error occurred while converting PEM file to X509Certificate";
log.error(msg, e); log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).type(responseMediaType).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).type(responseMediaType).build();
@ -164,6 +161,28 @@ public class CertificateImpl implements Certificate {
} }
} }
/**
* Get all certificates
*
* @return certificate details in an array.
* @throws MDMAPIException
*/
@GET
public Response getAllCertificates(@HeaderParam("Accept") String acceptHeader)
throws MDMAPIException {
MediaType responseMediaType = DeviceMgtAPIUtils.getResponseMediaType(acceptHeader);
CertificateManagementService certificateService = DeviceMgtAPIUtils.getCertificateManagementService();
try {
List<CertificateResponse> certificates = certificateService.getCertificates();
return Response.status(Response.Status.OK).entity(certificates).type(responseMediaType).build();
} catch (CertificateManagementDAOException e) {
String msg = "Error occurred while fetching all certificates.";
log.error(msg, e);
throw new MDMAPIException(msg, e);
}
}
@DELETE @DELETE
@Path("{serialNumber}") @Path("{serialNumber}")
public Response removeCertificate(@HeaderParam("Accept") String acceptHeader, public Response removeCertificate(@HeaderParam("Accept") String acceptHeader,

@ -0,0 +1,687 @@
/*
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* you may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.wso2.carbon.device.mgt.jaxrs.api;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.mgt.analytics.dashboard.GadgetDataService;
import org.wso2.carbon.device.mgt.analytics.dashboard.bean.BasicFilterSet;
import org.wso2.carbon.device.mgt.analytics.dashboard.bean.DeviceCountByGroup;
import org.wso2.carbon.device.mgt.analytics.dashboard.bean.DeviceWithDetails;
import org.wso2.carbon.device.mgt.analytics.dashboard.bean.ExtendedFilterSet;
import org.wso2.carbon.device.mgt.analytics.dashboard.exception.*;
import org.wso2.carbon.device.mgt.common.PaginationResult;
import org.wso2.carbon.device.mgt.jaxrs.api.util.DeviceMgtAPIUtils;
import org.wso2.carbon.device.mgt.jaxrs.beans.DashboardGadgetDataWrapper;
import org.wso2.carbon.device.mgt.jaxrs.beans.DashboardPaginationGadgetDataWrapper;
import javax.ws.rs.*;
import javax.ws.rs.core.Response;
import java.util.ArrayList;
import java.util.List;
/**
* This class consists of dashboard related REST APIs
* to be consumed by individual client gadgets such as
* [1] Overview of Devices,
* [2] Potential Vulnerabilities,
* [3] Non-compliant Devices by Features,
* [4] Device Groupings and etc.
*/
@Consumes({"application/json"})
@Produces({"application/json"})
@SuppressWarnings("NonJaxWsWebServices")
public class DashboardImpl implements Dashboard{
private static Log log = LogFactory.getLog(DashboardImpl.class);
private static final String FLAG_TRUE = "true";
private static final String FLAG_FALSE = "false";
// Constants related to common error-response messages
private static final String INVALID_QUERY_PARAM_VALUE_POTENTIAL_VULNERABILITY = "Received an invalid value for " +
"query parameter : " + POTENTIAL_VULNERABILITY + ", Should be either NON_COMPLIANT or UNMONITORED.";
private static final String INVALID_QUERY_PARAM_VALUE_START_INDEX = "Received an invalid value for " +
"query parameter : " + START_INDEX + ", Should not be lesser than 0.";
private static final String INVALID_QUERY_PARAM_VALUE_RESULT_COUNT = "Received an invalid value for " +
"query parameter : " + RESULT_COUNT + ", Should not be lesser than 5.";
private static final String INVALID_QUERY_PARAM_VALUE_PAGINATION_ENABLED = "Received an invalid value for " +
"query parameter : " + PAGINATION_ENABLED + ", Should be either true or false.";
private static final String REQUIRED_QUERY_PARAM_VALUE_NON_COMPLIANT_FEATURE_CODE = "Missing required query " +
"parameter : " + NON_COMPLIANT_FEATURE_CODE;
private static final String REQUIRED_QUERY_PARAM_VALUE_PAGINATION_ENABLED = "Missing required query " +
"parameter : " + PAGINATION_ENABLED;
private static final String ERROR_IN_RETRIEVING_REQUESTED_DATA = "Error in retrieving requested data.";
@GET
@Path("device-count-overview")
public Response getOverviewDeviceCounts() {
GadgetDataService gadgetDataService = DeviceMgtAPIUtils.getGadgetDataService();
DashboardGadgetDataWrapper dashboardGadgetDataWrapper1 = new DashboardGadgetDataWrapper();
// getting total device count
DeviceCountByGroup totalDeviceCount;
try {
totalDeviceCount = gadgetDataService.getTotalDeviceCount();
} catch (DataAccessLayerException e) {
log.error("An internal error occurred while trying to execute relevant data service function " +
"@ Dashboard API layer to retrieve total device count.", e);
return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR).
entity(ERROR_IN_RETRIEVING_REQUESTED_DATA).build();
}
List<DeviceCountByGroup> totalDeviceCountInListEntry = new ArrayList<>();
totalDeviceCountInListEntry.add(totalDeviceCount);
dashboardGadgetDataWrapper1.setContext("Total-device-count");
dashboardGadgetDataWrapper1.setGroupingAttribute(null);
dashboardGadgetDataWrapper1.setData(totalDeviceCountInListEntry);
// getting device counts by connectivity statuses
List<DeviceCountByGroup> deviceCountsByConnectivityStatuses;
try {
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<DashboardGadgetDataWrapper> responsePayload = new ArrayList<>();
responsePayload.add(dashboardGadgetDataWrapper1);
responsePayload.add(dashboardGadgetDataWrapper2);
return Response.status(HttpStatus.SC_OK).entity(responsePayload).build();
}
@GET
@Path("device-counts-by-potential-vulnerabilities")
public Response getDeviceCountsByPotentialVulnerabilities() {
GadgetDataService gadgetDataService = DeviceMgtAPIUtils.getGadgetDataService();
List<DeviceCountByGroup> deviceCountsByPotentialVulnerabilities;
try {
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<DashboardGadgetDataWrapper> responsePayload = new ArrayList<>();
responsePayload.add(dashboardGadgetDataWrapper);
return Response.status(HttpStatus.SC_OK).entity(responsePayload).build();
}
@GET
@Path("non-compliant-device-counts-by-features")
public Response getNonCompliantDeviceCountsByFeatures(@QueryParam(START_INDEX) int startIndex,
@QueryParam(RESULT_COUNT) int resultCount) {
GadgetDataService gadgetDataService = DeviceMgtAPIUtils.getGadgetDataService();
DashboardPaginationGadgetDataWrapper
dashboardPaginationGadgetDataWrapper = new DashboardPaginationGadgetDataWrapper();
PaginationResult paginationResult;
try {
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<DashboardPaginationGadgetDataWrapper> responsePayload = new ArrayList<>();
responsePayload.add(dashboardPaginationGadgetDataWrapper);
return Response.status(HttpStatus.SC_OK).entity(responsePayload).build();
}
@GET
@Path("device-counts-by-groups")
public Response getDeviceCountsByGroups(@QueryParam(CONNECTIVITY_STATUS) String connectivityStatus,
@QueryParam(POTENTIAL_VULNERABILITY) String potentialVulnerability,
@QueryParam(PLATFORM) String platform,
@QueryParam(OWNERSHIP) String ownership) {
// getting gadget data service
GadgetDataService gadgetDataService = DeviceMgtAPIUtils.getGadgetDataService();
// constructing filter set
ExtendedFilterSet filterSet = new ExtendedFilterSet();
filterSet.setConnectivityStatus(connectivityStatus);
filterSet.setPotentialVulnerability(potentialVulnerability);
filterSet.setPlatform(platform);
filterSet.setOwnership(ownership);
// creating device-Counts-by-platforms Data Wrapper
List<DeviceCountByGroup> deviceCountsByPlatforms;
try {
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<DeviceCountByGroup> 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<DashboardGadgetDataWrapper> responsePayload = new ArrayList<>();
responsePayload.add(dashboardGadgetDataWrapper1);
responsePayload.add(dashboardGadgetDataWrapper2);
return Response.status(HttpStatus.SC_OK).entity(responsePayload).build();
}
@GET
@Path("feature-non-compliant-device-counts-by-groups")
public Response getFeatureNonCompliantDeviceCountsByGroups(@QueryParam(NON_COMPLIANT_FEATURE_CODE) String nonCompliantFeatureCode,
@QueryParam(PLATFORM) String platform,
@QueryParam(OWNERSHIP) String ownership) {
// getting gadget data service
GadgetDataService gadgetDataService = DeviceMgtAPIUtils.getGadgetDataService();
// constructing filter set
BasicFilterSet filterSet = new BasicFilterSet();
filterSet.setPlatform(platform);
filterSet.setOwnership(ownership);
// creating feature-non-compliant-device-Counts-by-platforms Data Wrapper
List<DeviceCountByGroup> featureNonCompliantDeviceCountsByPlatforms;
try {
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<DeviceCountByGroup> 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<DashboardGadgetDataWrapper> responsePayload = new ArrayList<>();
responsePayload.add(dashboardGadgetDataWrapper1);
responsePayload.add(dashboardGadgetDataWrapper2);
return Response.status(HttpStatus.SC_OK).entity(responsePayload).build();
}
@GET
@Path("filtered-device-count-over-total")
public Response getFilteredDeviceCountOverTotal(@QueryParam(CONNECTIVITY_STATUS) String connectivityStatus,
@QueryParam(POTENTIAL_VULNERABILITY) String potentialVulnerability,
@QueryParam(PLATFORM) String platform,
@QueryParam(OWNERSHIP) String ownership) {
// getting gadget data service
GadgetDataService gadgetDataService = DeviceMgtAPIUtils.getGadgetDataService();
// constructing filter set
ExtendedFilterSet filterSet = new ExtendedFilterSet();
filterSet.setConnectivityStatus(connectivityStatus);
filterSet.setPotentialVulnerability(potentialVulnerability);
filterSet.setPlatform(platform);
filterSet.setOwnership(ownership);
// creating filteredDeviceCount Data Wrapper
DeviceCountByGroup filteredDeviceCount;
try {
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<Object> filteredDeviceCountOverTotalDataWrapper = new ArrayList<>();
filteredDeviceCountOverTotalDataWrapper.add(filteredDeviceCount);
filteredDeviceCountOverTotalDataWrapper.add(totalDeviceCount);
DashboardGadgetDataWrapper dashboardGadgetDataWrapper = new DashboardGadgetDataWrapper();
dashboardGadgetDataWrapper.setContext("Filtered-device-count-over-total");
dashboardGadgetDataWrapper.setGroupingAttribute(null);
dashboardGadgetDataWrapper.setData(filteredDeviceCountOverTotalDataWrapper);
List<DashboardGadgetDataWrapper> responsePayload = new ArrayList<>();
responsePayload.add(dashboardGadgetDataWrapper);
return Response.status(HttpStatus.SC_OK).entity(responsePayload).build();
}
@GET
@Path("feature-non-compliant-device-count-over-total")
public Response getFeatureNonCompliantDeviceCountOverTotal(@QueryParam(NON_COMPLIANT_FEATURE_CODE) String nonCompliantFeatureCode,
@QueryParam(PLATFORM) String platform,
@QueryParam(OWNERSHIP) String ownership) {
// getting gadget data service
GadgetDataService gadgetDataService = DeviceMgtAPIUtils.getGadgetDataService();
// constructing filter set
BasicFilterSet filterSet = new BasicFilterSet();
filterSet.setPlatform(platform);
filterSet.setOwnership(ownership);
// creating featureNonCompliantDeviceCount Data Wrapper
DeviceCountByGroup featureNonCompliantDeviceCount;
try {
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<Object> featureNonCompliantDeviceCountOverTotalDataWrapper = new ArrayList<>();
featureNonCompliantDeviceCountOverTotalDataWrapper.add(featureNonCompliantDeviceCount);
featureNonCompliantDeviceCountOverTotalDataWrapper.add(totalDeviceCount);
DashboardGadgetDataWrapper dashboardGadgetDataWrapper = new DashboardGadgetDataWrapper();
dashboardGadgetDataWrapper.setContext("Feature-non-compliant-device-count-over-total");
dashboardGadgetDataWrapper.setGroupingAttribute(null);
dashboardGadgetDataWrapper.setData(featureNonCompliantDeviceCountOverTotalDataWrapper);
List<DashboardGadgetDataWrapper> responsePayload = new ArrayList<>();
responsePayload.add(dashboardGadgetDataWrapper);
return Response.status(HttpStatus.SC_OK).entity(responsePayload).build();
}
@GET
@Path("devices-with-details")
public Response getDevicesWithDetails(@QueryParam(CONNECTIVITY_STATUS) String connectivityStatus,
@QueryParam(POTENTIAL_VULNERABILITY) String potentialVulnerability,
@QueryParam(PLATFORM) String platform,
@QueryParam(OWNERSHIP) String ownership,
@QueryParam(PAGINATION_ENABLED) String paginationEnabled,
@QueryParam(START_INDEX) int startIndex,
@QueryParam(RESULT_COUNT) int resultCount) {
if (paginationEnabled == null) {
log.error("Bad request on retrieving a filtered set of devices with details @ " +
"Dashboard API layer. " + REQUIRED_QUERY_PARAM_VALUE_PAGINATION_ENABLED);
return Response.status(HttpStatus.SC_BAD_REQUEST).
entity(REQUIRED_QUERY_PARAM_VALUE_PAGINATION_ENABLED).build();
} else if (FLAG_TRUE.equals(paginationEnabled)) {
// getting gadget data service
GadgetDataService gadgetDataService = DeviceMgtAPIUtils.getGadgetDataService();
// constructing filter set
ExtendedFilterSet filterSet = new ExtendedFilterSet();
filterSet.setConnectivityStatus(connectivityStatus);
filterSet.setPotentialVulnerability(potentialVulnerability);
filterSet.setPlatform(platform);
filterSet.setOwnership(ownership);
PaginationResult paginationResult;
try {
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<DashboardPaginationGadgetDataWrapper> responsePayload = new ArrayList<>();
responsePayload.add(dashboardPaginationGadgetDataWrapper);
return Response.status(HttpStatus.SC_OK).entity(responsePayload).build();
} else if (FLAG_FALSE.equals(paginationEnabled)) {
// getting gadget data service
GadgetDataService gadgetDataService = DeviceMgtAPIUtils.getGadgetDataService();
// constructing filter set
ExtendedFilterSet filterSet = new ExtendedFilterSet();
filterSet.setConnectivityStatus(connectivityStatus);
filterSet.setPotentialVulnerability(potentialVulnerability);
filterSet.setPlatform(platform);
filterSet.setOwnership(ownership);
List<DeviceWithDetails> devicesWithDetails;
try {
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<DashboardGadgetDataWrapper> responsePayload = new ArrayList<>();
responsePayload.add(dashboardGadgetDataWrapper);
return Response.status(HttpStatus.SC_OK).entity(responsePayload).build();
} else {
log.error("Bad request on retrieving a filtered set of devices with details @ " +
"Dashboard API layer. " + INVALID_QUERY_PARAM_VALUE_PAGINATION_ENABLED);
return Response.status(HttpStatus.SC_BAD_REQUEST).
entity(INVALID_QUERY_PARAM_VALUE_PAGINATION_ENABLED).build();
}
}
@GET
@Path("feature-non-compliant-devices-with-details")
public Response getFeatureNonCompliantDevicesWithDetails(@QueryParam(NON_COMPLIANT_FEATURE_CODE) String nonCompliantFeatureCode,
@QueryParam(PLATFORM) String platform,
@QueryParam(OWNERSHIP) String ownership,
@QueryParam(PAGINATION_ENABLED) String paginationEnabled,
@QueryParam(START_INDEX) int startIndex,
@QueryParam(RESULT_COUNT) int resultCount) {
if (paginationEnabled == null) {
log.error("Bad request on retrieving a filtered set of feature non-compliant devices with " +
"details @ Dashboard API layer. " + REQUIRED_QUERY_PARAM_VALUE_PAGINATION_ENABLED);
return Response.status(HttpStatus.SC_BAD_REQUEST).
entity(REQUIRED_QUERY_PARAM_VALUE_PAGINATION_ENABLED).build();
} else if (FLAG_TRUE.equals(paginationEnabled)) {
// getting gadget data service
GadgetDataService gadgetDataService = DeviceMgtAPIUtils.getGadgetDataService();
// constructing filter set
BasicFilterSet filterSet = new BasicFilterSet();
filterSet.setPlatform(platform);
filterSet.setOwnership(ownership);
PaginationResult paginationResult;
try {
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<DashboardPaginationGadgetDataWrapper> responsePayload = new ArrayList<>();
responsePayload.add(dashboardPaginationGadgetDataWrapper);
return Response.status(HttpStatus.SC_OK).entity(responsePayload).build();
} else if (FLAG_FALSE.equals(paginationEnabled)) {
// getting gadget data service
GadgetDataService gadgetDataService = DeviceMgtAPIUtils.getGadgetDataService();
// constructing filter set
BasicFilterSet filterSet = new BasicFilterSet();
filterSet.setPlatform(platform);
filterSet.setOwnership(ownership);
List<DeviceWithDetails> featureNonCompliantDevicesWithDetails;
try {
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<DashboardGadgetDataWrapper> responsePayload = new ArrayList<>();
responsePayload.add(dashboardGadgetDataWrapper);
return Response.status(HttpStatus.SC_OK).entity(responsePayload).build();
} else {
log.error("Bad request on retrieving a filtered set of feature non-compliant devices with " +
"details @ Dashboard API layer. " + INVALID_QUERY_PARAM_VALUE_PAGINATION_ENABLED);
return Response.status(HttpStatus.SC_BAD_REQUEST).
entity(INVALID_QUERY_PARAM_VALUE_PAGINATION_ENABLED).build();
}
}
}

@ -19,6 +19,7 @@
package org.wso2.carbon.device.mgt.jaxrs.api.impl; package org.wso2.carbon.device.mgt.jaxrs.api.impl;
import io.swagger.annotations.Api;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.mgt.common.device.details.DeviceWrapper; import org.wso2.carbon.device.mgt.common.device.details.DeviceWrapper;
@ -29,16 +30,22 @@ import org.wso2.carbon.device.mgt.jaxrs.api.DeviceSearch;
import org.wso2.carbon.device.mgt.jaxrs.api.util.DeviceMgtAPIUtils; import org.wso2.carbon.device.mgt.jaxrs.api.util.DeviceMgtAPIUtils;
import javax.ws.rs.GET; import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import java.util.List; import java.util.List;
@Path("/search")
@Api(value = "DeviceSearch", description = "Device searching related operations can be found here.")
@SuppressWarnings("NonJaxWsWebServices") @SuppressWarnings("NonJaxWsWebServices")
public class DeviceSearchImpl implements DeviceSearch { public class DeviceSearchImpl implements DeviceSearch {
private static Log log = LogFactory.getLog(DeviceSearchImpl.class); private static Log log = LogFactory.getLog(DeviceSearchImpl.class);
@GET @GET
public Response getFilteredDeviceInfo(SearchContext searchContext) { public Response getDeviceInfo(SearchContext searchContext) {
SearchManagerService searchManagerService; SearchManagerService searchManagerService;
List<DeviceWrapper> devices; List<DeviceWrapper> devices;
try { try {
@ -52,5 +59,25 @@ public class DeviceSearchImpl implements DeviceSearch {
} }
return Response.status(Response.Status.OK).entity(devices).build(); return Response.status(Response.Status.OK).entity(devices).build();
} }
@POST
@Path("after/{time}")
public Response getUpdatedDevices(@PathParam("time") String time){
SearchManagerService searchManagerService;
List<DeviceWrapper> devices;
try {
searchManagerService = DeviceMgtAPIUtils.getSearchManagerService();
devices = searchManagerService.getUpdated(Long.parseLong(time));
} catch (SearchMgtException e) {
String msg = "Error occurred while retrieving the updated device information after the given time.";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
return Response.status(Response.Status.OK).entity(devices).build();
}
} }

@ -25,7 +25,10 @@ import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationException; import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationException;
import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationService; import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationService;
import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup;
import org.wso2.carbon.device.mgt.common.group.mgt.GroupManagementException;
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder; import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
import org.wso2.carbon.device.mgt.core.service.GroupManagementProviderService;
import org.wso2.carbon.device.mgt.jaxrs.api.common.MDMAPIException; import org.wso2.carbon.device.mgt.jaxrs.api.common.MDMAPIException;
import org.wso2.carbon.device.mgt.jaxrs.api.util.DeviceMgtAPIUtils; import org.wso2.carbon.device.mgt.jaxrs.api.util.DeviceMgtAPIUtils;
import org.wso2.carbon.device.mgt.jaxrs.beans.PriorityUpdatedPolicyWrapper; import org.wso2.carbon.device.mgt.jaxrs.beans.PriorityUpdatedPolicyWrapper;
@ -33,6 +36,7 @@ import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtUtil;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.jaxrs.api.util.ResponsePayload; import org.wso2.carbon.device.mgt.jaxrs.api.util.ResponsePayload;
import org.wso2.carbon.device.mgt.jaxrs.beans.PolicyWrapper; import org.wso2.carbon.device.mgt.jaxrs.beans.PolicyWrapper;
import org.wso2.carbon.policy.mgt.common.DeviceGroupWrapper;
import org.wso2.carbon.policy.mgt.common.PolicyAdministratorPoint; import org.wso2.carbon.policy.mgt.common.PolicyAdministratorPoint;
import org.wso2.carbon.policy.mgt.common.PolicyManagementException; import org.wso2.carbon.policy.mgt.common.PolicyManagementException;
import org.wso2.carbon.policy.mgt.common.PolicyMonitoringTaskException; import org.wso2.carbon.policy.mgt.common.PolicyMonitoringTaskException;
@ -447,9 +451,9 @@ public class PolicyImpl implements org.wso2.carbon.device.mgt.jaxrs.api.Policy {
} }
} }
@Override @Override
@GET @GET
@Path("{type}/{id}/active-policy") @Path("{type}/{id}/active-policy")
public Response getDeviceActivePolicy(@PathParam("type") String type, @PathParam("id") String id) { public Response getDeviceActivePolicy(@PathParam("type") String type, @PathParam("id") String id) {
try { try {
DeviceIdentifier deviceIdentifier = DeviceMgtAPIUtils.instantiateDeviceIdentifier(type, id); DeviceIdentifier deviceIdentifier = DeviceMgtAPIUtils.instantiateDeviceIdentifier(type, id);
@ -463,4 +467,35 @@ public class PolicyImpl implements org.wso2.carbon.device.mgt.jaxrs.api.Policy {
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} }
} }
@GET
@Path("/device-group/{user}")
public Response getDeviceGroupsRelatedToPolicies(@PathParam("user") String userName) {
try {
List<DeviceGroupWrapper> groupWrappers = new ArrayList<>();
GroupManagementProviderService service = DeviceMgtAPIUtils.getGroupManagementProviderService();
List<DeviceGroup> deviceGroups = service.getGroups(userName);
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
for (DeviceGroup dg : deviceGroups) {
DeviceGroupWrapper gw = new DeviceGroupWrapper();
gw.setId(dg.getId());
gw.setOwner(dg.getOwner());
gw.setName(dg.getName());
gw.setTenantId(tenantId);
groupWrappers.add(gw);
}
ResponsePayload responsePayload = new ResponsePayload();
responsePayload.setStatusCode(HttpStatus.SC_OK);
responsePayload.setMessageFromServer("Sending all retrieved device groups.");
responsePayload.setResponseContent(groupWrappers);
return Response.status(HttpStatus.SC_OK).entity(groupWrappers).build();
} catch (GroupManagementException e) {
String error = "Error occurred while getting the groups related to users for policy.";
log.error(error, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(error).build();
}
}
} }

@ -23,6 +23,7 @@ import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.certificate.mgt.core.service.CertificateManagementService; import org.wso2.carbon.certificate.mgt.core.service.CertificateManagementService;
import org.wso2.carbon.context.CarbonContext; import org.wso2.carbon.context.CarbonContext;
import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.device.mgt.analytics.dashboard.GadgetDataService;
import org.wso2.carbon.device.mgt.jaxrs.api.common.MDMAPIException; import org.wso2.carbon.device.mgt.jaxrs.api.common.MDMAPIException;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.PaginationResult; import org.wso2.carbon.device.mgt.common.PaginationResult;
@ -319,4 +320,13 @@ public class DeviceMgtAPIUtils {
} }
return searchManagerService; return searchManagerService;
} }
public static GadgetDataService getGadgetDataService() {
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
GadgetDataService gadgetDataService = (GadgetDataService) ctx.getOSGiService(GadgetDataService.class, null);
if (gadgetDataService == null) {
throw new IllegalStateException("Gadget Data Service has not been initialized.");
}
return gadgetDataService;
}
} }

@ -0,0 +1,56 @@
/*
* 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.beans;
import java.util.List;
public class DashboardGadgetDataWrapper {
private String context;
private String groupingAttribute;
private List<?> data;
@SuppressWarnings("unused")
public String getContext() {
return context;
}
public void setContext(String context) {
this.context = context;
}
@SuppressWarnings("unused")
public String getGroupingAttribute() {
return groupingAttribute;
}
public void setGroupingAttribute(String groupingAttribute) {
this.groupingAttribute = groupingAttribute;
}
@SuppressWarnings("unused")
public List<?> getData() {
return data;
}
public void setData(List<?> data) {
this.data = data;
}
}

@ -0,0 +1,34 @@
/*
* 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.beans;
public class DashboardPaginationGadgetDataWrapper extends DashboardGadgetDataWrapper {
private int totalRecordCount;
@SuppressWarnings("unused")
public int getTotalRecordCount() {
return totalRecordCount;
}
public void setTotalRecordCount(int totalRecordCount) {
this.totalRecordCount = totalRecordCount;
}
}

@ -886,10 +886,16 @@
<Permission> <Permission>
<name>Device Search</name> <name>Device Search</name>
<path>/device-mgt/admin/search</path> <path>/device-mgt/admin/search</path>
<url>/information/*</url> <url>/search</url>
<method>GET</method> <method>POST</method>
</Permission> </Permission>
<Permission>
<name>Device Updated</name>
<path>/device-mgt/admin/search/after</path>
<url>/search/after/*</url>
<method>GET</method>
</Permission>
<!--End of the device search and information --> <!--End of the device search and information -->
@ -937,19 +943,25 @@
<!-- Certificate related APIs --> <!-- Certificate related APIs -->
<Permission> <Permission>
<name>Save certificate in the database</name> <name>Save certificate in the database</name>
<path>/device-mgt/android/certificate/save</path> <path>/device-mgt/admin/certificate/save</path>
<url>/certificates/saveCertificate</url> <url>/certificates</url>
<method>POST</method> <method>POST</method>
</Permission> </Permission>
<Permission> <Permission>
<name>get certificate in the database</name> <name>get certificate in the database</name>
<path>/device-mgt/android/certificate/view</path> <path>/device-mgt/admin/certificate/Get</path>
<url>/certificates/*</url> <url>/certificates/*</url>
<method>GET</method> <method>GET</method>
</Permission> </Permission>
<Permission> <Permission>
<name>Remove certificate in the database</name> <name>get certificate in the database</name>
<path>/device-mgt/android/certificate/remove</path> <path>/device-mgt/admin/certificate/GetAll</path>
<url>/certificates</url>
<method>GET</method>
</Permission>
<Permission>
<name>get certificate in the database</name>
<path>/device-mgt/admin/certificate/Get</path>
<url>/certificates/*</url> <url>/certificates/*</url>
<method>DELETE</method> <method>DELETE</method>
</Permission> </Permission>
@ -1152,5 +1164,61 @@
<method>DELETE</method> <method>DELETE</method>
</Permission> </Permission>
<!-- End of Group related APIs --> <!-- End of Group related APIs -->
<!-- Dashboard related APIs -->
<Permission>
<name>get device count overview</name>
<path>/device-mgt/admin/dashboard/device-count-overview</path>
<url>/dashboard/device-count-overview</url>
<method>GET</method>
</Permission>
<Permission>
<name>get device counts by potential vulnerabilities</name>
<path>/device-mgt/admin/dashboard/device-counts-by-potential-vulnerabilities</path>
<url>/dashboard/device-counts-by-potential-vulnerabilities</url>
<method>GET</method>
</Permission>
<Permission>
<name>get non-compliant device counts by features</name>
<path>/device-mgt/admin/dashboard/non-compliant-device-counts-by-features</path>
<url>/dashboard/non-compliant-device-counts-by-features</url>
<method>GET</method>
</Permission>
<Permission>
<name>get device counts by groups</name>
<path>/device-mgt/admin/dashboard/device-counts-by-groups</path>
<url>/dashboard/device-counts-by-groups</url>
<method>GET</method>
</Permission>
<Permission>
<name>get feature-non-compliant device counts by groups</name>
<path>/device-mgt/admin/dashboard/feature-non-compliant-device-counts-by-groups</path>
<url>/dashboard/feature-non-compliant-device-counts-by-groups</url>
<method>GET</method>
</Permission>
<Permission>
<name>get filtered device count over total</name>
<path>/device-mgt/admin/dashboard/filtered-device-count-over-total</path>
<url>/dashboard/filtered-device-count-over-total</url>
<method>GET</method>
</Permission>
<Permission>
<name>get feature-non-compliant device count over total</name>
<path>/device-mgt/admin/dashboard/feature-non-compliant-device-count-over-total</path>
<url>/dashboard/feature-non-compliant-device-count-over-total</url>
<method>GET</method>
</Permission>
<Permission>
<name>get devices with details</name>
<path>/device-mgt/admin/dashboard/devices-with-details</path>
<url>/dashboard/devices-with-details</url>
<method>GET</method>
</Permission>
<Permission>
<name>get feature-non-compliant devices with details</name>
<path>/device-mgt/admin/dashboard/feature-non-compliant-devices-with-details</path>
<url>/dashboard/feature-non-compliant-devices-with-details</url>
<method>GET</method>
</Permission>
<!-- End of Dashboard related APIs -->
</PermissionConfiguration> </PermissionConfiguration>

@ -40,6 +40,7 @@
<ref bean="notificationServiceBean"/> <ref bean="notificationServiceBean"/>
<ref bean="informationServiceBean"/> <ref bean="informationServiceBean"/>
<ref bean="searchingServiceBean"/> <ref bean="searchingServiceBean"/>
<ref bean="dashboardServiceBean"/>
<ref bean="swaggerResource"/> <ref bean="swaggerResource"/>
</jaxrs:serviceBeans> </jaxrs:serviceBeans>
<jaxrs:providers> <jaxrs:providers>
@ -78,6 +79,7 @@
<bean id="searchingServiceBean" class="org.wso2.carbon.device.mgt.jaxrs.api.impl.DeviceSearchImpl"/> <bean id="searchingServiceBean" class="org.wso2.carbon.device.mgt.jaxrs.api.impl.DeviceSearchImpl"/>
<bean id="policyServiceBean" class="org.wso2.carbon.device.mgt.jaxrs.api.impl.PolicyImpl"/> <bean id="policyServiceBean" class="org.wso2.carbon.device.mgt.jaxrs.api.impl.PolicyImpl"/>
<bean id="profileServiceBean" class="org.wso2.carbon.device.mgt.jaxrs.api.impl.ProfileImpl"/> <bean id="profileServiceBean" class="org.wso2.carbon.device.mgt.jaxrs.api.impl.ProfileImpl"/>
<bean id="dashboardServiceBean" class="org.wso2.carbon.device.mgt.jaxrs.api.DashboardImpl"/>
<bean id="jsonProvider" class="org.wso2.carbon.device.mgt.jaxrs.common.GsonMessageBodyHandler"/> <bean id="jsonProvider" class="org.wso2.carbon.device.mgt.jaxrs.common.GsonMessageBodyHandler"/>
<bean id="errorHandler" class="org.wso2.carbon.device.mgt.jaxrs.api.common.ErrorHandler"/> <bean id="errorHandler" class="org.wso2.carbon.device.mgt.jaxrs.api.common.ErrorHandler"/>

@ -4,6 +4,8 @@
"apiContext" : "api", "apiContext" : "api",
"httpsURL" : "%https.ip%", "httpsURL" : "%https.ip%",
"httpURL" : "%http.ip%", "httpURL" : "%http.ip%",
"wssURL" : "%https.ip%",
"wsURL" : "%http.ip%",
"enrollmentDir": "/emm-web-agent/enrollment", "enrollmentDir": "/emm-web-agent/enrollment",
"iOSConfigRoot" : "%https.ip%/ios-enrollment/", "iOSConfigRoot" : "%https.ip%/ios-enrollment/",
"iOSAPIRoot" : "%https.ip%/ios/", "iOSAPIRoot" : "%https.ip%/ios/",

@ -19,11 +19,19 @@
package org.wso2.carbon.policy.mgt.common; package org.wso2.carbon.policy.mgt.common;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
@ApiModel(value = "DeviceGroupWrapper", description = "This class carries all information related to device groups")
public class DeviceGroupWrapper { public class DeviceGroupWrapper {
@ApiModelProperty(name = "id", value = "Id of the group", required = true)
private int id; private int id;
@ApiModelProperty(name = "name", value = "Name of the group.", required = true)
private String name; private String name;
@ApiModelProperty(name = "owner", value = "Creator of the group", required = true)
private String owner; private String owner;
@ApiModelProperty(name = "tenant ID", value = "To which tenant id the group belongs to.", required = true)
private int tenantId; private int tenantId;
public int getId() { public int getId() {

@ -102,6 +102,9 @@
<bundleDef> <bundleDef>
org.wso2.orbit.com.nimbusds:nimbus-jose-jwt:${nimbus.orbit.version} org.wso2.orbit.com.nimbusds:nimbus-jose-jwt:${nimbus.orbit.version}
</bundleDef> </bundleDef>
<bundleDef>
net.minidev:json-smart:${json.smart.version}
</bundleDef>
</bundles> </bundles>
<importFeatures> <importFeatures>
<importFeatureDef>org.wso2.carbon.core.server:${carbon.kernel.version} <importFeatureDef>org.wso2.carbon.core.server:${carbon.kernel.version}

@ -1821,6 +1821,7 @@
<nimbus.orbit.version>2.26.1.wso2v3</nimbus.orbit.version> <nimbus.orbit.version>2.26.1.wso2v3</nimbus.orbit.version>
<commons-json.version>2.0.0.wso2v1</commons-json.version> <commons-json.version>2.0.0.wso2v1</commons-json.version>
<json.smart.version>1.3</json.smart.version>
<google.gson.version>2.3.1</google.gson.version> <google.gson.version>2.3.1</google.gson.version>
<jsr311.version>1.1.1</jsr311.version> <jsr311.version>1.1.1</jsr311.version>
<commons.logging.version>1.2</commons.logging.version> <commons.logging.version>1.2</commons.logging.version>

Loading…
Cancel
Save